+ silc_parse_userfqdn(nickname, &nick, &servername);
+
+ silc_free(client->nickname);
+ silc_free(client->username);
+
+ client->nickname = nick;
+ client->username = strdup(username);
+ client->servername = servername;
+
+ /* Remove the old cache entry and create a new one */
+ silc_idcache_del_by_context(global ? server->global_list->clients :
+ server->local_list->clients, client);
+ silc_idcache_add(global ? server->global_list->clients :
+ server->local_list->clients, nick, client->id,
+ client, 0, NULL);
+ }
+
+ silc_free(client_id);
+
+ return TRUE;
+}
+
+/* Received reply for WHOWAS command. Cache the client information only for
+ a short period of time. */
+
+SILC_SERVER_CMD_REPLY_FUNC(whowas)
+{
+ SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
+ SilcCommandStatus status;
+
+ COMMAND_CHECK_STATUS_LIST;
+
+ if (!silc_server_command_reply_whowas_save(cmd))
+ goto out;
+
+ /* Pending callbacks are not executed if this was an list entry */
+ if (status != SILC_STATUS_OK &&
+ status != SILC_STATUS_LIST_END) {
+ silc_server_command_reply_free(cmd);
+ return;
+ }
+
+ out:
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WHOWAS);
+ silc_server_command_reply_free(cmd);
+}
+
+/* Caches the received IDENTIFY information. */
+
+static char
+silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd)
+{
+ SilcServer server = cmd->server;
+ SilcUInt32 len, id_len;
+ unsigned char *id_data;
+ char *name, *info;
+ SilcClientID *client_id = NULL;
+ SilcServerID *server_id = NULL;
+ SilcChannelID *channel_id = NULL;
+ SilcClientEntry client;
+ SilcServerEntry server_entry;
+ SilcChannelEntry channel;
+ char global = FALSE;
+ char *nick = NULL;
+ SilcIDPayload idp = NULL;
+ SilcIdType id_type;
+ int expire = 0;
+
+ id_data = silc_argument_get_arg_type(cmd->args, 2, &id_len);
+ if (!id_data)
+ return FALSE;
+ idp = silc_id_payload_parse(id_data, id_len);
+ if (!idp)
+ return FALSE;
+
+ name = silc_argument_get_arg_type(cmd->args, 3, &len);
+ info = silc_argument_get_arg_type(cmd->args, 4, &len);
+
+ id_type = silc_id_payload_get_type(idp);
+
+ switch (id_type) {
+ case SILC_ID_CLIENT:
+ client_id = silc_id_payload_get_id(idp);
+ if (!client_id)
+ goto error;
+
+ SILC_LOG_DEBUG(("Received client information"));
+
+ client = silc_idlist_find_client_by_id(server->local_list,
+ client_id, FALSE, NULL);
+ if (!client) {
+ client = silc_idlist_find_client_by_id(server->global_list, client_id,
+ FALSE, NULL);
+ global = TRUE;
+ }
+ if (!client) {
+ /* If router did not find such Client ID in its lists then this must
+ be bogus client or some router in the net is buggy. */
+ if (server->server_type != SILC_SERVER)
+ goto error;
+
+ /* Take nickname */
+ if (name)
+ silc_parse_userfqdn(name, &nick, NULL);
+
+ /* We don't have that client anywhere, add it. The client is added
+ to global list since server didn't have it in the lists so it must be
+ global. */
+ client = silc_idlist_add_client(server->global_list, nick,
+ info ? strdup(info) : NULL, NULL,
+ client_id, cmd->sock->user_data, NULL,
+ time(NULL) + 300);
+ if (!client) {
+ SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
+ goto error;
+ }
+ client->data.status |= SILC_IDLIST_STATUS_REGISTERED;
+ client->data.status |= SILC_IDLIST_STATUS_RESOLVED;
+ client->data.status &= ~SILC_IDLIST_STATUS_RESOLVING;
+ } else {
+ /* We have the client already, update the data */
+
+ SILC_LOG_DEBUG(("Updating client data"));
+
+ /* Take nickname */
+ if (name) {
+ silc_parse_userfqdn(name, &nick, NULL);
+
+ /* Remove the old cache entry */
+ silc_idcache_del_by_context(global ? server->global_list->clients :
+ server->local_list->clients, client);
+
+ silc_free(client->nickname);
+ client->nickname = nick;
+ }
+
+ if (info) {
+ silc_free(client->username);
+ client->username = strdup(info);