updates.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 19 Jul 2001 19:39:15 +0000 (19:39 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 19 Jul 2001 19:39:15 +0000 (19:39 +0000)
CHANGES
TODO
apps/silcd/command.c
lib/silcclient/client.c
lib/silcclient/client_notify.c
lib/silcclient/command.c
lib/silcclient/idlist.c
lib/silcclient/idlist.h
lib/silcclient/silcapi.h

diff --git a/CHANGES b/CHANGES
index 4149c0885af28796c78b3e47ab188a29388d09bb..4399701d09b3c3c2d2fae76f1324188f9209d44c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,26 @@
+Thu Jul 19 21:44:31 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
+
+       * 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 <priikone@silcnet.org>
 
        * Removed the non-blocking settings in WIN32 code in the
diff --git a/TODO b/TODO
index 02d3d74a05e21dfade5a31485bdea2f6a9739e17..aa2b3b9b0b850f80fd10d51aeb585cec413a2a57 100644 (file)
--- 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
 ========================
index bab8ee25dfc658a3829aa50be83a0fb0792d00a6..b2b268db0b454df1ebff8a38b458abe6cd551337 100644 (file)
@@ -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 */
index 45d43517c9fbb60a26f88de87c763d40c13302f3..09249d05a39e62578c116071b88dec2ad24d1dc9 100644 (file)
@@ -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)
index f03a20074af7dba40bf066787f9f8c6353dc2963..dd787cac42c12b1f94a1dd1208762d20239b435a 100644 (file)
@@ -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);
 
index d74faf3db569c5784a5abf4d37fb41849b4b25ac..6a8335fe7ab5da1cf710c3b6d45e37d33f0c03ff 100644 (file)
@@ -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);
index 0599b405143659ce9df0159be1804229a117a076..5085c39202ae56a3c2339e6ebf80bc94534dfc17 100644 (file)
@@ -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;
+}
index 32088f1545282eb00f6e9c4716717589b086e8f8..815d039240fb9ade0d72570cc54034ec51acb069 100644 (file)
@@ -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,
index ed5c5f0f94d4a1f94577c4695e2e03f94b59f031..91de9b63fef9bc7ca3eef10e5e6fd7fc4fe150a9 100644 (file)
@@ -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) */