Re: [PATCH v2 1/3] proxy: support ipv6 addresses in brackets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,

So we have both spice_uri_parse() and spice_parse_uri(), the former used
for parsing proxy URIs, the latter for parsing spice:// URIs.
spice_parse_uri() supports [] notation, but also knows how to unescape
URI components (eg @ encoded as %40 in usernames), which
spice_uri_parse() does not seem to be doing.
Have you tried making these 2 functions use common code?

Christophe

On Mon, Oct 05, 2015 at 04:16:41PM +0200, Wolfgang Bumiller wrote:
> Signed-off-by: Wolfgang Bumiller <w.bumiller@xxxxxxxxxxx>
> ---
>  src/spice-uri.c | 36 +++++++++++++++++++++++++++++-------
>  1 file changed, 29 insertions(+), 7 deletions(-)
> 
> diff --git a/src/spice-uri.c b/src/spice-uri.c
> index 82aefdb..c0d2d9c 100644
> --- a/src/spice-uri.c
> +++ b/src/spice-uri.c
> @@ -114,11 +114,24 @@ gboolean spice_uri_parse(SpiceURI *self, const gchar *_uri, GError **error)
>          uri = next;
>      }
>  
> -    /* max 2 parts, host:port */
> -    gchar **uriv = g_strsplit(uri, ":", 2);
> +    /* ipv6 support */
> +    gchar **uriv = NULL;
>      const gchar *uri_port = NULL;
> +    if (uri[0] == '[') {
> +        gchar *end = strchr(uri+1, ']');
> +        if (end) {
> +            *end = 0;
> +            uriv = g_malloc(sizeof(gchar*)*3);
> +            uriv[0] = g_strdup(uri+1);
> +            uriv[1] = (end[1] == ':') ? g_strdup(end+2) : NULL;
> +            uriv[2] = NULL;
> +        }
> +    } else {
> +        /* max 2 parts, host:port */
> +        uriv = g_strsplit(uri, ":", 2);
> +    }
>  
> -    if (uriv[0] == NULL || strlen(uriv[0]) == 0) {
> +    if (!uriv || uriv[0] == NULL || strlen(uriv[0]) == 0) {
>          g_set_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
>                      "Invalid hostname in uri address");
>          goto end;
> @@ -387,14 +400,23 @@ gchar* spice_uri_to_string(SpiceURI* self)
>      if (self->scheme == NULL || self->hostname == NULL)
>          return NULL;
>  
> +    gchar *brackets[2] = { "", "" };
> +    if (strchr(self->hostname, ':')) {
> +        brackets[0] = "[";
> +        brackets[1] = "]";
> +    }
> +
>      if (self->user || self->password)
> -        return g_strdup_printf("%s://%s:%s@%s:%u",
> +        return g_strdup_printf("%s://%s%s%s:%s@%s:%u",
>                                 self->scheme,
>                                 self->user, self->password,
> -                               self->hostname, self->port);
> +                               brackets[0], self->hostname, brackets[1],
> +                               self->port);
>      else
> -        return g_strdup_printf("%s://%s:%u",
> -                               self->scheme, self->hostname, self->port);
> +        return g_strdup_printf("%s://%s%s%s:%u",
> +                               self->scheme,
> +                               brackets[0], self->hostname, brackets[1],
> +                               self->port);
>  }
>  
>  /**
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> http://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]