static int
-virQEMUBuildObjectCommandLinePropsInternal(const char *key,
- const virJSONValue *value,
- virBufferPtr buf,
- bool nested)
+virQEMUBuildCommandLineJSONRecurse(const char *key,
+ const virJSONValue *value,
+ virBufferPtr buf,
+ bool nested)
{
virJSONValuePtr elem;
virBitmapPtr bitmap = NULL;
case VIR_JSON_TYPE_ARRAY:
if (nested) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("nested -object property arrays are not supported"));
+ _("nested JSON array to commandline conversion is "
+ "not supported"));
return -1;
}
elem = virJSONValueArrayGet((virJSONValuePtr)value, i);
/* recurse to avoid duplicating code */
- if (virQEMUBuildObjectCommandLinePropsInternal(key, elem, buf,
- true) < 0)
+ if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, true) < 0)
return -1;
}
}
static int
-virQEMUBuildObjectCommandLineProps(const char *key,
+virQEMUBuildCommandLineJSONIterate(const char *key,
const virJSONValue *value,
void *opaque)
{
- return virQEMUBuildObjectCommandLinePropsInternal(key, value, opaque, false);
+ return virQEMUBuildCommandLineJSONRecurse(key, value, opaque, false);
+}
+
+
+/**
+ * virQEMUBuildCommandLineJSON:
+ * @value: json object containing the value
+ * @buf: otuput buffer
+ *
+ * Formats JSON value object into command line parameters suitable for use with
+ * qemu.
+ *
+ * Returns 0 on success -1 on error.
+ */
+int
+virQEMUBuildCommandLineJSON(const virJSONValue *value,
+ virBufferPtr buf)
+{
+ if (virJSONValueObjectForeachKeyValue(value,
+ virQEMUBuildCommandLineJSONIterate,
+ buf) < 0)
+ return -1;
+
+ return 0;
}
virBufferAsprintf(&buf, "%s,id=%s", type, alias);
- if (virJSONValueObjectForeachKeyValue(props,
- virQEMUBuildObjectCommandLineProps,
- &buf) < 0)
+ if (virQEMUBuildCommandLineJSON(props, &buf) < 0)
goto cleanup;
if (virBufferCheckError(&buf) < 0)
} testQemuCommandBuildObjectFromJSONData;
static int
-testQemuCommandBuildObjectFromJSON(const void *opaque)
+testQemuCommandBuildFromJSON(const void *opaque)
{
const testQemuCommandBuildObjectFromJSONData *data = opaque;
virJSONValuePtr val = NULL;
char *expect = NULL;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
char *result = NULL;
int ret = -1;
return -1;
}
- if (virAsprintf(&expect, "testobject,id=testalias%s%s",
- data->expectprops ? "," : "",
- data->expectprops ? data->expectprops : "") < 0)
+ if (data->expectprops &&
+ virAsprintf(&expect, ",%s", data->expectprops) < 0)
return -1;
- result = virQEMUBuildObjectCommandlineFromJSON("testobject",
- "testalias", val);
+ if (virQEMUBuildCommandLineJSON(val, &buf) < 0) {
+ fprintf(stderr,
+ "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n",
+ data->props);
+ goto cleanup;
+ }
+
+ result = virBufferContentAndReset(&buf);
if (STRNEQ_NULLABLE(expect, result)) {
fprintf(stderr, "\nFailed to create object string. "
return EXIT_AM_SKIP;
#endif
- virTestCounterReset("testQemuCommandBuildObjectFromJSON");
+ virTestCounterReset("testQemuCommandBuildFromJSON");
#define DO_TEST_COMMAND_OBJECT_FROM_JSON(PROPS, EXPECT) \
do { \
data1.props = PROPS; \
data1.expectprops = EXPECT; \
if (virTestRun(virTestCounterNext(), \
- testQemuCommandBuildObjectFromJSON, \
+ testQemuCommandBuildFromJSON, \
&data1) < 0) \
ret = -1; \
} while (0)