summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2012-01-05 14:04:47 +0200
committerAlon Levy <alevy@redhat.com>2012-01-05 19:42:38 +0200
commitb4c72ece9ca3b9b2d8f8f3912138cc0fbeee6263 (patch)
treedb0461502538fb28b785c73e7e586dfe6d68e7c3
parent62957c2934fa1c33b772297bd8416fefa5ad286a (diff)
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)
-rw-r--r--gtk/spice-session.c20
1 files changed, 18 insertions, 2 deletions
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")) {