libvirt/SOURCES/libvirt-virxml-Introduce-virXPathTristateSwitch.patch

99 lines
3.0 KiB
Diff

From 712964c94adb60b390c283d997e398d1c9cd9930 Mon Sep 17 00:00:00 2001
Message-ID: <712964c94adb60b390c283d997e398d1c9cd9930.1763133105.git.jdenemar@redhat.com>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Thu, 2 Oct 2025 09:26:59 +0200
Subject: [PATCH] virxml: Introduce virXPathTristateSwitch()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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>
(cherry picked from commit c689aa80c10242b9c1c4633089ba7ee3f7c1f801)
Resolves: https://issues.redhat.com/browse/RHEL-122930
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virxml.c | 34 ++++++++++++++++++++++++++++++++++
src/util/virxml.h | 5 +++++
3 files changed, 40 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0a1235e6d8..0edd526a68 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3796,6 +3796,7 @@ virXPathLongLong;
virXPathNode;
virXPathNodeSet;
virXPathString;
+virXPathTristateSwitch;
virXPathUInt;
virXPathUIntBase;
virXPathULongLong;
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 51173303fe..cb0a59ffda 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -258,6 +258,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 06ba324df0..3d2de4f976 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);
--
2.51.1