[PATCH 03/11] storage: Add a struct for auth secret

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

 



This also abstracts the code for parsing the XMLs to use the secret
object as a helper.
---
 src/conf/storage_conf.c | 68 ++++++++++++++++++++++++++++---------------------
 src/conf/storage_conf.h | 14 ++++++----
 2 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index c0bf084..0047372 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -439,6 +439,43 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
     }
 }
 
+static int
+virStoragePoolDefParseAuthSecret(xmlXPathContextPtr ctxt,
+                                 virStoragePoolAuthSecretPtr secret)
+
+{
+    char *uuid = NULL;
+    int ret = -1;
+
+    uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
+    secret->usage = virXPathString("string(./auth/secret/@usage)", ctxt);
+    if (uuid == NULL && secret->usage == NULL) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing auth secret uuid or usage attribute"));
+        return -1;
+    }
+
+    if (uuid != NULL) {
+        if (secret->usage != NULL) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("either auth secret uuid or usage expected"));
+            goto cleanup;
+        }
+        if (virUUIDParse(uuid, secret->uuid) < 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("invalid auth secret uuid"));
+            goto cleanup;
+        }
+        secret->uuidUsable = true;
+    } else {
+        secret->uuidUsable = false;
+    }
+
+    ret = 0;
+cleanup:
+    VIR_FREE(uuid);
+    return ret;
+}
 
 static int
 virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt,
@@ -484,9 +521,6 @@ static int
 virStoragePoolDefParseAuthCephx(xmlXPathContextPtr ctxt,
                                 virStoragePoolAuthCephxPtr auth)
 {
-    char *uuid = NULL;
-    int ret = -1;
-
     auth->username = virXPathString("string(./auth/@username)", ctxt);
     if (auth->username == NULL) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -494,34 +528,10 @@ virStoragePoolDefParseAuthCephx(xmlXPathContextPtr ctxt,
         return -1;
     }
 
-    uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
-    auth->secret.usage = virXPathString("string(./auth/secret/@usage)", ctxt);
-    if (uuid == NULL && auth->secret.usage == NULL) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing auth secret uuid or usage attribute"));
+    if (virStoragePoolDefParseAuthSecret(ctxt, &auth->secret) < 0)
         return -1;
-    }
-
-    if (uuid != NULL) {
-        if (auth->secret.usage != NULL) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("either auth secret uuid or usage expected"));
-            goto cleanup;
-        }
-        if (virUUIDParse(uuid, auth->secret.uuid) < 0) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("invalid auth secret uuid"));
-            goto cleanup;
-        }
-        auth->secret.uuidUsable = true;
-    } else {
-        auth->secret.uuidUsable = false;
-    }
 
-    ret = 0;
-cleanup:
-    VIR_FREE(uuid);
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 8e739ff..aff1393 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -145,6 +145,14 @@ enum virStoragePoolAuthType {
     VIR_STORAGE_POOL_AUTH_CEPHX,
 };
 
+typedef struct _virStoragePoolAuthSecret virStoragePoolAuthSecret;
+typedef virStoragePoolAuthSecret *virStoragePoolAuthSecretPtr;
+struct _virStoragePoolAuthSecret {
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    char *usage;
+    bool uuidUsable;
+};
+
 typedef struct _virStoragePoolAuthChap virStoragePoolAuthChap;
 typedef virStoragePoolAuthChap *virStoragePoolAuthChapPtr;
 struct _virStoragePoolAuthChap {
@@ -156,11 +164,7 @@ typedef struct _virStoragePoolAuthCephx virStoragePoolAuthCephx;
 typedef virStoragePoolAuthCephx *virStoragePoolAuthCephxPtr;
 struct _virStoragePoolAuthCephx {
     char *username;
-    struct {
-            unsigned char uuid[VIR_UUID_BUFLEN];
-            char *usage;
-            bool uuidUsable;
-    } secret;
+    virStoragePoolAuthSecret secret;
 };
 
 /*
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]