From: Michal Privoznik Date: Thu, 2 Oct 2025 07:26:59 +0000 (+0200) Subject: virxml: Introduce virXPathTristateSwitch() X-Git-Tag: v11.9.0-rc1~70 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c689aa80c10242b9c1c4633089ba7ee3f7c1f801;p=thirdparty%2Flibvirt.git virxml: Introduce virXPathTristateSwitch() Similarly to other virXPath* functions, let's have a helper that evaluates an XPath and stores the value into virTristateSwitch. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7986ad123c..0b692c038e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3827,6 +3827,7 @@ virXPathLongLong; virXPathNode; virXPathNodeSet; virXPathString; +virXPathTristateSwitch; virXPathUInt; virXPathUIntBase; virXPathULongLong; diff --git a/src/util/virxml.c b/src/util/virxml.c index bb80bb7444..60485c10fa 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -284,6 +284,40 @@ virXPathLongLong(const char *xpath, } +/** + * virXPathTristateSwitch: + * @xpath: the XPath string to evaluate + * @ctxt: an XPath context + * @value: the returned virTristateSwitch 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 virTristateSwitch value. + */ +int +virXPathTristateSwitch(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateSwitch *value) +{ + g_autoptr(xmlXPathObject) obj = NULL; + int rc; + + if (!(obj = virXPathEvalString(xpath, ctxt))) + return -1; + + rc = virTristateSwitchTypeFromString((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 7cc3f47913..dfec386494 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -73,6 +73,11 @@ virXPathLongLong(const char *xpath, xmlXPathContextPtr ctxt, long long *value); +int +virXPathTristateSwitch(const char *xpath, + xmlXPathContextPtr ctxt, + virTristateSwitch *value); + xmlNodePtr virXMLNodeGetSubelement(xmlNodePtr node, const char *name);