X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=apps%2Fsilcd%2Fidlist.c;h=e302b6e6bf3ddfed204cdd7fee49e633c4dff14e;hp=8088150e8c1ee1e880ee5ff9d9f9fa4e434d2400;hb=52e57c880aba9c5e89f59d962eb9af75670b76e0;hpb=ae1482a76c29db9fdcd6ed6cf63d312a37a5cb01 diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 8088150e..e302b6e6 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2005, 2007 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -62,23 +62,6 @@ void silc_idlist_del_data(void *entry) idata->public_key = NULL; } -/* Purges ID cache */ - -SILC_TASK_CALLBACK(silc_idlist_purge) -{ - SilcServer server = app_context; - SilcIDListPurge i = (SilcIDListPurge)context; - - SILC_LOG_DEBUG(("Purging cache")); - -#if 0 - /* XXX */ - silc_idcache_purge(i->cache); - silc_schedule_task_add_timeout(server->schedule, silc_idlist_purge, i, - i->timeout, 0); -#endif -} - /****************************************************************************** Server entry functions @@ -380,7 +363,7 @@ silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username, int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry) { - SILC_LOG_DEBUG(("Start")); + SILC_LOG_DEBUG(("Delete client %p", entry)); if (entry) { /* Delete client, destructor will free data */ @@ -459,7 +442,8 @@ int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname, is returned to `clients_count'. Caller must free the returned table. The 'nickname' must be normalized already. */ -int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname, +int silc_idlist_get_clients_by_hash(SilcIDList id_list, + char *nickname, char *server, SilcHash md5hash, SilcClientEntry **clients, SilcUInt32 *clients_count) @@ -468,6 +452,7 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname, SilcIDCacheEntry id_cache = NULL; unsigned char hash[SILC_HASH_MAXLEN]; SilcClientID client_id; + SilcClientEntry client_entry; SILC_LOG_DEBUG(("Start")); @@ -482,6 +467,21 @@ int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname, if (!silc_idcache_find_by_id(id_list->clients, &client_id, &list)) return FALSE; + /* If server is specified, narrow the search with it. */ + if (server) { + silc_list_start(list); + while ((id_cache = silc_list_get(list))) { + client_entry = id_cache->context; + if (!client_entry->servername) + continue; + if (!silc_utf8_strcasecmp(client_entry->servername, server)) + silc_list_del(list, id_cache); + } + } + + if (!silc_list_count(list)) + return FALSE; + *clients = silc_realloc(*clients, (silc_list_count(list) + *clients_count) * sizeof(**clients)); @@ -558,18 +558,17 @@ silc_idlist_replace_client_id(SilcServer server, client = (SilcClientEntry)id_cache->context; - /* Remove the old entry and add a new one */ - - if (!silc_idcache_del_by_context(id_list->clients, client, server)) - return NULL; - /* Check if anyone is watching old nickname */ if (server->server_type == SILC_ROUTER) silc_server_check_watcher_list(server, client, nickname, SILC_NOTIFY_TYPE_NICK_CHANGE); + /* Replace */ + if (!silc_idcache_update(id_list->clients, id_cache, new_id, nicknamec, + TRUE)) + return NULL; + silc_free(client->nickname); - *client->id = *new_id; client->nickname = nickname ? strdup(nickname) : NULL; /* Check if anyone is watching new nickname */ @@ -577,10 +576,6 @@ silc_idlist_replace_client_id(SilcServer server, silc_server_check_watcher_list(server, client, nickname, SILC_NOTIFY_TYPE_NICK_CHANGE); - if (!silc_idcache_add(id_list->clients, nicknamec, client->id, - client)) - return NULL; - SILC_LOG_DEBUG(("Replaced")); return client;