[PATCH 03/43] virNWFilterBindingObjParse: Refactor XML parsing code

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

 



Remove the redundant root node checking and XPath context creation by
using virXMLParse properly.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/virnwfilterbindingobj.c     | 65 +++++-----------------------
 src/conf/virnwfilterbindingobj.h     |  2 +-
 src/conf/virnwfilterbindingobjlist.c |  2 +-
 src/libvirt_private.syms             |  2 +-
 4 files changed, 14 insertions(+), 57 deletions(-)

diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c
index cc6009d1f2..5ff53f7380 100644
--- a/src/conf/virnwfilterbindingobj.c
+++ b/src/conf/virnwfilterbindingobj.c
@@ -202,74 +202,31 @@ virNWFilterBindingObjDelete(const virNWFilterBindingObj *obj,
 }


-static virNWFilterBindingObj *
-virNWFilterBindingObjParseXML(xmlDocPtr doc,
-                              xmlXPathContextPtr ctxt)
+virNWFilterBindingObj *
+virNWFilterBindingObjParse(const char *filename)
 {
-    virNWFilterBindingObj *ret;
+    g_autoptr(virNWFilterBindingObj) ret = NULL;
+    g_autoptr(xmlDoc) xml = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr node;

+    if (!(xml = virXMLParse(filename, NULL, _("(nwfilterbinding_status)"),
+                            "filterbindingstatus", &ctxt, NULL, false)))
+        return NULL;
+
     if (!(ret = virNWFilterBindingObjNew()))
         return NULL;

     if (!(node = virXPathNode("./filterbinding", ctxt))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("filter binding status missing content"));
-        goto cleanup;
-    }
-
-    if (!(ret->def = virNWFilterBindingDefParseNode(doc, node)))
-        goto cleanup;
-
-    return ret;
-
- cleanup:
-    virObjectUnref(ret);
-    return NULL;
-}
-
-
-static virNWFilterBindingObj *
-virNWFilterBindingObjParseNode(xmlDocPtr doc,
-                               xmlNodePtr root)
-{
-    g_autoptr(xmlXPathContext) ctxt = NULL;
-
-    if (STRNEQ((const char *)root->name, "filterbindingstatus")) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("unknown root element '%s' for filter binding"),
-                       root->name);
         return NULL;
     }

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

-    ctxt->node = root;
-    return virNWFilterBindingObjParseXML(doc, ctxt);
-}
-
-
-static virNWFilterBindingObj *
-virNWFilterBindingObjParse(const char *xmlStr,
-                           const char *filename)
-{
-    virNWFilterBindingObj *obj = NULL;
-    g_autoptr(xmlDoc) xml = NULL;
-
-    if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)"),
-                           NULL, NULL, NULL, false))) {
-        obj = virNWFilterBindingObjParseNode(xml, xmlDocGetRootElement(xml));
-    }
-
-    return obj;
-}
-
-
-virNWFilterBindingObj *
-virNWFilterBindingObjParseFile(const char *filename)
-{
-    return virNWFilterBindingObjParse(NULL, filename);
+    return g_steal_pointer(&ret);
 }


diff --git a/src/conf/virnwfilterbindingobj.h b/src/conf/virnwfilterbindingobj.h
index 17f855bda1..33aa575436 100644
--- a/src/conf/virnwfilterbindingobj.h
+++ b/src/conf/virnwfilterbindingobj.h
@@ -64,7 +64,7 @@ virNWFilterBindingObjDelete(const virNWFilterBindingObj *obj,
                             const char *statusDir);

 virNWFilterBindingObj *
-virNWFilterBindingObjParseFile(const char *filename);
+virNWFilterBindingObjParse(const char *filename);

 char *
 virNWFilterBindingObjFormat(const virNWFilterBindingObj *obj);
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index 9a46fa06b9..a349f5c195 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -266,7 +266,7 @@ virNWFilterBindingObjListLoadStatus(virNWFilterBindingObjList *bindings,
     if ((statusFile = virNWFilterBindingObjConfigFile(statusDir, name)) == NULL)
         goto error;

-    if (!(obj = virNWFilterBindingObjParseFile(statusFile)))
+    if (!(obj = virNWFilterBindingObjParse(statusFile)))
         goto error;

     def = virNWFilterBindingObjGetDef(obj);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5be40dbefe..11862bb1a9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1377,7 +1377,7 @@ virNWFilterBindingObjFormat;
 virNWFilterBindingObjGetDef;
 virNWFilterBindingObjGetRemoving;
 virNWFilterBindingObjNew;
-virNWFilterBindingObjParseFile;
+virNWFilterBindingObjParse;
 virNWFilterBindingObjSave;
 virNWFilterBindingObjSetDef;
 virNWFilterBindingObjSetRemoving;
-- 
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