util: Introduce virXMLPropTristateBoolAllowDefault()

We need it for a single scenario in which prop='default' has to
be treated as valid input.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2022-03-24 19:46:12 +01:00
parent c49651ac17
commit fd3ca84c3e
3 changed files with 26 additions and 0 deletions

View File

@ -3647,6 +3647,7 @@ virXMLPropEnumDefault;
virXMLPropInt;
virXMLPropString;
virXMLPropTristateBool;
virXMLPropTristateBoolAllowDefault;
virXMLPropTristateSwitch;
virXMLPropUInt;
virXMLPropULongLong;

View File

@ -552,6 +552,24 @@ virXMLPropTristateBool(xmlNodePtr node,
}
/* Same as virXMLPropTristateBoolAllowDefault, but will accept the
* value 'default' and convert it to VIR_TRISTATE_BOOL_ABSENT instead
* of rejecting it with an error. Should only be used for backwards
* compatibility reasons, and specifically to parse XML files where a
* property having value VIR_TRISTATE_BOOL_ABSENT has historically
* resulted in it being formatted with value 'default' instead of
* being omitted entirely */
int
virXMLPropTristateBoolAllowDefault(xmlNodePtr node,
const char* name,
virXMLPropFlags flags,
virTristateBool *result)
{
return virXMLPropEnumInternal(node, name, virTristateBoolTypeFromString,
flags, result, VIR_TRISTATE_BOOL_ABSENT);
}
/**
* virXMLPropTristateSwitch:
* @node: XML dom node pointer

View File

@ -103,6 +103,13 @@ virXMLPropTristateBool(xmlNodePtr node,
virTristateBool *result)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
int
virXMLPropTristateBoolAllowDefault(xmlNodePtr node,
const char *name,
virXMLPropFlags flags,
virTristateBool *result)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
int
virXMLPropTristateSwitch(xmlNodePtr node,
const char *name,