[PATCH 3/6] util: json: Extract deflattening of keys into a separate function

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

 



Extract the code so that there's a clean separation once we'll want do
do other steps.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virjson.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index f308927fa0..65d6521789 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -2049,6 +2049,10 @@ virJSONStringReformat(const char *jsonstr,
 }


+static virJSONValuePtr
+virJSONValueObjectDeflattenKeys(virJSONValuePtr json);
+
+
 static int
 virJSONValueObjectDeflattenWorker(const char *key,
                                   virJSONValuePtr value,
@@ -2064,7 +2068,7 @@ virJSONValueObjectDeflattenWorker(const char *key,
     if (!strchr(key, '.')) {

         if (virJSONValueIsObject(value))
-            newval = virJSONValueObjectDeflatten(value);
+            newval = virJSONValueObjectDeflattenKeys(value);
         else
             newval = virJSONValueCopy(value);

@@ -2113,6 +2117,20 @@ virJSONValueObjectDeflattenWorker(const char *key,
 }


+static virJSONValuePtr
+virJSONValueObjectDeflattenKeys(virJSONValuePtr json)
+{
+    g_autoptr(virJSONValue) deflattened = virJSONValueNewObject();
+
+    if (virJSONValueObjectForeachKeyValue(json,
+                                          virJSONValueObjectDeflattenWorker,
+                                          deflattened) < 0)
+        return NULL;
+
+    return g_steal_pointer(&deflattened);
+}
+
+
 /**
  * virJSONValueObjectDeflatten:
  *
@@ -2128,12 +2146,5 @@ virJSONValueObjectDeflattenWorker(const char *key,
 virJSONValuePtr
 virJSONValueObjectDeflatten(virJSONValuePtr json)
 {
-    g_autoptr(virJSONValue) deflattened = virJSONValueNewObject();
-
-    if (virJSONValueObjectForeachKeyValue(json,
-                                          virJSONValueObjectDeflattenWorker,
-                                          deflattened) < 0)
-        return NULL;
-
-    return g_steal_pointer(&deflattened);
+    return virJSONValueObjectDeflattenKeys(json);
 }
-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux