[RFC 15/29] conf: Extract error-checking code from virNetworkDNSHostDefParseXML

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

 



Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx>
---
 docs/schemas/network.rng |  8 ++++++
 src/conf/network_conf.c  | 58 +++++++++++++++++++++++++++-------------
 2 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng
index 919464d..ee4487e 100644
--- a/docs/schemas/network.rng
+++ b/docs/schemas/network.rng
@@ -336,6 +336,14 @@
                 <!-- VIRT:DIRECTIVE {
                   "structure": {"output": "src/conf/network_conf"},
                   "clearfunc": {"output": "src/conf/network_conf"},
+                  "parsefunc": {
+                    "args.noctxt": true,
+                    "args.instname": true,
+                    "post": true,
+                    "args": [
+                      {"name": "partialOkay", "type": "Bool"}
+                    ]
+                  },
                   "members": [{"id": "hostname", "name": "name"}]
                 } -->
                 <element name="host">
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 060d0e3..d9f2252 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -560,6 +560,40 @@ virNetworkDHCPDefParseXML(const char *networkName,
 }
 
 
+static int
+virNetworkDNSHostDefParseXMLPost(xmlNodePtr curnode G_GNUC_UNUSED,
+                                 virNetworkDNSHostDefPtr def,
+                                 const char *networkName,
+                                 bool partialOkay,
+                                 const char *ipStr,
+                                 int nHostnameNodes G_GNUC_UNUSED)
+{
+    if (!ipStr && !partialOkay) {
+        virReportError(VIR_ERR_XML_DETAIL,
+                       _("Missing IP address in network '%s' DNS HOST record"),
+                       networkName);
+        return -1;
+    }
+
+    if (def->nnames == 0 && !partialOkay) {
+        virReportError(VIR_ERR_XML_DETAIL,
+                       _("Missing hostname in network '%s' DNS HOST record"),
+                       networkName);
+        return -1;
+    }
+
+    if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames == 0) {
+        virReportError(VIR_ERR_XML_DETAIL,
+                       _("Missing ip and hostname in network '%s' DNS HOST record"),
+                       networkName);
+        return -1;
+    }
+
+    return 0;
+}
+
+
+/* virNetworkDNSHostDefParseXML will be replaced by generated namesake */
 static int
 virNetworkDNSHostDefParseXML(const char *networkName,
                              xmlNodePtr node,
@@ -569,13 +603,7 @@ virNetworkDNSHostDefParseXML(const char *networkName,
     xmlNodePtr cur;
     char *ip;
 
-    if (!(ip = virXMLPropString(node, "ip")) && !partialOkay) {
-        virReportError(VIR_ERR_XML_DETAIL,
-                       _("Missing IP address in network '%s' DNS HOST record"),
-                       networkName);
-        goto error;
-    }
-
+    ip = virXMLPropString(node, "ip");
     if (ip && (virSocketAddrParse(&def->ip, ip, AF_UNSPEC) < 0)) {
         virReportError(VIR_ERR_XML_DETAIL,
                        _("Invalid IP address in network '%s' DNS HOST record"),
@@ -583,7 +611,6 @@ virNetworkDNSHostDefParseXML(const char *networkName,
         VIR_FREE(ip);
         goto error;
     }
-    VIR_FREE(ip);
 
     cur = node->children;
     while (cur != NULL) {
@@ -606,23 +633,16 @@ virNetworkDNSHostDefParseXML(const char *networkName,
         }
         cur = cur->next;
     }
-    if (def->nnames == 0 && !partialOkay) {
-        virReportError(VIR_ERR_XML_DETAIL,
-                       _("Missing hostname in network '%s' DNS HOST record"),
-                       networkName);
-        goto error;
-    }
 
-    if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames == 0) {
-        virReportError(VIR_ERR_XML_DETAIL,
-                       _("Missing ip and hostname in network '%s' DNS HOST record"),
-                       networkName);
+    if (virNetworkDNSHostDefParseXMLPost(node, def, networkName,
+                                         partialOkay, ip, def->nnames) < 0)
         goto error;
-    }
 
+    VIR_FREE(ip);
     return 0;
 
  error:
+    VIR_FREE(ip);
     virNetworkDNSHostDefClear(def);
     return -1;
 }
-- 
2.17.1







[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