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(a)redhat.com>
---
src/qemu/qemu_monitor_json.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index ffa1fb5d57..efcef211ed 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6206,11 +6206,13 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
static int
qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
virJSONValuePtr reply,
+ const char *type,
char ***props)
{
virJSONValuePtr data;
char **proplist = NULL;
size_t n = 0;
+ size_t count = 0;
size_t i;
int ret = -1;
@@ -6228,17 +6230,21 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
virJSONValuePtr child = virJSONValueArrayGet(data, i);
const char *tmp;
+ if (type &&
+ STRNEQ_NULLABLE(virJSONValueObjectGetString(child, "type"), type))
+ continue;
+
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("reply data was missing 'name'"));
goto cleanup;
}
- if (VIR_STRDUP(proplist[i], tmp) < 0)
+ if (VIR_STRDUP(proplist[count++], tmp) < 0)
goto cleanup;
}
- ret = n;
+ ret = count;
*props = proplist;
proplist = NULL;
@@ -6271,7 +6277,7 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
goto cleanup;
}
- ret = qemuMonitorJSONParsePropsList(cmd, reply, props);
+ ret = qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
cleanup:
virJSONValueFree(reply);
virJSONValueFree(cmd);
@@ -6303,7 +6309,7 @@ qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
goto cleanup;
}
- ret = qemuMonitorJSONParsePropsList(cmd, reply, props);
+ ret = qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
cleanup:
virJSONValueFree(reply);
virJSONValueFree(cmd);
--
2.22.0