74 lines
2.6 KiB
Diff
74 lines
2.6 KiB
Diff
From 0924902c3814677f9f328f521a95d4a79635d81a Mon Sep 17 00:00:00 2001
|
|
From: Peter Krempa <pkrempa@redhat.com>
|
|
Date: Thu, 14 May 2020 08:09:56 +0200
|
|
Subject: [PATCH 04/18] util: json: Introduce
|
|
virJSONValueObjectAppendStringPrintf
|
|
|
|
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 | 1 +
|
|
src/util/virjson.c | 17 +++++++++++++++++
|
|
src/util/virjson.h | 2 ++
|
|
3 files changed, 20 insertions(+)
|
|
|
|
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
index 84f3bd57ca..726e7a21f9 100644
|
|
--- a/src/libvirt_private.syms
|
|
+++ b/src/libvirt_private.syms
|
|
@@ -2349,6 +2349,7 @@ virJSONValueObjectAppendNumberLong;
|
|
virJSONValueObjectAppendNumberUint;
|
|
virJSONValueObjectAppendNumberUlong;
|
|
virJSONValueObjectAppendString;
|
|
+virJSONValueObjectAppendStringPrintf;
|
|
virJSONValueObjectCreate;
|
|
virJSONValueObjectCreateVArgs;
|
|
virJSONValueObjectDeflatten;
|
|
diff --git a/src/util/virjson.c b/src/util/virjson.c
|
|
index dc662bf8e9..6921eccb60 100644
|
|
--- a/src/util/virjson.c
|
|
+++ b/src/util/virjson.c
|
|
@@ -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,
|
|
diff --git a/src/util/virjson.h b/src/util/virjson.h
|
|
index 0894e91b59..588c977650 100644
|
|
--- a/src/util/virjson.h
|
|
+++ b/src/util/virjson.h
|
|
@@ -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);
|
|
--
|
|
2.23.0.windows.1
|
|
|