+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_KICK);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_KICK);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(silcoper)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_SILCOPER);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_SILCOPER);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(oper)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn,
+ SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_OPER);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_OPER);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(connect)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_CONNECT);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_CONNECT);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(ban)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ SilcIDCacheEntry id_cache = NULL;
+ SilcChannelEntry channel;
+ SilcChannelID *channel_id;
+ unsigned char *tmp;
+ uint32 len;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Take Channel ID */
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ if (!tmp)
+ goto out;
+
+ channel_id = silc_id_payload_parse_id(tmp, len);
+ if (!channel_id)
+ goto out;
+
+ /* Get the channel entry */
+ if (!silc_idcache_find_by_id_one(conn->channel_cache, (void *)channel_id,
+ &id_cache)) {
+ silc_free(channel_id);
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ channel = (SilcChannelEntry)id_cache->context;
+
+ /* Get the ban list */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, channel, tmp));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_BAN);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_BAN);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(close)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_CLOSE);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_CLOSE);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(shutdown)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_SHUTDOWN);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_SHUTDOWN);
+ silc_client_command_reply_free(cmd);
+}
+
+/* Reply to LEAVE command. */
+
+SILC_CLIENT_CMD_REPLY_FUNC(leave)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_LEAVE);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_LEAVE);
+ silc_client_command_reply_free(cmd);
+}
+
+/* Reply to USERS command. Received list of client ID's and theirs modes
+ on the channel we requested. */
+
+SILC_CLIENT_CMD_REPLY_FUNC(users)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ SilcIDCacheEntry id_cache = NULL;
+ SilcChannelEntry channel;
+ SilcChannelUser chu;
+ SilcChannelID *channel_id = NULL;
+ SilcBuffer client_id_list = NULL;
+ SilcBuffer client_mode_list = NULL;
+ unsigned char *tmp;
+ uint32 tmp_len, list_count;
+ int i;
+ unsigned char **res_argv = NULL;
+ uint32 *res_argv_lens = NULL, *res_argv_types = NULL, res_argc = 0;
+
+ SILC_LOG_DEBUG(("Start"));
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(
+ cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Get channel ID */
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
+ if (!tmp) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+ channel_id = silc_id_payload_parse_id(tmp, tmp_len);
+ if (!channel_id) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Get the list count */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
+ if (!tmp) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+ SILC_GET32_MSB(list_count, tmp);
+
+ /* Get Client ID list */
+ tmp = silc_argument_get_arg_type(cmd->args, 4, &tmp_len);
+ if (!tmp) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ client_id_list = silc_buffer_alloc(tmp_len);
+ silc_buffer_pull_tail(client_id_list, tmp_len);
+ silc_buffer_put(client_id_list, tmp, tmp_len);
+
+ /* Get client mode list */
+ tmp = silc_argument_get_arg_type(cmd->args, 5, &tmp_len);
+ if (!tmp) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ client_mode_list = silc_buffer_alloc(tmp_len);
+ silc_buffer_pull_tail(client_mode_list, tmp_len);
+ silc_buffer_put(client_mode_list, tmp, tmp_len);
+
+ /* Get channel entry */
+ if (!silc_idcache_find_by_id_one(conn->channel_cache, (void *)channel_id,
+ &id_cache)) {
+ /* Resolve the channel from server */
+ silc_idlist_get_channel_by_id(cmd->client, conn, channel_id, TRUE);
+
+ /* Register pending command callback. After we've received the channel
+ information we will reprocess this command reply by re-calling this
+ USERS command reply callback. */
+ silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, conn->cmd_ident,
+ NULL, silc_client_command_reply_users, cmd);
+ return;
+ } else {
+ channel = (SilcChannelEntry)id_cache->context;
+ }
+
+ /* Remove old client list from channel. */
+ silc_list_start(channel->clients);
+ while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
+ silc_list_del(channel->clients, chu);
+ silc_free(chu);
+ }
+
+ /* Cache the received Client ID's and modes. */
+ for (i = 0; i < list_count; i++) {
+ uint16 idp_len;
+ uint32 mode;
+ SilcClientID *client_id;
+ SilcClientEntry client;
+
+ /* Client ID */
+ SILC_GET16_MSB(idp_len, client_id_list->data + 2);
+ idp_len += 4;
+ client_id = silc_id_payload_parse_id(client_id_list->data, idp_len);
+ if (!client_id)
+ continue;
+
+ /* Mode */
+ SILC_GET32_MSB(mode, client_mode_list->data);
+
+ /* Check if we have this client cached already. */
+ id_cache = NULL;
+ silc_idcache_find_by_id_one_ext(conn->client_cache,
+ (void *)client_id,
+ NULL, NULL,
+ silc_hash_client_id_compare, NULL,
+ &id_cache);
+
+ if (!id_cache || !((SilcClientEntry)id_cache->context)->username ||
+ !((SilcClientEntry)id_cache->context)->realname) {
+
+ if (id_cache && id_cache->context) {
+ SilcClientEntry client_entry = (SilcClientEntry)id_cache->context;
+ if (client_entry->status & SILC_CLIENT_STATUS_RESOLVING) {
+ silc_buffer_pull(client_id_list, idp_len);
+ silc_buffer_pull(client_mode_list, 4);
+ continue;
+ }
+ client_entry->status |= SILC_CLIENT_STATUS_RESOLVING;
+ }
+
+ /* No we don't have it (or it is incomplete in information), query
+ it from the server. Assemble argument table that will be sent
+ for the WHOIS command later. */
+ res_argv = silc_realloc(res_argv, sizeof(*res_argv) *
+ (res_argc + 1));
+ res_argv_lens = silc_realloc(res_argv_lens, sizeof(*res_argv_lens) *
+ (res_argc + 1));
+ res_argv_types = silc_realloc(res_argv_types, sizeof(*res_argv_types) *
+ (res_argc + 1));
+ res_argv[res_argc] = client_id_list->data;
+ res_argv_lens[res_argc] = idp_len;
+ res_argv_types[res_argc] = res_argc + 3;
+ res_argc++;
+ } else {
+ /* Found the client, join it to the channel */
+ client = (SilcClientEntry)id_cache->context;
+ chu = silc_calloc(1, sizeof(*chu));
+ chu->client = client;
+ chu->mode = mode;
+ silc_list_add(channel->clients, chu);
+
+ silc_free(client_id);
+ id_cache = NULL;
+ }
+
+ silc_buffer_pull(client_id_list, idp_len);
+ silc_buffer_pull(client_mode_list, 4);
+ }
+
+ /* Query the client information from server if the list included clients
+ that we don't know about. */
+ if (res_argc) {
+ SilcBuffer res_cmd;
+
+ /* Send the WHOIS command to server */
+ silc_client_command_register(cmd->client, SILC_COMMAND_WHOIS, NULL, NULL,
+ silc_client_command_reply_whois_i, 0,
+ ++conn->cmd_ident);
+ res_cmd = silc_command_payload_encode(SILC_COMMAND_WHOIS,
+ res_argc, res_argv, res_argv_lens,
+ res_argv_types, conn->cmd_ident);
+ silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND,
+ NULL, 0, NULL, NULL, res_cmd->data, res_cmd->len,
+ TRUE);
+
+ /* Register pending command callback. After we've received the WHOIS
+ command reply we will reprocess this command reply by re-calling this
+ USERS command reply callback. */
+ silc_client_command_pending(conn, SILC_COMMAND_WHOIS, conn->cmd_ident,
+ NULL, silc_client_command_reply_users, cmd);
+
+ silc_buffer_free(res_cmd);
+ if (channel_id)
+ silc_free(channel_id);
+
+ silc_free(res_argv);
+ silc_free(res_argv_lens);
+ silc_free(res_argv_types);
+ return;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, channel, list_count, client_id_list, client_mode_list));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_USERS);
+ silc_client_command_reply_free(cmd);
+ silc_free(channel_id);
+ if (client_id_list)
+ silc_buffer_free(client_id_list);
+ if (client_mode_list)
+ silc_buffer_free(client_mode_list);
+}
+
+/* Received command reply to GETKEY command. WE've received the remote
+ client's public key. */
+
+SILC_CLIENT_CMD_REPLY_FUNC(getkey)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ SilcIDCacheEntry id_cache;
+ SilcIDPayload idp = NULL;
+ SilcClientID *client_id = NULL;
+ SilcClientEntry client_entry;
+ SilcServerID *server_id = NULL;
+ SilcServerEntry server_entry;
+ SilcSKEPKType type;
+ unsigned char *tmp, *pk;
+ uint32 len;
+ uint16 pk_len;
+ SilcIdType id_type;
+ SilcPublicKey public_key = NULL;
+
+ SILC_LOG_DEBUG(("Start"));
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK) {
+ cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ if (!tmp) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+ idp = silc_id_payload_parse(tmp, len);
+ if (!idp) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Get the public key payload */
+ tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
+ if (tmp) {
+ /* Decode the public key */
+ SILC_GET16_MSB(pk_len, tmp);
+ SILC_GET16_MSB(type, tmp + 2);
+ pk = tmp + 4;
+
+ if (type != SILC_SKE_PK_TYPE_SILC) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ if (!silc_pkcs_public_key_decode(pk, pk_len, &public_key)) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+ }
+
+ id_type = silc_id_payload_get_type(idp);
+ if (id_type == SILC_ID_CLIENT) {
+ /* Received client's public key */
+ client_id = silc_id_payload_get_id(idp);
+ if (!silc_idcache_find_by_id_one_ext(conn->client_cache,
+ (void *)client_id,
+ NULL, NULL,
+ silc_hash_client_id_compare, NULL,
+ &id_cache)) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ client_entry = (SilcClientEntry)id_cache->context;
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, id_type, client_entry, public_key));
+ } else if (id_type == SILC_ID_SERVER) {
+ /* Received server's public key */
+ server_id = silc_id_payload_get_id(idp);
+ if (!silc_idcache_find_by_id_one(conn->server_cache, (void *)server_id,
+ &id_cache)) {
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ server_entry = (SilcServerEntry)id_cache->context;
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS, id_type, server_entry, public_key));
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_GETKEY);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_GETKEY);
+ if (idp)
+ silc_id_payload_free(idp);
+ if (public_key)
+ silc_pkcs_public_key_free(public_key);
+ silc_free(client_id);
+ silc_free(server_id);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(quit)
+{
+ silc_client_command_reply_free(context);
+}
+
+
+/******************************************************************************
+
+ Internal command reply functions
+
+******************************************************************************/
+
+SILC_CLIENT_CMD_REPLY_FUNC(whois_i)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+
+ SILC_LOG_DEBUG(("Start"));
+
+ SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL));
+ if (status != SILC_STATUS_OK &&
+ status != SILC_STATUS_LIST_START &&
+ status != SILC_STATUS_LIST_ITEM &&
+ status != SILC_STATUS_LIST_END)
+ goto out;
+
+ /* Save WHOIS info */
+ silc_client_command_reply_whois_save(cmd, status, FALSE);
+
+ /* Pending callbacks are not executed if this was an list entry */
+ if (status != SILC_STATUS_OK &&
+ status != SILC_STATUS_LIST_END) {
+ silc_client_command_reply_free(cmd);
+ return;
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_WHOIS);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_WHOIS);
+
+ /* If we received notify for invalid ID we'll remove the ID if we
+ have it cached. */
+ if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
+ SilcClientEntry client_entry;
+ uint32 tmp_len;
+ unsigned char *tmp =
+ silc_argument_get_arg_type(silc_command_get_args(cmd->payload),
+ 2, &tmp_len);
+ if (tmp) {
+ SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len);
+ if (client_id) {
+ client_entry = silc_client_get_client_by_id(cmd->client, conn,
+ client_id);
+ if (client_entry)
+ silc_client_del_client(cmd->client, conn, client_entry);
+ silc_free(client_id);
+ }
+ }
+ }
+
+ /* Unregister this command reply */
+ silc_client_command_unregister(cmd->client, SILC_COMMAND_WHOIS,
+ NULL, silc_client_command_reply_whois_i,
+ cmd->ident);
+
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(identify_i)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+
+ SILC_LOG_DEBUG(("Start"));
+
+ SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL));
+ if (status != SILC_STATUS_OK &&
+ status != SILC_STATUS_LIST_START &&
+ status != SILC_STATUS_LIST_ITEM &&
+ status != SILC_STATUS_LIST_END)
+ goto out;
+
+ /* Save IDENTIFY info */
+ silc_client_command_reply_identify_save(cmd, status, FALSE);
+
+ /* Pending callbacks are not executed if this was an list entry */
+ if (status != SILC_STATUS_OK &&
+ status != SILC_STATUS_LIST_END) {
+ silc_client_command_reply_free(cmd);
+ return;
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_IDENTIFY);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_IDENTIFY);
+
+ /* If we received notify for invalid ID we'll remove the ID if we
+ have it cached. */
+ if (status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
+ SilcClientEntry client_entry;
+ uint32 tmp_len;
+ unsigned char *tmp =
+ silc_argument_get_arg_type(silc_command_get_args(cmd->payload),
+ 2, &tmp_len);
+ if (tmp) {
+ SilcClientID *client_id = silc_id_payload_parse_id(tmp, tmp_len);
+ if (client_id) {
+ client_entry = silc_client_get_client_by_id(cmd->client, conn,
+ client_id);
+ if (client_entry)
+ silc_client_del_client(cmd->client, conn, client_entry);
+ silc_free(client_id);
+ }
+ }
+ }
+
+ /* Unregister this command reply */
+ silc_client_command_unregister(cmd->client, SILC_COMMAND_IDENTIFY,
+ NULL, silc_client_command_reply_identify_i,
+ cmd->ident);
+
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(info_i)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+ SilcCommandStatus status;
+ unsigned char *tmp;
+ SilcIDCacheEntry id_cache;
+ SilcServerEntry server;
+ SilcServerID *server_id = NULL;
+ char *server_name, *server_info;
+ uint32 len;
+
+ SILC_LOG_DEBUG(("Start"));
+
+ tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
+ SILC_GET16_MSB(status, tmp);
+ if (status != SILC_STATUS_OK)
+ goto out;
+
+ /* Get server ID */
+ tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+ if (!tmp)
+ goto out;
+
+ server_id = silc_id_payload_parse_id(tmp, len);
+ if (!server_id)
+ goto out;
+
+ /* Get server name */
+ server_name = silc_argument_get_arg_type(cmd->args, 3, NULL);
+ if (!server_name)
+ goto out;
+
+ /* Get server info */
+ server_info = silc_argument_get_arg_type(cmd->args, 4, NULL);
+ if (!server_info)
+ goto out;
+
+ /* See whether we have this server cached. If not create it. */
+ if (!silc_idcache_find_by_id_one(conn->server_cache, (void *)server_id,
+ &id_cache)) {
+ SILC_LOG_DEBUG(("New server entry"));
+ server = silc_calloc(1, sizeof(*server));
+ server->server_name = strdup(server_name);
+ server->server_info = strdup(server_info);
+ server->server_id = silc_id_dup(server_id, SILC_ID_SERVER);
+
+ /* Add it to the cache */
+ silc_idcache_add(conn->server_cache, server->server_name,
+ server->server_id, (void *)server, 0, NULL);
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_INFO);
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_INFO);
+ silc_free(server_id);