summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl-Anton Ingmarsson <ca.ingmarsson@gmail.com>2012-03-12 21:34:36 +0100
committerCarl-Anton Ingmarsson <ca.ingmarsson@gmail.com>2012-08-09 21:06:05 +0200
commitb355a34ca375c686f83279dfacd068607b35452a (patch)
tree1e581a668e2a54bc1192358918f3e72fdf3150c8
parentef8d81602b01cecf0c9cab8b54c0f9e65486dc57 (diff)
downloadgvfs-b355a34ca375c686f83279dfacd068607b35452a.tar.gz
afp: make fields private in GVfsAfpServer
-rw-r--r--daemon/gvfsafpconnection.h4
-rw-r--r--daemon/gvfsafpserver.c230
-rw-r--r--daemon/gvfsafpserver.h33
-rw-r--r--daemon/gvfsafpvolume.c55
-rw-r--r--daemon/gvfsafpvolume.h2
-rw-r--r--daemon/gvfsbackendafp.c11
-rw-r--r--daemon/gvfsbackendafpbrowse.c9
7 files changed, 213 insertions, 131 deletions
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index caea1526..5637ed96 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -324,8 +324,8 @@ GType g_vfs_afp_command_get_type (void) G_GNUC_CONST;
#define G_VFS_TYPE_AFP_CONNECTION (g_vfs_afp_connection_get_type ())
#define G_VFS_AFP_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_VFS_TYPE_AFP_CONNECTION, GVfsAfpConnection))
#define G_VFS_AFP_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_VFS_TYPE_AFP_CONNECTION, GVfsAfpConnectionClass))
-#define G_IS_VFS_AFP_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_VFS_TYPE_AFP_CONNECTION))
-#define G_IS_VFS_AFP_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_VFS_TYPE_AFP_CONNECTION))
+#define G_VFS_IS_AFP_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_VFS_TYPE_AFP_CONNECTION))
+#define G_VFS_IS_AFP_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G_VFS_TYPE_AFP_CONNECTION))
#define G_VFS_AFP_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_VFS_TYPE_AFP_CONNECTION, GVfsAfpConnectionClass))
typedef struct _GVfsAfpConnectionClass GVfsAfpConnectionClass;
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c
index 9631f9ae..6c80eb53 100644
--- a/daemon/gvfsafpserver.c
+++ b/daemon/gvfsafpserver.c
@@ -36,6 +36,18 @@
G_DEFINE_TYPE (GVfsAfpServer, g_vfs_afp_server, G_TYPE_OBJECT);
+struct _GvfsAfpServerPrivate
+{
+ GNetworkAddress *addr;
+ GVfsAfpConnection *conn;
+
+ GVfsAfpServerInfo info;
+ gint32 time_diff;
+
+ guint32 user_id;
+ guint32 group_id;
+};
+
#define AFP_UAM_NO_USER "No User Authent"
#define AFP_UAM_DHX "DHCAST128"
#define AFP_UAM_DHX2 "DHX2"
@@ -43,38 +55,44 @@ G_DEFINE_TYPE (GVfsAfpServer, g_vfs_afp_server, G_TYPE_OBJECT);
GVfsAfpServer *
g_vfs_afp_server_new (GNetworkAddress *addr)
{
- GVfsAfpServer *afp_serv;
+ GVfsAfpServer *server;
- afp_serv = g_object_new (G_VFS_TYPE_AFP_SERVER, NULL);
+ server = g_object_new (G_VFS_TYPE_AFP_SERVER, NULL);
- afp_serv->addr = addr;
+ server->priv->addr = addr;
- return afp_serv;
+ return server;
}
static void
-g_vfs_afp_server_init (GVfsAfpServer *afp_serv)
+g_vfs_afp_server_init (GVfsAfpServer *server)
{
- 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;
+ GVfsAfpServerPrivate *priv;
+
+ server->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (server, G_VFS_TYPE_AFP_SERVER,
+ GVfsAfpServerPrivate);
+
+ priv->info.machine_type = NULL;
+ priv->info.server_name = NULL;
+ priv->info.utf8_server_name = NULL;
+ priv->info.uams = NULL;
+ priv->info.version = AFP_VERSION_INVALID;
}
static void
g_vfs_afp_server_finalize (GObject *object)
{
- GVfsAfpServer *afp_serv = G_VFS_AFP_SERVER (object);
+ GVfsAfpServer *server = G_VFS_AFP_SERVER (object);
+ GVfsAfpServerPrivate *priv = server->priv;
- g_clear_object (&afp_serv->addr);
- g_clear_object (&afp_serv->conn);
+ g_clear_object (&priv->addr);
+ g_clear_object (&priv->conn);
- g_free (afp_serv->machine_type);
- g_free (afp_serv->server_name);
- g_free (afp_serv->utf8_server_name);
+ g_free (priv->info.machine_type);
+ g_free (priv->info.server_name);
+ g_free (priv->info.utf8_server_name);
- g_slist_free_full (afp_serv->uams, g_free);
+ g_slist_free_full (priv->info.uams, g_free);
G_OBJECT_CLASS (g_vfs_afp_server_parent_class)->finalize (object);
}
@@ -85,6 +103,8 @@ g_vfs_afp_server_class_init (GVfsAfpServerClass *klass)
GObjectClass* object_class = G_OBJECT_CLASS (klass);
object_class->finalize = g_vfs_afp_server_finalize;
+
+ g_type_class_add_private (klass, sizeof (GVfsAfpServerPrivate));
}
static const char *
@@ -113,12 +133,14 @@ string_to_afp_version (const char *str)
#ifdef HAVE_GCRYPT
static gboolean
-dhx2_login (GVfsAfpServer *afp_serv,
+dhx2_login (GVfsAfpServer *server,
const char *username,
const char *password,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
gboolean res;
gcry_error_t gcry_err;
GVfsAfpCommand *comm;
@@ -177,12 +199,12 @@ dhx2_login (GVfsAfpServer *afp_serv,
/* Request 1 */
comm = g_vfs_afp_command_new (AFP_COMMAND_LOGIN);
- g_vfs_afp_command_put_pascal (comm, afp_version_to_string (afp_serv->version));
+ g_vfs_afp_command_put_pascal (comm, afp_version_to_string (priv->info.version));
g_vfs_afp_command_put_pascal (comm, AFP_UAM_DHX2);
g_vfs_afp_command_put_pascal (comm, username);
g_vfs_afp_command_pad_to_even (comm);
- reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm,
cancellable, error);
g_object_unref (comm);
if (!reply)
@@ -286,7 +308,7 @@ dhx2_login (GVfsAfpServer *afp_serv,
/* clientNonce */
g_output_stream_write_all (G_OUTPUT_STREAM (comm), clientNonce_buf, 16, NULL, NULL, NULL);
- reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm,
cancellable, error);
g_object_unref (comm);
if (!reply)
@@ -351,7 +373,7 @@ dhx2_login (GVfsAfpServer *afp_serv,
G_N_ELEMENTS (answer_buf), NULL, NULL, NULL);
- reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm,
cancellable, error);
g_object_unref (comm);
if (!reply)
@@ -365,7 +387,7 @@ dhx2_login (GVfsAfpServer *afp_serv,
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
_("AFP server %s declined the submitted password"),
- afp_serv->server_name);
+ priv->info.server_name);
goto error;
}
else
@@ -399,12 +421,14 @@ generic_error:
}
static gboolean
-dhx_login (GVfsAfpServer *afp_serv,
+dhx_login (GVfsAfpServer *server,
const char *username,
const char *password,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
gcry_error_t gcry_err;
gcry_mpi_t prime, base;
gcry_mpi_t ra;
@@ -474,14 +498,14 @@ dhx_login (GVfsAfpServer *afp_serv,
/* Create login command */
comm = g_vfs_afp_command_new (AFP_COMMAND_LOGIN);
- g_vfs_afp_command_put_pascal (comm, afp_version_to_string (afp_serv->version));
+ g_vfs_afp_command_put_pascal (comm, afp_version_to_string (priv->info.version));
g_vfs_afp_command_put_pascal (comm, AFP_UAM_DHX);
g_vfs_afp_command_put_pascal (comm, username);
g_vfs_afp_command_pad_to_even (comm);
g_output_stream_write_all (G_OUTPUT_STREAM(comm), ma_buf, G_N_ELEMENTS (ma_buf),
NULL, NULL, NULL);
- reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm,
cancellable, error);
g_object_unref (comm);
if (!reply)
@@ -571,7 +595,7 @@ dhx_login (GVfsAfpServer *afp_serv,
G_N_ELEMENTS (answer_buf), NULL, NULL, NULL);
- reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm,
cancellable, error);
g_object_unref (comm);
if (!reply)
@@ -585,7 +609,7 @@ dhx_login (GVfsAfpServer *afp_serv,
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
_("AFP server %s declined the submitted password"),
- afp_serv->server_name);
+ priv->info.server_name);
goto error;
}
else
@@ -612,13 +636,15 @@ generic_error:
#endif
static gboolean
-do_login (GVfsAfpServer *afp_serv,
+do_login (GVfsAfpServer *server,
const char *username,
const char *password,
gboolean anonymous,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
/* anonymous login */
if (anonymous)
{
@@ -626,19 +652,19 @@ do_login (GVfsAfpServer *afp_serv,
GVfsAfpReply *reply;
AfpResultCode res_code;
- if (!g_slist_find_custom (afp_serv->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0))
+ if (!g_slist_find_custom (priv->info.uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
_("AFP server %s doesn't support anonymous login"),
- afp_serv->server_name);
+ priv->info.server_name);
return FALSE;
}
comm = g_vfs_afp_command_new (AFP_COMMAND_LOGIN);
- g_vfs_afp_command_put_pascal (comm, afp_version_to_string (afp_serv->version));
+ g_vfs_afp_command_put_pascal (comm, afp_version_to_string (priv->info.version));
g_vfs_afp_command_put_pascal (comm, AFP_UAM_NO_USER);
- reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm,
cancellable, error);
g_object_unref (comm);
if (!reply)
@@ -655,7 +681,7 @@ do_login (GVfsAfpServer *afp_serv,
case AFP_RESULT_BAD_UAM:
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
_("AFP server %s doesn't support anonymous login"),
- afp_serv->server_name);
+ priv->info.server_name);
break;
default:
@@ -673,26 +699,28 @@ do_login (GVfsAfpServer *afp_serv,
#ifdef HAVE_GCRYPT
/* Diffie-Hellman 2 */
- if (g_slist_find_custom (afp_serv->uams, AFP_UAM_DHX2, (GCompareFunc)g_strcmp0))
- return dhx2_login (afp_serv, username, password, cancellable, error);
+ if (g_slist_find_custom (priv->info.uams, AFP_UAM_DHX2, (GCompareFunc)g_strcmp0))
+ return dhx2_login (server, username, password, cancellable, error);
/* Diffie-Hellman */
- if (g_slist_find_custom (afp_serv->uams, AFP_UAM_DHX, (GCompareFunc)g_strcmp0))
- return dhx_login (afp_serv, username, password, cancellable, error);
+ if (g_slist_find_custom (priv->info.uams, AFP_UAM_DHX, (GCompareFunc)g_strcmp0))
+ return dhx_login (server, username, password, cancellable, error);
#endif
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Login to AFP server %s failed (no suitable authentication mechanism found)"),
- afp_serv->server_name);
+ priv->info.server_name);
return FALSE;
}
}
static gboolean
-get_server_info (GVfsAfpServer *afp_serv,
+get_server_info (GVfsAfpServer *server,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
GVfsAfpReply *reply;
guint16 MachineType_offset, AFPVersionCount_offset, UAMCount_offset;
@@ -700,7 +728,7 @@ get_server_info (GVfsAfpServer *afp_serv,
guint8 count;
guint i;
- reply = g_vfs_afp_query_server_info (G_SOCKET_CONNECTABLE (afp_serv->addr),
+ reply = g_vfs_afp_query_server_info (G_SOCKET_CONNECTABLE (priv->addr),
cancellable, error);
if (!reply)
return FALSE;
@@ -711,12 +739,12 @@ get_server_info (GVfsAfpServer *afp_serv,
/* VolumeIconAndMask_offset */
g_vfs_afp_reply_read_uint16 (reply, NULL);
- g_vfs_afp_reply_read_uint16 (reply, &afp_serv->flags);
+ g_vfs_afp_reply_read_uint16 (reply, &priv->info.flags);
- g_vfs_afp_reply_read_pascal (reply, &afp_serv->server_name);
+ g_vfs_afp_reply_read_pascal (reply, &priv->info.server_name);
/* Parse UTF-8 ServerName */
- if (afp_serv->flags & (0x1 << 8)) {
+ if (priv->info.flags & (0x1 << 8)) {
guint16 UTF8ServerName_offset;
GVfsAfpName *utf8_server_name;
@@ -726,13 +754,13 @@ get_server_info (GVfsAfpServer *afp_serv,
g_vfs_afp_reply_seek (reply, UTF8ServerName_offset, G_SEEK_SET);
g_vfs_afp_reply_read_afp_name (reply, FALSE, &utf8_server_name);
- afp_serv->utf8_server_name = g_vfs_afp_name_get_string (utf8_server_name);
+ priv->info.utf8_server_name = g_vfs_afp_name_get_string (utf8_server_name);
g_vfs_afp_name_unref (utf8_server_name);
}
/* Parse MachineType */
g_vfs_afp_reply_seek (reply, MachineType_offset, G_SEEK_SET);
- g_vfs_afp_reply_read_pascal (reply, &afp_serv->machine_type);
+ g_vfs_afp_reply_read_pascal (reply, &priv->info.machine_type);
/* Parse Versions */
g_vfs_afp_reply_seek (reply, AFPVersionCount_offset, G_SEEK_SET);
@@ -744,11 +772,11 @@ get_server_info (GVfsAfpServer *afp_serv,
g_vfs_afp_reply_read_pascal (reply, &version);
afp_version = string_to_afp_version (version);
- if (afp_version > afp_serv->version)
- afp_serv->version = afp_version;
+ if (afp_version > priv->info.version)
+ priv->info.version = afp_version;
}
- if (afp_serv->version == AFP_VERSION_INVALID)
+ if (priv->info.version == AFP_VERSION_INVALID)
{
g_object_unref (reply);
g_set_error (error,
@@ -765,7 +793,7 @@ get_server_info (GVfsAfpServer *afp_serv,
char *uam;
g_vfs_afp_reply_read_pascal (reply, &uam);
- afp_serv->uams = g_slist_prepend (afp_serv->uams, uam);
+ priv->info.uams = g_slist_prepend (priv->info.uams, uam);
}
g_object_unref (reply);
@@ -778,6 +806,8 @@ get_server_parms (GVfsAfpServer *server,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
GVfsAfpCommand *comm;
GVfsAfpReply *reply;
AfpResultCode res_code;
@@ -788,7 +818,7 @@ get_server_parms (GVfsAfpServer *server,
/* pad byte */
g_vfs_afp_command_put_byte (comm, 0);
- reply = g_vfs_afp_connection_send_command_sync (server->conn, comm, cancellable,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm, cancellable,
error);
g_object_unref (comm);
if (!reply)
@@ -805,7 +835,7 @@ get_server_parms (GVfsAfpServer *server,
/* server time */
g_vfs_afp_reply_read_int32 (reply, &server_time);
- server->time_diff = (g_get_real_time () / G_USEC_PER_SEC) - server_time;
+ priv->time_diff = (g_get_real_time () / G_USEC_PER_SEC) - server_time;
g_object_unref (reply);
@@ -817,6 +847,8 @@ get_userinfo (GVfsAfpServer *server,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
GVfsAfpCommand *comm;
guint16 bitmap;
@@ -832,8 +864,8 @@ get_userinfo (GVfsAfpServer *server,
bitmap = AFP_GET_USER_INFO_BITMAP_GET_UID_BIT | AFP_GET_USER_INFO_BITMAP_GET_GID_BIT;
g_vfs_afp_command_put_uint16 (comm, bitmap);
- reply = g_vfs_afp_connection_send_command_sync (server->conn,
- comm, cancellable, error);
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm, cancellable,
+ error);
g_object_unref (comm);
if (!reply)
return FALSE;
@@ -873,9 +905,9 @@ get_userinfo (GVfsAfpServer *server,
/* Bitmap */
g_vfs_afp_reply_read_uint16 (reply, NULL);
/* UID */
- g_vfs_afp_reply_read_uint32 (reply, &server->user_id);
+ g_vfs_afp_reply_read_uint32 (reply, &priv->user_id);
/* GID */
- g_vfs_afp_reply_read_uint32 (reply, &server->group_id);
+ g_vfs_afp_reply_read_uint32 (reply, &priv->group_id);
g_object_unref (reply);
@@ -890,6 +922,8 @@ g_vfs_afp_server_login (GVfsAfpServer *server,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv = server->priv;
+
gboolean res;
char *user, *olduser;
char *password;
@@ -908,7 +942,7 @@ g_vfs_afp_server_login (GVfsAfpServer *server,
if (initial_user)
{
if (g_str_equal (initial_user, "anonymous") &&
- g_slist_find_custom (server->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0))
+ g_slist_find_custom (priv->info.uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0))
{
user = NULL;
password = NULL;
@@ -917,12 +951,12 @@ g_vfs_afp_server_login (GVfsAfpServer *server,
}
else if (g_vfs_keyring_lookup_password (initial_user,
- g_network_address_get_hostname (server->addr),
+ g_network_address_get_hostname (priv->addr),
NULL,
"afp",
NULL,
NULL,
- g_network_address_get_port (server->addr),
+ g_network_address_get_port (priv->addr),
&user,
NULL,
&password) &&
@@ -935,7 +969,7 @@ g_vfs_afp_server_login (GVfsAfpServer *server,
}
/* Use utf8_server_name if it exists */
- server_name = server->utf8_server_name ? server->utf8_server_name : server->server_name;
+ server_name = priv->info.utf8_server_name ? priv->info.utf8_server_name : priv->info.server_name;
while (TRUE)
{
@@ -969,7 +1003,7 @@ g_vfs_afp_server_login (GVfsAfpServer *server,
{
flags |= G_ASK_PASSWORD_NEED_USERNAME;
- if (g_slist_find_custom (server->uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0))
+ if (g_slist_find_custom (priv->info.uams, AFP_UAM_NO_USER, (GCompareFunc)g_strcmp0))
flags |= G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
}
@@ -1002,8 +1036,8 @@ g_vfs_afp_server_login (GVfsAfpServer *server,
try_login:
/* Open connection */
- server->conn = g_vfs_afp_connection_new (G_SOCKET_CONNECTABLE (server->addr));
- res = g_vfs_afp_connection_open_sync (server->conn, cancellable, &err);
+ priv->conn = g_vfs_afp_connection_new (G_SOCKET_CONNECTABLE (priv->addr));
+ res = g_vfs_afp_connection_open_sync (priv->conn, cancellable, &err);
if (!res)
break;
@@ -1011,8 +1045,8 @@ try_login:
cancellable, &err);
if (!res)
{
- g_vfs_afp_connection_close_sync (server->conn, cancellable, NULL);
- g_clear_object (&server->conn);
+ g_vfs_afp_connection_close_sync (priv->conn, cancellable, NULL);
+ g_clear_object (&priv->conn);
if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED))
break;
@@ -1043,12 +1077,12 @@ try_login:
{
/* a prompt was created, so we have to save the password */
g_vfs_keyring_save_password (user,
- g_network_address_get_hostname (server->addr),
+ g_network_address_get_hostname (priv->addr),
NULL,
"afp",
NULL,
NULL,
- g_network_address_get_port (server->addr),
+ g_network_address_get_port (priv->addr),
password,
password_save);
g_free (prompt);
@@ -1085,33 +1119,65 @@ g_vfs_afp_server_logout_sync (GVfsAfpServer *server,
GCancellable *cancellable,
GError **error)
{
+ GVfsAfpServerPrivate *priv;
GVfsAfpCommand *comm;
GVfsAfpReply *reply;
gint32 res_code;
+ gboolean res = FALSE;
+ g_return_val_if_fail (G_VFS_IS_AFP_SERVER (server), FALSE);
+
+ priv = server->priv;
+
comm = g_vfs_afp_command_new (AFP_COMMAND_LOGOUT);
/* pad byte */
g_vfs_afp_command_put_byte (comm, 0);
- reply = g_vfs_afp_connection_send_command_sync (server->conn, comm, cancellable, error);
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm, cancellable, error);
if (!reply) {
- g_vfs_afp_connection_close_sync (server->conn, cancellable, NULL);
- return FALSE;
+ g_vfs_afp_connection_close_sync (priv->conn, cancellable, NULL);
+ goto done;
}
res_code = g_vfs_afp_reply_get_result_code (reply);
g_object_unref (reply);
if (res_code != AFP_RESULT_NO_ERROR) {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to logout from server"));
- g_vfs_afp_connection_close_sync (server->conn, cancellable, NULL);
- return FALSE;
+ g_vfs_afp_connection_close_sync (priv->conn, cancellable, NULL);
+ goto done;
}
- return g_vfs_afp_connection_close_sync (server->conn, cancellable, error);
+ res = g_vfs_afp_connection_close_sync (priv->conn, cancellable, error);
+
+done:
+ g_clear_object (&priv->conn);
+ return res;
}
-
+
+/*
+ * g_vfs_afp_server_get_info:
+ *
+ * @server: a #GVfsAfpServer
+ *
+ * Returns: a #GVfsAfpServerInfo or %NULL if the server is not logged in.
+ */
+const GVfsAfpServerInfo *
+g_vfs_afp_server_get_info (GVfsAfpServer *server)
+{
+ GVfsAfpServerPrivate *priv;
+
+ g_return_val_if_fail (G_VFS_IS_AFP_SERVER (server), FALSE);
+
+ priv = server->priv;
+
+ if (!priv->conn)
+ return NULL;
+
+ return &priv->info;
+}
+
/*
- * g_vfs_server_time_to_local_time:
+ * g_vfs_afp_server_time_to_local_time:
*
* @server: a #GVfsAfpServer
* @server_time: a time value in server time
@@ -1121,8 +1187,10 @@ g_vfs_afp_server_logout_sync (GVfsAfpServer *server,
gint64
g_vfs_afp_server_time_to_local_time (GVfsAfpServer *server,
gint32 server_time)
-{
- return server_time + server->time_diff;
+{
+ g_return_val_if_fail (G_VFS_IS_AFP_SERVER (server), 0);
+
+ return server_time + server->priv->time_diff;
}
@@ -1225,7 +1293,7 @@ g_vfs_afp_server_get_volumes (GVfsAfpServer *server,
simple = g_simple_async_result_new (G_OBJECT (server), callback, user_data,
g_vfs_afp_server_get_volumes);
- g_vfs_afp_connection_send_command (server->conn, comm, NULL, get_volumes_cb,
+ g_vfs_afp_connection_send_command (server->priv->conn, comm, NULL, get_volumes_cb,
cancellable, simple);
}
@@ -1271,7 +1339,7 @@ g_vfs_afp_server_mount_volume_sync (GVfsAfpServer *server,
{
GVfsAfpVolume *volume;
- volume = g_vfs_afp_volume_new (server);
+ volume = g_vfs_afp_volume_new (server, server->priv->conn);
if (!g_vfs_afp_volume_mount_sync (volume, volume_name, cancellable, error))
{
g_object_unref (volume);
@@ -1483,9 +1551,9 @@ g_vfs_afp_server_fill_info (GVfsAfpServer *server,
g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_AFP_UA_PERMISSIONS,
ua_permissions);
- if (uid == server->user_id)
+ if (uid == server->priv->user_id)
set_access_attributes_trusted (info, (permissions >> 6) & 0x7);
- else if (gid == server->group_id)
+ else if (gid == server->priv->group_id)
set_access_attributes (info, (permissions >> 3) & 0x7);
else
set_access_attributes (info, (permissions >> 0) & 0x7);
diff --git a/daemon/gvfsafpserver.h b/daemon/gvfsafpserver.h
index d528850a..f2c22352 100644
--- a/daemon/gvfsafpserver.h
+++ b/daemon/gvfsafpserver.h
@@ -40,6 +40,16 @@ typedef enum
AFP_VERSION_3_3
} AfpVersion;
+typedef struct
+{
+ guint16 flags;
+ char *machine_type;
+ char *server_name;
+ char *utf8_server_name;
+ GSList *uams;
+ AfpVersion version;
+} GVfsAfpServerInfo;
+
#define G_VFS_TYPE_AFP_SERVER (g_vfs_afp_server_get_type ())
#define G_VFS_AFP_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_VFS_TYPE_AFP_SERVER, GVfsAfpServer))
#define G_VFS_AFP_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G_VFS_TYPE_AFP_SERVER, GVfsAfpServerClass))
@@ -48,6 +58,7 @@ typedef enum
#define G_VFS_AFP_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_VFS_TYPE_AFP_SERVER, GVfsAfpServerClass))
typedef struct _GVfsAfpServerClass GVfsAfpServerClass;
+typedef struct _GvfsAfpServerPrivate GVfsAfpServerPrivate;
struct _GVfsAfpServerClass
{
@@ -58,27 +69,14 @@ struct _GVfsAfpServer
{
GObject parent_instance;
- GNetworkAddress *addr;
- GVfsAfpConnection *conn;
-
- guint16 flags;
- char *machine_type;
- char *server_name;
- char *utf8_server_name;
- GSList *uams;
- AfpVersion version;
-
- gint32 time_diff;
-
- guint32 user_id;
- guint32 group_id;
+ GVfsAfpServerPrivate *priv;
};
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,
+gboolean g_vfs_afp_server_login (GVfsAfpServer *server,
const char *initial_user,
GMountSource *mount_source,
char **logged_in_user,
@@ -89,9 +87,12 @@ gboolean g_vfs_afp_server_logout_sync (GVfsAfpServer *server,
GCancellable *cancellable,
GError **error);
-gint64 g_vfs_afp_server_time_to_local_time (GVfsAfpServer *afp_serv,
+gint64 g_vfs_afp_server_time_to_local_time (GVfsAfpServer *server,
gint32 server_time);
+const
+GVfsAfpServerInfo* g_vfs_afp_server_get_info (GVfsAfpServer *server);
+
typedef struct _GVfsAfpVolumeData GVfsAfpVolumeData;
struct _GVfsAfpVolumeData
{
diff --git a/daemon/gvfsafpvolume.c b/daemon/gvfsafpvolume.c
index 4329aaf4..2e5e7c13 100644
--- a/daemon/gvfsafpvolume.c
+++ b/daemon/gvfsafpvolume.c
@@ -33,6 +33,7 @@ G_DEFINE_TYPE (GVfsAfpVolume, g_vfs_afp_volume, G_TYPE_OBJECT);
struct _GVfsAfpVolumePrivate
{
GVfsAfpServer *server;
+ GVfsAfpConnection *conn;
gboolean mounted;
guint16 attributes;
@@ -68,17 +69,19 @@ g_vfs_afp_volume_class_init (GVfsAfpVolumeClass *klass)
}
GVfsAfpVolume *
-g_vfs_afp_volume_new (GVfsAfpServer *server)
+g_vfs_afp_volume_new (GVfsAfpServer *server, GVfsAfpConnection *conn)
{
GVfsAfpVolume *volume;
GVfsAfpVolumePrivate *priv;
g_return_val_if_fail (G_VFS_IS_AFP_SERVER (server), NULL);
+ g_return_val_if_fail (G_VFS_IS_AFP_CONNECTION (conn), NULL);
volume = g_object_new (G_VFS_TYPE_AFP_VOLUME, NULL);
priv = volume->priv;
priv->server = server;
+ priv->conn = conn;
return volume;
}
@@ -111,7 +114,7 @@ g_vfs_afp_volume_mount_sync (GVfsAfpVolume *volume,
/* TODO: password? */
- reply = g_vfs_afp_connection_send_command_sync (priv->server->conn, comm, cancellable,
+ reply = g_vfs_afp_connection_send_command_sync (priv->conn, comm, cancellable,
error);
g_object_unref (comm);
if (!reply)
@@ -140,7 +143,7 @@ generic_error:
/* Translators: first %s is volumename and second servername */
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Couldn't mount AFP volume %s on %s"), volume_name,
- priv->server->server_name);
+ g_vfs_afp_server_get_info(priv->server)->server_name);
return FALSE;
}
@@ -297,7 +300,7 @@ g_vfs_afp_volume_get_parms (GVfsAfpVolume *volume,
g_vfs_afp_volume_get_parms);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL, get_vol_parms_cb,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL, get_vol_parms_cb,
cancellable, simple);
g_object_unref (comm);
}
@@ -481,7 +484,7 @@ g_vfs_afp_volume_open_fork (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback,
user_data, g_vfs_afp_volume_open_fork);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
open_fork_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -593,7 +596,7 @@ g_vfs_afp_volume_close_fork (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback, user_data,
g_vfs_afp_volume_close_fork);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
close_fork_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -729,7 +732,7 @@ g_vfs_afp_volume_delete (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback,
user_data, g_vfs_afp_volume_delete);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
delete_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -883,7 +886,7 @@ create_file_get_filedir_parms_cb (GObject *source_object, GAsyncResult *res, gpo
g_vfs_afp_command_put_pathname (comm, basename);
g_free (basename);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
create_file_cb, cfd->cancellable, simple);
g_object_unref (comm);
}
@@ -1071,7 +1074,7 @@ create_directory_get_filedir_parms_cb (GObject *source_object, GAsyncResult *res
/* Pathname */
g_vfs_afp_command_put_pathname (comm, cdd->basename);
- g_vfs_afp_connection_send_command (volume->priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (volume->priv->conn, comm, NULL,
make_directory_cb, cdd->cancellable, simple);
g_object_unref (comm);
return;
@@ -1281,7 +1284,7 @@ rename_get_filedir_parms_cb (GObject *source_object,
/* NewName */
g_vfs_afp_command_put_pathname (comm, rd->new_name);
- g_vfs_afp_connection_send_command (volume->priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (volume->priv->conn, comm, NULL,
rename_cb, rd->cancellable, simple);
g_object_unref (comm);
}
@@ -1480,7 +1483,7 @@ g_vfs_afp_volume_move_and_rename (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback,
user_data, g_vfs_afp_volume_move_and_rename);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
move_and_rename_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -1640,7 +1643,7 @@ g_vfs_afp_volume_copy_file (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback,
user_data, g_vfs_afp_volume_copy_file);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
copy_file_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -1805,7 +1808,7 @@ g_vfs_afp_volume_map_id (GVfsAfpVolume *volume,
g_simple_async_result_set_op_res_gpointer (simple, map_data,
(GDestroyNotify)map_id_data_free);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
map_id_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -1965,7 +1968,7 @@ g_vfs_afp_volume_get_filedir_parms (GVfsAfpVolume *volume,
g_vfs_afp_volume_get_filedir_parms);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
get_filedir_parms_cb, cancellable,
simple);
g_object_unref (comm);
@@ -2090,7 +2093,7 @@ g_vfs_afp_volume_get_fork_parms (GVfsAfpVolume *volume,
g_vfs_afp_volume_get_fork_parms);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
get_fork_parms_cb, cancellable,
simple);
g_object_unref (comm);
@@ -2218,7 +2221,7 @@ g_vfs_afp_volume_set_fork_size (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback, user_data,
g_vfs_afp_volume_set_fork_size);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
set_fork_parms_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -2364,7 +2367,7 @@ g_vfs_afp_volume_set_unix_privs (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback,
user_data, g_vfs_afp_volume_set_unix_privs);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
set_unix_privs_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -2523,6 +2526,8 @@ g_vfs_afp_volume_enumerate (GVfsAfpVolume *volume,
gpointer user_data)
{
GVfsAfpVolumePrivate *priv;
+
+ const GVfsAfpServerInfo *info;
gint32 max;
GVfsAfpCommand *comm;
@@ -2534,8 +2539,10 @@ g_vfs_afp_volume_enumerate (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback,
user_data, g_vfs_afp_volume_enumerate);
+
+ info = g_vfs_afp_server_get_info (priv->server);
- max = (priv->server->version >= AFP_VERSION_3_1) ? G_MAXINT32 : G_MAXINT16;
+ max = (info->version >= AFP_VERSION_3_1) ? G_MAXINT32 : G_MAXINT16;
/* Can't enumerate any more files */
if (start_index > max)
{
@@ -2544,7 +2551,7 @@ g_vfs_afp_volume_enumerate (GVfsAfpVolume *volume,
return;
}
- if (priv->server->version >= AFP_VERSION_3_1)
+ if (info->version >= AFP_VERSION_3_1)
comm = g_vfs_afp_command_new (AFP_COMMAND_ENUMERATE_EXT2);
else
comm = g_vfs_afp_command_new (AFP_COMMAND_ENUMERATE_EXT);
@@ -2568,7 +2575,7 @@ g_vfs_afp_volume_enumerate (GVfsAfpVolume *volume,
/* StartIndex and MaxReplySize */
- if (priv->server->version >= AFP_VERSION_3_1)
+ if (info->version >= AFP_VERSION_3_1)
{
g_vfs_afp_command_put_int32 (comm, start_index);
g_vfs_afp_command_put_int32 (comm, ENUMERATE_EXT2_MAX_REPLY_SIZE);
@@ -2582,7 +2589,7 @@ g_vfs_afp_volume_enumerate (GVfsAfpVolume *volume,
/* Pathname */
g_vfs_afp_command_put_pathname (comm, directory);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
enumerate_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -2722,7 +2729,7 @@ g_vfs_afp_volume_exchange_files (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback, user_data,
g_vfs_afp_volume_exchange_files);
- g_vfs_afp_connection_send_command (priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (priv->conn, comm, NULL,
close_replace_exchange_files_cb,
cancellable, simple);
g_object_unref (comm);
@@ -2859,7 +2866,7 @@ g_vfs_afp_volume_write_to_fork (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback, user_data,
g_vfs_afp_volume_write_to_fork);
- g_vfs_afp_connection_send_command (volume->priv->server->conn, comm, NULL,
+ g_vfs_afp_connection_send_command (volume->priv->conn, comm, NULL,
write_ext_cb, cancellable, simple);
g_object_unref (comm);
}
@@ -2989,7 +2996,7 @@ g_vfs_afp_volume_read_from_fork (GVfsAfpVolume *volume,
simple = g_simple_async_result_new (G_OBJECT (volume), callback, user_data,
g_vfs_afp_volume_read_from_fork);
- g_vfs_afp_connection_send_command (volume->priv->server->conn, comm, buffer,
+ g_vfs_afp_connection_send_command (volume->priv->conn, comm, buffer,
read_ext_cb, cancellable, simple);
g_object_unref (comm);
}
diff --git a/daemon/gvfsafpvolume.h b/daemon/gvfsafpvolume.h
index 209ad746..86eefa1c 100644
--- a/daemon/gvfsafpvolume.h
+++ b/daemon/gvfsafpvolume.h
@@ -54,7 +54,7 @@ struct _GVfsAfpVolume
GType g_vfs_afp_volume_get_type (void) G_GNUC_CONST;
-GVfsAfpVolume *g_vfs_afp_volume_new (GVfsAfpServer *server);
+GVfsAfpVolume *g_vfs_afp_volume_new (GVfsAfpServer *server, GVfsAfpConnection *conn);
gboolean g_vfs_afp_volume_mount_sync (GVfsAfpVolume *volume,
const char *volume_name,
diff --git a/daemon/gvfsbackendafp.c b/daemon/gvfsbackendafp.c
index 003a6965..030a14c2 100644
--- a/daemon/gvfsbackendafp.c
+++ b/daemon/gvfsbackendafp.c
@@ -2023,7 +2023,8 @@ do_mount (GVfsBackend *backend,
gboolean res;
GError *err = NULL;
-
+
+ const GVfsAfpServerInfo *info;
GMountSpec *afp_mount_spec;
char *server_name;
char *display_name;
@@ -2052,10 +2053,12 @@ do_mount (GVfsBackend *backend,
g_vfs_backend_set_mount_spec (backend, afp_mount_spec);
g_mount_spec_unref (afp_mount_spec);
- if (afp_backend->server->utf8_server_name)
- server_name = afp_backend->server->utf8_server_name;
+ info = g_vfs_afp_server_get_info (afp_backend->server);
+
+ if (info->utf8_server_name)
+ server_name = info->utf8_server_name;
else
- server_name = afp_backend->server->server_name;
+ server_name = info->server_name;
if (afp_backend->user)
/* Translators: first %s is volumename, second username and third servername */
diff --git a/daemon/gvfsbackendafpbrowse.c b/daemon/gvfsbackendafpbrowse.c
index f597cc6e..1f007874 100644
--- a/daemon/gvfsbackendafpbrowse.c
+++ b/daemon/gvfsbackendafpbrowse.c
@@ -417,6 +417,7 @@ do_mount (GVfsBackend *backend,
gboolean res;
GError *err = NULL;
+ const GVfsAfpServerInfo *info;
GMountSpec *afp_mount_spec;
char *server_name;
char *display_name;
@@ -439,10 +440,12 @@ do_mount (GVfsBackend *backend,
g_vfs_backend_set_mount_spec (backend, afp_mount_spec);
g_mount_spec_unref (afp_mount_spec);
- if (afp_backend->server->utf8_server_name)
- server_name = afp_backend->server->utf8_server_name;
+ info = g_vfs_afp_server_get_info (afp_backend->server);
+
+ if (info->utf8_server_name)
+ server_name = info->utf8_server_name;
else
- server_name = afp_backend->server->server_name;
+ server_name = info->server_name;
if (afp_backend->user)
/* Translators: first %s is username and second serververname */