[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[RFCv2 21/46] conf: Generate virNetworkDNSDefFormatBuf



Signed-off-by: Shi Lei <shi_lei massclouds com>
---
 src/conf/network_conf.c | 77 ++---------------------------------------
 src/conf/network_conf.h | 10 +++---
 2 files changed, 8 insertions(+), 79 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 2f1a88b..3a126d4 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -864,10 +864,10 @@ virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED,
                              void *opaque G_GNUC_UNUSED,
                              const char *enable G_GNUC_UNUSED,
                              const char *forwardPlainNames G_GNUC_UNUSED,
+                             int nfwds,
                              int ntxts,
-                             int nhosts,
                              int nsrvs,
-                             int nfwds)
+                             int nhosts)
 {
     if (def->enable == VIR_TRISTATE_BOOL_NO &&
         (nfwds || nhosts || nsrvs || ntxts)) {
@@ -1975,77 +1975,6 @@ virNetworkDefParseNode(xmlDocPtr xml,
 }
 
 
-static int
-virNetworkDNSDefFormat(virBufferPtr buf,
-                       const virNetworkDNSDef *def)
-{
-    size_t i;
-
-    if (!(def->enable || def->forwardPlainNames || def->nfwds || def->nhosts ||
-          def->nsrvs || def->ntxts))
-        return 0;
-
-    virBufferAddLit(buf, "<dns");
-    if (def->enable) {
-        const char *fwd = virTristateBoolTypeToString(def->enable);
-
-        if (!fwd) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Unknown enable type %d in network"),
-                           def->enable);
-            return -1;
-        }
-        virBufferAsprintf(buf, " enable='%s'", fwd);
-    }
-    if (def->forwardPlainNames) {
-        const char *fwd = virTristateBoolTypeToString(def->forwardPlainNames);
-
-        if (!fwd) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Unknown forwardPlainNames type %d in network"),
-                           def->forwardPlainNames);
-            return -1;
-        }
-        virBufferAsprintf(buf, " forwardPlainNames='%s'", fwd);
-    }
-    if (!(def->nfwds || def->nhosts || def->nsrvs || def->ntxts)) {
-        virBufferAddLit(buf, "/>\n");
-        return 0;
-    }
-
-    virBufferAddLit(buf, ">\n");
-    virBufferAdjustIndent(buf, 2);
-
-    for (i = 0; i < def->nfwds; i++) {
-        if (virNetworkDNSForwarderFormatBuf(buf, "forwarder",
-                                            &def->forwarders[i], def, NULL) < 0)
-            return -1;
-    }
-
-    for (i = 0; i < def->ntxts; i++) {
-        if (virNetworkDNSTxtDefFormatBuf(buf, "txt", &def->txts[i], def, NULL) < 0)
-            return -1;
-    }
-
-    for (i = 0; i < def->nsrvs; i++) {
-        if (def->srvs[i].service && def->srvs[i].protocol) {
-            if (virNetworkDNSSrvDefFormatBuf(buf, "srv", &def->srvs[i], def, NULL) < 0)
-                return -1;
-        }
-    }
-
-    if (def->nhosts) {
-        for (i = 0; i < def->nhosts; i++) {
-            if (virNetworkDNSHostDefFormatBuf(buf, "host", &def->hosts[i], def, NULL) < 0)
-                return -1;
-        }
-    }
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</dns>\n");
-    return 0;
-}
-
-
 static int
 virNetworkIPDefFormat(virBufferPtr buf,
                       const virNetworkIPDef *def)
@@ -2455,7 +2384,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
         virBufferAddLit(buf, "/>\n");
     }
 
-    if (virNetworkDNSDefFormat(buf, &def->dns) < 0)
+    if (virNetworkDNSDefFormatBuf(buf, "dns", &def->dns, def, NULL) < 0)
         return -1;
 
     if (virNetDevVlanFormat(&def->vlan, buf) < 0)
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 45cfa4e..60739bb 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -165,17 +165,17 @@ struct _virNetworkDNSForwarder {    /* genparse:withhook, genformat */
 
 typedef struct _virNetworkDNSDef virNetworkDNSDef;
 typedef virNetworkDNSDef *virNetworkDNSDefPtr;
-struct _virNetworkDNSDef {              /* genparse:withhook */
+struct _virNetworkDNSDef {              /* genparse:withhook, genformat */
     virTristateBool enable;             /* xmlattr */
     virTristateBool forwardPlainNames;  /* xmlattr */
+    size_t nfwds;
+    virNetworkDNSForwarderPtr forwarders;   /* xmlelem, array:nfwds */
     size_t ntxts;
     virNetworkDNSTxtDefPtr txts;        /* xmlelem, array */
-    size_t nhosts;
-    virNetworkDNSHostDefPtr hosts;      /* xmlelem, array */
     size_t nsrvs;
     virNetworkDNSSrvDefPtr srvs;        /* xmlelem, array */
-    size_t nfwds;
-    virNetworkDNSForwarderPtr forwarders;   /* xmlelem, array:nfwds */
+    size_t nhosts;
+    virNetworkDNSHostDefPtr hosts;      /* xmlelem, array */
 };
 
 typedef struct _virNetworkIPDef virNetworkIPDef;
-- 
2.25.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]