From: Tim Wiederhake Date: Wed, 21 Apr 2021 15:51:24 +0000 (+0200) Subject: virDomainKeyWrapCipherDefParseXML: Use virXMLProp* X-Git-Tag: v7.3.0-rc1~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=931afa7d99b8ff6eb18a6aa402ed64b789197d30;p=thirdparty%2Flibvirt.git virDomainKeyWrapCipherDefParseXML: Use virXMLProp* Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f8a462fb3b..aa3a109a32 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1456,46 +1456,28 @@ static int virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDef *keywrap, xmlNodePtr node) { - int state_type; - int name_type; - g_autofree char *name = NULL; - g_autofree char *state = NULL; - - if (!(name = virXMLPropString(node, "name"))) { - virReportError(VIR_ERR_CONF_SYNTAX, "%s", - _("missing name for cipher")); - return -1; - } + virDomainKeyWrapCipherName name; + virTristateSwitch state; - if ((name_type = virDomainKeyWrapCipherNameTypeFromString(name)) < 0) { - virReportError(VIR_ERR_CONF_SYNTAX, - _("%s is not a supported cipher name"), name); + if (virXMLPropEnum(node, "name", virDomainKeyWrapCipherNameTypeFromString, + VIR_XML_PROP_REQUIRED, &name) < 0) return -1; - } - if (!(state = virXMLPropString(node, "state"))) { - virReportError(VIR_ERR_CONF_SYNTAX, - _("missing state for cipher named %s"), name); + if (virXMLPropTristateSwitch(node, "state", VIR_XML_PROP_REQUIRED, + &state) < 0) return -1; - } - - if ((state_type = virTristateSwitchTypeFromString(state)) < 0) { - virReportError(VIR_ERR_CONF_SYNTAX, - _("%s is not a supported cipher state"), state); - return -1; - } - switch ((virDomainKeyWrapCipherName) name_type) { + switch (name) { case VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_AES: if (keywrap->aes != VIR_TRISTATE_SWITCH_ABSENT) { virReportError(VIR_ERR_INTERNAL_ERROR, _("A domain definition can have no more than " "one cipher node with name %s"), - virDomainKeyWrapCipherNameTypeToString(name_type)); + virDomainKeyWrapCipherNameTypeToString(name)); return -1; } - keywrap->aes = state_type; + keywrap->aes = state; break; case VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_DEA: @@ -1503,11 +1485,11 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDef *keywrap, virReportError(VIR_ERR_INTERNAL_ERROR, _("A domain definition can have no more than " "one cipher node with name %s"), - virDomainKeyWrapCipherNameTypeToString(name_type)); + virDomainKeyWrapCipherNameTypeToString(name)); return -1; } - keywrap->dea = state_type; + keywrap->dea = state; break; case VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_LAST: