aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Bligh <alex@alex.org.uk>2013-02-19 15:25:13 +0000
committerAlex Bligh <alex@alex.org.uk>2013-02-19 15:25:13 +0000
commit6a2aca9fdef0499e613715baf107f2296b9007cf (patch)
treeef80d591a5ecb6c8d0af66a1f2d39c8d34e60a08
parentbfdb59bd58b617f0ffc3ea2616b60936dee6fa1b (diff)
downloadxen-6a2aca9fdef0499e613715baf107f2296b9007cf.tar.gz
xen-6a2aca9fdef0499e613715baf107f2296b9007cf.tar.bz2
xen-6a2aca9fdef0499e613715baf107f2296b9007cf.zip
libxl_json: Replace JSON_TRUE/FALSE by JSON_BOOL.
Those two JSON_TRUE and JSON_FALSE were types of node. But it's better to have a unique JSON_BOOL type. Backported from xen-unstable patch: : HG changeset patch : User Anthony PERARD <anthony.perard@citrix.com> : Date 1349693131 -3600 : Node ID 3f71aab0e2774ded0c5a03436c364fb031ba9aa0 : Parent 4a6d5d8cba4fc44f9bbda201188885868604b8e8 Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
-rw-r--r--tools/libxl/libxl_internal.h15
-rw-r--r--tools/libxl/libxl_json.c3
-rw-r--r--tools/libxl/libxl_qmp.c3
3 files changed, 16 insertions, 5 deletions
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 5b285d488b..7dbd8af2bf 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1429,8 +1429,7 @@ _hidden yajl_gen_status libxl__yajl_gen_enum(yajl_gen hand, const char *str);
typedef enum {
JSON_NULL,
- JSON_TRUE,
- JSON_FALSE,
+ JSON_BOOL,
JSON_INTEGER,
JSON_DOUBLE,
/* number is store in string, it's too big to be a long long or a double */
@@ -1444,6 +1443,7 @@ typedef enum {
typedef struct libxl__json_object {
libxl__json_node_type type;
union {
+ bool b;
long long i;
double d;
char *string;
@@ -1462,6 +1462,10 @@ typedef struct {
typedef struct libxl__yajl_ctx libxl__yajl_ctx;
+static inline bool libxl__json_object_is_bool(const libxl__json_object *o)
+{
+ return o != NULL && o->type == JSON_BOOL;
+}
static inline bool libxl__json_object_is_string(const libxl__json_object *o)
{
return o != NULL && o->type == JSON_STRING;
@@ -1479,6 +1483,13 @@ static inline bool libxl__json_object_is_array(const libxl__json_object *o)
return o != NULL && o->type == JSON_ARRAY;
}
+static inline bool libxl__json_object_get_bool(const libxl__json_object *o)
+{
+ if (libxl__json_object_is_bool(o))
+ return o->u.b;
+ else
+ return false;
+}
static inline
const char *libxl__json_object_get_string(const libxl__json_object *o)
{
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c
index 0b0cf2fc93..98db4657b9 100644
--- a/tools/libxl/libxl_json.c
+++ b/tools/libxl/libxl_json.c
@@ -411,8 +411,7 @@ static int json_callback_boolean(void *opaque, int boolean)
DEBUG_GEN_VALUE(ctx, bool, boolean);
- if ((obj = libxl__json_object_alloc(ctx->gc,
- boolean ? JSON_TRUE : JSON_FALSE)) == NULL)
+ if ((obj = libxl__json_object_alloc(ctx->gc, JSON_BOOL)) == NULL)
return 0;
if (libxl__json_object_append_to(ctx->gc, obj, ctx->current) == -1) {
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index e33b130f00..9e86c35cc5 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -178,7 +178,8 @@ static int qmp_register_vnc_callback(libxl__qmp_handler *qmp,
goto out;
}
- if (libxl__json_map_get("enabled", o, JSON_FALSE)) {
+ obj = libxl__json_map_get("enabled", o, JSON_BOOL);
+ if (!obj || !libxl__json_object_get_bool(obj)) {
rc = 0;
goto out;
}