[PATCH 1/5] virQEMUQAPISchemaTraverseObject: Consider features also on current members

Peter Krempa via Devel posted 5 patches 2 days, 3 hours ago
[PATCH 1/5] virQEMUQAPISchemaTraverseObject: Consider features also on current members
Posted by Peter Krempa via Devel 2 days, 3 hours ago
From: Peter Krempa <pkrempa@redhat.com>

The 'features' to check can be also on the entry in the 'members' array
of an object type. We wouldn't check that because we'd only check if the
type of the member has any features.

While the query language is flawed in the way that the user can't
specify if they want to check features of the member rather than the
type we work it around by checking both and returing if either of them
matches.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_qapi.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index a2fef55019..e2b1904bf5 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -107,6 +107,24 @@ virQEMUQAPISchemaTraverseContextNextQuery(struct virQEMUQAPISchemaTraverseContex
 }


+/**
+ * virQEMUQAPISchemaTraverseContextHasNextQueryFeatures:
+ * @ctxt: query context
+ *
+ * If the next query is a feature query returns it without advancing the query
+ * state in the context.
+ */
+static const char *
+virQEMUQAPISchemaTraverseContextHasNextQueryFeatures(struct virQEMUQAPISchemaTraverseContext *ctxt)
+{
+    if (!ctxt->queries[0] ||
+        *ctxt->queries[0] != '$')
+        return NULL;
+
+    return ctxt->queries[0] + 1;
+}
+
+
 static bool
 virQEMUQAPISchemaTraverseContextHasNextQuery(struct virQEMUQAPISchemaTraverseContext *ctxt)
 {
@@ -178,11 +196,19 @@ virQEMUQAPISchemaTraverseObject(virJSONValue *cur,
     if (modifier == '+') {
         obj = virQEMUQAPISchemaObjectGet("variants", query, "case", cur);
     } else {
+        const char *featuresquery;
+
         obj = virQEMUQAPISchemaObjectGet("members", query, "name", cur);

         if (modifier == '*' && obj &&
             !virJSONValueObjectHasKey(obj, "default"))
             return 0;
+
+        /* checks if the member itself has features, because if not we also
+         * need to check the subsequent object */
+        if ((featuresquery = virQEMUQAPISchemaTraverseContextHasNextQueryFeatures(ctxt)) &&
+            virQEMUQAPISchemaTraverseHasObjectFeature(featuresquery, obj) == 1)
+            return 1;
     }

     if (!obj)
-- 
2.53.0