[PATCH 06/43] virNWFilterBindingDefParse: Properly use virXMLParse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fetch the XPath context and validate the node by using virXMLParse's
features.

This allows to completely remove virNWFilterBindingDefParseNode as
all callers now properly validate the root element name and have a XPath
context handy.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/virnwfilterbindingdef.c | 34 ++++++--------------------------
 src/conf/virnwfilterbindingdef.h |  3 +--
 src/conf/virnwfilterbindingobj.c |  4 +++-
 src/libvirt_private.syms         |  2 +-
 4 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbindingdef.c
index e58bab3f08..524010c4c4 100644
--- a/src/conf/virnwfilterbindingdef.c
+++ b/src/conf/virnwfilterbindingdef.c
@@ -71,7 +71,7 @@ virNWFilterBindingDefCopy(virNWFilterBindingDef *src)
 }


-static virNWFilterBindingDef *
+virNWFilterBindingDef *
 virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt)
 {
     virNWFilterBindingDef *ret;
@@ -154,42 +154,20 @@ virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt)
 }


-virNWFilterBindingDef *
-virNWFilterBindingDefParseNode(xmlDocPtr xml,
-                               xmlNodePtr root)
-{
-    g_autoptr(xmlXPathContext) ctxt = NULL;
-
-    if (STRNEQ((const char *)root->name, "filterbinding")) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       "%s",
-                       _("unknown root element for nwfilter binding"));
-        return NULL;
-    }
-
-    if (!(ctxt = virXMLXPathContextNew(xml)))
-        return NULL;
-
-    ctxt->node = root;
-    return virNWFilterBindingDefParseXML(ctxt);
-}
-
-
 static virNWFilterBindingDef *
 virNWFilterBindingDefParse(const char *xmlStr,
                            const char *filename,
                            unsigned int flags)
 {
-    virNWFilterBindingDef *def = NULL;
     g_autoptr(xmlDoc) xml = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     bool validate = flags & VIR_NWFILTER_BINDING_CREATE_VALIDATE;

-    if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_definition)"),
-                           NULL, NULL, "nwfilterbinding.rng", validate))) {
-        def = virNWFilterBindingDefParseNode(xml, xmlDocGetRootElement(xml));
-    }
+    if (!(xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_definition)"),
+                            "filterbinding", &ctxt, "nwfilterbinding.rng", validate)))
+        return NULL;

-    return def;
+    return virNWFilterBindingDefParseXML(ctxt);
 }


diff --git a/src/conf/virnwfilterbindingdef.h b/src/conf/virnwfilterbindingdef.h
index 4bf0f252f8..a5497d5a1c 100644
--- a/src/conf/virnwfilterbindingdef.h
+++ b/src/conf/virnwfilterbindingdef.h
@@ -47,8 +47,7 @@ virNWFilterBindingDef *
 virNWFilterBindingDefCopy(virNWFilterBindingDef *src);

 virNWFilterBindingDef *
-virNWFilterBindingDefParseNode(xmlDocPtr xml,
-                               xmlNodePtr root);
+virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt);

 virNWFilterBindingDef *
 virNWFilterBindingDefParseString(const char *xml,
diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c
index 5ff53f7380..6e67c5c7b6 100644
--- a/src/conf/virnwfilterbindingobj.c
+++ b/src/conf/virnwfilterbindingobj.c
@@ -223,7 +223,9 @@ virNWFilterBindingObjParse(const char *filename)
         return NULL;
     }

-    if (!(ret->def = virNWFilterBindingDefParseNode(xml, node)))
+    ctxt->node = node;
+
+    if (!(ret->def = virNWFilterBindingDefParseXML(ctxt)))
         return NULL;

     return g_steal_pointer(&ret);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 11862bb1a9..6e85a8c6cb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1365,8 +1365,8 @@ virNWFilterBindingDefFormat;
 virNWFilterBindingDefFormatBuf;
 virNWFilterBindingDefFree;
 virNWFilterBindingDefParseFile;
-virNWFilterBindingDefParseNode;
 virNWFilterBindingDefParseString;
+virNWFilterBindingDefParseXML;


 # conf/virnwfilterbindingobj.h
-- 
2.37.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux