[RFCv3 15/25] conf: Replace virNetworkDNSSrvDefParseXML(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 | 83 +++--------------------------------------
 src/conf/network_conf.h | 17 +++++----
 2 files changed, 15 insertions(+), 85 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 20128af0..cb2f3163 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -183,16 +183,6 @@ virNetworkDNSHostDefClear(virNetworkDNSHostDef *def)
 }
 
 
-static void
-virNetworkDNSSrvDefClear(virNetworkDNSSrvDef *def)
-{
-    VIR_FREE(def->domain);
-    VIR_FREE(def->service);
-    VIR_FREE(def->protocol);
-    VIR_FREE(def->target);
-}
-
-
 static void
 virNetworkDNSForwarderClear(virNetworkDNSForwarder *def)
 {
@@ -767,7 +757,7 @@ virNetworkDNSHostDefParseXML(const char *networkName,
     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" \
     "_-+/*"
 
-static int
+int
 virNetworkDNSSrvDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
                              virNetworkDNSSrvDef *def,
                              const char *networkName,
@@ -874,69 +864,6 @@ virNetworkDNSSrvDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
 }
 
 
-static int
-virNetworkDNSSrvDefParseXML(const char *networkName,
-                            xmlNodePtr node,
-                            xmlXPathContextPtr ctxt G_GNUC_UNUSED,
-                            virNetworkDNSSrvDef *def,
-                            bool partialOkay)
-{
-    g_autofree char *portStr = NULL;
-    g_autofree char *priorityStr = NULL;
-    g_autofree char *weightStr = NULL;
-
-    def->service = virXMLPropString(node, "service");
-    def->protocol = virXMLPropString(node, "protocol");
-
-    /* Following attributes are optional */
-    def->domain = virXMLPropString(node, "domain");
-    def->target = virXMLPropString(node, "target");
-
-    portStr = virXMLPropString(node, "port");
-    if (portStr) {
-        if (virStrToLong_uip(portStr, NULL, 0, &def->port) < 0) {
-            virReportError(VIR_ERR_XML_DETAIL,
-                           _("invalid DNS SRV port attribute "
-                             "for service '%s' in network '%s'"),
-                           def->service, networkName);
-            goto error;
-        }
-    }
-
-    priorityStr = virXMLPropString(node, "priority");
-    if (priorityStr) {
-        if (virStrToLong_uip(priorityStr, NULL, 0, &def->priority) < 0) {
-            virReportError(VIR_ERR_XML_DETAIL,
-                           _("Invalid DNS SRV priority attribute "
-                             "for service '%s' in network '%s'"),
-                           def->service, networkName);
-            goto error;
-        }
-    }
-
-    weightStr = virXMLPropString(node, "weight");
-    if (weightStr) {
-        if (virStrToLong_uip(weightStr, NULL, 0, &def->weight) < 0) {
-            virReportError(VIR_ERR_XML_DETAIL,
-                           _("invalid DNS SRV weight attribute "
-                             "for service '%s' in network '%s'"),
-                           def->service, networkName);
-            goto error;
-        }
-    }
-
-    if (virNetworkDNSSrvDefParseHook(node, def, networkName, def, &partialOkay,
-                                     portStr, priorityStr, weightStr) < 0)
-        goto error;
-
-    return 0;
-
- error:
-    virNetworkDNSSrvDefClear(def);
-    return -1;
-}
-
-
 int
 virNetworkDNSTxtDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
                              virNetworkDNSTxtDef *def,
@@ -1082,8 +1009,8 @@ virNetworkDNSDefParseXML(const char *networkName,
         def->srvs = g_new0(virNetworkDNSSrvDef, nsrvs);
 
         for (i = 0; i < nsrvs; i++) {
-            if (virNetworkDNSSrvDefParseXML(networkName, srvNodes[i], ctxt,
-                                            &def->srvs[def->nsrvs], false) < 0) {
+            if (virNetworkDNSSrvDefParseXML(srvNodes[i], &def->srvs[def->nsrvs],
+                                            networkName, def, NULL) < 0) {
                 return -1;
             }
             def->nsrvs++;
@@ -3553,6 +3480,7 @@ virNetworkDefUpdateDNSSrv(virNetworkDef *def,
     bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ||
                   command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
     int foundCt = 0;
+    bool notAdd;
 
     memset(&srv, 0, sizeof(srv));
 
@@ -3566,7 +3494,8 @@ virNetworkDefUpdateDNSSrv(virNetworkDef *def,
     if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "srv") < 0)
         goto cleanup;
 
-    if (virNetworkDNSSrvDefParseXML(def->name, ctxt->node, ctxt, &srv, !isAdd) < 0)
+    notAdd = !isAdd;
+    if (virNetworkDNSSrvDefParseXML(ctxt->node, &srv, def->name, def, &notAdd) < 0)
         goto cleanup;
 
     for (i = 0; i < dns->nsrvs; i++) {
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index a4c83b46..a58d8953 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -131,14 +131,14 @@ struct _virNetworkDNSTxtDef {   /* genparse, genformat */
 };
 
 typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
-struct _virNetworkDNSSrvDef {
-    char *domain;
-    char *service;
-    char *protocol;
-    char *target;
-    unsigned int port;
-    unsigned int priority;
-    unsigned int weight;
+struct _virNetworkDNSSrvDef {   /* genparse */
+    char *service;              /* xmlattr */
+    char *protocol;             /* xmlattr */
+    char *domain;               /* xmlattr */
+    char *target;               /* xmlattr */
+    unsigned int port;          /* xmlattr */
+    unsigned int priority;      /* xmlattr */
+    unsigned int weight;        /* xmlattr */
 };
 
 typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
@@ -429,5 +429,6 @@ virNetworkDefUpdateSection(virNetworkDef *def,
 
 VIR_ENUM_DECL(virNetworkTaint);
 
+#define ENABLE_VIR_NETWORK_DNSSRV_DEF_PARSE_HOOK
 #define ENABLE_VIR_NETWORK_DNSTXT_DEF_PARSE_HOOK
 #include "network_conf.generated.h"
-- 
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