return 0;
if (!*query) {
- *type = base;
- return 0;
+ if (type)
+ *type = base;
+ return 1;
}
if (!(metatype = virJSONValueObjectGetString(base, "meta-type")))
* 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
* 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
{
VIR_AUTOSTRINGLIST elems = NULL;
- *entry = NULL;
+ if (entry)
+ *entry = NULL;
if (!(elems = virStringSplit(query, "/", 0)))
return -1;
return -1;
}
- if (virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry) < 0)
- return -1;
-
- return 0;
+ return virQEMUQAPISchemaTraverse(elems[0], elems + 1, schema, entry);
}
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
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);