SilcList list;
SilcDList clients;
SilcClientEntry entry;
- char *nicknamec, *parsed = NULL, *format = NULL;
+ char nick[128 + 1], *nicknamec, *parsed = NULL, *format = NULL;
+ char server[256 + 1];
if (!client || !conn || !nickname)
return NULL;
+ /* Get nickname from nickname@server string */
+ silc_parse_userfqdn(nickname, nick, sizeof(nick), server, sizeof(server));
+
/* Parse nickname in case it is formatted */
- if (!silc_client_nickname_parse(client, conn, (char *)nickname, &parsed))
+ if (!silc_client_nickname_parse(client, conn, (char *)nick, &parsed))
return NULL;
if (!get_all && parsed)
- format = (char *)nickname;
+ format = (char *)nick;
if (!parsed) {
- parsed = silc_memdup(nickname, strlen(nickname));
+ parsed = silc_memdup(nick, strlen(nick));
if (!parsed)
return NULL;
}
/* Check multiple cache entries for exact match */
while ((id_cache = silc_list_get(list))) {
entry = id_cache->context;
+
+ /* If server was provided, find entries that either have no server
+ set or have the same server. Ignore those that have different
+ server. */
+ if (server[0] && entry->server &&
+ !silc_utf8_strcasecmp(entry->server, server))
+ continue;
+
if (silc_utf8_strcasecmp(entry->nickname,
format ? format : parsed) &&
(!get_valid || entry->internal.valid)) {
/* Parse server name from the nickname if set */
if (silc_parse_userfqdn(nickname, nick, sizeof(nick),
- serv, sizeof(serv) == 2))
+ serv, sizeof(serv)) == 2)
server = (const char *)serv;
nickname = (const char *)nick;
}
/* Is the requested client formatted already */
- if (!silc_utf8_strcasecmp(client_entry->nickname,
+ if (client_entry->nickname_normalized &&
+ !silc_utf8_strcasecmp(client_entry->nickname,
client_entry->nickname_normalized))
formatted = TRUE;
unformatted = entry;
break;
}
- }
+ }
/* If there are no other unformatted clients and the requested client is
unformatted, just return it. */
return client_entry;
}
- /* If priority formatting then the requested client will get the
+ /* If priority formatting then the requested client will get the
unformatted nickname, and the unformatted client will get a new
formatted nickname. */
if (priority) {
&cp))
return NULL;
- silc_snprintf(client_entry->nickname, sizeof(client_entry->nickname),
+ silc_snprintf(client_entry->nickname, sizeof(client_entry->nickname),
cp);
silc_free(cp);
}
SilcChannelEntry channel)
{
SilcIDCacheEntry id_cache;
- SilcBool ret;
+ SilcBool ret = TRUE;
SilcCipher key;
SilcHmac hmac;
+ char *namec;
if (!channel)
return FALSE;
silc_mutex_lock(conn->internal->lock);
if (silc_idcache_find_by_context(conn->internal->channel_cache, channel,
- &id_cache))
- silc_free(id_cache->name);
- ret = silc_idcache_del_by_context(conn->internal->channel_cache,
- channel, NULL);
+ &id_cache)) {
+ namec = id_cache->name;
+ ret = silc_idcache_del_by_context(conn->internal->channel_cache,
+ channel, NULL);
+ silc_free(namec);
+ }
silc_mutex_unlock(conn->internal->lock);
if (!ret)
SilcServerEntry server)
{
SilcIDCacheEntry id_cache;
- SilcBool ret;
+ SilcBool ret = TRUE;
+ char *namec;
if (!server)
return FALSE;
silc_mutex_lock(conn->internal->lock);
if (silc_idcache_find_by_context(conn->internal->server_cache, server,
- &id_cache))
- silc_free(id_cache->name);
- ret = silc_idcache_del_by_context(conn->internal->server_cache,
- server, NULL);
+ &id_cache)) {
+ namec = id_cache->name;
+ ret = silc_idcache_del_by_context(conn->internal->server_cache,
+ server, NULL);
+ silc_free(namec);
+ }
silc_mutex_unlock(conn->internal->lock);
silc_free(server->server_name);