[gvfs] smb: Drop custom GString functionality
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] smb: Drop custom GString functionality
- Date: Wed, 16 Nov 2016 10:44:16 +0000 (UTC)
commit 7eb9165d0dcb4fad5e905ff052a55c40ab456c3b
Author: Ondrej Holy <oholy redhat com>
Date: Tue Nov 15 11:54:08 2016 +0100
smb: Drop custom GString functionality
Replace custom g_string_append_encoded() by g_string_append_uri_escaped().
The functions are identical except additional UTF-8 support, which can
be simply disabled by allow_utf8 parameter. The custom function was used
probably because the g_string_append_uri_escaped has been added later.
https://bugzilla.gnome.org/show_bug.cgi?id=604116
daemon/gvfsbackendsmb.c | 50 ++++----------------------------------
daemon/gvfsbackendsmbbrowse.c | 54 +++-------------------------------------
2 files changed, 9 insertions(+), 95 deletions(-)
---
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
index a5a4773..be648dc 100644
--- a/daemon/gvfsbackendsmb.c
+++ b/daemon/gvfsbackendsmb.c
@@ -313,44 +313,6 @@ auth_callback (SMBCCTX *context,
#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 void
-g_string_append_encoded (GString *string,
- const char *encoded,
- const char *reserved_chars_allowed)
-{
- char c;
- static const gchar hex[16] = "0123456789ABCDEF";
-
- while ((c = *encoded++) != 0)
- {
- if (is_valid (c, reserved_chars_allowed))
- g_string_append_c (string, c);
- else
- {
- g_string_append_c (string, '%');
- g_string_append_c (string, hex[((guchar)c) >> 4]);
- g_string_append_c (string, hex[((guchar)c) & 0xf]);
- }
- }
-}
-
static GString *
create_smb_uri_string (const char *server,
int port,
@@ -366,24 +328,24 @@ create_smb_uri_string (const char *server,
/* IPv6 server includes brackets in GMountSpec, smbclient doesn't */
if (server[0] == '[')
{
- g_string_append_encoded (uri, server + 1, NULL);
+ g_string_append_uri_escaped (uri, server + 1, NULL, FALSE);
g_string_truncate (uri, uri->len - 3);
}
else
- g_string_append_encoded (uri, server, NULL);
+ g_string_append_uri_escaped (uri, server, NULL, FALSE);
if (port != -1)
g_string_append_printf (uri, ":%d", port);
g_string_append_c (uri, '/');
if (share != NULL)
- g_string_append_encoded (uri, share, NULL);
+ g_string_append_uri_escaped (uri, share, NULL, FALSE);
if (path != NULL)
{
if (*path != '/')
g_string_append_c (uri, '/');
- g_string_append_encoded (uri, path, SUB_DELIM_CHARS ":@/");
+ g_string_append_uri_escaped (uri, path, SUB_DELIM_CHARS ":@/", FALSE);
}
while (uri->len > 0 &&
@@ -1832,9 +1794,7 @@ do_enumerate (GVfsBackend *backend,
{
int stat_res;
g_string_truncate (uri, uri_start_len);
- g_string_append_encoded (uri,
- dirp->name,
- SUB_DELIM_CHARS ":@/");
+ g_string_append_uri_escaped (uri, dirp->name, SUB_DELIM_CHARS ":@/", FALSE);
if (matcher == NULL ||
g_file_attribute_matcher_matches_only (matcher, G_FILE_ATTRIBUTE_STANDARD_NAME))
diff --git a/daemon/gvfsbackendsmbbrowse.c b/daemon/gvfsbackendsmbbrowse.c
index fc554eb..ba41023 100644
--- a/daemon/gvfsbackendsmbbrowse.c
+++ b/daemon/gvfsbackendsmbbrowse.c
@@ -541,52 +541,6 @@ purge_cached (SMBCCTX * context)
return 0;
}
-#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 void
-g_string_append_encoded (GString *string,
- const char *encoded,
- const char *encoded_end,
- const char *reserved_chars_allowed)
-{
- char c;
- static const gchar hex[16] = "0123456789ABCDEF";
-
- if (encoded_end == NULL)
- encoded_end = encoded + strlen (encoded);
-
- while (encoded < encoded_end)
- {
- c = *encoded++;
-
- if (is_valid (c, reserved_chars_allowed))
- g_string_append_c (string, c);
- else
- {
- g_string_append_c (string, '%');
- g_string_append_c (string, hex[((guchar)c) >> 4]);
- g_string_append_c (string, hex[((guchar)c) & 0xf]);
- }
- }
-}
-
static gboolean
update_cache (GVfsBackendSmbBrowse *backend, SMBCFILE *supplied_dir)
{
@@ -1297,7 +1251,7 @@ get_file_info_from_entry (GVfsBackendSmbBrowse *backend, BrowseEntry *entry, GFi
entry->smbc_type == SMBC_SERVER)
{
uri = g_string_new ("smb://");
- g_string_append_encoded (uri, entry->name, NULL, NULL);
+ g_string_append_uri_escaped (uri, entry->name, NULL, FALSE);
g_string_append_c (uri, '/');
}
else
@@ -1305,16 +1259,16 @@ get_file_info_from_entry (GVfsBackendSmbBrowse *backend, BrowseEntry *entry, GFi
mount_spec = get_mount_spec_for_share (backend->server, backend->port, entry->name);
uri = g_string_new ("smb://");
- g_string_append_encoded (uri, backend->server, NULL, NULL);
+ g_string_append_uri_escaped (uri, backend->server, NULL, FALSE);
g_string_append_c (uri, '/');
- g_string_append_encoded (uri, entry->name, NULL, NULL);
+ g_string_append_uri_escaped (uri, entry->name, NULL, FALSE);
}
}
else
{
/* browsing network */
uri = g_string_new ("smb://");
- g_string_append_encoded (uri, entry->name, NULL, NULL);
+ g_string_append_uri_escaped (uri, entry->name, NULL, FALSE);
g_string_append_c (uri, '/');
/* these are auto-mounted, so no CAN_MOUNT/UNMOUNT */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]