[PATCH 3/5] util: virSecretLookupParseSecret refactor

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

 



From: Kirill Shchetiniuk <kshcheti@xxxxxxxxxx>

Refactored the virSecretLookupParseSecret fucntion to use the
virXMLPropUUID fucntion, avoid getting the string and parsing it
later. Previously two separate error states merged into one by using
boolean NXOR operation.

Signed-off-by: Kirill Shchetiniuk <kshcheti@xxxxxxxxxx>
---
 src/util/virsecret.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/util/virsecret.c b/src/util/virsecret.c
index 8a220a37ec..c5eb1055be 100644
--- a/src/util/virsecret.c
+++ b/src/util/virsecret.c
@@ -64,34 +64,27 @@ int
 virSecretLookupParseSecret(xmlNodePtr secretnode,
                            virSecretLookupTypeDef *def)
 {
-    g_autofree char *uuid = NULL;
     g_autofree char *usage = NULL;
+    int ret;
 
-    uuid = virXMLPropString(secretnode, "uuid");
     usage = virXMLPropString(secretnode, "usage");
-    if (uuid == NULL && usage == NULL) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("missing secret uuid or usage attribute"));
+
+    if ((ret = virXMLPropUUID(secretnode, "uuid", VIR_XML_PROP_NONE, def->u.uuid)) < 0)
         return -1;
-    }
 
-    if (uuid && usage) {
+    if (!(usage) == !(ret)) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("either secret uuid or usage expected"));
         return -1;
     }
 
-    if (uuid) {
-        if (virUUIDParse(uuid, def->u.uuid) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid secret uuid '%1$s'"), uuid);
-            return -1;
-        }
+    if (ret) {
         def->type = VIR_SECRET_LOOKUP_TYPE_UUID;
     } else {
         def->u.usage = g_steal_pointer(&usage);
         def->type = VIR_SECRET_LOOKUP_TYPE_USAGE;
     }
+
     return 0;
 }
 
-- 
2.49.0




[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