mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemu: qapi: Convert arguments of QAPI traversal helpers to a struct
Create a context data type for the QAPI path rather than passing an increasing number of arguments. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
115e677a52
commit
06283debe3
@ -69,21 +69,24 @@ virQEMUQAPISchemaObjectGet(const char *field,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct virQEMUQAPISchemaTraverseContext {
|
||||||
|
virHashTablePtr schema;
|
||||||
|
char **query;
|
||||||
|
virJSONValuePtr returnType;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUQAPISchemaTraverse(const char *baseName,
|
virQEMUQAPISchemaTraverse(const char *baseName,
|
||||||
char **query,
|
struct virQEMUQAPISchemaTraverseContext *ctxt);
|
||||||
virHashTablePtr schema,
|
|
||||||
virJSONValuePtr *type);
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUQAPISchemaTraverseObject(virJSONValuePtr cur,
|
virQEMUQAPISchemaTraverseObject(virJSONValuePtr cur,
|
||||||
char **query,
|
struct virQEMUQAPISchemaTraverseContext *ctxt)
|
||||||
virHashTablePtr schema,
|
|
||||||
virJSONValuePtr *type)
|
|
||||||
{
|
{
|
||||||
virJSONValuePtr obj;
|
virJSONValuePtr obj;
|
||||||
const char *querystr = *query;
|
const char *querystr = *ctxt->query;
|
||||||
char modifier = *querystr;
|
char modifier = *querystr;
|
||||||
|
|
||||||
if (!c_isalpha(modifier))
|
if (!c_isalpha(modifier))
|
||||||
@ -102,16 +105,15 @@ virQEMUQAPISchemaTraverseObject(virJSONValuePtr cur,
|
|||||||
if (!obj)
|
if (!obj)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return virQEMUQAPISchemaTraverse(virJSONValueObjectGetString(obj, "type"),
|
ctxt->query++;
|
||||||
query + 1, schema, type);
|
|
||||||
|
return virQEMUQAPISchemaTraverse(virJSONValueObjectGetString(obj, "type"), ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUQAPISchemaTraverseArray(virJSONValuePtr cur,
|
virQEMUQAPISchemaTraverseArray(virJSONValuePtr cur,
|
||||||
char **query,
|
struct virQEMUQAPISchemaTraverseContext *ctxt)
|
||||||
virHashTablePtr schema,
|
|
||||||
virJSONValuePtr *type)
|
|
||||||
{
|
{
|
||||||
const char *querytype;
|
const char *querytype;
|
||||||
|
|
||||||
@ -119,41 +121,37 @@ virQEMUQAPISchemaTraverseArray(virJSONValuePtr cur,
|
|||||||
if (!(querytype = virJSONValueObjectGetString(cur, "element-type")))
|
if (!(querytype = virJSONValueObjectGetString(cur, "element-type")))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return virQEMUQAPISchemaTraverse(querytype, query, schema, type);
|
return virQEMUQAPISchemaTraverse(querytype, ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUQAPISchemaTraverseCommand(virJSONValuePtr cur,
|
virQEMUQAPISchemaTraverseCommand(virJSONValuePtr cur,
|
||||||
char **query,
|
struct virQEMUQAPISchemaTraverseContext *ctxt)
|
||||||
virHashTablePtr schema,
|
|
||||||
virJSONValuePtr *type)
|
|
||||||
{
|
{
|
||||||
const char *querytype;
|
const char *querytype;
|
||||||
|
|
||||||
if (!(querytype = virJSONValueObjectGetString(cur, *query)))
|
if (!(querytype = virJSONValueObjectGetString(cur, *ctxt->query)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return virQEMUQAPISchemaTraverse(querytype, query + 1, schema, type);
|
ctxt->query++;
|
||||||
|
|
||||||
|
return virQEMUQAPISchemaTraverse(querytype, ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUQAPISchemaTraverse(const char *baseName,
|
virQEMUQAPISchemaTraverse(const char *baseName,
|
||||||
char **query,
|
struct virQEMUQAPISchemaTraverseContext *ctxt)
|
||||||
virHashTablePtr schema,
|
|
||||||
virJSONValuePtr *type)
|
|
||||||
{
|
{
|
||||||
virJSONValuePtr cur;
|
virJSONValuePtr cur;
|
||||||
const char *metatype;
|
const char *metatype;
|
||||||
|
|
||||||
if (!(cur = virHashLookup(schema, baseName)))
|
if (!(cur = virHashLookup(ctxt->schema, baseName)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!*query) {
|
if (!ctxt->query[0]) {
|
||||||
if (type)
|
ctxt->returnType = cur;
|
||||||
*type = cur;
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,12 +159,12 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (STREQ(metatype, "array")) {
|
if (STREQ(metatype, "array")) {
|
||||||
return virQEMUQAPISchemaTraverseArray(cur, query, schema, type);
|
return virQEMUQAPISchemaTraverseArray(cur, ctxt);
|
||||||
} else if (STREQ(metatype, "object")) {
|
} else if (STREQ(metatype, "object")) {
|
||||||
return virQEMUQAPISchemaTraverseObject(cur, query, schema, type);
|
return virQEMUQAPISchemaTraverseObject(cur, ctxt);
|
||||||
} else if (STREQ(metatype, "command") ||
|
} else if (STREQ(metatype, "command") ||
|
||||||
STREQ(metatype, "event")) {
|
STREQ(metatype, "event")) {
|
||||||
return virQEMUQAPISchemaTraverseCommand(cur, query, schema, type);
|
return virQEMUQAPISchemaTraverseCommand(cur, ctxt);
|
||||||
} else {
|
} else {
|
||||||
/* alternates, basic types and enums can't be entered */
|
/* alternates, basic types and enums can't be entered */
|
||||||
return 0;
|
return 0;
|
||||||
@ -216,6 +214,8 @@ virQEMUQAPISchemaPathGet(const char *query,
|
|||||||
virJSONValuePtr *entry)
|
virJSONValuePtr *entry)
|
||||||
{
|
{
|
||||||
VIR_AUTOSTRINGLIST elems = NULL;
|
VIR_AUTOSTRINGLIST elems = NULL;
|
||||||
|
struct virQEMUQAPISchemaTraverseContext ctxt = { .schema = schema };
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (entry)
|
if (entry)
|
||||||
*entry = NULL;
|
*entry = NULL;
|
||||||
@ -228,7 +228,14 @@ virQEMUQAPISchemaPathGet(const char *query,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry);
|
ctxt.query = elems + 1;
|
||||||
|
|
||||||
|
rc = virQEMUQAPISchemaTraverse(elems[0], &ctxt);
|
||||||
|
|
||||||
|
if (entry)
|
||||||
|
*entry = ctxt.returnType;
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user