]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: json: Introduce virJSONValueObjectAppendStringPrintf
authorPeter Krempa <pkrempa@redhat.com>
Thu, 14 May 2020 06:09:56 +0000 (08:09 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 20 May 2020 07:41:57 +0000 (09:41 +0200)
Add a variant similar to virJSONValueObjectAppendString which also
formats more complex value strings with printf syntax.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
src/libvirt_private.syms
src/util/virjson.c
src/util/virjson.h

index 31813f177fe2ecd7475702ea4687c1cc2aad4b11..1bd02fd8eeb46d9e90f238e8b4f8f7614d13eae0 100644 (file)
@@ -2361,6 +2361,7 @@ virJSONValueObjectAppendNumberLong;
 virJSONValueObjectAppendNumberUint;
 virJSONValueObjectAppendNumberUlong;
 virJSONValueObjectAppendString;
+virJSONValueObjectAppendStringPrintf;
 virJSONValueObjectCreate;
 virJSONValueObjectCreateVArgs;
 virJSONValueObjectDeflatten;
index dc662bf8e90b43a0d1c68c11adff21bb6abb0ba3..6921eccb60681bf1be82b2323b6f4877e0a96085 100644 (file)
@@ -649,6 +649,23 @@ virJSONValueObjectAppendString(virJSONValuePtr object,
 }
 
 
+int
+virJSONValueObjectAppendStringPrintf(virJSONValuePtr object,
+                                     const char *key,
+                                     const char *fmt,
+                                     ...)
+{
+    va_list ap;
+    g_autofree char *str = NULL;
+
+    va_start(ap, fmt);
+    str = g_strdup_vprintf(fmt, ap);
+    va_end(ap);
+
+    return virJSONValueObjectInsertString(object, key, str, false);
+}
+
+
 int
 virJSONValueObjectPrependString(virJSONValuePtr object,
                                 const char *key,
index 0894e91b5927fea71791d5304526d5addc5ff1a3..588c977650f1f3fe9b7d0d1119e1cd8d4400d314 100644 (file)
@@ -127,6 +127,8 @@ int virJSONValueObjectGetBoolean(virJSONValuePtr object, const char *key, bool *
 int virJSONValueObjectIsNull(virJSONValuePtr object, const char *key);
 
 int virJSONValueObjectAppendString(virJSONValuePtr object, const char *key, const char *value);
+int virJSONValueObjectAppendStringPrintf(virJSONValuePtr object, const char *key, const char *fmt, ...)
+    G_GNUC_PRINTF(3, 4);
 int virJSONValueObjectPrependString(virJSONValuePtr object, const char *key, const char *value);
 int virJSONValueObjectAppendNumberInt(virJSONValuePtr object, const char *key, int number);
 int virJSONValueObjectAppendNumberUint(virJSONValuePtr object, const char *key, unsigned int number);