virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml, xmlNodePtr root) { xmlXPathContextPtr ctxt = NULL; virInterfaceDefPtr def = NULL; if (!xmlStrEqual(root->name, BAD_CAST "interface")) { virInterfaceReportError(VIR_ERR_XML_ERROR, _("unexpected root element <%s>, " "expecting <interface>"), root->name); return NULL; } ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { virReportOOMError(); goto cleanup; } ctxt->node = root; def = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); cleanup: xmlXPathFreeContext(ctxt); return def; }
static int virInterfaceDefParseBondItfs(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr *interfaces = NULL; xmlNodePtr bond = ctxt->node; virInterfaceDefPtr itf; int nbItf, i; int ret = 0; nbItf = virXPathNodeSet("./interface", ctxt, &interfaces); if (nbItf < 0) { ret = -1; goto error; } if (nbItf == 0) { virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bond has no interfaces")); ret = -1; goto error; } if (VIR_ALLOC_N(def->data.bond.itf, nbItf) < 0) { virReportOOMError(); ret = -1; goto error; } def->data.bond.nbItf = nbItf; for (i = 0; i < nbItf;i++) { ctxt->node = interfaces[i]; itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND); if (itf == NULL) { ret = -1; def->data.bond.nbItf = i; goto error; } def->data.bond.itf[i] = itf; } error: VIR_FREE(interfaces); ctxt->node = bond; return ret; }
static int virInterfaceDefParseBridge(virInterfaceDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr *interfaces = NULL; xmlNodePtr bridge; virInterfaceDefPtr itf; int nbItf, i; int ret = 0; bridge = ctxt->node; nbItf = virXPathNodeSet("./interface", ctxt, &interfaces); if (nbItf < 0) { virInterfaceReportError(VIR_ERR_XML_ERROR, "%s", _("bridge interfaces")); ret = -1; goto error; } if (nbItf > 0) { if (VIR_ALLOC_N(def->data.bridge.itf, nbItf) < 0) { virReportOOMError(); ret = -1; goto error; } def->data.bridge.nbItf = nbItf; for (i = 0; i < nbItf;i++) { ctxt->node = interfaces[i]; itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDGE); if (itf == NULL) { ret = -1; def->data.bridge.nbItf = i; goto error; } def->data.bridge.itf[i] = itf; } } error: VIR_FREE(interfaces); ctxt->node = bridge; return(ret); }