X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcclient%2Fidlist.c;h=edd2df0449943a1ece111c5077317c2c1953a8f4;hb=4d35af3be05cacf69ca4bd634973cdcd25118e98;hp=7f632e965ed30ab389f56df3622bebdd5ce66cc3;hpb=e14cef8f772a6f73f05254ae220a3a83981ea753;p=silc.git diff --git a/lib/silcclient/idlist.c b/lib/silcclient/idlist.c index 7f632e96..edd2df04 100644 --- a/lib/silcclient/idlist.c +++ b/lib/silcclient/idlist.c @@ -72,21 +72,23 @@ SilcClientEntry silc_idlist_get_client(SilcClient client, entry = (SilcClientEntry)id_cache->context; } else { /* Check multiple cache entries for match */ - while (silc_idcache_list_next(list, &id_cache)) { - entry = (SilcClientEntry)id_cache->context; - + silc_idcache_list_first(list, &id_cache); + entry = (SilcClientEntry)id_cache->context; + + while (entry) { if (server && entry->server && - strncasecmp(server, entry->server, strlen(server))) { - entry = NULL; - continue; - } + !strncasecmp(server, entry->server, strlen(server))) + break; - if (num && entry->num != num) { + if (num && entry->num == num) + break; + + if (!silc_idcache_list_next(list, &id_cache)) { entry = NULL; - continue; + break; } - break; + entry = (SilcClientEntry)id_cache->context; } /* If match weren't found, request it */ @@ -100,6 +102,32 @@ SilcClientEntry silc_idlist_get_client(SilcClient client, return entry; } +/* Finds client entry from cache by Client ID. If the entry is not found + from the cache this function can query it from the server. */ + +SilcClientEntry silc_idlist_get_client_by_id(SilcClient client, + SilcClientConnection conn, + SilcClientID *client_id, + int query) +{ + SilcIDCacheEntry id_cache; + + /* Find ID from cache */ + if (!silc_idcache_find_by_id_one(conn->client_cache, client_id, + SILC_ID_CLIENT, &id_cache)) { + if (!query) { + return NULL; + } else { + SilcBuffer idp = silc_id_payload_encode(client_id, SILC_ID_CLIENT); + silc_client_send_command(client, conn, SILC_COMMAND_WHOIS, 1, + 2, idp->data, idp->len); + return NULL; + } + } + + return (SilcClientEntry)id_cache->context; +} + /* Finds channel entry from ID cache by channel name. */ SilcChannelEntry silc_idlist_get_channel(SilcClient client,