updates.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 18 May 2001 09:38:30 +0000 (09:38 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 18 May 2001 09:38:30 +0000 (09:38 +0000)
CHANGES
TODO
apps/silcd/command.c
apps/silcd/command_reply.c
apps/silcd/idlist.c
apps/silcd/packet_receive.c
apps/silcd/server.c
lib/silccore/idcache.c
lib/silccore/idcache.h

diff --git a/CHANGES b/CHANGES
index c70abe0de18fa4377515910fdd2b77c848634258..0c7bd93254bab977c13b68f5b4ecfd5de1dcc745 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+Fri May 18 11:18:45 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Added new function silc_idcache_del_by_context into the
+         lib/silccore/idcache.[ch].
+
+       * Changed the server's ID list routines to use the new ID Cache
+         interface.  Changes around the source tree.
+
 Fri May 18 08:35:31 EEST 2001  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Added silc_hash_table_del[_by_context]_ext functions in to the
diff --git a/TODO b/TODO
index 2e7dd511a4d9c0334966e7b6dfc5ce41f212cd62..b695701e9bb0fd7526bd65f9f6fc065841ea4616 100644 (file)
--- a/TODO
+++ b/TODO
@@ -19,6 +19,10 @@ TODO/bugs In SILC Client Library
 TODO/bugs In SILC Server
 ========================
 
+ o Save channel names in the ID Cache always as lowered characters,
+   though allow mixed case characters in the channel entry but the ID
+   cache does not handle loose data searching anymore.
+
  o When server quits and all clients of that server are removed from all
    channels the channel keys are re-generated for all clients.  This is
    a bug and should be done only once per channel after all clients of
index a961f6c9ec52399c720128987452f77786c841e8..b260c141524f0dc96c8631f6bf8e71b6dc345b32 100644 (file)
@@ -1764,8 +1764,7 @@ SILC_SERVER_CMD_FUNC(nick)
                                        new_id);
 
   /* Remove old cache entry */
-  silc_idcache_del_by_id(server->local_list->clients, SILC_ID_CLIENT, 
-                        client->id); 
+  silc_idcache_del_by_id(server->local_list->clients, client->id);
 
   oidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
 
@@ -1782,8 +1781,8 @@ SILC_SERVER_CMD_FUNC(nick)
 
   /* Update client cache */
   silc_idcache_add(server->local_list->clients, client->nickname, 
-                  strlen(client->nickname), SILC_ID_CLIENT, client->id, 
-                  (void *)client, TRUE, FALSE);
+                  strlen(client->nickname), client->id, 
+                  (void *)client, FALSE);
 
   nidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
 
index eec802895db6798bc068583f0ec960f86613af60..fa0e2be2c49f1d2a8b648e3e568abbf581412dee 100644 (file)
@@ -132,7 +132,6 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
   char *nickname, *username, *realname, *servername = NULL;
   SilcClientID *client_id;
   SilcClientEntry client;
-  SilcIDCacheEntry cache = NULL;
   char global = FALSE;
   char *nick;
   uint32 mode = 0, len, id_len;
@@ -159,11 +158,10 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
 
   /* Check if we have this client cached already. */
 
-  client = silc_idlist_find_client_by_id(server->local_list, client_id,
-                                        &cache);
+  client = silc_idlist_find_client_by_id(server->local_list, client_id, NULL);
   if (!client) {
-    client = silc_idlist_find_client_by_id(server->global_list, 
-                                          client_id, &cache);
+    client = silc_idlist_find_client_by_id(server->global_list, client_id, 
+                                          NULL);
     global = TRUE;
   }
 
@@ -226,13 +224,12 @@ silc_server_command_reply_whois_save(SilcServerCommandReplyContext cmd)
     client->mode = mode;
     client->servername = servername;
 
-    if (cache) {
-      cache->data = nick;
-      cache->data_len = strlen(nick);
-      silc_idcache_sort_by_data(global ? server->global_list->clients : 
-                               server->local_list->clients);
-    }
-
+    /* Remove the old cache entry and create a new one */
+    silc_idcache_del_by_context(global ? server->global_list->clients :
+                               server->local_list->clients, client);
+    silc_idcache_add(global ? server->global_list->clients :
+                    server->local_list->clients, nick, strlen(nick),
+                    client->id, client, FALSE);
     silc_free(client_id);
   }
 
@@ -360,12 +357,12 @@ silc_server_command_reply_whowas_save(SilcServerCommandReplyContext cmd)
     client->username = strdup(username);
     client->servername = servername;
 
-    if (cache) {
-      cache->data = nick;
-      cache->data_len = strlen(nick);
-      silc_idcache_sort_by_data(global ? server->global_list->clients : 
-                               server->local_list->clients);
-    }
+    /* Remove the old cache entry and create a new one */
+    silc_idcache_del_by_context(global ? server->global_list->clients :
+                               server->local_list->clients, client);
+    silc_idcache_add(global ? server->global_list->clients :
+                    server->local_list->clients, nick, strlen(nick),
+                    client->id, client, FALSE);
   }
 
   silc_free(client_id);
@@ -410,7 +407,6 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd)
   char *nickname, *username;
   SilcClientID *client_id;
   SilcClientEntry client;
-  SilcIDCacheEntry cache = NULL;
   char global = FALSE;
   char *nick = NULL;
 
@@ -426,11 +422,10 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd)
 
   /* Check if we have this client cached already. */
 
-  client = silc_idlist_find_client_by_id(server->local_list, client_id,
-                                        &cache);
+  client = silc_idlist_find_client_by_id(server->local_list, client_id, NULL);
   if (!client) {
-    client = silc_idlist_find_client_by_id(server->global_list, 
-                                          client_id, &cache);
+    client = silc_idlist_find_client_by_id(server->global_list, client_id,
+                                          NULL);
     global = TRUE;
   }
 
@@ -485,13 +480,14 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd)
       client->username = strdup(username);
     }
 
-    if (nickname && cache) {
-      cache->data = nick;
-      cache->data_len = strlen(nick);
-      silc_idcache_sort_by_data(global ? server->global_list->clients : 
-                               server->local_list->clients);
+    /* Remove the old cache entry and create a new one */
+    if (nickname) {
+      silc_idcache_del_by_context(global ? server->global_list->clients :
+                                 server->local_list->clients, client);
+      silc_idcache_add(global ? server->global_list->clients :
+                      server->local_list->clients, nick, strlen(nick),
+                      client->id, client, FALSE);
     }
-
     silc_free(client_id);
   }
 
index ae733745b3d10ff4c2d694a250c916bd37fa5cd6..d3d0b200f1b6b2fa6deeab90d341768cb07012cb 100644 (file)
@@ -113,8 +113,7 @@ silc_idlist_add_server(SilcIDList id_list,
 
   if (!silc_idcache_add(id_list->servers, server->server_name, 
                        server->server_name ? strlen(server->server_name) : 0,
-                       SILC_ID_SERVER, (void *)server->id, 
-                       (void *)server, TRUE, FALSE)) {
+                       (void *)server->id, (void *)server, FALSE)) {
     silc_free(server);
     return NULL;
   }
@@ -137,8 +136,8 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
   SILC_LOG_DEBUG(("Server ID (%s)",
                  silc_id_render(id, SILC_ID_SERVER)));
 
-  if (!silc_idcache_find_by_id_one(id_list->servers, (void *)id, 
-                                  SILC_ID_SERVER, &id_cache))
+  if (!silc_idcache_find_by_id(id_list->servers, (void *)id, 
+                              &id_cache))
     return NULL;
 
   server = (SilcServerEntry)id_cache->context;
@@ -160,7 +159,8 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
 
   SILC_LOG_DEBUG(("Server by name `%s'", name));
 
-  if (!silc_idcache_find_by_data_one(id_list->servers, name, &id_cache))
+  if (!silc_idcache_find_by_data_one(id_list->servers, name, strlen(name),
+                                    &id_cache))
     return NULL;
 
   server = (SilcServerEntry)id_cache->context;
@@ -186,8 +186,7 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
  
   SILC_LOG_DEBUG(("Server by hostname %s and port %d", hostname, port));
 
-  if (!silc_idcache_find_by_id(id_list->servers, SILC_ID_CACHE_ANY, 
-                              SILC_ID_SERVER, &list))
+  if (!silc_idcache_get_all(id_list->servers, &list))
     return NULL;
 
   if (!silc_idcache_list_first(list, &id_cache)) {
@@ -235,8 +234,7 @@ silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
 
   SILC_LOG_DEBUG(("Replacing Server ID"));
 
-  if (!silc_idcache_find_by_id_one(id_list->servers, (void *)old_id, 
-                                  SILC_ID_SERVER, &id_cache))
+  if (!silc_idcache_find_by_id(id_list->servers, (void *)old_id, &id_cache))
     return NULL;
 
   server = (SilcServerEntry)id_cache->context;
@@ -258,8 +256,7 @@ int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry)
   if (entry) {
     /* Remove from cache */
     if (entry->id)
-      if (!silc_idcache_del_by_id(id_list->servers, SILC_ID_SERVER, 
-                                 (void *)entry->id))
+      if (!silc_idcache_del_by_id(id_list->servers, (void *)entry->id))
        return FALSE;
 
     /* Free data */
@@ -312,8 +309,7 @@ silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
                 client_list);
 
   if (!silc_idcache_add(id_list->clients, nickname,  nickname_len,
-                       SILC_ID_CLIENT, (void *)client->id, 
-                       (void *)client, TRUE, FALSE)) {
+                       (void *)client->id, (void *)client, FALSE)) {
     silc_free(client);
     return NULL;
   }
@@ -331,8 +327,7 @@ int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
   if (entry) {
     /* Remove from cache */
     if (entry->id)
-      if (!silc_idcache_del_by_id(id_list->clients, SILC_ID_CLIENT, 
-                                 (void *)entry->id))
+      if (!silc_idcache_del_by_id(id_list->clients, (void *)entry->id))
        return FALSE;
 
     /* Free data */
@@ -368,7 +363,8 @@ int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
 
   SILC_LOG_DEBUG(("Start"));
 
-  if (!silc_idcache_find_by_data(id_list->clients, nickname, &list))
+  if (!silc_idcache_find_by_data(id_list->clients, nickname, strlen(nickname),
+                                &list))
     return FALSE;
 
   *clients = silc_realloc(*clients, 
@@ -410,7 +406,8 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
 
   silc_hash_make(md5hash, nickname, strlen(nickname), hash);
 
-  if (!silc_idcache_find_by_data(id_list->clients, hash, &list))
+  if (!silc_idcache_find_by_data(id_list->clients, hash, 
+                                md5hash->hash->hash_len, &list))
     return FALSE;
 
   *clients = silc_realloc(*clients, 
@@ -446,8 +443,7 @@ silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
   SILC_LOG_DEBUG(("Client ID (%s)", 
                  silc_id_render(id, SILC_ID_CLIENT)));
 
-  if (!silc_idcache_find_by_id_one(id_list->clients, (void *)id, 
-                                  SILC_ID_CLIENT, &id_cache))
+  if (!silc_idcache_find_by_id(id_list->clients, (void *)id, &id_cache))
     return NULL;
 
   client = (SilcClientEntry)id_cache->context;
@@ -474,8 +470,7 @@ silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
 
   SILC_LOG_DEBUG(("Replacing Client ID"));
 
-  if (!silc_idcache_find_by_id_one(id_list->clients, (void *)old_id, 
-                                  SILC_ID_CLIENT, &id_cache))
+  if (!silc_idcache_find_by_id(id_list->clients, (void *)old_id, &id_cache))
     return NULL;
 
   client = (SilcClientEntry)id_cache->context;
@@ -483,13 +478,14 @@ silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
   client->id = new_id;
   id_cache->id = (void *)new_id;
 
+  /* XXX does not work correctly with the new ID Cache */
+
   /* If the old ID Cache data was the hash value of the old Client ID
      replace it with the hash of new Client ID */
   if (id_cache->data && SILC_ID_COMPARE_HASH(old_id, id_cache->data)) {
     silc_free(id_cache->data);
     id_cache->data = silc_calloc(sizeof(new_id->hash), sizeof(unsigned char));
     memcpy(id_cache->data, new_id->hash, sizeof(new_id->hash));
-    silc_idcache_sort_by_data(id_list->clients);
   }
 
   SILC_LOG_DEBUG(("Replaced"));
@@ -555,9 +551,8 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
                 channel_list);
 
   if (!silc_idcache_add(id_list->channels, channel->channel_name, 
-                       channel->channel_name ? strlen(channel->channel_name) :
-                       0, SILC_ID_CHANNEL, 
-                       (void *)channel->id, (void *)channel, TRUE, FALSE)) {
+                       strlen(channel->channel_name),
+                       (void *)channel->id, (void *)channel, FALSE)) {
     silc_free(channel);
     return NULL;
   }
@@ -576,8 +571,7 @@ int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
 
     /* Remove from cache */
     if (entry->id)
-      if (!silc_idcache_del_by_id(id_list->channels, SILC_ID_CHANNEL, 
-                                 (void *)entry->id))
+      if (!silc_idcache_del_by_id(id_list->channels, (void *)entry->id))
        return FALSE;
 
     /* Free data */
@@ -630,7 +624,7 @@ silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
 
   SILC_LOG_DEBUG(("Channel by name"));
 
-  if (!silc_idcache_find_by_data_loose(id_list->channels, name, &list))
+  if (!silc_idcache_find_by_data(id_list->channels, name, strlen(name), &list))
     return NULL;
   
   if (!silc_idcache_list_first(list, &id_cache)) {
@@ -665,8 +659,7 @@ silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
   SILC_LOG_DEBUG(("Channel ID (%s)",
                  silc_id_render(id, SILC_ID_CHANNEL)));
 
-  if (!silc_idcache_find_by_id_one(id_list->channels, (void *)id, 
-                                  SILC_ID_CHANNEL, &id_cache))
+  if (!silc_idcache_find_by_id(id_list->channels, (void *)id, &id_cache))
     return NULL;
 
   channel = (SilcChannelEntry)id_cache->context;
@@ -694,8 +687,7 @@ silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
 
   SILC_LOG_DEBUG(("Replacing Channel ID"));
 
-  if (!silc_idcache_find_by_id_one(id_list->channels, (void *)old_id, 
-                                  SILC_ID_CHANNEL, &id_cache))
+  if (!silc_idcache_find_by_id(id_list->channels, (void *)old_id, &id_cache))
     return NULL;
 
   channel = (SilcChannelEntry)id_cache->context;
@@ -717,26 +709,34 @@ silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
 {
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;
-  SilcChannelEntry *channels;
-  int i;
+  SilcChannelEntry *channels = NULL;
+  int i = 0;
 
   SILC_LOG_DEBUG(("Start"));
 
-  if (!silc_idcache_find_by_id(id_list->channels, channel_id ? channel_id :
-                              SILC_ID_CACHE_ANY, SILC_ID_CHANNEL, &list))
-    return NULL;
+  if (!channel_id) {
+    if (!silc_idcache_get_all(id_list->channels, &list))
+      return NULL;
 
-  channels = silc_calloc(silc_idcache_list_count(list), sizeof(*channels));
+    channels = silc_calloc(silc_idcache_list_count(list), sizeof(*channels));
+    
+    i = 0;
+    silc_idcache_list_first(list, &id_cache);
+    channels[i++] = (SilcChannelEntry)id_cache->context;
+    
+    while (silc_idcache_list_next(list, &id_cache))
+      channels[i++] = (SilcChannelEntry)id_cache->context;
+    
+    silc_idcache_list_free(list);
+  } else {
+    if (!silc_idcache_find_by_id(id_list->channels, channel_id, &id_cache))
+      return NULL;
 
-  i = 0;
-  silc_idcache_list_first(list, &id_cache);
-  channels[i++] = (SilcChannelEntry)id_cache->context;
+    i = 1;
+    channels = silc_calloc(1, sizeof(*channels));
+    channels[0] = (SilcChannelEntry)id_cache->context;
+  }
 
-  while (silc_idcache_list_next(list, &id_cache))
-    channels[i++] = (SilcChannelEntry)id_cache->context;
-  
-  silc_idcache_list_free(list);
-  
   if (channels_count)
     *channels_count = i;
 
index b325fd6a894e356f70dd5760b4a97cada1f28985..5091da02e7ffe22e41771340e58954e5323ba4aa 100644 (file)
@@ -1274,7 +1274,6 @@ SilcClientEntry silc_server_new_client(SilcServer server,
 {
   SilcBuffer buffer = packet->buffer;
   SilcClientEntry client;
-  SilcIDCacheEntry cache;
   SilcClientID *client_id;
   SilcBuffer reply;
   SilcIDListData idata;
@@ -1291,14 +1290,8 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   client = (SilcClientEntry)sock->user_data;
   idata = (SilcIDListData)client;
 
-  /* Fetch the old client cache entry so that we can update it. */
-  if (!silc_idcache_find_by_context(server->local_list->clients,
-                                   sock->user_data, &cache)) {
-    SILC_LOG_ERROR(("Lost client's cache entry - bad thing"));
-    silc_server_disconnect_remote(server, sock, "Server closed connection: "
-                                  "Unknown client");
-    return NULL;
-  }
+  /* Remove the old cache entry */
+  silc_idcache_del_by_context(server->local_list->clients, client);
 
   /* Parse incoming packet */
   ret = silc_buffer_unformat(buffer,
@@ -1339,12 +1332,9 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   client->id = client_id;
   id_len = silc_id_get_len(client_id, SILC_ID_CLIENT);
 
-  /* Update the cache entry */
-  cache->id = (void *)client_id;
-  cache->type = SILC_ID_CLIENT;
-  cache->data = username;
-  cache->data_len = strlen(username);
-  silc_idcache_sort_by_data(server->local_list->clients);
+  /* Add the client again to the ID cache */
+  silc_idcache_add(server->local_list->clients, client->nickname,
+                  strlen(client->nickname), client_id, client, FALSE);
 
   /* Notify our router about new client on the SILC network */
   if (!server->standalone)
@@ -1434,7 +1424,6 @@ SilcServerEntry silc_server_new_server(SilcServer server,
 {
   SilcBuffer buffer = packet->buffer;
   SilcServerEntry new_server;
-  SilcIDCacheEntry cache;
   SilcServerID *server_id;
   SilcIDListData idata;
   unsigned char *server_name, *id_string;
@@ -1451,12 +1440,8 @@ SilcServerEntry silc_server_new_server(SilcServer server,
   new_server = (SilcServerEntry)sock->user_data;
   idata = (SilcIDListData)new_server;
 
-  /* Fetch the old server cache entry so that we can update it. */
-  if (!silc_idcache_find_by_context(server->local_list->servers,
-                                   sock->user_data, &cache)) {
-    SILC_LOG_ERROR(("Lost server's cache entry - bad thing"));
-    return NULL;
-  }
+  /* Remove the old cache entry */
+  silc_idcache_del_by_context(server->local_list->servers, new_server);
 
   /* Parse the incoming packet */
   ret = silc_buffer_unformat(buffer,
@@ -1490,17 +1475,14 @@ SilcServerEntry silc_server_new_server(SilcServer server,
   }
   silc_free(id_string);
 
-  /* Update client entry */
+  /* Update server entry */
   idata->registered = TRUE;
   new_server->server_name = server_name;
   new_server->id = server_id;
 
-  /* Update the cache entry */
-  cache->id = (void *)server_id;
-  cache->type = SILC_ID_SERVER;
-  cache->data = server_name;
-  cache->data_len = strlen(server_name);
-  silc_idcache_sort_by_data(server->local_list->servers);
+  /* Add again the entry to the ID cache. */
+  silc_idcache_add(server->local_list->servers, server_name, 
+                  strlen(server_name), server_id, server, FALSE);
 
   /* Distribute the information about new server in the SILC network
      to our router. If we are normal server we won't send anything
index 455a8c33747d2ebbd08bdb88e475a18d22ab5637..8435e02af0269060911d6159e8ac0d1981ac86ad 100644 (file)
@@ -182,17 +182,17 @@ int silc_server_init(SilcServer server)
 
   /* Initialize ID caches */
   server->local_list->clients = 
-    silc_idcache_alloc(0, silc_idlist_client_destructor);
-  server->local_list->servers = silc_idcache_alloc(0, NULL);
-  server->local_list->channels = silc_idcache_alloc(0, NULL);
+    silc_idcache_alloc(0, SILC_ID_CLIENT, silc_idlist_client_destructor);
+  server->local_list->servers = silc_idcache_alloc(0, SILC_ID_SERVER, NULL);
+  server->local_list->channels = silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL);
 
   /* These are allocated for normal server as well as these hold some 
      global information that the server has fetched from its router. For 
      router these are used as they are supposed to be used on router. */
   server->global_list->clients = 
-    silc_idcache_alloc(0, silc_idlist_client_destructor);
-  server->global_list->servers = silc_idcache_alloc(0, NULL);
-  server->global_list->channels = silc_idcache_alloc(0, NULL);
+    silc_idcache_alloc(0, SILC_ID_CLIENT, silc_idlist_client_destructor);
+  server->global_list->servers = silc_idcache_alloc(0, SILC_ID_SERVER, NULL);
+  server->global_list->channels = silc_idcache_alloc(0, SILC_ID_CHANNEL, NULL);
 
   /* Allocate the entire socket list that is used in server. Eventually 
      all connections will have entry in this table (it is a table of 
@@ -2297,8 +2297,7 @@ int silc_server_remove_clients_by_server(SilcServer server,
     silc_buffer_free(idp);
   }
 
-  if (silc_idcache_find_by_id(server->local_list->clients, 
-                             SILC_ID_CACHE_ANY, SILC_ID_CLIENT, &list)) {
+  if (silc_idcache_get_all(server->local_list->clients, &list)) {
 
     if (silc_idcache_list_first(list, &id_cache)) {
       while (id_cache) {
@@ -2351,8 +2350,7 @@ int silc_server_remove_clients_by_server(SilcServer server,
     silc_idcache_list_free(list);
   }
   
-  if (silc_idcache_find_by_id(server->global_list->clients, 
-                             SILC_ID_CACHE_ANY, SILC_ID_CLIENT, &list)) {
+  if (silc_idcache_get_all(server->global_list->clients, &list)) {
 
     if (silc_idcache_list_first(list, &id_cache)) {
       while (id_cache) {
@@ -3105,8 +3103,7 @@ static void silc_server_announce_get_servers(SilcServer server,
   SilcBuffer idp;
 
   /* Go through all clients in the list */
-  if (silc_idcache_find_by_id(id_list->servers, SILC_ID_CACHE_ANY, 
-                             SILC_ID_SERVER, &list)) {
+  if (silc_idcache_get_all(id_list->servers, &list)) {
     if (silc_idcache_list_first(list, &id_cache)) {
       while (id_cache) {
        entry = (SilcServerEntry)id_cache->context;
@@ -3172,8 +3169,7 @@ static void silc_server_announce_get_clients(SilcServer server,
   SilcBuffer idp;
 
   /* Go through all clients in the list */
-  if (silc_idcache_find_by_id(id_list->clients, SILC_ID_CACHE_ANY, 
-                             SILC_ID_CLIENT, &list)) {
+  if (silc_idcache_get_all(id_list->clients, &list)) {
     if (silc_idcache_list_first(list, &id_cache)) {
       while (id_cache) {
        client = (SilcClientEntry)id_cache->context;
@@ -3321,8 +3317,7 @@ void silc_server_announce_get_channels(SilcServer server,
   SILC_LOG_DEBUG(("Start"));
 
   /* Go through all channels in the list */
-  if (silc_idcache_find_by_id(id_list->channels, SILC_ID_CACHE_ANY, 
-                             SILC_ID_CHANNEL, &list)) {
+  if (silc_idcache_get_all(id_list->channels, &list)) {
     if (silc_idcache_list_first(list, &id_cache)) {
       while (id_cache) {
        channel = (SilcChannelEntry)id_cache->context;
index 9842a7d7e1bb42c9a7e1a072c474d361b849ec05..6c307d2a419633f23f2529aa72fcfdf9a3a11a1a 100644 (file)
@@ -212,6 +212,18 @@ bool silc_idcache_del_by_id(SilcIDCache cache, void *id)
   return silc_idcache_del(cache, c);
 }
 
+/* Deletes ID cache entry by context. */
+
+bool silc_idcache_del_by_context(SilcIDCache cache, void *context)
+{
+  SilcIDCacheEntry c;
+
+  if (!silc_hash_table_find(cache->context_table, context, NULL, (void *)&c))
+    return FALSE;
+
+  return silc_idcache_del(cache, c);
+}
+
 /* Deletes all ID entries from cache. Free's memory as well. */
 
 bool silc_idcache_del_all(SilcIDCache cache)
index 98f010142799c5812e50a1e6447fffc7e1cfe233..032bad702b3d3d85c1b20682194b62319b0f287a 100644 (file)
@@ -88,6 +88,7 @@ bool silc_idcache_add(SilcIDCache cache, unsigned char *data,
                      uint32 data_len, void *id, void *context, int expire);
 bool silc_idcache_del(SilcIDCache cache, SilcIDCacheEntry old);
 bool silc_idcache_del_by_id(SilcIDCache cache, void *id);
+bool silc_idcache_del_by_context(SilcIDCache cache, void *context);
 bool silc_idcache_del_all(SilcIDCache cache);
 bool silc_idcache_purge(SilcIDCache cache);
 bool silc_idcache_purge_by_context(SilcIDCache cache, void *context);