]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virjson: add convenience wrapper for appending string to array
authorEric Blake <eblake@redhat.com>
Fri, 25 Jan 2019 03:32:55 +0000 (21:32 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 25 Jan 2019 15:21:24 +0000 (09:21 -0600)
Upcoming patches need an array of strings for use in QMP
block-dirty-bitmap-merge.  A convenience wrapper cuts down
on the verbosity of creating the array, similar to the
existing virJSONValueObjectAppendString().

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virjson.c
src/util/virjson.h

index 89b8ca3b4f23bfd5f42ade31539cd2e77aadf19f..c1f619f514482258c38faf2b42728bec25fcfd4a 100644 (file)
@@ -2092,6 +2092,7 @@ virISCSIScanTargets;
 # util/virjson.h
 virJSONStringReformat;
 virJSONValueArrayAppend;
+virJSONValueArrayAppendString;
 virJSONValueArrayForeachSteal;
 virJSONValueArrayGet;
 virJSONValueArraySize;
index a028a0813a6471daa401a11ab6c2399814bc0feb..d5d66f879f6e1552ce62a79ad6553ee1bab9bff6 100644 (file)
@@ -795,6 +795,21 @@ virJSONValueArrayAppend(virJSONValuePtr array,
 }
 
 
+int
+virJSONValueArrayAppendString(virJSONValuePtr object,
+                              const char *value)
+{
+    virJSONValuePtr jvalue = virJSONValueNewString(value);
+    if (!jvalue)
+        return -1;
+    if (virJSONValueArrayAppend(object, jvalue) < 0) {
+        virJSONValueFree(jvalue);
+        return -1;
+    }
+    return 0;
+}
+
+
 int
 virJSONValueObjectHasKey(virJSONValuePtr object,
                          const char *key)
index a6768d904c76e3e5583cb38d16d882328394a724..d815e60de931bd26d209df4a1b374da87d2f422f 100644 (file)
@@ -138,6 +138,8 @@ int virJSONValueObjectRemoveKey(virJSONValuePtr object, const char *key,
                                 virJSONValuePtr *value)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+int virJSONValueArrayAppendString(virJSONValuePtr object, const char *value);
+
 virJSONValuePtr virJSONValueFromString(const char *jsonstring);
 char *virJSONValueToString(virJSONValuePtr object,
                            bool pretty);