[libvirt] [PATCH 07/19] util: Introduce virSecretFormatSecret

John Ferlan jferlan at redhat.com
Tue Jun 14 00:27:46 UTC 2016


Add utility to format the virSecretLookupTypeDefPtr in XML

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/libvirt_private.syms  |  1 +
 src/util/virsecret.c      | 26 ++++++++++++++++++++++++++
 src/util/virsecret.h      |  3 +++
 src/util/virstoragefile.c | 19 +------------------
 4 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ca65885..fdf06ae 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2209,6 +2209,7 @@ virSecurityLabelDefNew;
 
 
 # util/virsecret.h
+virSecretFormatSecret;
 virSecretLookupDefClear;
 virSecretLookupDefCopy;
 virSecretParseSecret;
diff --git a/src/util/virsecret.c b/src/util/virsecret.c
index da5f7af..c08ace8 100644
--- a/src/util/virsecret.c
+++ b/src/util/virsecret.c
@@ -99,3 +99,29 @@ virSecretParseSecret(xmlNodePtr secretnode,
     VIR_FREE(usage);
     return ret;
 }
+
+
+void
+virSecretFormatSecret(virBufferPtr buf,
+                      const char *secrettype,
+                      virSecretLookupTypeDefPtr secdef)
+{
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    virBufferAdjustIndent(buf, 2);
+    if (secrettype)
+        virBufferAsprintf(buf, "<secret type='%s'", secrettype);
+    else
+        virBufferAddLit(buf, "<secret");
+
+    if (secdef->type == VIR_SECRET_LOOKUP_TYPE_UUID) {
+        virUUIDFormat(secdef->u.uuid, uuidstr);
+        virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
+    } else if (secdef->type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
+        virBufferEscapeString(buf, " usage='%s'/>\n",
+                              secdef->u.usage);
+    } else {
+        virBufferAddLit(buf, "/>\n");
+    }
+    virBufferAdjustIndent(buf, -2);
+}
diff --git a/src/util/virsecret.h b/src/util/virsecret.h
index d97c17d..f70ed31 100644
--- a/src/util/virsecret.h
+++ b/src/util/virsecret.h
@@ -50,4 +50,7 @@ int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
                            const virSecretLookupTypeDef *src);
 int virSecretParseSecret(xmlNodePtr secretnode,
                          virSecretLookupTypeDefPtr secdef);
+void virSecretFormatSecret(virBufferPtr buf,
+                           const char *secrettype,
+                           virSecretLookupTypeDefPtr secdef);
 #endif /* __VIR_SECRET_H__ */
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 3a2fd75..6d7e5d9 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1623,8 +1623,6 @@ int
 virStorageAuthDefFormat(virBufferPtr buf,
                         virStorageAuthDefPtr authdef)
 {
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
-
     if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
         virBufferEscapeString(buf, "<auth username='%s'>\n", authdef->username);
     } else {
@@ -1633,22 +1631,7 @@ virStorageAuthDefFormat(virBufferPtr buf,
         virBufferEscapeString(buf, "username='%s'>\n", authdef->username);
     }
 
-    virBufferAdjustIndent(buf, 2);
-    if (authdef->secrettype)
-        virBufferAsprintf(buf, "<secret type='%s'", authdef->secrettype);
-    else
-        virBufferAddLit(buf, "<secret");
-
-    if (authdef->secdef.type == VIR_SECRET_LOOKUP_TYPE_UUID) {
-        virUUIDFormat(authdef->secdef.u.uuid, uuidstr);
-        virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
-    } else if (authdef->secdef.type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
-        virBufferEscapeString(buf, " usage='%s'/>\n",
-                              authdef->secdef.u.usage);
-    } else {
-        virBufferAddLit(buf, "/>\n");
-    }
-    virBufferAdjustIndent(buf, -2);
+    virSecretFormatSecret(buf, authdef->secrettype, &authdef->secdef);
     virBufferAddLit(buf, "</auth>\n");
 
     return 0;
-- 
2.5.5




More information about the libvir-list mailing list