From: Kirill Shchetiniuk Date: Tue, 22 Jul 2025 15:12:02 +0000 (+0200) Subject: conf: virNetDevVPortProfileParse refactor X-Git-Tag: v11.6.0-rc1~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1173b091fe9b3cfdb74c5730018ecae7717180a2;p=thirdparty%2Flibvirt.git conf: virNetDevVPortProfileParse refactor Refactored the virNetDevVPortProfileParse function to use the appropriate virXMLProp* functions to parse input configuration XML. Signed-off-by: Kirill Shchetiniuk Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index 032a3147d7..523d9b642c 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -29,12 +29,6 @@ virNetDevVPortProfile * virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags) { g_autofree char *virtPortType = NULL; - g_autofree char *virtPortManagerID = NULL; - g_autofree char *virtPortTypeID = NULL; - g_autofree char *virtPortTypeIDVersion = NULL; - g_autofree char *virtPortInstanceID = NULL; - g_autofree char *virtPortProfileID = NULL; - g_autofree char *virtPortInterfaceID = NULL; g_autofree virNetDevVPortProfile *virtPort = NULL; xmlNodePtr parameters; @@ -55,88 +49,82 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags) } if ((parameters = virXMLNodeGetSubelement(node, "parameters"))) { - virtPortManagerID = virXMLPropString(parameters, "managerid"); - virtPortTypeID = virXMLPropString(parameters, "typeid"); - virtPortTypeIDVersion = virXMLPropString(parameters, "typeidversion"); - virtPortInstanceID = virXMLPropString(parameters, "instanceid"); - virtPortProfileID = virXMLPropString(parameters, "profileid"); - virtPortInterfaceID = virXMLPropString(parameters, "interfaceid"); - } - - if (virtPortManagerID) { + int rc; unsigned int val; + g_autofree char *virtPortProfileID = NULL; - if (virStrToLong_ui(virtPortManagerID, NULL, 0, &val)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse value of managerid parameter")); + virtPortProfileID = virXMLPropString(parameters, "profileid"); + + if ((rc = virXMLPropUInt(parameters, "managerid", 10, + VIR_XML_PROP_NONE, &val)) < 0) { return NULL; } - if (val > 0xff) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("value of managerid out of range")); + + if (rc > 0) { + if (val > 0xff) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("value of managerid out of range")); + return NULL; + } + + virtPort->managerID = val; + virtPort->managerID_specified = true; + } + + if ((rc = virXMLPropUInt(parameters, "typeid", 10, + VIR_XML_PROP_NONE, &val)) < 0) { return NULL; } - virtPort->managerID = (uint8_t)val; - virtPort->managerID_specified = true; - } - if (virtPortTypeID) { - unsigned int val; + if (rc > 0) { + if (val > 0xffffff) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("value for typeid out of range")); + return NULL; + } - if (virStrToLong_ui(virtPortTypeID, NULL, 0, &val)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse value of typeid parameter")); - return NULL; + virtPort->typeID = val; + virtPort->typeID_specified = true; } - if (val > 0xffffff) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("value for typeid out of range")); + + if ((rc = virXMLPropUInt(parameters, "typeidversion", 10, + VIR_XML_PROP_NONE, &val)) < 0) { return NULL; } - virtPort->typeID = (uint32_t)val; - virtPort->typeID_specified = true; - } - if (virtPortTypeIDVersion) { - unsigned int val; + if (rc > 0) { + if (val > 0xff) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("value of typeidversion out of range")); + return NULL; + } - if (virStrToLong_ui(virtPortTypeIDVersion, NULL, 0, &val)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse value of typeidversion parameter")); - return NULL; + virtPort->typeIDVersion = val; + virtPort->typeIDVersion_specified = true; } - if (val > 0xff) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("value of typeidversion out of range")); + + if ((rc = virXMLPropUUID(parameters, "instanceid", + VIR_XML_PROP_NONE, virtPort->instanceID)) < 0) { return NULL; } - virtPort->typeIDVersion = (uint8_t)val; - virtPort->typeIDVersion_specified = true; - } - if (virtPortInstanceID) { - if (virUUIDParse(virtPortInstanceID, virtPort->instanceID) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse instanceid parameter as a uuid")); + if (rc > 0) + virtPort->instanceID_specified = true; + + if ((rc = virXMLPropUUID(parameters, "interfaceid", + VIR_XML_PROP_NONE, virtPort->interfaceID)) < 0) { return NULL; } - virtPort->instanceID_specified = true; - } - if (virtPortProfileID && - virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("profileid parameter too long")); - return NULL; - } + if (rc > 0) + virtPort->interfaceID_specified = true; - if (virtPortInterfaceID) { - if (virUUIDParse(virtPortInterfaceID, virtPort->interfaceID) < 0) { + if (virtPortProfileID && + virStrcpyStatic(virtPort->profileID, virtPortProfileID) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("cannot parse interfaceid parameter as a uuid")); + _("profileid parameter too long")); return NULL; } - virtPort->interfaceID_specified = true; } /* generate default instanceID/interfaceID if appropriate */