X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_format_json.c;h=5b5fcdf0536170b5cae56c3230f90e7e95995dc9;hb=6a151af7649eb811a5f8dc1bd78c21e6c53c74aa;hp=ed94230170b702653fd5cc4284f7eeccd61069d9;hpb=30c111183bf529381359a411edf5e5b1feb6ba9e;p=collectd.git diff --git a/src/utils_format_json.c b/src/utils_format_json.c index ed942301..5b5fcdf0 100644 --- a/src/utils_format_json.c +++ b/src/utils_format_json.c @@ -33,7 +33,14 @@ #include "utils_cache.h" #if HAVE_LIBYAJL -#include +# include +# include +# if HAVE_YAJL_YAJL_VERSION_H +# include +# endif +# if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1) +# define HAVE_YAJL_V2 1 +# endif #endif static int json_escape_string (char *buffer, size_t buffer_size, /* {{{ */ @@ -655,18 +662,33 @@ int format_json_notification (char *buffer, size_t buffer_size, /* {{{ */ { yajl_gen g; unsigned char const *out; +#if HAVE_YAJL_V2 size_t unused_out_len; +#else + unsigned int unused_out_len; +#endif if ((buffer == NULL) || (n == NULL)) return EINVAL; +#if HAVE_YAJL_V2 g = yajl_gen_alloc (NULL); if (g == NULL) return -1; - -#if COLLECT_DEBUG - yajl_gen_config (g, yajl_gen_beautify); - yajl_gen_config (g, yajl_gen_validate_utf8); +# if COLLECT_DEBUG + yajl_gen_config (g, yajl_gen_beautify, 1); + yajl_gen_config (g, yajl_gen_validate_utf8, 1); +# endif + +#else /* !HAVE_YAJL_V2 */ + yajl_gen_config conf = { 0 }; +# if COLLECT_DEBUG + conf.beautify = 1; + conf.indentString = " "; +# endif + g = yajl_gen_alloc (&conf, NULL); + if (g == NULL) + return -1; #endif if (format_alert (g, n) != 0)