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 */
typedef struct libxl__json_object {
libxl__json_node_type type;
union {
+ bool b;
long long i;
double d;
char *string;
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;
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)
{
DEBUG_GEN_VALUE(ctx, bool, boolean);
- obj = libxl__json_object_alloc(ctx->gc,
- boolean ? JSON_TRUE : JSON_FALSE);
+ obj = libxl__json_object_alloc(ctx->gc, JSON_BOOL);
+ obj->u.b = boolean;
if (libxl__json_object_append_to(ctx->gc, obj, ctx->current) == -1) {
return 0;
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;
}