From 9a7e0adece982a24090b9574a05f01394bf264b6 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 25 Oct 2001 20:12:41 +0000 Subject: [PATCH] updates. --- CHANGES | 19 ++++++ apps/irssi/src/silc/core/client_ops.c | 4 -- apps/irssi/src/silc/core/silc-channels.c | 40 +++++++---- apps/irssi/src/silc/core/silc-servers.c | 84 +++++++++++++----------- lib/silcclient/client_notify.c | 13 ++++ lib/silcclient/command_reply.c | 4 +- lib/silcclient/silcapi.h | 3 +- 7 files changed, 111 insertions(+), 56 deletions(-) diff --git a/CHANGES b/CHANGES index f7dbcb28..5379d3f6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,22 @@ +Thu Oct 25 22:44:06 EDT 2001 Pekka Riikonen + + * Assure that silc_client_notify_by_server_resolve does not + resolve the client information multiple times. If it cannot + be found by the first it cannot be found at all. Affected + file lib/silcclient/client_notify.c. + + * Fixed WHOWAS command reply calling. Affected file + lib/silcclient/command_reply.c. + + * Removed all references to silc_idlist_get_client from the + Irssi SILC client since that call is internal call used by + the library. The Irssi SILC client will use now client + retrieval functions found in silcapi.h. + + * Fixed a bug in resolving nickname info before sending + private message. It used freed memory. Affected file + irssi/src/silc/core/silc-servers.c. + Thu Oct 25 19:04:49 EDT 2001 Pekka Riikonen * Assure my_channels statistics cannot go negative in server. diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 9923412e..59ecd372 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -413,8 +413,6 @@ silc_command_reply(SilcClient client, SilcClientConnection conn, if (tmp) silc_say_error("%s: %s", tmp, silc_client_command_status_message(status)); - else - silc_say_error("%s", silc_client_command_status_message(status)); break; } @@ -503,8 +501,6 @@ silc_command_reply(SilcClient client, SilcClientConnection conn, if (tmp) silc_say_error("%s: %s", tmp, silc_client_command_status_message(status)); - else - silc_say_error("%s", silc_client_command_status_message(status)); break; } diff --git a/apps/irssi/src/silc/core/silc-channels.c b/apps/irssi/src/silc/core/silc-channels.c index 3bdc9cc7..499b0cfe 100644 --- a/apps/irssi/src/silc/core/silc-channels.c +++ b/apps/irssi/src/silc/core/silc-channels.c @@ -815,18 +815,35 @@ static void keyagr_completion(SilcClient client, typedef struct { SILC_SERVER_REC *server; char *data; + char *nick; WI_ITEM_REC *item; } *KeyGetClients; /* Callback to be called after client information is resolved from the server. */ -SILC_CLIENT_CMD_FUNC(key_get_clients) +static void silc_client_command_key_get_clients(SilcClient client, + SilcClientConnection conn, + SilcClientEntry *clients, + uint32 clients_count, + void *context) { KeyGetClients internal = (KeyGetClients)context; + + if (!clients) { + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s", + internal->nick); + silc_free(internal->data); + silc_free(internal->nick); + silc_free(internal); + return; + } + signal_emit("command key", 3, internal->data, internal->server, internal->item); + silc_free(internal->data); + silc_free(internal->nick); silc_free(internal); } @@ -834,7 +851,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server, WI_ITEM_REC *item) { SilcClientConnection conn; - SilcClientEntry client_entry = NULL; + SilcClientEntry *entrys, client_entry = NULL; + uint32 entry_count; SilcChannelEntry channel_entry = NULL; char *nickname = NULL, *tmp; int command = 0, port = 0, type = 0; @@ -878,22 +896,20 @@ static void command_key(const char *data, SILC_SERVER_REC *server, } /* Find client entry */ - client_entry = silc_idlist_get_client(silc_client, conn, nickname, - argv[2], TRUE); - if (!client_entry) { + entrys = silc_client_get_clients_local(silc_client, conn, nickname, + argv[2], &entry_count); + if (!entrys) { KeyGetClients inter = silc_calloc(1, sizeof(*inter)); inter->server = server; inter->data = strdup(data); + inter->nick = strdup(nickname); inter->item = item; - - /* Client entry not found, it was requested thus mark this to be - pending command. */ - silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, - NULL, silc_client_command_key_get_clients, - inter); + silc_client_get_clients(silc_client, conn, nickname, argv[2], + silc_client_command_key_get_clients, inter); goto out; } + client_entry = entrys[0]; + silc_free(entrys); } } diff --git a/apps/irssi/src/silc/core/silc-servers.c b/apps/irssi/src/silc/core/silc-servers.c index 6fccc11b..e20a2d4b 100644 --- a/apps/irssi/src/silc/core/silc-servers.c +++ b/apps/irssi/src/silc/core/silc-servers.c @@ -129,8 +129,6 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg) /* Find client entry */ clients = silc_client_get_clients_local(silc_client, server->conn, nickname, nick, &clients_count); - silc_free(nickname); - if (!clients) { rec = g_new0(PRIVMSG_REC, 1); rec->nick = g_strdup(nick); @@ -140,10 +138,12 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg) /* Could not find client with that nick, resolve it from server. */ silc_client_get_clients(silc_client, server->conn, nickname, NULL, silc_send_msg_clients, rec); + silc_free(nickname); return; } /* Send the private message directly */ + silc_free(nickname); silc_client_send_private_message(silc_client, server->conn, clients[0], 0, msg, strlen(msg), TRUE); } @@ -485,15 +485,32 @@ static void silc_client_file_monitor(SilcClient client, typedef struct { SILC_SERVER_REC *server; char *data; + char *nick; WI_ITEM_REC *item; } *FileGetClients; -SILC_CLIENT_CMD_FUNC(file_get_clients) +static void silc_client_command_file_get_clients(SilcClient client, + SilcClientConnection conn, + SilcClientEntry *clients, + uint32 clients_count, + void *context) { FileGetClients internal = (FileGetClients)context; + + if (!clients) { + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s", + internal->nick); + silc_free(internal->data); + silc_free(internal->nick); + silc_free(internal); + return; + } + signal_emit("command file", 3, internal->data, internal->server, internal->item); + silc_free(internal->data); + silc_free(internal->nick); silc_free(internal); } @@ -501,7 +518,8 @@ static void command_file(const char *data, SILC_SERVER_REC *server, WI_ITEM_REC *item) { SilcClientConnection conn; - SilcClientEntry client_entry; + SilcClientEntry *entrys, client_entry; + uint32 entry_count; char *nickname = NULL, *tmp; unsigned char **argv; uint32 argc; @@ -548,22 +566,20 @@ static void command_file(const char *data, SILC_SERVER_REC *server, } /* Find client entry */ - client_entry = silc_idlist_get_client(silc_client, conn, nickname, - argv[3], TRUE); - if (!client_entry) { + entrys = silc_client_get_clients_local(silc_client, conn, nickname, + argv[3], &entry_count); + if (!entrys) { FileGetClients inter = silc_calloc(1, sizeof(*inter)); inter->server = server; inter->data = strdup(data); + inter->nick = strdup(nickname); inter->item = item; - - /* Client entry not found, it was requested thus mark this to be - pending command. */ - silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, - NULL, silc_client_command_file_get_clients, - inter); + silc_client_get_clients(silc_client, conn, nickname, argv[3], + silc_client_command_file_get_clients, inter); goto out; } + client_entry = entrys[0]; + silc_free(entrys); silc_client_file_send(silc_client, conn, silc_client_file_monitor, server, client_entry, argv[2]); @@ -591,23 +607,20 @@ static void command_file(const char *data, SILC_SERVER_REC *server, } /* Find client entry */ - client_entry = silc_idlist_get_client(silc_client, conn, nickname, - argv[2], TRUE); - if (!client_entry) { + entrys = silc_client_get_clients_local(silc_client, conn, nickname, + argv[2], &entry_count); + if (!entrys) { FileGetClients inter = silc_calloc(1, sizeof(*inter)); inter->server = server; inter->data = strdup(data); + inter->nick = strdup(nickname); inter->item = item; - - /* Client entry not found, it was requested thus mark this to be - pending command. */ - silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, - NULL, - silc_client_command_file_get_clients, - inter); + silc_client_get_clients(silc_client, conn, nickname, argv[2], + silc_client_command_file_get_clients, inter); goto out; } + client_entry = entrys[0]; + silc_free(entrys); } else { if (!server->current_session) { printformat_module("fe-common/silc", server, NULL, @@ -658,30 +671,27 @@ static void command_file(const char *data, SILC_SERVER_REC *server, } /* Find client entry */ - client_entry = silc_idlist_get_client(silc_client, conn, nickname, - argv[2], TRUE); - if (!client_entry) { + entrys = silc_client_get_clients_local(silc_client, conn, nickname, + argv[2], &entry_count); + if (!entrys) { FileGetClients inter = silc_calloc(1, sizeof(*inter)); inter->server = server; inter->data = strdup(data); + inter->nick = strdup(nickname); inter->item = item; - - /* Client entry not found, it was requested thus mark this to be - pending command. */ - silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, - NULL, - silc_client_command_file_get_clients, - inter); + silc_client_get_clients(silc_client, conn, nickname, argv[2], + silc_client_command_file_get_clients, inter); goto out; } + client_entry = entrys[0]; + silc_free(entrys); } else { if (!server->current_session) { printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, SILCTXT_FILE_NA); goto out; } - + if (!silc_client_file_close(silc_client, conn, server->current_session->session_id)) printformat_module("fe-common/silc", server, NULL, diff --git a/lib/silcclient/client_notify.c b/lib/silcclient/client_notify.c index 85b4530d..5b508e5c 100644 --- a/lib/silcclient/client_notify.c +++ b/lib/silcclient/client_notify.c @@ -38,6 +38,19 @@ typedef struct { static void silc_client_notify_by_server_pending(void *context, void *context2) { SilcClientNotifyResolve res = (SilcClientNotifyResolve)context; + SilcClientCommandReplyContext reply = + (SilcClientCommandReplyContext)context2; + + if (reply) { + SilcCommandStatus status; + unsigned char *tmp = silc_argument_get_arg_type(reply->args, 1, NULL); + SILC_GET16_MSB(status, tmp); + if (status != SILC_STATUS_OK) { + silc_socket_free(res->sock); + return; + } + } + silc_client_notify_by_server(res->context, res->sock, res->packet); silc_socket_free(res->sock); } diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 01fe350c..e6a77869 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -389,8 +389,8 @@ SILC_CLIENT_CMD_REPLY_FUNC(whowas) } out: - SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_WHOIS); - SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_WHOIS); + SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_WHOWAS); + SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_WHOWAS); silc_client_command_reply_free(cmd); } diff --git a/lib/silcclient/silcapi.h b/lib/silcclient/silcapi.h index e7d7b9cc..7ee729e2 100644 --- a/lib/silcclient/silcapi.h +++ b/lib/silcclient/silcapi.h @@ -843,7 +843,8 @@ void silc_client_get_clients(SilcClient client, * is the formatted nickname to find exact match from multiple found * entries. The format must be same as given in the SilcClientParams * structure to the client library. If the `format' is NULL all found - * clients by `nickname' are returned. + * clients by `nickname' are returned. The caller must return the + * returned array. * ***/ SilcClientEntry *silc_client_get_clients_local(SilcClient client, -- 2.24.0