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