Chnaged "disconnect" client operation to deliver the reason
authorPekka Riikonen <priikone@silcnet.org>
Sat, 22 Jun 2002 15:14:16 +0000 (15:14 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 22 Jun 2002 15:14:16 +0000 (15:14 +0000)
and optional message of the disconnection.  Print the reason
now in Irssi SILC client instead of in library.

CHANGES
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/client_ops.h
lib/silcclient/client.c
lib/silcclient/client_ops_example.c
lib/silcclient/command.c
lib/silcclient/silcclient.h

diff --git a/CHANGES b/CHANGES
index 46f6f97cce830685b8ad568ef1a06fbeed1fec55..0c3c23308365aa9ef2876879104898a5eaac4750 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,10 @@ Sat Jun 22 17:06:58 EEST 2002 Pekka Riikonen <priikone@silcnet.org>
          fixed some CMODE_CHANGE notify handling in server and router.
          Affected file is silcd/packet_receive.c.
 
+       * Changed "disconnect" client operation to include the
+         reason of the disconnection and optional disconnection
+         message.  Affected file lib/silcclient/silcclient.h.
+
 Sat Jun 22 12:49:21 EEST 2002 Pekka Riikonen <priikone@silcnet.org>
 
        * All CMODE_CHANGE and CUMODE_CHANGE notifys are now sent back
index 8b75868cc764276227ba451c3b0232bfa8318987..d92b4eb06362cfa926a59b9e857d9e38840e8117 100644 (file)
@@ -875,7 +875,8 @@ void silc_connect(SilcClient client, SilcClientConnection conn,
 
 /* Called to indicate that connection was disconnected to the server. */
 
-void silc_disconnect(SilcClient client, SilcClientConnection conn)
+void silc_disconnect(SilcClient client, SilcClientConnection conn,
+                    SilcStatus status, const char *message)
 {
   SILC_SERVER_REC *server = conn->context;
 
@@ -892,6 +893,12 @@ void silc_disconnect(SilcClient client, SilcClientConnection conn)
     silc_change_nick(server, silc_client->username);
   }
 
+  if (message)
+    silc_say(client, conn, SILC_CLIENT_MESSAGE_AUDIT,
+            "Server closed connection: %s (%d) %s",
+            silc_get_status_message(status), status,
+            message ? message : "");
+
   server->conn->context = NULL;
   server->conn = NULL;
   server->connection_lost = TRUE;
index 6a7eaef7d82ddff2a0d123615e8732e7c872bf60..9fbf84bcaff5bcb1397676ccd1f2fbfa933df88b 100644 (file)
@@ -45,7 +45,8 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
                        SilcCommand command, SilcStatus status, ...);
 void silc_connect(SilcClient client, SilcClientConnection conn,
                  SilcClientConnectionStatus status);
-void silc_disconnect(SilcClient client, SilcClientConnection conn);
+void silc_disconnect(SilcClient client, SilcClientConnection conn,
+                    SilcStatus status, const char *message);
 void silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
                         SilcAskPassphrase completion, void *context);
 void silc_verify_public_key(SilcClient client, SilcClientConnection conn,
index 0e3d8387f3cd5c6a40602146a1b99fdc40588ea9..b459ee8947344bafefc21fdbc28e10536eefd6d3 100644 (file)
@@ -864,14 +864,14 @@ SILC_TASK_CALLBACK_GLOBAL(silc_client_packet_process)
         close the connection */
       if (SILC_IS_DISCONNECTING(sock)) {
        if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
-         client->internal->ops->disconnect(client, conn);
+         client->internal->ops->disconnect(client, conn, 0, NULL);
        silc_client_close_connection_real(client, sock, conn);
        return;
       }
       
       SILC_LOG_DEBUG(("EOF from connection %d", sock->sock));
       if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
-       client->internal->ops->disconnect(client, conn);
+       client->internal->ops->disconnect(client, conn, 0, NULL);
       silc_client_close_connection_real(client, sock, conn);
       return;
     }
@@ -1476,17 +1476,12 @@ void silc_client_close_connection(SilcClient client,
 SILC_TASK_CALLBACK(silc_client_disconnected_by_server_later)
 {
   SilcClient client = (SilcClient)context;
-  SilcClientConnection conn;
   SilcSocketConnection sock;
 
   SILC_CLIENT_GET_SOCK(client, fd, sock);
   if (sock == NULL)
     return;
 
-  conn = (SilcClientConnection)sock->user_data;
-  if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
-    client->internal->ops->disconnect(client, conn);
-
   silc_client_close_connection_real(client, sock, sock->user_data);
 }
 
@@ -1498,6 +1493,7 @@ void silc_client_disconnected_by_server(SilcClient client,
                                        SilcSocketConnection sock,
                                        SilcBuffer packet)
 {
+  SilcClientConnection conn;
   SilcStatus status;
   char *message = NULL;
 
@@ -1512,11 +1508,10 @@ void silc_client_disconnected_by_server(SilcClient client,
       silc_utf8_valid(packet->data + 1, packet->len - 1))
     message = silc_memdup(packet->data + 1, packet->len - 1);
 
-  client->internal->ops->say(client, sock->user_data, 
-                            SILC_CLIENT_MESSAGE_AUDIT, 
-                            "Server closed connection: %s (%d) %s",
-                            silc_get_status_message(status), status,
-                            message ? message : "");
+  conn = (SilcClientConnection)sock->user_data;
+  if (sock == conn->sock && sock->type != SILC_SOCKET_TYPE_CLIENT)
+    client->internal->ops->disconnect(client, conn, status, message);
+
   silc_free(message);
 
   SILC_SET_DISCONNECTED(sock);
index d7d922351a335562003f7d043bbfdeb201bae07c..32debf66de2333e99cb8bf4050d73add3690725b 100644 (file)
@@ -124,10 +124,14 @@ silc_connect(SilcClient client, SilcClientConnection conn,
 }
 
 
-/* Called to indicate that connection was disconnected to the server. */
+/* Called to indicate that connection was disconnected to the server.
+   The `status' may tell the reason of the disconnection, and if the
+   `message' is non-NULL it may include the disconnection message
+   received from server. */
 
 static void
-silc_disconnect(SilcClient client, SilcClientConnection conn)
+silc_disconnect(SilcClient client, SilcClientConnection conn,
+               SilcStatus status, const char *message)
 {
 
 }
index 07fb54ce17dd2468c4e4e86040b4eb79f641dfb2..6b1986917c2f13c475d24456aaed1c5a7dc8ff63 100644 (file)
@@ -651,7 +651,7 @@ SILC_TASK_CALLBACK(silc_client_command_quit_cb)
   QuitInternal q = (QuitInternal)context;
 
   /* Close connection */
-  q->client->internal->ops->disconnect(q->client, q->conn);
+  q->client->internal->ops->disconnect(q->client, q->conn, 0, NULL);
   silc_client_close_connection(q->client, q->conn->sock->user_data);
 
   silc_free(q);
index 71dae8c1927e0031b0f7d6efa4fc7d84a90f1628..0640001e618c10280a441c91aec803693a843efd 100644 (file)
@@ -376,8 +376,12 @@ typedef struct {
   void (*connect)(SilcClient client, SilcClientConnection conn,
                  SilcClientConnectionStatus status);
 
-  /* Called to indicate that connection was disconnected to the server. */
-  void (*disconnect)(SilcClient client, SilcClientConnection conn);
+  /* Called to indicate that connection was disconnected to the server.
+     The `status' may tell the reason of the disconnection, and if the
+     `message' is non-NULL it may include the disconnection message
+     received from server. */
+  void (*disconnect)(SilcClient client, SilcClientConnection conn,
+                    SilcStatus status, const char *message);
 
   /* Find authentication method and authentication data by hostname and
      port. The hostname may be IP address as well. When the authentication