1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-21 10:50:24 +03:00

qemu: use virJSONValueObjectGetStringArray

There might be more potential users around, I haven't looked thoroughly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Han Han <hhan@redhat.com>
This commit is contained in:
Marc-André Lureau 2020-11-20 22:09:44 +04:00 committed by Michal Privoznik
parent b3dad96972
commit 3169db81f6

@ -7533,10 +7533,6 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
char **list = NULL;
size_t n = 0;
size_t i;
*array = NULL;
@ -7554,32 +7550,12 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
goto cleanup;
data = virJSONValueObjectGetArray(reply, "return");
n = virJSONValueArraySize(data);
if (!(*array = virJSONValueObjectGetStringArray(reply, "return")))
goto cleanup;
/* null-terminated list */
list = g_new0(char *, n + 1);
for (i = 0; i < n; i++) {
virJSONValuePtr child = virJSONValueArrayGet(data, i);
const char *tmp;
if (!(tmp = virJSONValueGetString(child))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s array element does not contain data"),
qmpCmd);
goto cleanup;
}
list[i] = g_strdup(tmp);
}
ret = n;
*array = list;
list = NULL;
ret = g_strv_length(*array);
cleanup:
g_strfreev(list);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;