[RFCv2 20/46] conf: Replace virNetworkDNSDefParseXML(hardcoded) with namesake(generated)

[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 | 164 +---------------------------------------
 src/conf/network_conf.h |  14 ++--
 2 files changed, 9 insertions(+), 169 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 910d23f..2f1a88b 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -174,32 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def)
 }
 
 
-static void
-virNetworkDNSDefClear(virNetworkDNSDefPtr def)
-{
-    if (def->forwarders) {
-        while (def->nfwds)
-            virNetworkDNSForwarderClear(&def->forwarders[--def->nfwds]);
-        VIR_FREE(def->forwarders);
-    }
-    if (def->txts) {
-        while (def->ntxts)
-            virNetworkDNSTxtDefClear(&def->txts[--def->ntxts]);
-        VIR_FREE(def->txts);
-    }
-    if (def->hosts) {
-        while (def->nhosts)
-            virNetworkDNSHostDefClear(&def->hosts[--def->nhosts]);
-        VIR_FREE(def->hosts);
-    }
-    if (def->srvs) {
-        while (def->nsrvs)
-            virNetworkDNSSrvDefClear(&def->srvs[--def->nsrvs]);
-        VIR_FREE(def->srvs);
-    }
-}
-
-
 static void
 virNetworkForwardDefClear(virNetworkForwardDefPtr def)
 {
@@ -882,7 +856,7 @@ virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
-static int
+int
 virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
                              virNetworkDNSDefPtr def,
                              const char *networkName,
@@ -907,140 +881,6 @@ virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
-static int
-virNetworkDNSDefParseXML(const char *networkName,
-                         xmlNodePtr node,
-                         xmlXPathContextPtr ctxt,
-                         virNetworkDNSDefPtr def)
-{
-    g_autofree xmlNodePtr *hostNodes = NULL;
-    g_autofree xmlNodePtr *srvNodes = NULL;
-    g_autofree xmlNodePtr *txtNodes = NULL;
-    g_autofree xmlNodePtr *fwdNodes = NULL;
-    g_autofree char *forwardPlainNames = NULL;
-    g_autofree char *enable = NULL;
-    int nhosts, nsrvs, ntxts, nfwds;
-    size_t i;
-    VIR_XPATH_NODE_AUTORESTORE(ctxt)
-
-    ctxt->node = node;
-
-    enable = virXPathString("string(./@enable)", ctxt);
-    if (enable) {
-        def->enable = virTristateBoolTypeFromString(enable);
-        if (def->enable <= 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid dns enable setting '%s' "
-                             "in network '%s'"),
-                           enable, networkName);
-            return -1;
-        }
-    }
-
-    forwardPlainNames = virXPathString("string(./@forwardPlainNames)", ctxt);
-    if (forwardPlainNames) {
-        def->forwardPlainNames = virTristateBoolTypeFromString(forwardPlainNames);
-        if (def->forwardPlainNames <= 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("Invalid dns forwardPlainNames setting '%s' "
-                             "in network '%s'"),
-                           forwardPlainNames, networkName);
-            return -1;
-        }
-    }
-
-    nfwds = virXPathNodeSet("./forwarder", ctxt, &fwdNodes);
-    if (nfwds < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid <forwarder> element found in <dns> of network %s"),
-                       networkName);
-        return -1;
-    }
-    if (nfwds > 0) {
-        if (VIR_ALLOC_N(def->forwarders, nfwds) < 0)
-            return -1;
-
-        for (i = 0; i < nfwds; i++) {
-            if (virNetworkDNSForwarderParseXML(fwdNodes[i],
-                                               &def->forwarders[i],
-                                               networkName,
-                                               def,
-                                               NULL) < 0)
-                return -1;
-
-            def->nfwds++;
-        }
-    }
-
-    nhosts = virXPathNodeSet("./host", ctxt, &hostNodes);
-    if (nhosts < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid <host> element found in <dns> of network %s"),
-                       networkName);
-        return -1;
-    }
-    if (nhosts > 0) {
-        if (VIR_ALLOC_N(def->hosts, nhosts) < 0)
-            return -1;
-
-        for (i = 0; i < nhosts; i++) {
-            if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def->nhosts],
-                                             networkName, def, NULL) < 0) {
-                return -1;
-            }
-            def->nhosts++;
-        }
-    }
-
-    nsrvs = virXPathNodeSet("./srv", ctxt, &srvNodes);
-    if (nsrvs < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid <srv> element found in <dns> of network %s"),
-                       networkName);
-        return -1;
-    }
-    if (nsrvs > 0) {
-        if (VIR_ALLOC_N(def->srvs, nsrvs) < 0)
-            return -1;
-
-        for (i = 0; i < nsrvs; i++) {
-            if (virNetworkDNSSrvDefParseXML(srvNodes[i], &def->srvs[def->nsrvs],
-                                            networkName, def, NULL) < 0) {
-                return -1;
-            }
-            def->nsrvs++;
-        }
-    }
-
-    ntxts = virXPathNodeSet("./txt", ctxt, &txtNodes);
-    if (ntxts < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid <txt> element found in <dns> of network %s"),
-                       networkName);
-        return -1;
-    }
-    if (ntxts > 0) {
-        if (VIR_ALLOC_N(def->txts, ntxts) < 0)
-            return -1;
-
-        for (i = 0; i < ntxts; i++) {
-            if (virNetworkDNSTxtDefParseXML(txtNodes[i], &def->txts[def->ntxts],
-                                            networkName, def, NULL) < 0) {
-                return -1;
-            }
-            def->ntxts++;
-        }
-    }
-
-    if (virNetworkDNSDefParseXMLHook(node, def, networkName, def, NULL,
-                                     enable, forwardPlainNames,
-                                     ntxts, nhosts, nsrvs, nfwds) < 0)
-        return -1;
-
-    return 0;
-}
-
-
 static int
 virNetworkIPDefParseXML(const char *networkName,
                         xmlNodePtr node,
@@ -1812,7 +1652,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
 
     dnsNode = virXPathNode("./dns", ctxt);
     if (dnsNode != NULL &&
-        virNetworkDNSDefParseXML(def->name, dnsNode, ctxt, &def->dns) < 0) {
+        virNetworkDNSDefParseXML(dnsNode, &def->dns, def->name, def, NULL) < 0) {
         return NULL;
     }
 
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 84b636e..45cfa4e 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -165,17 +165,17 @@ struct _virNetworkDNSForwarder {    /* genparse:withhook, genformat */
 
 typedef struct _virNetworkDNSDef virNetworkDNSDef;
 typedef virNetworkDNSDef *virNetworkDNSDefPtr;
-struct _virNetworkDNSDef {
-    int enable;            /* enum virTristateBool */
-    int forwardPlainNames; /* enum virTristateBool */
+struct _virNetworkDNSDef {              /* genparse:withhook */
+    virTristateBool enable;             /* xmlattr */
+    virTristateBool forwardPlainNames;  /* xmlattr */
     size_t ntxts;
-    virNetworkDNSTxtDefPtr txts;
+    virNetworkDNSTxtDefPtr txts;        /* xmlelem, array */
     size_t nhosts;
-    virNetworkDNSHostDefPtr hosts;
+    virNetworkDNSHostDefPtr hosts;      /* xmlelem, array */
     size_t nsrvs;
-    virNetworkDNSSrvDefPtr srvs;
+    virNetworkDNSSrvDefPtr srvs;        /* xmlelem, array */
     size_t nfwds;
-    virNetworkDNSForwarderPtr forwarders;
+    virNetworkDNSForwarderPtr forwarders;   /* xmlelem, array:nfwds */
 };
 
 typedef struct _virNetworkIPDef virNetworkIPDef;
-- 
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