mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu: qapi: Return schema entry via argument in virQEMUQAPISchemaTraverse
To allow for boolean query string, let's return the queried schema entry via argument rather than a return value. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
eed544e131
commit
9da894dea7
@ -101,10 +101,11 @@ virQEMUQAPISchemaObjectGetType(const char *field,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virJSONValuePtr
|
static int
|
||||||
virQEMUQAPISchemaTraverse(const char *baseName,
|
virQEMUQAPISchemaTraverse(const char *baseName,
|
||||||
char **query,
|
char **query,
|
||||||
virHashTablePtr schema)
|
virHashTablePtr schema,
|
||||||
|
virJSONValuePtr *type)
|
||||||
{
|
{
|
||||||
virJSONValuePtr base;
|
virJSONValuePtr base;
|
||||||
virJSONValuePtr obj;
|
virJSONValuePtr obj;
|
||||||
@ -114,18 +115,20 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!(base = virHashLookup(schema, baseName)))
|
if (!(base = virHashLookup(schema, baseName)))
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
if (!*query)
|
if (!*query) {
|
||||||
return base;
|
*type = base;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
|
if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
/* flatten arrays by default */
|
/* flatten arrays by default */
|
||||||
if (STREQ(metatype, "array")) {
|
if (STREQ(metatype, "array")) {
|
||||||
if (!(baseName = virJSONValueObjectGetString(base, "element-type")))
|
if (!(baseName = virJSONValueObjectGetString(base, "element-type")))
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else if (STREQ(metatype, "object")) {
|
} else if (STREQ(metatype, "object")) {
|
||||||
@ -145,26 +148,26 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
|
|
||||||
if (modifier == '*' &&
|
if (modifier == '*' &&
|
||||||
!virJSONValueObjectHasKey(obj, "default"))
|
!virJSONValueObjectHasKey(obj, "default"))
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
baseName = virQEMUQAPISchemaTypeFromObject(obj);
|
baseName = virQEMUQAPISchemaTypeFromObject(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!baseName)
|
if (!baseName)
|
||||||
return NULL;
|
return 0;
|
||||||
} else if (STREQ(metatype, "command") ||
|
} else if (STREQ(metatype, "command") ||
|
||||||
STREQ(metatype, "event")) {
|
STREQ(metatype, "event")) {
|
||||||
if (!(baseName = virJSONValueObjectGetString(base, *query)))
|
if (!(baseName = virJSONValueObjectGetString(base, *query)))
|
||||||
return NULL;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/* alternates, basic types and enums can't be entered */
|
/* alternates, basic types and enums can't be entered */
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
query++;
|
query++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -219,7 +222,8 @@ virQEMUQAPISchemaPathGet(const char *query,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*entry = virQEMUQAPISchemaTraverse(*elems, elems + 1, schema);
|
if (virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user