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

[RFCv2 13/46] conf: Extract error-checking code from virNetworkDNSHostDefParseXML



Signed-off-by: Shi Lei <shi_lei massclouds com>
---
 src/conf/network_conf.c | 63 +++++++++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 18 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 518f6da..44032e6 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -675,21 +675,57 @@ virNetworkDHCPDefParseXML(const char *networkName,
 
 
 static int
-virNetworkDNSHostDefParseXML(const char *networkName,
-                             xmlNodePtr node,
-                             virNetworkDNSHostDefPtr def,
-                             bool partialOkay)
+virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
+                                 virNetworkDNSHostDefPtr def,
+                                 const char *networkName,
+                                 void *parent G_GNUC_UNUSED,
+                                 void *opaque,
+                                 const char *ip,
+                                 int nHostnameNodes G_GNUC_UNUSED)
 {
-    xmlNodePtr cur;
-    g_autofree char *ip = NULL;
+    bool partialOkay = false;
 
-    if (!(ip = virXMLPropString(node, "ip")) && !partialOkay) {
+    if (opaque)
+        partialOkay = *((bool *) opaque);
+
+    if (!ip && !partialOkay) {
         virReportError(VIR_ERR_XML_DETAIL,
                        _("Missing IP address in network '%s' DNS HOST record"),
                        networkName);
         goto error;
     }
 
+    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);
+        goto error;
+    }
+
+    return 0;
+
+ error:
+    return -1;
+}
+
+
+static int
+virNetworkDNSHostDefParseXML(const char *networkName,
+                             xmlNodePtr node,
+                             virNetworkDNSHostDefPtr def,
+                             bool partialOkay)
+{
+    xmlNodePtr cur;
+    g_autofree char *ip = NULL;
+
+    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"),
@@ -719,19 +755,10 @@ 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 (virNetworkDNSHostDefParseXMLHook(node, def, networkName, def, &partialOkay,
+                                         ip, def->nnames) < 0)
         goto error;
-    }
 
     return 0;
 
-- 
2.25.1



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