Author: Pekka Riikonen <priikone@silcnet.org>
- 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
if (idata->hash)
silc_hash_free(idata->hash);
- if (idata->public_key)
- silc_pkcs_public_key_free(idata->public_key);
idata->hash = NULL;
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
int ret;
ret = silc_parse_userfqdn(username, u, sizeof(u), h, sizeof(h));
- if (!u)
+ if (!ret)
return NULL;
if (!silc_identifier_verify(u, strlen(u), SILC_STRING_UTF8, 128))
return NULL;
}
client = silc_calloc(1, sizeof(*client));
+ if (!client)
+ return NULL;
client->nickname = nickname;
client->username = username ? strdup(username) : NULL;
client->userinfo = userinfo;
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 */
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)
SilcIDCacheEntry id_cache = NULL;
unsigned char hash[SILC_HASH_MAXLEN];
SilcClientID client_id;
+ SilcClientEntry client_entry;
SILC_LOG_DEBUG(("Start"));
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));
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 */
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;