[Spice-devel] [PATCH] spice-session: support uri with colon

Alon Levy alevy at redhat.com
Tue Jan 3 08:51:44 PST 2012


On Tue, Jan 03, 2012 at 06:31:05PM +0200, Alon Levy wrote:

Please ignore this patch, sending a new fixed version (this one
silently parsed host:port&blabla and threw away the blabla).

> With this patch if you use:
>  spice://<host>:<port>
> 
> You will get a warning (g_warning) and it will be treated the same as
>  spice://<host>?port=<port>
> ---
>  gtk/spice-session.c |   35 ++++++++++++++++++++++++++++++-----
>  1 files changed, 30 insertions(+), 5 deletions(-)
> 
> diff --git a/gtk/spice-session.c b/gtk/spice-session.c
> index a2fa550..d0dbdc7 100644
> --- a/gtk/spice-session.c
> +++ b/gtk/spice-session.c
> @@ -241,6 +241,8 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
>      SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
>      char host[128], key[32], value[128];
>      char *port = NULL, *tls_port = NULL, *uri = NULL, *password = NULL;
> +    char **target_key;
> +    int punctuation = 0;
>      int len, pos = 0;
>  
>      g_return_val_if_fail(original_uri != NULL, -1);
> @@ -258,25 +260,48 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
>      for (;;) {
>          if (uri[pos] == '?' || uri[pos] == ';' || uri[pos] == '&') {
>              pos++;
> +            punctuation++;
>              continue;
>          }
>          if (uri[pos] == 0) {
>              break;
>          }
> -        if (sscanf(uri + pos, "%31[-a-zA-Z0-9]=%127[^;&]%n", key, value, &len) != 2)
> -            goto fail;
> +        if (uri[pos] == ':') {
> +            g_warning("usage of colon in spice URI parsing. Treating as a port (?port=)");
> +            if (punctuation++) {
> +                g_warning("colon seen after a previous punctuation (?;&:)");
> +                goto fail;
> +            }
> +            pos++;
> +            if (sscanf(uri + pos, "%127[^;&]%n", value, &len) != 1)
> +                goto fail;
> +            port = g_strdup(value);
> +            pos += len;
> +            continue;
> +        } else {
> +            if (sscanf(uri + pos, "%31[-a-zA-Z0-9]=%127[^;&]%n", key, value, &len) != 2)
> +                goto fail;
> +        }
>          pos += len;
> +        target_key = NULL;
>          if (g_str_equal(key, "port")) {
> -            port = g_strdup(value);
> +            target_key = &port;
>          } else if (g_str_equal(key, "tls-port")) {
> -            tls_port = g_strdup(value);
> +            target_key = &tls_port;
>          } else if (g_str_equal(key, "password")) {
> -            password = g_strdup(value);
> +            target_key = &password;
>              g_warning("password may be visible in process listings");
>          } else {
>              g_warning("unknown key in spice URI parsing: %s", key);
>              goto fail;
>          }
> +        if (target_key) {
> +            if (*target_key) {
> +                g_warning("double set of %s", key);
> +                goto fail;
> +            }
> +            *target_key = g_strdup(value);
> +        }
>      }
>  
>      if (port == NULL && tls_port == NULL) {
> -- 
> 1.7.8.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list