]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: xml: Add wrapper for xmlXPathNewContext
authorPeter Krempa <pkrempa@redhat.com>
Mon, 9 Sep 2019 06:33:58 +0000 (08:33 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 19 Sep 2019 12:31:15 +0000 (14:31 +0200)
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>
18 files changed:
src/conf/checkpoint_conf.c
src/conf/domain_conf.c
src/conf/interface_conf.c
src/conf/network_conf.c
src/conf/node_device_conf.c
src/conf/nwfilter_conf.c
src/conf/secret_conf.c
src/conf/snapshot_conf.c
src/conf/storage_conf.c
src/conf/virnetworkportdef.c
src/conf/virnwfilterbindingdef.c
src/conf/virnwfilterbindingobj.c
src/libvirt_private.syms
src/qemu/qemu_capabilities.c
src/util/virxml.c
src/util/virxml.h
src/vbox/vbox_snapshot_conf.c
src/vz/vz_sdk.c

index a3513aaa657ad0f1786cec613229c49d2e684626..113d85cc14fe4a4f788bb0212efeef6ba3b8bf96 100644 (file)
@@ -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);
index 848c831330232e0704d4eb947f966a73e55b7e25..e5e3f31f769415644707bc72ddb18d7d30aaeb78 100644 (file)
@@ -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);
index b134ff4adccc375841429e9388df0f3187e7f3b7..64729aea43e0056411ee0696182d5921aefd4910 100644 (file)
@@ -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);
index aa0d48af8f3553969e8b3ecb3fdc1f6e77c5c59f..585c87a9f4b05ba97aa5eb039d025a556f864785 100644 (file)
@@ -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);
index 618ce8e00e5c974b993f5e1683971310134ff95b..8f8830aef19968217bf49879a4053fc4044b8055 100644 (file)
@@ -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);
index cecee51d87ad14bcc74f673059535b3570a0fe4d..21885eb7ae36a22951b022a2769e9a37aa0ac71e 100644 (file)
@@ -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);
index b291339e77bbf0aa49a296cd7f2a05ad5a0dd617..a7691da7b5260a51f8d214faef6181163d1d36ab 100644 (file)
@@ -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)
index cce9a7999c22e5375424bf597055d4942429d58a..8cf80aed83d2e2d8a5416e6d6affdeed8c040a1d 100644 (file)
@@ -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);
index 024f047fabdecb8b0e6907ddd8e1bd3da1dbf3f3..05609942810606931dc74748fac55f427b2ebe38 100644 (file)
@@ -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);
index 29ecf5b178ed1bc9b396cae0ac628bf8804617df..2e20bff66ecff4baf0da7887adc516bab1f4496f 100644 (file)
@@ -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);
index facca61833884117eb18d2b3ea4bd2fdb6ada472..6f13bc581a5836666cf81214a6c56c762a165a5b 100644 (file)
@@ -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);
index 68afb9c4340da82664ab4fedc6c552165456fff3..06dd66a5d1abc658f1417091a2ca50a6a121c51b 100644 (file)
@@ -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);
index 9510686ebf47e7dd21f5fc7295645bacbee7cdfb..39812227aa22177ffd33f33b51d34ff328337676 100644 (file)
@@ -3365,6 +3365,7 @@ virXMLValidateAgainstSchema;
 virXMLValidatorFree;
 virXMLValidatorInit;
 virXMLValidatorValidate;
+virXMLXPathContextNew;
 virXPathBoolean;
 virXPathContextNodeRestore;
 virXPathInt;
index a7575fcd8b2ce82db1b5bb8ecc860b8e5e2a7614..43f01bf2ba5ddce11544e18a5be8b0faebb1454f 100644 (file)
@@ -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);
 
index f9c117dd5884a940739557590df88e9d5db904cd..245ca0a752b9c2bb5e50fcdb77e98de79a88fade 100644 (file)
@@ -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);
     }
 
index 30cc8954364cb850ca7f3568f5e87ed0e46a5b08..39e5a988a2d98993d7af525907ea64291ac9d65f 100644 (file)
@@ -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,
index a36da30a4fd92759fbd1fef981df5de6f111f9b2..a6daf0ffcfb9cb6175adee66c551a985e035dd7a 100644 (file)
@@ -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,
index 478443298f77583e76d579a91eb515bcc749e54d..c6e3398620bc9595aac6dbf0f7d0851915943d91 100644 (file)
@@ -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) {