mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
qemu: qapi: Modify values returned by virQEMUQAPISchemaPathGet
Return 1 if the schema entry was found optionally returning it rather than depending on the returned object. Some callers don't care which schema object belongs to the query, but rather only want to know whether it exists. Additionally this will allow introducing boolean queries for checking if enum values exist. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
9da894dea7
commit
641c60a17d
@ -118,8 +118,9 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!*query) {
|
if (!*query) {
|
||||||
*type = base;
|
if (type)
|
||||||
return 0;
|
*type = base;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
|
if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
|
||||||
@ -175,7 +176,7 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
* virQEMUQAPISchemaPathGet:
|
* virQEMUQAPISchemaPathGet:
|
||||||
* @query: string specifying the required data type (see below)
|
* @query: string specifying the required data type (see below)
|
||||||
* @schema: hash table containing the schema data
|
* @schema: hash table containing the schema data
|
||||||
* @entry: filled with the located schema object requested by @query
|
* @entry: filled with the located schema object requested by @query (optional)
|
||||||
*
|
*
|
||||||
* Retrieves the requested schema entry specified by @query to @entry. The
|
* Retrieves the requested schema entry specified by @query to @entry. The
|
||||||
* @query parameter has the following syntax which is very closely tied to the
|
* @query parameter has the following syntax which is very closely tied to the
|
||||||
@ -201,8 +202,8 @@ virQEMUQAPISchemaTraverse(const char *baseName,
|
|||||||
* The above types can be chained arbitrarily using slashes to construct any
|
* The above types can be chained arbitrarily using slashes to construct any
|
||||||
* path into the schema tree.
|
* path into the schema tree.
|
||||||
*
|
*
|
||||||
* Returns 0 on success (including if the requested schema was not found) and
|
* Returns 1 if @query was found in @schema filling @entry if non-NULL, 0 if
|
||||||
* fills @entry appropriately. On failure returns -1 and sets an appropriate
|
* @query was not found in @schema and -1 on other errors along with an appropriate
|
||||||
* error message.
|
* error message.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@ -212,7 +213,8 @@ virQEMUQAPISchemaPathGet(const char *query,
|
|||||||
{
|
{
|
||||||
VIR_AUTOSTRINGLIST elems = NULL;
|
VIR_AUTOSTRINGLIST elems = NULL;
|
||||||
|
|
||||||
*entry = NULL;
|
if (entry)
|
||||||
|
*entry = NULL;
|
||||||
|
|
||||||
if (!(elems = virStringSplit(query, "/", 0)))
|
if (!(elems = virStringSplit(query, "/", 0)))
|
||||||
return -1;
|
return -1;
|
||||||
@ -222,10 +224,7 @@ virQEMUQAPISchemaPathGet(const char *query,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry) < 0)
|
return virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry);
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -233,12 +232,7 @@ bool
|
|||||||
virQEMUQAPISchemaPathExists(const char *query,
|
virQEMUQAPISchemaPathExists(const char *query,
|
||||||
virHashTablePtr schema)
|
virHashTablePtr schema)
|
||||||
{
|
{
|
||||||
virJSONValuePtr entry;
|
return virQEMUQAPISchemaPathGet(query, schema, NULL) == 1;
|
||||||
|
|
||||||
if (virQEMUQAPISchemaPathGet(query, schema, &entry))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return !!entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -3085,12 +3085,12 @@ mymain(void)
|
|||||||
ret = -1; \
|
ret = -1; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
DO_TEST_QAPI_QUERY("command", "blockdev-add", 0, true);
|
DO_TEST_QAPI_QUERY("command", "blockdev-add", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 0, true);
|
DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 0, true);
|
DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 0, true);
|
DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 0, true);
|
DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 1, true);
|
||||||
DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 0, true);
|
DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 1, true);
|
||||||
|
|
||||||
DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
|
DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
|
||||||
DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
|
DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user