mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
libxl_json: libxl__json_object_to_json
Allow to generate a JSON string from a libxl__json_object, useful for debugging. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com> Acked-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
1 parent
544c15c827
commit
7fbaf06d2d
2 files changed
+35
No files matched your search
@@ -2037,6 +2037,9 @@ _hidden void libxl__json_object_free(libxl__gc *gc_opt,
|
||||
|
||||
_hidden libxl__json_object *libxl__json_parse(libxl__gc *gc_opt, const char *s);
|
||||
|
||||
_hidden char *libxl__json_object_to_json(libxl__gc *gc,
|
||||
const libxl__json_object *args);
|
||||
|
||||
/* Based on /local/domain/$domid/dm-version xenstore key
|
||||
* default is qemu xen traditional */
|
||||
_hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);
|
||||
|
||||
@@ -1017,6 +1017,38 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *libxl__json_object_to_json(libxl__gc *gc,
|
||||
const libxl__json_object *args)
|
||||
{
|
||||
const unsigned char *buf;
|
||||
libxl_yajl_length len;
|
||||
yajl_gen_status s;
|
||||
yajl_gen hand;
|
||||
char *ret = NULL;
|
||||
int rc;
|
||||
|
||||
if (!args)
|
||||
return NULL;
|
||||
|
||||
hand = libxl_yajl_gen_alloc(NULL);
|
||||
if (!hand)
|
||||
return NULL;
|
||||
|
||||
rc = libxl__json_object_to_yajl_gen(gc, hand, args);
|
||||
if (rc)
|
||||
goto out;
|
||||
|
||||
s = yajl_gen_get_buf(hand, &buf, &len);
|
||||
if (s)
|
||||
goto out;
|
||||
|
||||
ret = libxl__strndup(gc, (const char *)buf, len);
|
||||
|
||||
out:
|
||||
yajl_gen_free(hand);
|
||||
return ret;
|
||||
}
|
||||
|
||||
yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val)
|
||||
{
|
||||
char *num;
|
||||
|
||||