From nobody Sat Apr 20 01:00:41 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 1552458674160154.0918452346101; Tue, 12 Mar 2019 23:31:14 -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 6295930018C4; Wed, 13 Mar 2019 06:31:12 +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 3768E5D706; Wed, 13 Mar 2019 06:31:12 +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 E88EA3FB11; Wed, 13 Mar 2019 06:31:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2D6Ug6e029855 for ; Wed, 13 Mar 2019 02:30:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 865F917AD1; Wed, 13 Mar 2019 06:30:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81B765DD84 for ; Wed, 13 Mar 2019 06:30:39 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) (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 CF32E3ED89 for ; Wed, 13 Mar 2019 06:30:38 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id b2so787412pgl.9 for ; Tue, 12 Mar 2019 23:30:38 -0700 (PDT) Received: from localhost.localdomain ([157.82.204.204]) by smtp.googlemail.com with ESMTPSA id d26sm14573310pfn.86.2019.03.12.23.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:30:37 -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=mZ8u39s4i/BLSeFwdDn37Cxjt47/Mns9BQoUmkhpU90=; b=lLQxtd/3Fdag/vXwnjM3EKHSAuvzHTpzNCX+ALZKU7OMJYaAgBkNtx/eSqJtzAl2co SGMVKkvGJumq0s6Mg0qCy99BknaWPXmkHkbYf/24x4xaMUE/49M50Ps/5cFkLorpqAHG UGIhkcpeVyZ4iNcPlxrwL4FdsJiagsj6nxJgvQfXTpFDew998oDIWWSR1UN9Y8V1xryK k47TQluM/4LlMjc8KTlHqRyJfYkoI/8o40CQPYy0HTJY/hysLemahnpfwum7XIO6EhQK QZd8tyaA8wBwliiCGq4w7f02pV3w8J0yn+fu90W4VFLQzq4pv1To5GYiw5MDFmC+JehI GhYQ== 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=mZ8u39s4i/BLSeFwdDn37Cxjt47/Mns9BQoUmkhpU90=; b=PLihaxl8OugV+AEMb4xNkGTrnTJtJn3D/9mcfXLT+gz4ZI+MlwvR9lO6qGhVmYG3SE 79yi0qoVTTGYzI6mcJOGoA2d6KSuKflPKCi2gZqvythTmPF9zDM9J9AX6n+qKAU/ltu4 ONtLIVDzbIf1oAcz3/5BMDJZQj/jk/6q/bmGCmVs/Wr5/ZJnG1nDYIocHeHGFUNcivOJ jj9wPdSGn71HSps6pNTN5OzLFAJV9hIk9BVdmZ6penyentQPGz3HTpIai+gi/Q0xLXYW QfAibZP7b1fx69Rx2kR+de4eBIF7GzcmdbJ53Od2nYSenAiw17mnBspLxUPmhbLgS151 d+iQ== X-Gm-Message-State: APjAAAXSl733dN7UdveZLOqIwjQ6A3TSOU/mfaTgqnQ8XoUf9/85s1s0 SuQZCp3zrmG1loDl3Kdtv5jrkLVRilWs+w== X-Google-Smtp-Source: APXvYqyY8WxpJXzZZvgpj+BSxAEeVHDVRMGbuWf1bjiYwpf8AGlsHy+LuBksiS/GylDLLRkN7GQPMQ== X-Received: by 2002:a17:902:9a43:: with SMTP id x3mr43343896plv.173.1552458637831; Tue, 12 Mar 2019 23:30:37 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Wed, 13 Mar 2019 15:30:10 +0900 Message-Id: <20190313063011.16317-2-g.sho1500@gmail.com> In-Reply-To: <20190313063011.16317-1-g.sho1500@gmail.com> References: <20190313063011.16317-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.39]); Wed, 13 Mar 2019 06:30:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 13 Mar 2019 06:30:38 +0000 (UTC) for IP:'209.85.215.193' DOMAIN:'mail-pg1-f193.google.com' HELO:'mail-pg1-f193.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.193 mail-pg1-f193.google.com 209.85.215.193 mail-pg1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH v3 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 13 Mar 2019 06:31:12 +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 returns 0. If the string is anything other than "yes|no", this function returns -1. Signed-off-by: Shotaro Gotanda Reviewed-by: Erik Skultety --- src/util/virstring.c | 21 +++++++++++++++++++++ src/util/virstring.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 33f8191f45..3bbe36ea25 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1548,3 +1548,24 @@ 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 Apr 20 01:00:41 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 1552458652516905.2734741189158; Tue, 12 Mar 2019 23:30:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03CD97DCF4; Wed, 13 Mar 2019 06:30:50 +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 C5081605C2; Wed, 13 Mar 2019 06:30:49 +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 DFF8341F3C; Wed, 13 Mar 2019 06:30:46 +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 x2D6UjnY029873 for ; Wed, 13 Mar 2019 02:30:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id BF4F36013F; Wed, 13 Mar 2019 06:30:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4B40605C7 for ; Wed, 13 Mar 2019 06:30:43 +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 095C77F3F7 for ; Wed, 13 Mar 2019 06:30:42 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id v64so685902pfb.1 for ; Tue, 12 Mar 2019 23:30:42 -0700 (PDT) Received: from localhost.localdomain ([157.82.204.204]) by smtp.googlemail.com with ESMTPSA id d26sm14573310pfn.86.2019.03.12.23.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:30:40 -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=rNjSQIQmro+tbdyAeH4Fij5LlDuxaD42hsXBXImZjPKSNXQzM4aJhfae7vwbRIoEjl 9oQDpHOHM5X641EwTmDV2KEIML3AjisE0hiU7P8RadHDuNssC1EtSkgoDz9jgrumqNlq gpdWFGttkmfKNMGml1d8sHoEAhzm/loJwTkRlwHKRRrHAZFWvSje0ZDnda4qLnHAU3jS Sh9TAJJ1fcOrE5mim/F6SUPzXVkj1ata3X6ZWYEXPmGQcKFkFGIcIgvF3tK+0XPeEELX w2pRFkt166kna1tDnsvsTLJIkqbx1BlRJTOZcDLPuDIgvNVJLHpBuoZgQzq8SW9nQLQa 4R7w== 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=gbQMINVL6sjcE9Y9WNJ/OeUsJi3w39cD8U2McHyRDdw11ne+fHBfewvP3DI57wm2EB MCYMSie7HI/NDVI0bHn8TQtISgApYxex+U2IPk29/07Ki7SLxk/yb+luLCpaeWviWVi3 EztoDTwgThxBoMMU5HXdr+zkptfI6A1Z7KC/QA6i9odVhpremfNpdXKHznNws+V/quB7 Od+YIC2rQDWEVPqLBsE2OL2hNc1SyrQAngx6Yz+4W3LMoSJBbtL/MuqkzeJtQPzoliwZ TGuegv5ApgpXZAHMoHwNlLiE2Mp1OK4dDs9bltew0BD/qRi80qULNNsYJhRJvG2IPfLP U4dw== X-Gm-Message-State: APjAAAVq0nkrW/www18Qakvcos7aylxrenyUDtV+5DP02kK+UUYXhu1U 4za9Vwt1AlWmmvF26ijj+AmDw4dz5VVhNg== X-Google-Smtp-Source: APXvYqw3o8XsHiK2Xp7UV4EySWp70D02LBgge/Tyx3ff+3Ce1GY9IOslh+TOkF6ZKPO8DpqLl42Guw== X-Received: by 2002:aa7:8a4c:: with SMTP id n12mr5946432pfa.127.1552458640966; Tue, 12 Mar 2019 23:30:40 -0700 (PDT) From: Shotaro Gotanda To: libvir-list@redhat.com Date: Wed, 13 Mar 2019 15:30:11 +0900 Message-Id: <20190313063011.16317-3-g.sho1500@gmail.com> In-Reply-To: <20190313063011.16317-1-g.sho1500@gmail.com> References: <20190313063011.16317-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.25]); Wed, 13 Mar 2019 06:30:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 13 Mar 2019 06:30:42 +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.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.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Shotaro Gotanda Subject: [libvirt] [PATCH v3 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 13 Mar 2019 06:30:51 +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 Reviewed-by: Erik Skultety --- 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