After previous cleanups, the virNetworkPortDefParseXML() function
uses a mixture of virXMLProp*() and the old virXMLPropString() +
virXXXTypeFromString() patterns. Rework it so that virXMLProp*()
is used.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/virnetworkportdef.c | 20 +++++++++-----------
src/conf/virnetworkportdef.h | 2 +-
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index 1d75436085..fcd9e55a55 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -92,7 +92,6 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
g_autofree char *mac = NULL;
g_autofree char *macmgr = NULL;
g_autofree char *mode = NULL;
- g_autofree char *plugtype = NULL;
g_autofree char *driver = NULL;
def = g_new0(virNetworkPortDef, 1);
@@ -176,13 +175,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
return NULL;
plugNode = virXPathNode("./plug", ctxt);
- plugtype = virXPathString("string(./plug/@type)", ctxt);
- if (plugtype &&
- (def->plugtype = virNetworkPortPlugTypeFromString(plugtype)) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid network port plug type '%s'"),
plugtype);
- }
+ if (virXMLPropEnum(plugNode, "type",
+ virNetworkPortPlugTypeFromString,
+ VIR_XML_PROP_NONE,
+ &def->plugtype) < 0)
+ return NULL;
switch (def->plugtype) {
case VIR_NETWORK_PORT_PLUG_TYPE_NONE:
@@ -190,12 +188,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK:
case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE:
- if (!(def->plug.bridge.brname =
virXPathString("string(./plug/@bridge)", ctxt))) {
+ if (!(def->plug.bridge.brname = virXMLPropString(plugNode,
"bridge"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network port bridge name"));
return NULL;
}
- macmgr = virXPathString("string(./plug/@macTableManager)", ctxt);
+ macmgr = virXMLPropString(plugNode, "macTableManager");
if (macmgr &&
(def->plug.bridge.macTableManager =
virNetworkBridgeMACTableManagerTypeFromString(macmgr)) <= 0) {
@@ -207,12 +205,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
break;
case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT:
- if (!(def->plug.direct.linkdev =
virXPathString("string(./plug/@dev)", ctxt))) {
+ if (!(def->plug.direct.linkdev = virXMLPropString(plugNode, "dev")))
{
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing network port link device name"));
return NULL;
}
- mode = virXPathString("string(./plug/@mode)", ctxt);
+ mode = virXMLPropString(plugNode, "mode");
if (mode &&
(def->plug.direct.mode =
virNetDevMacVLanModeTypeFromString(mode)) < 0) {
diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h
index c6474c4ad8..ee13f8a084 100644
--- a/src/conf/virnetworkportdef.h
+++ b/src/conf/virnetworkportdef.h
@@ -58,7 +58,7 @@ struct _virNetworkPortDef {
virTristateBool trustGuestRxFilters;
virTristateBool isolatedPort;
- int plugtype; /* virNetworkPortPlugType */
+ virNetworkPortPlugType plugtype;
union {
struct {
char *brname;
--
2.34.1