const char *prefix;
virBufferPtr buf;
const char *skipKey;
+ bool onOff;
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc;
};
virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
+ bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc,
bool nested);
virQEMUBuildCommandLineJSONArrayBitmap(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey G_GNUC_UNUSED)
+ const char *skipKey G_GNUC_UNUSED,
+ bool onOff G_GNUC_UNUSED)
{
ssize_t pos = -1;
ssize_t end;
virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
virJSONValuePtr array,
virBufferPtr buf,
- const char *skipKey)
+ const char *skipKey,
+ bool onOff)
{
virJSONValuePtr member;
size_t i;
prefix = g_strdup_printf("%s.%zu", key, i);
- if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey,
+ if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey, onOff,
virQEMUBuildCommandLineJSONArrayNumbered,
true) < 0)
return 0;
tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
- data->skipKey,
+ data->skipKey, data->onOff,
data->arrayFunc, false);
} else {
return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
- data->skipKey,
+ data->skipKey, data->onOff,
data->arrayFunc, false);
}
}
virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
+ bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc,
bool nested)
{
- struct virQEMUCommandLineJSONIteratorData data = { key, buf, skipKey, arrayFunc };
+ struct virQEMUCommandLineJSONIteratorData data = { key, buf, skipKey, onOff, arrayFunc };
virJSONType type = virJSONValueGetType(value);
virJSONValuePtr elem;
bool tmp;
case VIR_JSON_TYPE_BOOLEAN:
virJSONValueGetBoolean(value, &tmp);
- if (tmp)
- virBufferAsprintf(buf, "%s=yes,", key);
- else
- virBufferAsprintf(buf, "%s=no,", key);
+ if (onOff) {
+ if (tmp)
+ virBufferAsprintf(buf, "%s=on,", key);
+ else
+ virBufferAsprintf(buf, "%s=off,", key);
+ } else {
+ if (tmp)
+ virBufferAsprintf(buf, "%s=yes,", key);
+ else
+ virBufferAsprintf(buf, "%s=no,", key);
+ }
break;
return -1;
}
- if (!arrayFunc || arrayFunc(key, value, buf, skipKey) < 0) {
+ if (!arrayFunc || arrayFunc(key, value, buf, skipKey, onOff) < 0) {
/* fallback, treat the array as a non-bitmap, adding the key
* for each member */
for (i = 0; i < virJSONValueArraySize(value); i++) {
/* recurse to avoid duplicating code */
if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, skipKey,
- arrayFunc, true) < 0)
+ onOff, arrayFunc, true) < 0)
return -1;
}
}
* @value: json object containing the value
* @buf: otuput buffer
* @skipKey: name of key that will be handled separately by caller
+ * @onOff: Use 'on' and 'off' for boolean values rather than 'yes' and 'no'
* @arrayFunc: array formatter function to allow for different syntax
*
* Formats JSON value object into command line parameters suitable for use with
virQEMUBuildCommandLineJSON(virJSONValuePtr value,
virBufferPtr buf,
const char *skipKey,
+ bool onOff,
virQEMUBuildCommandLineJSONArrayFormatFunc array)
{
- if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, array, false) < 0)
+ if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, onOff, array, false) < 0)
return -1;
virBufferTrim(buf, ",");
if (props) {
virBufferAddLit(buf, ",");
- if (virQEMUBuildCommandLineJSON(props, buf, NULL,
+ if (virQEMUBuildCommandLineJSON(props, buf, NULL, false,
virQEMUBuildCommandLineJSONArrayBitmap) < 0)
return -1;
}
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *ret = NULL;
- if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL,
+ if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, false,
virQEMUBuildCommandLineJSONArrayNumbered) < 0)
goto cleanup;