From bd2d5ceea1f1cac3bb4a18c4b6e4be5a08b60bc5 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 25 Feb 2001 18:39:49 +0000 Subject: [PATCH] updates. --- apps/silcd/command.c | 11 ++++- lib/silcclient/command.c | 88 ++++++++++++++++++++++++++++------ lib/silcclient/command_reply.c | 33 ++++++------- 3 files changed, 98 insertions(+), 34 deletions(-) diff --git a/apps/silcd/command.c b/apps/silcd/command.c index c72a18c9..c36b8bdf 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -2976,10 +2976,13 @@ SILC_SERVER_CMD_FUNC(connect) SilcClientEntry client = (SilcClientEntry)cmd->sock->user_data; unsigned char *tmp; unsigned int tmp_len; - unsigned int port; + unsigned int port = SILC_PORT; SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_CONNECT, cmd, 0, 0); + if (!client || cmd->sock->type != SILC_SOCKET_TYPE_CLIENT) + goto out; + /* Check whether client has the permissions. */ if (client->mode == SILC_UMODE_NONE) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, @@ -3036,6 +3039,9 @@ SILC_SERVER_CMD_FUNC(close) SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_CLOSE, cmd, 0, 0); + if (!client || cmd->sock->type != SILC_SOCKET_TYPE_CLIENT) + goto out; + /* Check whether client has the permissions. */ if (client->mode == SILC_UMODE_NONE) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, @@ -3093,6 +3099,9 @@ SILC_SERVER_CMD_FUNC(shutdown) SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_SHUTDOWN, cmd, 0, 0); + if (!client || cmd->sock->type != SILC_SOCKET_TYPE_CLIENT) + goto out; + /* Check whether client has the permission. */ if (client->mode == SILC_UMODE_NONE) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_SHUTDOWN, diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 288a138a..ebb7c577 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -37,7 +37,7 @@ SilcClientCommand silc_command_list[] = SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2), 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, 2), + 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), @@ -52,7 +52,7 @@ SilcClientCommand silc_command_list[] = SILC_CLIENT_CMD(close, CLOSE, "CLOSE", SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2), SILC_CLIENT_CMD(shutdown, SHUTDOWN, "SHUTDOWN", - SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2), + 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(leave, LEAVE, "LEAVE", SILC_CF_LAG | SILC_CF_REG, 2), @@ -617,10 +617,6 @@ SILC_CLIENT_CMD_FUNC(info) silc_client_command_free(cmd); } -SILC_CLIENT_CMD_FUNC(connect) -{ -} - /* Command PING. Sends ping to server. This is used to test the communication channel. */ @@ -684,10 +680,6 @@ SILC_CLIENT_CMD_FUNC(ping) silc_client_command_free(cmd); } -SILC_CLIENT_CMD_FUNC(oper) -{ -} - SILC_CLIENT_CMD_FUNC(trace) { } @@ -1229,6 +1221,59 @@ SILC_CLIENT_CMD_FUNC(kick) silc_client_command_free(cmd); } +SILC_CLIENT_CMD_FUNC(silcoper) +{ +} + +SILC_CLIENT_CMD_FUNC(oper) +{ +} + +/* CONNECT command. Connects the server to another server. */ + +SILC_CLIENT_CMD_FUNC(connect) +{ + SilcClientCommandContext cmd = (SilcClientCommandContext)context; + SilcClientConnection conn = cmd->conn; + SilcBuffer buffer; + unsigned char port[4]; + + 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: /CONNECT []"); + COMMAND_ERROR; + goto out; + } + + if (cmd->argc == 3) + SILC_PUT32_MSB(atoi(cmd->argv[2]), port); + + if (cmd->argc == 3) + buffer = silc_command_payload_encode_va(SILC_COMMAND_CONNECT, 0, 2, + 1, cmd->argv[1], + strlen(cmd->argv[1]), + 2, port, 4); + else + buffer = silc_command_payload_encode_va(SILC_COMMAND_CONNECT, 0, 1, + 1, cmd->argv[1], + strlen(cmd->argv[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); + + /* Notify application */ + COMMAND; + + out: + silc_client_command_free(cmd); +} + SILC_CLIENT_CMD_FUNC(restart) { } @@ -1237,14 +1282,29 @@ SILC_CLIENT_CMD_FUNC(close) { } +/* SHUTDOWN command. Shutdowns the server. */ + SILC_CLIENT_CMD_FUNC(shutdown) { + SilcClientCommandContext cmd = (SilcClientCommandContext)context; + + if (!cmd->conn) { + SILC_NOT_CONNECTED(cmd->client, cmd->conn); + COMMAND_ERROR; + goto out; + } + + /* Send the command */ + silc_client_send_command(cmd->client, cmd->conn, + SILC_COMMAND_SHUTDOWN, 0, 0); + + /* Notify application */ + COMMAND; + + out: + silc_client_command_free(cmd); } -SILC_CLIENT_CMD_FUNC(silcoper) -{ -} - /* LEAVE command. Leaves a channel. Client removes itself from a channel. */ SILC_CLIENT_CMD_FUNC(leave) diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index c026a869..120395ce 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -45,7 +45,6 @@ SilcClientCommandReply silc_command_reply_list[] = SILC_CLIENT_CMD_REPLY(list, LIST), SILC_CLIENT_CMD_REPLY(topic, TOPIC), SILC_CLIENT_CMD_REPLY(invite, INVITE), - SILC_CLIENT_CMD_REPLY(quit, QUIT), SILC_CLIENT_CMD_REPLY(kill, KILL), SILC_CLIENT_CMD_REPLY(info, INFO), SILC_CLIENT_CMD_REPLY(connect, CONNECT), @@ -59,7 +58,7 @@ SilcClientCommandReply silc_command_reply_list[] = SILC_CLIENT_CMD_REPLY(kick, KICK), SILC_CLIENT_CMD_REPLY(restart, RESTART), SILC_CLIENT_CMD_REPLY(close, CLOSE), - SILC_CLIENT_CMD_REPLY(die, DIE), + SILC_CLIENT_CMD_REPLY(shutdown, SHUTDOWN), SILC_CLIENT_CMD_REPLY(silcoper, SILCOPER), SILC_CLIENT_CMD_REPLY(leave, LEAVE), SILC_CLIENT_CMD_REPLY(users, USERS), @@ -626,10 +625,6 @@ SILC_CLIENT_CMD_REPLY_FUNC(invite) silc_client_command_reply_free(cmd); } -SILC_CLIENT_CMD_REPLY_FUNC(quit) -{ -} - SILC_CLIENT_CMD_REPLY_FUNC(kill) { } @@ -681,10 +676,6 @@ SILC_CLIENT_CMD_REPLY_FUNC(info) silc_client_command_reply_free(cmd); } -SILC_CLIENT_CMD_REPLY_FUNC(connect) -{ -} - /* Received reply to PING command. The reply time is shown to user. */ SILC_CLIENT_CMD_REPLY_FUNC(ping) @@ -742,10 +733,6 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping) silc_client_command_reply_free(cmd); } -SILC_CLIENT_CMD_REPLY_FUNC(oper) -{ -} - /* Received reply for JOIN command. */ SILC_CLIENT_CMD_REPLY_FUNC(join) @@ -1037,6 +1024,18 @@ SILC_CLIENT_CMD_REPLY_FUNC(kick) silc_client_command_reply_free(cmd); } +SILC_CLIENT_CMD_REPLY_FUNC(silcoper) +{ +} + +SILC_CLIENT_CMD_REPLY_FUNC(oper) +{ +} + +SILC_CLIENT_CMD_REPLY_FUNC(connect) +{ +} + SILC_CLIENT_CMD_REPLY_FUNC(restart) { } @@ -1045,14 +1044,10 @@ SILC_CLIENT_CMD_REPLY_FUNC(close) { } -SILC_CLIENT_CMD_REPLY_FUNC(die) +SILC_CLIENT_CMD_REPLY_FUNC(shutdown) { } -SILC_CLIENT_CMD_REPLY_FUNC(silcoper) -{ -} - /* Reply to LEAVE command. */ SILC_CLIENT_CMD_REPLY_FUNC(leave) -- 2.43.0