mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-04 10:55:19 +00:00
Refactoring virDomainLeaseDefParseXML() to use XPath
Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
997b920433
commit
8d635a0bf2
@ -8042,54 +8042,43 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
|
|||||||
*/
|
*/
|
||||||
static virDomainLeaseDef *
|
static virDomainLeaseDef *
|
||||||
virDomainLeaseDefParseXML(xmlNodePtr node,
|
virDomainLeaseDefParseXML(xmlNodePtr node,
|
||||||
xmlXPathContextPtr ctxt G_GNUC_UNUSED)
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
virDomainLeaseDef *def;
|
virDomainLeaseDef *def;
|
||||||
xmlNodePtr cur;
|
|
||||||
g_autofree char *lockspace = NULL;
|
g_autofree char *lockspace = NULL;
|
||||||
g_autofree char *key = NULL;
|
g_autofree char *key = NULL;
|
||||||
g_autofree char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
g_autofree char *offset = NULL;
|
xmlNodePtr targetNode = NULL;
|
||||||
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||||
|
|
||||||
|
ctxt->node = node;
|
||||||
def = g_new0(virDomainLeaseDef, 1);
|
def = g_new0(virDomainLeaseDef, 1);
|
||||||
|
|
||||||
cur = node->children;
|
if (!(key = virXPathString("string(./key)", ctxt))) {
|
||||||
while (cur != NULL) {
|
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
|
||||||
if (!key && virXMLNodeNameEqual(cur, "key")) {
|
|
||||||
if (!(key = virXMLNodeContentString(cur)))
|
|
||||||
goto error;
|
|
||||||
} else if (!lockspace &&
|
|
||||||
virXMLNodeNameEqual(cur, "lockspace")) {
|
|
||||||
if (!(lockspace = virXMLNodeContentString(cur)))
|
|
||||||
goto error;
|
|
||||||
} else if (!path &&
|
|
||||||
virXMLNodeNameEqual(cur, "target")) {
|
|
||||||
path = virXMLPropString(cur, "path");
|
|
||||||
offset = virXMLPropString(cur, "offset");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!key) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("Missing 'key' element for lease"));
|
_("Missing 'key' element for lease"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!path) {
|
|
||||||
|
if (!(lockspace = virXPathString("string(./lockspace)", ctxt)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!(targetNode = virXPathNode("./target", ctxt))) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("Missing 'target' element for lease"));
|
_("Missing 'target' element for lease"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset &&
|
if (!(path = virXMLPropString(targetNode, "path"))) {
|
||||||
virStrToLong_ull(offset, NULL, 10, &def->offset) < 0) {
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
_("Missing 'path' attribute to 'target' element for lease"));
|
||||||
_("Malformed lease target offset %s"), offset);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virXMLPropULongLong(targetNode, "offset", 10,
|
||||||
|
VIR_XML_PROP_NONE, &def->offset) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
def->key = g_steal_pointer(&key);
|
def->key = g_steal_pointer(&key);
|
||||||
def->lockspace = g_steal_pointer(&lockspace);
|
def->lockspace = g_steal_pointer(&lockspace);
|
||||||
def->path = g_steal_pointer(&path);
|
def->path = g_steal_pointer(&path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user