Package: collectd
Severity: normal
Tags: patch

Hi,

Yajl version 2.0.4 will soon be uploaded to unstable.  It will cause
collectd to FTBFS because of API changes.

I've attached a patch adapted from upstream commit
5ec7a37c81d6f64f35b1f35e2f0e3157e83f2718. It allows support for either
the v1 or v2 API.

Please let me know if you have concerns.

Regards,

John Stamp
#! /bin/sh /usr/share/dpatch/dpatch-run
## yajl2_api.dpatch by John Stamp <jst...@users.sourceforge.net>
##
## DP: Add support for libyajl v2 API
## DP:
## DP: This is based on upstream git commit
## DP: 5ec7a37c81d6f64f35b1f35e2f0e3157e83f2718 

@DPATCH@

--- a/configure
+++ b/configure
@@ -22499,6 +22499,18 @@
 
 done
 
+	for ac_header in yajl/yajl_version.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "yajl/yajl_version.h" "ac_cv_header_yajl_yajl_version_h" "$ac_includes_default"
+if test "x$ac_cv_header_yajl_yajl_version_h" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_YAJL_YAJL_VERSION_H 1
+_ACEOF
+
+fi
+
+done
+
 
 	CPPFLAGS="$SAVE_CPPFLAGS"
 fi
--- a/configure.in
+++ b/configure.in
@@ -3609,6 +3609,7 @@
 	CPPFLAGS="$CPPFLAGS $with_libyajl_cppflags"
 
 	AC_CHECK_HEADERS(yajl/yajl_parse.h, [with_libyajl="yes"], [with_libyajl="no (yajl/yajl_parse.h not found)"])
+	AC_CHECK_HEADERS(yajl/yajl_version.h)
 
 	CPPFLAGS="$SAVE_CPPFLAGS"
 fi
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -1212,6 +1212,9 @@
 /* Define to 1 if you have the <yajl/yajl_parse.h> header file. */
 #undef HAVE_YAJL_YAJL_PARSE_H
 
+/* Define to 1 if you have the <yajl/yajl_version.h> header file. */
+#undef HAVE_YAJL_YAJL_VERSION_H
+
 /* Define to 1 if the system has the type `_Bool'. */
 #undef HAVE__BOOL
 
--- a/src/curl_json.c
+++ b/src/curl_json.c
@@ -29,6 +29,13 @@
 
 #include <curl/curl.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
 
 #define CJ_DEFAULT_HOST "localhost"
 #define CJ_KEY_MAGIC 0x43484b59UL /* CHKY */
@@ -77,6 +84,12 @@
 };
 typedef struct cj_s cj_t; /* }}} */
 
+#if HAVE_YAJL_V2
+typedef size_t yajl_len_t;
+#else
+typedef unsigned int yajl_len_t;
+#endif
+
 static int cj_read (user_data_t *ud);
 static int cj_curl_perform (cj_t *db, CURL *curl);
 static void cj_submit (cj_t *db, cj_key_t *key, value_t *value);
@@ -100,11 +113,17 @@
   status = yajl_parse(db->yajl, (unsigned char *)buf, len);
   if (status == yajl_status_ok)
   {
+#if HAVE_YAJL_V2
+    status = yajl_complete_parse(db->yajl);
+#else
     status = yajl_parse_complete(db->yajl);
+#endif
     return (len);
   }
+#if !HAVE_YAJL_V2
   else if (status == yajl_status_insufficient_data)
     return (len);
+#endif
 
   if (status != yajl_status_ok)
   {
@@ -130,7 +149,11 @@
 }
 
 /* yajl callbacks */
+#if HAVE_YAJL_V2
+static int cj_cb_integer (void *ctx, long long val)
+#else
 static int cj_cb_integer (void *ctx, long val)
+#endif
 {
   cj_t *db = (cj_t *)ctx;
   cj_key_t *key = db->state[db->depth].key;
@@ -185,7 +208,7 @@
 }
 
 static int cj_cb_map_key (void *ctx, const unsigned char *val,
-                            unsigned int len)
+    yajl_len_t len)
 {
   cj_t *db = (cj_t *)ctx;
   c_avl_tree_t *tree;
@@ -213,7 +236,7 @@
 }
 
 static int cj_cb_string (void *ctx, const unsigned char *val,
-                           unsigned int len)
+    yajl_len_t len)
 {
   cj_t *db = (cj_t *)ctx;
   c_avl_tree_t *tree;
@@ -762,7 +785,13 @@
   char *url;
   yajl_handle yprev = db->yajl;
 
-  db->yajl = yajl_alloc (&ycallbacks, NULL, NULL, (void *)db);
+  db->yajl = yajl_alloc (&ycallbacks,
+#if HAVE_YAJL_V2
+      /* alloc funcs = */ NULL,
+#else
+      /* alloc funcs = */ NULL, NULL,
+#endif
+      /* context = */ (void *)db);
   if (db->yajl == NULL)
   {
     ERROR ("curl_json plugin: yajl_alloc failed.");

Reply via email to