+ /* Check username */
+ silc_parse_userfqdn(username, &tmp, NULL);
+ if (!silc_identifier_verify(tmp, strlen(tmp), SILC_STRING_UTF8, 128)) {
+ silc_free(tmp);
+ silc_free(nick);
+ silc_free(servername);
+ SILC_LOG_ERROR(("Malformed username '%s' received in WHOWAS reply "
+ "from %s",
+ cmd->sock->hostname ? cmd->sock->hostname : "", tmp));
+ return FALSE;
+ }
+ silc_free(tmp);
+
+ silc_free(client->nickname);
+ silc_free(client->username);
+ silc_free(client->servername);
+
+ client->nickname = nick;
+ client->username = strdup(username);
+ client->servername = servername;
+ client->data.status |= SILC_IDLIST_STATUS_RESOLVED;
+ client->data.status &= ~SILC_IDLIST_STATUS_RESOLVING;
+
+ /* 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, nickname, client->id,
+ client, 0, NULL);
+ }
+
+ /* If client is global and is not on any channel then add that we'll
+ expire the entry after a while. */
+ if (global) {
+ silc_idlist_find_client_by_id(server->global_list, client->id,
+ FALSE, &cache);
+ if (!silc_hash_table_count(client->channels))
+ cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
+ else
+ cache->expire = 0;
+ }
+
+ 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;
+ SilcStatus status, error;
+
+ COMMAND_CHECK_STATUS;
+
+ 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_command_process_error(cmd, error);
+ SILC_SERVER_PENDING_EXEC(cmd, SILC_COMMAND_WHOWAS);
+ silc_server_command_reply_free(cmd);
+ return;
+
+ err:
+ silc_server_command_process_error(cmd, error);
+ 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;