]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: json: Extract deflattening of keys into a separate function
authorPeter Krempa <pkrempa@redhat.com>
Thu, 19 Mar 2020 17:11:48 +0000 (18:11 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Mar 2020 08:47:16 +0000 (09:47 +0100)
Extract the code so that there's a clean separation once we'll want do
do other steps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virjson.c

index f308927fa0158060c9aaf9eef4917ba216a24129..65d6521789fcee0d92e66e9122df724575e831b0 100644 (file)
@@ -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);
 }