qemu: qapi: Convert virQEMUQAPISchemaTraverse to recursive lookup

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-04-09 15:11:22 +02:00
parent 641c60a17d
commit 5ded7590d1

View File

@ -107,68 +107,66 @@ virQEMUQAPISchemaTraverse(const char *baseName,
virHashTablePtr schema, virHashTablePtr schema,
virJSONValuePtr *type) virJSONValuePtr *type)
{ {
virJSONValuePtr base; virJSONValuePtr curtype;
virJSONValuePtr obj; virJSONValuePtr obj;
const char *metatype; const char *metatype;
const char *querytype = NULL;
const char *querystr; const char *querystr;
char modifier; char modifier;
while (1) { if (!(curtype = virHashLookup(schema, baseName)))
if (!(base = virHashLookup(schema, baseName))) return 0;
return 0;
if (!*query) { if (!*query) {
if (type) if (type)
*type = base; *type = curtype;
return 1;
}
if (!(metatype = virJSONValueObjectGetString(base, "meta-type"))) return 1;
return 0;
/* flatten arrays by default */
if (STREQ(metatype, "array")) {
if (!(baseName = virJSONValueObjectGetString(base, "element-type")))
return 0;
continue;
} else if (STREQ(metatype, "object")) {
querystr = *query;
modifier = **query;
if (!c_isalpha(modifier))
querystr++;
if (modifier == '+') {
baseName = virQEMUQAPISchemaObjectGetType("variants",
querystr,
"case", base);
} else {
obj = virQEMUQAPISchemaObjectGet("members", querystr,
"name", base);
if (modifier == '*' &&
!virJSONValueObjectHasKey(obj, "default"))
return 0;
baseName = virQEMUQAPISchemaTypeFromObject(obj);
}
if (!baseName)
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;
}
query++;
} }
return 0; if (!(metatype = virJSONValueObjectGetString(curtype, "meta-type")))
return 0;
/* 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 (!c_isalpha(modifier))
querystr++;
if (modifier == '+') {
querytype = virQEMUQAPISchemaObjectGetType("variants",
querystr,
"case", curtype);
} else {
obj = virQEMUQAPISchemaObjectGet("members", querystr,
"name", curtype);
if (modifier == '*' &&
!virJSONValueObjectHasKey(obj, "default"))
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;
}
if (!querytype)
return 0;
return virQEMUQAPISchemaTraverse(querytype, query, schema, type);
} }