Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
---
po/POTFILES.in | 1 +
src/conf/meson.build | 1 +
src/conf/network_conf.c | 45 ++++++-----------------------------------
src/conf/network_conf.h | 9 ++++++---
4 files changed, 14 insertions(+), 42 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9740bb2b..fe20b9d7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
@BUILDDIR(a)src/access/viraccessapicheckqemu.c
@BUILDDIR(a)src/admin/admin_client.h
@BUILDDIR(a)src/admin/admin_server_dispatch_stubs.h
+@BUILDDIR(a)src/conf/network_conf.generated.c
@BUILDDIR(a)src/remote/remote_client_bodies.h
@BUILDDIR(a)src/remote/remote_daemon_dispatch_stubs.h
@SRCDIR(a)scripts/xmlgen/directive.py
diff --git a/src/conf/meson.build b/src/conf/meson.build
index 1439c31d..f1cfe35c 100644
--- a/src/conf/meson.build
+++ b/src/conf/meson.build
@@ -1,4 +1,5 @@
conf_xmlgen_input = [
+ 'network_conf.h',
]
conf_xmlgen_output = []
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 87157591..a6c2f11a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -174,14 +174,6 @@ virNetworkIPDefClear(virNetworkIPDef *def)
}
-static void
-virNetworkDNSTxtDefClear(virNetworkDNSTxtDef *def)
-{
- VIR_FREE(def->name);
- VIR_FREE(def->value);
-}
-
-
static void
virNetworkDNSHostDefClear(virNetworkDNSHostDef *def)
{
@@ -886,7 +878,7 @@ virNetworkDNSSrvDefParseXML(const char *networkName,
}
-static int
+int
virNetworkDNSTxtDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
virNetworkDNSTxtDef *def,
const char *networkName,
@@ -927,33 +919,6 @@ virNetworkDNSTxtDefParseHook(xmlNodePtr node G_GNUC_UNUSED,
}
-static int
-virNetworkDNSTxtDefParseXML(const char *networkName,
- xmlNodePtr node,
- virNetworkDNSTxtDef *def,
- bool partialOkay)
-{
- if (!(def->name = virXMLPropString(node, "name"))) {
- virReportError(VIR_ERR_XML_DETAIL,
- _("missing required name attribute in DNS TXT record "
- "of network %s"), networkName);
- goto error;
- }
-
- def->value = virXMLPropString(node, "value");
-
- if (virNetworkDNSTxtDefParseHook(node, def, networkName,
- NULL, &partialOkay) < 0)
- goto error;
-
- return 0;
-
- error:
- virNetworkDNSTxtDefClear(def);
- return -1;
-}
-
-
static int
virNetworkDNSDefParseXML(const char *networkName,
xmlNodePtr node,
@@ -1077,8 +1042,8 @@ virNetworkDNSDefParseXML(const char *networkName,
def->txts = g_new0(virNetworkDNSTxtDef, ntxts);
for (i = 0; i < ntxts; i++) {
- if (virNetworkDNSTxtDefParseXML(networkName, txtNodes[i],
- &def->txts[def->ntxts], false) <
0) {
+ if (virNetworkDNSTxtDefParseXML(txtNodes[i],
&def->txts[def->ntxts],
+ networkName, def, NULL) < 0) {
return -1;
}
def->ntxts++;
@@ -3614,6 +3579,7 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def,
virNetworkDNSTxtDef txt;
bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ||
command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
+ bool notAdd;
memset(&txt, 0, sizeof(txt));
@@ -3627,7 +3593,8 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def,
if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "txt") < 0)
goto cleanup;
- if (virNetworkDNSTxtDefParseXML(def->name, ctxt->node, &txt, !isAdd) <
0)
+ notAdd = !isAdd;
+ if (virNetworkDNSTxtDefParseXML(ctxt->node, &txt, def->name, def,
¬Add) < 0)
goto cleanup;
for (foundIdx = 0; foundIdx < dns->ntxts; foundIdx++) {
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index a7e6b7a2..f5720e5e 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -125,9 +125,9 @@ struct _virNetworkDHCPHostDef {
};
typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef;
-struct _virNetworkDNSTxtDef {
- char *name;
- char *value;
+struct _virNetworkDNSTxtDef { /* genparse */
+ char *name; /* xmlattr, required */
+ char *value; /* xmlattr */
};
typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
@@ -428,3 +428,6 @@ virNetworkDefUpdateSection(virNetworkDef *def,
unsigned int flags); /* virNetworkUpdateFlags */
VIR_ENUM_DECL(virNetworkTaint);
+
+#define ENABLE_VIR_NETWORK_DNSTXT_DEF_PARSE_HOOK
+#include "network_conf.generated.h"
--
2.25.1