> +static int doParseURI(const char *uri, char **p_hostname, int *p_port)
> +{
> + char *p, *hostname;
> + int port_nr = 0;
> +
> + if (uri == NULL)
> + return -1;
> +
> + /* URI passed is a string "hostname[:port]" */
> + if ((p = strrchr(uri, ':')) != NULL) { /* "hostname:port" */
> + int n;
> +
> + if (virStrToLong_i(p+1, NULL, 10, &port_nr) < 0) {
> + libxlError(VIR_ERR_INVALID_ARG,
> + _("Invalid port number"));
> + return -1;
> + }
> +
> + /* Get the hostname. */
> + n = p - uri; /* n = Length of hostname in bytes. */
> + if (n <= 0) {
> + libxlError(VIR_ERR_INVALID_ARG,
> + _("Hostname must be specified in the URI"));
> + return -1;
> + }
> +
> + if (virAsprintf(&hostname, "%s", uri) < 0) {
> + virReportOOMError();
> + return -1;
> + }
> +
> + hostname[n] = '\0';
> + }
> + else {/* "hostname" (or IP address) */
> + if (virAsprintf(&hostname, "%s", uri) < 0) {
> + virReportOOMError();
> + return -1;
> + }
> + }
> + *p_hostname = hostname;
> + *p_port = port_nr;
> + return 0;
> +}
Lets not re-invent URI parsing code with wierd special cases for