summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: adb1603)
raw | patch | inline | side by side (parent: adb1603)
author | Florian Forster <octo@collectd.org> | |
Wed, 2 Dec 2015 11:42:54 +0000 (12:42 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 6 Aug 2016 18:37:40 +0000 (20:37 +0200) |
src/utils_format_json.c | patch | blob | history | |
src/utils_format_json_test.c | patch | blob | history |
index ed94230170b702653fd5cc4284f7eeccd61069d9..63f03da3300f68b7e590bfa803da9c70d23c20ce 100644 (file)
--- a/src/utils_format_json.c
+++ b/src/utils_format_json.c
#include "utils_cache.h"
#if HAVE_LIBYAJL
-#include <yajl/yajl_gen.h>
+# include <yajl/yajl_common.h>
+# include <yajl/yajl_gen.h>
+# if HAVE_YAJL_YAJL_VERSION_H
+# include <yajl/yajl_version.h>
+# 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, /* {{{ */
{
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
+# if COLLECT_DEBUG
yajl_gen_config (g, yajl_gen_beautify);
yajl_gen_config (g, yajl_gen_validate_utf8);
+# 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)
index 6df6211952d8edc14e08afe98b45b8388f2f7684..353ef01c36f707e89e2436674201b71acae478f4 100644 (file)
#include "utils_format_json.h"
#include "common.h" /* for STATIC_ARRAY_SIZE */
+#include <yajl/yajl_common.h>
#include <yajl/yajl_parse.h>
+#if HAVE_YAJL_YAJL_VERSION_H
+# include <yajl/yajl_version.h>
+#endif
+#if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
+# define HAVE_YAJL_V2 1
+#endif
struct label_s
{
};
typedef struct test_case_s test_case_t;
+#if HAVE_YAJL_V2
static int test_map_key (void *ctx, unsigned char const *key, size_t key_len)
+#else
+static int test_map_key (void *ctx, unsigned char const *key, unsigned int key_len)
+#endif
{
test_case_t *c = ctx;
size_t i;
return 0;
}
+#if HAVE_YAJL_V2
static int test_string (void *ctx, unsigned char const *value, size_t value_len)
+#else
+static int test_string (void *ctx, unsigned char const *value, unsigned int value_len)
+#endif
{
test_case_t *c = ctx;
test_case_t c = { labels, labels_num, NULL };
yajl_handle hndl;
- CHECK_NOT_NULL (hndl = yajl_alloc (&funcs, NULL, &c));
+#if HAVE_YAJL_V2
+ CHECK_NOT_NULL (hndl = yajl_alloc (&funcs, /* alloc = */ NULL, &c));
+#else
+ CHECK_NOT_NULL (hndl = yajl_alloc (&funcs, /* config = */ NULL, /* alloc = */ NULL, &c));
+#endif
OK (yajl_parse (hndl, (unsigned char *) json, strlen (json)) == yajl_status_ok);
yajl_free (hndl);
};
/* 1448284606.125 ^= 1555083754651779072 */
- notification_t n = { NOTIF_WARNING, 1555083754651779072, "this is a message",
+ notification_t n = { NOTIF_WARNING, 1555083754651779072ULL, "this is a message",
"example.com", "unit", "", "test", "case", NULL };
char got[1024];