diff options
author | Bastien Nocera <hadess@hadess.net> | 2008-01-23 16:05:59 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@src.gnome.org> | 2008-01-23 16:05:59 +0000 |
commit | f070d884ef62efd8f5d1affa3d9c702f2c4557dc (patch) | |
tree | 287453eaa4ef9201c127438a6e7e7bf2ac8a7bd3 | |
parent | 05419a9d8232e7af27e9fb31de248ebe583a002e (diff) | |
download | gvfs-f070d884ef62efd8f5d1affa3d9c702f2c4557dc.tar.gz |
Add test program for the functions in gvfsuriutils.c
2008-01-23 Bastien Nocera <hadess@hadess.net>
* client/test-uri-utils.c: (main):
* client/Makefile.am: Add test program for the
functions in gvfsuriutils.c
* client/gvfsuriutils.c: (g_vfs_decode_uri):
Fix parsing of IPv6 URIs where the host is in brackets
svn path=/trunk/; revision=1171
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | client/Makefile.am | 6 | ||||
-rw-r--r-- | client/gvfsuriutils.c | 18 | ||||
-rw-r--r-- | client/test-uri-utils.c | 55 |
4 files changed, 87 insertions, 1 deletions
@@ -1,3 +1,12 @@ +2008-01-23 Bastien Nocera <hadess@hadess.net> + + * client/test-uri-utils.c: (main): + * client/Makefile.am: Add test program for the + functions in gvfsuriutils.c + + * client/gvfsuriutils.c: (g_vfs_decode_uri): + Fix parsing of IPv6 URIs where the host is in brackets + 2008-01-23 Alexander Larsson <alexl@redhat.com> * daemon/gvfsbackendtrash.c: diff --git a/client/Makefile.am b/client/Makefile.am index 03858a26..738b13b6 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -53,6 +53,12 @@ libgvfsdbus_la_LDFLAGS = $(module_flags) libgvfsdbus_la_SOURCES = $(vfssources) libgvfsdbus_la_LIBADD = $(vfslibs) +noinst_PROGRAMS = test-uri-utils + +test_uri_utils_SOURCES = test-uri-utils.c gvfsuriutils.c gvfsuriutils.h +test_uri_utils_LDADD = $(vfslibs) +test_uri_utils_CFLAGS = $(INCLUDES) + if USE_FUSE ## FUSE daemon diff --git a/client/gvfsuriutils.c b/client/gvfsuriutils.c index 78aa850e..428f1ef2 100644 --- a/client/gvfsuriutils.c +++ b/client/gvfsuriutils.c @@ -170,7 +170,23 @@ g_vfs_decode_uri (const char *uri) else host_start = authority_start; - port_start = memchr (host_start, ':', authority_end - host_start); + /* We should handle hostnames in brackets, as those are used by IPv6 URIs + * See http://tools.ietf.org/html/rfc2732 */ + if (*host_start == '[') + { + 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); + } + else + { + port_start = memchr (host_start, ':', authority_end - host_start); + } + if (port_start) { host_end = port_start++; diff --git a/client/test-uri-utils.c b/client/test-uri-utils.c new file mode 100644 index 00000000..ce7b2524 --- /dev/null +++ b/client/test-uri-utils.c @@ -0,0 +1,55 @@ + +#include <string.h> + +#include "gvfsuriutils.h" + + +typedef struct { + const char *uri; + const char *expected_host; + guint expected_port; +} TestURIs; + +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 } +}; + +int main (int argc, char **argv) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (uris); i++) { + GDecodedUri *decoded; + char *encoded; + + decoded = g_vfs_decode_uri (uris[i].uri); + if (decoded == NULL) { + g_warning ("Failed to parse \"%s\"", uris[i].uri); + return 1; + } + if (decoded->host == NULL || strcmp (decoded->host, uris[i].expected_host) != 0) { + 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); + return 1; + } + encoded = g_vfs_encode_uri (decoded, TRUE); + if (encoded == NULL || strcmp (encoded, uris[i].uri) != 0) { + g_vfs_decoded_uri_free (decoded); + g_free (encoded); + g_warning ("Failed to re-encode \"%s\"", uris[i].uri); + return 1; + } + g_free (encoded); + g_vfs_decoded_uri_free (decoded); + } + + return 0; +} + |