]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virxml: Introduce virXPathTristateBool()
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Oct 2025 07:29:19 +0000 (09:29 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Oct 2025 07:56:30 +0000 (09:56 +0200)
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 <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virxml.c
src/util/virxml.h

index 0b692c038e5a4ef05ac48e3f8b1dfe2dce967fda..1a4f47aabc80eac5367311f614f9cf8def8fbbd7 100644 (file)
@@ -3827,6 +3827,7 @@ virXPathLongLong;
 virXPathNode;
 virXPathNodeSet;
 virXPathString;
+virXPathTristateBool;
 virXPathTristateSwitch;
 virXPathUInt;
 virXPathUIntBase;
index 60485c10fa35227300c46dc1c2959038ec7282c4..44f11accf3cf0f34d7c680670b52a1856d2f1b35 100644 (file)
@@ -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
index dfec386494ed0255bffbc508f5592e8c344d3ff6..82218c053987424a568cd44fb339cfa0a3e06851 100644 (file)
@@ -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);