mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virNWFilterBindingObjParse: Refactor XML parsing code
Remove the redundant root node checking and XPath context creation by using virXMLParse properly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f8d36b3f97
commit
2597e16e29
@ -202,74 +202,31 @@ virNWFilterBindingObjDelete(const virNWFilterBindingObj *obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virNWFilterBindingObj *
|
virNWFilterBindingObj *
|
||||||
virNWFilterBindingObjParseXML(xmlDocPtr doc,
|
virNWFilterBindingObjParse(const char *filename)
|
||||||
xmlXPathContextPtr ctxt)
|
|
||||||
{
|
{
|
||||||
virNWFilterBindingObj *ret;
|
g_autoptr(virNWFilterBindingObj) ret = NULL;
|
||||||
|
g_autoptr(xmlDoc) xml = NULL;
|
||||||
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||||
xmlNodePtr node;
|
xmlNodePtr node;
|
||||||
|
|
||||||
|
if (!(xml = virXMLParse(filename, NULL, _("(nwfilterbinding_status)"),
|
||||||
|
"filterbindingstatus", &ctxt, NULL, false)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (!(ret = virNWFilterBindingObjNew()))
|
if (!(ret = virNWFilterBindingObjNew()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(node = virXPathNode("./filterbinding", ctxt))) {
|
if (!(node = virXPathNode("./filterbinding", ctxt))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("filter binding status missing content"));
|
_("filter binding status missing content"));
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(ret->def = virNWFilterBindingDefParseNode(doc, node)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnref(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virNWFilterBindingObj *
|
|
||||||
virNWFilterBindingObjParseNode(xmlDocPtr doc,
|
|
||||||
xmlNodePtr root)
|
|
||||||
{
|
|
||||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
|
||||||
|
|
||||||
if (STRNEQ((const char *)root->name, "filterbindingstatus")) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("unknown root element '%s' for filter binding"),
|
|
||||||
root->name);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ctxt = virXMLXPathContextNew(doc)))
|
if (!(ret->def = virNWFilterBindingDefParseNode(xml, node)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ctxt->node = root;
|
return g_steal_pointer(&ret);
|
||||||
return virNWFilterBindingObjParseXML(doc, ctxt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virNWFilterBindingObj *
|
|
||||||
virNWFilterBindingObjParse(const char *xmlStr,
|
|
||||||
const char *filename)
|
|
||||||
{
|
|
||||||
virNWFilterBindingObj *obj = NULL;
|
|
||||||
g_autoptr(xmlDoc) xml = NULL;
|
|
||||||
|
|
||||||
if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)"),
|
|
||||||
NULL, NULL, NULL, false))) {
|
|
||||||
obj = virNWFilterBindingObjParseNode(xml, xmlDocGetRootElement(xml));
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virNWFilterBindingObj *
|
|
||||||
virNWFilterBindingObjParseFile(const char *filename)
|
|
||||||
{
|
|
||||||
return virNWFilterBindingObjParse(NULL, filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ virNWFilterBindingObjDelete(const virNWFilterBindingObj *obj,
|
|||||||
const char *statusDir);
|
const char *statusDir);
|
||||||
|
|
||||||
virNWFilterBindingObj *
|
virNWFilterBindingObj *
|
||||||
virNWFilterBindingObjParseFile(const char *filename);
|
virNWFilterBindingObjParse(const char *filename);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virNWFilterBindingObjFormat(const virNWFilterBindingObj *obj);
|
virNWFilterBindingObjFormat(const virNWFilterBindingObj *obj);
|
||||||
|
@ -266,7 +266,7 @@ virNWFilterBindingObjListLoadStatus(virNWFilterBindingObjList *bindings,
|
|||||||
if ((statusFile = virNWFilterBindingObjConfigFile(statusDir, name)) == NULL)
|
if ((statusFile = virNWFilterBindingObjConfigFile(statusDir, name)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(obj = virNWFilterBindingObjParseFile(statusFile)))
|
if (!(obj = virNWFilterBindingObjParse(statusFile)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
def = virNWFilterBindingObjGetDef(obj);
|
def = virNWFilterBindingObjGetDef(obj);
|
||||||
|
@ -1377,7 +1377,7 @@ virNWFilterBindingObjFormat;
|
|||||||
virNWFilterBindingObjGetDef;
|
virNWFilterBindingObjGetDef;
|
||||||
virNWFilterBindingObjGetRemoving;
|
virNWFilterBindingObjGetRemoving;
|
||||||
virNWFilterBindingObjNew;
|
virNWFilterBindingObjNew;
|
||||||
virNWFilterBindingObjParseFile;
|
virNWFilterBindingObjParse;
|
||||||
virNWFilterBindingObjSave;
|
virNWFilterBindingObjSave;
|
||||||
virNWFilterBindingObjSetDef;
|
virNWFilterBindingObjSetDef;
|
||||||
virNWFilterBindingObjSetRemoving;
|
virNWFilterBindingObjSetRemoving;
|
||||||
|
Loading…
Reference in New Issue
Block a user