Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_qapi.c | 88 ++++++++++++++++++++++----------------------
1 file changed, 43 insertions(+), 45 deletions(-)
diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c
index 23cbac4405..2652061f4e 100644
--- a/src/qemu/qemu_qapi.c
+++ b/src/qemu/qemu_qapi.c
@@ -107,68 +107,66 @@ virQEMUQAPISchemaTraverse(const char *baseName,
virHashTablePtr schema,
virJSONValuePtr *type)
{
- virJSONValuePtr base;
+ virJSONValuePtr curtype;
virJSONValuePtr obj;
const char *metatype;
+ const char *querytype = NULL;
const char *querystr;
char modifier;
- while (1) {
- if (!(base = virHashLookup(schema, baseName)))
- return 0;
-
- if (!*query) {
- if (type)
- *type = base;
- return 1;
- }
-
- if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
- return 0;
+ if (!(curtype = virHashLookup(schema, baseName)))
+ return 0;
- /* flatten arrays by default */
- if (STREQ(metatype, "array")) {
- if (!(baseName = virJSONValueObjectGetString(base,
"element-type")))
- return 0;
+ if (!*query) {
+ if (type)
+ *type = curtype;
- continue;
- } else if (STREQ(metatype, "object")) {
- querystr = *query;
- modifier = **query;
+ return 1;
+ }
- if (!c_isalpha(modifier))
- querystr++;
+ if (!(metatype = virJSONValueObjectGetString(curtype, "meta-type")))
+ return 0;
- if (modifier == '+') {
- baseName = virQEMUQAPISchemaObjectGetType("variants",
- querystr,
- "case", base);
- } else {
- obj = virQEMUQAPISchemaObjectGet("members", querystr,
- "name", base);
+ /* flatten arrays by default */
+ if (STREQ(metatype, "array")) {
+ if (!(querytype = virJSONValueObjectGetString(curtype,
"element-type")))
+ return 0;
+ } else if (STREQ(metatype, "object")) {
+ querystr = *query;
+ modifier = **query;
- if (modifier == '*' &&
- !virJSONValueObjectHasKey(obj, "default"))
- return 0;
+ if (!c_isalpha(modifier))
+ querystr++;
- baseName = virQEMUQAPISchemaTypeFromObject(obj);
- }
+ if (modifier == '+') {
+ querytype = virQEMUQAPISchemaObjectGetType("variants",
+ querystr,
+ "case", curtype);
+ } else {
+ obj = virQEMUQAPISchemaObjectGet("members", querystr,
+ "name", curtype);
- if (!baseName)
+ if (modifier == '*' &&
+ !virJSONValueObjectHasKey(obj, "default"))
return 0;
- } else if (STREQ(metatype, "command") ||
- STREQ(metatype, "event")) {
- if (!(baseName = virJSONValueObjectGetString(base, *query)))
- return 0;
- } else {
- /* alternates, basic types and enums can't be entered */
- return 0;
- }
+ querytype = virQEMUQAPISchemaTypeFromObject(obj);
+ }
query++;
+ } else if (STREQ(metatype, "command") ||
+ STREQ(metatype, "event")) {
+ if (!(querytype = virJSONValueObjectGetString(curtype, *query)))
+ return 0;
+ query++;
+ } else {
+ /* alternates, basic types and enums can't be entered */
+ return 0;
}
- return 0;
+ if (!querytype)
+ return 0;
+
+ return virQEMUQAPISchemaTraverse(querytype, query, schema, type);
}
--
2.20.1