[gvfs] Revert "afp: reuse g_vfs_afp_connection_send_command in the sync version"



commit 7ab124383c9f7373d42b020f419a9c9561ea22ff
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Fri Aug 26 12:01:09 2011 +0200

    Revert "afp: reuse g_vfs_afp_connection_send_command in the sync version"
    
    This reverts commit ecc1730d3bfdc11fa07f15893267a7ea054328f1.

 daemon/gvfsafpconnection.c |  127 ++++++++++++++++++++------------------------
 daemon/gvfsafpconnection.h |   14 +++--
 daemon/gvfsafpserver.c     |   50 +++++++++++++----
 daemon/gvfsbackendafp.c    |   32 ++++++++---
 4 files changed, 128 insertions(+), 95 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.c b/daemon/gvfsafpconnection.c
index 96cea8e..0f092cf 100644
--- a/daemon/gvfsafpconnection.c
+++ b/daemon/gvfsafpconnection.c
@@ -1275,76 +1275,6 @@ g_vfs_afp_connection_send_command_finish (GVfsAfpConnection *afp_connection,
   return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
 }
 
-typedef struct {
-
-  /* For sync calls */
-  GMutex *mutex;
-  GCond *cond;
-
-  /* results: */
-  GAsyncResult *result;
-} SyncData;
-
-static void
-init_sync_data (SyncData *data)
-{
-  data->mutex = g_mutex_new ();
-  data->cond = g_cond_new ();
-}
-
-static void
-clear_sync_data (SyncData *data)
-{
-  g_mutex_free (data->mutex);
-  g_cond_free (data->cond);
-  g_object_unref (data->result);
-}
-
-static void
-sync_data_wait (SyncData *data)
-{
-  g_mutex_lock (data->mutex);
-  g_cond_wait (data->cond, data->mutex);
-  g_mutex_unlock (data->mutex);
-}
-
-static void
-reply_sync  (GObject *source_object,
-             GAsyncResult *res,
-             gpointer user_data)
-{
-  SyncData *data;
-
-  data = (SyncData *) user_data;
-
-  data->result = g_object_ref (res);
-
-  /* Wake up sync call thread */
-  g_mutex_lock (data->mutex);
-  g_cond_signal (data->cond);
-  g_mutex_unlock (data->mutex);
-}
-
-GVfsAfpReply *
-g_vfs_afp_connection_send_command_sync (GVfsAfpConnection *afp_connection,
-                                        GVfsAfpCommand    *command,
-                                        GCancellable      *cancellable,
-                                        GError            **error)
-{
-  SyncData data;
-  GVfsAfpReply *reply;
-
-  init_sync_data (&data);
-  g_vfs_afp_connection_send_command (afp_connection, command, NULL, reply_sync,
-                                     cancellable, &data);
-  sync_data_wait (&data);
-
-  reply = g_vfs_afp_connection_send_command_finish (afp_connection, data.result,
-                                                    error);
-  clear_sync_data (&data);
-  return reply;
-}
-
 static gboolean
 read_reply_sync (GInputStream      *input,
                  DSIHeader         *dsi_header,
@@ -1400,6 +1330,25 @@ read_reply_sync (GInputStream      *input,
   return TRUE;
 }
 
+GVfsAfpReply *
+g_vfs_afp_connection_read_reply_sync (GVfsAfpConnection *afp_connection,
+                                      GCancellable *cancellable,
+                                      GError **error)
+{
+  GVfsAfpConnectionPrivate *priv = afp_connection->priv;
+  
+  gboolean res;
+  char *data;
+  DSIHeader dsi_header;
+
+  res = read_reply_sync (g_io_stream_get_input_stream (priv->conn), &dsi_header,
+                         &data, cancellable, error);
+  if (!res)
+    return NULL;
+
+  return g_vfs_afp_reply_new (dsi_header.errorCode, data, dsi_header.totalDataLength, TRUE);
+}
+
 static gboolean
 send_request_sync (GOutputStream     *output,
                    DsiCommand        command,
@@ -1440,6 +1389,44 @@ send_request_sync (GOutputStream     *output,
 }
 
 gboolean
+g_vfs_afp_connection_send_command_sync (GVfsAfpConnection *afp_connection,
+                                        GVfsAfpCommand    *afp_command,
+                                        GCancellable      *cancellable,
+                                        GError            **error)
+{
+  GVfsAfpConnectionPrivate *priv = afp_connection->priv;
+  
+  DsiCommand dsi_command;
+  guint16 req_id;
+  guint32 writeOffset;
+
+  /* set dsi_command */
+  switch (afp_command->type)
+  {
+    case AFP_COMMAND_WRITE:
+      writeOffset = 8;
+      dsi_command = DSI_WRITE;
+      break;
+    case AFP_COMMAND_WRITE_EXT:
+      writeOffset = 20;
+      dsi_command = DSI_WRITE;
+      break;
+
+    default:
+      writeOffset = 0;
+      dsi_command = DSI_COMMAND;
+      break;
+  }
+
+  req_id = get_request_id (afp_connection);
+  return send_request_sync (g_io_stream_get_output_stream (priv->conn),
+                            dsi_command, req_id, writeOffset,
+                            g_vfs_afp_command_get_size (afp_command),
+                            g_vfs_afp_command_get_data (afp_command),
+                            cancellable, error);
+}
+
+gboolean
 g_vfs_afp_connection_close (GVfsAfpConnection *afp_connection,
                             GCancellable      *cancellable,
                             GError            **error)
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index d815b31..90ce765 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -400,6 +400,15 @@ gboolean           g_vfs_afp_connection_close             (GVfsAfpConnection *af
                                                            GCancellable      *cancellable,
                                                            GError            **error);
 
+gboolean           g_vfs_afp_connection_send_command_sync (GVfsAfpConnection *afp_connection,
+                                                           GVfsAfpCommand    *afp_command,
+                                                           GCancellable      *cancellable,
+                                                           GError            **error);
+
+GVfsAfpReply*      g_vfs_afp_connection_read_reply_sync   (GVfsAfpConnection *afp_connection,
+                                                           GCancellable *cancellable,
+                                                           GError **error);
+
 GVfsAfpReply*      g_vfs_afp_connection_send_command_finish (GVfsAfpConnection *afp_connnection,
                                                              GAsyncResult      *res,
                                                              GError           **error);
@@ -410,11 +419,6 @@ void               g_vfs_afp_connection_send_command     (GVfsAfpConnection   *a
                                                           GAsyncReadyCallback  callback,
                                                           GCancellable        *cancellable,                                                           
                                                           gpointer             user_data);
-
-GVfsAfpReply *     g_vfs_afp_connection_send_command_sync (GVfsAfpConnection *afp_connection,
-                                                           GVfsAfpCommand    *command,
-                                                           GCancellable      *cancellable,
-                                                           GError            **error);
 G_END_DECLS
 
 #endif /* _GVFSAFPCONNECTION_H_ */
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c
index 2462281..ce0d5b7 100644
--- a/daemon/gvfsafpserver.c
+++ b/daemon/gvfsafpserver.c
@@ -208,9 +208,13 @@ dhx2_login (GVfsAfpServer *afp_serv,
   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,
-                                                  cancellable, error);
+  res = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+                                                cancellable, error);
   g_object_unref (comm);
+  if (!res)
+    goto error;
+
+  reply = g_vfs_afp_connection_read_reply_sync (afp_serv->conn, cancellable, error);
   if (!reply)
     goto error;
 
@@ -312,9 +316,14 @@ 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,
-                                                  cancellable, error);
+  res = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+                                                cancellable, error);
   g_object_unref (comm);
+  if (!res)
+    goto error;
+
+  
+  reply = g_vfs_afp_connection_read_reply_sync (afp_serv->conn, cancellable, error);
   if (!reply)
     goto error;
 
@@ -378,9 +387,13 @@ 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,
-                                                  cancellable, error);
+  res = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+                                                cancellable, error);
   g_object_unref (comm);
+  if (!res)
+    goto error;
+  
+  reply = g_vfs_afp_connection_read_reply_sync (afp_serv->conn, cancellable, error);
   if (!reply)
     goto error;
 
@@ -509,9 +522,13 @@ dhx_login (GVfsAfpServer *afp_serv,
   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,
-                                                  cancellable, error);
+  res = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+                                                cancellable, error);
   g_object_unref (comm);
+  if (!res)
+    goto done;
+
+  reply = g_vfs_afp_connection_read_reply_sync (afp_serv->conn, cancellable, error);
   if (!reply)
     goto error;
 
@@ -599,9 +616,13 @@ 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,
-                                                  cancellable, error);
+  res = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+                                                cancellable, error);
   g_object_unref (comm);
+  if (!res)
+    goto done;
+
+  reply = g_vfs_afp_connection_read_reply_sync (afp_serv->conn, cancellable, error);
   if (!reply)
     goto error;
 
@@ -652,6 +673,7 @@ do_login (GVfsAfpServer *afp_serv,
   if (anonymous)
   {
     GVfsAfpCommand *comm;
+    gboolean res;
     GVfsAfpReply *reply;
     AfpResultCode res_code;
     
@@ -667,9 +689,13 @@ do_login (GVfsAfpServer *afp_serv,
 
     g_vfs_afp_command_put_pascal (comm, afp_version_to_string (afp_serv->version));
     g_vfs_afp_command_put_pascal (comm, AFP_UAM_NO_USER);
-    reply = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
-                                                    cancellable, error);
+    res = g_vfs_afp_connection_send_command_sync (afp_serv->conn, comm,
+                                                  cancellable, error);
     g_object_unref (comm);
+    if (!res)
+      return FALSE;
+
+    reply = g_vfs_afp_connection_read_reply_sync (afp_serv->conn, cancellable, error);
     if (!reply)
       return FALSE;
 
diff --git a/daemon/gvfsbackendafp.c b/daemon/gvfsbackendafp.c
index 32c1dc7..5355216 100644
--- a/daemon/gvfsbackendafp.c
+++ b/daemon/gvfsbackendafp.c
@@ -4049,6 +4049,7 @@ get_userinfo (GVfsBackendAfp *afp_backend,
 {
   GVfsAfpCommand *comm;
   guint16 bitmap;
+  gboolean res;
 
   GVfsAfpReply *reply;
   AfpResultCode res_code;
@@ -4062,9 +4063,14 @@ get_userinfo (GVfsBackendAfp *afp_backend,
   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 (afp_backend->server->conn,
-                                                  comm, cancellable, error);
+  res = g_vfs_afp_connection_send_command_sync (afp_backend->server->conn,
+                                                comm, cancellable, error);
   g_object_unref (comm);
+  if (!res)
+    return FALSE;
+
+  reply = g_vfs_afp_connection_read_reply_sync (afp_backend->server->conn,
+                                                cancellable, error);
   if (!reply)
     return FALSE;
 
@@ -4154,10 +4160,15 @@ do_mount (GVfsBackend *backend,
   /* pad byte */
   g_vfs_afp_command_put_byte (comm, 0);
 
-  reply = g_vfs_afp_connection_send_command_sync (afp_backend->server->conn,
-                                                  comm, G_VFS_JOB (job)->cancellable,
-                                                  &err);
+  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;
 
@@ -4191,10 +4202,15 @@ do_mount (GVfsBackend *backend,
 
   /* TODO: password? */
 
-  reply = g_vfs_afp_connection_send_command_sync (afp_backend->server->conn,
-                                                  comm, G_VFS_JOB (job)->cancellable,
-                                                  &err);
+  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;
 



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