- silc_parse_nickname(nickname, &client_entry->nickname,
- &client_entry->server, &client_entry->num);
-
- if (username)
- client_entry->username = strdup(username);
-
- /* Remove the old cache entry and create a new one */
- silc_idcache_del_by_context(conn->client_cache, client_entry);
- silc_idcache_add(conn->client_cache, client_entry->nickname,
- client_entry->id, client_entry, FALSE);
- silc_free(client_id);
+ switch (id_type) {
+ case SILC_ID_CLIENT:
+ client_id = silc_id_payload_get_id(idp);
+
+ SILC_LOG_DEBUG(("Received client information"));
+
+ /* Check if we have this client cached already. */
+ if (!silc_idcache_find_by_id_one_ext(conn->client_cache,
+ (void *)client_id,
+ NULL, NULL,
+ silc_hash_client_id_compare, NULL,
+ &id_cache)) {
+ SILC_LOG_DEBUG(("Adding new client entry"));
+ client_entry =
+ silc_client_add_client(cmd->client, conn, name, info, NULL,
+ silc_id_dup(client_id, id_type), 0);
+ } else {
+ client_entry = (SilcClientEntry)id_cache->context;
+ silc_client_update_client(cmd->client, conn, client_entry,
+ name, info, NULL, 0);
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, client_entry, name, info));
+ break;
+
+ case SILC_ID_SERVER:
+ server_id = silc_id_payload_get_id(idp);
+
+ SILC_LOG_DEBUG(("Received server information"));
+
+ /* Check if we have this server cached already. */
+ if (!silc_idcache_find_by_id_one(conn->server_cache,
+ (void *)server_id, &id_cache)) {
+ SILC_LOG_DEBUG(("Adding new server entry"));
+
+ server_entry = silc_calloc(1, sizeof(*server_entry));
+ server_entry->server_id = silc_id_dup(server_id, id_type);
+ if (name)
+ server_entry->server_name = strdup(name);
+ if (info)
+ server_entry->server_info = strdup(info);
+
+ /* Add server to cache */
+ silc_idcache_add(conn->server_cache, server_entry->server_name,
+ server_entry->server_id, (void *)server_entry, FALSE);
+ } else {
+ server_entry = (SilcServerEntry)id_cache->context;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, server_entry, name, info));
+ break;
+
+ case SILC_ID_CHANNEL:
+ channel_id = silc_id_payload_get_id(idp);
+
+ SILC_LOG_DEBUG(("Received channel information"));
+
+ /* Check if we have this channel cached already. */
+ if (!silc_idcache_find_by_id_one(conn->channel_cache,
+ (void *)channel_id, &id_cache)) {
+ if (!name)
+ break;
+
+ SILC_LOG_DEBUG(("Adding new channel entry"));
+ channel_entry = silc_client_new_channel_id(client, conn->sock,
+ strdup(name), 0, idp);
+ } else {
+ channel_entry = (SilcChannelEntry)id_cache->context;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, channel_entry, name, info));
+ break;