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,
37 SilcIDCacheEntry id_cache;
38 SilcIDCacheList list = NULL;
39 SilcClientEntry entry = NULL;
41 /* Find ID from cache */
42 if (!silc_idcache_find_by_data_loose(conn->client_cache, nickname, &list)) {
46 SilcClientCommandContext ctx;
49 SILC_LOG_DEBUG(("Requesting Client ID from server"));
51 /* No ID found. Do query from the server. The query is done by
52 sending simple IDENTIFY command to the server. */
53 ctx = silc_client_command_alloc();
56 ctx->command = silc_client_command_find("IDENTIFY");
57 memset(ident, 0, sizeof(ident));
58 snprintf(ident, sizeof(ident), "IDENTIFY %s", nickname);
59 silc_parse_command_line(ident, &ctx->argv, &ctx->argv_lens,
60 &ctx->argv_types, &ctx->argc, 2);
61 ctx->command->cb(ctx);
64 silc_idcache_list_free(list);
71 if (!server && !num) {
72 /* Take first found cache entry */
73 if (!silc_idcache_list_first(list, &id_cache))
76 entry = (SilcClientEntry)id_cache->context;
78 /* Check multiple cache entries for match */
79 silc_idcache_list_first(list, &id_cache);
80 entry = (SilcClientEntry)id_cache->context;
83 if (server && entry->server &&
84 !strncasecmp(server, entry->server, strlen(server)))
87 if (num && entry->num == num)
90 if (!silc_idcache_list_next(list, &id_cache)) {
95 entry = (SilcClientEntry)id_cache->context;
98 /* If match weren't found, request it */
104 silc_idcache_list_free(list);
109 /* Finds client entry from cache by Client ID. */
111 SilcClientEntry silc_idlist_get_client_by_id(SilcClient client,
112 SilcClientConnection conn,
113 SilcClientID *client_id)
115 SilcIDCacheEntry id_cache;
117 SILC_LOG_DEBUG(("Finding client by ID (%s)",
118 silc_id_render(client_id, SILC_ID_CLIENT)));
120 /* Find ID from cache */
121 if (!silc_idcache_find_by_id_one(conn->client_cache, client_id,
122 SILC_ID_CLIENT, &id_cache))
125 SILC_LOG_DEBUG(("Found"));
127 return (SilcClientEntry)id_cache->context;
130 /* Finds channel entry from ID cache by channel name. */
132 SilcChannelEntry silc_idlist_get_channel(SilcClient client,
133 SilcClientConnection conn,
136 SilcIDCacheEntry id_cache;
137 SilcChannelEntry entry;
139 if (!silc_idcache_find_by_data_one(conn->channel_cache, channel, &id_cache))
142 entry = (SilcChannelEntry)id_cache->context;