Convert the field and adjust the XML parsers to use virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/access/viraccessdriverpolkit.c | 4 ++++ src/conf/secret_conf.c | 24 ++++++++---------------- src/conf/secret_conf.h | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/access/viraccessdriverpolkit.c b/src/access/viraccessdriverpolkit.c index b78049583c..83381183a5 100644 --- a/src/access/viraccessdriverpolkit.c +++ b/src/access/viraccessdriverpolkit.c @@ -403,6 +403,10 @@ virAccessDriverPolkitCheckSecret(virAccessManager *manager, virAccessPermSecretTypeToString(perm), attrs); } break; + + case VIR_SECRET_USAGE_TYPE_LAST: + virReportEnumRangeError(virSecretUsageType, secret->usage_type); + return -1; } } diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index d8ce772d3b..c6c8c30ba9 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -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); diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h index dee98899ac..8f8f47933a 100644 --- a/src/conf/secret_conf.h +++ b/src/conf/secret_conf.h @@ -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 */ }; -- 2.43.0 _______________________________________________ Devel mailing list -- devel@xxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx