[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH v4 4/6] libxl: Extend libxl__json_object_to_json() prototype



The function libxl__json_object_to_json() returns a json object as
string in a pretty format. With support for the new PCI device
passthrough option hotplug=0, the function will be used to generate the
json string passed to qemu -device command line parameter, but the
string needs to be in plain format, i.e. without carriage return or tab
characters.

This patch adds a 'pretty' parameter to the function to control the
output string format.

Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxx>
---
v4: new patch
---
 tools/libs/light/libxl_internal.h |  5 +++--
 tools/libs/light/libxl_json.c     | 11 +++++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/libs/light/libxl_internal.h 
b/tools/libs/light/libxl_internal.h
index b6d764ad00..b87959e44a 100644
--- a/tools/libs/light/libxl_internal.h
+++ b/tools/libs/light/libxl_internal.h
@@ -2270,10 +2270,11 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc 
*gc_opt, const char *s);
 
 /* `args` may be NULL */
 _hidden char *libxl__json_object_to_json(libxl__gc *gc,
-                                         const libxl__json_object *args);
+                                         const libxl__json_object *args,
+                                         bool pretty);
 /* Always return a valid string, but invalid json on error. */
 #define JSON(o) \
-    (libxl__json_object_to_json(gc, (o)) ? : "<invalid-json-object>")
+    (libxl__json_object_to_json(gc, (o), true) ? : "<invalid-json-object>")
 
   /* Based on /local/domain/$domid/dm-version xenstore key */
 _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);
diff --git a/tools/libs/light/libxl_json.c b/tools/libs/light/libxl_json.c
index 68f36901c2..c566ec83ff 100644
--- a/tools/libs/light/libxl_json.c
+++ b/tools/libs/light/libxl_json.c
@@ -1527,7 +1527,8 @@ out:
 #endif
 
 char *libxl__json_object_to_json(libxl__gc *gc,
-                                 const libxl__json_object *args)
+                                 const libxl__json_object *args,
+                                 bool pretty)
 {
 #ifdef HAVE_LIBJSONC
     const char *buf;
@@ -1542,7 +1543,9 @@ char *libxl__json_object_to_json(libxl__gc *gc,
     if (rc)
         goto out;
 
-    buf = json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY);
+    buf = json_object_to_json_string_ext(root, pretty ?
+                                               JSON_C_TO_STRING_PRETTY :
+                                               JSON_C_TO_STRING_PLAIN);
     if (!buf)
         goto out;
 
@@ -1566,6 +1569,10 @@ out:
     if (!hand)
         return NULL;
 
+#if HAVE_YAJL_V2
+    yajl_gen_config(hand, yajl_gen_beautify, pretty);
+#endif
+
     rc = libxl__json_object_to_yajl_gen(gc, hand, args);
     if (rc)
         goto out;
-- 
2.53.0



--
Thierry Escande | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.