]> xenbits.xensource.com Git - libvirt.git/commit
json: make it easier to type-check when getting from object
authorEric Blake <eblake@redhat.com>
Fri, 19 Jun 2015 23:13:03 +0000 (17:13 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 22 Jun 2015 16:38:21 +0000 (10:38 -0600)
commit58fd67033505d448e484041f928d3fe7c92cadc6
tree3a9f6996543320d5e6a9a6e1db9f5e1fe2d1b908
parentceb496e5f086a7fc922b8f7e2b1bc38410752306
json: make it easier to type-check when getting from object

While working in qemu_monitor_json, I repeatedly found myself
getting a value then checking if it was an object.  Add some
wrappers to make this task easier.

* src/util/virjson.c (virJSONValueObjectGetByType)
(virJSONValueObjectGetObject, virJSONValueObjectGetArray): New
functions.
(virJSONValueObjectGetString, virJSONValueObjectGetNumberInt)
(virJSONValueObjectGetNumberUint)
(virJSONValueObjectGetNumberLong)
(virJSONValueObjectGetNumberUlong)
(virJSONValueObjectGetNumberDouble)
(virJSONValueObjectGetBoolean): Simplify.
(virJSONValueIsNull): Change return type.
* src/util/virjson.h: Reflect changes.
* src/libvirt_private.syms (virjson.h): Export them.
* tests/jsontest.c (testJSONLookup): New test.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/libvirt_private.syms
src/util/virjson.c
src/util/virjson.h
tests/jsontest.c