[PATCH v2 1/4] conf: propagate xmlDocPtr and flags into virInterfaceDefParseXML()

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

 



We need to know if validation flag is present in order to
validate given XML against schema in virInterfaceDefParseXML().

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/conf/interface_conf.c               | 29 +++++++++++++++----------
 src/conf/interface_conf.h               |  6 +++--
 src/conf/virinterfaceobj.c              |  2 +-
 src/interface/interface_backend_netcf.c |  4 ++--
 src/test/test_driver.c                  |  4 ++--
 tests/interfacexml2xmltest.c            |  2 +-
 6 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index d84ec66def..7b0cfa6562 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -38,7 +38,8 @@ VIR_ENUM_IMPL(virInterface,
 );
 
 static virInterfaceDef *
-virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType);
+virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType,
+                        xmlDocPtr xml, unsigned int flags);
 
 static int
 virInterfaceDefDevFormat(virBuffer *buf, const virInterfaceDef *def,
@@ -521,7 +522,7 @@ virInterfaceDefParseBridge(virInterfaceDef *def,
 
         for (i = 0; i < nbItf; i++) {
             ctxt->node = interfaces[i];
-            itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDGE);
+            itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDGE, NULL, 0);
             if (itf == NULL) {
                 ret = -1;
                 def->data.bridge.nbItf = i;
@@ -565,7 +566,7 @@ virInterfaceDefParseBondItfs(virInterfaceDef *def,
 
     for (i = 0; i < nbItf; i++) {
         ctxt->node = interfaces[i];
-        itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND);
+        itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND, NULL, 0);
         if (itf == NULL) {
             def->data.bond.nbItf = i;
             goto cleanup;
@@ -677,7 +678,9 @@ virInterfaceDefParseVlan(virInterfaceDef *def,
 
 static virInterfaceDef *
 virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
-                        int parentIfType)
+                        int parentIfType,
+                        xmlDocPtr xml G_GNUC_UNUSED,
+                        unsigned int flags)
 {
     virInterfaceDef *def;
     int type;
@@ -685,6 +688,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     xmlNodePtr lnk;
 
+    virCheckFlags(0, NULL);
 
     /* check @type */
     tmp = virXPathString("string(./@type)", ctxt);
@@ -797,7 +801,8 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
 
 virInterfaceDef *
 virInterfaceDefParseNode(xmlDocPtr xml,
-                         xmlNodePtr root)
+                         xmlNodePtr root,
+                         unsigned int flags)
 {
     g_autoptr(xmlXPathContext) ctxt = NULL;
 
@@ -813,19 +818,20 @@ virInterfaceDefParseNode(xmlDocPtr xml,
         return NULL;
 
     ctxt->node = root;
-    return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST);
+    return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST, xml, flags);
 }
 
 
 static virInterfaceDef *
 virInterfaceDefParse(const char *xmlStr,
-                     const char *filename)
+                     const char *filename,
+                     unsigned int flags)
 {
     xmlDocPtr xml;
     virInterfaceDef *def = NULL;
 
     if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)")))) {
-        def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
+        def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml), flags);
         xmlFreeDoc(xml);
     }
 
@@ -834,16 +840,17 @@ virInterfaceDefParse(const char *xmlStr,
 
 
 virInterfaceDef *
-virInterfaceDefParseString(const char *xmlStr)
+virInterfaceDefParseString(const char *xmlStr,
+                           unsigned int flags)
 {
-    return virInterfaceDefParse(xmlStr, NULL);
+    return virInterfaceDefParse(xmlStr, NULL, flags);
 }
 
 
 virInterfaceDef *
 virInterfaceDefParseFile(const char *filename)
 {
-    return virInterfaceDefParse(NULL, filename);
+    return virInterfaceDefParse(NULL, filename, 0);
 }
 
 
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index f5e802736b..15819b000f 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -155,14 +155,16 @@ void
 virInterfaceDefFree(virInterfaceDef *def);
 
 virInterfaceDef *
-virInterfaceDefParseString(const char *xmlStr);
+virInterfaceDefParseString(const char *xmlStr,
+                           unsigned int flags);
 
 virInterfaceDef *
 virInterfaceDefParseFile(const char *filename);
 
 virInterfaceDef *
 virInterfaceDefParseNode(xmlDocPtr xml,
-                         xmlNodePtr root);
+                         xmlNodePtr root,
+                         unsigned int flags);
 
 char *
 virInterfaceDefFormat(const virInterfaceDef *def);
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index a73208f1fc..9439bb3d0b 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -373,7 +373,7 @@ virInterfaceObjListCloneCb(void *payload,
     if (!(xml = virInterfaceDefFormat(srcObj->def)))
         goto error;
 
-    if (!(backup = virInterfaceDefParseString(xml)))
+    if (!(backup = virInterfaceDefParseString(xml, 0)))
         goto error;
     VIR_FREE(xml);
 
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index 416e0af36f..9f93cdd657 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -862,7 +862,7 @@ static char *netcfInterfaceGetXMLDesc(virInterfacePtr ifinfo,
         goto cleanup;
     }
 
-    ifacedef = virInterfaceDefParseString(xmlstr);
+    ifacedef = virInterfaceDefParseString(xmlstr, 0);
     if (!ifacedef) {
         /* error was already reported */
         goto cleanup;
@@ -898,7 +898,7 @@ static virInterfacePtr netcfInterfaceDefineXML(virConnectPtr conn,
 
     virObjectLock(driver);
 
-    ifacedef = virInterfaceDefParseString(xml);
+    ifacedef = virInterfaceDefParseString(xml, 0);
     if (!ifacedef) {
         /* error was already reported */
         goto cleanup;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 16d70d9025..149d1afdad 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1113,7 +1113,7 @@ testParseInterfaces(testDriver *privconn,
         if (!node)
             return -1;
 
-        def = virInterfaceDefParseNode(ctxt->doc, node);
+        def = virInterfaceDefParseNode(ctxt->doc, node, 0);
         if (!def)
             return -1;
 
@@ -6074,7 +6074,7 @@ testInterfaceDefineXML(virConnectPtr conn,
     virCheckFlags(0, NULL);
 
     virObjectLock(privconn);
-    if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
+    if ((def = virInterfaceDefParseString(xmlStr, flags)) == NULL)
         goto cleanup;
 
     if ((obj = virInterfaceObjListAssignDef(privconn->ifaces, def)) == NULL)
diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c
index 07d179e3a3..3785467f84 100644
--- a/tests/interfacexml2xmltest.c
+++ b/tests/interfacexml2xmltest.c
@@ -24,7 +24,7 @@ testCompareXMLToXMLFiles(const char *xml)
     if (virTestLoadFile(xml, &xmlData) < 0)
         goto fail;
 
-    if (!(dev = virInterfaceDefParseString(xmlData)))
+    if (!(dev = virInterfaceDefParseString(xmlData, 0)))
         goto fail;
 
     if (!(actual = virInterfaceDefFormat(dev)))
-- 
2.31.1




[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