From 5dc483d75f8a84ad4a6d5d2cef8bc296eb132eb9 Mon Sep 17 00:00:00 2001 From: Kirill Shchetiniuk Date: Tue, 22 Jul 2025 17:12:03 +0200 Subject: [PATCH] util: virSecretLookupParseSecret refactor 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 Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/util/virsecret.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/util/virsecret.c b/src/util/virsecret.c index 8a220a37ec..8e74df3b93 100644 --- a/src/util/virsecret.c +++ b/src/util/virsecret.c @@ -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; } -- 2.47.2