|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XEN PATCH 08/11] libxl: convert libxl__json_object_to_json() to json_object
From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
But keep the implementation done for YAJL.
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
tools/libs/light/libxl_json.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c
index 01944ef94d..cffda158d2 100644
--- a/tools/libs/light/libxl_json.c
+++ b/tools/libs/light/libxl_json.c
@@ -104,10 +104,12 @@ typedef struct libxl__yajl_ctx {
* YAJL Helper
*/
+#ifdef HAVE_LIBYAJL
yajl_gen_status libxl__yajl_gen_asciiz(yajl_gen hand, const char *str)
{
return yajl_gen_string(hand, (const unsigned char *)str, strlen(str));
}
+#endif
#ifdef HAVE_LIBJSONC
int libxl__enum_gen_jso(json_object **jso_r, const char *str)
@@ -1522,6 +1524,29 @@ char *libxl__object_to_json(libxl_ctx *ctx, const char
*type,
char *libxl__json_object_to_json(libxl__gc *gc,
const libxl__json_object *args)
{
+#ifdef HAVE_LIBJSONC
+ const char *buf;
+ json_object *root;
+ char *ret = NULL;
+ int rc;
+
+ if (!args)
+ return NULL;
+
+ rc = libxl__json_object_to_json_object(gc, &root, args);
+ if (rc)
+ goto out;
+
+ buf = json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY);
+ if (!buf)
+ goto out;
+
+ ret = libxl__strdup(gc, buf);
+
+out:
+ json_object_put(root);
+ return ret;
+#elif defined(HAVE_LIBYAJL)
const unsigned char *buf;
libxl_yajl_length len;
yajl_gen_status s;
@@ -1549,6 +1574,7 @@ char *libxl__json_object_to_json(libxl__gc *gc,
out:
yajl_gen_free(hand);
return ret;
+#endif
}
#ifdef HAVE_LIBJSONC
--
Anthony PERARD
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |