Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
---
src/conf/network_conf.c | 88 +++--------------------------------------
src/conf/network_conf.h | 16 ++++----
2 files changed, 14 insertions(+), 90 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 21b13ad..bfdc10b 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -183,16 +183,6 @@ virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def)
}
-static void
-virNetworkDNSSrvDefClear(virNetworkDNSSrvDefPtr def)
-{
- VIR_FREE(def->domain);
- VIR_FREE(def->service);
- VIR_FREE(def->protocol);
- VIR_FREE(def->target);
-}
-
-
static void
virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def)
{
@@ -784,7 +774,7 @@ virNetworkDNSHostDefParseXML(const char *networkName,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" \
"_-+/*"
-static int
+int
virNetworkDNSSrvDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
virNetworkDNSSrvDefPtr def,
const char *networkName,
@@ -894,74 +884,6 @@ virNetworkDNSSrvDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
}
-static int
-virNetworkDNSSrvDefParseXML(const char *networkName,
- xmlNodePtr node,
- xmlXPathContextPtr ctxt,
- virNetworkDNSSrvDefPtr def,
- bool partialOkay)
-{
- g_autofree char *portStr = NULL;
- g_autofree char *priorityStr = NULL;
- g_autofree char *weightStr = NULL;
- VIR_XPATH_NODE_AUTORESTORE(ctxt);
-
- ctxt->node = node;
-
- 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 (virNetworkDNSSrvDefParseXMLHook(node, def, networkName, &partialOkay,
- def->domain, def->service,
- def->protocol, def->target,
- portStr, priorityStr, weightStr) < 0)
- goto error;
-
- return 0;
-
- error:
- virNetworkDNSSrvDefClear(def);
- return -1;
-}
-
-
int
virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
virNetworkDNSTxtDefPtr def,
@@ -1112,8 +1034,8 @@ virNetworkDNSDefParseXML(const char *networkName,
goto cleanup;
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, NULL) < 0) {
goto cleanup;
}
def->nsrvs++;
@@ -3661,6 +3583,7 @@ virNetworkDefUpdateDNSSrv(virNetworkDefPtr 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));
@@ -3674,7 +3597,8 @@ virNetworkDefUpdateDNSSrv(virNetworkDefPtr 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, ¬Add)
< 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 b3c2895..3a4d829 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -137,14 +137,14 @@ struct _virNetworkDNSTxtDef { /* genparse:concisehook, genformat
*/
typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr;
-struct _virNetworkDNSSrvDef {
- char *domain;
- char *service;
- char *protocol;
- char *target;
- unsigned int port;
- unsigned int priority;
- unsigned int weight;
+struct _virNetworkDNSSrvDef { /* genparse:withhook */
+ char *domain; /* xmlattr */
+ char *service; /* xmlattr */
+ char *protocol; /* xmlattr */
+ char *target; /* xmlattr */
+ unsigned int port; /* xmlattr */
+ unsigned int priority; /* xmlattr */
+ unsigned int weight; /* xmlattr */
};
typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
--
2.17.1