From d8556a0db3243e9c5628307dc3f7d840d1228bd1 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 1 Dec 2016 13:02:58 +0100 Subject: client: Escape ":[]" chars in host if it is not IPv6 The "[]:" chars are omitted currently when encoding uri, because they are valid for IPv6. This causes problems in some cases, e.g. output from g_file_get_uri(g_file_new_for_uri("dav+sd://foo%3Abar._webdav._tcp.local")) is "dav+sd://foo:bar._webdav._tcp.local/", which is obviously wrong. Add gvfs_is_ipv6 in order to detect IPv6 addresses and encode also "[]:" chars in other cases. Use gvfs_is_ipv6 to detect IPv6 also in some backends. https://bugzilla.gnome.org/show_bug.cgi?id=772849 --- common/gvfsutils.c | 20 ++++++++++++++++++++ common/gvfsutils.h | 2 ++ 2 files changed, 22 insertions(+) (limited to 'common') diff --git a/common/gvfsutils.c b/common/gvfsutils.c index 1c5c2e3a..cb994e4f 100644 --- a/common/gvfsutils.c +++ b/common/gvfsutils.c @@ -125,3 +125,23 @@ gvfs_setup_debug_handler (void) sa.sa_flags = 0; sigaction (SIGUSR2, &sa, NULL); } + +gboolean +gvfs_is_ipv6 (const char *host) +{ + const char *p = host; + + g_return_val_if_fail (host != NULL, FALSE); + + if (*p != '[') + return FALSE; + + while (++p) + if (!g_ascii_isxdigit (*p) && *p != ':') + break; + + if (*p != ']' || *(p + 1) != '\0') + return FALSE; + + return TRUE; +} diff --git a/common/gvfsutils.h b/common/gvfsutils.h index 2c2146c8..acaea9d2 100644 --- a/common/gvfsutils.h +++ b/common/gvfsutils.h @@ -30,6 +30,8 @@ gboolean gvfs_get_debug (void); void gvfs_set_debug (gboolean debugging); void gvfs_setup_debug_handler (void); +gboolean gvfs_is_ipv6 (const char *host); + G_END_DECLS #endif /* __G_VFS_UTILS_H__ */ -- cgit v1.2.1