diff options
-rw-r--r-- | daemon/gvfsafpserver.c | 173 | ||||
-rw-r--r-- | daemon/gvfsafpserver.h | 11 | ||||
-rw-r--r-- | daemon/gvfsbackendafp.c | 58 |
3 files changed, 143 insertions, 99 deletions
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c index d77130f7..baa499f8 100644 --- a/daemon/gvfsafpserver.c +++ b/daemon/gvfsafpserver.c @@ -40,6 +40,50 @@ G_DEFINE_TYPE (GVfsAfpServer, g_vfs_afp_server, G_TYPE_OBJECT); #define AFP_UAM_DHX "DHCAST128" #define AFP_UAM_DHX2 "DHX2" +GVfsAfpServer * +g_vfs_afp_server_new (GNetworkAddress *addr) +{ + GVfsAfpServer *afp_serv; + + afp_serv = g_object_new (G_VFS_TYPE_AFP_SERVER, NULL); + + afp_serv->addr = addr; + afp_serv->conn = g_vfs_afp_connection_new (G_SOCKET_CONNECTABLE (addr)); + + return afp_serv; +} + +static void +g_vfs_afp_server_init (GVfsAfpServer *afp_serv) +{ + afp_serv->machine_type = NULL; + afp_serv->server_name = NULL; + afp_serv->utf8_server_name = NULL; + afp_serv->uams = NULL; + afp_serv->version = AFP_VERSION_INVALID; +} + +static void +g_vfs_afp_server_finalize (GObject *object) +{ + GVfsAfpServer *afp_serv = G_VFS_AFP_SERVER (object); + + g_free (afp_serv->machine_type); + g_free (afp_serv->server_name); + g_free (afp_serv->utf8_server_name); + + g_slist_free_full (afp_serv->uams, g_free); + + G_OBJECT_CLASS (g_vfs_afp_server_parent_class)->finalize (object); +} + +static void +g_vfs_afp_server_class_init (GVfsAfpServerClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = g_vfs_afp_server_finalize; +} static const char * afp_version_to_string (AfpVersion afp_version) @@ -753,8 +797,52 @@ get_server_info (GVfsAfpServer *afp_serv, return TRUE; } +static gboolean +get_server_parms (GVfsAfpServer *server, + GCancellable *cancellable, + GError **error) +{ + GVfsAfpCommand *comm; + GVfsAfpReply *reply; + gboolean res; + AfpResultCode res_code; + gint32 server_time; + + /* Get Server Parameters */ + comm = g_vfs_afp_command_new (AFP_COMMAND_GET_SRVR_PARMS); + /* pad byte */ + g_vfs_afp_command_put_byte (comm, 0); + + res = g_vfs_afp_connection_send_command_sync (server->conn, comm, cancellable, + error); + g_object_unref (comm); + if (!res) + return FALSE; + + reply = g_vfs_afp_connection_read_reply_sync (server->conn, cancellable, error); + if (!reply) + return FALSE; + + res_code = g_vfs_afp_reply_get_result_code (reply); + if (res_code != AFP_RESULT_NO_ERROR) + { + g_object_unref (reply); + + g_propagate_error (error, afp_result_code_to_gerror (res_code)); + return FALSE; + } + + /* server time */ + g_vfs_afp_reply_read_int32 (reply, &server_time); + server->time_diff = (g_get_real_time () / G_USEC_PER_SEC) - server_time; + + g_object_unref (reply); + + return TRUE; +} + gboolean -g_vfs_afp_server_login (GVfsAfpServer *afp_serv, +g_vfs_afp_server_login (GVfsAfpServer *server, const char *initial_user, GMountSource *mount_source, char **logged_in_user, @@ -769,7 +857,7 @@ g_vfs_afp_server_login (GVfsAfpServer *afp_serv, char *prompt = NULL; GError *err = NULL; - res = get_server_info (afp_serv, cancellable, error); + res = get_server_info (server, cancellable, error); if (!res) return FALSE; @@ -778,7 +866,7 @@ g_vfs_afp_server_login (GVfsAfpServer *afp_serv, if (initial_user) { if (g_str_equal (initial_user, "anonymous") && - g_slist_find_custom (afp_serv->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0)) + g_slist_find_custom (server->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0)) { user = NULL; password = NULL; @@ -787,12 +875,12 @@ g_vfs_afp_server_login (GVfsAfpServer *afp_serv, } else if (g_vfs_keyring_lookup_password (initial_user, - g_network_address_get_hostname (afp_serv->addr), + g_network_address_get_hostname (server->addr), NULL, "afp", NULL, NULL, - g_network_address_get_port (afp_serv->addr), + g_network_address_get_port (server->addr), &user, NULL, &password) && @@ -823,10 +911,10 @@ g_vfs_afp_server_login (GVfsAfpServer *afp_serv, /* create prompt */ if (initial_user) /* Translators: the first %s is the username, the second the host name */ - g_string_append_printf (str, _("Enter password for afp as %s on %s"), initial_user, afp_serv->server_name); + g_string_append_printf (str, _("Enter password for afp as %s on %s"), initial_user, server->server_name); else /* translators: %s here is the hostname */ - g_string_append_printf (str, _("Enter password for afp on %s"), afp_serv->server_name); + g_string_append_printf (str, _("Enter password for afp on %s"), server->server_name); prompt = g_string_free (str, FALSE); @@ -836,7 +924,7 @@ g_vfs_afp_server_login (GVfsAfpServer *afp_serv, { flags |= G_ASK_PASSWORD_NEED_USERNAME; - if (g_slist_find_custom (afp_serv->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0)) + if (g_slist_find_custom (server->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0)) flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED; } @@ -869,15 +957,15 @@ g_vfs_afp_server_login (GVfsAfpServer *afp_serv, try_login: /* Open connection */ - res = g_vfs_afp_connection_open (afp_serv->conn, cancellable, &err); + res = g_vfs_afp_connection_open (server->conn, cancellable, &err); if (!res) break; - res = do_login (afp_serv, user, password, anonymous, + res = do_login (server, user, password, anonymous, cancellable, &err); if (!res) { - g_vfs_afp_connection_close (afp_serv->conn, cancellable, NULL); + g_vfs_afp_connection_close (server->conn, cancellable, NULL); if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED)) break; @@ -906,17 +994,21 @@ try_login: { /* a prompt was created, so we have to save the password */ g_vfs_keyring_save_password (user, - g_network_address_get_hostname (afp_serv->addr), + g_network_address_get_hostname (server->addr), NULL, "afp", NULL, NULL, - g_network_address_get_port (afp_serv->addr), + g_network_address_get_port (server->addr), password, password_save); g_free (prompt); } + /* Get server parms */ + if (!get_server_parms (server, cancellable, error)) + return FALSE; + if (logged_in_user) { if (anonymous) @@ -932,48 +1024,17 @@ try_login: return TRUE; } -GVfsAfpServer * -g_vfs_afp_server_new (GNetworkAddress *addr) -{ - GVfsAfpServer *afp_serv; - - afp_serv = g_object_new (G_VFS_TYPE_AFP_SERVER, NULL); - - afp_serv->addr = addr; - afp_serv->conn = g_vfs_afp_connection_new (G_SOCKET_CONNECTABLE (addr)); - - return afp_serv; -} - -static void -g_vfs_afp_server_init (GVfsAfpServer *afp_serv) -{ - afp_serv->machine_type = NULL; - afp_serv->server_name = NULL; - afp_serv->utf8_server_name = NULL; - afp_serv->uams = NULL; - afp_serv->version = AFP_VERSION_INVALID; -} - -static void -g_vfs_afp_server_finalize (GObject *object) -{ - GVfsAfpServer *afp_serv = G_VFS_AFP_SERVER (object); - - g_free (afp_serv->machine_type); - g_free (afp_serv->server_name); - g_free (afp_serv->utf8_server_name); - - g_slist_free_full (afp_serv->uams, g_free); - - G_OBJECT_CLASS (g_vfs_afp_server_parent_class)->finalize (object); -} - -static void -g_vfs_afp_server_class_init (GVfsAfpServerClass *klass) +/* + * g_vfs_server_time_to_local_time: + * + * @server: a #GVfsAfpServer + * @server_time: a time value in server time + * + * Returns: the time converted to local time + */ +gint64 +g_vfs_afp_server_time_to_local_time (GVfsAfpServer *server, + gint32 server_time) { - GObjectClass* object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = g_vfs_afp_server_finalize; + return server_time + server->time_diff; } - diff --git a/daemon/gvfsafpserver.h b/daemon/gvfsafpserver.h index 5c624a65..5d1626fc 100644 --- a/daemon/gvfsafpserver.h +++ b/daemon/gvfsafpserver.h @@ -67,8 +67,14 @@ struct _GVfsAfpServer char *utf8_server_name; GSList *uams; AfpVersion version; + + gint32 time_diff; }; +GType g_vfs_afp_server_get_type (void) G_GNUC_CONST; + +GVfsAfpServer* g_vfs_afp_server_new (GNetworkAddress *addr); + gboolean g_vfs_afp_server_login (GVfsAfpServer *afp_serv, const char *initial_user, GMountSource *mount_source, @@ -76,9 +82,8 @@ gboolean g_vfs_afp_server_login (GVfsAfpServer *afp_serv, GCancellable *cancellable, GError **error); -GVfsAfpServer* g_vfs_afp_server_new (GNetworkAddress *addr); - -GType g_vfs_afp_server_get_type (void) G_GNUC_CONST; +gint64 g_vfs_afp_server_time_to_local_time (GVfsAfpServer *afp_serv, + gint32 server_time); G_END_DECLS diff --git a/daemon/gvfsbackendafp.c b/daemon/gvfsbackendafp.c index 8dd436cf..f1dd86b7 100644 --- a/daemon/gvfsbackendafp.c +++ b/daemon/gvfsbackendafp.c @@ -80,8 +80,7 @@ struct _GVfsBackendAfp char *user; GVfsAfpServer *server; - - gint32 time_diff; + guint16 vol_attrs_bitmap; guint16 volume_id; @@ -293,10 +292,14 @@ static void fill_info (GVfsBackendAfp *afp_backend, if (bitmap & AFP_FILEDIR_BITMAP_CREATE_DATE_BIT) { gint32 create_date; + gint64 create_date_local; g_vfs_afp_reply_read_int32 (reply, &create_date); + + create_date_local = g_vfs_afp_server_time_to_local_time (afp_backend->server, + create_date); g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED, - create_date + afp_backend->time_diff); + create_date_local); } if (bitmap & AFP_FILEDIR_BITMAP_MOD_DATE_BIT) @@ -306,7 +309,8 @@ static void fill_info (GVfsBackendAfp *afp_backend, char *etag; g_vfs_afp_reply_read_int32 (reply, &mod_date); - mod_date_unix = mod_date + afp_backend->time_diff; + mod_date_unix = g_vfs_afp_server_time_to_local_time (afp_backend->server, + mod_date); g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED, mod_date_unix); @@ -916,19 +920,27 @@ get_vol_parms_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) if (vol_bitmap & AFP_VOLUME_BITMAP_CREATE_DATE_BIT) { gint32 create_date; + gint64 create_date_local; g_vfs_afp_reply_read_int32 (reply, &create_date); + + create_date_local = g_vfs_afp_server_time_to_local_time (afp_backend->server, + create_date); g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED, - create_date + afp_backend->time_diff); + create_date_local); } if (vol_bitmap & AFP_VOLUME_BITMAP_MOD_DATE_BIT) { gint32 mod_date; + gint64 mod_date_local; g_vfs_afp_reply_read_int32 (reply, &mod_date); + + mod_date_local = g_vfs_afp_server_time_to_local_time (afp_backend->server, + mod_date); g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED, - mod_date + afp_backend->time_diff); + mod_date_local); } if (vol_bitmap & AFP_VOLUME_BITMAP_EXT_BYTES_FREE_BIT) @@ -4124,8 +4136,6 @@ do_mount (GVfsBackend *backend, GVfsAfpReply *reply; AfpResultCode res_code; - gint32 server_time; - GMountSpec *afp_mount_spec; char *server_name; char *display_name; @@ -4137,38 +4147,6 @@ do_mount (GVfsBackend *backend, if (!res) goto error; - - /* Get Server Parameters */ - comm = g_vfs_afp_command_new (AFP_COMMAND_GET_SRVR_PARMS); - /* pad byte */ - g_vfs_afp_command_put_byte (comm, 0); - - res = g_vfs_afp_connection_send_command_sync (afp_backend->server->conn, - comm, G_VFS_JOB (job)->cancellable, - &err); - g_object_unref (comm); - if (!res) - goto error; - - reply = g_vfs_afp_connection_read_reply_sync (afp_backend->server->conn, - G_VFS_JOB (job)->cancellable, &err); - if (!reply) - goto error; - - res_code = g_vfs_afp_reply_get_result_code (reply); - if (res_code != AFP_RESULT_NO_ERROR) - { - g_object_unref (reply); - goto generic_error; - } - - /* server time */ - g_vfs_afp_reply_read_int32 (reply, &server_time); - afp_backend->time_diff = (g_get_real_time () / G_USEC_PER_SEC) - server_time; - - g_object_unref (reply); - - /* Get User Info */ if (!get_userinfo (afp_backend, G_VFS_JOB (job)->cancellable, &err)) goto error; |