mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virNWFilterBindingDefParse: Properly use virXMLParse
Fetch the XPath context and validate the node by using virXMLParse's features. This allows to completely remove virNWFilterBindingDefParseNode as all callers now properly validate the root element name and have a XPath context handy. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3761a67625
commit
3eb151ddfd
@ -71,7 +71,7 @@ virNWFilterBindingDefCopy(virNWFilterBindingDef *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virNWFilterBindingDef *
|
virNWFilterBindingDef *
|
||||||
virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt)
|
virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
virNWFilterBindingDef *ret;
|
virNWFilterBindingDef *ret;
|
||||||
@ -154,42 +154,20 @@ virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virNWFilterBindingDef *
|
|
||||||
virNWFilterBindingDefParseNode(xmlDocPtr xml,
|
|
||||||
xmlNodePtr root)
|
|
||||||
{
|
|
||||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
|
||||||
|
|
||||||
if (STRNEQ((const char *)root->name, "filterbinding")) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
"%s",
|
|
||||||
_("unknown root element for nwfilter binding"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ctxt->node = root;
|
|
||||||
return virNWFilterBindingDefParseXML(ctxt);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virNWFilterBindingDef *
|
static virNWFilterBindingDef *
|
||||||
virNWFilterBindingDefParse(const char *xmlStr,
|
virNWFilterBindingDefParse(const char *xmlStr,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virNWFilterBindingDef *def = NULL;
|
|
||||||
g_autoptr(xmlDoc) xml = NULL;
|
g_autoptr(xmlDoc) xml = NULL;
|
||||||
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||||
bool validate = flags & VIR_NWFILTER_BINDING_CREATE_VALIDATE;
|
bool validate = flags & VIR_NWFILTER_BINDING_CREATE_VALIDATE;
|
||||||
|
|
||||||
if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_definition)"),
|
if (!(xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_definition)"),
|
||||||
NULL, NULL, "nwfilterbinding.rng", validate))) {
|
"filterbinding", &ctxt, "nwfilterbinding.rng", validate)))
|
||||||
def = virNWFilterBindingDefParseNode(xml, xmlDocGetRootElement(xml));
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return def;
|
return virNWFilterBindingDefParseXML(ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,8 +47,7 @@ virNWFilterBindingDef *
|
|||||||
virNWFilterBindingDefCopy(virNWFilterBindingDef *src);
|
virNWFilterBindingDefCopy(virNWFilterBindingDef *src);
|
||||||
|
|
||||||
virNWFilterBindingDef *
|
virNWFilterBindingDef *
|
||||||
virNWFilterBindingDefParseNode(xmlDocPtr xml,
|
virNWFilterBindingDefParseXML(xmlXPathContextPtr ctxt);
|
||||||
xmlNodePtr root);
|
|
||||||
|
|
||||||
virNWFilterBindingDef *
|
virNWFilterBindingDef *
|
||||||
virNWFilterBindingDefParseString(const char *xml,
|
virNWFilterBindingDefParseString(const char *xml,
|
||||||
|
@ -223,7 +223,9 @@ virNWFilterBindingObjParse(const char *filename)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret->def = virNWFilterBindingDefParseNode(xml, node)))
|
ctxt->node = node;
|
||||||
|
|
||||||
|
if (!(ret->def = virNWFilterBindingDefParseXML(ctxt)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return g_steal_pointer(&ret);
|
return g_steal_pointer(&ret);
|
||||||
|
@ -1365,8 +1365,8 @@ virNWFilterBindingDefFormat;
|
|||||||
virNWFilterBindingDefFormatBuf;
|
virNWFilterBindingDefFormatBuf;
|
||||||
virNWFilterBindingDefFree;
|
virNWFilterBindingDefFree;
|
||||||
virNWFilterBindingDefParseFile;
|
virNWFilterBindingDefParseFile;
|
||||||
virNWFilterBindingDefParseNode;
|
|
||||||
virNWFilterBindingDefParseString;
|
virNWFilterBindingDefParseString;
|
||||||
|
virNWFilterBindingDefParseXML;
|
||||||
|
|
||||||
|
|
||||||
# conf/virnwfilterbindingobj.h
|
# conf/virnwfilterbindingobj.h
|
||||||
|
Loading…
Reference in New Issue
Block a user