From nobody Sat May 11 02:37:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552384714798379.98857080849587; Tue, 12 Mar 2019 02:58:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE2C05946A; Tue, 12 Mar 2019 09:58:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C52681A930; Tue, 12 Mar 2019 09:58:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 83F3A41F3D; Tue, 12 Mar 2019 09:58:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2C9ulcW025732 for ; Tue, 12 Mar 2019 05:56:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id A03AC6014E; Tue, 12 Mar 2019 09:56:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98A0760164 for ; Tue, 12 Mar 2019 09:56:44 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0ABC93082200 for ; Tue, 12 Mar 2019 09:56:44 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id b2so1405400pgl.9 for ; Tue, 12 Mar 2019 02:56:44 -0700 (PDT) Received: from localhost.localdomain ([157.82.204.204]) by smtp.googlemail.com with ESMTPSA id p6sm10697679pgd.69.2019.03.12.02.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 02:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wup8XRWKtSlY16AXkED2zt/gZQNL3PAalXJGV+3Byhs=; b=o3Rlcmcjprf+RrsLgvHmhFNAod/H+hPMuvu5A8k4Z9qKWnx75oIS/16EKBpxtY89hl 3HCs+2ZLPKMZbRQhd6HhH8hdr3s1avR7dSaSshOud0AloOq5c+n9KMH5rdut6GWCehIx nz1JO66e+vm6vfUYUIo0fTPB7MAm8nf01DANZ8HVxm2nqThgMM5vFoEjpBE1PEXTw/pe uz3m3xUYrnRGEMEq1uedcOo4tbRFmcF689iXbbl1hUqKBUwLXgdrfwVny0hMVIZOtF9t n5cuqr2XIUqnZkNibey3rrVqZhSvQ0dZuxvXX4B217uNcOdZSXk86hd6olAaYOBwLpWq vf1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wup8XRWKtSlY16AXkED2zt/gZQNL3PAalXJGV+3Byhs=; b=hN/KGN55Mq0TDcFbVsLV6/5hiRO4Sizlzo6Nk81MAobiecHNg7J5IjIiTzJEdv5in2 6yrWAXSB0OnyqQXB6nAZrtcedWbhoj35Q/j6mHy2j6N+SdzKjp+/n6bb5EIJEjoId9NE cETuPClXHTfTzprfEj3UMMASm0cc53HiD3oatVE64c72LfcWyUiZwSS67uxdFYW868G1 T9JTI7LWEqljA9emhRVDTv9KlkUZXUlZHd/g88r19Jc6NPDhyaRnHPK5KHNb7fKiB1eZ hs1cxNDD9sjgrXIgNhTpEH9/CBa9EOBiTI1KiyN6svi5ToRGSeOEmm68Ru2+CRBqKs9u 2Qlw== X-Gm-Message-State: APjAAAVk1dnj9z7vaOSX9PJotXFnFavLZoe/C4UdxW6MCA8/x9Wnl+ah awYzQvDUBcGDmVW7mbD5vDxy6ROhfZqZAA== X-Google-Smtp-Source: APXvYqxu6Qi8jcrMvPaZ/Hcv+H7EXXgP/UaBkK4FnjYZaQc8XAg45eM716JY0av+89PTq3P87Zk+Lw== X-Received: by 2002:a63:7444:: with SMTP id e4mr34551100pgn.398.1552384602884; Tue, 12 Mar 2019 02:56:42 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 18:56:22 +0900 Message-Id: <20190312095623.3899-2-g.sho1500@gmail.com> In-Reply-To: <20190312095623.3899-1-g.sho1500@gmail.com> References: <20190312095623.3899-1-g.sho1500@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 12 Mar 2019 09:56:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 12 Mar 2019 09:56:44 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'g.sho1500@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.142 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH v2 1/2] util: add virStringParseYesNo() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 12 Mar 2019 09:58:33 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function parse the string "yes" into bool true and "no" into false, and return 0. If the string is anything other than "yes|no", this function return -1. Signed-off-by: Shotaro Gotanda --- src/util/virstring.c | 23 +++++++++++++++++++++++ src/util/virstring.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 33f8191f45..945a8d0c84 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1548,3 +1548,26 @@ virStringParsePort(const char *str, =20 return 0; } + + +/** + * virStringParseYesNo: + * @str: "yes|no" to parse, and the value must not be NULL. + * @port: pointer to parse and convert "yes|no" into + * + * Parses a string "yes|no" and convert it into true|false. + * Returns 0 on success and -1 on error. + */ +int virStringParseYesNo(const char *str, bool *result) +{ + + if (STREQ(str, "yes")) { + *result =3D true; + } else if (STREQ(str, "no")) { + *result =3D false; + } else { + return -1; + } + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 1e36ac459c..9b01e8568a 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -316,6 +316,9 @@ int virStringParsePort(const char *str, unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 +int virStringParseYesNo(const char *str, + bool *result) + ATTRIBUTE_RETURN_CHECK; /** * VIR_AUTOSTRINGLIST: * --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 11 02:37:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552384719586812.5854045596203; Tue, 12 Mar 2019 02:58:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0B39307D861; Tue, 12 Mar 2019 09:58:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1F3D5D70E; Tue, 12 Mar 2019 09:58:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5912C131F9; Tue, 12 Mar 2019 09:58:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2C9unT7025742 for ; Tue, 12 Mar 2019 05:56:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9B865D71A; Tue, 12 Mar 2019 09:56:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D37AF5D70E for ; Tue, 12 Mar 2019 09:56:47 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E061A81F22 for ; Tue, 12 Mar 2019 09:56:46 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id l11so1398633pgq.10 for ; Tue, 12 Mar 2019 02:56:46 -0700 (PDT) Received: from localhost.localdomain ([157.82.204.204]) by smtp.googlemail.com with ESMTPSA id p6sm10697679pgd.69.2019.03.12.02.56.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 02:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KaYZEGs0H9pHZRjUfLFYX2/qNRPpsdeiK7uZdhEaGGg=; b=QtAsQ18y7ggL2FPeAiMqrmn0oPn8AD4XerCdcWk0gksUDdbUWeVDIsa/UY+Ndg9pDU BiZum7U0ThfkVyyiI8AUlG452E8oPgXQxe88pgGdYy2JtHmkGax85Ekg1iQadWmpfcZD MsaeuYTNV20scKVz8qNdSKEo3lTQxTXQT5N6HLTiVmcmz7e/Nq1g/MhVlVEnkp/KoNWK oXKaBx02DGfssRXXA3fUv4u9QwdSddeWasp3tl7Telbb3MuEs5fhMm+i4fA1YYc42GXR 14XMJmx8ftSMkH7wbpUZNbOouINzIjTj4GeRv7FmE/KPLLU1BLogv5F8UT5SE/jfTU+T 7CUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KaYZEGs0H9pHZRjUfLFYX2/qNRPpsdeiK7uZdhEaGGg=; b=sIY+3nOuncOpliLmPYWGyadR+rvdDa0Vp1NcABjpWSd/t0hgDloCUN2/8f6omA4S5H A71KcJENEYBSa/CEJEw13c7uxtOS9Ccv/o3eHKRDNh5GtOElWC8ss0kD/FIHhrdxN6fl V6w/z7mNQVzbkpgT8amfrsXXubYN8+cThQxHaTkeGJwkNi13e3SWSh3YidRDhVZ81p9j M4gn4L4+fbGrhcluNlePinFxeKqUxYw98TcF+6j3Fa5yXiX0oSQ4NKHXZ8Lzmue95mw+ P0qg6PLT/p36Ti6b1Q4y+XMtgEpGOhl7fUni6pbseRlTnRLZeYCxkd1lwIsYKmTN3PqU UzCA== X-Gm-Message-State: APjAAAXTAocYifAdcML5tNS5JExYyZnF5lsNc+iTcJF7NS8z1nEA7AFv fJNCpOV9+eerjtb8Mp2T1CEOSJPeYsozjg== X-Google-Smtp-Source: APXvYqx0avaXxKUTxCiXLb5agoVkIGpdXdomaf4h3OwkV/uWgTQVdZXuj3d2ljdDIfORCB/XBj4A3Q== X-Received: by 2002:a63:6903:: with SMTP id e3mr34479889pgc.147.1552384605780; Tue, 12 Mar 2019 02:56:45 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 18:56:23 +0900 Message-Id: <20190312095623.3899-3-g.sho1500@gmail.com> In-Reply-To: <20190312095623.3899-1-g.sho1500@gmail.com> References: <20190312095623.3899-1-g.sho1500@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 12 Mar 2019 09:56:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 12 Mar 2019 09:56:47 +0000 (UTC) for IP:'209.85.215.195' DOMAIN:'mail-pg1-f195.google.com' HELO:'mail-pg1-f195.google.com' FROM:'g.sho1500@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.14 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.215.195 mail-pg1-f195.google.com 209.85.215.195 mail-pg1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH v2 2/2] conf: Use virStringParseYesNo() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 12 Mar 2019 09:58:37 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" this commit remove redundant common pattern in our XML parsing. Signed-off-by: Shotaro Gotanda --- src/conf/domain_conf.c | 30 +++++------------------------- src/conf/secret_conf.c | 12 ++---------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 995f87bcbe..3830926f3d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8412,11 +8412,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, p =3D virXMLPropStringLimit(ctxt->node, "relabel", VIR_SECURITY_LABEL_BUFLEN-1); if (p) { - if (STREQ(p, "yes")) { - seclabel->relabel =3D true; - } else if (STREQ(p, "no")) { - seclabel->relabel =3D false; - } else { + if (virStringParseYesNo(p, &seclabel->relabel) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid security relabel value %s"), p); goto error; @@ -8646,11 +8642,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceL= abelDefPtr **seclabels_rtn, =20 relabel =3D virXMLPropString(list[i], "relabel"); if (relabel !=3D NULL) { - if (STREQ(relabel, "yes")) { - seclabels[i]->relabel =3D true; - } else if (STREQ(relabel, "no")) { - seclabels[i]->relabel =3D false; - } else { + if (virStringParseYesNo(relabel, &seclabels[i]->relabel) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid security relabel value %s"), relabel); @@ -13653,11 +13645,7 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsD= efPtr def, ctxt->node =3D node; =20 if (fullscreen !=3D NULL) { - if (STREQ(fullscreen, "yes")) { - def->data.sdl.fullscreen =3D true; - } else if (STREQ(fullscreen, "no")) { - def->data.sdl.fullscreen =3D false; - } else { + if (virStringParseYesNo(fullscreen, &def->data.sdl.fullscreen) < 0= ) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); goto cleanup; @@ -13745,11 +13733,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraph= icsDefPtr def, VIR_AUTOFREE(char *) fullscreen =3D virXMLPropString(node, "fullscreen= "); =20 if (fullscreen !=3D NULL) { - if (STREQ(fullscreen, "yes")) { - def->data.desktop.fullscreen =3D true; - } else if (STREQ(fullscreen, "no")) { - def->data.desktop.fullscreen =3D false; - } else { + if (virStringParseYesNo(fullscreen, &def->data.desktop.fullscreen)= < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); return -1; @@ -15458,11 +15442,7 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr n= ode) =20 allow =3D virXMLPropString(node, "allow"); if (allow) { - if (STREQ(allow, "yes")) { - def->allow =3D true; - } else if (STREQ(allow, "no")) { - def->allow =3D false; - } else { + if (virStringParseYesNo(allow, &def->allow) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid allow value, either 'yes' or 'no'")); goto error; diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index ca6cc194a2..5b85a7c0be 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -147,11 +147,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) =20 prop =3D virXPathString("string(./@ephemeral)", ctxt); if (prop !=3D NULL) { - if (STREQ(prop, "yes")) { - def->isephemeral =3D true; - } else if (STREQ(prop, "no")) { - def->isephemeral =3D false; - } else { + if (virStringParseYesNo(prop, &def->isephemeral) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid value of 'ephemeral'")); goto cleanup; @@ -161,11 +157,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) =20 prop =3D virXPathString("string(./@private)", ctxt); if (prop !=3D NULL) { - if (STREQ(prop, "yes")) { - def->isprivate =3D true; - } else if (STREQ(prop, "no")) { - def->isprivate =3D false; - } else { + if (virStringParseYesNo(prop, &def->isprivate) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid value of 'private'")); goto cleanup; --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list