[PATCH 2/4] conf: add validation and propagate flags into virInterfaceDefParse()

[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 virXMLParse().

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

diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index c371a252a8..464ff26856 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -685,7 +685,6 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     xmlNodePtr lnk;
 
-
     /* check @type */
     tmp = virXPathString("string(./@type)", ctxt);
     if (tmp == NULL) {
@@ -819,12 +818,14 @@ virInterfaceDefParseNode(xmlDocPtr xml,
 
 static virInterfaceDef *
 virInterfaceDefParse(const char *xmlStr,
-                     const char *filename)
+                     const char *filename,
+                     unsigned int flags)
 {
     g_autoptr(xmlDoc) xml = NULL;
     virInterfaceDef *def = NULL;
 
-    if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), NULL, false))) {
+    if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), "interface.rng",
+                           flags & VIR_INTERFACE_DEFINE_VALIDATE))) {
         def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
     }
 
@@ -833,16 +834,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..ea92e0fb31 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -155,7 +155,8 @@ void
 virInterfaceDefFree(virInterfaceDef *def);
 
 virInterfaceDef *
-virInterfaceDefParseString(const char *xmlStr);
+virInterfaceDefParseString(const char *xmlStr,
+                           unsigned int flags);
 
 virInterfaceDef *
 virInterfaceDefParseFile(const char *filename);
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 10a1767542..450510ee54 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -6159,7 +6159,7 @@ testInterfaceDefineXML(virConnectPtr conn,
     virCheckFlags(0, NULL);
 
     virObjectLock(privconn);
-    if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
+    if ((def = virInterfaceDefParseString(xmlStr, 0)) == 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