From: Alex Bligh <alex@alex.org.uk>
To: xen-devel <xen-devel@lists.xen.org>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
Ian Campbell <Ian.Campbell@citrix.com>,
Alex Bligh <alex@alex.org.uk>
Subject: [PATCH 04/11] libxl_json: Introduce libxl__json_object_to_yajl_gen.
Date: Wed, 13 Feb 2013 18:32:13 +0000 [thread overview]
Message-ID: <1360780340-19117-5-git-send-email-alex@alex.org.uk> (raw)
In-Reply-To: <1360780340-19117-1-git-send-email-alex@alex.org.uk>
This function converts a libxl__json_object to yajl by calling every
yajl_gen_* function on a preallocated yajl_gen hand.
This helps to integrate a json_object into an already existing
yajl_gen tree.
This function is used in a later patch.
Backported from xen-unstable patch:
: HG changeset patch
: User Anthony PERARD <anthony.perard@citrix.com>
: Date 1349693132 -3600
: Node ID 74dee58cfc0d2d6594f388db3b4d2ce91d1bb204
: Parent 3f71aab0e2774ded0c5a03436c364fb031ba9aa0
Signed-off-by: Alex Bligh <alex@alex.org.uk>
---
tools/libxl/libxl_internal.h | 3 ++
tools/libxl/libxl_json.c | 61 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 7dbd8af..b00ff61 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1539,6 +1539,9 @@ libxl__json_map_node *libxl__json_map_node_get(const libxl__json_object *o,
_hidden const libxl__json_object *libxl__json_map_get(const char *key,
const libxl__json_object *o,
libxl__json_node_type expected_type);
+_hidden yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc_opt,
+ yajl_gen hand,
+ libxl__json_object *param);
_hidden void libxl__json_object_free(libxl__gc *gc_opt,
libxl__json_object *obj);
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c
index 98db465..72b52e8 100644
--- a/tools/libxl/libxl_json.c
+++ b/tools/libxl/libxl_json.c
@@ -381,6 +381,67 @@ const libxl__json_object *libxl__json_map_get(const char *key,
return NULL;
}
+yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc,
+ yajl_gen hand,
+ libxl__json_object *obj)
+{
+ int idx = 0;
+ yajl_status rc;
+
+ switch (obj->type) {
+ case JSON_NULL:
+ return yajl_gen_null(hand);
+ case JSON_BOOL:
+ return yajl_gen_bool(hand, obj->u.b);
+ case JSON_INTEGER:
+ return yajl_gen_integer(hand, obj->u.i);
+ case JSON_DOUBLE:
+ return yajl_gen_double(hand, obj->u.d);
+ case JSON_NUMBER:
+ return yajl_gen_number(hand, obj->u.string, strlen(obj->u.string));
+ case JSON_STRING:
+ return libxl__yajl_gen_asciiz(hand, obj->u.string);
+ case JSON_MAP: {
+ libxl__json_map_node *node = NULL;
+
+ rc = yajl_gen_map_open(hand);
+ if (rc != yajl_status_ok)
+ return rc;
+ for (idx = 0; idx < obj->u.map->count; idx++) {
+ if (flexarray_get(obj->u.map, idx, (void**)&node) != 0)
+ break;
+
+ rc = libxl__yajl_gen_asciiz(hand, node->map_key);
+ if (rc != yajl_status_ok)
+ return rc;
+ rc = libxl__json_object_to_yajl_gen(gc, hand, node->obj);
+ if (rc != yajl_status_ok)
+ return rc;
+ }
+ return yajl_gen_map_close(hand);
+ }
+ case JSON_ARRAY: {
+ libxl__json_object *node = NULL;
+
+ rc = yajl_gen_array_open(hand);
+ if (rc != yajl_status_ok)
+ return rc;
+ for (idx = 0; idx < obj->u.array->count; idx++) {
+ if (flexarray_get(obj->u.array, idx, (void**)&node) != 0)
+ break;
+ rc = libxl__json_object_to_yajl_gen(gc, hand, node);
+ if (rc != yajl_status_ok)
+ return rc;
+ }
+ return yajl_gen_array_close(hand);
+ }
+ case JSON_ANY:
+ /* JSON_ANY is not a valid value for obj->type. */
+ ;
+ }
+ abort();
+}
+
/*
* JSON callbacks
--
1.7.4.1
next prev parent reply other threads:[~2013-02-13 18:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-13 18:32 [v3] QEMU: Enabling live-migrate on HVM on qemu-xen device model in 4.2 Alex Bligh
2013-02-13 18:32 ` [PATCH 01/11] libxl_json: Export json_object related function Alex Bligh
2013-02-15 14:23 ` Ian Jackson
2013-02-13 18:32 ` [PATCH 02/11] libxl_json: Remove JSON_ERROR from enum Alex Bligh
2013-02-13 18:32 ` [PATCH 03/11] libxl_json: Replace JSON_TRUE/FALSE by JSON_BOOL Alex Bligh
2013-02-13 18:32 ` Alex Bligh [this message]
2013-02-13 18:32 ` [PATCH 05/11] libxl_qmp: Introduces helpers to create an argument list Alex Bligh
2013-02-13 18:32 ` [PATCH 06/11] libxl_qmp: Use qmp_parameters_* functions for param list of a QMP command Alex Bligh
2013-02-13 18:32 ` [PATCH 07/11] libxl_qmp: Simplify run of single QMP commands Alex Bligh
2013-02-13 18:32 ` [PATCH 08/11] libxl_qmp: Introduce libxl__qmp_set_global_dirty_log Alex Bligh
2013-02-13 18:32 ` [PATCH 09/11] libxl_dom: Call the right switch logdirty for the right DM Alex Bligh
2013-02-13 18:32 ` [PATCH 10/11] libxl: libxl__qmp_save: Add filename as JSON parameter to xen-save-devices-state Alex Bligh
2013-02-13 18:32 ` [PATCH 11/11] libxl: Allow migration with qemu-xen Alex Bligh
-- strict thread matches above, loose matches on Subject: below --
2013-01-19 17:57 QEMU: Enabling live-migrate on HVM on qemu-xen device model in 4.2 Alex Bligh
2013-01-19 17:58 ` [PATCH 04/11] libxl_json: Introduce libxl__json_object_to_yajl_gen Alex Bligh
2013-02-12 15:38 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360780340-19117-5-git-send-email-alex@alex.org.uk \
--to=alex@alex.org.uk \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).