conf: Move XPath context node in descendants of virSysinfoParseXML

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>
This commit is contained in:
Peter Krempa 2019-03-05 15:38:26 +01:00
parent 8f6ac3b740
commit 933f136844
1 changed files with 19 additions and 26 deletions

View 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: