From nobody Wed Nov 27 08:52:34 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 1552318955513748.7162373091869; Mon, 11 Mar 2019 08:42:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A557B87624; Mon, 11 Mar 2019 15:42:33 +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 7B9A3608E2; Mon, 11 Mar 2019 15:42:33 +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 16D47247E3; Mon, 11 Mar 2019 15:42:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2BFcbSh002188 for ; Mon, 11 Mar 2019 11:38:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F13A1001DDB; Mon, 11 Mar 2019 15:38:37 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 798B8100194A for ; Mon, 11 Mar 2019 15:38:34 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 73DE930001D9 for ; Mon, 11 Mar 2019 15:38:33 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j5so3971438pfa.2 for ; Mon, 11 Mar 2019 08:38:33 -0700 (PDT) Received: from localhost.localdomain (KD036012073125.au-net.ne.jp. [36.12.73.125]) by smtp.googlemail.com with ESMTPSA id v1sm9191073pff.9.2019.03.11.08.38.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 08:38:31 -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=yN62uG6d65MfKbANkIUgwYsMpzC7Yb6YqGk6T4Nv4s8=; b=VRRK7W3M7wIKhXo4SAoaMY9ROpOhzUZPVesHBwbshQhyjz+mNxcj4qZ4hdRw0ZDBGC tIpsqlXdS0EqTcRCeroiIcyid7KJVp5E1dJPpfh91a3RKNxE7eqsq/gCpGQW3SzUk6K7 N5pyMpi+fcPy9IFSkhhnTaJysXhdOpkvnL2+zO5OZtp0sWTSYgijNzhmIUnSTIUyW+Ez +L1pFHmhRHbhgEVrVBZUp21Akbv2c/fu/XyopiA6ay/vPUkxNl818jbja1jweO7RQVaD nX6vybUONNjKK849yLf//zXdm6hy7BWhZWaZUxKwnpdmmPaQn+ND64do6Yg7ZQb26dxT OsqA== 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=yN62uG6d65MfKbANkIUgwYsMpzC7Yb6YqGk6T4Nv4s8=; b=VDzB2+Enjx05IQKVg8+S3ET0tYa2r6WDdivlfoUJfO4yoKYg6YyRUPYJrBCDPoKU7l KUHicCgAZpgJdvrCEmZuhDjHdatFnVtqy6gniWDSmjJ0W7lFp+aLgypwOQHkePTVy5aa Dk3JwzBmu0Lrxc2SQeELRhCYDLJiPJRef09Rzrg2mFqsbmXwiKhIxpb8XJX+kwi7zQIw cXujYRT8nCDARhncZqSKMjCzh7DivVZ5uGGluyuYyHy5s/FzvAhqlvzsr9tEDpXE1zSb MKoJrJZUhalZy0tVxMbN7mdW2c/8T+wmoZ+4fkg4TV+IAygrxHy5VddAJ4S2zewtwIgD KtuA== X-Gm-Message-State: APjAAAVrXXoIR3njjb+stQWEdqKxkEqiX6pmvc8dLv0g3eix5ECs/yKa bfNWyPWxSYL1hEonxAdqnlPFbwN+ X-Google-Smtp-Source: APXvYqzBs2RPSoSTgqaEt/OgdvEl5dkfZ0jArzyxJeFKi157hanLDGMb/WhGb+FPoVubFAy1XKjgZg== X-Received: by 2002:a63:101c:: with SMTP id f28mr29900021pgl.224.1552318712320; Mon, 11 Mar 2019 08:38:32 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 00:38:05 +0900 Message-Id: <20190311153806.31327-2-g.sho1500@gmail.com> In-Reply-To: <20190311153806.31327-1-g.sho1500@gmail.com> References: <20190311153806.31327-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.49]); Mon, 11 Mar 2019 15:38:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 11 Mar 2019 15:38:33 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'g.sho1500@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.12 (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.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 11 Mar 2019 15:42:34 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This function parse and convert string "yes|no" into bool true|false. Signed-off-by: Shotaro Gotanda --- src/util/virstring.c | 32 ++++++++++++++++++++++++++++++++ src/util/virstring.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 33f8191f45..70018459de 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1548,3 +1548,35 @@ virStringParsePort(const char *str, =20 return 0; } + + +/** + * virStringParseYesNo: + * @str: "yes|no" to parse + * @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) +{ + bool r =3D false; + + if (!str) + return -1; + + if (STREQ(str, "yes")) { + r =3D true; + } else if (STREQ(str, "no")) { + r =3D false; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid value, '%s' must be either 'yes' or 'no'"), st= r); + return -1; + } + + *result =3D r; + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 1e36ac459c..b921d5407b 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); + /** * VIR_AUTOSTRINGLIST: * --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Nov 27 08:52:34 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 1552318761039571.2027108780942; Mon, 11 Mar 2019 08:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42E4A30842B3; Mon, 11 Mar 2019 15:39:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B07BD608E2; Mon, 11 Mar 2019 15:39:17 +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 22ED9181A138; Mon, 11 Mar 2019 15:39:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2BFcfs5002212 for ; Mon, 11 Mar 2019 11:38:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id D935D4384; Mon, 11 Mar 2019 15:38:41 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2E77614E6 for ; Mon, 11 Mar 2019 15:38:38 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 1DBA0AC2E1 for ; Mon, 11 Mar 2019 15:38:37 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id a3so3954375pff.11 for ; Mon, 11 Mar 2019 08:38:37 -0700 (PDT) Received: from localhost.localdomain (KD036012073125.au-net.ne.jp. [36.12.73.125]) by smtp.googlemail.com with ESMTPSA id v1sm9191073pff.9.2019.03.11.08.38.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 08:38:35 -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=SQXdqMEIZRDgHZmiPSuhF9+PNLSxNKMD4IFjfDs2G0A=; b=cvDcndkFUR5ZJKd78xKdWaEp7EyiTDLYb8NShITCS5+aweAjWFk+ce6Hx+ajLY55T4 qtTHYCthWAN6T3RW1Z5THs39XHptrPV/nQ92UDDBBlEElqngWh3p7jFkV7V9T3QduBz2 +dbUFVGCdnzGwRAsBwEsqhhHiLVP1zvIzyxE1FF1tiqNeBR4HOUrKjMT+c3cP+Du9AyH vsvc3GwsZmcFcsqNGjaktxvP8CavwFS0OfYNT3+d8+rJ78klTBIyVIqsMwBCpCXED1GI qt5fKWlR2zSQXcaCcApEzZRTt49o7vhj0bpyNjhsesrJloGR3rV56X4Fyh6XAbEHTXrR r9yw== 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=SQXdqMEIZRDgHZmiPSuhF9+PNLSxNKMD4IFjfDs2G0A=; b=NqLIN9j2SMtrdeF7/jHLmtYO6PSNzvK+TYYEZfm7IpLjtDC9AEDPustPAyFoEdJbFT 2pgLb2v0m2ub3sKu72/0M7+zNkHK76R44wdGvlw/5M7O9qyNUODvNVMQAfZ+1/oYnBjb aCoFahba1nHe56GX9C9/xBPUZ0MwQ0cm/YAukC6jZzqasmA14qrdxqJ1a6MpeZBAl9U7 ViguWrSsUM0ai3Mv/elu+wq6SxV7Sz+2f5pZVb/AeqI8d9ZqXRk0uLhoftGFuZpdtU4o 2b9dCC+nyxBH2pVt1OeTGszfSVcBW/LBuyaIb+MFjQHxzCQDvffe5LpCnWo1OdqImYRS z27g== X-Gm-Message-State: APjAAAXGRr1sXrT8DKRxN9myC39ph2XIs9qXlBmhGEDvpcF1cZITbuf8 ZTYY1sMpvMdGx8YzNKpG9+4QxCyN X-Google-Smtp-Source: APXvYqwkAgCXyQZiKPDzts8ShsI2sASnV4YHXjXPcRIBdXgEkKiGRSpDfX/bfHPby2CpsA4UsjakUw== X-Received: by 2002:a65:64c3:: with SMTP id t3mr17723606pgv.14.1552318715885; Mon, 11 Mar 2019 08:38:35 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Tue, 12 Mar 2019 00:38:06 +0900 Message-Id: <20190311153806.31327-3-g.sho1500@gmail.com> In-Reply-To: <20190311153806.31327-1-g.sho1500@gmail.com> References: <20190311153806.31327-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.38]); Mon, 11 Mar 2019 15:38:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 11 Mar 2019 15:38:37 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'g.sho1500@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.12 (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.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 11 Mar 2019 15:39:19 +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 that convert string 'yes' into true and 'no' into false, and error if we receive anything other values. 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