}
+static int
+virQEMUQAPISchemaTraverseAlternate(virJSONValuePtr cur,
+ struct virQEMUQAPISchemaTraverseContext *ctxt)
+{
+ struct virQEMUQAPISchemaTraverseContext savectxt = *ctxt;
+ virJSONValuePtr members;
+ virJSONValuePtr member;
+ const char *membertype;
+ int rc;
+ size_t i;
+
+ if (!(members = virJSONValueObjectGetArray(cur, "members")))
+ return -2;
+
+ for (i = 0; i < virJSONValueArraySize(members); i++) {
+ if (!(member = virJSONValueArrayGet(members, i)) ||
+ !(membertype = virJSONValueObjectGetString(member, "type")))
+ continue;
+
+ *ctxt = savectxt;
+
+ if ((rc = virQEMUQAPISchemaTraverse(membertype, ctxt)) != 0)
+ return rc;
+ }
+
+ return 0;
+}
+
+
/* The function must return 1 on successful query, 0 if the query was not found
* -1 when a libvirt error is reported, -2 if the schema is invalid and -3 if
* the query component is malformed. */
{ "event", virQEMUQAPISchemaTraverseCommand },
{ "enum", virQEMUQAPISchemaTraverseEnum },
{ "builtin", virQEMUQAPISchemaTraverseBuiltin },
+ { "alternate", virQEMUQAPISchemaTraverseAlternate },
};
* If the name of any (sub)attribute starts with non-alphabetical symbols it
* needs to be prefixed by a single space.
*
- * Array types are automatically flattened to the singular type. Alternate
- * types are currently not supported.
+ * Array types are automatically flattened to the singular type. Alternates are
+ * iterated until first success.
*
* The above types can be chained arbitrarily using slashes to construct any
* path into the schema tree, booleans must be always the last component as they
DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 1, true);
DO_TEST_QAPI_QUERY("enum value", "query-status/ret-type/status/^debug", 1, false);
DO_TEST_QAPI_QUERY("builtin type", "query-qmp-schema/ret-type/name/!string", 1, false);
+ DO_TEST_QAPI_QUERY("alternate variant 1", "blockdev-add/arg-type/+qcow2/backing/!null", 1, false);
+ DO_TEST_QAPI_QUERY("alternate variant 2", "blockdev-add/arg-type/+qcow2/backing/!string", 1, false);
+ DO_TEST_QAPI_QUERY("alternate variant 3", "blockdev-add/arg-type/+qcow2/backing/+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);