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

[libvirt] [PATCH 2/2] virjson: add convenience wrapper for appending string to array



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>
---
 src/util/virjson.h       |  2 ++
 src/libvirt_private.syms |  1 +
 src/util/virjson.c       | 15 +++++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/src/util/virjson.h b/src/util/virjson.h
index a6768d904c..d815e60de9 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -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);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 89b8ca3b4f..c1f619f514 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2092,6 +2092,7 @@ virISCSIScanTargets;
 # util/virjson.h
 virJSONStringReformat;
 virJSONValueArrayAppend;
+virJSONValueArrayAppendString;
 virJSONValueArrayForeachSteal;
 virJSONValueArrayGet;
 virJSONValueArraySize;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index a028a0813a..d5d66f879f 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -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)
-- 
2.20.1


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