diff options
author | Alexander Larsson <alexl@redhat.com> | 2007-10-22 15:02:05 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2007-10-22 15:02:05 +0000 |
commit | 7c2be725921030667db51449ee178b722aed518e (patch) | |
tree | d204de02d8ac38ff50ab3837efc8959b9b5b3ff4 | |
parent | dfd8e5728fa5680218c244ea5ba0eb6ce3c58e5d (diff) | |
download | gvfs-7c2be725921030667db51449ee178b722aed518e.tar.gz |
Update to use the gurifuncs.h from gio. Fix filename parsing to handle ~/x
2007-10-22 Alexander Larsson <alexl@redhat.com>
* client/gdaemonvfs.c:
* common/gvfsuriutils.[ch]:
* daemon/gvfsbackendtrash.c:
Update to use the gurifuncs.h from gio.
Fix filename parsing to handle ~/x
svn path=/trunk/; revision=988
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | client/gdaemonvfs.c | 13 | ||||
-rw-r--r-- | common/gvfsuriutils.c | 172 | ||||
-rw-r--r-- | common/gvfsuriutils.h | 12 | ||||
-rw-r--r-- | daemon/gvfsbackendtrash.c | 2 |
5 files changed, 21 insertions, 186 deletions
@@ -1,3 +1,11 @@ +2007-10-22 Alexander Larsson <alexl@redhat.com> + + * client/gdaemonvfs.c: + * common/gvfsuriutils.[ch]: + * daemon/gvfsbackendtrash.c: + Update to use the gurifuncs.h from gio. + Fix filename parsing to handle ~/x + 2007-10-19 Alexander Larsson <alexl@redhat.com> * daemon/gvfsbackend.[ch]: diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c index 1b13d1cc..3a43a9db 100644 --- a/client/gdaemonvfs.c +++ b/client/gdaemonvfs.c @@ -237,7 +237,7 @@ _g_daemon_vfs_get_uri_for_mountspec (GMountSpec *spec, { GString *string = g_string_new ("unknown://"); if (path) - g_string_append_uri_encoded (string, + g_string_append_uri_escaped (string, path, "!$&'()*+,;=:@/", allow_utf8); @@ -256,7 +256,7 @@ _g_daemon_vfs_get_uri_for_mountspec (GMountSpec *spec, g_string_append (string, type); g_string_append (string, "://"); if (path) - g_string_append_uri_encoded (string, + g_string_append_uri_escaped (string, path, "!$&'()*+,;=:@/", allow_utf8); @@ -673,13 +673,12 @@ g_daemon_vfs_parse_name (GVfs *vfs, const char *parse_name) { GFile *file; - char *path; - if (g_path_is_absolute (parse_name)) + if (g_path_is_absolute (parse_name) || + *parse_name == '~') { - path = g_filename_from_utf8 (parse_name, -1, NULL, NULL, NULL); - file = g_daemon_vfs_get_file_for_path (vfs, path); - g_free (path); + /* TODO: detect fuse paths and convert to daemon vfs GFiles ? */ + file = g_vfs_parse_name (G_DAEMON_VFS (vfs)->wrapped_vfs, parse_name); } else { diff --git a/common/gvfsuriutils.c b/common/gvfsuriutils.c index c5d0fbf8..25d6aa97 100644 --- a/common/gvfsuriutils.c +++ b/common/gvfsuriutils.c @@ -3,71 +3,6 @@ #include <string.h> #include <stdlib.h> -static int -unescape_character (const char *scanner) -{ - int first_digit; - int second_digit; - - first_digit = g_ascii_xdigit_value (*scanner++); - if (first_digit < 0) - return -1; - - second_digit = g_ascii_xdigit_value (*scanner++); - if (second_digit < 0) - return -1; - - return (first_digit << 4) | second_digit; -} - -char * -g_uri_unescape_string (const gchar *escaped_string, - const gchar *escaped_string_end, - const gchar *illegal_characters) -{ - const gchar *in; - gchar *out, *result; - gint character; - - if (escaped_string == NULL) - return NULL; - - if (escaped_string_end == NULL) - escaped_string_end = escaped_string + strlen (escaped_string); - - result = g_malloc (escaped_string_end - escaped_string + 1); - - out = result; - for (in = escaped_string; in < escaped_string_end; in++) { - character = *in; - if (*in == '%') { - in++; - if (escaped_string_end - in < 2) - { - g_free (result); - return NULL; - } - - character = unescape_character (in); - - /* Check for an illegal character. We consider '\0' illegal here. */ - if (character <= 0 || - (illegal_characters != NULL && - strchr (illegal_characters, (char)character) != NULL)) - { - g_free (result); - return NULL; - } - in++; /* The other char will be eaten in the loop header */ - } - *out++ = (char)character; - } - - *out = '\0'; - g_assert (out - result <= strlen (escaped_string)); - return result; -} - void g_decoded_uri_free (GDecodedUri *decoded) { @@ -94,42 +29,6 @@ g_decoded_uri_new (void) return uri; } -char * -g_uri_get_scheme (const char *uri) -{ - const char *p; - char c; - - /* From RFC 3986 Decodes: - * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - */ - - p = uri; - - /* Decode scheme: - scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) - */ - - if (!g_ascii_isalpha (*p)) - return NULL; - - while (1) - { - c = *p++; - - if (c == ':') - break; - - if (!(g_ascii_isalnum(c) || - c == '+' || - c == '-' || - c == '.')) - return NULL; - } - - return g_strndup (uri, p - uri - 1); -} - GDecodedUri * g_decode_uri (const char *uri) { @@ -238,7 +137,7 @@ g_decode_uri (const char *uri) if (userinfo_end) { userinfo_start = authority_start; - decoded->userinfo = g_uri_unescape_string (userinfo_start, userinfo_end, NULL); + decoded->userinfo = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL); if (decoded->userinfo == NULL) { g_decoded_uri_free (decoded); @@ -267,7 +166,7 @@ g_decode_uri (const char *uri) hier_part_start = authority_end; } - decoded->path = g_uri_unescape_string (hier_part_start, hier_part_end, "/"); + decoded->path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/"); if (decoded->path == NULL) { @@ -278,68 +177,6 @@ g_decode_uri (const char *uri) return decoded; } -#define SUB_DELIM_CHARS "!$&'()*+,;=" - -static gboolean -is_valid (char c, const char *reserved_chars_allowed) -{ - if (g_ascii_isalnum (c) || - c == '-' || - c == '.' || - c == '_' || - c == '~') - return TRUE; - - if (reserved_chars_allowed && - strchr (reserved_chars_allowed, c) != NULL) - return TRUE; - - return FALSE; -} - -static gboolean -gunichar_ok (gunichar c) -{ - return - (c != (gunichar) -2) && - (c != (gunichar) -1); -} - -void -g_string_append_uri_encoded (GString *string, const char *encoded, - const char *reserved_chars_allowed, - gboolean allow_utf8) -{ - unsigned char c; - const char *end; - static const gchar hex[16] = "0123456789ABCDEF"; - - end = encoded + strlen (encoded); - - while ((c = *encoded) != 0) - { - if (c >= 0x80 && allow_utf8 && - gunichar_ok (g_utf8_get_char_validated (encoded, end - encoded))) - { - int len = g_utf8_skip [c]; - g_string_append_len (string, encoded, len); - encoded += len; - } - else if (is_valid (c, reserved_chars_allowed)) - { - g_string_append_c (string, c); - encoded++; - } - else - { - g_string_append_c (string, '%'); - g_string_append_c (string, hex[((guchar)c) >> 4]); - g_string_append_c (string, hex[((guchar)c) & 0xf]); - encoded++; - } - } -} - char * g_encode_uri (GDecodedUri *decoded, gboolean allow_utf8) { @@ -355,7 +192,8 @@ g_encode_uri (GDecodedUri *decoded, gboolean allow_utf8) if (decoded->userinfo) { /* userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) */ - g_string_append_uri_encoded (uri, decoded->userinfo, SUB_DELIM_CHARS ":", allow_utf8); + g_string_append_uri_escaped (uri, decoded->userinfo, + G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO, allow_utf8); g_string_append_c (uri, '@'); } @@ -368,7 +206,7 @@ g_encode_uri (GDecodedUri *decoded, gboolean allow_utf8) } } - g_string_append_uri_encoded (uri, decoded->path, SUB_DELIM_CHARS ":@/", allow_utf8); + g_string_append_uri_escaped (uri, decoded->path, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, allow_utf8); if (decoded->query) { diff --git a/common/gvfsuriutils.h b/common/gvfsuriutils.h index 64cea354..f8e2a866 100644 --- a/common/gvfsuriutils.h +++ b/common/gvfsuriutils.h @@ -2,6 +2,7 @@ #define __G_VFS_URI_UTILS_H__ #include <glib.h> +#include <gio/gurifuncs.h> G_BEGIN_DECLS @@ -15,16 +16,6 @@ typedef struct { char *fragment; } GDecodedUri; -char * g_uri_get_scheme (const char *uri); - -char * g_uri_unescape_string (const gchar *escaped_string, - const gchar *escaped_string_end, - const gchar *illegal_characters); -void g_string_append_uri_encoded (GString *string, - const char *encoded, - const char *reserved_chars_allowed, - gboolean allow_utf8); - char * g_encode_uri (GDecodedUri *decoded, gboolean allow_utf8); void g_decoded_uri_free (GDecodedUri *decoded); @@ -32,7 +23,6 @@ GDecodedUri *g_decode_uri (const char *uri); GDecodedUri *g_decoded_uri_new (void); - G_END_DECLS #endif /* __G_VFS_URI_UTILS_H__ */ diff --git a/daemon/gvfsbackendtrash.c b/daemon/gvfsbackendtrash.c index 3f5b4cb7..62867e9e 100644 --- a/daemon/gvfsbackendtrash.c +++ b/daemon/gvfsbackendtrash.c @@ -912,7 +912,7 @@ add_extra_trash_info (GFileInfo *file_info, orig_path_key = g_key_file_get_string (keyfile, "Trash Info", "Path", NULL); if (orig_path_key) { - orig_path_unescaped = g_uri_unescape_string (orig_path_key, NULL, ""); + orig_path_unescaped = g_uri_unescape_string (orig_path_key, ""); if (orig_path_unescaped) { |