[RFC 21/21] conf: Generate virNetworkDNSDefFormatBuf

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

 



Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx>
---
 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 db2b75f..604e589 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -881,10 +881,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)) {
@@ -2024,77 +2024,6 @@ virNetworkDefParseNode(xmlDocPtr xml,
 }
 
 
-static int
-virNetworkDNSDefFormat(virBufferPtr buf,
-                       const virNetworkDNSDef *def)
-{
-    size_t i;
-
-    if (!(def->enable || def->forwardPlainNames || def->nforwarders || 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->nforwarders || def->nhosts || def->nsrvs || def->ntxts)) {
-        virBufferAddLit(buf, "/>\n");
-        return 0;
-    }
-
-    virBufferAddLit(buf, ">\n");
-    virBufferAdjustIndent(buf, 2);
-
-    for (i = 0; i < def->nforwarders; i++) {
-        if (virNetworkDNSForwarderFormatBuf(buf, "forwarder",
-                                            &def->forwarders[i], NULL) < 0)
-            return -1;
-    }
-
-    for (i = 0; i < def->ntxts; i++) {
-        if (virNetworkDNSTxtDefFormatBuf(buf, "txt", &def->txts[i], 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], NULL) < 0)
-                return -1;
-        }
-    }
-
-    if (def->nhosts) {
-        for (i = 0; i < def->nhosts; i++) {
-            if (virNetworkDNSHostDefFormatBuf(buf, "host", &def->hosts[i], NULL) < 0)
-                return -1;
-        }
-    }
-    virBufferAdjustIndent(buf, -2);
-    virBufferAddLit(buf, "</dns>\n");
-    return 0;
-}
-
-
 static int
 virNetworkIPDefFormat(virBufferPtr buf,
                       const virNetworkIPDef *def)
@@ -2502,7 +2431,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
         virBufferAddLit(buf, "/>\n");
     }
 
-    if (virNetworkDNSDefFormat(buf, &def->dns) < 0)
+    if (virNetworkDNSDefFormatBuf(buf, "dns", &def->dns, 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 462d97d..cfbd7c9 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 nforwarders;
+    virNetworkDNSForwarderPtr forwarders;   /* xmlelem, array */
     size_t ntxts;
     virNetworkDNSTxtDefPtr txts;        /* xmlelem, array */
-    size_t nhosts;
-    virNetworkDNSHostDefPtr hosts;      /* xmlelem, array */
     size_t nsrvs;
     virNetworkDNSSrvDefPtr srvs;        /* xmlelem, array */
-    size_t nforwarders;
-    virNetworkDNSForwarderPtr forwarders;   /* xmlelem, array */
+    size_t nhosts;
+    virNetworkDNSHostDefPtr hosts;      /* xmlelem, array */
 };
 
 typedef struct _virNetworkIPDef virNetworkIPDef;
-- 
2.17.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux