mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
util: xml: Introduce virXMLParseStringCtxtRoot
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>
This commit is contained in:
parent
3362ab5e02
commit
5c56538937
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user