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
SilcServerEntry
silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
- SilcBool registered, SilcIDCacheEntry *ret_entry)
+ SilcBool registered,
+ SilcIDCacheEntry *ret_entry)
{
SilcIDCacheEntry id_cache = NULL;
SilcServerEntry server;
return FALSE;
}
+/* ID Cache destructor */
+
+void silc_idlist_server_destructor(SilcIDCache cache,
+ SilcIDCacheEntry entry,
+ void *dest_context,
+ void *app_context)
+{
+ silc_free(entry->name);
+}
+
/******************************************************************************
Client 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 */
void *dest_context,
void *app_context)
{
- SilcServer server = app_context;
+ SilcServer server = dest_context;
SilcClientEntry client;
client = (SilcClientEntry)entry->context;
if (client) {
- /* Remove this client from the public key hash list */
+ /* Remove client's public key from repository, this will free it too. */
if (client->data.public_key)
- silc_hash_table_del_by_context(server->pk_hash,
- client->data.public_key, client);
+ silc_skr_del_public_key(server->repository, client->data.public_key,
+ client);
assert(!silc_hash_table_count(client->channels));
silc_free(client->nickname);
silc_free(client->userinfo);
silc_free(client->id);
silc_free(client->attrs);
- if (client->data.public_key)
- silc_pkcs_public_key_free(client->data.public_key);
silc_hash_table_free(client->channels);
memset(client, 'A', sizeof(*client));
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;
NULL, NULL, NULL, TRUE);
if (!silc_idcache_add(id_list->channels, channel_namec,
- (void *)channel->id, (void *)channel /*XXX, expire */)) {
+ (void *)channel->id, (void *)channel)) {
silc_hmac_free(channel->hmac);
silc_hash_table_free(channel->user_list);
silc_free(channel);
return channel;
}
+/* ID Cache destructor */
+
+void silc_idlist_channel_destructor(SilcIDCache cache,
+ SilcIDCacheEntry entry,
+ void *dest_context,
+ void *app_context)
+{
+ silc_free(entry->name);
+}
+
/* Foreach callbcak to free all users from the channel when deleting a
channel entry. */