updates.
[silc.git] / apps / silcd / idlist.c
index 40b9041caaafee09f3b3d36f3e64168429b7972e..9503742f82e7c66fb08d48536047bf608d2ca01e 100644 (file)
@@ -2,9 +2,9 @@
 
   idlist.c
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2002 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 
 #include "serverincludes.h"
 #include "idlist.h"
+#include "server_internal.h"
 
 /******************************************************************************
 
@@ -381,7 +382,7 @@ int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
                                        char *server, 
                                        SilcClientEntry **clients,
-                                       uint32 *clients_count)
+                                       SilcUInt32 *clients_count)
 {
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;
@@ -414,16 +415,19 @@ int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
                                    SilcHash md5hash,
                                    SilcClientEntry **clients,
-                                   uint32 *clients_count)
+                                   SilcUInt32 *clients_count)
 {
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;
   unsigned char hash[32];
   SilcClientID client_id;
+  char nick[128 + 1];
 
   SILC_LOG_DEBUG(("Start"));
 
-  silc_hash_make(md5hash, nickname, strlen(nickname), hash);
+  memset(nick, 0, sizeof(nick));
+  silc_to_lower(nickname, nick, sizeof(nick) - 1);
+  silc_hash_make(md5hash, nick, strlen(nick), hash);
 
   /* As the Client ID is hashed in the ID cache by hashing only the hash
      from the Client ID, we can do a lookup with only the hash not the
@@ -493,8 +497,9 @@ silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
 /* Replaces old Client ID with new one */
 
 SilcClientEntry
-silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
-                             SilcClientID *new_id)
+silc_idlist_replace_client_id(SilcServer server,
+                             SilcIDList id_list, SilcClientID *old_id,
+                             SilcClientID *new_id, const char *nickname)
 {
   SilcIDCacheEntry id_cache = NULL;
   SilcClientEntry client;
@@ -518,12 +523,22 @@ silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
 
   /* Remove the old entry and add a new one */
 
-  silc_idcache_del_by_context(id_list->clients, client);
+  if (!silc_idcache_del_by_context(id_list->clients, client))
+    return NULL;
+
+  /* Check if anyone is watching this nickname */
+  if (server->server_type == SILC_ROUTER)
+    silc_server_check_watcher_list(server, client, nickname,
+                                  SILC_NOTIFY_TYPE_NICK_CHANGE);
 
   silc_free(client->id);
+  silc_free(client->nickname);
   client->id = new_id;
+  client->nickname = nickname ? strdup(nickname) : NULL;
 
-  silc_idcache_add(id_list->clients, NULL, client->id, client, 0, NULL);
+  if (!silc_idcache_add(id_list->clients, client->nickname, client->id, 
+                       client, 0, NULL))
+    return NULL;
 
   SILC_LOG_DEBUG(("Replaced"));
 
@@ -648,6 +663,8 @@ int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
       silc_hmac_free(entry->hmac);
     silc_free(entry->hmac_name);
     silc_free(entry->rekey);
+    if (entry->founder_key)
+      silc_pkcs_public_key_free(entry->founder_key);
 
     memset(entry, 'F', sizeof(*entry));
     silc_free(entry);
@@ -748,7 +765,7 @@ silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
 
 SilcChannelEntry *
 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
-                        uint32 *channels_count)
+                        SilcUInt32 *channels_count)
 {
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;