From: Pekka Riikonen Date: Thu, 19 Jul 2001 19:39:15 +0000 (+0000) Subject: updates. X-Git-Tag: robodoc-323~58 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=20cf6a02a72e97a63a93ffb478d02fee4fbb9e38 updates. --- diff --git a/CHANGES b/CHANGES index 4149c088..4399701d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,26 @@ +Thu Jul 19 21:44:31 EEST 2001 Pekka Riikonen + + * Added `task_max' field to the SilcClientParams to indicate + the maximum tasks the scheduler can handle. If set to zero, + default values are used. Affected file lib/silcclient/silcapi.h. + + * Fixed memory leaks in silc_client_close_connection. Affected + file lib/silcclient/client.c. + + * Added silc_client_del_client_entry to client library to free + all memory of given client entry. Affected file is + lib/silcclient/idlist.[ch]. + + * Added new functions silc_client_del_channel and + silc_client_del_server to delete channel and server entries. + Affected file lib/silcclient/[silcapi.h/idlist.c]. + + * Removed silc_client_del_client_by_id from silcapi.h. + + * Fixed the INFO command to return the server's own info + correctly when querying by Server ID. Affected file is + silcd/command.c. + Thu Jul 19 14:47:30 EEST 2001 Pekka Riikonen * Removed the non-blocking settings in WIN32 code in the diff --git a/TODO b/TODO index 02d3d74a..aa2b3b9b 100644 --- a/TODO +++ b/TODO @@ -41,8 +41,6 @@ TODO/bugs In SILC Client Library interface separately or it could just remove the old client unless it is on some channels. - o silc_client_close_connection leaks memory. Read the XXX from code. - TODO/bugs In SILC Server ======================== diff --git a/apps/silcd/command.c b/apps/silcd/command.c index bab8ee25..b2b268db 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -2603,7 +2603,8 @@ SILC_SERVER_CMD_FUNC(info) } } - if ((!dest_server && !server_id) || + if ((!dest_server && !server_id && !entry) || (entry && + entry == server->id_entry) || (dest_server && !cmd->pending && !strncasecmp(dest_server, server->server_name, strlen(dest_server)))) { /* Send our reply */ diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 45d43517..09249d05 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -100,7 +100,8 @@ int silc_client_init(SilcClient client) silc_client_protocols_register(); /* Initialize the scheduler */ - client->schedule = silc_schedule_init(200); + client->schedule = silc_schedule_init(client->params->task_max ? + client->params->task_max : 200); if (!client->schedule) return FALSE; @@ -1189,7 +1190,37 @@ void silc_client_close_connection(SilcClient client, /* Free everything */ if (del && sock->user_data) { - /* XXX Free all client entries and channel entries. */ + /* Free all cache entries */ + SilcIDCacheList list; + SilcIDCacheEntry entry; + bool ret; + + if (silc_idcache_get_all(conn->client_cache, &list)) { + ret = silc_idcache_list_first(list, &entry); + while (ret) { + silc_client_del_client(client, conn, entry->context); + ret = silc_idcache_list_next(list, &entry); + } + silc_idcache_list_free(list); + } + + if (silc_idcache_get_all(conn->channel_cache, &list)) { + ret = silc_idcache_list_first(list, &entry); + while (ret) { + silc_client_del_channel(client, conn, entry->context); + ret = silc_idcache_list_next(list, &entry); + } + silc_idcache_list_free(list); + } + + if (silc_idcache_get_all(conn->server_cache, &list)) { + ret = silc_idcache_list_first(list, &entry); + while (ret) { + silc_client_del_server(client, conn, entry->context); + ret = silc_idcache_list_next(list, &entry); + } + silc_idcache_list_free(list); + } /* Clear ID caches */ if (conn->client_cache) diff --git a/lib/silcclient/client_notify.c b/lib/silcclient/client_notify.c index f03a2007..dd787cac 100644 --- a/lib/silcclient/client_notify.c +++ b/lib/silcclient/client_notify.c @@ -294,16 +294,7 @@ void silc_client_notify_by_server(SilcClient client, client->ops->notify(client, conn, type, client_entry, tmp); /* Free data */ - if (client_entry->nickname) - silc_free(client_entry->nickname); - if (client_entry->server) - silc_free(client_entry->server); - if (client_entry->id) - silc_free(client_entry->id); - if (client_entry->send_key) - silc_cipher_free(client_entry->send_key); - if (client_entry->receive_key) - silc_cipher_free(client_entry->receive_key); + silc_client_del_client_entry(client, client_entry); break; case SILC_NOTIFY_TYPE_TOPIC_SET: @@ -402,17 +393,7 @@ void silc_client_notify_by_server(SilcClient client, client->ops->notify(client, conn, type, client_entry, client_entry2); /* Free data */ - if (client_entry->nickname) - silc_free(client_entry->nickname); - if (client_entry->server) - silc_free(client_entry->server); - if (client_entry->id) - silc_free(client_entry->id); - if (client_entry->send_key) - silc_cipher_free(client_entry->send_key); - if (client_entry->receive_key) - silc_cipher_free(client_entry->receive_key); - silc_free(client_entry); + silc_client_del_client_entry(client, client_entry); break; case SILC_NOTIFY_TYPE_CMODE_CHANGE: @@ -725,18 +706,7 @@ void silc_client_notify_by_server(SilcClient client, if (client_entry != conn->local_entry) { /* Remove client from all channels */ silc_client_remove_from_channels(client, conn, client_entry); - silc_idcache_del_by_context(conn->client_cache, client_entry); - if (client_entry->nickname) - silc_free(client_entry->nickname); - if (client_entry->server) - silc_free(client_entry->server); - if (client_entry->id) - silc_free(client_entry->id); - if (client_entry->send_key) - silc_cipher_free(client_entry->send_key); - if (client_entry->receive_key) - silc_cipher_free(client_entry->receive_key); - silc_free(client_entry); + silc_client_del_client(client, conn, client_entry); } break; @@ -784,18 +754,7 @@ void silc_client_notify_by_server(SilcClient client, continue; silc_client_remove_from_channels(client, conn, client_entry); - silc_idcache_del_by_context(conn->client_cache, client_entry); - if (client_entry->nickname) - silc_free(client_entry->nickname); - if (client_entry->server) - silc_free(client_entry->server); - if (client_entry->id) - silc_free(client_entry->id); - if (client_entry->send_key) - silc_cipher_free(client_entry->send_key); - if (client_entry->receive_key) - silc_cipher_free(client_entry->receive_key); - silc_free(client_entry); + silc_client_del_client(client, conn, client_entry); } silc_free(clients); diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index d74faf3d..6a8335fe 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -2013,12 +2013,7 @@ SILC_CLIENT_CMD_FUNC(leave) if (conn->current_channel == channel) conn->current_channel = NULL; - silc_idcache_del_by_id(conn->channel_cache, channel->id); - silc_free(channel->channel_name); - silc_free(channel->id); - silc_free(channel->key); - silc_cipher_free(channel->channel_key); - silc_free(channel); + silc_client_del_channel(cmd->client, cmd->conn, channel); out: silc_client_command_free(cmd); diff --git a/lib/silcclient/idlist.c b/lib/silcclient/idlist.c index 0599b405..5085c392 100644 --- a/lib/silcclient/idlist.c +++ b/lib/silcclient/idlist.c @@ -517,23 +517,50 @@ void silc_client_get_client_by_id_resolve(SilcClient client, (void *)i); } +/* Deletes the client entry and frees all memory. */ + +void silc_client_del_client_entry(SilcClient client, + SilcClientEntry client_entry) +{ + silc_free(client_entry->nickname); + silc_free(client_entry->username); + silc_free(client_entry->realname); + silc_free(client_entry->server); + silc_free(client_entry->id); + if (client_entry->send_key) + silc_cipher_free(client_entry->send_key); + if (client_entry->receive_key) + silc_cipher_free(client_entry->receive_key); + silc_free(client_entry->key); + silc_free(client_entry); +} + /* Removes client from the cache by the client entry. */ bool silc_client_del_client(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry) { - return silc_idcache_del_by_context(conn->client_cache, client_entry); + bool ret = silc_idcache_del_by_context(conn->client_cache, client_entry); + silc_client_del_client_entry(client, client_entry); + return ret; } -/* Removes client from the cache by the client ID. */ +/* Removes channel from the cache by the channel entry. */ -bool silc_client_del_client_by_id(SilcClient client, - SilcClientConnection conn, - SilcClientID *client_id) +bool silc_client_del_channel(SilcClient client, SilcClientConnection conn, + SilcChannelEntry channel) { - return silc_idcache_del_by_id_ext(conn->client_cache, (void *)client_id, - NULL, NULL, - silc_hash_client_id_compare, NULL); + bool ret = silc_idcache_del_by_context(conn->channel_cache, channel); + silc_free(channel->channel_name); + silc_free(channel->id); + silc_free(channel->key); + if (channel->channel_key) + silc_cipher_free(channel->channel_key); + if (channel->hmac) + silc_hmac_free(channel->hmac); + silc_client_del_channel_private_keys(client, conn, channel); + silc_free(channel); + return ret; } /* Finds entry for channel by the channel name. Returns the entry or NULL @@ -701,3 +728,16 @@ SilcServerEntry silc_client_get_server_by_id(SilcClient client, return entry; } + +/* Removes server from the cache by the server entry. */ + +bool silc_client_del_server(SilcClient client, SilcClientConnection conn, + SilcServerEntry server) +{ + bool ret = silc_idcache_del_by_context(conn->server_cache, server); + silc_free(server->server_name); + silc_free(server->server_info); + silc_free(server->server_id); + silc_free(server); + return ret; +} diff --git a/lib/silcclient/idlist.h b/lib/silcclient/idlist.h index 32088f15..815d0392 100644 --- a/lib/silcclient/idlist.h +++ b/lib/silcclient/idlist.h @@ -91,6 +91,8 @@ typedef struct { /* Prototypes. These are used only by the library. Application should not call these directly. */ +void silc_client_del_client_entry(SilcClient client, + SilcClientEntry client_entry); SilcClientEntry silc_idlist_get_client(SilcClient client, SilcClientConnection conn, char *nickname, diff --git a/lib/silcclient/silcapi.h b/lib/silcclient/silcapi.h index ed5c5f0f..91de9b63 100644 --- a/lib/silcclient/silcapi.h +++ b/lib/silcclient/silcapi.h @@ -340,8 +340,14 @@ typedef struct { * SOURCE */ typedef struct { + /* Number of maximum tasks the client library's scheduler can handle. + If set to zero, the default value will be used (200). For WIN32 + systems this should be set to 64 as it is the hard limit dictated + by the WIN32. */ + int task_max; + /* Rekey timeout in seconds. The client will perform rekey in this - time interval. If set to zero, default value will be used. */ + time interval. If set to zero, the default value will be used. */ unsigned int rekey_secs; } SilcClientParams; /***/ @@ -817,24 +823,6 @@ void silc_client_get_client_by_id_resolve(SilcClient client, bool silc_client_del_client(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry); -/****f* silcclient/SilcClientAPI/silc_client_del_client_by_id - * - * SYNOPSIS - * - * bool silc_client_del_client_by_id(SilcClient client, - * SilcClientConnection conn, - * SilcClientID *client_id); - * - * DESCRIPTION - * - * Removes client from local cache by the Client ID indicated by - * the `Client ID'. Returns TRUE if the deletion were successful. - * - ***/ -bool silc_client_del_client_by_id(SilcClient client, - SilcClientConnection conn, - SilcClientID *client_id); - /****f* silcclient/SilcClientAPI/SilcGetChannelCallback * * SYNOPSIS @@ -923,6 +911,23 @@ void silc_client_get_channel_by_id_resolve(SilcClient client, SilcGetChannelCallback completion, void *context); +/****f* silcclient/SilcClientAPI/silc_client_del_channel + * + * SYNOPSIS + * + * bool silc_client_del_channel(SilcClient client, + * SilcClientConnection conn, + * SilcChannelEntry channel) + * + * DESCRIPTION + * + * Removes channel from local cache by the channel entry indicated by + * the `channel'. Returns TRUE if the deletion were successful. + * + ***/ +bool silc_client_del_channel(SilcClient client, SilcClientConnection conn, + SilcChannelEntry channel); + /****f* silcclient/SilcClientAPI/silc_client_get_server * * SYNOPSIS @@ -959,6 +964,21 @@ SilcServerEntry silc_client_get_server_by_id(SilcClient client, SilcClientConnection conn, SilcServerID *server_id); +/****f* silcclient/SilcClientAPI/silc_client_get_server_by_id + * + * SYNOPSIS + * + * bool silc_client_del_server(SilcClient client, SilcClientConnection conn, + * SilcServerEntry server); + * + * DESCRIPTION + * + * Removes server from local cache by the server entry indicated by + * the `server'. Returns TRUE if the deletion were successful. + * + ***/ +bool silc_client_del_server(SilcClient client, SilcClientConnection conn, + SilcServerEntry server); /* Command management (command.c) */