mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virxml: Add virXMLPropEnum
Convenience function to return the value of an enum XML attribute. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
68cda45b57
commit
ab5d2776c9
@ -3548,6 +3548,7 @@ virXMLNodeSanitizeNamespaces;
|
|||||||
virXMLNodeToString;
|
virXMLNodeToString;
|
||||||
virXMLParseHelper;
|
virXMLParseHelper;
|
||||||
virXMLPickShellSafeComment;
|
virXMLPickShellSafeComment;
|
||||||
|
virXMLPropEnum;
|
||||||
virXMLPropInt;
|
virXMLPropInt;
|
||||||
virXMLPropString;
|
virXMLPropString;
|
||||||
virXMLPropStringLimit;
|
virXMLPropStringLimit;
|
||||||
|
@ -759,6 +759,54 @@ virXMLPropUInt(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virXMLPropEnum:
|
||||||
|
* @node: XML dom node pointer
|
||||||
|
* @name: Name of the property (attribute) to get
|
||||||
|
* @strToInt: Conversion function to turn enum name to value. Expected to
|
||||||
|
* return negative value on failure.
|
||||||
|
* @flags: Bitwise or of virXMLPropFlags
|
||||||
|
* @result: The returned value
|
||||||
|
*
|
||||||
|
* Convenience function to return value of an enum attribute.
|
||||||
|
*
|
||||||
|
* Returns 1 in case of success in which case @result is set,
|
||||||
|
* or 0 if the attribute is not present,
|
||||||
|
* or -1 and reports an error on failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virXMLPropEnum(xmlNodePtr node,
|
||||||
|
const char* name,
|
||||||
|
int (*strToInt)(const char*),
|
||||||
|
virXMLPropFlags flags,
|
||||||
|
unsigned int *result)
|
||||||
|
{
|
||||||
|
g_autofree char *tmp = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!(tmp = virXMLPropString(node, name))) {
|
||||||
|
if (!(flags & VIR_XML_PROP_REQUIRED))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("Missing required attribute '%s' in element '%s'"),
|
||||||
|
name, node->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = strToInt(tmp);
|
||||||
|
if (ret < 0 ||
|
||||||
|
((flags & VIR_XML_PROP_NONZERO) && (ret == 0))) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("Invalid value for attribute '%s' in element '%s': '%s'."),
|
||||||
|
name, node->name, NULLSTR(tmp));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = ret;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXPathBoolean:
|
* virXPathBoolean:
|
||||||
* @xpath: the XPath string to evaluate
|
* @xpath: the XPath string to evaluate
|
||||||
|
@ -135,6 +135,15 @@ virXMLPropUInt(xmlNodePtr node,
|
|||||||
unsigned int *result)
|
unsigned int *result)
|
||||||
ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
|
ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
|
int
|
||||||
|
virXMLPropEnum(xmlNodePtr node,
|
||||||
|
const char* name,
|
||||||
|
int (*strToInt)(const char*),
|
||||||
|
virXMLPropFlags flags,
|
||||||
|
unsigned int *result)
|
||||||
|
ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
||||||
|
ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
/* Internal function; prefer the macros below. */
|
/* Internal function; prefer the macros below. */
|
||||||
xmlDocPtr
|
xmlDocPtr
|
||||||
virXMLParseHelper(int domcode,
|
virXMLParseHelper(int domcode,
|
||||||
|
Loading…
Reference in New Issue
Block a user