>From 3ba1ff01079e2bf8f6ec722afe335edae9c80b8a Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Mon, 13 Jun 2011 20:19:14 -0400 Subject: [PATCH] squash to TXT records 1/5 --- docs/formatnetwork.html.in | 7 +++---- docs/schemas/network.rng | 9 ++++++++- src/conf/network_conf.c | 39 ++++++++++++++++++++++++++------------- src/network/bridge_driver.c | 14 ++++++-------- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index 008897d..1cf7636 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -172,7 +172,7 @@
dns
The dns element of a network contains configuration information for the - virtual network's DNS server. Since 0.9.1 + virtual network's DNS server. Since 0.9.3 Currently supported elements are:
txt
@@ -180,9 +180,8 @@ Each txt element defines a DNS TXT record and has two attributes, both required: a name that can be queried via dns, and a value that will be returned when that name is queried. names cannot contain embedded spaces - or commas. value is a single string that can contain multiple values which are - comma-separated which is allowed for the TXT records and it is represented a - single value. Since 0.9.1 + or commas. value is a single string that can contain multiple values + separated by commas. Since 0.9.3
dhcp
Also within the ip element there is an diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 3780af5..f6b3a4d 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -93,7 +93,7 @@ - + @@ -196,4 +196,11 @@ + + + + ([a-zA-Z\-]+ + + + diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 133ac84..93e931f 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -104,6 +104,20 @@ static void virNetworkIpDefClear(virNetworkIpDefPtr def) VIR_FREE(def->bootfile); } +static void virNetworkDNSDefFree(virNetworkDNSDefPtr def) +{ + if (def) { + if (def->txtrecords) { + while (def->ntxtrecords--) { + VIR_FREE(def->txtrecords[def->ntxtrecords].name); + VIR_FREE(def->txtrecords[def->ntxtrecords].value); + } + VIR_FREE(def->txtrecords); + } + VIR_FREE(def); + } +} + void virNetworkDefFree(virNetworkDefPtr def) { int ii; @@ -121,6 +135,8 @@ void virNetworkDefFree(virNetworkDefPtr def) } VIR_FREE(def->ips); + virNetworkDNSDefFree(def->dns); + VIR_FREE(def); } @@ -454,18 +470,19 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef, if (cur->type == XML_ELEMENT_NODE && xmlStrEqual(cur->name, BAD_CAST "txt")) { if (!(name = virXMLPropString(cur, "name"))) { - cur = cur->next; - continue; + virNetworkReportError(VIR_ERR_XML_DETAIL, + "%s", _("Missing required name attribute in dns txt record")); + goto error; } if (!(value = virXMLPropString(cur, "value"))) { - VIR_FREE(name); - cur = cur->next; - continue; + virNetworkReportError(VIR_ERR_XML_DETAIL, + _("Missing required value attribute in dns txt record '%s'"), name); + goto error; } if (strchr(name, ' ') != NULL) { virNetworkReportError(VIR_ERR_XML_DETAIL, - _("TXT record names in DNS don't support spaces in names (name is '%s')"), name); + _("spaces are not allowed in DNS TXT record names (name is '%s')"), name); goto error; } @@ -485,15 +502,12 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef, ret = 0; error: if (ret < 0) { - name = NULL; - value = NULL; VIR_FREE(name); VIR_FREE(value); - } - else - if (dnsdef != NULL) + virNetworkDNSDefFree(def); + } else { *dnsdef = def; - + } return ret; } @@ -765,7 +779,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) error: virNetworkDefFree(def); VIR_FREE(ipNodes); - VIR_FREE(dnsNode); return NULL; } diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 169bc08..a2cba05 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -515,18 +515,16 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, int i; for (i = 0; i < dns->ntxtrecords; i++) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - virBufferAsprintf(&buf, "%s,%s", - dns->txtrecords[i].name, - dns->txtrecords[i].value); - - if (virBufferError(&buf)) { + char *record = NULL; + if (virAsprintf(&record, "%s,%s", + dns->txtrecords[i].name, + dns->txtrecords[i].value) < 0) { virReportOOMError(); goto cleanup; } - virCommandAddArgPair(cmd, "--txt-record", virBufferContentAndReset(&buf)); - virBufferFreeAndReset(&buf); + virCommandAddArgPair(cmd, "--txt-record", record); + VIR_FREE(record); } } -- 1.7.3.4