]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf/domain_conf: use virStringParseYesNo helper
authorMao Zhongyi <maozhongyi@cmss.chinamobile.com>
Thu, 17 Oct 2019 03:19:31 +0000 (11:19 +0800)
committerCole Robinson <crobinso@redhat.com>
Thu, 14 Nov 2019 13:14:50 +0000 (08:14 -0500)
This helper performs a conversion from a "yes|no" string
to a corresponding boolean, and several conversions were
already done, but there are still some omissions.

For most of the remaining usages in domain_conf.c only
"yes" is explicitly checked for. This means all other
values are implicitly handled as 'false'. In this case,
use virStringParseYesNo to handle the conversion and
reserve the original logic of not raise an error, so
ignore the return value of helper.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
src/conf/domain_conf.c

index b8df4591b381e5279467a8233339d052e6eefb40..f825e521ec87d98b8ef38aeede2fd3b28e3f829c 100644 (file)
@@ -7589,10 +7589,8 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
         }
     }
 
-    if ((autoAddress = virXMLPropString(node, "autoAddress"))) {
-        if (STREQ(autoAddress, "yes"))
-            usbsrc->autoAddress = true;
-    }
+    if ((autoAddress = virXMLPropString(node, "autoAddress")))
+        ignore_value(virStringParseYesNo(autoAddress, &usbsrc->autoAddress));
 
     /* Product can validly be 0, so we need some extra help to determine
      * if it is uninitialized*/
@@ -8143,10 +8141,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
      * element that might be (pure hostdev, or higher level device
      * (e.g. <interface>) with type='hostdev')
      */
-    if ((managed = virXMLPropString(node, "managed")) != NULL) {
-        if (STREQ(managed, "yes"))
-            def->managed = true;
-    }
+    if ((managed = virXMLPropString(node, "managed")) != NULL)
+        ignore_value(virStringParseYesNo(managed, &def->managed));
 
     sgio = virXMLPropString(node, "sgio");
     rawio = virXMLPropString(node, "rawio");
@@ -13714,9 +13710,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
 
     if (autoGenerated &&
         flags & VIR_DOMAIN_DEF_PARSE_STATUS) {
-        if (STREQ(autoGenerated, "yes")) {
-            def->autoGenerated = true;
-        } else if (STRNEQ(autoGenerated, "no")) {
+        if (virStringParseYesNo(autoGenerated, &def->autoGenerated) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("Invalid autoGenerated value: %s"),
                            autoGenerated);
@@ -13846,13 +13840,10 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
     }
 
     if (autoport) {
-        if (STREQ(autoport, "yes")) {
-            if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)
-                def->data.vnc.port = 0;
-            def->data.vnc.autoport = true;
-        } else {
-            def->data.vnc.autoport = false;
-        }
+        ignore_value(virStringParseYesNo(autoport, &def->data.vnc.autoport));
+
+        if (def->data.vnc.autoport && flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)
+            def->data.vnc.port = 0;
     }
 
     if (websocket) {
@@ -13865,8 +13856,9 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
         }
     }
 
-    if (websocketGenerated && STREQ(websocketGenerated, "yes"))
-        def->data.vnc.websocketGenerated = true;
+    if (websocketGenerated)
+        ignore_value(virStringParseYesNo(websocketGenerated,
+                     &def->data.vnc.websocketGenerated));
 
     if (sharePolicy) {
         int policy =
@@ -15420,8 +15412,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
                 heads = virXMLPropString(cur, "heads");
 
                 if ((primary = virXMLPropString(cur, "primary")) != NULL) {
-                    if (STREQ(primary, "yes"))
-                        def->primary = true;
+                    ignore_value(virStringParseYesNo(primary, &def->primary));
                     VIR_FREE(primary);
                 }