Reorder the members of virNetworkDNSDef according to their orders in format function. Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/conf/network_conf.c | 160 +--------------------------------------- src/conf/network_conf.h | 19 ++--- 2 files changed, 12 insertions(+), 167 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 19408987..364c10e2 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,32 +174,6 @@ virNetworkIPDefClear(virNetworkIPDef *def) } -static void -virNetworkDNSDefClear(virNetworkDNSDef *def) -{ - if (def->forwarders) { - while (def->nfwds) - virNetworkDNSForwarderClear(&def->forwarders[--def->nfwds]); - VIR_FREE(def->forwarders); - } - if (def->txts) { - while (def->ntxts) - virNetworkDNSTxtDefClear(&def->txts[--def->ntxts]); - VIR_FREE(def->txts); - } - if (def->hosts) { - while (def->nhosts) - virNetworkDNSHostDefClear(&def->hosts[--def->nhosts]); - VIR_FREE(def->hosts); - } - if (def->srvs) { - while (def->nsrvs) - virNetworkDNSSrvDefClear(&def->srvs[--def->nsrvs]); - VIR_FREE(def->srvs); - } -} - - static void virNetworkForwardDefClear(virNetworkForwardDef *def) { @@ -883,7 +857,7 @@ virNetworkDNSForwarderParseHook(xmlNodePtr node G_GNUC_UNUSED, } -static int +int virNetworkDNSDefParseHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSDef *def, const char *networkName, @@ -908,136 +882,6 @@ virNetworkDNSDefParseHook(xmlNodePtr node G_GNUC_UNUSED, } -static int -virNetworkDNSDefParseXML(const char *networkName, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - virNetworkDNSDef *def) -{ - g_autofree xmlNodePtr *hostNodes = NULL; - g_autofree xmlNodePtr *srvNodes = NULL; - g_autofree xmlNodePtr *txtNodes = NULL; - g_autofree xmlNodePtr *fwdNodes = NULL; - g_autofree char *forwardPlainNames = NULL; - g_autofree char *enable = NULL; - int nhosts, nsrvs, ntxts, nfwds; - size_t i; - VIR_XPATH_NODE_AUTORESTORE(ctxt) - - ctxt->node = node; - - enable = virXPathString("string(./@enable)", ctxt); - if (enable) { - def->enable = virTristateBoolTypeFromString(enable); - if (def->enable <= 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid dns enable setting '%s' " - "in network '%s'"), - enable, networkName); - return -1; - } - } - - forwardPlainNames = virXPathString("string(./@forwardPlainNames)", ctxt); - if (forwardPlainNames) { - def->forwardPlainNames = virTristateBoolTypeFromString(forwardPlainNames); - if (def->forwardPlainNames <= 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid dns forwardPlainNames setting '%s' " - "in network '%s'"), - forwardPlainNames, networkName); - return -1; - } - } - - nfwds = virXPathNodeSet("./forwarder", ctxt, &fwdNodes); - if (nfwds < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid <forwarder> element found in <dns> of network %s"), - networkName); - return -1; - } - if (nfwds > 0) { - def->forwarders = g_new0(virNetworkDNSForwarder, nfwds); - - for (i = 0; i < nfwds; i++) { - if (virNetworkDNSForwarderParseXML(fwdNodes[i], - &def->forwarders[i], - networkName, - def, - NULL) < 0) - return -1; - - def->nfwds++; - } - } - - nhosts = virXPathNodeSet("./host", ctxt, &hostNodes); - if (nhosts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid <host> element found in <dns> of network %s"), - networkName); - return -1; - } - if (nhosts > 0) { - def->hosts = g_new0(virNetworkDNSHostDef, nhosts); - - for (i = 0; i < nhosts; i++) { - if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def->nhosts], - networkName, def, NULL) < 0) { - return -1; - } - def->nhosts++; - } - } - - nsrvs = virXPathNodeSet("./srv", ctxt, &srvNodes); - if (nsrvs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid <srv> element found in <dns> of network %s"), - networkName); - return -1; - } - if (nsrvs > 0) { - def->srvs = g_new0(virNetworkDNSSrvDef, nsrvs); - - for (i = 0; i < nsrvs; i++) { - if (virNetworkDNSSrvDefParseXML(srvNodes[i], &def->srvs[def->nsrvs], - networkName, def, NULL) < 0) { - return -1; - } - def->nsrvs++; - } - } - - ntxts = virXPathNodeSet("./txt", ctxt, &txtNodes); - if (ntxts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid <txt> element found in <dns> of network %s"), - networkName); - return -1; - } - if (ntxts > 0) { - def->txts = g_new0(virNetworkDNSTxtDef, ntxts); - - for (i = 0; i < ntxts; i++) { - if (virNetworkDNSTxtDefParseXML(txtNodes[i], &def->txts[def->ntxts], - networkName, def, NULL) < 0) { - return -1; - } - def->ntxts++; - } - } - - if (virNetworkDNSDefParseHook(node, def, networkName, def, NULL, - enable, forwardPlainNames, - nfwds, ntxts, nsrvs, nhosts) < 0) - return -1; - - return 0; -} - - static int virNetworkIPDefParseXML(const char *networkName, xmlNodePtr node, @@ -1795,7 +1639,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, dnsNode = virXPathNode("./dns", ctxt); if (dnsNode != NULL && - virNetworkDNSDefParseXML(def->name, dnsNode, ctxt, &def->dns) < 0) { + virNetworkDNSDefParseXML(dnsNode, &def->dns, def->name, def, NULL) < 0) { return NULL; } diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 577c1568..9968d962 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -156,17 +156,17 @@ struct _virNetworkDNSForwarder { /* genparse, genformat */ }; typedef struct _virNetworkDNSDef virNetworkDNSDef; -struct _virNetworkDNSDef { - int enable; /* enum virTristateBool */ - int forwardPlainNames; /* enum virTristateBool */ +struct _virNetworkDNSDef { /* genparse */ + virTristateBool enable; /* xmlattr */ + virTristateBool forwardPlainNames; /* xmlattr */ + size_t nfwds; + virNetworkDNSForwarder *forwarders; /* xmlelem, array:nfwds */ size_t ntxts; - virNetworkDNSTxtDef *txts; - size_t nhosts; - virNetworkDNSHostDef *hosts; + virNetworkDNSTxtDef *txts; /* xmlelem, array */ size_t nsrvs; - virNetworkDNSSrvDef *srvs; - size_t nfwds; - virNetworkDNSForwarder *forwarders; + virNetworkDNSSrvDef *srvs; /* xmlelem, array */ + size_t nhosts; + virNetworkDNSHostDef *hosts; /* xmlelem, array */ }; typedef struct _virNetworkIPDef virNetworkIPDef; @@ -429,6 +429,7 @@ virNetworkDefUpdateSection(virNetworkDef *def, VIR_ENUM_DECL(virNetworkTaint); +#define ENABLE_VIR_NETWORK_DNSDEF_PARSE_HOOK #define ENABLE_VIR_NETWORK_DNSFORWARDER_PARSE_HOOK #define ENABLE_VIR_NETWORK_DNSHOST_DEF_PARSE_HOOK #define ENABLE_VIR_NETWORK_DNSSRV_DEF_PARSE_HOOK -- 2.25.1