[Spice-commits] 2 commits - gtk/spice-session.c
Alon Levy
alon at kemper.freedesktop.org
Thu Jan 5 09:43:05 PST 2012
gtk/spice-session.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
New commits:
commit b4c72ece9ca3b9b2d8f8f3912138cc0fbeee6263
Author: Alon Levy <alevy at redhat.com>
Date: Thu Jan 5 14:04:47 2012 +0200
spice-session: support uri with colon
With this patch if you use:
spice://<host>:<port>
it will be treated the same as:
spice://<host>?port=<port>
You will also get a warning for the following double port definitions:
spice://<host>:<port1>?port=<port2>
spice://<host>:<port1>:<port2>
(similar to the double key warnings introduced in the previous commits)
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 604d72a..1199caf 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -242,6 +242,7 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
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);
@@ -259,13 +260,28 @@ 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] == ':') {
+ if (punctuation++) {
+ g_warning("colon seen after a previous punctuation (?;&:)");
+ goto fail;
+ }
+ pos++;
+ /* port numbers are 16 bit, fits in five decimal figures. */
+ if (sscanf(uri + pos, "%5[0-9]%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")) {
commit 62957c2934fa1c33b772297bd8416fefa5ad286a
Author: Alon Levy <alevy at redhat.com>
Date: Thu Jan 5 14:04:26 2012 +0200
spice-session/spice_uri_parse: fail if a key is seen twice
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index a2fa550..604d72a 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -241,6 +241,7 @@ 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 len, pos = 0;
g_return_val_if_fail(original_uri != NULL, -1);
@@ -266,17 +267,25 @@ static int spice_uri_parse(SpiceSession *session, const char *original_uri)
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) {
More information about the Spice-commits
mailing list