+
+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;
+
+ COMMAND_CHECK_STATUS_I;
+
+ /* Save WHOIS info */
+ silc_client_command_reply_whois_save(cmd, cmd->status, FALSE);
+
+ /* Pending callbacks are not executed if this was an list entry */
+ if (cmd->status != SILC_STATUS_OK &&
+ cmd->status != SILC_STATUS_LIST_END) {
+ silc_client_command_reply_free(cmd);
+ return;
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_WHOIS);
+
+ err:
+ /* If we received notify for invalid ID we'll remove the ID if we
+ have it cached. */
+ if (cmd->error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
+ SilcClientEntry client_entry;
+ SilcUInt32 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, NULL);
+ 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;
+
+ COMMAND_CHECK_STATUS_I;
+
+ /* Save IDENTIFY info */
+ silc_client_command_reply_identify_save(cmd, cmd->status, FALSE);
+
+ /* Pending callbacks are not executed if this was an list entry */
+ if (cmd->status != SILC_STATUS_OK &&
+ cmd->status != SILC_STATUS_LIST_END) {
+ silc_client_command_reply_free(cmd);
+ return;
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_IDENTIFY);
+
+ err:
+ /* If we received notify for invalid ID we'll remove the ID if we
+ have it cached. */
+ if (cmd->error == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
+ SilcClientEntry client_entry;
+ SilcUInt32 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, NULL);
+ 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;
+ unsigned char *tmp;
+ SilcServerEntry server;
+ SilcServerID *server_id = NULL;
+ char *server_name, *server_info;
+ SilcUInt32 len;
+
+ COMMAND_CHECK_STATUS_I;
+
+ /* 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, NULL);
+ 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. */
+ server = silc_client_get_server_by_id(cmd->client, conn, server_id);
+ if (!server) {
+ SILC_LOG_DEBUG(("New server entry"));
+ silc_client_add_server(cmd->client, conn, server_name, server_info,
+ silc_id_dup(server_id, SILC_ID_SERVER));
+ }
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_INFO);
+ silc_free(server_id);
+ err:
+ silc_client_command_reply_free(cmd);
+}
+
+static void silc_client_command_reply_users_i_cb(SilcClient client,
+ SilcClientConnection conn,
+ SilcChannelEntry *channels,
+ SilcUInt32 channels_count,
+ void *context)
+{
+ if (!channels_count) {
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+
+ cmd->status = cmd->error = SILC_STATUS_ERR_NO_SUCH_CHANNEL;
+ SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_get_status_message(cmd->error));
+ COMMAND_REPLY_ERROR(cmd->error);
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+ silc_client_command_reply_free(cmd);
+ return;
+ }
+
+ silc_client_command_reply_users_i(context, NULL);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(users_i)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+
+ COMMAND_CHECK_STATUS_I;
+
+ /* Save USERS info */
+ if (silc_client_command_reply_users_save(
+ cmd, cmd->status, FALSE, TRUE,
+ silc_client_command_reply_users_i_cb,
+ silc_client_command_reply_users_i))
+ return;
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_USERS);
+
+ err:
+ /* Unregister this command reply */
+ silc_client_command_unregister(cmd->client, SILC_COMMAND_USERS,
+ NULL, silc_client_command_reply_users_i,
+ cmd->ident);
+
+ silc_client_command_reply_free(cmd);
+}
+
+/* Private range commands, specific to this implementation (and compatible
+ with SILC Server >= 0.9). */
+
+SILC_CLIENT_CMD_REPLY_FUNC(connect)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+
+ if (cmd->error != SILC_STATUS_OK) {
+ SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_get_status_message(cmd->error));
+ COMMAND_REPLY_ERROR(cmd->error);
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((SILC_ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_PRIV_CONNECT);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(close)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+
+ if (cmd->error != SILC_STATUS_OK) {
+ SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_get_status_message(cmd->error));
+ COMMAND_REPLY_ERROR(cmd->error);
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((SILC_ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_PRIV_CLOSE);
+ silc_client_command_reply_free(cmd);
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(shutdown)
+{
+ SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+ SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
+
+ if (cmd->error != SILC_STATUS_OK) {
+ SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR,
+ "%s", silc_get_status_message(cmd->error));
+ COMMAND_REPLY_ERROR(cmd->error);
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((SILC_ARGS));
+
+ out:
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_PRIV_SHUTDOWN);
+ silc_client_command_reply_free(cmd);
+}