]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: qapi: Split up virQEMUQAPISchemaObjectGetType
authorPeter Krempa <pkrempa@redhat.com>
Wed, 15 Aug 2018 06:39:19 +0000 (08:39 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 24 Aug 2018 13:58:33 +0000 (15:58 +0200)
Split it into a function that returns the whole schema entry so that we
can do additional checks and a helper getting the type string from the
schema entry.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_qapi.c

index fea66833364952ecb58f21748109c7b5dee02a06..1492c0c7578962f280d725e93f1f3d674a952fa0 100644 (file)
@@ -33,24 +33,24 @@ VIR_LOG_INIT("qemu.qemu_qapi");
 
 
 /**
- * virQEMUQAPISchemaObjectGetType:
+ * virQEMUQAPISchemaObjectGet:
  * @field: name of the object containing the requested type
  * @name: name of the requested type
  * @namefield: name of the object property holding @name
+ * @elem: QAPI schema entry JSON object
  *
  * Helper that selects the type of a QMP schema object member or it's variant
- * member. Returns the type string on success or NULL on error.
+ * member. Returns the QMP entry on success or NULL on error.
  */
-static const char *
-virQEMUQAPISchemaObjectGetType(const char *field,
-                               const char *name,
-                               const char *namefield,
-                               virJSONValuePtr elem)
+static virJSONValuePtr
+virQEMUQAPISchemaObjectGet(const char *field,
+                           const char *name,
+                           const char *namefield,
+                           virJSONValuePtr elem)
 {
     virJSONValuePtr arr;
     virJSONValuePtr cur;
     const char *curname;
-    const char *type;
     size_t i;
 
     if (!(arr = virJSONValueObjectGetArray(elem, field)))
@@ -58,18 +58,49 @@ virQEMUQAPISchemaObjectGetType(const char *field,
 
     for (i = 0; i < virJSONValueArraySize(arr); i++) {
         if (!(cur = virJSONValueArrayGet(arr, i)) ||
-            !(curname = virJSONValueObjectGetString(cur, namefield)) ||
-            !(type = virJSONValueObjectGetString(cur, "type")))
+            !(curname = virJSONValueObjectGetString(cur, namefield)))
             continue;
 
         if (STREQ(name, curname))
-            return type;
+            return cur;
     }
 
     return NULL;
 }
 
 
+static const char *
+virQEMUQAPISchemaTypeFromObject(virJSONValuePtr obj)
+{
+    if (!obj)
+        return NULL;
+
+    return virJSONValueObjectGetString(obj, "type");
+}
+
+
+/**
+ * virQEMUQAPISchemaObjectGetType:
+ * @field: name of the object containing the requested type
+ * @name: name of the requested type
+ * @namefield: name of the object property holding @name
+ * @elem: QAPI schema entry JSON object
+ *
+ * Helper that selects the type of a QMP schema object member or it's variant
+ * member. Returns the type string on success or NULL on error.
+ */
+static const char *
+virQEMUQAPISchemaObjectGetType(const char *field,
+                               const char *name,
+                               const char *namefield,
+                               virJSONValuePtr elem)
+{
+    virJSONValuePtr obj = virQEMUQAPISchemaObjectGet(field, name, namefield, elem);
+
+    return virQEMUQAPISchemaTypeFromObject(obj);
+}
+
+
 static virJSONValuePtr
 virQEMUQAPISchemaTraverse(const char *baseName,
                           char **query,