]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virSecretLookupParseSecret refactor
authorKirill Shchetiniuk <kshcheti@redhat.com>
Tue, 22 Jul 2025 15:12:03 +0000 (17:12 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 23 Jul 2025 10:21:57 +0000 (12:21 +0200)
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@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virsecret.c

index 8a220a37ec32548d0cfc5e3c0cf39124bb825dfe..8e74df3b93761c091cc9081d09b2ef39ce78fb34 100644 (file)
@@ -64,34 +64,35 @@ int
 virSecretLookupParseSecret(xmlNodePtr secretnode,
                            virSecretLookupTypeDef *def)
 {
-    g_autofree char *uuid = NULL;
     g_autofree char *usage = NULL;
+    int rc;
 
-    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"));
-        return -1;
-    }
 
-    if (uuid && usage) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("either secret uuid or usage expected"));
+    if ((rc = virXMLPropUUID(secretnode, "uuid",
+                             VIR_XML_PROP_NONE, def->u.uuid)) < 0) {
         return -1;
     }
 
-    if (uuid) {
-        if (virUUIDParse(uuid, def->u.uuid) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid secret uuid '%1$s'"), uuid);
+    if (rc > 0) {
+        if (usage) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("either secret uuid or usage expected"));
             return -1;
         }
+
         def->type = VIR_SECRET_LOOKUP_TYPE_UUID;
     } else {
+        if (!usage) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("missing secret uuid or usage attribute"));
+            return -1;
+        }
+
         def->u.usage = g_steal_pointer(&usage);
         def->type = VIR_SECRET_LOOKUP_TYPE_USAGE;
     }
+
     return 0;
 }