[libvirt PATCH 09/10] virDomainDiskSourceNetworkParse: Use virXMLProp*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 55 ++++++++++++------------------------------
 1 file changed, 15 insertions(+), 40 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 367258bf7a..113f4123d7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8273,24 +8273,14 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
                                 virStorageSource *src,
                                 unsigned int flags)
 {
-    int tlsCfgVal;
-    g_autofree char *protocol = NULL;
-    g_autofree char *haveTLS = NULL;
-    g_autofree char *tlsCfg = NULL;
-    g_autofree char *sslverifystr = NULL;
+    virStorageNetProtocol protocol;
     xmlNodePtr tmpnode;
 
-    if (!(protocol = virXMLPropString(node, "protocol"))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing network source protocol type"));
+    if (virXMLPropEnum(node, "protocol", virStorageNetProtocolTypeFromString,
+                       VIR_XML_PROP_REQUIRED, &protocol) < 0)
         return -1;
-    }
 
-    if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) <= 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown protocol type '%s'"), protocol);
-        return -1;
-    }
+    src->protocol = protocol;
 
     if (!(src->path = virXMLPropString(node, "name")) &&
         src->protocol != VIR_STORAGE_NET_PROTOCOL_NBD) {
@@ -8299,26 +8289,16 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
         return -1;
     }
 
-    if ((haveTLS = virXMLPropString(node, "tls"))) {
-        int value;
-
-        if ((value = virTristateBoolTypeFromString(haveTLS)) <= 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unknown disk source 'tls' setting '%s'"), haveTLS);
-            return -1;
-        }
-        src->haveTLS = value;
-    }
+    if (virXMLPropTristateBool(node, "tls", VIR_XML_PROP_NONE,
+                               &src->haveTLS) < 0)
+        return -1;
 
-    if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) &&
-        (tlsCfg = virXMLPropString(node, "tlsFromConfig"))) {
-        if (virStrToLong_i(tlsCfg, NULL, 10, &tlsCfgVal) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid tlsFromConfig value: %s"),
-                           tlsCfg);
+    if (flags & VIR_DOMAIN_DEF_PARSE_STATUS) {
+        int value;
+        if (virXMLPropInt(node, "tlsFromConfig", 10, VIR_XML_PROP_NONE,
+                          &value) < 0)
             return -1;
-        }
-        src->tlsFromConfig = !!tlsCfgVal;
+        src->tlsFromConfig = !!value;
     }
 
     /* for historical reasons we store the volume and image name in one XML
@@ -8364,15 +8344,10 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
 
     if ((src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS ||
          src->protocol == VIR_STORAGE_NET_PROTOCOL_FTPS) &&
-        (sslverifystr = virXPathString("string(./ssl/@verify)", ctxt))) {
-        int verify;
-        if ((verify = virTristateBoolTypeFromString(sslverifystr)) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid ssl verify mode '%s'"), sslverifystr);
+        (tmpnode = virXPathNode("./ssl", ctxt))) {
+        if (virXMLPropTristateBool(tmpnode, "verify", VIR_XML_PROP_NONE,
+                                   &src->sslverify) < 0)
             return -1;
-        }
-
-        src->sslverify = verify;
     }
 
     if ((src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTP ||
-- 
2.26.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux