From: Michal Privoznik Date: Thu, 2 Oct 2025 07:29:19 +0000 (+0200) Subject: virxml: Introduce virXPathTristateBool() X-Git-Tag: v11.9.0-rc1~69 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e3e4c620f1af03c35c4f0dc7c8a65ea5464df687;p=thirdparty%2Flibvirt.git virxml: Introduce virXPathTristateBool() Similarly to other virXPath* functions, let's have a helper that evaluates an XPath and stores the value into virTristateBool. Signed-off-by: Michal Privoznik --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0b692c038e..1a4f47aabc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3827,6 +3827,7 @@ virXPathLongLong; virXPathNode; virXPathNodeSet; virXPathString; +virXPathTristateBool; virXPathTristateSwitch; virXPathUInt; virXPathUIntBase; diff --git a/src/util/virxml.c b/src/util/virxml.c index 60485c10fa..44f11accf3 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -318,6 +318,40 @@ virXPathTristateSwitch(const char *xpath, } +/** + * virXPathTristateBool: + * @xpath: the XPath string to evaluate + * @ctxt: an XPath context + * @value: the returned virTristateBool value + * + * Convenience function to evaluate an XPath tristate value. The @xpath + * expression must ensure that the evaluated value is returned as a + * string (use the 'string()' conversion in the expression). + * + * Returns 0 in case of success in which case @value is set, + * or -1 if the XPath evaluation failed or -2 if the + * value isn't of a virTristateBool value. + */ +int +virXPathTristateBool(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateBool *value) +{ + g_autoptr(xmlXPathObject) obj = NULL; + int rc; + + if (!(obj = virXPathEvalString(xpath, ctxt))) + return -1; + + rc = virTristateBoolTypeFromString((char *)obj->stringval); + if (rc < 0) + return -2; + + *value = rc; + return 0; +} + + /** * virXMLCheckIllegalChars: * @nodeName: Name of checked node diff --git a/src/util/virxml.h b/src/util/virxml.h index dfec386494..82218c0539 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -78,6 +78,11 @@ virXPathTristateSwitch(const char *xpath, xmlXPathContextPtr ctxt, virTristateSwitch *value); +int +virXPathTristateBool(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateBool *value); + xmlNodePtr virXMLNodeGetSubelement(xmlNodePtr node, const char *name);