From nobody Wed Apr 24 19:29:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1584895256; cv=none; d=zohomail.com; s=zohoarc; b=Y+GTp8Xd6yWVL9GMtavbC0PA1C6fHDOD9lhLm6ePvKSpjEby5zLwB42mWvXKCblXicNYEJLs7ZlTivGzYUqbPG5bIcHOCdN3jXCpv7ZyRAhDr+vkRtMXORKGEUHXEiU+n77zLNQUj4gOUAeW8Wnxqll7sTDWV+6/VI0awKg41Iw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584895256; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=os+w1Xlls3eJGGY5EAFNBamIPQVgdpBNetuJMQsJqhw=; b=de7wXWxSGa5kBVSx9VBXfysAqOC7y7xGV6CqQuBgUEGUMqVHbi7HunfxpNV85tffnr3JUI60pwZxMUaRtWSia7N9Q4FLn91JyTy6Fpelu/4t6ZwXYiy32mIrsZ0UVtNbmWoMMn41ZDIOxdqIlsNjeQUwLtRYjlimyh8JjiDyHOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584895256585914.9443734338719; Sun, 22 Mar 2020 09:40:56 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-nBj1yoeVMIm6SCKd1Vm5dw-1; Sun, 22 Mar 2020 12:40:48 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C06C800D48; Sun, 22 Mar 2020 16:40:39 +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 CBA6673897; Sun, 22 Mar 2020 16:40: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 A379B86386; Sun, 22 Mar 2020 16:40:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02MGePk7022190 for ; Sun, 22 Mar 2020 12:40:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 34E3EB17E0; Sun, 22 Mar 2020 16:40:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 31282B17DF for ; Sun, 22 Mar 2020 16:40:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6DBE2800298 for ; Sun, 22 Mar 2020 16:40:22 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-lPzDGpwWOgCM8EjJ5-Zarg-1; Sun, 22 Mar 2020 12:40:19 -0400 Received: by mail-wr1-f66.google.com with SMTP id h9so13681209wrc.8 for ; Sun, 22 Mar 2020 09:40:19 -0700 (PDT) Received: from localhost.localdomain (public-gprs375156.centertel.pl. [37.47.96.181]) by smtp.gmail.com with ESMTPSA id s22sm16398011wmc.16.2020.03.22.09.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 09:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584895255; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=os+w1Xlls3eJGGY5EAFNBamIPQVgdpBNetuJMQsJqhw=; b=Jx/FQnx7dyKZyG7F9YdxeM5UxRl6dS6bBxerRMQeab2bzxVukf7PrZKNvby+2HCCDSrKZQ 6IWFRpGvr7MjqPu30E/G1QDNjAt16CVeapEDJrbKN/zzAwMc1HUQUQaePGVQlbk/kn136D sDhbOnl1w8YSRsuilkT9hMEXwVuz7no= X-MC-Unique: nBj1yoeVMIm6SCKd1Vm5dw-1 X-MC-Unique: lPzDGpwWOgCM8EjJ5-Zarg-1 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:mime-version :content-transfer-encoding; bh=78PCJ7GFLIgzZqL7B941CdXL7Rco3hLBp5ObT5SomD0=; b=eQq2TD0uQE+s8MAvM1aZ3cxvUypLLPlUXGDngLmdWql2692o2yjbKasC3+XY9JrqM0 hT0AtKmHg6gfLHe4nagOq0eH5WAwUqRor3OWf+MVMV6eivIJkBbaFnjbh01S+1ka7yhb 7Tp3NmDUEyn+1thToYFpBqubfVlEw2neGtF9iHthed5yMeChDTHt2ANtBLu0LapEv/hs a4MZfnxjGlq6RWZxqazzUl+SM0pOx3XX3ckGuKxgb7TKY95RPlEIBxO4X+75d6MGGJR3 wQzL3+yL7bDdGgI0imadg1JI0CWdaNzJn4KuVAHSpzwguuh/dw1E1xRiBN9ezE5iCOFc IOzg== X-Gm-Message-State: ANhLgQ1M5cIproYewfagpvYAQ0GBv31WjHFurDFR0KCLAn1KeJQPXOuk No9u2rG4ij0GMcxxiQPsHbTyXWi2Cow= X-Google-Smtp-Source: ADFU+vs8MjtEydq6Wl9g5NGuHdvtQ4AfBzfLYdro9RGeBLBcPYsZhPLdZsVhcIyrOWK1HB1UoplYHw== X-Received: by 2002:adf:8385:: with SMTP id 5mr7417464wre.35.1584895218225; Sun, 22 Mar 2020 09:40:18 -0700 (PDT) From: Rafael Fonseca To: libvir-list@redhat.com Subject: [PATCH] conf: use virStringParseYesNo Date: Sun, 22 Mar 2020 17:39:50 +0100 Message-Id: <20200322163950.454016-1-r4f4rfs@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 02MGePk7022190 X-loop: libvir-list@redhat.com Cc: Rafael Fonseca 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use existing function built for this exact purpose. Signed-off-by: Rafael Fonseca Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 25 ++++++++++--------------- src/conf/interface_conf.c | 13 ++++++------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e0432fc47d..2fed8dff14 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9203,7 +9203,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDefPtr **seclabels_rtn, labelskip =3D virXMLPropString(list[i], "labelskip"); seclabels[i]->labelskip =3D false; if (labelskip && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - seclabels[i]->labelskip =3D STREQ(labelskip, "yes"); + ignore_value(virStringParseYesNo(labelskip, &seclabels[i]->lab= elskip)); VIR_FREE(labelskip); =20 ctxt->node =3D list[i]; @@ -12354,16 +12354,14 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xml= opt, goto error; =20 if (managed_tap) { - if (STREQ(managed_tap, "no")) { - def->managed_tap =3D VIR_TRISTATE_BOOL_NO; - } else if (STREQ(managed_tap, "yes")) { - def->managed_tap =3D VIR_TRISTATE_BOOL_YES; - } else { + bool state =3D false; + if (virStringParseYesNo(managed_tap, &state) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid 'managed' value '%s'"), managed_tap); goto error; } + def->managed_tap =3D virTristateBoolFromBool(state); } =20 if (def->managed_tap !=3D VIR_TRISTATE_BOOL_NO && ifname && @@ -13887,15 +13885,13 @@ virDomainTimerDefParseXML(xmlNodePtr node, =20 def->present =3D -1; /* unspecified */ if ((present =3D virXMLPropString(node, "present")) !=3D NULL) { - if (STREQ(present, "yes")) { - def->present =3D 1; - } else if (STREQ(present, "no")) { - def->present =3D 0; - } else { + bool state =3D false; + if (virStringParseYesNo(present, &state) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown timer present value '%s'"), present); goto error; } + def->present =3D state ? 1 : 0; } =20 def->tickpolicy =3D -1; @@ -18611,10 +18607,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, if ((node =3D virXPathNode("./os/bios[1]", ctxt))) { tmp =3D virXMLPropString(node, "useserial"); if (tmp) { - if (STREQ(tmp, "yes")) - def->os.bios.useserial =3D VIR_TRISTATE_BOOL_YES; - else - def->os.bios.useserial =3D VIR_TRISTATE_BOOL_NO; + bool state =3D false; + ignore_value(virStringParseYesNo(tmp, &state)); + def->os.bios.useserial =3D virTristateBoolFromBool(state); VIR_FREE(tmp); } =20 diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 7a41b19ed0..d1732621b5 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -28,6 +28,7 @@ #include "virxml.h" #include "viruuid.h" #include "virbuffer.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_INTERFACE =20 @@ -268,21 +269,19 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr d= ef, def->dhcp =3D 1; save =3D ctxt->node; ctxt->node =3D dhcp; + def->peerdns =3D -1; /* Not much to do in the current version */ tmp =3D virXPathString("string(./@peerdns)", ctxt); if (tmp) { - if (STREQ(tmp, "yes")) { - def->peerdns =3D 1; - } else if (STREQ(tmp, "no")) { - def->peerdns =3D 0; - } else { + bool state =3D false; + if (virStringParseYesNo(tmp, &state) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown dhcp peerdns value %s"), tmp); ret =3D -1; + } else { + def->peerdns =3D state ? 1 : 0; } VIR_FREE(tmp); - } else { - def->peerdns =3D -1; } =20 ctxt->node =3D save; --=20 2.25.1