1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-04-01 20:05:19 +00:00

Split out USB port parsing

Make rewriting it easier.
This commit is contained in:
Ján Tomko 2016-06-16 15:00:27 +02:00
parent e9843279cc
commit 0956d9b2a3

View File

@ -5100,12 +5100,31 @@ virDomainDeviceCcidAddressParseXML(xmlNodePtr node,
return ret;
}
static int
virDomainDeviceUSBAddressParsePort(char *port)
{
unsigned int p;
char *tmp;
if ((virStrToLong_uip(port, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.')) ||
(*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.'))) ||
(*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.'))) ||
(*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0'))))
goto error;
return 0;
error:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot parse <address> 'port' attribute"));
return -1;
}
static int
virDomainDeviceUSBAddressParseXML(xmlNodePtr node,
virDomainDeviceUSBAddressPtr addr)
{
char *port, *bus, *tmp;
unsigned int p;
char *port, *bus;
int ret = -1;
memset(addr, 0, sizeof(*addr));
@ -5113,15 +5132,8 @@ virDomainDeviceUSBAddressParseXML(xmlNodePtr node,
port = virXMLPropString(node, "port");
bus = virXMLPropString(node, "bus");
if (port &&
((virStrToLong_uip(port, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.')) ||
(*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.'))) ||
(*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.'))) ||
(*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0'))))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot parse <address> 'port' attribute"));
if (port && virDomainDeviceUSBAddressParsePort(port) < 0)
goto cleanup;
}
addr->port = port;
port = NULL;