updates.
[silc.git] / apps / silcd / idlist.c
index cb18b18b559dbf596477061e1abf02ea7fa27372..f762787fe80af56f9e921192b0bb14947bafccce 100644 (file)
@@ -43,7 +43,9 @@ 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;
+
+  data->created = time(0);     /* Update creation time */
 }
 
 /* Free's all data in the common ID entry data structure. */
@@ -144,7 +146,8 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
   if (ret_entry)
     *ret_entry = id_cache;
 
-  if (server && registered && !server->data.registered)
+  if (server && registered && 
+      !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
   SILC_LOG_DEBUG(("Found"));
@@ -171,7 +174,8 @@ silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
   if (ret_entry)
     *ret_entry = id_cache;
 
-  if (server && registered && !server->data.registered)
+  if (server && registered &&
+      !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
   SILC_LOG_DEBUG(("Found"));
@@ -222,7 +226,8 @@ silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
   if (ret_entry)
     *ret_entry = id_cache;
 
-  if (server && registered && !server->data.registered)
+  if (server && registered &&
+      !(server->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
   SILC_LOG_DEBUG(("Found"));
@@ -278,10 +283,8 @@ int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry)
        return FALSE;
 
     /* Free data */
-    if (entry->server_name)
-      silc_free(entry->server_name);
-    if (entry->id)
-      silc_free(entry->id);
+    silc_free(entry->server_name);
+    silc_free(entry->id);
 
     memset(entry, 'F', sizeof(*entry));
     silc_free(entry);
@@ -349,14 +352,10 @@ int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
        return FALSE;
 
     /* Free data */
-    if (entry->nickname)
-      silc_free(entry->nickname);
-    if (entry->username)
-      silc_free(entry->username);
-    if (entry->userinfo)
-      silc_free(entry->userinfo);
-    if (entry->id)
-      silc_free(entry->id);
+    silc_free(entry->nickname);
+    silc_free(entry->username);
+    silc_free(entry->userinfo);
+    silc_free(entry->id);
 
     memset(entry, 'F', sizeof(*entry));
     silc_free(entry);
@@ -377,7 +376,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"));
 
@@ -388,18 +386,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;
 }
@@ -415,7 +410,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"));
@@ -435,18 +429,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;
 }
@@ -481,7 +472,8 @@ silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
   if (ret_entry)
     *ret_entry = id_cache;
 
-  if (client && registered && !client->data.registered)
+  if (client && registered &&
+      !(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
     return NULL;
 
   SILC_LOG_DEBUG(("Found"));
@@ -522,8 +514,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"));
 
@@ -580,8 +571,9 @@ silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
   channel->router = router;
   channel->channel_key = channel_key;
   channel->hmac = hmac;
+  channel->created = time(0);
   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;
     }
@@ -627,24 +619,18 @@ int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry)
        return FALSE;
 
     /* Free data */
-    if (entry->channel_name)
-      silc_free(entry->channel_name);
-    if (entry->id)
-      silc_free(entry->id);
-    if (entry->topic)
-      silc_free(entry->topic);
+    silc_free(entry->channel_name);
+    silc_free(entry->id);
+    silc_free(entry->topic);
     if (entry->channel_key)
       silc_cipher_free(entry->channel_key);
     if (entry->key) {
       memset(entry->key, 0, entry->key_len / 8);
       silc_free(entry->key);
     }
-    if (entry->cipher)
-      silc_free(entry->cipher);
-    if (entry->hmac_name)
-      silc_free(entry->hmac_name);
-    if (entry->rekey)
-      silc_free(entry->rekey);
+    silc_free(entry->cipher);
+    silc_free(entry->hmac_name);
+    silc_free(entry->rekey);
 
     /* Free all client entrys from the users list. The silc_hash_table_free
        will free all the entries so they are not freed at the foreach