From 15b445f8a277f5884e0b8d2f920b8687e71fc5bc Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 22 Jun 2002 15:14:16 +0000 Subject: [PATCH] Chnaged "disconnect" client operation to deliver the reason and optional message of the disconnection. Print the reason now in Irssi SILC client instead of in library. --- CHANGES | 4 ++++ apps/irssi/src/silc/core/client_ops.c | 9 ++++++++- apps/irssi/src/silc/core/client_ops.h | 3 ++- lib/silcclient/client.c | 19 +++++++------------ lib/silcclient/client_ops_example.c | 8 ++++++-- lib/silcclient/command.c | 2 +- lib/silcclient/silcclient.h | 8 ++++++-- 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 46f6f97c..0c3c2330 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,10 @@ Sat Jun 22 17:06:58 EEST 2002 Pekka Riikonen 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 * All CMODE_CHANGE and CUMODE_CHANGE notifys are now sent back diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 8b75868c..d92b4eb0 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -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; diff --git a/apps/irssi/src/silc/core/client_ops.h b/apps/irssi/src/silc/core/client_ops.h index 6a7eaef7..9fbf84bc 100644 --- a/apps/irssi/src/silc/core/client_ops.h +++ b/apps/irssi/src/silc/core/client_ops.h @@ -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, diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 0e3d8387..b459ee89 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -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); diff --git a/lib/silcclient/client_ops_example.c b/lib/silcclient/client_ops_example.c index d7d92235..32debf66 100644 --- a/lib/silcclient/client_ops_example.c +++ b/lib/silcclient/client_ops_example.c @@ -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) { } diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 07fb54ce..6b198691 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -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); diff --git a/lib/silcclient/silcclient.h b/lib/silcclient/silcclient.h index 71dae8c1..0640001e 100644 --- a/lib/silcclient/silcclient.h +++ b/lib/silcclient/silcclient.h @@ -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 -- 2.24.0