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.
23 * Revision 1.1 2000/07/12 05:55:05 priikone
28 #include "clientincludes.h"
30 /* Finds client entry from cache by nickname. If the entry is not found
31 from the cache this function queries it from the server. If `server'
32 and `num' are defined as well thisk checks the match from multiple
33 cache entries thus providing support for multiple same nickname
34 handling. This also ignores case-sensitivity. */
36 SilcClientEntry silc_idlist_get_client(SilcClient client,
42 SilcIDCacheEntry id_cache;
43 SilcIDCacheList list = NULL;
44 SilcClientEntry entry = NULL;
46 /* Find ID from cache */
47 if (!silc_idcache_find_by_data_loose(win->client_cache, nickname, &list)) {
48 SilcClientCommandContext ctx;
53 SILC_LOG_DEBUG(("Requesting Client ID from server"));
55 /* No ID found. Do query from the server. The query is done by
56 sending simple IDENTIFY command to the server. */
57 ctx = silc_calloc(1, sizeof(*ctx));
59 ctx->sock = win->sock;
60 memset(ident, 0, sizeof(ident));
61 snprintf(ident, sizeof(ident), "/IDENTIFY %s", nickname);
62 silc_client_parse_command_line(ident, &ctx->argv, &ctx->argv_lens,
63 &ctx->argv_types, &ctx->argc, 2);
64 silc_client_command_identify(ctx);
67 silc_idcache_list_free(list);
72 if (!server && !num) {
73 /* Take first found cache entry */
74 if (!silc_idcache_list_first(list, &id_cache))
77 entry = (SilcClientEntry)id_cache->context;
79 /* Check multiple cache entries for match */
80 while (silc_idcache_list_next(list, &id_cache)) {
81 entry = (SilcClientEntry)id_cache->context;
83 if (server && entry->server &&
84 strncasecmp(server, entry->server, strlen(server))) {
89 if (num && entry->num != num) {
97 /* If match weren't found, request it */
103 silc_idcache_list_free(list);
108 /* Finds channel entry from ID cache by channel name. */
110 SilcChannelEntry silc_idlist_get_channel(SilcClient client,
111 SilcClientWindow win,
114 SilcIDCacheEntry id_cache;
115 SilcChannelEntry entry;
117 if (!silc_idcache_find_by_data_one(win->channel_cache, channel, &id_cache))
120 entry = (SilcChannelEntry)id_cache->context;