render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d76c62
From 28699a44646cf4a754808fb2c815c741343264cd Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <28699a44646cf4a754808fb2c815c741343264cd@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Tue, 4 Feb 2020 15:08:17 +0100
d76c62
Subject: [PATCH] util: json: Introduce virJSONValueArrayConcat
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Add a helper that concatenates the second array into the first.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 3b60a0c0276ae7200b0bff7394e0d1e00706a1dd)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
d76c62
Message-Id: <d7f92bced2f95d7802dd3a823b7c6b966e454a7e.1580824112.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/libvirt_private.syms |  1 +
d76c62
 src/util/virjson.c       | 31 +++++++++++++++++++++++++++++++
d76c62
 src/util/virjson.h       |  2 ++
d76c62
 3 files changed, 34 insertions(+)
d76c62
d76c62
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
d76c62
index afa7d4fcae..bc2858fc00 100644
d76c62
--- a/src/libvirt_private.syms
d76c62
+++ b/src/libvirt_private.syms
d76c62
@@ -2279,6 +2279,7 @@ virISCSIScanTargets;
d76c62
 virJSONStringReformat;
d76c62
 virJSONValueArrayAppend;
d76c62
 virJSONValueArrayAppendString;
d76c62
+virJSONValueArrayConcat;
d76c62
 virJSONValueArrayForeachSteal;
d76c62
 virJSONValueArrayGet;
d76c62
 virJSONValueArraySize;
d76c62
diff --git a/src/util/virjson.c b/src/util/virjson.c
d76c62
index 988a09e956..50993648eb 100644
d76c62
--- a/src/util/virjson.c
d76c62
+++ b/src/util/virjson.c
d76c62
@@ -811,6 +811,37 @@ virJSONValueArrayAppendString(virJSONValuePtr object,
d76c62
 }
d76c62
 
d76c62
 
d76c62
+/**
d76c62
+ * virJSONValueArrayConcat:
d76c62
+ * @a: JSON value array (destination)
d76c62
+ * @c: JSON value array (source)
d76c62
+ *
d76c62
+ * Merges the members of @c array into @a. The values are stolen from @c.
d76c62
+ */
d76c62
+int
d76c62
+virJSONValueArrayConcat(virJSONValuePtr a,
d76c62
+                        virJSONValuePtr c)
d76c62
+{
d76c62
+    size_t i;
d76c62
+
d76c62
+    if (a->type != VIR_JSON_TYPE_ARRAY ||
d76c62
+        c->type != VIR_JSON_TYPE_ARRAY) {
d76c62
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("expecting JSON array"));
d76c62
+        return -1;
d76c62
+    }
d76c62
+
d76c62
+    a->data.array.values = g_renew(virJSONValuePtr, a->data.array.values,
d76c62
+                                   a->data.array.nvalues + c->data.array.nvalues);
d76c62
+
d76c62
+    for (i = 0; i < c->data.array.nvalues; i++)
d76c62
+        a->data.array.values[a->data.array.nvalues++] = g_steal_pointer(&c->data.array.values[i]);
d76c62
+
d76c62
+    c->data.array.nvalues = 0;
d76c62
+
d76c62
+    return 0;
d76c62
+}
d76c62
+
d76c62
+
d76c62
 int
d76c62
 virJSONValueObjectHasKey(virJSONValuePtr object,
d76c62
                          const char *key)
d76c62
diff --git a/src/util/virjson.h b/src/util/virjson.h
d76c62
index 7a6b063b17..0894e91b59 100644
d76c62
--- a/src/util/virjson.h
d76c62
+++ b/src/util/virjson.h
d76c62
@@ -71,6 +71,8 @@ virJSONValuePtr virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap);
d76c62
 
d76c62
 int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr value);
d76c62
 int virJSONValueArrayAppend(virJSONValuePtr object, virJSONValuePtr value);
d76c62
+int virJSONValueArrayConcat(virJSONValuePtr a,
d76c62
+                            virJSONValuePtr c);
d76c62
 
d76c62
 int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key);
d76c62
 virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key);
d76c62
-- 
d76c62
2.25.0
d76c62