qemu: Add type filter to qemuMonitorJSONParsePropsList
The function converts a list of QOM properties into a NULL-terminated array of property names. The new type parameter may be used to limit the result to properties of a specific type. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
df73078c61
commit
430023e5ee
@ -6206,11 +6206,13 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
|
|||||||
static int
|
static int
|
||||||
qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
|
qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
|
||||||
virJSONValuePtr reply,
|
virJSONValuePtr reply,
|
||||||
|
const char *type,
|
||||||
char ***props)
|
char ***props)
|
||||||
{
|
{
|
||||||
virJSONValuePtr data;
|
virJSONValuePtr data;
|
||||||
char **proplist = NULL;
|
char **proplist = NULL;
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
size_t count = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -6228,17 +6230,21 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
|
|||||||
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
|
|
||||||
|
if (type &&
|
||||||
|
STRNEQ_NULLABLE(virJSONValueObjectGetString(child, "type"), type))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("reply data was missing 'name'"));
|
_("reply data was missing 'name'"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRDUP(proplist[i], tmp) < 0)
|
if (VIR_STRDUP(proplist[count++], tmp) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = n;
|
ret = count;
|
||||||
*props = proplist;
|
*props = proplist;
|
||||||
proplist = NULL;
|
proplist = NULL;
|
||||||
|
|
||||||
@ -6271,7 +6277,7 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemuMonitorJSONParsePropsList(cmd, reply, props);
|
ret = qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
virJSONValueFree(cmd);
|
virJSONValueFree(cmd);
|
||||||
@ -6303,7 +6309,7 @@ qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemuMonitorJSONParsePropsList(cmd, reply, props);
|
ret = qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
virJSONValueFree(cmd);
|
virJSONValueFree(cmd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user