[PATCH 6/9] util: json: Improve handling and docs for adding JSON objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The JSON structure constructor has an option to add JSON arrays to the
constructed object. The description is inaccurate as it can add any json
object even a dict. Change the docs to cover this option and add
possibility to specify NULL object to be added. These will be skipped as
we have with other specifiers.
---
 src/util/virjson.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 0dfeaed..f490f2c 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -97,8 +97,9 @@ struct _virJSONParser {
  *
  * d: double precision floating point number
  * n: json null value
- * a: json array
  *
+ * a: json object, must be non-NULL
+ * A: json object, omitted if NULL
  * The value corresponds to the selected type.
  *
  * Returns -1 on error. 1 on success, if at least one key:pair was valid 0
@@ -229,8 +230,20 @@ virJSONValueObjectCreateVArgs(virJSONValuePtr *obj, va_list args)
             rc = virJSONValueObjectAppendNull(jargs, key);
         }   break;

+        case 'A':
         case 'a': {
             virJSONValuePtr val = va_arg(args, virJSONValuePtr);
+
+            if (!val) {
+                if (type == 'A')
+                    continue;
+
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("argument key '%s' must not have null value"),
+                               key);
+                goto cleanup;
+            }
+
             rc = virJSONValueObjectAppend(jargs, key, val);
         }   break;

-- 
2.1.0

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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]