Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* $Id$ */
#include "clientlibincludes.h"
+#include "client_internal.h"
/* Client command reply list. */
SilcClientCommandReply silc_command_reply_list[] =
{ STAT(BAD_NICKNAME), "Bad nickname" },
{ STAT(BAD_CHANNEL), "Bad channel name" },
{ STAT(AUTH_FAILED), "Authentication failed" },
+ { STAT(UNKNOWN_ALGORITHM), "Unsupported algorithm" },
{ 0, NULL }
};
SilcClient client = cmd->client;
SilcCommandStatus status;
SilcIDPayload idp = NULL;
+ SilcChannelEntry channel;
unsigned int argc, mode, len;
- char *topic, *tmp, *channel_name = NULL;
+ char *topic, *tmp, *channel_name = NULL, *hmac;
SilcBuffer keyp;
SILC_LOG_DEBUG(("Start"));
silc_buffer_put(keyp, tmp, len);
/* Get topic */
- topic = silc_argument_get_arg_type(cmd->args, 8, NULL);
+ topic = silc_argument_get_arg_type(cmd->args, 9, NULL);
- /* Save received Channel ID */
- silc_client_new_channel_id(cmd->client, cmd->sock, channel_name,
- mode, idp);
+ /* Save received Channel ID. This actually creates the channel */
+ channel = silc_client_new_channel_id(cmd->client, cmd->sock, channel_name,
+ mode, idp);
silc_id_payload_free(idp);
+ /* Get hmac */
+ hmac = silc_argument_get_arg_type(cmd->args, 10, NULL);
+ if (hmac) {
+ if (!silc_hmac_alloc(hmac, NULL, &channel->hmac)) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Cannot join channel: Unsupported HMAC `%s'",
+ hmac);
+ COMMAND_REPLY_ERROR;
+ silc_free(channel_name);
+ goto out;
+ }
+ }
+
/* Save channel key */
- silc_client_save_channel_key(conn, keyp, conn->current_channel);
+ silc_client_save_channel_key(conn, keyp, channel);
silc_buffer_free(keyp);
if (topic)
"Topic for %s: %s", channel_name, topic);
/* Notify application */
- COMMAND_REPLY((ARGS, channel_name, conn->current_channel, mode,
- NULL, NULL, topic));
+ COMMAND_REPLY((ARGS, channel_name, channel, mode, NULL, NULL, topic, hmac));
/* Execute any pending command callbacks */
SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_JOIN);
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->ops->say(cmd->client, conn,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ /* Execute any pending command callbacks */
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_CONNECT);
+
+ out:
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_CONNECT);
+ silc_client_command_reply_free(cmd);
}
SILC_CLIENT_CMD_REPLY_FUNC(restart)
{
+ 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->ops->say(cmd->client, conn,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ /* Execute any pending command callbacks */
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_RESTART);
+
+ out:
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_RESTART);
+ 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->ops->say(cmd->client, conn,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ /* Execute any pending command callbacks */
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_CLOSE);
+
+ out:
+ 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->ops->say(cmd->client, conn,
+ "%s", silc_client_command_status_message(status));
+ COMMAND_REPLY_ERROR;
+ goto out;
+ }
+
+ /* Notify application */
+ COMMAND_REPLY((ARGS));
+
+ /* Execute any pending command callbacks */
+ SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_SHUTDOWN);
+
+ out:
+ SILC_CLIENT_PENDING_DESTRUCTOR(cmd, SILC_COMMAND_SHUTDOWN);
+ silc_client_command_reply_free(cmd);
}
/* Reply to LEAVE command. */