gvfs r1154 - in trunk: . client



Author: alexl
Date: Mon Jan 21 11:11:28 2008
New Revision: 1154
URL: http://svn.gnome.org/viewvc/gvfs?rev=1154&view=rev

Log:
2008-01-21  Alexander Larsson  <alexl redhat com>

        * client/Makefile.am:
        * client/gdaemonvfs.c:
        * client/sftpuri.c: Added.
	Added sftp uri mapper that aliases ssh: to sftp: (#509860)
	
        * client/smburi.c:
        (smb_from_uri):
	Fix leak.




Added:
   trunk/client/sftpuri.c
Modified:
   trunk/ChangeLog
   trunk/client/Makefile.am
   trunk/client/gdaemonvfs.c
   trunk/client/smburi.c

Modified: trunk/client/Makefile.am
==============================================================================
--- trunk/client/Makefile.am	(original)
+++ trunk/client/Makefile.am	Mon Jan 21 11:11:28 2008
@@ -19,6 +19,7 @@
 	$(NULL)
 
 URI_PARSER_SOURCES = \
+	sftpuri.c \
 	smburi.c \
 	httpuri.c \
 	$(NULL)

Modified: trunk/client/gdaemonvfs.c
==============================================================================
--- trunk/client/gdaemonvfs.c	(original)
+++ trunk/client/gdaemonvfs.c	Mon Jan 21 11:11:28 2008
@@ -783,6 +783,7 @@
 
 void g_vfs_uri_mapper_smb_register (GIOModule *module);
 void g_vfs_uri_mapper_http_register (GIOModule *module);
+void g_vfs_uri_mapper_sftp_register (GIOModule *module);
 
 void
 g_io_module_load (GIOModule *module)
@@ -792,6 +793,7 @@
 
   g_vfs_uri_mapper_register (module);
   g_vfs_uri_mapper_smb_register (module);
+  g_vfs_uri_mapper_sftp_register (module);
   g_vfs_uri_mapper_http_register (module);
 }
 

Added: trunk/client/sftpuri.c
==============================================================================
--- (empty file)
+++ trunk/client/sftpuri.c	Mon Jan 21 11:11:28 2008
@@ -0,0 +1,167 @@
+/* GIO - GLib Input, Output and Streaming Library
+ * 
+ * Copyright (C) 2006-2007 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Alexander Larsson <alexl redhat com>
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <gio/gio.h>
+#include <gvfsurimapper.h>
+#include <gvfsuriutils.h>
+
+typedef struct _GVfsUriMapperSftp GVfsUriMapperSftp;
+typedef struct _GVfsUriMapperSftpClass GVfsUriMapperSftpClass;
+
+struct _GVfsUriMapperSftp
+{
+  GVfsUriMapper parent;
+};
+
+struct _GVfsUriMapperSftpClass
+{
+  GVfsUriMapperClass parent_class;
+};
+
+GType g_vfs_uri_mapper_sftp_get_type (void);
+void g_vfs_uri_mapper_sftp_register (GIOModule *module);
+
+G_DEFINE_DYNAMIC_TYPE (GVfsUriMapperSftp, g_vfs_uri_mapper_sftp, G_VFS_TYPE_URI_MAPPER)
+
+static void
+g_vfs_uri_mapper_sftp_init (GVfsUriMapperSftp *vfs)
+{
+}
+
+static const char * const *
+sftp_get_handled_schemes (GVfsUriMapper *mapper)
+{
+  static const char *schemes[] = {
+    "sftp",
+    "ssh",
+    NULL
+  };
+  return schemes;
+}
+
+static GVfsUriMountInfo *
+sftp_from_uri (GVfsUriMapper *mapper,
+	       const char *uri_str)
+{
+  GDecodedUri *uri;
+  GVfsUriMountInfo *info;
+
+  uri = g_vfs_decode_uri (uri_str);
+  if (uri == NULL)
+    return NULL;
+
+  info = g_vfs_uri_mount_info_new ("sftp");
+  
+  if (uri->host && *uri->host)
+    g_vfs_uri_mount_info_set (info, "host", uri->host);
+  
+  if (uri->userinfo && *uri->userinfo)
+    g_vfs_uri_mount_info_set (info, "user", uri->userinfo);
+  
+  if (uri->port != -1)
+    {
+      char *port = g_strdup_printf ("%d", uri->port);
+      g_vfs_uri_mount_info_set (info, "port", port);
+      g_free (port);
+    }
+  
+  info->path = g_strdup (uri->path);
+  
+  g_vfs_decoded_uri_free (uri);
+
+  return info;
+}
+
+static const char * const *
+sftp_get_handled_mount_types (GVfsUriMapper *mapper)
+{
+  static const char *types[] = {
+    "sftp", 
+    NULL
+  };
+  return types;
+}
+
+static char *
+sftp_to_uri (GVfsUriMapper *mapper,
+	     GVfsUriMountInfo *info,
+	     gboolean allow_utf8)
+{
+  char *s;
+  GDecodedUri uri;
+  const char *port;
+
+  memset (&uri, 0, sizeof (uri));
+  uri.port = -1;
+
+  uri.scheme = "sftp";
+  uri.host = (char *)g_vfs_uri_mount_info_get (info, "host");
+  uri.userinfo = (char *)g_vfs_uri_mount_info_get (info, "user");
+  
+  port = g_vfs_uri_mount_info_get (info, "port");
+  if (port != NULL)
+    uri.port = atoi (port);
+
+  if (info->path == NULL)
+    uri.path = "/";
+  else
+    uri.path = info->path;
+  
+  return g_vfs_encode_uri (&uri, allow_utf8);
+}
+
+static const char *
+sftp_to_uri_scheme (GVfsUriMapper *mapper,
+		    GVfsUriMountInfo *info)
+{
+  return "sftp";
+}
+
+static void
+g_vfs_uri_mapper_sftp_class_finalize (GVfsUriMapperSftpClass *klass)
+{
+}
+
+static void
+g_vfs_uri_mapper_sftp_class_init (GVfsUriMapperSftpClass *class)
+{
+  GObjectClass *object_class;
+  GVfsUriMapperClass *mapper_class;
+  
+  object_class = (GObjectClass *) class;
+  mapper_class = G_VFS_URI_MAPPER_CLASS (class);
+  mapper_class->get_handled_schemes = sftp_get_handled_schemes;
+  mapper_class->from_uri = sftp_from_uri;
+  mapper_class->get_handled_mount_types = sftp_get_handled_mount_types;
+  mapper_class->to_uri = sftp_to_uri;
+  mapper_class->to_uri_scheme = sftp_to_uri_scheme;
+}
+
+void
+g_vfs_uri_mapper_sftp_register (GIOModule *module)
+{
+  g_vfs_uri_mapper_sftp_register_type (G_TYPE_MODULE (module));
+}

Modified: trunk/client/smburi.c
==============================================================================
--- trunk/client/smburi.c	(original)
+++ trunk/client/smburi.c	Mon Jan 21 11:11:28 2008
@@ -181,6 +181,8 @@
 	g_vfs_uri_mount_info_set  (info, "user", user);
     }
 
+  g_vfs_decoded_uri_free (uri);
+  
   return info;
 }
 



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