]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: xml: introduce virXMLNamespaceRegister
authorJán Tomko <jtomko@redhat.com>
Tue, 20 Aug 2019 20:14:13 +0000 (22:14 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 21 Aug 2019 08:29:21 +0000 (10:29 +0200)
A wrapper around xmlXPathRegisterNs that will save us
from having to include xpathInternals.h everywhere
we want to use a custom namespace and open-coding
the strings already contained in virXMLNamespace.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/util/virxml.c
src/util/virxml.h

index 02693d14ed251a3b86d719e7ea17bc48df1ff21f..84b824f43235cfafe86b45e7377a2a0d16ad4415 100644 (file)
@@ -24,6 +24,8 @@
 #include <math.h>               /* for isnan() */
 #include <sys/stat.h>
 
+#include <libxml/xpathInternals.h>
+
 #include "virerror.h"
 #include "virxml.h"
 #include "virbuffer.h"
@@ -1416,3 +1418,20 @@ virXMLNamespaceFormatNS(virBufferPtr buf,
 {
     virBufferAsprintf(buf, " xmlns:%s='%s'", ns->prefix, ns->href());
 }
+
+
+int
+virXMLNamespaceRegister(xmlXPathContextPtr ctxt,
+                        virXMLNamespace const *ns)
+{
+    if (xmlXPathRegisterNs(ctxt,
+                           BAD_CAST ns->prefix,
+                           BAD_CAST ns->href()) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to register xml namespace '%s'"),
+                       ns->href());
+        return -1;
+    }
+
+    return 0;
+}
index cdea11619686bf09ff51e996d9a86be16c6ac011..be2abd23f760d5b1eeed94f4912c077bb9971fe8 100644 (file)
@@ -265,3 +265,6 @@ typedef virXMLNamespace *virXMLNamespacePtr;
 void
 virXMLNamespaceFormatNS(virBufferPtr buf,
                         virXMLNamespace const *ns);
+int
+virXMLNamespaceRegister(xmlXPathContextPtr ctxt,
+                        virXMLNamespace const *ns);