[Spice-devel] [PATCH v2 1/3] proxy: support ipv6 addresses in brackets
Christophe Fergeau
cfergeau at redhat.com
Mon Oct 12 09:19:06 PDT 2015
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 at proxmox.com>
> ---
> 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 at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20151012/c73861dc/attachment.sig>
More information about the Spice-devel
mailing list