A LOT updates. Cannot separate. :)
[silc.git] / apps / silcd / idlist.c
index 97ee88544126bf3897a45cca39874ae45a0b6880..358bef33f467826ace5549b419c4c4dc7652fcf5 100644 (file)
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.7  2000/07/26 07:04:01  priikone
- *     Added server_find_by_id, replace_[server/client]_id.
- *
- * Revision 1.6  2000/07/17 11:47:30  priikone
- *     Added command lagging support. Added idle counting support.
- *
- * Revision 1.5  2000/07/12 05:59:41  priikone
- *     Major rewrite of ID Cache system. Support added for the new
- *     ID cache system. Major rewrite of ID List stuff on server.  All
- *     SilcXXXList's are now called SilcXXXEntry's and they are pointers
- *     by default. A lot rewritten ID list functions.
- *
- * Revision 1.4  2000/07/06 07:16:13  priikone
- *     Added SilcPublicKey's
- *
- * Revision 1.3  2000/07/05 06:14:01  priikone
- *     Global costemic changes.
- *
- * Revision 1.2  2000/07/03 05:52:11  priikone
- *     Fixed typo and a bug.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:56  priikone
- *     Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
 
 #include "serverincludes.h"
 #include "idlist.h"
@@ -219,6 +191,38 @@ void silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
   }
 }
 
+/* Returns all clients matching requested nickname. Number of clients is
+   returned to `clients_count'. Caller must free the returned table. */
+
+SilcClientEntry *
+silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
+                                   char *server, unsigned int *clients_count)
+{
+  SilcIDCacheList list = NULL;
+  SilcIDCacheEntry id_cache = NULL;
+  SilcClientEntry *clients;
+  int i;
+
+  if (!silc_idcache_find_by_data(id_list->clients, nickname, &list))
+    return NULL;
+
+  clients = silc_calloc(silc_idcache_list_count(list), sizeof(*clients));
+
+  i = 0;
+  silc_idcache_list_first(list, &id_cache);
+  clients[i++] = (SilcClientEntry)id_cache->context;
+
+  while (silc_idcache_list_next(list, &id_cache))
+    clients[i++] = (SilcClientEntry)id_cache->context;
+  
+  silc_idcache_list_free(list);
+  
+  if (clients_count)
+    *clients_count = i;
+
+  return clients;
+}
+
 /* Finds client entry by nickname. */
 
 SilcClientEntry
@@ -373,6 +377,8 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
   channel->id = id;
   channel->router = router;
   channel->channel_key = channel_key;
+  silc_list_init(channel->user_list, struct SilcChannelClientEntryStruct, 
+                next);
 
   if (!silc_idcache_add(id_list->channels, channel->channel_name, 
                        SILC_ID_CHANNEL, (void *)channel->id, 
@@ -389,6 +395,8 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
 void silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
 {
   if (entry) {
+    SilcChannelClientEntry chl;
+
     /* Remove from cache */
     if (entry->id)
       silc_idcache_del_by_id(id_list->channels, SILC_ID_CHANNEL, 
@@ -408,9 +416,12 @@ void silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
       silc_free(entry->key);
     }
     memset(entry->iv, 0, sizeof(entry->iv));
-
-    if (entry->user_list_count)
-      silc_free(entry->user_list);
+    
+    silc_list_start(entry->user_list);
+    while ((chl = silc_list_get(entry->user_list)) != SILC_LIST_END) {
+      silc_list_del(entry->user_list, chl);
+      silc_free(chl);
+    }
   }
 }