Skip to content

Commit

Permalink
Use #if HAVE_YAJL instead of #ifdef HAVE_YAJL
Browse files Browse the repository at this point in the history
  • Loading branch information
Woazboat committed Nov 28, 2023
1 parent 259d9a7 commit a583819
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/cgimap/mime_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum type {
unspecified_type, // a "null" type, used to indicate no choice.
text_plain,
application_xml,
#ifdef HAVE_YAJL
#if HAVE_YAJL
application_json,
#endif
any_type // the "*/*" type used to mean that anything is acceptable.
Expand Down
6 changes: 4 additions & 2 deletions src/choose_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "cgimap/request_helpers.hpp"
#include "cgimap/xml_writer.hpp"
#include "cgimap/xml_formatter.hpp"
#if HAVE_YAJL
#include "cgimap/json_writer.hpp"
#include "cgimap/json_formatter.hpp"
#endif
#include "cgimap/text_writer.hpp"
#include "cgimap/text_formatter.hpp"
#include "cgimap/logger.hpp"
Expand Down Expand Up @@ -115,7 +117,7 @@ struct http_accept_grammar
= lit("* / *") [_val = mime::any_type]
| lit("text/xml") [_val = mime::application_xml]
| lit("application/xml") [_val = mime::application_xml]
#ifdef HAVE_YAJL
#if HAVE_YAJL
| lit("application/json")[_val = mime::application_json]
#endif
;
Expand Down Expand Up @@ -256,7 +258,7 @@ std::unique_ptr<output_formatter> create_formatter(mime::type best_type, output_
case mime::application_xml:
return std::make_unique<xml_formatter>(std::make_unique<xml_writer>(out, true));

#ifdef HAVE_YAJL
#if HAVE_YAJL
case mime::application_json:
return std::make_unique<json_formatter>(std::make_unique<json_writer>(out, false));
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct json_writer::pimpl_ {
// so seems best to be on the safe side.
yajl_gen gen;

#ifdef HAVE_YAJL2
#if HAVE_YAJL2
yajl_alloc_funcs alloc_funcs;
#else
yajl_gen_config config;
Expand All @@ -36,7 +36,7 @@ static void wrap_write(void *context, const char *str, unsigned int len) {

json_writer::json_writer(output_buffer &out, bool indent)
: pimpl(std::make_unique<pimpl_>()), out(out) {
#ifdef HAVE_YAJL2
#if HAVE_YAJL2
pimpl->gen = yajl_gen_alloc(NULL);

#else /* older version of YAJL */
Expand All @@ -56,7 +56,7 @@ json_writer::json_writer(output_buffer &out, bool indent)
throw std::runtime_error("error creating json writer.");
}

#ifdef HAVE_YAJL2
#if HAVE_YAJL2
if (indent) {
yajl_gen_config(pimpl->gen, yajl_gen_beautify, 1);
yajl_gen_config(pimpl->gen, yajl_gen_indent_string, " ");
Expand Down
4 changes: 2 additions & 2 deletions src/mime_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ string to_string(type t) {
return "text/plain";
} else if (application_xml == t) {
return "application/xml";
#ifdef HAVE_YAJL
#if HAVE_YAJL
} else if (application_json == t) {
return "application/json";
#endif
Expand All @@ -37,7 +37,7 @@ type parse_from(const std::string &name) {
t = application_xml;
} else if (name == "application/xml") {
t = application_xml;
#ifdef HAVE_YAJL
#if HAVE_YAJL
} else if (name == "application/json") {
t = application_json;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/osm_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ osm_responder::~osm_responder() = default;
list<mime::type> osm_responder::types_available() const {
list<mime::type> types;
types.push_back(mime::application_xml);
#ifdef HAVE_YAJL
#if HAVE_YAJL
types.push_back(mime::application_json);
#endif
return types;
Expand Down
2 changes: 1 addition & 1 deletion src/routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ namespace {
*/
pair<string, mime::type> resource_mime_type(const string &path) {

#ifdef HAVE_YAJL
#if HAVE_YAJL
{
std::size_t json_found = path.rfind(".json");

Expand Down

0 comments on commit a583819

Please sign in to comment.