[gvfs] afp: receive and print out server messages



commit 63489ab39435705b2d5ef11201d7a3f30a727169
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Mon Jul 11 21:08:45 2011 +0200

    afp: receive and print out server messages

 daemon/gvfsafpconnection.c |   45 +++++++++++++-----------------
 daemon/gvfsafpconnection.h |   19 +++++++++++++
 daemon/gvfsafpserver.c     |   65 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 103 insertions(+), 26 deletions(-)
---
diff --git a/daemon/gvfsafpconnection.c b/daemon/gvfsafpconnection.c
index b6d230e..ec794ba 100644
--- a/daemon/gvfsafpconnection.c
+++ b/daemon/gvfsafpconnection.c
@@ -514,6 +514,14 @@ g_vfs_afp_command_get_data (GVfsAfpCommand *comm)
 /*
  * GVfsAfpConnection
  */
+
+enum {
+  ATTENTION,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = {0,};
+
 G_DEFINE_TYPE (GVfsAfpConnection, g_vfs_afp_connection, G_TYPE_OBJECT);
 
 typedef struct {
@@ -635,35 +643,12 @@ dispatch_reply (GVfsAfpConnection *afp_connection)
   }
 
   else if (dsi_header->command == DSI_ATTENTION)
-  {
-    enum
-    {
-      AFP_ATTENTION_CODE_MESSAGE_AVAILABLE     = 0x2,
-      AFP_ATTENTION_CODE_IMMEDIATE_SHUTDOWN    = 0x4,
-      AFP_ATTENTION_CODE_SHUTDOWN_NO_MESSAGE   = 0x8,
-      AFP_ATTENTION_CODE_DISCONNECT_NO_MESSAGE = 0x9,
-      AFP_ATTENTION_CODE_SHUTDOWN_MESSAGE      = 0xA,
-      AFP_ATTENTION_CODE_DISCONNECT_MESSAGE    = 0xB
-    };
-
-    enum
-    {
-      AFP_ATTENTION_MASK_DONT_RECONNECT_BIT = 0x1,
-      AFP_ATTENTION_MASK_SERVER_MESSAGE_BIT = 0x2,
-      AFP_ATTENTION_MASK_SERVER_CRASH_BIT   = 0x4,
-      AFP_ATTENTION_MASK_SHUTDOWN_BIT       = 0x8
-    };
-    
+  { 
     guint8 attention_code;
 
     attention_code = priv->data[0] >> 4;
 
-    if (attention_code & AFP_ATTENTION_MASK_SERVER_CRASH_BIT)
-      g_debug ("Server Crash!!!\n");
-
-    else if (attention_code & AFP_ATTENTION_MASK_SHUTDOWN_BIT)
-      g_debug ("Server is shutting down!\n");
-    
+    g_signal_emit (afp_connection, signals[ATTENTION], 0, attention_code);
     g_free (priv->data);
   }
   
@@ -936,7 +921,8 @@ g_vfs_afp_connection_queue_command (GVfsAfpConnection *afp_connection,
   request_data->tickle = FALSE;
   request_data->command = g_object_ref (command);
   request_data->reply_cb = reply_cb;
-  request_data->cancellable = g_object_ref (cancellable);
+  if (cancellable)
+    request_data->cancellable = g_object_ref (cancellable);
   request_data->user_data = user_data;
   request_data->conn = afp_connection;
 
@@ -1297,5 +1283,12 @@ g_vfs_afp_connection_class_init (GVfsAfpConnectionClass *klass)
   g_type_class_add_private (klass, sizeof (GVfsAfpConnectionPrivate));
 
   object_class->finalize = g_vfs_afp_connection_finalize;
+
+  signals[ATTENTION] =
+    g_signal_new ("attention",
+                  G_TYPE_FROM_CLASS (object_class),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+                  0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
+                  G_TYPE_NONE, 1, G_TYPE_UINT);
 }
 
diff --git a/daemon/gvfsafpconnection.h b/daemon/gvfsafpconnection.h
index f1bcda5..4b8d40d 100644
--- a/daemon/gvfsafpconnection.h
+++ b/daemon/gvfsafpconnection.h
@@ -125,6 +125,24 @@ enum
   AFP_VOLUME_BITMAP_BLOCK_SIZE_BIT      = 0x800  
 };
 
+enum
+{
+  AFP_ATTENTION_CODE_MESSAGE_AVAILABLE     = 0x2,
+  AFP_ATTENTION_CODE_IMMEDIATE_SHUTDOWN    = 0x4,
+  AFP_ATTENTION_CODE_SHUTDOWN_NO_MESSAGE   = 0x8,
+  AFP_ATTENTION_CODE_DISCONNECT_NO_MESSAGE = 0x9,
+  AFP_ATTENTION_CODE_SHUTDOWN_MESSAGE      = 0xA,
+  AFP_ATTENTION_CODE_DISCONNECT_MESSAGE    = 0xB
+};
+
+enum
+{
+  AFP_ATTENTION_MASK_DONT_RECONNECT_BIT = 0x1,
+  AFP_ATTENTION_MASK_SERVER_MESSAGE_BIT = 0x2,
+  AFP_ATTENTION_MASK_SERVER_CRASH_BIT   = 0x4,
+  AFP_ATTENTION_MASK_SHUTDOWN_BIT       = 0x8
+};
+
 typedef enum
 {
   AFP_COMMAND_CLOSE_FORK         = 4,
@@ -142,6 +160,7 @@ typedef enum
   AFP_COMMAND_RENAME             = 28,
   AFP_COMMAND_WRITE              = 33,
   AFP_COMMAND_GET_FILE_DIR_PARMS = 34,
+  AFP_COMMAND_GET_SRVR_MSG       = 35,
   AFP_COMMAND_EXCHANGE_FILES     = 42,
   AFP_COMMAND_READ_EXT           = 60,
   AFP_COMMAND_WRITE_EXT          = 61,
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c
index 1cd8745..0b96b06 100644
--- a/daemon/gvfsafpserver.c
+++ b/daemon/gvfsafpserver.c
@@ -40,6 +40,68 @@ G_DEFINE_TYPE (GVfsAfpServer, g_vfs_afp_server, G_TYPE_OBJECT);
 #define AFP_UAM_DHX       "DHCAST128"
 #define AFP_UAM_DHX2      "DHX2"
 
+static void
+get_srvr_msg_cb (GVfsAfpConnection *conn, GVfsAfpReply *reply, GError *error,
+                 gpointer user_data)
+{
+  gint16 message_bitmap;
+  
+  if (!reply)
+    return;
+
+  /* MessageType */
+  g_vfs_afp_reply_read_int16 (reply, NULL);
+  /* MessageBitmap */
+  g_vfs_afp_reply_read_int16 (reply, &message_bitmap);
+
+  if (message_bitmap == 0x1)
+  {
+    char *str;
+
+    g_vfs_afp_reply_read_pascal (reply, &str);
+
+    g_debug ("Server message: %s\n", str);
+    g_free (str);
+  }
+  else if (message_bitmap == 0x2)
+  {
+    GVfsAfpName *afp_name;
+    char *str;
+    
+    g_vfs_afp_reply_read_afp_name (reply, TRUE, &afp_name);
+    str = g_vfs_afp_name_get_string (afp_name);
+    g_vfs_afp_name_unref (afp_name);
+
+    g_debug ("Server message: %s\n", str);
+    g_free (str);
+  }
+
+  g_object_unref (reply);
+}
+
+static void
+attention_cb (GVfsAfpConnection *conn, guint attention_code, gpointer user_data)
+{
+  GVfsAfpServer *afp_serv = G_VFS_AFP_SERVER (user_data);
+
+  if (attention_code & AFP_ATTENTION_MASK_SERVER_MESSAGE_BIT)
+  {
+    GVfsAfpCommand *comm;
+
+    comm = g_vfs_afp_command_new (AFP_COMMAND_GET_SRVR_MSG);
+    /* pad byte */
+    g_vfs_afp_command_put_byte (comm, 0);
+    /* MessageType */
+    g_vfs_afp_command_put_int16 (comm, 1);
+    /* MessageBitmap */
+    g_vfs_afp_command_put_int16 (comm, 1);
+
+    g_vfs_afp_connection_queue_command (afp_serv->conn, comm, get_srvr_msg_cb,
+                                        NULL, afp_serv);
+    g_object_unref (comm);
+  }
+}
+
 static const char *
 afp_version_to_string (AfpVersion afp_version)
 {
@@ -926,6 +988,9 @@ g_vfs_afp_server_new (GNetworkAddress *addr)
   afp_serv->addr = addr;
   afp_serv->conn = g_vfs_afp_connection_new (G_SOCKET_CONNECTABLE (addr));
 
+  g_signal_connect (afp_serv->conn, "attention", G_CALLBACK (attention_cb),
+                    afp_serv);
+  
   return afp_serv;
 }
 



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