From 3adb75e88118d286a6e31954c690db2c4229ce17 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 25 Feb 2001 18:39:49 +0000 Subject: [PATCH] updates. --- CHANGES | 4 ++ README | 2 +- apps/silcd/command.c | 41 ++++++------ apps/silcd/idlist.c | 69 ++++++++++++++++++++ apps/silcd/idlist.h | 6 ++ apps/silcd/server.h | 3 + doc/draft-riikonen-silc-spec-01.nroff | 7 +- lib/silcclient/command.c | 45 +++++++++++-- lib/silcclient/command_reply.c | 92 +++++++++++++++++++++++++++ lib/silcclient/command_reply.h | 3 +- 10 files changed, 239 insertions(+), 33 deletions(-) diff --git a/CHANGES b/CHANGES index a0299768..951432b0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +Sun Feb 25 20:47:29 EET 2001 Pekka Riikonen + + * Implemented CONNECT and SHUTDOWN commands in the client. + Sat Feb 24 23:45:49 EET 2001 Pekka Riikonen * DIE command was renamed to SHUTDOWN. Updated the both code diff --git a/README b/README index d396d704..0152f46d 100644 --- a/README +++ b/README @@ -172,7 +172,7 @@ Following commands has been, at least partly, implemented: server operator to be able to do this. - /CLOSE + /CLOSE [] Closes connection to the . You must be server operator to be able to do this. diff --git a/apps/silcd/command.c b/apps/silcd/command.c index c36b8bdf..e09327a0 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -2985,14 +2985,14 @@ SILC_SERVER_CMD_FUNC(connect) /* Check whether client has the permissions. */ if (client->mode == SILC_UMODE_NONE) { - silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, + silc_server_command_send_status_reply(cmd, SILC_COMMAND_CONNECT, SILC_STATUS_ERR_NO_SERVER_PRIV); goto out; } if (server->server_type == SILC_ROUTER && client->mode & SILC_UMODE_SERVER_OPERATOR) { - silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, + silc_server_command_send_status_reply(cmd, SILC_COMMAND_CONNECT, SILC_STATUS_ERR_NO_ROUTER_PRIV); goto out; } @@ -3000,7 +3000,7 @@ SILC_SERVER_CMD_FUNC(connect) /* Get the remote server */ tmp = silc_argument_get_arg_type(cmd->args, 1, &tmp_len); if (!tmp) { - silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, + silc_server_command_send_status_reply(cmd, SILC_COMMAND_CONNECT, SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -3014,7 +3014,7 @@ SILC_SERVER_CMD_FUNC(connect) silc_server_create_connection(server, tmp, port); /* Send reply to the sender */ - silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE, + silc_server_command_send_status_reply(cmd, SILC_COMMAND_CONNECT, SILC_STATUS_OK); out: @@ -3032,10 +3032,11 @@ SILC_SERVER_CMD_FUNC(close) SilcServerCommandContext cmd = (SilcServerCommandContext)context; SilcServer server = cmd->server; SilcClientEntry client = (SilcClientEntry)cmd->sock->user_data; - SilcServerID *server_id; SilcServerEntry server_entry; unsigned char *tmp; unsigned int tmp_len; + unsigned char *name; + unsigned int port = SILC_PORT; SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_CLOSE, cmd, 0, 0); @@ -3049,25 +3050,21 @@ SILC_SERVER_CMD_FUNC(close) goto out; } - /* Get the server ID */ - tmp = silc_argument_get_arg_type(cmd->args, 1, &tmp_len); - if (!tmp) { - silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, - SILC_STATUS_ERR_NO_SERVER_ID); - goto out; - } - server_id = silc_id_payload_parse_id(tmp, tmp_len); - if (!server_id) { + /* Get the remote server */ + name = silc_argument_get_arg_type(cmd->args, 1, &tmp_len); + if (!name) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, - SILC_STATUS_ERR_NO_SERVER_ID); + SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } - /* Check that the server ID is valid and that I have an active - connection to it. Check only local list as it holds the local - connections. */ - server_entry = silc_idlist_find_server_by_id(server->local_list, - server_id, NULL); + /* Get port */ + tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); + if (tmp) + SILC_GET32_MSB(port, tmp); + + server_entry = silc_idlist_find_server_by_conn(server->local_list, + name, port, NULL); if (!server_entry) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, SILC_STATUS_ERR_NO_SERVER_ID); @@ -3081,7 +3078,7 @@ SILC_SERVER_CMD_FUNC(close) "Closed by operator"); /* Send reply to the sender */ - silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE, + silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE, SILC_STATUS_OK); out: @@ -3113,7 +3110,7 @@ SILC_SERVER_CMD_FUNC(shutdown) silc_server_stop(server); /* Send reply to the sender */ - silc_server_command_send_status_reply(cmd, SILC_COMMAND_INVITE, + silc_server_command_send_status_reply(cmd, SILC_COMMAND_SHUTDOWN, SILC_STATUS_OK); out: diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index e50a87be..b4d2f7fe 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -131,6 +131,75 @@ silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id, return server; } +/* Find server by name */ + +SilcServerEntry +silc_idlist_find_server_by_name(SilcIDList id_list, char *name, + SilcIDCacheEntry *ret_entry) +{ + SilcIDCacheEntry id_cache = NULL; + SilcServerEntry server; + + SILC_LOG_DEBUG(("Server by name `%s'", name)); + + if (!silc_idcache_find_by_data_one(id_list->servers, name, &id_cache)) + return NULL; + + server = (SilcServerEntry)id_cache->context; + + if (ret_entry) + *ret_entry = id_cache; + + return server; +} + +/* Find server by connection parameters, hostname and port */ + +SilcServerEntry +silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname, + int port, SilcIDCacheEntry *ret_entry) +{ + SilcIDCacheList list = NULL; + SilcIDCacheEntry id_cache = NULL; + SilcServerEntry server = NULL; + SilcSocketConnection sock; + + SILC_LOG_DEBUG(("Server by hostname %s and port %d", hostname, port)); + + if (!silc_idcache_find_by_id(id_list->servers, SILC_ID_CACHE_ANY, + SILC_ID_SERVER, &list)) + return NULL; + + if (!silc_idcache_list_first(list, &id_cache)) { + silc_idcache_list_free(list); + return NULL; + } + + while (id_cache) { + server = (SilcServerEntry)id_cache->context; + sock = (SilcSocketConnection)server->connection; + + if (sock && (!strcmp(sock->hostname, hostname) || + !strcmp(sock->ip, hostname)) && sock->port == port) + break; + + id_cache = NULL; + server = NULL; + + if (!silc_idcache_list_next(list, &id_cache)) + break; + } + + silc_idcache_list_free(list); + + if (ret_entry) + *ret_entry = id_cache; + + SILC_LOG_DEBUG(("Found")); + + return server; +} + /* Replaces old Server ID with new one */ SilcServerEntry diff --git a/apps/silcd/idlist.h b/apps/silcd/idlist.h index 09292227..444f9108 100644 --- a/apps/silcd/idlist.h +++ b/apps/silcd/idlist.h @@ -463,6 +463,12 @@ SilcServerEntry silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id, SilcIDCacheEntry *ret_entry); SilcServerEntry +silc_idlist_find_server_by_name(SilcIDList id_list, char *name, + SilcIDCacheEntry *ret_entry); +SilcServerEntry +silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname, + int port, SilcIDCacheEntry *ret_entry); +SilcServerEntry silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id, SilcServerID *new_id); void silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry); diff --git a/apps/silcd/server.h b/apps/silcd/server.h index 4d4ab240..2a0e30df 100644 --- a/apps/silcd/server.h +++ b/apps/silcd/server.h @@ -30,6 +30,9 @@ typedef struct SilcServerStruct *SilcServer; /* General definitions */ +/* SILC port */ +#define SILC_PORT 768; + /* Server and router. Used internally by the code. */ #define SILC_SERVER 0 #define SILC_ROUTER 1 diff --git a/doc/draft-riikonen-silc-spec-01.nroff b/doc/draft-riikonen-silc-spec-01.nroff index 1c286fc0..f2558ddc 100644 --- a/doc/draft-riikonen-silc-spec-01.nroff +++ b/doc/draft-riikonen-silc-spec-01.nroff @@ -2855,12 +2855,11 @@ List of all defined commands in SILC follows. 21 SILC_COMMAND_CLOSE - Max Arguments: 1 - Arguments: (1) + Max Arguments: 2 + Arguments: (1) (2) [] This command is used only by operator to close connection to a - remote site. The argument is the ID of the remote - site and must be valid. + remote site. Reply messages to the command: diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index ebb7c577..0afa717b 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -680,10 +680,6 @@ SILC_CLIENT_CMD_FUNC(ping) silc_client_command_free(cmd); } -SILC_CLIENT_CMD_FUNC(trace) -{ -} - SILC_CLIENT_CMD_FUNC(notice) { } @@ -1277,9 +1273,50 @@ SILC_CLIENT_CMD_FUNC(connect) SILC_CLIENT_CMD_FUNC(restart) { } + +/* CLOSE command. Close server connection to the remote server */ SILC_CLIENT_CMD_FUNC(close) { + 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: /CLOSE []"); + 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_CLOSE, 0, 2, + 1, cmd->argv[1], + strlen(cmd->argv[1]), + 2, port, 4); + else + buffer = silc_command_payload_encode_va(SILC_COMMAND_CLOSE, 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); } /* SHUTDOWN command. Shutdowns the server. */ diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 120395ce..b40426b9 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -1034,18 +1034,110 @@ SILC_CLIENT_CMD_REPLY_FUNC(oper) 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. */ diff --git a/lib/silcclient/command_reply.h b/lib/silcclient/command_reply.h index 2bd274ba..d6f9faf1 100644 --- a/lib/silcclient/command_reply.h +++ b/lib/silcclient/command_reply.h @@ -66,7 +66,6 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick); SILC_CLIENT_CMD_REPLY_FUNC(list); SILC_CLIENT_CMD_REPLY_FUNC(topic); SILC_CLIENT_CMD_REPLY_FUNC(invite); -SILC_CLIENT_CMD_REPLY_FUNC(quit); SILC_CLIENT_CMD_REPLY_FUNC(kill); SILC_CLIENT_CMD_REPLY_FUNC(info); SILC_CLIENT_CMD_REPLY_FUNC(links); @@ -84,7 +83,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(cumode); SILC_CLIENT_CMD_REPLY_FUNC(kick); SILC_CLIENT_CMD_REPLY_FUNC(restart); SILC_CLIENT_CMD_REPLY_FUNC(close); -SILC_CLIENT_CMD_REPLY_FUNC(die); +SILC_CLIENT_CMD_REPLY_FUNC(shutdown); SILC_CLIENT_CMD_REPLY_FUNC(silcoper); SILC_CLIENT_CMD_REPLY_FUNC(leave); SILC_CLIENT_CMD_REPLY_FUNC(users); -- 2.24.0