From nobody Thu May 2 23:42:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1659015225; cv=none; d=zohomail.com; s=zohoarc; b=C42MEkfHE8cMCGz1fqz0UyK7zBoVO99JerfUZgv/vywsdLEEUbNZiHqIovJnK79B7zjEW/SWtrq/u2/XM1WQ1k/+Fy265Esleks5H3qx23quVdiWKcmnuw4iTLCJYbtdcXHWNTqU5PpRs56zDKapK2a6CsYqAg4X4VdHoXwFtJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659015225; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=RXi16Zq6YfcIS78GSAXP+9KMglNpKD8zSvXOcNNTmJQ=; b=aspRYX0yAQ4vGe/6U/4loRxaOH+iNWhalDkjLme8/tffzR/HuAH5RdVKmZ8wsfEEF123cjuY0oXXimrXWpcxN7czUq79mWiAQbThsVuocUyQ3OXK98y0t+UqEfKHSOYyqiYhDOCKJqfh/dgdZT3LS4n2Fyu+MWmEtJFFqZIQ2LE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1659015225841682.2015907565277; Thu, 28 Jul 2022 06:33:45 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-gvKljvhSOcyGOUEtV9dNtA-1; Thu, 28 Jul 2022 09:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E0678032F0; Thu, 28 Jul 2022 13:33:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 698571410F3C; Thu, 28 Jul 2022 13:33:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 36C671945DA7; Thu, 28 Jul 2022 13:33:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4112C1945D85 for ; Thu, 28 Jul 2022 13:33:36 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 22B0B400DFD7; Thu, 28 Jul 2022 13:33:36 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1887404C6C9 for ; Thu, 28 Jul 2022 13:33:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659015224; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RXi16Zq6YfcIS78GSAXP+9KMglNpKD8zSvXOcNNTmJQ=; b=fjmaJ81WVD+OUSGcUVg4bCMLcfhR6iECPkvhcC4i+4e7pXaZ83NepT1TcBkAlE6U81Ag7K PaChYNjtxF5fGUmkKl6+o+j0PO/bJCD3BnUg9eiIgC2PS0ehI/gEb9ylQAZ/0YRnjDAR+7 wuU1Zi+B5VLd2cqiUULTcLuuIaTn3Qw= X-MC-Unique: gvKljvhSOcyGOUEtV9dNtA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virjson: Change virJSONValueObjectHasKey() signature Date: Thu, 28 Jul 2022 15:33:33 +0200 Message-Id: <79193fc94035ccd84ae6848cfedc37fe578eecd3.1659015213.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659015228176100001 Content-Type: text/plain; charset="utf-8"; x-default="true" 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 =3D=3D 1 case. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_agent.c | 8 ++++---- src/qemu/qemu_monitor_json.c | 10 +++++----- src/util/virjson.c | 8 ++++---- src/util/virjson.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index d81f01ba77..0d77a2f90d 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -231,12 +231,12 @@ qemuAgentIOProcessLine(qemuAgent *agent, return -1; } =20 - if (virJSONValueObjectHasKey(obj, "QMP") =3D=3D 1) { + if (virJSONValueObjectHasKey(obj, "QMP")) { return 0; - } else if (virJSONValueObjectHasKey(obj, "event") =3D=3D 1) { + } else if (virJSONValueObjectHasKey(obj, "event")) { return qemuAgentIOProcessEvent(agent, obj); - } else if (virJSONValueObjectHasKey(obj, "error") =3D=3D 1 || - virJSONValueObjectHasKey(obj, "return") =3D=3D 1) { + } else if (virJSONValueObjectHasKey(obj, "error") || + virJSONValueObjectHasKey(obj, "return")) { if (msg) { if (msg->sync) { unsigned long long id; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 941596563a..2469165728 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -203,14 +203,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, return -1; } =20 - if (virJSONValueObjectHasKey(obj, "QMP") =3D=3D 1) { + if (virJSONValueObjectHasKey(obj, "QMP")) { return 0; - } else if (virJSONValueObjectHasKey(obj, "event") =3D=3D 1) { + } else if (virJSONValueObjectHasKey(obj, "event")) { PROBE(QEMU_MONITOR_RECV_EVENT, "mon=3D%p event=3D%s", mon, line); return qemuMonitorJSONIOProcessEvent(mon, obj); - } else if (virJSONValueObjectHasKey(obj, "error") =3D=3D 1 || - virJSONValueObjectHasKey(obj, "return") =3D=3D 1) { + } else if (virJSONValueObjectHasKey(obj, "error") || + virJSONValueObjectHasKey(obj, "return")) { PROBE(QEMU_MONITOR_RECV_REPLY, "mon=3D%p reply=3D%s", mon, line); if (msg) { @@ -270,7 +270,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, =20 memset(&msg, 0, sizeof(msg)); =20 - if (virJSONValueObjectHasKey(cmd, "execute") =3D=3D 1) { + if (virJSONValueObjectHasKey(cmd, "execute")) { g_autofree char *id =3D qemuMonitorNextCommandID(mon); =20 if (virJSONValueObjectAppendString(cmd, "id", id) < 0) { diff --git a/src/util/virjson.c b/src/util/virjson.c index 53f8cdff95..ef59b5deb4 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -798,21 +798,21 @@ virJSONValueArrayConcat(virJSONValue *a, } =20 =20 -int +bool virJSONValueObjectHasKey(virJSONValue *object, const char *key) { size_t i; =20 if (object->type !=3D VIR_JSON_TYPE_OBJECT) - return -1; + return false; =20 for (i =3D 0; i < object->data.object.npairs; i++) { if (STREQ(object->data.object.pairs[i].key, key)) - return 1; + return true; } =20 - return 0; + return false; } =20 =20 diff --git a/src/util/virjson.h b/src/util/virjson.h index aced48a538..ce181dcb82 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -88,7 +88,7 @@ int virJSONValueArrayConcat(virJSONValue *a, virJSONValue *c); =20 -int +bool virJSONValueObjectHasKey(virJSONValue *object, const char *key); virJSONValue * --=20 2.35.1