]> xenbits.xensource.com Git - libvirt.git/commitdiff
virjson: Change virJSONValueObjectHasKey() signature
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 28 Jul 2022 10:36:19 +0000 (12:36 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 1 Aug 2022 08:24:34 +0000 (10:24 +0200)
Currently, virJSONValueObjectHasKey() can return one of three
values:

  -1 if passed object type is not VIR_JSON_TYPE_OBJECT,
   0 if the key is not present, and finally
   1 if the key is present.

But, neither of callers is interested in the -1 case. In fact,
some callers call this function treating -1 and 1 cases the same.
Therefore, make the function return just true/false and fix few
callers that explicitly checked for == 1 case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_agent.c
src/qemu/qemu_monitor_json.c
src/util/virjson.c
src/util/virjson.h
tests/testutilsqemuschema.c

index d81f01ba773f75e7f0471afc6b7583b29b635025..0d77a2f90d9ccdf907384bc0843f6ee4534847eb 100644 (file)
@@ -231,12 +231,12 @@ qemuAgentIOProcessLine(qemuAgent *agent,
         return -1;
     }
 
-    if (virJSONValueObjectHasKey(obj, "QMP") == 1) {
+    if (virJSONValueObjectHasKey(obj, "QMP")) {
         return 0;
-    } else if (virJSONValueObjectHasKey(obj, "event") == 1) {
+    } else if (virJSONValueObjectHasKey(obj, "event")) {
         return qemuAgentIOProcessEvent(agent, obj);
-    } else if (virJSONValueObjectHasKey(obj, "error") == 1 ||
-               virJSONValueObjectHasKey(obj, "return") == 1) {
+    } else if (virJSONValueObjectHasKey(obj, "error") ||
+               virJSONValueObjectHasKey(obj, "return")) {
         if (msg) {
             if (msg->sync) {
                 unsigned long long id;
index 941596563a0582e25dffdf66e33f591a07395f28..24691657284d23d2180769a8e52f25646f483de5 100644 (file)
@@ -203,14 +203,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
         return -1;
     }
 
-    if (virJSONValueObjectHasKey(obj, "QMP") == 1) {
+    if (virJSONValueObjectHasKey(obj, "QMP")) {
         return 0;
-    } else if (virJSONValueObjectHasKey(obj, "event") == 1) {
+    } else if (virJSONValueObjectHasKey(obj, "event")) {
         PROBE(QEMU_MONITOR_RECV_EVENT,
               "mon=%p event=%s", mon, line);
         return qemuMonitorJSONIOProcessEvent(mon, obj);
-    } else if (virJSONValueObjectHasKey(obj, "error") == 1 ||
-               virJSONValueObjectHasKey(obj, "return") == 1) {
+    } else if (virJSONValueObjectHasKey(obj, "error") ||
+               virJSONValueObjectHasKey(obj, "return")) {
         PROBE(QEMU_MONITOR_RECV_REPLY,
               "mon=%p reply=%s", mon, line);
         if (msg) {
@@ -270,7 +270,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon,
 
     memset(&msg, 0, sizeof(msg));
 
-    if (virJSONValueObjectHasKey(cmd, "execute") == 1) {
+    if (virJSONValueObjectHasKey(cmd, "execute")) {
         g_autofree char *id = qemuMonitorNextCommandID(mon);
 
         if (virJSONValueObjectAppendString(cmd, "id", id) < 0) {
index 53f8cdff956df1a5b2b6c1813757679ecf4f3dd8..ef59b5deb4b554579d35b637387f16bab9b7d70c 100644 (file)
@@ -798,21 +798,21 @@ virJSONValueArrayConcat(virJSONValue *a,
 }
 
 
-int
+bool
 virJSONValueObjectHasKey(virJSONValue *object,
                          const char *key)
 {
     size_t i;
 
     if (object->type != VIR_JSON_TYPE_OBJECT)
-        return -1;
+        return false;
 
     for (i = 0; i < object->data.object.npairs; i++) {
         if (STREQ(object->data.object.pairs[i].key, key))
-            return 1;
+            return true;
     }
 
-    return 0;
+    return false;
 }
 
 
index aced48a5380fccabb86d6cbe29ff43540bda87a4..ce181dcb820bea23bebd893579ed6576d0306eee 100644 (file)
@@ -88,7 +88,7 @@ int
 virJSONValueArrayConcat(virJSONValue *a,
                         virJSONValue *c);
 
-int
+bool
 virJSONValueObjectHasKey(virJSONValue *object,
                          const char *key);
 virJSONValue *
index 4a0fb8d944fe3e5c6e9ed5a211c61669dfc15cf9..d431e7b3fc1d3974147be54206802ce751cab92b 100644 (file)
@@ -289,7 +289,7 @@ testQEMUSchemaValidateObjectMandatoryMember(size_t pos G_GNUC_UNUSED,
 {
     struct testQEMUSchemaValidateObjectMemberData *data = opaque;
 
-    if (virJSONValueObjectHasKey(item, "default") != 1) {
+    if (!virJSONValueObjectHasKey(item, "default")) {
         virBufferAsprintf(data->ctxt->debug, "ERROR: missing mandatory attribute '%s'\n",
                           NULLSTR(virJSONValueObjectGetString(item, "name")));
         data->missingMandatory = true;