X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=apps%2Fsilcd%2Fidlist.c;h=f762787fe80af56f9e921192b0bb14947bafccce;hp=3de0c40e854f5cb86b6c0e5f76be07924d6433af;hb=e5d8d3db6caa344b3d419b884556c21b15e7d123;hpb=ee2d310105a20fe8b07ce042395187364e1bd58e diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 3de0c40e..f762787f 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -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. */ @@ -77,10 +79,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 +126,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 +146,12 @@ 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; } @@ -151,7 +159,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; @@ -166,6 +174,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; @@ -175,7 +187,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; @@ -213,6 +226,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; @@ -237,11 +254,14 @@ silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id, return NULL; server = (SilcServerEntry)id_cache->context; + + /* Remove the old entry and add a new one */ + + silc_idcache_del_by_id(id_list->servers, (void *)server->id); + silc_free(server->id); server->id = new_id; - /* Remove the old entry and add a new one */ - silc_idcache_del_by_context(id_list->servers, server); silc_idcache_add(id_list->servers, server->server_name, server->id, server, FALSE); @@ -263,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); @@ -334,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); @@ -362,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")); @@ -373,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; } @@ -400,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")); @@ -420,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; } @@ -440,7 +446,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; @@ -466,6 +472,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; @@ -496,13 +506,15 @@ silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id, return NULL; client = (SilcClientEntry)id_cache->context; - silc_free(client->id); - client->id = new_id; /* Remove the old entry and add a new one */ + silc_idcache_del_by_context(id_list->clients, client); - silc_idcache_add(id_list->clients, client->nickname, client->id, - client, FALSE); + + silc_free(client->id); + client->id = new_id; + + silc_idcache_add(id_list->clients, NULL, client->id, client, FALSE); SILC_LOG_DEBUG(("Replaced")); @@ -550,6 +562,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; @@ -557,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; } @@ -604,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 @@ -708,11 +717,14 @@ silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id, return NULL; channel = (SilcChannelEntry)id_cache->context; + + /* Remove the old entry and add a new one */ + + silc_idcache_del_by_id(id_list->channels, (void *)channel->id); + silc_free(channel->id); channel->id = new_id; - /* Remove the old entry and add a new one */ - silc_idcache_del_by_context(id_list->channels, channel); silc_idcache_add(id_list->channels, channel->channel_name, channel->id, channel, FALSE);