From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virjson.c | 30 ++++++++++++++++++++++++++++++
src/util/virjson.h | 1 +
3 files changed, 32 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 79a23f34cb..0f8447cfbb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2408,6 +2408,7 @@ virJSONValueObjectGetNumberUint;
virJSONValueObjectGetNumberUlong;
virJSONValueObjectGetObject;
virJSONValueObjectGetString;
+virJSONValueObjectGetStringArray;
virJSONValueObjectGetValue;
virJSONValueObjectHasKey;
virJSONValueObjectIsNull;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 3fa9a9ca24..05c4804410 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1463,6 +1463,36 @@ virJSONValueObjectIsNull(virJSONValuePtr object,
return virJSONValueIsNull(val);
}
+char **
+virJSONValueObjectGetStringArray(virJSONValuePtr object, const char *key)
+{
+ g_auto(GStrv) ret = NULL;
+ virJSONValuePtr data;
+ size_t n;
+ size_t i;
+
+ data = virJSONValueObjectGetArray(object, key);
+ if (!data)
+ return NULL;
+
+ n = virJSONValueArraySize(data);
+ ret = g_new0(char *, n + 1);
+ for (i = 0; i < n; i++) {
+ virJSONValuePtr child = virJSONValueArrayGet(data, i);
+ const char *tmp;
+
+ if (!(tmp = virJSONValueGetString(child))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("%s array element does not contain a string"),
+ key);
+ return NULL;
+ }
+
+ ret[i] = g_strdup(tmp);
+ }
+
+ return g_steal_pointer(&ret);
+}
/**
* virJSONValueObjectForeachKeyValue:
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 588c977650..4dc7ed1a2d 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -117,6 +117,7 @@ virJSONValuePtr virJSONValueObjectStealObject(virJSONValuePtr object,
const char *key);
const char *virJSONValueObjectGetString(virJSONValuePtr object, const char *key);
+char **virJSONValueObjectGetStringArray(virJSONValuePtr object, const char *key);
const char *virJSONValueObjectGetStringOrNumber(virJSONValuePtr object, const char
*key);
int virJSONValueObjectGetNumberInt(virJSONValuePtr object, const char *key, int *value);
int virJSONValueObjectGetNumberUint(virJSONValuePtr object, const char *key, unsigned int
*value);
--
2.29.0