]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Move XPath context node in descendants of virSysinfoParseXML
authorPeter Krempa <pkrempa@redhat.com>
Tue, 5 Mar 2019 14:38:26 +0000 (15:38 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 6 Mar 2019 14:53:53 +0000 (15:53 +0100)
Rather than moving the XPath root node in the caller and then still
passing it down, make sure that the callees move the node themselves.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index ea4fbf2280f31900d7217430178f88de076f7bdb..bbeb1c1a8dc2436c34c5d426a02882b9cda4cfc6 100644 (file)
@@ -14606,9 +14606,12 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
                        xmlXPathContextPtr ctxt,
                        virSysinfoBIOSDefPtr *bios)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoBIOSDefPtr def;
 
+    ctxt->node = node;
+
     if (!virXMLNodeNameEqual(node, "bios")) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("XML does not contain expected 'bios' element"));
@@ -14666,10 +14669,13 @@ virSysinfoSystemParseXML(xmlNodePtr node,
                          unsigned char *domUUID,
                          bool uuid_generated)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoSystemDefPtr def;
     VIR_AUTOFREE(char *) tmpUUID = NULL;
 
+    ctxt->node = node;
+
     if (!virXMLNodeNameEqual(node, "system")) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("XML does not contain expected 'system' element"));
@@ -14786,15 +14792,19 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt,
 
 
 static int
-virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt,
+virSysinfoOEMStringsParseXML(xmlNodePtr node,
+                             xmlXPathContextPtr ctxt,
                              virSysinfoOEMStringsDefPtr *oem)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoOEMStringsDefPtr def;
     int nstrings;
     size_t i;
     VIR_AUTOFREE(xmlNodePtr *) strings = NULL;
 
+    ctxt->node = node;
+
     nstrings = virXPathNodeSet("./entry", ctxt, &strings);
     if (nstrings < 0)
         return -1;
@@ -14824,9 +14834,12 @@ virSysinfoChassisParseXML(xmlNodePtr node,
                          xmlXPathContextPtr ctxt,
                          virSysinfoChassisDefPtr *chassisdef)
 {
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
     int ret = -1;
     virSysinfoChassisDefPtr def;
 
+    ctxt->node = node;
+
     if (!xmlStrEqual(node->name, BAD_CAST "chassis")) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("XML does not contain expected 'chassis' element"));
@@ -14868,7 +14881,7 @@ virSysinfoParseXML(xmlNodePtr node,
                   bool uuid_generated)
 {
     virSysinfoDefPtr def;
-    xmlNodePtr oldnode, tmpnode;
+    xmlNodePtr tmpnode;
     VIR_AUTOFREE(char *) type = NULL;
 
     if (!virXMLNodeNameEqual(node, "sysinfo")) {
@@ -14894,25 +14907,15 @@ virSysinfoParseXML(xmlNodePtr node,
 
     /* Extract BIOS related metadata */
     if ((tmpnode = virXPathNode("./bios[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
-        if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0) {
-            ctxt->node = oldnode;
+        if (virSysinfoBIOSParseXML(tmpnode, ctxt, &def->bios) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }
 
     /* Extract system related metadata */
     if ((tmpnode = virXPathNode("./system[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
         if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system,
-                                     domUUID, uuid_generated) < 0) {
-            ctxt->node = oldnode;
+                                     domUUID, uuid_generated) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }
 
     /* Extract system base board metadata */
@@ -14921,24 +14924,14 @@ virSysinfoParseXML(xmlNodePtr node,
 
     /* Extract chassis related metadata */
     if ((tmpnode = virXPathNode("./chassis[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
-        if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0) {
-            ctxt->node = oldnode;
+        if (virSysinfoChassisParseXML(tmpnode, ctxt, &def->chassis) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }
 
     /* Extract system related metadata */
     if ((tmpnode = virXPathNode("./oemStrings[1]", ctxt)) != NULL) {
-        oldnode = ctxt->node;
-        ctxt->node = tmpnode;
-        if (virSysinfoOEMStringsParseXML(ctxt, &def->oemStrings) < 0) {
-            ctxt->node = oldnode;
+        if (virSysinfoOEMStringsParseXML(tmpnode, ctxt, &def->oemStrings) < 0)
             goto error;
-        }
-        ctxt->node = oldnode;
     }
 
  cleanup: