Use existing function built for this exact purpose.

Signed-off-by: Rafael Fonseca <r4f4...@gmail.com>
---
 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(virSecurityDeviceLabelDefPtr **seclabels_rtn,
         labelskip = virXMLPropString(list[i], "labelskip");
         seclabels[i]->labelskip = false;
         if (labelskip && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
-            seclabels[i]->labelskip = STREQ(labelskip, "yes");
+            ignore_value(virStringParseYesNo(labelskip, 
&seclabels[i]->labelskip));
         VIR_FREE(labelskip);
 
         ctxt->node = list[i];
@@ -12354,16 +12354,14 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
     if (managed_tap) {
-        if (STREQ(managed_tap, "no")) {
-            def->managed_tap = VIR_TRISTATE_BOOL_NO;
-        } else if (STREQ(managed_tap, "yes")) {
-            def->managed_tap = VIR_TRISTATE_BOOL_YES;
-        } else {
+        bool state = false;
+        if (virStringParseYesNo(managed_tap, &state) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("invalid 'managed' value '%s'"),
                            managed_tap);
             goto error;
         }
+        def->managed_tap = virTristateBoolFromBool(state);
     }
 
     if (def->managed_tap != VIR_TRISTATE_BOOL_NO && ifname &&
@@ -13887,15 +13885,13 @@ virDomainTimerDefParseXML(xmlNodePtr node,
 
     def->present = -1; /* unspecified */
     if ((present = virXMLPropString(node, "present")) != NULL) {
-        if (STREQ(present, "yes")) {
-            def->present = 1;
-        } else if (STREQ(present, "no")) {
-            def->present = 0;
-        } else {
+        bool state = false;
+        if (virStringParseYesNo(present, &state) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unknown timer present value '%s'"), present);
             goto error;
         }
+        def->present = state ? 1 : 0;
     }
 
     def->tickpolicy = -1;
@@ -18611,10 +18607,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
     if ((node = virXPathNode("./os/bios[1]", ctxt))) {
         tmp = virXMLPropString(node, "useserial");
         if (tmp) {
-            if (STREQ(tmp, "yes"))
-                def->os.bios.useserial = VIR_TRISTATE_BOOL_YES;
-            else
-                def->os.bios.useserial = VIR_TRISTATE_BOOL_NO;
+            bool state = false;
+            ignore_value(virStringParseYesNo(tmp, &state));
+            def->os.bios.useserial = virTristateBoolFromBool(state);
             VIR_FREE(tmp);
         }
 
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"
 
 #define VIR_FROM_THIS VIR_FROM_INTERFACE
 
@@ -268,21 +269,19 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
     def->dhcp = 1;
     save = ctxt->node;
     ctxt->node = dhcp;
+    def->peerdns = -1;
     /* Not much to do in the current version */
     tmp = virXPathString("string(./@peerdns)", ctxt);
     if (tmp) {
-        if (STREQ(tmp, "yes")) {
-            def->peerdns = 1;
-        } else if (STREQ(tmp, "no")) {
-            def->peerdns = 0;
-        } else {
+        bool state = false;
+        if (virStringParseYesNo(tmp, &state) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("unknown dhcp peerdns value %s"), tmp);
             ret = -1;
+        } else {
+            def->peerdns = state ? 1 : 0;
         }
         VIR_FREE(tmp);
-    } else {
-        def->peerdns = -1;
     }
 
     ctxt->node = save;
-- 
2.25.1


Reply via email to