/*
* $Id$
* $Log$
+ * Revision 1.8 2000/07/12 05:56:32 priikone
+ * Major rewrite of ID Cache system. Support added for the new
+ * ID cache system.
+ *
* Revision 1.7 2000/07/10 05:40:33 priikone
* Minor bug fixes.
*
win->remote_port = -1;
win->sock = NULL;
+ /* Initialize ID caches */
+ win->client_cache = silc_idcache_alloc(0);
+ win->channel_cache = silc_idcache_alloc(0);
+ win->server_cache = silc_idcache_alloc(0);
+
/* Create the actual screen */
screen = (void *)silc_screen_create_output_window(client->screen);
silc_screen_create_input_window(client->screen);
win->screen = silc_screen_add_output_window(client->screen);
win->sock = NULL;
+ /* Initialize ID caches */
+ win->client_cache = silc_idcache_alloc(0);
+ win->channel_cache = silc_idcache_alloc(0);
+ win->server_cache = silc_idcache_alloc(0);
+
/* Add the window to windows table */
client->windows = silc_realloc(client->windows, sizeof(*client->windows)
* (client->windows_count + 1));
SilcSocketConnection sock)
{
SilcClientWindow win;
- int i;
/* We won't listen for this connection anymore */
silc_schedule_unset_listen_fd(sock->sock);
/* XXX Free all client entries and channel entries. */
/* Clear ID caches */
- for (i = 0; i < 96; i++)
- silc_idcache_del_all(&win->client_id_cache[i],
- win->client_id_cache_count[i]);
- for (i = 0; i < 96; i++)
- silc_idcache_del_all(&win->channel_id_cache[i],
- win->channel_id_cache_count[i]);
+ silc_idcache_del_all(win->client_cache);
+ silc_idcache_del_all(win->channel_cache);
/* Free data */
if (win->remote_host)
unsigned char *id_string)
{
SilcClientWindow win = (SilcClientWindow)sock->user_data;
- char *nickname = win->nickname;
-
-#define CIDC(x) win->client_id_cache[(x) - 32]
-#define CIDCC(x) win->client_id_cache_count[(x) - 32]
/* Delete old ID from ID cache */
- silc_idcache_del_by_id(CIDC(nickname[0]), CIDCC(nickname[0]),
- SILC_ID_CLIENT, win->local_id);
+ silc_idcache_del_by_id(win->client_cache, SILC_ID_CLIENT, win->local_id);
/* Save the new ID */
if (win->local_id)
win->local_entry->id = win->local_id;
/* Put it to the ID cache */
- CIDCC(nickname[0]) = silc_idcache_add(&CIDC(nickname[0]),
- CIDCC(nickname[0]),
- win->nickname, SILC_ID_CLIENT,
- win->local_id,
- (void *)win->local_entry);
-#undef CIDC
-#undef CIDCC
+ silc_idcache_add(win->client_cache, win->nickname, SILC_ID_CLIENT,
+ win->local_id, (void *)win->local_entry, TRUE);
}
/* Processed received Channel ID for a channel. This is called when client
SILC_LOG_DEBUG(("New channel ID"));
-#define CIDC(x) win->channel_id_cache[(x) - 32]
-#define CIDCC(x) win->channel_id_cache_count[(x) - 32]
-
id = silc_id_str2id(id_string, SILC_ID_CHANNEL);
channel = silc_calloc(1, sizeof(*channel));
channel->channel_name = channel_name;
win->current_channel = channel;
/* Put it to the ID cache */
- CIDCC(channel_name[0]) = silc_idcache_add(&CIDC(channel_name[0]),
- CIDCC(channel_name[0]),
- channel_name, SILC_ID_CHANNEL,
- id, (void *)channel);
-#undef CIDC
-#undef CIDCC
+ silc_idcache_add(win->channel_cache, channel_name, SILC_ID_CHANNEL,
+ (void *)id, (void *)channel, TRUE);
}
/* Processes received key for channel. The received key will be used
SilcSocketConnection sock,
SilcBuffer packet)
{
- int i;
unsigned char *id_string, *key, *cipher;
unsigned int key_len;
SilcClientWindow win = (SilcClientWindow)sock->user_data;
SilcChannelID *id;
- SilcIDCache *id_cache = NULL;
+ SilcIDCacheEntry id_cache = NULL;
SilcChannelEntry channel;
SilcChannelKeyPayload payload;
SILC_LOG_DEBUG(("Received key for channel"));
-#define CIDC(x) win->channel_id_cache[(x)]
-#define CIDCC(x) win->channel_id_cache_count[(x)]
-
payload = silc_channel_key_parse_payload(packet);
if (!payload)
return;
}
id = silc_id_str2id(id_string, SILC_ID_CHANNEL);
- /* Find channel. XXX: This is bad and slow. */
- for (i = 0; i < 96; i++) {
- if (CIDC(i) == NULL)
- continue;
- if (silc_idcache_find_by_id(CIDC(i), CIDCC(i), (void *)id,
- SILC_ID_CHANNEL, &id_cache))
- break;
- }
-
- if (!id_cache)
+ /* Find channel. */
+ if (!silc_idcache_find_by_id_one(win->channel_cache, (void *)id,
+ SILC_ID_CHANNEL, &id_cache))
goto out;
-
+
/* Save the key */
key = silc_channel_key_get_key(payload, &key_len);
cipher = silc_channel_key_get_cipher(payload, NULL);
out:
silc_free(id);
silc_channel_key_free_payload(payload);
-#undef CIDC
-#undef CIDCC
}
/* Process received message to a channel (or from a channel, really). This
SilcSocketConnection sock,
SilcPacketContext *packet)
{
- int i;
SilcClientWindow win = (SilcClientWindow)sock->user_data;
SilcBuffer buffer = packet->buffer;
SilcChannelPayload payload = NULL;
SilcChannelID *id = NULL;
SilcChannelEntry channel;
- SilcIDCache *id_cache = NULL;
-
-#define CIDC(x) win->channel_id_cache[(x)]
-#define CIDCC(x) win->channel_id_cache_count[(x)]
+ SilcIDCacheEntry id_cache = NULL;
/* Sanity checks */
if (packet->dst_id_type != SILC_ID_CHANNEL)
id = silc_id_str2id(packet->dst_id, SILC_ID_CHANNEL);
/* Find the channel entry from channels on this window */
- for (i = 0; i < 96; i++) {
- if (CIDC(i) == NULL)
- continue;
- if (silc_idcache_find_by_id(CIDC(i), CIDCC(i), (void *)id,
- SILC_ID_CHANNEL, &id_cache))
- break;
- }
-
- if (!id_cache)
+ if (!silc_idcache_find_by_id_one(win->channel_cache, (void *)id,
+ SILC_ID_CHANNEL, &id_cache))
goto out;
channel = (SilcChannelEntry)id_cache->context;
silc_free(id);
if (payload)
silc_channel_free_payload(payload);
-#undef CIDC
-#undef CIDCC
}