summaryrefslogtreecommitdiff
path: root/daemon/gvfsbackendftp.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2009-12-03 16:28:21 +0100
committerBenjamin Otte <otte@gnome.org>2009-12-03 16:32:31 +0100
commit5b082a22bcecb6ad3767bf70dbc3d98f08368e19 (patch)
tree9dbcd2653cc8429e472df3306e89e93a078d06a2 /daemon/gvfsbackendftp.c
parent0fb2f6262124247137346c478aa018bb16ed87fa (diff)
downloadgvfs-5b082a22bcecb6ad3767bf70dbc3d98f08368e19.tar.gz
[FTP] implement default location support
https://bugzilla.gnome.org/show_bug.cgi?id=560357 https://bugzilla.gnome.org/show_bug.cgi?id=561998
Diffstat (limited to 'daemon/gvfsbackendftp.c')
-rw-r--r--daemon/gvfsbackendftp.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/daemon/gvfsbackendftp.c b/daemon/gvfsbackendftp.c
index 5dfaa4c7..1b48fb0a 100644
--- a/daemon/gvfsbackendftp.c
+++ b/daemon/gvfsbackendftp.c
@@ -191,6 +191,58 @@ gvfs_backend_ftp_setup_directory_cache (GVfsBackendFtp *ftp)
ftp->dir_cache = g_vfs_ftp_dir_cache_new (ftp->dir_funcs);
}
+static GVfsFtpFile *
+g_vfs_backend_create_file_from_reply (GVfsBackendFtp *ftp, const char *name)
+{
+ const char *end;
+
+ end = name + strlen (name);
+
+ /* strip leading spaces */
+ while (g_ascii_isspace (*name))
+ name++;
+
+ /* strip leading and trailing quote character */
+ /* FIXME: need to unescape th contained string? */
+ if (*name == '"' && end[-1] == '"')
+ {
+ name++;
+ end--;
+ }
+
+ if (*end == '\0') {
+ return g_vfs_ftp_file_new_from_ftp (ftp, name);
+ } else {
+ char *s = g_strndup (name, end - name);
+ GVfsFtpFile *file = g_vfs_ftp_file_new_from_ftp (ftp, s);
+ g_free (s);
+ return file;
+ }
+}
+
+static void
+gvfs_backend_ftp_determine_default_location (GVfsFtpTask *task)
+{
+ char **reply;
+ GVfsFtpFile *home;
+
+ if (g_vfs_ftp_task_is_in_error (task))
+ return;
+
+ if (!g_vfs_ftp_task_send_and_check (task, 0, NULL, NULL, &reply, "PWD"))
+ {
+ g_vfs_ftp_task_clear_error (task);
+ return;
+ }
+
+ home = g_vfs_backend_create_file_from_reply (task->backend, reply[0] + 4);
+ g_vfs_backend_set_default_location (G_VFS_BACKEND (task->backend),
+ g_vfs_ftp_file_get_gvfs_path (home));
+ g_vfs_ftp_file_free (home);
+
+ g_strfreev (reply);
+}
+
/*** COMMON FUNCTIONS WITH SPECIAL HANDLING ***/
static gboolean
@@ -411,6 +463,7 @@ try_login:
g_vfs_ftp_task_setup_connection (&task);
gvfs_backend_ftp_determine_system (&task);
gvfs_backend_ftp_setup_directory_cache (ftp);
+ gvfs_backend_ftp_determine_default_location (&task);
/* Save the address of the current connection, so that for future connections,
* we are sure to connect to the same machine.