Added SERVICE command (incomplete implementation).
authorPekka Riikonen <priikone@silcnet.org>
Wed, 27 Apr 2005 10:52:22 +0000 (10:52 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 27 Apr 2005 10:52:22 +0000 (10:52 +0000)
CHANGES
apps/silcd/command.c
apps/silcd/command.h
lib/doc/command_reply_args.html
lib/silcclient/command.c
lib/silcclient/command.h
lib/silcclient/command_reply.c
lib/silcclient/command_reply.h

diff --git a/CHANGES b/CHANGES
index 50d30b8382cf101939dd770a45b7b969d45435f2..347171e7844685dbf2584f071d00a0ee7c77baba 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,14 @@ Wed Apr 27 11:49:41 EEST 2005  Pekka Riikonen <priikone@silcnet.org>
        * 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 <priikone@silcnet.org>
 
        * Moved silcer/, silc/, silcd/ and irssi/ to apps/.  This
index 67e2ad4813e3ce634b2c0cc1324292700002c107..927e14ccdb2200a9a02cf346df04b180c5256499 100644 (file)
@@ -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 */
 
index 9cd04d79171152ca71cd5b48637173f51a0dc41a..ba7fd2ce2d9383105a580b9de52890fac712f866 100644 (file)
@@ -4,13 +4,12 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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);
index a38209e9df6b57aa618222c32ed85b97a7acfb17..562282a5a99be60ac84f5c7b7f008043c9103059 100644 (file)
@@ -399,6 +399,20 @@ SilcPublicKey public_key
 </td>
 </tr>
 
+<tr>
+<td><small>SILC_COMMAND_SERVICE</td>
+<td><small>
+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.
+</td>
+<td width="50%"><small>const char *server_list, const char *service_name
+</td>
+</tr>
+
 </table>
 
 <br />&nbsp;<br />
index e2537fe69ca3b2a7a5daf0347e83ef4f63895531..0122fee97007d4129bb0c21be8320322224e3ac5 100644 (file)
@@ -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 [<service name>] [-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");
index c6c597de1cb49f038bb03bc0ca96935819c0fb00..3f5e58a339102df5535a0b9db5fe8eb247da7ddd 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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);
index 3c041113b70157cc139bea90bbf6ef96dd56e9ca..5c64922e3992af206be3aded6576c9f6a421f96c 100644 (file)
@@ -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);
index 4eb8ca18ea428b63345f25ae0234cd7d9a8f14af..e07fcccbfb1649cb3ea0a6c20020408081f5c91e 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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 */