[gvfs] client: remove GVfsUriMountInfo



commit 5de780f7d7ca5ef3d930c050fa6f57c8d3f0ebdf
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Jan 4 16:30:38 2014 +0100

    client: remove GVfsUriMountInfo
    
    This structure is too similar to GMountSpec to deserve a presence
    (it's essentially a GMountSpec with a path). By removing it we
    can remove some code and avoid wasteful allocations in sensitive
    paths such as creating and traversing GFiles.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721461

 client/afpuri.c        |   88 +++++++++++++++----------------
 client/gdaemonvfs.c    |   56 ++++----------------
 client/gvfsurimapper.c |  135 ++++++-----------------------------------------
 client/gvfsurimapper.h |   55 +++++++------------
 client/httpuri.c       |   87 ++++++++++++++++---------------
 client/smburi.c        |  124 ++++++++++++++++++++------------------------
 common/gmountspec.c    |   39 +++++++++++---
 common/gmountspec.h    |    3 +
 8 files changed, 226 insertions(+), 361 deletions(-)
---
diff --git a/client/afpuri.c b/client/afpuri.c
index 4f29058..7fa0f32 100644
--- a/client/afpuri.c
+++ b/client/afpuri.c
@@ -63,13 +63,14 @@ afp_get_handled_schemes (GVfsUriMapper *mapper)
   return schemes;
 }
 
-static GVfsUriMountInfo *
-afp_from_uri (GVfsUriMapper *mapper,
-              const char *uri_str)
+static GMountSpec *
+afp_from_uri (GVfsUriMapper  *mapper,
+              const char     *uri_str,
+              char          **path)
 {
   const char *p;
   GDecodedUri *uri;
-  GVfsUriMountInfo *info;
+  GMountSpec *spec;
 
   uri = g_vfs_decode_uri (uri_str);
   if (uri == NULL)
@@ -90,15 +91,15 @@ afp_from_uri (GVfsUriMapper *mapper,
     if (p == NULL || *p == 0)
     {
       /* uri form: afp://$host/ */
-       info = g_vfs_uri_mount_info_new ("afp-server");
+       spec = g_mount_spec_new ("afp-server");
 
-       g_vfs_uri_mount_info_set (info, "host", uri->host);
-       info->path = g_strdup ("/");
+       g_mount_spec_set (spec, "host", uri->host);
+       *path = g_strdup ("/");
     }
     else
     {
       const char *volume, *volume_end;
-      
+
       volume = p;
       volume_end = strchr (volume, '/');
       if (volume_end == NULL)
@@ -116,62 +117,56 @@ afp_from_uri (GVfsUriMapper *mapper,
         if (volume[0] == '.' && volume[1] == '_')
         {
           char *tmp;
-          
-          info = g_vfs_uri_mount_info_new ("afp-server");
-          
-          g_vfs_uri_mount_info_set  (info, "host", uri->host);
-          
+
+          spec = g_mount_spec_new ("afp-server");
+          g_mount_spec_set (spec, "host", uri->host);
+
           tmp = g_strndup (volume + 2, volume_end - (volume + 2));
-          info->path = g_strconcat ("/", tmp, NULL);
+          *path = g_strconcat ("/", tmp, NULL);
           g_free (tmp);
         }
         else
         {
           char *tmp;
-          
-          info = g_vfs_uri_mount_info_new ("afp-volume");
 
-          g_vfs_uri_mount_info_set  (info, "host", uri->host);
+          spec = g_mount_spec_new ("afp-volume");
+          g_mount_spec_set (spec, "host", uri->host);
 
           tmp = g_strndup (volume, volume_end - volume);
-          g_vfs_uri_mount_info_set  (info, "volume", tmp);
-          g_free (tmp);
-          info->path = g_strdup ("/");
+          g_mount_spec_take (spec, "volume", tmp);
+
+          *path = g_strdup ("/");
         }
       }
       else
       {
         char *tmp;
-        
-        info = g_vfs_uri_mount_info_new ("afp-volume");
 
-        g_vfs_uri_mount_info_set  (info, "host", uri->host);
+        spec = g_mount_spec_new ("afp-volume");
+        g_mount_spec_set (spec, "host", uri->host);
 
         tmp = g_strndup (volume, volume_end - volume);
-        g_vfs_uri_mount_info_set  (info, "volume", tmp);
-        g_free (tmp);
+        g_mount_spec_take (spec, "volume", tmp);
 
-        info->path = g_strconcat ("/", p, NULL);
+        *path = g_strconcat ("/", p, NULL);
       }
     }
   }
 
   if (uri->userinfo)
-  {
-    g_vfs_uri_mount_info_set  (info, "user", uri->userinfo);
-  }
+    g_mount_spec_set (spec, "user", uri->userinfo);
 
   g_vfs_decoded_uri_free (uri);
-           
-  return info;
+
+  return spec;
 }
 
 static const char * const *
 afp_get_handled_mount_types (GVfsUriMapper *mapper)
 {
   static const char *types[] = {
-    "afp-server", 
-    "afp-volume", 
+    "afp-server",
+    "afp-volume",
     NULL
   };
   return types;
@@ -179,7 +174,8 @@ afp_get_handled_mount_types (GVfsUriMapper *mapper)
 
 static char *
 afp_to_uri (GVfsUriMapper *mapper,
-            GVfsUriMountInfo *info,
+            GMountSpec *spec,
+            const char *path,
             gboolean allow_utf8)
 {
   const char *type;
@@ -191,27 +187,27 @@ afp_to_uri (GVfsUriMapper *mapper,
 
   uri = g_new0 (GDecodedUri, 1);
 
-  type = g_vfs_uri_mount_info_get (info, "type");
+  type = g_mount_spec_get (spec, "type");
 
   uri->scheme = g_strdup ("afp");
 
-  host = g_vfs_uri_mount_info_get (info, "host");
+  host = g_mount_spec_get (spec, "host");
   uri->host = g_strdup (host);
 
-  port = g_vfs_uri_mount_info_get (info, "port");
+  port = g_mount_spec_get (spec, "port");
   if (port)
     uri->port = atoi (port);
   else
     uri->port = -1;
 
-  user = g_vfs_uri_mount_info_get (info, "user");
+  user = g_mount_spec_get (spec, "user");
   uri->userinfo = g_strdup (user);
 
   if (strcmp (type, "afp-server") == 0)
   {
     /* Map the mountables in server to ._share because the actual share mount maps to afp://host/share */
-     if (info->path && info->path[0] == '/' && info->path[1] != 0)
-     uri->path = g_strconcat ("/._", info->path + 1, NULL);
+     if (path && path[0] == '/' && path[1] != 0)
+     uri->path = g_strconcat ("/._", path + 1, NULL);
      else
      uri->path = g_strdup ("/");
   }
@@ -219,11 +215,11 @@ afp_to_uri (GVfsUriMapper *mapper,
   {
     const char *volume;
 
-    volume = g_vfs_uri_mount_info_get (info, "volume");
-    if (info->path[0] == '/')
-      uri->path = g_strconcat ("/", volume, info->path, NULL);
+    volume = g_mount_spec_get (spec, "volume");
+    if (path[0] == '/')
+      uri->path = g_strconcat ("/", volume, path, NULL);
     else
-      uri->path = g_strconcat ("/", volume, "/", info->path, NULL);
+      uri->path = g_strconcat ("/", volume, "/", path, NULL);
   }
 
   s = g_vfs_encode_uri (uri, allow_utf8);
@@ -233,9 +229,9 @@ afp_to_uri (GVfsUriMapper *mapper,
 
 static const char *
 afp_to_uri_scheme (GVfsUriMapper *mapper,
-                   GVfsUriMountInfo *info)
+                   GMountSpec *spec)
 {
-  const gchar *type = g_vfs_uri_mount_info_get (info, "type");
+  const gchar *type = g_mount_spec_get (spec, "type");
 
   if (strcmp ("afp-server", type) == 0 ||
       strcmp ("afp-volume", type) == 0)
diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c
index 7c7f9a7..17bd8a3 100644
--- a/client/gdaemonvfs.c
+++ b/client/gdaemonvfs.c
@@ -180,8 +180,7 @@ get_mountspec_from_uri (GDaemonVfs *vfs,
   char *path;
   GVfsUriMapper *mapper;
   char *scheme;
-  GVfsUriMountInfo *info;
-  
+
   scheme = g_uri_parse_scheme (uri);
   if (scheme == NULL)
     return FALSE;
@@ -189,24 +188,15 @@ get_mountspec_from_uri (GDaemonVfs *vfs,
   /* convert the scheme to lower case since g_uri_parse_scheme
    * doesn't do that and we compare with g_str_equal */
   str_tolower_inplace (scheme);
-  
+
   spec = NULL;
   path = NULL;
-  
+
   mapper = g_hash_table_lookup (vfs->from_uri_hash, scheme);
-  
+
   if (mapper)
-    {
-      info = g_vfs_uri_mapper_from_uri (mapper, uri);
-      if (info != NULL)
-       {
-         spec = g_mount_spec_new_from_data (info->keys, NULL);
-         path = info->path;
-         /* We took over ownership of info parts, custom free: */
-         g_free (info);
-       }
-    }
-  
+    spec = g_vfs_uri_mapper_from_uri (mapper, uri, &path);
+
   if (spec == NULL)
     {
       GDecodedUri *decoded;
@@ -449,19 +439,7 @@ _g_daemon_vfs_get_mount_spec_for_path (GMountSpec *spec,
   new_spec = NULL;
   mapper = g_hash_table_lookup (the_vfs->to_uri_hash, type);
   if (mapper)
-    {
-      GVfsUriMountInfo info, *new_info;
-      info.keys = spec->items;
-      info.path = (char *)path;
-      new_info = g_vfs_uri_mapper_get_mount_info_for_path (mapper, &info, new_path);
-      if (new_info != NULL)
-       {
-         new_spec = g_mount_spec_new_from_data (new_info->keys, NULL);
-         /* We took over ownership of parts of new_info, custom free: */
-         g_free (new_info->path);
-         g_free (new_info);
-       }
-    }
+    new_spec = g_vfs_uri_mapper_get_mount_spec_for_path (mapper, spec, path, new_path);
 
   if (new_spec == NULL)
     new_spec = g_mount_spec_ref (spec);
@@ -494,12 +472,7 @@ _g_daemon_vfs_get_uri_for_mountspec (GMountSpec *spec,
   uri = NULL;
   mapper = g_hash_table_lookup (the_vfs->to_uri_hash, type);
   if (mapper)
-    {
-      GVfsUriMountInfo info;
-      info.keys = spec->items;
-      info.path = path;
-      uri = g_vfs_uri_mapper_to_uri (mapper, &info, allow_utf8);
-    }
+    uri = g_vfs_uri_mapper_to_uri (mapper, spec, path, allow_utf8);
 
   if (uri == NULL)
     {
@@ -559,15 +532,8 @@ _g_daemon_vfs_mountspec_get_uri_scheme (GMountSpec *spec)
 
   scheme = NULL;
   if (mapper)
-    {
-      GVfsUriMountInfo info;
-      
-      info.keys = spec->items;
-      info.path = "/";
-      
-      scheme = g_vfs_uri_mapper_to_uri_scheme (mapper, &info);
-    }
-  
+    scheme = g_vfs_uri_mapper_to_uri_scheme (mapper, spec);
+
   if (scheme == NULL)
     {
       mountable = get_mountable_info_for_type (the_vfs, type);
@@ -576,7 +542,7 @@ _g_daemon_vfs_mountspec_get_uri_scheme (GMountSpec *spec)
       else
        scheme = type;
     }
-  
+
   return scheme;
 }
 
diff --git a/client/gvfsurimapper.c b/client/gvfsurimapper.c
index 40c12fc..cb8426c 100644
--- a/client/gvfsurimapper.c
+++ b/client/gvfsurimapper.c
@@ -33,106 +33,6 @@ g_vfs_uri_mapper_register (GIOModule *module)
   g_vfs_uri_mapper_register_type (G_TYPE_MODULE (module));
 }
 
-GVfsUriMountInfo *
-g_vfs_uri_mount_info_new (const char *type)
-{
-  GVfsUriMountInfo *info;
-
-  info = g_new0 (GVfsUriMountInfo, 1);
-  info->keys = g_array_new (TRUE, TRUE, sizeof (GVfsUriMountInfoKey));
-
-  if (type != NULL)
-    g_vfs_uri_mount_info_set (info, "type", type);
-  
-  return info;
-}
-
-void
-g_vfs_uri_mount_info_free (GVfsUriMountInfo *info)
-{
-  int i;
-  GVfsUriMountInfoKey *key;
-    
-  for (i = 0; i < info->keys->len; i++) {
-    key = &g_array_index (info->keys, GVfsUriMountInfoKey, i);
-
-    g_free (key->key);
-    g_free (key->value);
-  }
-  g_array_free (info->keys, TRUE);  
-  g_free (info->path);
-  g_free (info);
-}
-
-static GVfsUriMountInfoKey *
-lookup_key (GVfsUriMountInfo *info,
-           const char *key)
-{
-  int i;
-  GVfsUriMountInfoKey *keyp;
-    
-  for (i = 0; i < info->keys->len; i++) {
-    keyp = &g_array_index (info->keys, GVfsUriMountInfoKey, i);
-    
-    if (strcmp (keyp->key, key) == 0)
-      return keyp;
-  }
-
-  return NULL;
-}
-  
-const char *
-g_vfs_uri_mount_info_get (GVfsUriMountInfo *info,
-                         const char       *key)
-{
-  GVfsUriMountInfoKey *keyp;
-
-  keyp = lookup_key (info, key);
-
-  if (keyp)
-    return keyp->value;
-  
-  return NULL;
-}
-
-void 
-g_vfs_uri_mount_info_set_with_len (GVfsUriMountInfo *info,
-                                  const char *key,
-                                  const char *value,
-                                  int value_len)
-{
-  GVfsUriMountInfoKey *keyp;
-  GVfsUriMountInfoKey keyv;
-  char *value_copy;
-
-  if (value_len == -1)
-    value_copy = g_strdup (value);
-  else
-    value_copy = g_strndup (value, value_len);
-  
-  keyp = lookup_key (info, key);
-  if (keyp)
-    {
-      g_free (keyp->value);
-      keyp->value = value_copy;
-    }
-  else
-    {
-      keyv.key = g_strdup (key);
-      keyv.value = value_copy;
-      g_array_append_val (info->keys, keyv);
-    }
-}
-
-void
-g_vfs_uri_mount_info_set (GVfsUriMountInfo *info,
-                         const char *key,
-                         const char *value)
-{
-  g_vfs_uri_mount_info_set_with_len (info, key, value, -1);
-}
-
-
 static void
 g_vfs_uri_mapper_class_finalize (GVfsUriMapperClass *klass)
 {
@@ -158,29 +58,30 @@ g_vfs_uri_mapper_get_handled_schemes (GVfsUriMapper  *mapper)
   return (* class->get_handled_schemes) (mapper);
 }
 
-  
-GVfsUriMountInfo *
+GMountSpec *
 g_vfs_uri_mapper_from_uri (GVfsUriMapper  *mapper,
-                          const char     *uri)
+                          const char     *uri,
+                           char          **path)
 {
   GVfsUriMapperClass *class;
 
   class = G_VFS_URI_MAPPER_GET_CLASS (mapper);
 
-  return (* class->from_uri) (mapper, uri);
+  return (* class->from_uri) (mapper, uri, path);
 }
 
-GVfsUriMountInfo *
-g_vfs_uri_mapper_get_mount_info_for_path (GVfsUriMapper    *mapper,
-                                         GVfsUriMountInfo *info,
+GMountSpec *
+g_vfs_uri_mapper_get_mount_spec_for_path (GVfsUriMapper    *mapper,
+                                         GMountSpec       *spec,
+                                          const char       *old_path,
                                          const char       *new_path)
 {
   GVfsUriMapperClass *class;
 
   class = G_VFS_URI_MAPPER_GET_CLASS (mapper);
 
-  if (class->get_mount_info_for_path != NULL)
-    return (* class->get_mount_info_for_path) (mapper, info, new_path);
+  if (class->get_mount_spec_for_path != NULL)
+    return (* class->get_mount_spec_for_path) (mapper, spec, old_path, new_path);
   else
     return NULL;
 }
@@ -197,24 +98,24 @@ g_vfs_uri_mapper_get_handled_mount_types (GVfsUriMapper  *mapper)
 
 char *
 g_vfs_uri_mapper_to_uri (GVfsUriMapper *mapper,
-                        GVfsUriMountInfo *mount_info,
+                        GMountSpec *mount_spec,
+                         const char *path,
                         gboolean allow_utf8)
 {
   GVfsUriMapperClass *class;
   
   class = G_VFS_URI_MAPPER_GET_CLASS (mapper);
   
-  return (* class->to_uri) (mapper, mount_info, allow_utf8);
+  return (* class->to_uri) (mapper, mount_spec, path, allow_utf8);
 }
 
 const char *
-g_vfs_uri_mapper_to_uri_scheme (GVfsUriMapper  *mapper,
-                                GVfsUriMountInfo *mount_info)
+g_vfs_uri_mapper_to_uri_scheme (GVfsUriMapper *mapper,
+                                GMountSpec    *mount_spec)
 {
   GVfsUriMapperClass *class;
-  
+
   class = G_VFS_URI_MAPPER_GET_CLASS (mapper);
-  
-  return (* class->to_uri_scheme) (mapper, mount_info);
+
+  return (* class->to_uri_scheme) (mapper, mount_spec);
 }
-                                                      
diff --git a/client/gvfsurimapper.h b/client/gvfsurimapper.h
index 4b59929..10acc25 100644
--- a/client/gvfsurimapper.h
+++ b/client/gvfsurimapper.h
@@ -26,6 +26,8 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
+#include <common/gmountspec.h>
+
 G_BEGIN_DECLS
 
 #define G_VFS_TYPE_URI_MAPPER         (g_vfs_uri_mapper_get_type ())
@@ -42,17 +44,6 @@ struct _GVfsUriMapper {
   GObject parent;
 };
 
-/* Keep in sync with GMountSpecItem */
-typedef struct {
-  char *key;
-  char *value;
-} GVfsUriMountInfoKey;
-
-typedef struct {
-  GArray *keys;
-  char *path;
-} GVfsUriMountInfo;
-
 struct _GVfsUriMapperClass
 {
   GObjectClass parent_class;
@@ -60,48 +51,42 @@ struct _GVfsUriMapperClass
   /* Virtual Table */
 
   const char * const * (*get_handled_schemes)     (GVfsUriMapper *mapper);
-  GVfsUriMountInfo *   (*from_uri)                (GVfsUriMapper *mapper,
-                                                  const char *uri);
-  GVfsUriMountInfo *   (*get_mount_info_for_path) (GVfsUriMapper *mapper,
-                                                  GVfsUriMountInfo *mount_info,
+  GMountSpec *         (*from_uri)                (GVfsUriMapper *mapper,
+                                                  const char *uri,
+                                                   char **path);
+  GMountSpec *         (*get_mount_spec_for_path) (GVfsUriMapper *mapper,
+                                                  GMountSpec *mount_spec,
+                                                   const char *old_path,
                                                   const char *new_path);
 
   const char * const * (*get_handled_mount_types) (GVfsUriMapper *mapper);
   char *               (*to_uri)                  (GVfsUriMapper *mapper,
-                                                  GVfsUriMountInfo *mount_info,
+                                                  GMountSpec *mount_spec,
+                                                   const char *path,
                                                   gboolean allow_utf8);
   const char *         (*to_uri_scheme)           (GVfsUriMapper *mapper,
-                                                  GVfsUriMountInfo *mount_info);
+                                                  GMountSpec *mount_spec);
 };
 
 GType g_vfs_uri_mapper_get_type (void);
 void g_vfs_uri_mapper_register (GIOModule *module);
 
-GVfsUriMountInfo *g_vfs_uri_mount_info_new          (const char       *type);
-void              g_vfs_uri_mount_info_free         (GVfsUriMountInfo *info);
-const char *      g_vfs_uri_mount_info_get          (GVfsUriMountInfo *info,
-                                                    const char       *key);
-void              g_vfs_uri_mount_info_set          (GVfsUriMountInfo *info,
-                                                    const char       *key,
-                                                    const char       *value);
-void              g_vfs_uri_mount_info_set_with_len (GVfsUriMountInfo *info,
-                                                    const char       *key,
-                                                    const char       *value,
-                                                    int               value_len);
-
 const char * const *g_vfs_uri_mapper_get_handled_schemes     (GVfsUriMapper    *mapper);
-GVfsUriMountInfo *  g_vfs_uri_mapper_from_uri                (GVfsUriMapper    *mapper,
-                                                             const char       *uri);
-GVfsUriMountInfo *  g_vfs_uri_mapper_get_mount_info_for_path (GVfsUriMapper    *mapper,
-                                                             GVfsUriMountInfo *mount_info,
+GMountSpec *        g_vfs_uri_mapper_from_uri                (GVfsUriMapper    *mapper,
+                                                             const char       *uri,
+                                                              char            **path);
+GMountSpec *        g_vfs_uri_mapper_get_mount_spec_for_path (GVfsUriMapper    *mapper,
+                                                             GMountSpec       *mount_spec,
+                                                              const char       *old_path,
                                                              const char       *new_path);
 
 const char * const *g_vfs_uri_mapper_get_handled_mount_types (GVfsUriMapper    *mapper);
 char *              g_vfs_uri_mapper_to_uri                  (GVfsUriMapper    *mapper,
-                                                             GVfsUriMountInfo *mount_info,
+                                                             GMountSpec       *mount_spec,
+                                                              const char       *path,
                                                              gboolean          allow_utf8);
 const char *        g_vfs_uri_mapper_to_uri_scheme           (GVfsUriMapper    *mapper,
-                                                             GVfsUriMountInfo *mount_infoxo);
+                                                             GMountSpec       *mount_spec);
 
 
 G_END_DECLS
diff --git a/client/httpuri.c b/client/httpuri.c
index a60b7af..0e65c79 100644
--- a/client/httpuri.c
+++ b/client/httpuri.c
@@ -74,11 +74,12 @@ port_is_default_port (int port, gboolean ssl)
     return port == 80;
 }
 
-static GVfsUriMountInfo *
-http_from_uri (GVfsUriMapper *mapper,
-               const char     *uri_str)
+static GMountSpec *
+http_from_uri (GVfsUriMapper  *mapper,
+               const char     *uri_str,
+               char          **path)
 {
-  GVfsUriMountInfo *info;
+  GMountSpec *spec;
   gboolean ssl;
   GDecodedUri *uri;
 
@@ -89,54 +90,55 @@ http_from_uri (GVfsUriMapper *mapper,
 
   if (!g_ascii_strncasecmp (uri->scheme, "http", 4))
     {
-      info = g_vfs_uri_mount_info_new ("http");
-      g_vfs_uri_mount_info_set (info, "uri", uri_str);
+      spec = g_mount_spec_new ("http");
+      g_mount_spec_set (spec, "uri", uri_str);
     }
   else
     {
-      info = g_vfs_uri_mount_info_new ("dav");
+      spec = g_mount_spec_new ("dav");
       ssl = !g_ascii_strcasecmp (uri->scheme, "davs");
-      g_vfs_uri_mount_info_set (info, "ssl", ssl ? "true" : "false");
+      g_mount_spec_set (spec, "ssl", ssl ? "true" : "false");
 
       if (uri->host && *uri->host)
-        g_vfs_uri_mount_info_set (info, "host", uri->host);
+        g_mount_spec_set (spec, "host", uri->host);
 
       if (uri->userinfo && *uri->userinfo)
-        g_vfs_uri_mount_info_set (info, "user", uri->userinfo);
+        g_mount_spec_set (spec, "user", uri->userinfo);
 
       /* only set the port if it isn't the default port */
       if (uri->port != -1 && ! port_is_default_port (uri->port, ssl))
         {
           char *port = g_strdup_printf ("%d", uri->port);
-          g_vfs_uri_mount_info_set (info, "port", port);
+          g_mount_spec_set (spec, "port", port);
           g_free (port);
         }
     }
 
-  info->path = uri->path;
+  *path = uri->path;
   uri->path = NULL;
   g_vfs_decoded_uri_free (uri);
 
-  return info;
+  return spec;
 }
 
-static GVfsUriMountInfo *
-http_get_mount_info_for_path (GVfsUriMapper *mapper,
-                             GVfsUriMountInfo *info,
+static GMountSpec *
+http_get_mount_spec_for_path (GVfsUriMapper *mapper,
+                             GMountSpec *spec,
+                              const char *old_path,
                              const char *new_path)
 {
   const char *type;
 
-  type = g_vfs_uri_mount_info_get (info, "type");
+  type = g_mount_spec_get (spec, "type");
 
   if (strcmp (type, "http") == 0)
     {
       const char *uri_str;
       char *new_uri;
       GDecodedUri *uri;
-      GVfsUriMountInfo *new_info;
+      GMountSpec *new_spec;
 
-      uri_str = g_vfs_uri_mount_info_get (info, "uri");
+      uri_str = g_mount_spec_get (spec, "uri");
 
       uri = g_vfs_decode_uri (uri_str);
 
@@ -158,15 +160,15 @@ http_get_mount_info_for_path (GVfsUriMapper *mapper,
       g_free (uri->fragment);
       uri->fragment = NULL;
 
-      new_info = g_vfs_uri_mount_info_new ("http");
+      new_spec = g_mount_spec_new ("http");
 
       new_uri = g_vfs_encode_uri (uri, TRUE);
-      g_vfs_uri_mount_info_set (new_info, "uri", new_uri);
+      g_mount_spec_set (new_spec, "uri", new_uri);
       g_free (new_uri);
 
       g_vfs_decoded_uri_free (uri);
 
-      return new_info;
+      return new_spec;
     }
   else
     return NULL;
@@ -184,9 +186,10 @@ http_get_handled_mount_types (GVfsUriMapper *mapper)
 }
 
 static char *
-http_to_uri (GVfsUriMapper    *mapper,
-             GVfsUriMountInfo *info,
-             gboolean          allow_utf8)
+http_to_uri (GVfsUriMapper *mapper,
+             GMountSpec    *spec,
+             const char    *path,
+             gboolean       allow_utf8)
 {
   char       *res;
   const char *type;
@@ -195,11 +198,11 @@ http_to_uri (GVfsUriMapper    *mapper,
   const char *port;
   const char *ssl;
 
-  type = g_vfs_uri_mount_info_get (info, "type");
+  type = g_mount_spec_get (spec, "type");
 
   if (strcmp (type, "http") == 0)
     {
-      res = g_strdup (g_vfs_uri_mount_info_get (info, "uri"));
+      res = g_strdup (g_mount_spec_get (spec, "uri"));
     }
   else
     {
@@ -208,10 +211,10 @@ http_to_uri (GVfsUriMapper    *mapper,
 
       decoded_uri = g_new0 (GDecodedUri, 1);
 
-      ssl  = g_vfs_uri_mount_info_get (info, "ssl");
-      host = g_vfs_uri_mount_info_get (info, "host");
-      user = g_vfs_uri_mount_info_get (info, "user");
-      port = g_vfs_uri_mount_info_get (info, "port");
+      ssl  = g_mount_spec_get (spec, "ssl");
+      host = g_mount_spec_get (spec, "host");
+      user = g_mount_spec_get (spec, "user");
+      port = g_mount_spec_get (spec, "port");
 
       if (ssl && strcmp (ssl, "true") == 0)
           decoded_uri->scheme = g_strdup ("davs");
@@ -220,13 +223,13 @@ http_to_uri (GVfsUriMapper    *mapper,
 
       decoded_uri->host = g_strdup (host);
       decoded_uri->userinfo = g_strdup (user);
-      
+
       if (port && (port_num = atoi (port)))
           decoded_uri->port = port_num;
       else
           decoded_uri->port = -1;
 
-      decoded_uri->path = g_strdup (info->path);
+      decoded_uri->path = g_strdup (path);
 
       res = g_vfs_encode_uri (decoded_uri, allow_utf8);
       g_vfs_decoded_uri_free (decoded_uri);
@@ -236,28 +239,28 @@ http_to_uri (GVfsUriMapper    *mapper,
 }
 
 static const char *
-http_to_uri_scheme (GVfsUriMapper    *mapper,
-                    GVfsUriMountInfo *info)
+http_to_uri_scheme (GVfsUriMapper *mapper,
+                    GMountSpec    *spec)
 {
   const gchar *ssl;
   const gchar *type;
   gboolean     is_dav;
   gboolean     is_ssl;
 
-  ssl = g_vfs_uri_mount_info_get (info, "ssl");
-  type = g_vfs_uri_mount_info_get (info, "type");
-  
+  ssl = g_mount_spec_get (spec, "ssl");
+  type = g_mount_spec_get (spec, "type");
+
   if (strcmp (type, "dav") == 0)
      is_dav = TRUE;
   else if (strcmp (type, "http") == 0)
      is_dav = FALSE;
   else
-     return NULL; 
+     return NULL;
 
   is_ssl =
     ssl != NULL &&
     strcmp (ssl, "true") == 0;
-  
+
   if (is_dav && is_ssl)
     return "davs";
   else if (is_dav && !is_ssl)
@@ -277,11 +280,11 @@ static void
 g_vfs_uri_mapper_http_class_init (GVfsUriMapperHttpClass *class)
 {
   GVfsUriMapperClass *mapper_class;
-  
+
   mapper_class = G_VFS_URI_MAPPER_CLASS (class);
   mapper_class->get_handled_schemes     = http_get_handled_schemes;
   mapper_class->from_uri                = http_from_uri;
-  mapper_class->get_mount_info_for_path = http_get_mount_info_for_path;
+  mapper_class->get_mount_spec_for_path = http_get_mount_spec_for_path;
   mapper_class->get_handled_mount_types = http_get_handled_mount_types;
   mapper_class->to_uri                  = http_to_uri;
   mapper_class->to_uri_scheme           = http_to_uri_scheme;
diff --git a/client/smburi.c b/client/smburi.c
index af1efa5..93c17aa 100644
--- a/client/smburi.c
+++ b/client/smburi.c
@@ -76,28 +76,29 @@ smb_get_handled_schemes (GVfsUriMapper *mapper)
   return schemes;
 }
 
-static GVfsUriMountInfo *
+static GMountSpec *
 smb_from_uri (GVfsUriMapper *mapper,
-             const char *uri_str)
+             const char  *uri_str,
+              char       **path)
 {
   char *tmp;
   const char *p;
   const char *share, *share_end;
   GDecodedUri *uri;
-  GVfsUriMountInfo *info;
+  GMountSpec *spec;
 
   uri = g_vfs_decode_uri (uri_str);
   if (uri == NULL)
     return NULL;
-  
+
   if (uri->host == NULL || strlen (uri->host) == 0)
     {
       /* uri form: smb:/// or smb:///$path */
-      info = g_vfs_uri_mount_info_new ("smb-network");
+      spec = g_mount_spec_new ("smb-network");
       if (uri->path == NULL || *uri->path == 0)
-       info->path = g_strdup ("/");
+       *path = g_strdup ("/");
       else
-       info->path = g_strdup (uri->path);
+       *path = g_strdup (uri->path);
     }
   else
     {
@@ -105,15 +106,14 @@ smb_from_uri (GVfsUriMapper *mapper,
       p = uri->path;
       while (p && *p == '/')
        p++;
-      
+
       if (p == NULL || *p == 0)
        {
          /* uri form: smb://$host/ */
-         info = g_vfs_uri_mount_info_new ("smb-server");
-         tmp = normalize_smb_name (uri->host, -1);
-         g_vfs_uri_mount_info_set (info, "server", tmp);
-         g_free (tmp);
-         info->path = g_strdup ("/");
+         spec = g_mount_spec_new ("smb-server");
+          g_mount_spec_take (spec, "server", normalize_smb_name (uri->host, -1));
+
+         *path = g_strdup ("/");
        }
       else
        {
@@ -121,51 +121,41 @@ smb_from_uri (GVfsUriMapper *mapper,
          share_end = strchr (share, '/');
          if (share_end == NULL)
            share_end = share + strlen (share);
-         
+
          p = share_end;
-         
+
          while (*p == '/')
            p++;
-         
+
          if (*p == 0)
            {
              /* uri form: smb://$host/$share/
               * Here we special case smb-server files by adding "._" to the names in the uri */
              if (share[0] == '.' && share[1] == '_')
                {
-                 info = g_vfs_uri_mount_info_new ("smb-server");
-                 tmp = normalize_smb_name (uri->host, -1);
-                 g_vfs_uri_mount_info_set  (info, "server", tmp);
-                 g_free (tmp);
+                 spec = g_mount_spec_new ("smb-server");
+                  g_mount_spec_take (spec, "server", normalize_smb_name (uri->host, -1));
+
                  tmp = normalize_smb_name (share + 2, share_end - (share + 2));
-                 info->path = g_strconcat ("/", tmp, NULL);
+                 *path = g_strconcat ("/", tmp, NULL);
                  g_free (tmp);
                }
              else
                {
-                 info = g_vfs_uri_mount_info_new ("smb-share");
-                 tmp = normalize_smb_name (uri->host, -1);
-                 g_vfs_uri_mount_info_set  (info, "server", tmp);
-                 g_free (tmp);
-                 tmp = normalize_smb_name (share, share_end - share);
-                 g_vfs_uri_mount_info_set  (info, "share", tmp);
-                 g_free (tmp);
-                 info->path = g_strdup ("/");
+                 spec = g_mount_spec_new ("smb-share");
+                 g_mount_spec_take (spec, "server", normalize_smb_name (uri->host, -1));
+                  g_mount_spec_take (spec, "share", normalize_smb_name (share, share_end - share));
+
+                 *path = g_strdup ("/");
                }
            }
          else
            {
-             info = g_vfs_uri_mount_info_new ("smb-share");
-             
-             tmp = normalize_smb_name (uri->host, -1);
-             g_vfs_uri_mount_info_set  (info, "server", tmp);
-             g_free (tmp);
-             
-             tmp = normalize_smb_name (share, share_end - share);
-             g_vfs_uri_mount_info_set  (info, "share", tmp);
-             g_free (tmp);
-             
-             info->path = g_strconcat ("/", p, NULL);
+             spec = g_mount_spec_new ("smb-share");
+              g_mount_spec_take (spec, "server", normalize_smb_name (uri->host, -1));
+              g_mount_spec_take (spec, "share", normalize_smb_name (share, share_end - share));
+
+             *path = g_strconcat ("/", p, NULL);
            }
        }
 
@@ -173,11 +163,10 @@ smb_from_uri (GVfsUriMapper *mapper,
       if (uri->port != -1 && uri->port != DEFAULT_SMB_PORT)
        {
          gchar *port = g_strdup_printf ("%d", uri->port);
-         g_vfs_uri_mount_info_set (info, "port", port);
-         g_free (port);
+         g_mount_spec_take (spec, "port", port);
        }
     }
-  
+
   if (uri->userinfo)
     {
       const char *user = uri->userinfo;
@@ -185,16 +174,16 @@ smb_from_uri (GVfsUriMapper *mapper,
       if (p)
        {
          if (p != user)
-           g_vfs_uri_mount_info_set_with_len  (info, "domain", user, p - user);
+           g_mount_spec_set_with_len (spec, "domain", user, p - user);
          user = p + 1;
        }
       if (*user != 0)
-       g_vfs_uri_mount_info_set  (info, "user", user);
+       g_mount_spec_set (spec, "user", user);
     }
 
   g_vfs_decoded_uri_free (uri);
-  
-  return info;
+
+  return spec;
 }
 
 static const char * const *
@@ -211,7 +200,8 @@ smb_get_handled_mount_types (GVfsUriMapper *mapper)
 
 static char *
 smb_to_uri (GVfsUriMapper *mapper,
-           GVfsUriMountInfo *info,
+            GMountSpec *spec,
+            const char *path,
            gboolean allow_utf8)
 {
   const char *type;
@@ -226,45 +216,45 @@ smb_to_uri (GVfsUriMapper *mapper,
 
   uri = g_new0 (GDecodedUri, 1);
   
-  type = g_vfs_uri_mount_info_get (info, "type");
+  type = g_mount_spec_get (spec, "type");
 
   uri->scheme = g_strdup ("smb");
   
   if (strcmp (type, "smb-network") == 0)
     {
-      uri->path = g_strdup (info->path);
+      uri->path = g_strdup (path);
     }
   else if (strcmp (type, "smb-server") == 0)
     {
-      server = g_vfs_uri_mount_info_get (info, "server");
+      server = g_mount_spec_get (spec, "server");
       uri->host = g_strdup (server);
 
       /* Map the mountables in server to ._share because the actual share mount maps to smb://server/share */
-      if (info->path && info->path[0] == '/' && info->path[1] != 0)
-       uri->path = g_strconcat ("/._", info->path + 1, NULL);
+      if (path && path[0] == '/' && path[1] != 0)
+       uri->path = g_strconcat ("/._", path + 1, NULL);
       else
        uri->path = g_strdup ("/");
-      port = g_vfs_uri_mount_info_get (info, "port");
+      port = g_mount_spec_get (spec, "port");
     }
   else if (strcmp (type, "smb-share") == 0)
     {
-      server = g_vfs_uri_mount_info_get (info, "server");
+      server = g_mount_spec_get (spec, "server");
       uri->host = g_strdup (server);
-      share = g_vfs_uri_mount_info_get (info, "share");
-      if (info->path[0] == '/')
-       uri->path = g_strconcat ("/", share, info->path, NULL);
+      share = g_mount_spec_get (spec, "share");
+      if (path[0] == '/')
+       uri->path = g_strconcat ("/", share, path, NULL);
       else
-       uri->path = g_strconcat ("/", share, "/", info->path, NULL);
-       
-      user = g_vfs_uri_mount_info_get (info, "user");
-      domain = g_vfs_uri_mount_info_get (info, "domain");
+       uri->path = g_strconcat ("/", share, "/", path, NULL);
+
+      user = g_mount_spec_get (spec, "user");
+      domain = g_mount_spec_get (spec, "domain");
       if (user) {
         if (domain)
           uri->userinfo = g_strconcat (domain, ";", user, NULL);
         else
           uri->userinfo = g_strdup (user);
       }
-      port = g_vfs_uri_mount_info_get (info, "port");
+      port = g_mount_spec_get (spec, "port");
     }
 
   if (port && (port_num = atoi (port)))
@@ -279,10 +269,10 @@ smb_to_uri (GVfsUriMapper *mapper,
 
 static const char *
 smb_to_uri_scheme (GVfsUriMapper *mapper,
-                   GVfsUriMountInfo *info)
+                   GMountSpec    *spec)
 {
-  const gchar *type = g_vfs_uri_mount_info_get (info, "type");
-  
+  const gchar *type = g_mount_spec_get (spec, "type");
+
   if (strcmp ("smb-network", type) == 0 ||
       strcmp ("smb-server", type) == 0 ||
       strcmp ("smb-share", type) == 0)
@@ -300,7 +290,7 @@ static void
 g_vfs_uri_mapper_smb_class_init (GVfsUriMapperSmbClass *class)
 {
   GVfsUriMapperClass *mapper_class;
-  
+
   mapper_class = G_VFS_URI_MAPPER_CLASS (class);
   mapper_class->get_handled_schemes = smb_get_handled_schemes;
   mapper_class->from_uri = smb_from_uri;
diff --git a/common/gmountspec.c b/common/gmountspec.c
index ac9b66c..bde37fa 100644
--- a/common/gmountspec.c
+++ b/common/gmountspec.c
@@ -131,12 +131,12 @@ add_item (GMountSpec *spec,
   g_array_append_val (spec->items, item);
 }
 
-
-void 
-g_mount_spec_set_with_len (GMountSpec *spec,
-                          const char *key,
-                          const char *value,
-                          int value_len)
+static void 
+g_mount_spec_set_with_len_internal (GMountSpec *spec,
+                                    const char *key,
+                                    const char *value,
+                                    int value_len,
+                                    gboolean copy)
 {
   int i;
   char *value_copy;
@@ -144,10 +144,15 @@ g_mount_spec_set_with_len (GMountSpec *spec,
   g_return_if_fail (key != NULL);
   g_return_if_fail (value != NULL);
 
-  if (value_len == -1)
-    value_copy = g_strdup (value);
+  if (copy)
+    {
+      if (value_len == -1)
+        value_copy = g_strdup (value);
+      else
+        value_copy = g_strndup (value, value_len);
+    }
   else
-    value_copy = g_strndup (value, value_len);
+    value_copy = (char*) value;
 
   for (i = 0; i < spec->items->len; i++)
     {
@@ -165,6 +170,15 @@ g_mount_spec_set_with_len (GMountSpec *spec,
 }
 
 void 
+g_mount_spec_set_with_len (GMountSpec *spec,
+                           const char *key,
+                           const char *value,
+                           int value_len)
+{
+  g_mount_spec_set_with_len_internal (spec, key, value, value_len, TRUE);
+}
+
+void 
 g_mount_spec_set (GMountSpec *spec,
                  const char *key,
                  const char *value)
@@ -172,6 +186,13 @@ g_mount_spec_set (GMountSpec *spec,
   g_mount_spec_set_with_len (spec, key, value, -1);
 }
 
+void
+g_mount_spec_take (GMountSpec *spec,
+                   const char *key,
+                   char *value)
+{
+  g_mount_spec_set_with_len_internal (spec, key, value, -1, FALSE);
+}
 
 GMountSpec *
 g_mount_spec_copy (GMountSpec *spec)
diff --git a/common/gmountspec.h b/common/gmountspec.h
index 143c094..909079e 100644
--- a/common/gmountspec.h
+++ b/common/gmountspec.h
@@ -56,6 +56,9 @@ void        g_mount_spec_set_mount_prefix  (GMountSpec      *spec,
 void        g_mount_spec_set               (GMountSpec      *spec,
                                            const char      *key,
                                            const char      *value);
+void        g_mount_spec_take              (GMountSpec      *spec,
+                                            const char      *key,
+                                            char            *value);
 void        g_mount_spec_set_with_len      (GMountSpec      *spec,
                                            const char      *key,
                                            const char      *value,


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