Signed-off-by: Shi Lei <shi_lei(a)massclouds.com>
---
docs/schemas/network.rng | 13 ++++++++-
src/conf/network_conf.c | 60 +++++++++++++++++++++++++++-------------
2 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng
index 4caea02..b0f4a64 100644
--- a/docs/schemas/network.rng
+++ b/docs/schemas/network.rng
@@ -292,7 +292,18 @@
<zeroOrMore>
<!-- VIRT:DIRECTIVE {
"structure": {"output":
"src/conf/network_conf"},
- "clearfunc": {"output":
"src/conf/network_conf"}
+ "clearfunc": {"output":
"src/conf/network_conf"},
+ "parsefunc": {
+ "post": true,
+ "args.noctxt": true,
+ "args.instname": true,
+ "args": [
+ {"name": "partialOkay", "type":
"Bool"}
+ ]
+ },
+ "members": [
+ {"id": "value", "opt": true}
+ ]
} -->
<element name="txt">
<attribute name="name"><ref
name="dnsName"/></attribute>
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 0469f03..f83799f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -488,6 +488,41 @@ virSocketAddrRangeParseXML(const char *networkName,
}
+static int
+virNetworkDNSTxtDefParseXMLPost(xmlNodePtr curnode G_GNUC_UNUSED,
+ virNetworkDNSTxtDefPtr def,
+ const char *networkName,
+ bool partialOkay,
+ const char *nameStr G_GNUC_UNUSED,
+ const char *valueStr G_GNUC_UNUSED)
+{
+ const char *bad = " ,";
+
+ if (strcspn(def->name, bad) != strlen(def->name)) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("prohibited character in DNS TXT record "
+ "name '%s' of network %s"), def->name,
networkName);
+ return -1;
+ }
+
+ if (!def->value && !partialOkay) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("missing required value attribute in DNS TXT record "
+ "named '%s' of network %s"), def->name,
networkName);
+ return -1;
+ }
+
+ if (!(def->name || def->value)) {
+ virReportError(VIR_ERR_XML_DETAIL,
+ _("Missing required name or value "
+ "in DNS TXT record of network %s"), networkName);
+ return -1;
+ }
+
+ return 0;
+}
+
+
static int
virNetworkDHCPHostDefParseXML(const char *networkName,
virNetworkIPDefPtr def,
@@ -717,33 +752,20 @@ virNetworkDNSTxtDefParseXML(const char *networkName,
virNetworkDNSTxtDefPtr def,
bool partialOkay)
{
- const char *bad = " ,";
-
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;
}
- if (strcspn(def->name, bad) != strlen(def->name)) {
- virReportError(VIR_ERR_XML_DETAIL,
- _("prohibited character in DNS TXT record "
- "name '%s' of network %s"), def->name,
networkName);
- goto error;
- }
- if (!(def->value = virXMLPropString(node, "value")) &&
!partialOkay) {
- virReportError(VIR_ERR_XML_DETAIL,
- _("missing required value attribute in DNS TXT record "
- "named '%s' of network %s"), def->name,
networkName);
- goto error;
- }
- if (!(def->name || def->value)) {
- virReportError(VIR_ERR_XML_DETAIL,
- _("Missing required name or value "
- "in DNS TXT record of network %s"), networkName);
+ def->value = virXMLPropString(node, "value");
+
+ if (virNetworkDNSTxtDefParseXMLPost(node, def,
+ networkName, partialOkay,
+ def->name, def->value) < 0)
goto error;
- }
+
return 0;
error:
--
2.17.1