1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-26 14:03:49 +03:00

Refactoring virDomainChrDefParseXML() to use XPath

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-05-04 13:40:08 +02:00 committed by Michal Privoznik
parent d705f5b4f2
commit 7fefde1f44

View File

@ -11531,11 +11531,13 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
xmlNodePtr node,
unsigned int flags)
{
xmlNodePtr cur;
xmlNodePtr target;
const char *nodeName;
virDomainChrDef *def;
bool seenTarget = false;
g_autofree char *type = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
ctxt->node = node;
if (!(def = virDomainChrDefNew(xmlopt)))
return NULL;
@ -11558,21 +11560,12 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
goto error;
}
cur = node->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
if (virXMLNodeNameEqual(cur, "target")) {
seenTarget = true;
if (virDomainChrDefParseTargetXML(def, cur, ctxt, flags) < 0)
goto error;
}
}
cur = cur->next;
}
if (!seenTarget &&
((def->targetType = virDomainChrDefaultTargetType(def->deviceType)) < 0))
if ((target = virXPathNode("./target", ctxt))) {
if (virDomainChrDefParseTargetXML(def, target, ctxt, flags) < 0)
goto error;
} else if ((def->targetType = virDomainChrDefaultTargetType(def->deviceType)) < 0) {
goto error;
}
if (virDomainChrSourceDefParseXML(def->source, node, flags, def,
ctxt) < 0)