]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: xml: Introduce virXMLParseStringCtxtRoot
authorPeter Krempa <pkrempa@redhat.com>
Wed, 14 Apr 2021 12:16:28 +0000 (14:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Apr 2021 12:43:58 +0000 (14:43 +0200)
Use the new macro instead of virXMLParseStringCtxt in places where the
root node is being validated.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/conf/storage_conf.c
src/util/virxml.h

index 17bbeddec600a72f053af8289ee340df95bcf303..6795f0b3be4f8087d6d18ce3dd2d42bd0a85b567 100644 (file)
@@ -16438,16 +16438,9 @@ virDomainDiskDefParse(const char *xmlStr,
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
 
-    if (!(xml = virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &ctxt)))
+    if (!(xml = virXMLParseStringCtxtRoot(xmlStr, _("(disk_definition)"), "disk", &ctxt)))
         return NULL;
 
-    if (!virXMLNodeNameEqual(ctxt->node, "disk")) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("expecting root element of 'disk', not '%s'"),
-                       ctxt->node->name);
-        return NULL;
-    }
-
     return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, flags);
 }
 
index 66419616da81928398b4b412768774d4da4617ca..328650bd6a206d2da3ebcf799b300f758155fcea 100644 (file)
@@ -691,25 +691,19 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
                                    int pool_type)
 {
     g_autoptr(xmlDoc) doc = NULL;
-    xmlNodePtr node = NULL;
     g_autoptr(xmlXPathContext) xpath_ctxt = NULL;
     g_autoptr(virStoragePoolSource) def = NULL;
 
-    if (!(doc = virXMLParseStringCtxt(srcSpec,
-                                      _("(storage_source_specification)"),
-                                      &xpath_ctxt)))
+    if (!(doc = virXMLParseStringCtxtRoot(srcSpec,
+                                          _("(storage_source_specification)"),
+                                          "source",
+                                          &xpath_ctxt)))
         return NULL;
 
     def = g_new0(virStoragePoolSource, 1);
 
-    if (!(node = virXPathNode("/source", xpath_ctxt))) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("root element was not source"));
-        return NULL;
-    }
-
     if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type,
-                                     node) < 0)
+                                     xpath_ctxt->node) < 0)
         return NULL;
 
     return g_steal_pointer(&def);
index 38da2931a408c325135096af393616ab1fb77de2..2b40398eee14fe4cc6ecaf50e43eadfdfff5cfd9 100644 (file)
@@ -221,6 +221,10 @@ virXMLPickShellSafeComment(const char *str1,
 #define virXMLParseStringCtxt(xmlStr, url, pctxt) \
     virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt)
 
+/* virXMLParseStringCtxtRoot is same as above, except it also validates root node name */
+#define virXMLParseStringCtxtRoot(xmlStr, url, rootnode, pctxt) \
+    virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, rootnode, pctxt)
+
 /**
  * virXMLParseFileCtxt:
  * @filename: file to parse