Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
src/conf/domain_conf.c | 40 +++++++++++-----------------------------
1 file changed, 11 insertions(+), 29 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0a00be4e80..cc0bdeed56 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1449,46 +1449,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:
@@ -1496,11 +1478,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:
--
2.26.3