diff options
author | Bastien Nocera <hadess@hadess.net> | 2008-03-05 17:14:43 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@src.gnome.org> | 2008-03-05 17:14:43 +0000 |
commit | 7d9ad07c93149f2572e88ebc14d8163ee5b9bca6 (patch) | |
tree | 497922465b1871426a3d22ad8beef2457d5f17bc /client | |
parent | e0b5a4444ba8435aed29cdd9b442a2ddf0725ac4 (diff) | |
download | gvfs-7d9ad07c93149f2572e88ebc14d8163ee5b9bca6.tar.gz |
Fix parsing of IPv6-style hostnames to not find the port in the path
2008-03-05 Bastien Nocera <hadess@hadess.net>
* client/gvfsuriutils.c (g_vfs_decode_uri):
Fix parsing of IPv6-style hostnames to not find the
port in the path section of the URI, fixes browing
browsing ObexFTP on Nokia Series 60 phones which show
drive letters as directories in the root (eg. "C:")
(Closes: #520314)
* client/test-uri-utils.c (main): Add test for the above,
and another test for the IPv4-style URIs
svn path=/trunk/; revision=1558
Diffstat (limited to 'client')
-rw-r--r-- | client/gvfsuriutils.c | 28 | ||||
-rw-r--r-- | client/test-uri-utils.c | 10 |
2 files changed, 33 insertions, 5 deletions
diff --git a/client/gvfsuriutils.c b/client/gvfsuriutils.c index 428f1ef2..c9bae69b 100644 --- a/client/gvfsuriutils.c +++ b/client/gvfsuriutils.c @@ -174,13 +174,39 @@ g_vfs_decode_uri (const char *uri) * See http://tools.ietf.org/html/rfc2732 */ if (*host_start == '[') { + char *s; + + port_start = NULL; host_end = memchr (host_start, ']', authority_end - host_start); if (host_end == NULL) { g_vfs_decoded_uri_free (decoded); return NULL; } - port_start = memchr (host_end, ':', authority_end - host_start); + + /* Look for the start of the port, + * And we sure we don't have it start somewhere + * in the path section */ + s = (char *) host_end; + while (1) + { + if (*s == '/') + { + port_start = NULL; + break; + } + else if (*s == ':') + { + port_start = s; + break; + } + else if (*s == '\0') + { + break; + } + + s++; + } } else { diff --git a/client/test-uri-utils.c b/client/test-uri-utils.c index 52045671..41cfb057 100644 --- a/client/test-uri-utils.c +++ b/client/test-uri-utils.c @@ -14,7 +14,9 @@ static TestURIs uris[] = { { "https://[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:443/", "[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]", 443 }, { "http://test:443/", "test", 443 }, { "http://test/", "test", -1 }, - { "obex://[00:FF:FF:FF:FF:FF]/MMC/foo.jpg", "[00:FF:FF:FF:FF:FF]", -1 } + { "obex://[00:FF:FF:FF:FF:FF]/MMC/foo.jpg", "[00:FF:FF:FF:FF:FF]", -1 }, + { "obex://[00:FF:FF:FF:FF:FF]/C:", "[00:FF:FF:FF:FF:FF]", -1 }, + { "http://windows-host:8080/C:/", "windows-host", 8080 }, }; int main (int argc, char **argv) @@ -31,20 +33,20 @@ int main (int argc, char **argv) return 1; } if (decoded->host == NULL || strcmp (decoded->host, uris[i].expected_host) != 0) { + g_warning ("Wrong host for \"%s\" (got '%s', expected '%s')", uris[i].uri, decoded->host, uris[i].expected_host); g_vfs_decoded_uri_free (decoded); - g_warning ("Wrong host for \"%s\"", uris[i].uri); return 1; } if (decoded->port != uris[i].expected_port) { - g_vfs_decoded_uri_free (decoded); g_warning ("Wrong port for \"%s\"", uris[i].uri); + g_vfs_decoded_uri_free (decoded); return 1; } encoded = g_vfs_encode_uri (decoded, TRUE); if (encoded == NULL || strcmp (encoded, uris[i].uri) != 0) { + g_warning ("Failed to re-encode \"%s\" from '%s'", uris[i].uri, encoded); g_vfs_decoded_uri_free (decoded); g_free (encoded); - g_warning ("Failed to re-encode \"%s\"", uris[i].uri); return 1; } g_free (encoded); |