/* $Id$ */
#include "clientlibincludes.h"
+#include "client_internal.h"
/* Client command list. */
SilcClientCommand silc_command_list[] =
SILC_CLIENT_CMD(invite, INVITE, "INVITE", SILC_CF_LAG | SILC_CF_REG, 3),
SILC_CLIENT_CMD(quit, QUIT, "QUIT", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(kill, KILL, "KILL",
- SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
+ SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 3),
SILC_CLIENT_CMD(info, INFO, "INFO", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(connect, CONNECT, "CONNECT",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 3),
SILC_CLIENT_CMD(ping, PING, "PING", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(oper, OPER, "OPER",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
- SILC_CLIENT_CMD(join, JOIN, "JOIN", SILC_CF_LAG | SILC_CF_REG, 4),
+ SILC_CLIENT_CMD(join, JOIN, "JOIN", SILC_CF_LAG | SILC_CF_REG, 5),
SILC_CLIENT_CMD(motd, MOTD, "MOTD", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(umode, UMODE, "UMODE", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(cmode, CMODE, "CMODE", SILC_CF_LAG | SILC_CF_REG, 4),
SILC_CLIENT_CMD(restart, RESTART, "RESTART",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
SILC_CLIENT_CMD(close, CLOSE, "CLOSE",
- SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
+ SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 3),
SILC_CLIENT_CMD(shutdown, SHUTDOWN, "SHUTDOWN",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 1),
- SILC_CLIENT_CMD(silcoper, SILCOPER, "SILOPER",
- SILC_CF_LAG | SILC_CF_REG | SILC_CF_SILC_OPER, 2),
+ SILC_CLIENT_CMD(silcoper, SILCOPER, "SILCOPER",
+ SILC_CF_LAG | SILC_CF_REG | SILC_CF_SILC_OPER, 3),
SILC_CLIENT_CMD(leave, LEAVE, "LEAVE", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(users, USERS, "USERS", SILC_CF_LAG | SILC_CF_REG, 2),
silc_client_command_free(cmd);
}
+/* Command WHOWAS. This command is used to query history information about
+ specific user that used to exist in the network. */
+
SILC_CLIENT_CMD_FUNC(whowas)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcBuffer buffer;
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc < 2 || cmd->argc > 3) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Usage: /WHOWAS <nickname>[@<server>] [<count>]");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ buffer = silc_command_payload_encode(SILC_COMMAND_WHOWAS,
+ cmd->argc - 1, ++cmd->argv,
+ ++cmd->argv_lens, ++cmd->argv_types,
+ 0);
+ silc_client_packet_send(cmd->client, cmd->conn->sock,
+ SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
+ buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+ cmd->argv--;
+ cmd->argv_lens--;
+ cmd->argv_types--;
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
}
/* Command IDENTIFY. This command is used to query information about
buffer = silc_command_payload_encode(SILC_COMMAND_IDENTIFY,
cmd->argc - 1, ++cmd->argv,
++cmd->argv_lens, ++cmd->argv_types,
- 0);
+ ++conn->cmd_ident);
silc_client_packet_send(cmd->client, cmd->conn->sock,
SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
buffer->data, buffer->len, TRUE);
buffer = silc_command_payload_encode(SILC_COMMAND_NICK,
cmd->argc - 1, ++cmd->argv,
++cmd->argv_lens, ++cmd->argv_types,
- 0);
+ ++cmd->conn->cmd_ident);
silc_client_packet_send(cmd->client, cmd->conn->sock,
SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
buffer->data, buffer->len, TRUE);
silc_client_command_free(cmd);
}
+/* Command LIST. Lists channels on the current server. */
+
SILC_CLIENT_CMD_FUNC(list)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcIDCacheEntry id_cache = NULL;
+ SilcChannelEntry channel;
+ SilcBuffer buffer, idp = NULL;
+ char *name;
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc == 2) {
+ name = cmd->argv[1];
+
+ /* Get the Channel ID of the channel */
+ if (silc_idcache_find_by_data_one(conn->channel_cache, name, &id_cache)) {
+ channel = (SilcChannelEntry)id_cache->context;
+ idp = silc_id_payload_encode(id_cache->id, SILC_ID_CHANNEL);
+ }
+ }
+
+ if (!idp)
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_LIST,
+ ++conn->cmd_ident, 0);
+ else
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_LIST,
+ ++conn->cmd_ident, 1,
+ 1, idp->data, idp->len);
+
+ silc_client_packet_send(cmd->client, cmd->conn->sock,
+ SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
+ buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+ if (idp)
+ silc_buffer_free(idp);
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
}
/* Command TOPIC. Sets/shows topic on a channel. */
/* Client entry not found, it was requested thus mark this to be
pending command. */
- silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, 0,
+ silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, conn->cmd_ident,
silc_client_command_destructor,
silc_client_command_invite,
silc_client_command_dup(cmd));
COMMAND;
out:
+ if (nickname)
+ silc_free(nickname);
+ if (server)
+ silc_free(server);
silc_client_command_free(cmd);
}
silc_client_command_free(cmd);
}
+/* Command KILL. Router operator can use this command to remove an client
+ fromthe SILC Network. */
+
SILC_CLIENT_CMD_FUNC(kill)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcBuffer buffer, idp;
+ SilcClientEntry target;
+ unsigned int num = 0;
+ char *nickname = NULL, *server = NULL;
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc < 2) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Usage: /KILL <nickname> [<comment>]");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ /* Parse the typed nickname. */
+ if (!silc_parse_nickname(cmd->argv[1], &nickname, &server, &num)) {
+ cmd->client->ops->say(cmd->client, conn, "Bad nickname");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ /* Get the target client */
+ target = silc_idlist_get_client(cmd->client, conn, nickname,
+ server, num, TRUE);
+ if (!target) {
+ silc_free(nickname);
+ if (server)
+ silc_free(server);
+
+ /* Client entry not found, it was requested thus mark this to be
+ pending command. */
+ silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY,
+ conn->cmd_ident,
+ silc_client_command_destructor,
+ silc_client_command_kill,
+ silc_client_command_dup(cmd));
+ cmd->pending = 1;
+ return;
+ }
+
+ /* Send the KILL command to the server */
+ idp = silc_id_payload_encode(target->id, SILC_ID_CLIENT);
+ if (cmd->argc == 2)
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_KILL, 0, 1,
+ 1, idp->data, idp->len);
+ else
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_KILL, 0, 2,
+ 1, idp->data, idp->len,
+ 2, cmd->argv[2],
+ strlen(cmd->argv[2]));
+ silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
+ 0, NULL, NULL, buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+ silc_buffer_free(idp);
+
+ /* Notify application */
+ COMMAND;
+
+ /* Remove the client entry to be killed */
+ silc_idcache_del_by_id(conn->client_cache, SILC_ID_CLIENT,
+ target->id);
+ if (target->nickname)
+ silc_free(target->nickname);
+ if (target->server)
+ silc_free(target->server);
+ if (target->id)
+ silc_free(target->id);
+ if (target->send_key)
+ silc_cipher_free(target->send_key);
+ if (target->receive_key)
+ silc_cipher_free(target->receive_key);
+ silc_free(target);
+
+ out:
+ if (nickname)
+ silc_free(nickname);
+ if (server)
+ silc_free(server);
+ silc_client_command_free(cmd);
}
/* Command INFO. Request information about specific server. If specific
goto out;
}
- if (cmd->argc < 1 || cmd->argc > 1) {
+ if (cmd->argc < 1 || cmd->argc > 2) {
cmd->client->ops->say(cmd->client, conn,
- "Usage: /MOTD");
+ "Usage: /MOTD [<server>]");
COMMAND_ERROR;
goto out;
}
/* Send TOPIC command to the server */
- buffer = silc_command_payload_encode_va(SILC_COMMAND_MOTD, 0, 1,
- 2, conn->remote_host,
- strlen(conn->remote_host));
+ if (cmd->argc == 1)
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_MOTD, 0, 1,
+ 1, conn->remote_host,
+ strlen(conn->remote_host));
+ else
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_MOTD, 0, 1,
+ 1, cmd->argv[1],
+ cmd->argv_lens[1]);
silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
0, NULL, NULL, buffer->data, buffer->len, TRUE);
silc_buffer_free(buffer);
silc_client_command_free(cmd);
}
-/* UMODE. Set user mode in SILC. */
+/* UMODE. Set/unset user mode in SILC. This is used mainly to unset the
+ modes as client cannot set itself server/router operator privileges. */
SILC_CLIENT_CMD_FUNC(umode)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcBuffer buffer, idp;
+ unsigned char *cp, modebuf[4];
+ unsigned int mode, add, len;
+ int i;
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc < 2) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Usage: /UMODE +|-<modes>");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ mode = conn->local_entry->mode;
+
+ /* Are we adding or removing mode */
+ if (cmd->argv[1][0] == '-')
+ add = FALSE;
+ else
+ add = TRUE;
+
+ /* Parse mode */
+ cp = cmd->argv[1] + 1;
+ len = strlen(cp);
+ for (i = 0; i < len; i++) {
+ switch(cp[i]) {
+ case 'a':
+ if (add) {
+ mode = 0;
+ mode |= SILC_UMODE_SERVER_OPERATOR;
+ mode |= SILC_UMODE_ROUTER_OPERATOR;
+ } else {
+ mode = SILC_UMODE_NONE;
+ }
+ break;
+ case 's':
+ if (add)
+ mode |= SILC_UMODE_SERVER_OPERATOR;
+ else
+ mode &= ~SILC_UMODE_SERVER_OPERATOR;
+ break;
+ case 'r':
+ if (add)
+ mode |= SILC_UMODE_ROUTER_OPERATOR;
+ else
+ mode &= ~SILC_UMODE_ROUTER_OPERATOR;
+ break;
+ default:
+ COMMAND_ERROR;
+ goto out;
+ break;
+ }
+ }
+
+ idp = silc_id_payload_encode(conn->local_id, SILC_ID_CLIENT);
+ SILC_PUT32_MSB(mode, modebuf);
+
+ /* Send the command packet. We support sending only one mode at once
+ that requires an argument. */
+ buffer =
+ silc_command_payload_encode_va(SILC_COMMAND_UMODE, ++conn->cmd_ident, 2,
+ 1, idp->data, idp->len,
+ 2, modebuf, sizeof(modebuf));
+ silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
+ 0, NULL, NULL, buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+ silc_buffer_free(idp);
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
}
/* CMODE command. Sets channel mode. Modes that does not require any arguments
if (!client_entry) {
/* Client entry not found, it was requested thus mark this to be
pending command. */
- silc_client_command_pending(conn, SILC_COMMAND_CUMODE, 0,
+ silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY,
+ conn->cmd_ident,
silc_client_command_destructor,
silc_client_command_cumode,
silc_client_command_dup(cmd));
COMMAND;
out:
+ if (nickname)
+ silc_free(nickname);
+ if (server)
+ silc_free(server);
silc_client_command_free(cmd);
}
if (cmd->argc < 3) {
cmd->client->ops->say(cmd->client, conn,
- "Usage: /KICK <channel> <client> [<comment>]");
+ "Usage: /KICK <channel> <nickname> [<comment>]");
COMMAND_ERROR;
goto out;
}
COMMAND;
out:
+ if (nickname)
+ silc_free(nickname);
+ if (server)
+ silc_free(server);
silc_client_command_free(cmd);
}
-SILC_CLIENT_CMD_FUNC(silcoper)
+/* OPER command. Used to obtain server operator privileges. */
+
+SILC_CLIENT_CMD_FUNC(oper)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcBuffer buffer;
+ unsigned char *auth_data;
+ SilcBuffer auth;
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc < 2) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Usage: /OPER <username> [<public key>]");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc == 3) {
+ /* XXX Get public key */
+ auth_data = NULL;
+ COMMAND_ERROR;
+ goto out;
+ } else {
+ /* Get passphrase */
+
+ auth_data = cmd->client->ops->ask_passphrase(cmd->client, conn);
+ if (!auth_data) {
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ /* Encode the authentication payload */
+ auth = silc_auth_payload_encode(SILC_AUTH_PASSWORD, NULL, 0,
+ auth_data, strlen(auth_data));
+ }
+
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_OPER, 0, 2,
+ 1, cmd->argv[1],
+ strlen(cmd->argv[1]),
+ 2, auth->data, auth->len);
+ silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
+ 0, NULL, NULL, buffer->data, buffer->len, TRUE);
+
+ silc_buffer_free(buffer);
+ silc_buffer_free(auth);
+ memset(auth_data, 0, strlen(auth_data));
+ silc_free(auth_data);
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
}
-SILC_CLIENT_CMD_FUNC(oper)
+/* SILCOPER command. Used to obtain router operator privileges. */
+
+SILC_CLIENT_CMD_FUNC(silcoper)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcBuffer buffer;
+ unsigned char *auth_data;
+ SilcBuffer auth;
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc < 2) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Usage: /SILCOPER <username> [<public key>]");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc == 3) {
+ /* XXX Get public key */
+ auth_data = NULL;
+ COMMAND_ERROR;
+ goto out;
+ } else {
+ /* Get passphrase */
+
+ auth_data = cmd->client->ops->ask_passphrase(cmd->client, conn);
+ if (!auth_data) {
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ /* Encode the authentication payload */
+ auth = silc_auth_payload_encode(SILC_AUTH_PASSWORD, NULL, 0,
+ auth_data, strlen(auth_data));
+ }
+
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_SILCOPER, 0, 2,
+ 1, cmd->argv[1],
+ strlen(cmd->argv[1]),
+ 2, auth->data, auth->len);
+ silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
+ 0, NULL, NULL, buffer->data, buffer->len, TRUE);
+
+ silc_buffer_free(buffer);
+ silc_buffer_free(auth);
+ memset(auth_data, 0, strlen(auth_data));
+ silc_free(auth_data);
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
}
/* CONNECT command. Connects the server to another server. */
if (!cmd->pending) {
/* Send USERS command to the server */
idp = silc_id_payload_encode(id_cache->id, SILC_ID_CHANNEL);
- buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS, 0, 1,
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS,
+ ++conn->cmd_ident, 1,
1, idp->data, idp->len);
silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND,
NULL, 0, NULL, NULL, buffer->data,
/* Register pending callback which will recall this command callback with
same context and reprocesses the command. When reprocessing we actually
display the information on the screen. */
- silc_client_command_pending(conn, SILC_COMMAND_USERS, 0,
+ silc_client_command_pending(conn, SILC_COMMAND_USERS, conn->cmd_ident,
silc_client_command_destructor,
silc_client_command_users,
silc_client_command_dup(cmd));