<br><br><div class="gmail_quote">2012/3/19 Daniel P. Berrange <span dir="ltr"><<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Fri, Mar 09, 2012 at 06:55:55PM +0800, Chunyan Liu wrote:<br>
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c<br>
> index d5fa64a..5dc29a0 100644<br>
> --- a/src/libxl/libxl_driver.c<br>
> +++ b/src/libxl/libxl_driver.c<br>
</div><div><div class="h5">> +static int doParseURI(const char *uri, char **p_hostname, int *p_port)<br>
> +{<br>
> +    char *p, *hostname;<br>
> +    int port_nr = 0;<br>
> +<br>
> +    if (uri == NULL)<br>
> +        return -1;<br>
> +<br>
> +    /* URI passed is a string "hostname[:port]" */<br>
> +    if ((p = strrchr(uri, ':')) != NULL) { /* "hostname:port" */<br>
> +        int n;<br>
> +<br>
> +        if (virStrToLong_i(p+1, NULL, 10, &port_nr) < 0) {<br>
> +            libxlError(VIR_ERR_INVALID_ARG,<br>
> +                        _("Invalid port number"));<br>
> +            return -1;<br>
> +        }<br>
> +<br>
> +        /* Get the hostname. */<br>
> +        n = p - uri; /* n = Length of hostname in bytes. */<br>
> +        if (n <= 0) {<br>
> +            libxlError(VIR_ERR_INVALID_ARG,<br>
> +                       _("Hostname must be specified in the URI"));<br>
> +            return -1;<br>
> +        }<br>
> +<br>
> +        if (virAsprintf(&hostname, "%s", uri) < 0) {<br>
> +            virReportOOMError();<br>
> +            return -1;<br>
> +        }<br>
> +<br>
> +        hostname[n] = '\0';<br>
> +    }<br>
> +    else {/* "hostname" (or IP address) */<br>
> +        if (virAsprintf(&hostname, "%s", uri) < 0) {<br>
> +            virReportOOMError();<br>
> +            return -1;<br>
> +        }<br>
> +    }<br>
> +    *p_hostname = hostname;<br>
> +    *p_port = port_nr;<br>
> +    return 0;<br>
> +}<br>
<br>
</div></div>Lets not re-invent URI parsing code with wierd special cases for<br>
base hostnames. Please just use virURIParse, since there is no<br>
compatibility issue here.<br></blockquote></div><br>virURIParse can only parse full URI format like xenmigr://destIP:port, cannot handle simple URI like destIP:port correctly. Both xen_driver and qemu_driver have extra code like in doParseURI to handle the simple URI case.<br>
For libxl driver, currently use syntax: virsh migrate domU xen+ssh://destIP destIP[:port], so to parse hostname and port, need extra code to handle that but not virURIParse. And since there are several places that need to parse "port", so I extract the code to function doParseURI.<br>