summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2008-01-21 11:11:28 +0000
committerAlexander Larsson <alexl@src.gnome.org>2008-01-21 11:11:28 +0000
commit26647aaac8b6e44b0bc80e88b23c1d401743b754 (patch)
treef727cd73d47d5e2053b0e88a1aa2883f16280cc1
parentbd5de03ac4823797587048441d57fdd7a787f4b9 (diff)
downloadgvfs-26647aaac8b6e44b0bc80e88b23c1d401743b754.tar.gz
Added. Added sftp uri mapper that aliases ssh: to sftp: (#509860)
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. svn path=/trunk/; revision=1154
-rw-r--r--ChangeLog11
-rw-r--r--client/Makefile.am1
-rw-r--r--client/gdaemonvfs.c2
-rw-r--r--client/sftpuri.c167
-rw-r--r--client/smburi.c2
5 files changed, 183 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b3347ee3..d7cf6ebd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
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.
+
+2008-01-21 Alexander Larsson <alexl@redhat.com>
+
* common/gmounttracker.c:
Do the initial mount tracker call sync so that
the volume monitor is populated with the current
diff --git a/client/Makefile.am b/client/Makefile.am
index 6aeb703e..03858a26 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -19,6 +19,7 @@ gvfsclientinclude_HEADERS = \
$(NULL)
URI_PARSER_SOURCES = \
+ sftpuri.c \
smburi.c \
httpuri.c \
$(NULL)
diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c
index f41fd852..61c8bd1e 100644
--- a/client/gdaemonvfs.c
+++ b/client/gdaemonvfs.c
@@ -783,6 +783,7 @@ g_daemon_vfs_class_init (GDaemonVfsClass *class)
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_io_module_load (GIOModule *module)
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);
}
diff --git a/client/sftpuri.c b/client/sftpuri.c
new file mode 100644
index 00000000..0193653d
--- /dev/null
+++ b/client/sftpuri.c
@@ -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));
+}
diff --git a/client/smburi.c b/client/smburi.c
index c7871115..f2f3ea3a 100644
--- a/client/smburi.c
+++ b/client/smburi.c
@@ -181,6 +181,8 @@ smb_from_uri (GVfsUriMapper *mapper,
g_vfs_uri_mount_info_set (info, "user", user);
}
+ g_vfs_decoded_uri_free (uri);
+
return info;
}