mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
util: xml: Add wrapper for xmlXPathNewContext
The wrapper reports libvirt errors for the libxml2 function so that the same does not have to be repeated over and over. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
73aaa8f8c8
commit
bfedd14955
@ -227,11 +227,8 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml,
|
||||
if (virXMLValidateAgainstSchema(schema, xml) < 0)
|
||||
return NULL;
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, flags);
|
||||
|
@ -21575,11 +21575,8 @@ virDomainDefParseNode(xmlDocPtr xml,
|
||||
virDomainDefPtr def = NULL;
|
||||
virDomainDefPtr ret = NULL;
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
|
||||
@ -21621,10 +21618,8 @@ virDomainObjParseNode(xmlDocPtr xml,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(ctxt = xmlXPathNewContext(xml))) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
obj = virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags);
|
||||
|
@ -830,11 +830,8 @@ virInterfaceDefParseNode(xmlDocPtr xml,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST);
|
||||
|
@ -2125,11 +2125,8 @@ virNetworkDefParseNode(xmlDocPtr xml,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virNetworkDefParseXML(ctxt, xmlopt);
|
||||
|
@ -2063,11 +2063,8 @@ virNodeDeviceDefParseNode(xmlDocPtr xml,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virNodeDeviceDefParseXML(ctxt, create, virt_type);
|
||||
|
@ -2756,11 +2756,8 @@ virNWFilterDefParseNode(xmlDocPtr xml,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virNWFilterDefParseXML(ctxt);
|
||||
|
@ -144,11 +144,9 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
|
@ -450,11 +450,8 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, current, flags);
|
||||
|
@ -1024,11 +1024,8 @@ virStoragePoolDefParseNode(xmlDocPtr xml,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virStoragePoolDefParseXML(ctxt);
|
||||
@ -1468,11 +1465,8 @@ virStorageVolDefParseNode(virStoragePoolDefPtr pool,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virStorageVolDefParseXML(pool, ctxt, flags);
|
||||
|
@ -277,11 +277,8 @@ virNetworkPortDefParseNode(xmlDocPtr xml,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virNetworkPortDefParseXML(ctxt);
|
||||
|
@ -182,11 +182,8 @@ virNWFilterBindingDefParseNode(xmlDocPtr xml,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
def = virNWFilterBindingDefParseXML(ctxt);
|
||||
|
@ -248,11 +248,8 @@ virNWFilterBindingObjParseNode(xmlDocPtr doc,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(doc);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(doc)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
obj = virNWFilterBindingObjParseXML(doc, ctxt);
|
||||
|
@ -3365,6 +3365,7 @@ virXMLValidateAgainstSchema;
|
||||
virXMLValidatorFree;
|
||||
virXMLValidatorInit;
|
||||
virXMLValidatorValidate;
|
||||
virXMLXPathContextNew;
|
||||
virXPathBoolean;
|
||||
virXPathContextNodeRestore;
|
||||
virXPathInt;
|
||||
|
@ -3611,10 +3611,8 @@ virQEMUCapsLoadCache(virArch hostArch,
|
||||
if (!(doc = virXMLParseFile(filename)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(ctxt = xmlXPathNewContext(doc))) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(doc)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = xmlDocGetRootElement(doc);
|
||||
|
||||
|
@ -46,6 +46,20 @@ struct virParserData {
|
||||
};
|
||||
|
||||
|
||||
xmlXPathContextPtr
|
||||
virXMLXPathContextNew(xmlDocPtr xml)
|
||||
{
|
||||
xmlXPathContextPtr ctxt;
|
||||
|
||||
if (!(ctxt = xmlXPathNewContext(xml))) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctxt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXPathString:
|
||||
* @xpath: the XPath string to evaluate
|
||||
@ -824,11 +838,9 @@ virXMLParseHelper(int domcode,
|
||||
}
|
||||
|
||||
if (ctxt) {
|
||||
*ctxt = xmlXPathNewContext(xml);
|
||||
if (!*ctxt) {
|
||||
virReportOOMError();
|
||||
if (!(*ctxt = virXMLXPathContextNew(xml)))
|
||||
goto error;
|
||||
}
|
||||
|
||||
(*ctxt)->node = xmlDocGetRootElement(xml);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,9 @@
|
||||
#include "virbuffer.h"
|
||||
#include "virautoclean.h"
|
||||
|
||||
xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml)
|
||||
ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
int virXPathBoolean(const char *xpath,
|
||||
xmlXPathContextPtr ctxt);
|
||||
char * virXPathString(const char *xpath,
|
||||
|
@ -615,10 +615,9 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath,
|
||||
_("Unable to parse the xml"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(xPathContext = xmlXPathNewContext(xml))) {
|
||||
virReportOOMError();
|
||||
if (!(xPathContext = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (xmlXPathRegisterNs(xPathContext,
|
||||
BAD_CAST "vbox",
|
||||
BAD_CAST "http://www.innotek.de/VirtualBox-settings") < 0) {
|
||||
@ -1299,10 +1298,10 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath,
|
||||
_("Unable to parse the xml"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(xPathContext = xmlXPathNewContext(xml))) {
|
||||
virReportOOMError();
|
||||
|
||||
if (!(xPathContext = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
xPathContext->node = xmlDocGetRootElement(xml);
|
||||
if ((nodeSize = virXPathNodeSet("/domainsnapshot/disks/disk",
|
||||
xPathContext, &nodes)) < 0)
|
||||
@ -1360,10 +1359,10 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath,
|
||||
_("Unable to parse the xml"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(xPathContext = xmlXPathNewContext(xml))) {
|
||||
virReportOOMError();
|
||||
|
||||
if (!(xPathContext = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
xPathContext->node = xmlDocGetRootElement(xml);
|
||||
if ((nodeSize = virXPathNodeSet("/domainsnapshot/domain/devices/disk",
|
||||
xPathContext,
|
||||
|
@ -4674,11 +4674,9 @@ prlsdkParseSnapshotTree(const char *treexml)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (ctxt == NULL) {
|
||||
virReportOOMError();
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ctxt->node = root;
|
||||
|
||||
if ((n = virXPathNodeSet("//SavedStateItem", ctxt, &nodes)) < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user