]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virxml: Introduce virXPathTristateSwitch()
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Oct 2025 07:26:59 +0000 (09:26 +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 virTristateSwitch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virxml.c
src/util/virxml.h

index 7986ad123c67316a1b2c4ec0f8f6a9f077024b34..0b692c038e5a4ef05ac48e3f8b1dfe2dce967fda 100644 (file)
@@ -3827,6 +3827,7 @@ virXPathLongLong;
 virXPathNode;
 virXPathNodeSet;
 virXPathString;
+virXPathTristateSwitch;
 virXPathUInt;
 virXPathUIntBase;
 virXPathULongLong;
index bb80bb7444d58264e588d2964b98618bda167a74..60485c10fa35227300c46dc1c2959038ec7282c4 100644 (file)
@@ -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
index 7cc3f479139b1603154ca490a40199cdb5a81c2c..dfec386494ed0255bffbc508f5592e8c344d3ff6 100644 (file)
@@ -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);