5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
22 #include "clientlibincludes.h"
24 /* Finds client entry from cache by nickname. If the entry is not found
25 from the cache this function queries it from the server. If `server'
26 and `num' are defined as well thisk checks the match from multiple
27 cache entries thus providing support for multiple same nickname
28 handling. This also ignores case-sensitivity. */
30 SilcClientEntry silc_idlist_get_client(SilcClient client,
31 SilcClientConnection conn,
36 SilcIDCacheEntry id_cache;
37 SilcIDCacheList list = NULL;
38 SilcClientEntry entry = NULL;
40 /* Find ID from cache */
41 if (!silc_idcache_find_by_data_loose(conn->client_cache, nickname, &list)) {
42 SilcClientCommandContext ctx;
47 SILC_LOG_DEBUG(("Requesting Client ID from server"));
49 /* No ID found. Do query from the server. The query is done by
50 sending simple IDENTIFY command to the server. */
51 ctx = silc_calloc(1, sizeof(*ctx));
54 ctx->command = silc_client_command_find("IDENTIFY");
55 memset(ident, 0, sizeof(ident));
56 snprintf(ident, sizeof(ident), "IDENTIFY %s", nickname);
57 silc_parse_command_line(ident, &ctx->argv, &ctx->argv_lens,
58 &ctx->argv_types, &ctx->argc, 2);
59 ctx->command->cb(ctx);
62 silc_idcache_list_free(list);
67 if (!server && !num) {
68 /* Take first found cache entry */
69 if (!silc_idcache_list_first(list, &id_cache))
72 entry = (SilcClientEntry)id_cache->context;
74 /* Check multiple cache entries for match */
75 while (silc_idcache_list_next(list, &id_cache)) {
76 entry = (SilcClientEntry)id_cache->context;
78 if (server && entry->server &&
79 strncasecmp(server, entry->server, strlen(server))) {
84 if (num && entry->num != num) {
92 /* If match weren't found, request it */
98 silc_idcache_list_free(list);
103 /* Finds channel entry from ID cache by channel name. */
105 SilcChannelEntry silc_idlist_get_channel(SilcClient client,
106 SilcClientConnection conn,
109 SilcIDCacheEntry id_cache;
110 SilcChannelEntry entry;
112 if (!silc_idcache_find_by_data_one(conn->channel_cache, channel, &id_cache))
115 entry = (SilcChannelEntry)id_cache->context;