]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Introduce qemuMonitorJSONGetReply, a better qemuMonitorJSONCheckReply
authorPeter Krempa <pkrempa@redhat.com>
Thu, 1 Dec 2022 15:18:52 +0000 (16:18 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:18:37 +0000 (16:18 +0100)
Rather than simply checking that the 'return' field is of the expected
type we can directly return it as the caller is very likely going to use
it. Extract the code into the new function and add a wrapper to preserve
old functionality.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index f4e942a32f58d41e92a44d6811c4f613af3dd882..e6cfaaf0e99371e463c30b5a260660b2d2ea444b 100644 (file)
@@ -396,15 +396,15 @@ qemuMonitorJSONCheckError(virJSONValue *cmd,
 }
 
 
-static int
-qemuMonitorJSONCheckReply(virJSONValue *cmd,
-                          virJSONValue *reply,
-                          virJSONType type)
+static virJSONValue *
+qemuMonitorJSONGetReply(virJSONValue *cmd,
+                        virJSONValue *reply,
+                        virJSONType type)
 {
     virJSONValue *data;
 
     if (qemuMonitorJSONCheckError(cmd, reply) < 0)
-        return -1;
+        return NULL;
 
     data = virJSONValueObjectGet(reply, "return");
     if (virJSONValueGetType(data) != type) {
@@ -417,9 +417,21 @@ qemuMonitorJSONCheckReply(virJSONValue *cmd,
                        _("unexpected type returned by QEMU command '%s'"),
                        qemuMonitorJSONCommandName(cmd));
 
-        return -1;
+        return NULL;
     }
 
+    return data;
+}
+
+
+static int
+qemuMonitorJSONCheckReply(virJSONValue *cmd,
+                          virJSONValue *reply,
+                          virJSONType type)
+{
+    if (!qemuMonitorJSONGetReply(cmd, reply, type))
+        return -1;
+
     return 0;
 }