[gvfs] http: New function to get the basename without trying to decode it



commit e17226fac90b595ff8bac3cfd16530961f8bc4cc
Author: Christian Kellner <gicmo gnome org>
Date:   Tue May 17 18:22:55 2011 +0200

    http: New function to get the basename without trying to decode it
    
    http_uri_get_basename () remained the same and will still encode the
    resulting basename. http_path_get_basename (), which will be used by
    the dav backend, will not.
    Also make sure that in the trailing/leading spaces removal we do not
    exceed the string boundaries.

 daemon/gvfsbackendhttp.c |   70 +++++++++++++++++++++++++++-------------------
 daemon/gvfsbackendhttp.h |    2 +
 2 files changed, 43 insertions(+), 29 deletions(-)
---
diff --git a/daemon/gvfsbackendhttp.c b/daemon/gvfsbackendhttp.c
index 6c60e0b..90208d2 100644
--- a/daemon/gvfsbackendhttp.c
+++ b/daemon/gvfsbackendhttp.c
@@ -144,46 +144,58 @@ http_backend_get_mount_base (GVfsBackend *backend)
 }
 
 char *
-http_uri_get_basename (const char *uri_str)
+http_path_get_basename (const char *path)
 {
-    const char *parent;
-    const char *path;
-    char       *to_free;
-    char       *basename;
-    size_t      len;
+  const char *parent;
+  char       *basename;
+  size_t      len;
 
-    if (uri_str == NULL || *uri_str == '\0')
-      return NULL;
+  if (path == NULL || *path == '\0')
+    return NULL;
 
-    path =  uri_str;
+  /* remove any leading slashes */
+  while (*path != '\0' && (*path == '/' || *path == ' '))
+    path++;
 
-    /* remove any leading slashes */
-    while (*path == '/' || *path == ' ')
-        path++;
+  len = strlen (path);
+  if (len == 0)
+    return g_strdup ("/");
 
-    len = strlen (path);
+  /* remove any trailing slashes */
+  while (len)
+    {
+      char c = path[len - 1];
+      if (!g_ascii_isspace (c) && c != '/')
+	break;
 
-    if (len == 0)
-      return g_strdup ("/");
+      len--;
+    }
+
+  parent = g_strrstr_len (path, len, "/");
+
+  if (parent)
+    {
+      parent++; /* skip the found / char */
+      basename = g_strndup (parent, (len - (parent - path)));
+    }
+  else
+    basename = g_strndup (path, len);
 
-    /* remove any trailing slashes */
-    while (path[len - 1] == '/' || path[len - 1] == ' ')
-        len--;
+  return basename;
+}
 
-    parent = g_strrstr_len (path, len, "/");
+char *
+http_uri_get_basename (const char *uri_str)
+{
+  char *decoded;
+  char *basename;
 
-    if (parent)
-      {
-        parent++; /* skip the found / char */
-        to_free = g_strndup (parent, (len - (parent - path)));
-      }
-    else
-      to_free = g_strndup (path, len);
+  basename = http_path_get_basename (uri_str);
 
-    basename = soup_uri_decode (to_free);
-    g_free (to_free);
+  decoded = soup_uri_decode (basename);
+  g_free (basename);
 
-    return basename;
+  return decoded;
 }
 
 guint
diff --git a/daemon/gvfsbackendhttp.h b/daemon/gvfsbackendhttp.h
index 5cc4bd8..29b14e1 100644
--- a/daemon/gvfsbackendhttp.h
+++ b/daemon/gvfsbackendhttp.h
@@ -59,6 +59,8 @@ GType         g_vfs_backend_http_get_type    (void) G_GNUC_CONST;
 
 char *        http_uri_get_basename          (const char *uri_str);
 
+char *        http_path_get_basename         (const char *path_str);
+
 guint         http_error_code_from_status    (guint status);
 
 SoupURI *     http_backend_get_mount_base    (GVfsBackend *backend);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]