[RFC 16/29] 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>
---
 docs/schemas/network.rng |  7 +++--
 po/POTFILES.in           |  1 +
 src/conf/network_conf.c  | 66 +++++-----------------------------------
 3 files changed, 13 insertions(+), 61 deletions(-)

diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng
index ee4487e..c902f7e 100644
--- a/docs/schemas/network.rng
+++ b/docs/schemas/network.rng
@@ -337,14 +337,17 @@
                   "structure": {"output": "src/conf/network_conf"},
                   "clearfunc": {"output": "src/conf/network_conf"},
                   "parsefunc": {
-                    "args.noctxt": true,
+                    "output": "src/conf/network_conf",
                     "args.instname": true,
                     "post": true,
                     "args": [
                       {"name": "partialOkay", "type": "Bool"}
                     ]
                   },
-                  "members": [{"id": "hostname", "name": "name"}]
+                  "members": [
+                    {"id": "ip", "opt": true},
+                    {"id": "hostname", "name": "name", "opt": true}
+                  ]
                 } -->
                 <element name="host">
                   <attribute name="ip"><ref name="ipAddr"/></attribute>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2358b01..5e2985a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
 @BUILDDIR@/src/access/viraccessapicheckqemu.c
 @BUILDDIR@/src/admin/admin_client.h
 @BUILDDIR@/src/admin/admin_server_dispatch_stubs.h
+@BUILDDIR@/src/conf/network_conf.generated.c
 @BUILDDIR@/src/remote/remote_client_bodies.h
 @BUILDDIR@/src/remote/remote_daemon_dispatch_stubs.h
 @SRCDIR@/rng2c/directive.py
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index d9f2252..6f0722a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -560,9 +560,10 @@ virNetworkDHCPDefParseXML(const char *networkName,
 }
 
 
-static int
+int
 virNetworkDNSHostDefParseXMLPost(xmlNodePtr curnode G_GNUC_UNUSED,
                                  virNetworkDNSHostDefPtr def,
+                                 xmlXPathContextPtr ctxt G_GNUC_UNUSED,
                                  const char *networkName,
                                  bool partialOkay,
                                  const char *ipStr,
@@ -593,61 +594,6 @@ virNetworkDNSHostDefParseXMLPost(xmlNodePtr curnode G_GNUC_UNUSED,
 }
 
 
-/* virNetworkDNSHostDefParseXML will be replaced by generated namesake */
-static int
-virNetworkDNSHostDefParseXML(const char *networkName,
-                             xmlNodePtr node,
-                             virNetworkDNSHostDefPtr def,
-                             bool partialOkay)
-{
-    xmlNodePtr cur;
-    char *ip;
-
-    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);
-        VIR_FREE(ip);
-        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 (virNetworkDNSHostDefParseXMLPost(node, def, networkName,
-                                         partialOkay, ip, def->nnames) < 0)
-        goto error;
-
-    VIR_FREE(ip);
-    return 0;
-
- error:
-    VIR_FREE(ip);
-    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 "."
@@ -907,8 +853,10 @@ 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],
+                                             ctxt,
+                                             networkName, false) < 0) {
                 goto cleanup;
             }
             def->nhosts++;
@@ -3373,7 +3321,7 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def,
     if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0)
         goto cleanup;
 
-    if (virNetworkDNSHostDefParseXML(def->name, ctxt->node, &host, !isAdd) < 0)
+    if (virNetworkDNSHostDefParseXML(ctxt->node, &host, ctxt, def->name, !isAdd) < 0)
         goto cleanup;
 
     for (i = 0; i < dns->nhosts; i++) {
-- 
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