Both callers be easily made to call virInterfaceDefParseXML directly. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/interface_conf.c | 35 +++++------------------------------ src/conf/interface_conf.h | 4 ++-- src/libvirt_private.syms | 2 +- src/test/test_driver.c | 8 ++++---- 4 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index a3f6b6bed6..628199c6f3 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -33,9 +33,6 @@ VIR_ENUM_IMPL(virInterface, "ethernet", "bridge", "bond", "vlan", ); -static virInterfaceDef * -virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType); - static int virInterfaceDefDevFormat(virBuffer *buf, const virInterfaceDef *def, virInterfaceType parentIfType); @@ -565,7 +562,7 @@ virInterfaceDefParseVlan(virInterfaceDef *def, } -static virInterfaceDef * +virInterfaceDef * virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) { @@ -672,42 +669,20 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, } -virInterfaceDef * -virInterfaceDefParseNode(xmlDocPtr xml, - xmlNodePtr root) -{ - g_autoptr(xmlXPathContext) ctxt = NULL; - - if (!virXMLNodeNameEqual(root, "interface")) { - virReportError(VIR_ERR_XML_ERROR, - _("unexpected root element <%s>, " - "expecting <interface>"), - root->name); - return NULL; - } - - if (!(ctxt = virXMLXPathContextNew(xml))) - return NULL; - - ctxt->node = root; - return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); -} - - static virInterfaceDef * virInterfaceDefParse(const char *xmlStr, const char *filename, unsigned int flags) { g_autoptr(xmlDoc) xml = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; bool validate = flags & VIR_INTERFACE_DEFINE_VALIDATE; - xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), - NULL, NULL, "interface.rng", validate); - if (!xml) + if (!(xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), + "interface", &ctxt, "interface.rng", validate))) return NULL; - return virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml)); + return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); } diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h index fa6bce9a00..b8927d7b4f 100644 --- a/src/conf/interface_conf.h +++ b/src/conf/interface_conf.h @@ -162,8 +162,8 @@ virInterfaceDef * virInterfaceDefParseFile(const char *filename); virInterfaceDef * -virInterfaceDefParseNode(xmlDocPtr xml, - xmlNodePtr root); +virInterfaceDefParseXML(xmlXPathContextPtr ctxt, + int parentIfType); char * virInterfaceDefFormat(const virInterfaceDef *def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9cbbfef093..1251bba896 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -793,8 +793,8 @@ virDomainDiskDefValidateStartupPolicy; virInterfaceDefFormat; virInterfaceDefFree; virInterfaceDefParseFile; -virInterfaceDefParseNode; virInterfaceDefParseString; +virInterfaceDefParseXML; # conf/netdev_bandwidth_conf.h diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 72786da568..5f98c05c34 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1110,6 +1110,7 @@ testParseInterfaces(testDriver *privconn, const char *file, xmlXPathContextPtr ctxt) { + VIR_XPATH_NODE_AUTORESTORE(ctxt) int num; size_t i; virInterfaceObj *obj; @@ -1121,12 +1122,11 @@ testParseInterfaces(testDriver *privconn, for (i = 0; i < num; i++) { g_autoptr(virInterfaceDef) def = NULL; - xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file); - if (!node) + + if (!(ctxt->node = testParseXMLDocFromFile(nodes[i], file))) return -1; - def = virInterfaceDefParseNode(ctxt->doc, node); - if (!def) + if (!(def = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST))) return -1; if (!(obj = virInterfaceObjListAssignDef(privconn->ifaces, &def))) -- 2.37.3