提交 641c60a1 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 9da894de
......@@ -118,8 +118,9 @@ virQEMUQAPISchemaTraverse(const char *baseName,
return 0;
if (!*query) {
*type = base;
return 0;
if (type)
*type = base;
return 1;
}
if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
......@@ -175,7 +176,7 @@ virQEMUQAPISchemaTraverse(const char *baseName,
* virQEMUQAPISchemaPathGet:
* @query: string specifying the required data type (see below)
* @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
* @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
* path into the schema tree.
*
* Returns 0 on success (including if the requested schema was not found) and
* fills @entry appropriately. On failure returns -1 and sets an appropriate
* Returns 1 if @query was found in @schema filling @entry if non-NULL, 0 if
* @query was not found in @schema and -1 on other errors along with an appropriate
* error message.
*/
int
......@@ -212,7 +213,8 @@ virQEMUQAPISchemaPathGet(const char *query,
{
VIR_AUTOSTRINGLIST elems = NULL;
*entry = NULL;
if (entry)
*entry = NULL;
if (!(elems = virStringSplit(query, "/", 0)))
return -1;
......@@ -222,10 +224,7 @@ virQEMUQAPISchemaPathGet(const char *query,
return -1;
}
if (virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry) < 0)
return -1;
return 0;
return virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry);
}
......@@ -233,12 +232,7 @@ bool
virQEMUQAPISchemaPathExists(const char *query,
virHashTablePtr schema)
{
virJSONValuePtr entry;
if (virQEMUQAPISchemaPathGet(query, schema, &entry))
return false;
return !!entry;
return virQEMUQAPISchemaPathGet(query, schema, NULL) == 1;
}
static int
......
......@@ -3085,12 +3085,12 @@ mymain(void)
ret = -1; \
} while (0)
DO_TEST_QAPI_QUERY("command", "blockdev-add", 0, true);
DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 0, true);
DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 0, true);
DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 0, true);
DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 0, true);
DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 0, true);
DO_TEST_QAPI_QUERY("command", "blockdev-add", 1, true);
DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 1, true);
DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 1, true);
DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 1, 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", 1, true);
DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册