Support for SILC 1.2 INVITE and BAN commands. Client supports
[silc.git] / apps / silcd / idlist.c
index 3862582cb9e3f3afec92d3079f3568b7cbcf7bf0..6a4d5f767068236bdd717a67a06bbd02beccebcf 100644 (file)
@@ -90,13 +90,13 @@ void silc_idlist_del_data(void *entry)
 
 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge)
 {
+  SilcServer server = app_context;
   SilcIDListPurge i = (SilcIDListPurge)context;
 
   SILC_LOG_DEBUG(("Purging cache"));
 
   silc_idcache_purge(i->cache);
-  silc_schedule_task_add(i->schedule, 0, 
-                        silc_idlist_purge,
+  silc_schedule_task_add(server->schedule, 0, silc_idlist_purge,
                         (void *)i, i->timeout, 0,
                         SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);
 }
@@ -159,13 +159,13 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
 
   server = (SilcServerEntry)id_cache->context;
 
-  if (ret_entry)
-    *ret_entry = id_cache;
-
   if (server && registered && 
       !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
+  if (ret_entry)
+    *ret_entry = id_cache;
+
   SILC_LOG_DEBUG(("Found"));
 
   return server;
@@ -187,13 +187,13 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
 
   server = (SilcServerEntry)id_cache->context;
   
-  if (ret_entry)
-    *ret_entry = id_cache;
-
   if (server && registered &&
       !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
+  if (ret_entry)
+    *ret_entry = id_cache;
+
   SILC_LOG_DEBUG(("Found"));
 
   return server;
@@ -239,13 +239,13 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
   
   silc_idcache_list_free(list);
 
-  if (ret_entry)
-    *ret_entry = id_cache;
-
   if (server && registered &&
       !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
+  if (ret_entry)
+    *ret_entry = id_cache;
+
   SILC_LOG_DEBUG(("Found"));
 
   return server;
@@ -376,6 +376,7 @@ int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
     silc_free(entry->username);
     silc_free(entry->userinfo);
     silc_free(entry->id);
+    silc_free(entry->attrs);
     silc_hash_table_free(entry->channels);
 
     memset(entry, 'F', sizeof(*entry));
@@ -493,13 +494,13 @@ silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
 
   client = (SilcClientEntry)id_cache->context;
 
-  if (ret_entry)
-    *ret_entry = id_cache;
-
   if (client && registered &&
       !(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
+  if (ret_entry)
+    *ret_entry = id_cache;
+
   SILC_LOG_DEBUG(("Found"));
 
   return client;
@@ -575,6 +576,7 @@ void silc_idlist_client_destructor(SilcIDCache cache,
     silc_free(client->username);
     silc_free(client->userinfo);
     silc_free(client->id);
+    silc_free(client->attrs);
     silc_hash_table_free(client->channels);
 
     memset(client, 'A', sizeof(*client));
@@ -652,6 +654,10 @@ static void silc_idlist_del_channel_foreach(void *key, void *context,
 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
 {
   if (entry) {
+    SilcHashTableList htl;
+    SilcBuffer tmp;
+    SilcUInt32 type;
+
     /* Remove from cache */
     if (!silc_idcache_del_by_context(id_list->channels, entry))
       return FALSE;
@@ -669,6 +675,33 @@ int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
     silc_free(entry->channel_name);
     silc_free(entry->id);
     silc_free(entry->topic);
+
+    if (entry->invite_list) {
+      silc_hash_table_list(entry->invite_list, &htl);
+      while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp)) {
+       if (type == 1) {
+         silc_free((char *)tmp);
+         continue;
+       }
+       silc_buffer_free(tmp);
+      }
+      silc_hash_table_list_reset(&htl);
+      silc_hash_table_free(entry->invite_list);
+    }
+
+    if (entry->ban_list) {
+      silc_hash_table_list(entry->ban_list, &htl);
+      while (silc_hash_table_get(&htl, (void **)&type, (void **)&tmp)) {
+       if (type == 1) {
+         silc_free((char *)tmp);
+         continue;
+       }
+       silc_buffer_free(tmp);
+      }
+      silc_hash_table_list_reset(&htl);
+      silc_hash_table_free(entry->ban_list);
+    }
+
     if (entry->channel_key)
       silc_cipher_free(entry->channel_key);
     if (entry->key) {