[libvirt] [PATCH 2/9] util: json: Add virJSONValueIsObject

Peter Krempa posted 9 patches 8 years, 7 months ago
[libvirt] [PATCH 2/9] util: json: Add virJSONValueIsObject
Posted by Peter Krempa 8 years, 7 months ago
Allows testing whether a virJSONValue is an object.
---
 src/libvirt_private.syms |  1 +
 src/util/virjson.c       | 10 ++++++++++
 src/util/virjson.h       |  2 ++
 3 files changed, 13 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c1e9471c5..d487b1f43 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1905,6 +1905,7 @@ virJSONValueGetString;
 virJSONValueHashFree;
 virJSONValueIsArray;
 virJSONValueIsNull;
+virJSONValueIsObject;
 virJSONValueNewArray;
 virJSONValueNewArrayFromBitmap;
 virJSONValueNewBoolean;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index b49b29b0f..efd6c3a0e 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -905,6 +905,16 @@ virJSONValueObjectGetValue(virJSONValuePtr object,


 bool
+virJSONValueIsObject(virJSONValuePtr object)
+{
+    if (object)
+        return object->type == VIR_JSON_TYPE_OBJECT;
+    else
+        return NULL;
+}
+
+
+bool
 virJSONValueIsArray(virJSONValuePtr array)
 {
     return array->type == VIR_JSON_TYPE_ARRAY;
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 14b74c061..c9d9752de 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -114,6 +114,8 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
 virJSONValuePtr virJSONValueObjectGetByType(virJSONValuePtr object,
                                             const char *key, virJSONType type);

+bool virJSONValueIsObject(virJSONValuePtr object);
+
 bool virJSONValueIsArray(virJSONValuePtr array);
 ssize_t virJSONValueArraySize(const virJSONValue *array);
 virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element);
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/9] util: json: Add virJSONValueIsObject
Posted by Bjoern Walk 8 years, 7 months ago
Peter Krempa <pkrempa@redhat.com> [2017-06-27, 02:46PM +0200]:
> Allows testing whether a virJSONValue is an object.
> ---
>  src/libvirt_private.syms |  1 +
>  src/util/virjson.c       | 10 ++++++++++
>  src/util/virjson.h       |  2 ++
>  3 files changed, 13 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index c1e9471c5..d487b1f43 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1905,6 +1905,7 @@ virJSONValueGetString;
>  virJSONValueHashFree;
>  virJSONValueIsArray;
>  virJSONValueIsNull;
> +virJSONValueIsObject;
>  virJSONValueNewArray;
>  virJSONValueNewArrayFromBitmap;
>  virJSONValueNewBoolean;
> diff --git a/src/util/virjson.c b/src/util/virjson.c
> index b49b29b0f..efd6c3a0e 100644
> --- a/src/util/virjson.c
> +++ b/src/util/virjson.c
> @@ -905,6 +905,16 @@ virJSONValueObjectGetValue(virJSONValuePtr object,
> 
> 
>  bool
> +virJSONValueIsObject(virJSONValuePtr object)
> +{
> +    if (object)
> +        return object->type == VIR_JSON_TYPE_OBJECT;
> +    else
> +        return NULL;

s/NULL/false/

> +}
> +
> +
> +bool
>  virJSONValueIsArray(virJSONValuePtr array)
>  {
>      return array->type == VIR_JSON_TYPE_ARRAY;
> diff --git a/src/util/virjson.h b/src/util/virjson.h
> index 14b74c061..c9d9752de 100644
> --- a/src/util/virjson.h
> +++ b/src/util/virjson.h
> @@ -114,6 +114,8 @@ virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
>  virJSONValuePtr virJSONValueObjectGetByType(virJSONValuePtr object,
>                                              const char *key, virJSONType type);
> 
> +bool virJSONValueIsObject(virJSONValuePtr object);
> +
>  bool virJSONValueIsArray(virJSONValuePtr array);
>  ssize_t virJSONValueArraySize(const virJSONValue *array);
>  virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element);
> -- 
> 2.12.2
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

-- 
IBM Systems
Linux on z Systems & Virtualization Development
------------------------------------------------------------------------
IBM Deutschland
Schönaicher Str. 220
71032 Böblingen
Phone: +49 7031 16 1819
E-Mail: bwalk@de.ibm.com
------------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294 
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/9] util: json: Add virJSONValueIsObject
Posted by Peter Krempa 8 years, 7 months ago
On Tue, Jun 27, 2017 at 17:55:40 +0200, Bjoern Walk wrote:
> Peter Krempa <pkrempa@redhat.com> [2017-06-27, 02:46PM +0200]:
> > Allows testing whether a virJSONValue is an object.
> > ---
> >  src/libvirt_private.syms |  1 +
> >  src/util/virjson.c       | 10 ++++++++++
> >  src/util/virjson.h       |  2 ++
> >  3 files changed, 13 insertions(+)

[...]

> > diff --git a/src/util/virjson.c b/src/util/virjson.c
> > index b49b29b0f..efd6c3a0e 100644
> > --- a/src/util/virjson.c
> > +++ b/src/util/virjson.c
> > @@ -905,6 +905,16 @@ virJSONValueObjectGetValue(virJSONValuePtr object,
> > 
> > 
> >  bool
> > +virJSONValueIsObject(virJSONValuePtr object)
> > +{
> > +    if (object)
> > +        return object->type == VIR_JSON_TYPE_OBJECT;
> > +    else
> > +        return NULL;
> 
> s/NULL/false/

Thanks! It's a shame we don't have 'nullptr' like functionality in C.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/9] util: json: Add virJSONValueIsObject
Posted by John Ferlan 8 years, 7 months ago

On 06/27/2017 08:46 AM, Peter Krempa wrote:
> Allows testing whether a virJSONValue is an object.
> ---
>  src/libvirt_private.syms |  1 +
>  src/util/virjson.c       | 10 ++++++++++
>  src/util/virjson.h       |  2 ++
>  3 files changed, 13 insertions(+)
> 

As long as you've made the change Bjoern points out...

Reviewed-by: John Ferlan <jferlan@redhat.com>


John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list