[RFCv3 11/25] conf: Extract error-checking code from virNetworkDNSTxtDefParseXML

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

 



Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx>
---
 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 d6eafa3f..87157591 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -887,26 +887,26 @@ virNetworkDNSSrvDefParseXML(const char *networkName,
 
 
 static int
-virNetworkDNSTxtDefParseXML(const char *networkName,
-                            xmlNodePtr node,
-                            virNetworkDNSTxtDef *def,
-                            bool partialOkay)
+virNetworkDNSTxtDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
+                             virNetworkDNSTxtDef *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);
@@ -919,6 +919,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,
+                            virNetworkDNSTxtDef *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 (virNetworkDNSTxtDefParseHook(node, def, networkName,
+                                     NULL, &partialOkay) < 0)
+        goto error;
+
     return 0;
 
  error:
-- 
2.25.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