updates.
[silc.git] / apps / silcd / idlist.c
index 4e5f5272a8c7305dcd7bfc7b2936b7a566d9d3de..5788e65656a497a5f81c1e9e62998b0af0c1f612 100644 (file)
@@ -43,7 +43,7 @@ void silc_idlist_add_data(void *entry, SilcIDListData idata)
   data->public_key = idata->public_key;
   data->last_receive = idata->last_receive;
   data->last_sent = idata->last_sent;
-  data->registered = idata->registered;
+  data->status = idata->status;
 }
 
 /* Free's all data in the common ID entry data structure. */
@@ -77,10 +77,10 @@ SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge)
   SILC_LOG_DEBUG(("Start"));
 
   silc_idcache_purge(i->cache);
-  silc_task_register(i->timeout_queue, 0, 
-                    silc_idlist_purge,
-                    (void *)i, 600, 0,
-                    SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);
+  silc_schedule_task_add(i->schedule, 0, 
+                        silc_idlist_purge,
+                        (void *)i, 600, 0,
+                        SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);
 }
 
 /******************************************************************************
@@ -124,7 +124,7 @@ silc_idlist_add_server(SilcIDList id_list,
 
 SilcServerEntry
 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
-                             SilcIDCacheEntry *ret_entry)
+                             bool registered, SilcIDCacheEntry *ret_entry)
 {
   SilcIDCacheEntry id_cache = NULL;
   SilcServerEntry server;
@@ -144,6 +144,10 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
   if (ret_entry)
     *ret_entry = id_cache;
 
+  if (server && registered && 
+      !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
+    return NULL;
+
   SILC_LOG_DEBUG(("Found"));
 
   return server;
@@ -153,7 +157,7 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
 
 SilcServerEntry
 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
-                               SilcIDCacheEntry *ret_entry)
+                               bool registered, SilcIDCacheEntry *ret_entry)
 {
   SilcIDCacheEntry id_cache = NULL;
   SilcServerEntry server;
@@ -168,6 +172,10 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
   if (ret_entry)
     *ret_entry = id_cache;
 
+  if (server && registered &&
+      !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
+    return NULL;
+
   SILC_LOG_DEBUG(("Found"));
 
   return server;
@@ -177,7 +185,8 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
 
 SilcServerEntry
 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
-                               int port, SilcIDCacheEntry *ret_entry)
+                               int port, bool registered,
+                               SilcIDCacheEntry *ret_entry)
 {
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;
@@ -215,6 +224,10 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
   if (ret_entry)
     *ret_entry = id_cache;
 
+  if (server && registered &&
+      !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
+    return NULL;
+
   SILC_LOG_DEBUG(("Found"));
 
   return server;
@@ -367,7 +380,6 @@ int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
 {
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;
-  int i;
 
   SILC_LOG_DEBUG(("Start"));
 
@@ -378,18 +390,15 @@ int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
                          (silc_idcache_list_count(list) + *clients_count) * 
                          sizeof(**clients));
 
-  i = 0;
   silc_idcache_list_first(list, &id_cache);
-  (*clients)[i++] = (SilcClientEntry)id_cache->context;
+  (*clients)[(*clients_count)++] = (SilcClientEntry)id_cache->context;
 
   while (silc_idcache_list_next(list, &id_cache))
-    (*clients)[i++] = (SilcClientEntry)id_cache->context;
+    (*clients)[(*clients_count)++] = (SilcClientEntry)id_cache->context;
   
   silc_idcache_list_free(list);
   
-  *clients_count += i;
-
-  SILC_LOG_DEBUG(("Found %d clients", *clients_count));
+  SILC_LOG_DEBUG(("Found total %d clients", *clients_count));
 
   return TRUE;
 }
@@ -405,7 +414,6 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
   SilcIDCacheList list = NULL;
   SilcIDCacheEntry id_cache = NULL;
   unsigned char hash[32];
-  int i;
   SilcClientID client_id;
 
   SILC_LOG_DEBUG(("Start"));
@@ -425,18 +433,15 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
                          (silc_idcache_list_count(list) + *clients_count) * 
                          sizeof(**clients));
 
-  i = 0;
   silc_idcache_list_first(list, &id_cache);
-  (*clients)[i++] = (SilcClientEntry)id_cache->context;
+  (*clients)[(*clients_count)++] = (SilcClientEntry)id_cache->context;
 
   while (silc_idcache_list_next(list, &id_cache))
-    (*clients)[i++] = (SilcClientEntry)id_cache->context;
+    (*clients)[(*clients_count)++] = (SilcClientEntry)id_cache->context;
   
   silc_idcache_list_free(list);
   
-  *clients_count += i;
-
-  SILC_LOG_DEBUG(("Found %d clients", *clients_count));
+  SILC_LOG_DEBUG(("Found total %d clients", *clients_count));
 
   return TRUE;
 }
@@ -445,7 +450,7 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
 
 SilcClientEntry
 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
-                             SilcIDCacheEntry *ret_entry)
+                             bool registered, SilcIDCacheEntry *ret_entry)
 {
   SilcIDCacheEntry id_cache = NULL;
   SilcClientEntry client;
@@ -471,6 +476,10 @@ silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
   if (ret_entry)
     *ret_entry = id_cache;
 
+  if (client && registered &&
+      !(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
+    return NULL;
+
   SILC_LOG_DEBUG(("Found"));
 
   return client;
@@ -509,8 +518,7 @@ silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
   silc_free(client->id);
   client->id = new_id;
 
-  silc_idcache_add(id_list->clients, client->nickname, client->id, 
-                  client, FALSE);
+  silc_idcache_add(id_list->clients, NULL, client->id, client, FALSE);
 
   SILC_LOG_DEBUG(("Replaced"));
 
@@ -558,6 +566,8 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
 {
   SilcChannelEntry channel;
 
+  SILC_LOG_DEBUG(("Adding new channel entry"));
+
   channel = silc_calloc(1, sizeof(*channel));
   channel->channel_name = channel_name;
   channel->mode = mode;
@@ -566,7 +576,7 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
   channel->channel_key = channel_key;
   channel->hmac = hmac;
   if (!channel->hmac)
-    if (!silc_hmac_alloc("hmac-sha1-96", NULL, &channel->hmac)) {
+    if (!silc_hmac_alloc(SILC_DEFAULT_HMAC, NULL, &channel->hmac)) {
       silc_free(channel);
       return NULL;
     }