[RFC 14/21] conf: Replace virNetworkDNSHostDefParseXML(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 | 72 ++++-------------------------------------
 src/conf/network_conf.h |  6 ++--
 2 files changed, 10 insertions(+), 68 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 7a3dcd4..29ef3cf 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -174,15 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def)
 }
 
 
-static void
-virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def)
-{
-    while (def->nnames)
-        VIR_FREE(def->names[--def->nnames]);
-    VIR_FREE(def->names);
-}
-
-
 static void
 virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def)
 {
@@ -691,12 +682,12 @@ virNetworkDHCPDefParseXML(const char *networkName,
 }
 
 
-static int
+int
 virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
                                  virNetworkDNSHostDefPtr def,
                                  const char *networkName,
                                  void *opaque,
-                                 char *ip,
+                                 const char *ip,
                                  int nHostnameNodes G_GNUC_UNUSED)
 {
     bool partialOkay = false;
@@ -732,57 +723,6 @@ virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
-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"),
-                       networkName);
-        goto error;
-    }
-
-    cur = node->children;
-    while (cur != NULL) {
-        if (cur->type == XML_ELEMENT_NODE &&
-            virXMLNodeNameEqual(cur, "hostname")) {
-              if (cur->children != NULL) {
-                  char *name = (char *) xmlNodeGetContent(cur);
-
-                  if (!name) {
-                      virReportError(VIR_ERR_XML_DETAIL,
-                                     _("Missing hostname in network '%s' DNS HOST record"),
-                                     networkName);
-                      goto error;
-                  }
-                  if (VIR_APPEND_ELEMENT(def->names, def->nnames, name) < 0) {
-                      VIR_FREE(name);
-                      goto error;
-                  }
-              }
-        }
-        cur = cur->next;
-    }
-
-    if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, &partialOkay,
-                                         ip, def->nnames) < 0)
-        goto error;
-
-    return 0;
-
- error:
-    virNetworkDNSHostDefClear(def);
-    return -1;
-}
-
-
 /* This includes all characters used in the names of current
  * /etc/services and /etc/protocols files (on Fedora 20), except ".",
  * which we can't allow because it would conflict with the use of "."
@@ -1038,8 +978,8 @@ virNetworkDNSDefParseXML(const char *networkName,
             goto cleanup;
 
         for (i = 0; i < nhosts; i++) {
-            if (virNetworkDNSHostDefParseXML(networkName, hostNodes[i],
-                                             &def->hosts[def->nhosts], false) < 0) {
+            if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def->nhosts],
+                                             networkName, NULL) < 0) {
                 goto cleanup;
             }
             def->nhosts++;
@@ -3498,6 +3438,7 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def,
     bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ||
                   command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
     int foundCt = 0;
+    bool notAdd;
 
     memset(&host, 0, sizeof(host));
 
@@ -3511,7 +3452,8 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def,
     if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0)
         goto cleanup;
 
-    if (virNetworkDNSHostDefParseXML(def->name, ctxt->node, &host, !isAdd) < 0)
+    notAdd = !isAdd;
+    if (virNetworkDNSHostDefParseXML(ctxt->node, &host, def->name, &notAdd) < 0)
         goto cleanup;
 
     for (i = 0; i < dns->nhosts; i++) {
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index c867f27..b715dc3 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -149,10 +149,10 @@ struct _virNetworkDNSSrvDef {   /* genparse:withhook, genformat */
 
 typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
 typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
-struct _virNetworkDNSHostDef {
-    virSocketAddr ip;
+struct _virNetworkDNSHostDef {  /* genparse:withhook */
+    virSocketAddr ip;           /* xmlattr */
     size_t nnames;
-    char **names;
+    char **names;               /* xmlelem:hostname, array */
 };
 
 
-- 
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