]> xenbits.xensource.com Git - libvirt.git/commitdiff
virSecretDef: Convert 'usage_type' field to proper enum type
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Feb 2024 08:03:54 +0000 (09:03 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 13 Feb 2024 15:11:17 +0000 (16:11 +0100)
Convert the field and adjust the XML parsers to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/access/viraccessdriverpolkit.c
src/conf/secret_conf.c
src/conf/secret_conf.h

index b78049583c83790c4e28fe5e891348ec7f715d15..83381183a5d59d4a53a60becdc2179e12b487cc8 100644 (file)
@@ -403,6 +403,10 @@ virAccessDriverPolkitCheckSecret(virAccessManager *manager,
                                          virAccessPermSecretTypeToString(perm),
                                          attrs);
     }   break;
+
+    case VIR_SECRET_USAGE_TYPE_LAST:
+        virReportEnumRangeError(virSecretUsageType, secret->usage_type);
+        return -1;
     }
 }
 
index d8ce772d3bd2f4d9c8746e5c6fc88c4837e316ae..c6c8c30ba9e242d1d69ddb05f5f88af212e93859 100644 (file)
@@ -51,27 +51,19 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
 {
     xmlNodePtr node = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    g_autofree char *type_str = NULL;
-    int type;
 
     if (!(node = virXPathNode("./usage", ctxt)))
         return 0;
 
     ctxt->node = node;
 
-    type_str = virXMLPropString(node, "type");
-    if (type_str == NULL) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("unknown secret usage type"));
+    if (virXMLPropEnum(node, "type",
+                       virSecretUsageTypeFromString,
+                       VIR_XML_PROP_REQUIRED,
+                       &def->usage_type) < 0) {
         return -1;
     }
-    type = virSecretUsageTypeFromString(type_str);
-    if (type < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown secret usage type %1$s"), type_str);
-        return -1;
-    }
-    def->usage_type = type;
+
     switch (def->usage_type) {
     case VIR_SECRET_USAGE_TYPE_NONE:
         break;
@@ -121,6 +113,7 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
         }
         break;
 
+    case VIR_SECRET_USAGE_TYPE_LAST:
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected secret usage type %1$d"),
@@ -238,9 +231,8 @@ virSecretDefFormatUsage(virBuffer *buf,
         break;
 
     default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected secret usage type %1$d"),
-                       def->usage_type);
+    case VIR_SECRET_USAGE_TYPE_LAST:
+        virReportEnumRangeError(virSecretUsageType, def->usage_type);
         return -1;
     }
     virBufferAdjustIndent(buf, -2);
index dee98899ac946639f79e0c90c799271490565b8e..8f8f47933aee2b42266d60e7b911093c6056589f 100644 (file)
@@ -28,7 +28,7 @@ struct _virSecretDef {
     bool isprivate;
     unsigned char uuid[VIR_UUID_BUFLEN];
     char *description;          /* May be NULL */
-    int usage_type;  /* virSecretUsageType */
+    virSecretUsageType usage_type;
     char *usage_id; /* May be NULL */
 };