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

[RFCv2 07/46] conf: Extract error-checking code from virNetworkDNSTxtDefParseXML



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

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 2fcd498..9ca8f74 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -886,26 +886,26 @@ virNetworkDNSSrvDefParseXML(const char *networkName,
 
 
 static int
-virNetworkDNSTxtDefParseXML(const char *networkName,
-                            xmlNodePtr node,
-                            virNetworkDNSTxtDefPtr def,
-                            bool partialOkay)
+virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
+                                virNetworkDNSTxtDefPtr def,
+                                const char *networkName,
+                                void *parent G_GNUC_UNUSED,
+                                void *opaque)
 {
     const char *bad = " ,";
+    bool partialOkay = false;
+
+    if (opaque)
+        partialOkay = *((bool *) opaque);
 
-    if (!(def->name = virXMLPropString(node, "name"))) {
-        virReportError(VIR_ERR_XML_DETAIL,
-                       _("missing required name attribute in DNS TXT record "
-                         "of network %s"), networkName);
-        goto error;
-    }
     if (strcspn(def->name, bad) != strlen(def->name)) {
         virReportError(VIR_ERR_XML_DETAIL,
                        _("prohibited character in DNS TXT record "
                          "name '%s' of network %s"), def->name, networkName);
         goto error;
     }
-    if (!(def->value = virXMLPropString(node, "value")) && !partialOkay) {
+
+    if (!def->value && !partialOkay) {
         virReportError(VIR_ERR_XML_DETAIL,
                        _("missing required value attribute in DNS TXT record "
                          "named '%s' of network %s"), def->name, networkName);
@@ -918,6 +918,33 @@ virNetworkDNSTxtDefParseXML(const char *networkName,
                          "in DNS TXT record of network %s"), networkName);
         goto error;
     }
+
+    return 0;
+
+ error:
+    return -1;
+}
+
+
+static int
+virNetworkDNSTxtDefParseXML(const char *networkName,
+                            xmlNodePtr node,
+                            virNetworkDNSTxtDefPtr def,
+                            bool partialOkay)
+{
+    if (!(def->name = virXMLPropString(node, "name"))) {
+        virReportError(VIR_ERR_XML_DETAIL,
+                       _("missing required name attribute in DNS TXT record "
+                         "of network %s"), networkName);
+        goto error;
+    }
+
+    def->value = virXMLPropString(node, "value");
+
+    if (virNetworkDNSTxtDefParseXMLHook(node, def, networkName,
+                                        NULL, &partialOkay) < 0)
+        goto error;
+
     return 0;
 
  error:
-- 
2.25.1



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