From cf91a4b631e7ab5382a0dd41613fb4f1f492f0c2 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 27 Apr 2005 10:52:22 +0000 Subject: [PATCH] Added SERVICE command (incomplete implementation). --- CHANGES | 8 ++++++ apps/silcd/command.c | 45 +++++++++++++++++++++++++++++++++ apps/silcd/command.h | 22 ++++++++-------- lib/doc/command_reply_args.html | 14 ++++++++++ lib/silcclient/command.c | 43 +++++++++++++++++++++++++++++++ lib/silcclient/command.h | 3 ++- lib/silcclient/command_reply.c | 26 +++++++++++++++++++ lib/silcclient/command_reply.h | 3 ++- 8 files changed, 151 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index 50d30b83..347171e7 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,14 @@ Wed Apr 27 11:49:41 EEST 2005 Pekka Riikonen * A comma in invite/ban string is invalid, check for it. Affected file apps/silcd/server_util.c. + * Added SERVICE command to the server. It parses the command + request but SILC Server does not support services for the + time being. Affected file apps/silcd/command.[ch]. + + * Added SERVICE command and command reply to client library. + It is however incomplete. Updated Toolkit documentation. + Affected files are lib/silcclient/command[_reply].[ch]. + Mon Apr 25 14:25:24 EEST 2005 Pekka Riikonen * Moved silcer/, silc/, silcd/ and irssi/ to apps/. This diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 67e2ad48..927e14cc 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -74,6 +74,7 @@ SilcServerCommand silc_command_list[] = SILC_SERVER_CMD(leave, LEAVE, SILC_CF_LAG_STRICT | SILC_CF_REG), SILC_SERVER_CMD(users, USERS, SILC_CF_LAG | SILC_CF_REG), SILC_SERVER_CMD(getkey, GETKEY, SILC_CF_LAG | SILC_CF_REG), + SILC_SERVER_CMD(service, SERVICE, SILC_CF_LAG_STRICT | SILC_CF_REG), SILC_SERVER_CMD(connect, PRIV_CONNECT, SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER), @@ -5093,6 +5094,50 @@ SILC_SERVER_CMD_FUNC(getkey) silc_server_command_free(cmd); } +/* Server side of command SERVICE. */ +/* XXX currently this just sends empty reply back */ + +SILC_SERVER_CMD_FUNC(service) +{ + SilcServerCommandContext cmd = (SilcServerCommandContext)context; + SilcServer server = cmd->server; + SilcUInt32 tmp_len, auth_len; + unsigned char *service_name, *auth; + bool send_list = FALSE; + SilcUInt16 ident = silc_command_get_ident(cmd->payload); + + SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_SERVICE, cmd, 0, 256); + + /* Get requested service */ + service_name = silc_argument_get_arg_type(cmd->args, 1, &tmp_len); + if (service_name && tmp_len) { + /* Verify service name */ + if (!silc_identifier_verify(service_name, tmp_len, + SILC_STRING_UTF8, 256)) { + silc_server_command_send_status_reply(cmd, SILC_COMMAND_SERVICE, + SILC_STATUS_ERR_NOT_ENOUGH_PARAMS, + 0); + goto out; + } + } + + /* Get authentication payload if present */ + auth = silc_argument_get_arg_type(cmd->args, 2, &auth_len); + if (auth) { + /* XXX */ + } + + + send_list = TRUE; + + /* Send our service list back */ + silc_server_send_command_reply(server, cmd->sock, SILC_COMMAND_SERVICE, + SILC_STATUS_OK, 0, ident, 0); + + out: + silc_server_command_free(cmd); +} + /* Private range commands, specific to this implementation */ diff --git a/apps/silcd/command.h b/apps/silcd/command.h index 9cd04d79..ba7fd2ce 100644 --- a/apps/silcd/command.h +++ b/apps/silcd/command.h @@ -4,13 +4,12 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 1997 - 2005 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -21,8 +20,8 @@ #ifndef COMMAND_H #define COMMAND_H -/* - Structure holding one command and pointer to its function. +/* + Structure holding one command and pointer to its function. SilcCommandCb cb @@ -35,7 +34,7 @@ SilcCommandFlag flags Flags for the command. These set how command behaves on different - situations. + situations. */ typedef struct { @@ -79,9 +78,9 @@ typedef struct SilcServerCommandPendingStruct { { silc_server_command_##func, SILC_COMMAND_##cmd, flags } /* Macro used to declare command functions. The `context' will be the - SilcServerCommandContext and the `context2' is the + SilcServerCommandContext and the `context2' is the SilcServerCommandReplyContext if this function is called from the - command reply as pending command callback. Otherwise `context2' + command reply as pending command callback. Otherwise `context2' is NULL. */ #define SILC_SERVER_CMD_FUNC(func) \ void silc_server_command_##func(void *context, void *context2) @@ -104,7 +103,7 @@ void silc_server_command_process(SilcServer server, SilcPacketContext *packet); SilcServerCommandContext silc_server_command_alloc(); void silc_server_command_free(SilcServerCommandContext ctx); -SilcServerCommandContext +SilcServerCommandContext silc_server_command_dup(SilcServerCommandContext ctx); bool silc_server_command_pending(SilcServer server, SilcCommand reply_cmd, @@ -122,7 +121,7 @@ void silc_server_command_pending_del(SilcServer server, SilcUInt16 ident); SilcServerCommandPendingCallbacks silc_server_command_pending_check(SilcServer server, - SilcCommand command, + SilcCommand command, SilcUInt16 ident, SilcUInt32 *callbacks_count); SILC_SERVER_CMD_FUNC(whois); @@ -152,6 +151,7 @@ SILC_SERVER_CMD_FUNC(silcoper); SILC_SERVER_CMD_FUNC(leave); SILC_SERVER_CMD_FUNC(users); SILC_SERVER_CMD_FUNC(getkey); +SILC_SERVER_CMD_FUNC(service); SILC_SERVER_CMD_FUNC(connect); SILC_SERVER_CMD_FUNC(close); diff --git a/lib/doc/command_reply_args.html b/lib/doc/command_reply_args.html index a38209e9..562282a5 100644 --- a/lib/doc/command_reply_args.html +++ b/lib/doc/command_reply_args.html @@ -399,6 +399,20 @@ SilcPublicKey public_key + +SILC_COMMAND_SERVICE + +Returns the service list in the server, or information on the accepted +and authenticated service. The 'service_list' maybe NULL if server does +not support any services. It is NULL also when 'name' is not NULL. The +'service_list' is a comma separated list of services the server supports. +The 'name' MAY be NULL also. The 'name' is the requested service, and it is +non-NULL only if server accepted and authenticated client's request. + +const char *server_list, const char *service_name + + +
 
diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index e2537fe6..0122fee9 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -2624,6 +2624,47 @@ SILC_CLIENT_CMD_FUNC(getkey) silc_client_command_free(cmd); } +/* Command SERVICE. Negotiates service agreement with server. */ +/* XXX incomplete */ + +SILC_CLIENT_CMD_FUNC(service) +{ + SilcClientCommandContext cmd = (SilcClientCommandContext)context; + SilcClientConnection conn = cmd->conn; + SilcBuffer buffer; + char *name; + + if (!cmd->conn) { + SILC_NOT_CONNECTED(cmd->client, cmd->conn); + COMMAND_ERROR(SILC_STATUS_ERR_NOT_REGISTERED); + goto out; + } + + if (cmd->argc < 2) { + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /SERVICE [] [-pubkey]"); + COMMAND_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); + goto out; + } + + name = cmd->argv[1]; + + /* Send SERVICE command to the server */ + buffer = silc_command_payload_encode_va(SILC_COMMAND_SERVICE, + ++conn->cmd_ident, 1, + 1, name, strlen(name)); + 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(SILC_STATUS_OK); + + out: + silc_client_command_free(cmd); +} + /* Register a new command indicated by the `command' to the SILC client. The `name' is optional command name. If provided the command may be searched using the silc_client_command_find by that name. The @@ -2847,6 +2888,7 @@ void silc_client_commands_register(SilcClient client) SILC_CLIENT_CMD(leave, LEAVE, "LEAVE", 2); SILC_CLIENT_CMD(users, USERS, "USERS", 2); SILC_CLIENT_CMD(getkey, GETKEY, "GETKEY", 2); + SILC_CLIENT_CMD(service, SERVICE, "SERVICE", 10); SILC_CLIENT_CMD(connect, PRIV_CONNECT, "CONNECT", 3); SILC_CLIENT_CMD(close, PRIV_CLOSE, "CLOSE", 3); @@ -2883,6 +2925,7 @@ void silc_client_commands_unregister(SilcClient client) SILC_CLIENT_CMDU(leave, LEAVE, "LEAVE"); SILC_CLIENT_CMDU(users, USERS, "USERS"); SILC_CLIENT_CMDU(getkey, GETKEY, "GETKEY"); + SILC_CLIENT_CMDU(service, SERVICE, "SERVICE"); SILC_CLIENT_CMDU(connect, PRIV_CONNECT, "CONNECT"); SILC_CLIENT_CMDU(close, PRIV_CLOSE, "CLOSE"); diff --git a/lib/silcclient/command.h b/lib/silcclient/command.h index c6c597de..3f5e58a3 100644 --- a/lib/silcclient/command.h +++ b/lib/silcclient/command.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2005 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 @@ -153,6 +153,7 @@ SILC_CLIENT_CMD_FUNC(silcoper); SILC_CLIENT_CMD_FUNC(leave); SILC_CLIENT_CMD_FUNC(users); SILC_CLIENT_CMD_FUNC(getkey); +SILC_CLIENT_CMD_FUNC(service); SILC_CLIENT_CMD_FUNC(shutdown); SILC_CLIENT_CMD_FUNC(close); diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 3c041113..5c64922e 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -2046,6 +2046,32 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey) silc_client_command_reply_free(cmd); } +/* Reply to SERVICE command. */ +/* XXX incomplete */ + +SILC_CLIENT_CMD_REPLY_FUNC(service) +{ + SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context; + SilcUInt32 tmp_len; + unsigned char *service_list, *name; + + COMMAND_CHECK_STATUS; + + /* Get service list */ + service_list = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); + + /* Get requested service name */ + name = silc_argument_get_arg_type(cmd->args, 3, &tmp_len); + + /* Notify application */ + COMMAND_REPLY((SILC_ARGS, service_list, name)); + + out: + SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_SERVICE); + err: + silc_client_command_reply_free(cmd); +} + SILC_CLIENT_CMD_REPLY_FUNC(quit) { silc_client_command_reply_free(context); diff --git a/lib/silcclient/command_reply.h b/lib/silcclient/command_reply.h index 4eb8ca18..e07fcccb 100644 --- a/lib/silcclient/command_reply.h +++ b/lib/silcclient/command_reply.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2003 Pekka Riikonen + Copyright (C) 1997 - 2005 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 @@ -111,6 +111,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(silcoper); SILC_CLIENT_CMD_REPLY_FUNC(leave); SILC_CLIENT_CMD_REPLY_FUNC(users); SILC_CLIENT_CMD_REPLY_FUNC(getkey); +SILC_CLIENT_CMD_REPLY_FUNC(service); SILC_CLIENT_CMD_REPLY_FUNC(quit); /* Internal command reply functions */ -- 2.43.0