updates.
[silc.git] / lib / silcclient / command.h
index 11163ac4b2ba52220dcbf9ca31f89c4fa3803229..69a94efd267aacd77a4eff669111bd3005d81c46 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
 
-  Copyright (C) 1997 - 2000 Pekka Riikonen
+  Copyright (C) 1997 - 2001 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
@@ -53,42 +53,46 @@ typedef struct {
   SilcCommand cmd;
   char *name;
   SilcCommandFlag flags;
-  unsigned int max_args;
+  uint32 max_args;
 } SilcClientCommand;
 
 /* All client commands */
 extern SilcClientCommand silc_command_list[];
 
-/* Client command callback function. This included into Command Context, 
-   and if it is defined it will be executed when executing the command. */
-typedef void (*SilcClientCommandCallback)(void *context);
-
-/* Context sent as argument to all commands */
+/* Context sent as argument to all commands. This is used by the library
+   and application should use this as well. However, application may
+   choose to use some own context for its own local command. All library
+   commands, however, must use this context. */
 typedef struct {
   SilcClient client;
   SilcClientConnection conn;
   SilcClientCommand *command;
-  unsigned int argc;
+  uint32 argc;
   unsigned char **argv;
-  unsigned int *argv_lens;
-  unsigned int *argv_types;
+  uint32 *argv_lens;
+  uint32 *argv_types;
+  int pending;                 /* Command is being re-processed when TRUE */
+  int users;                   /* Reference counter */
 } *SilcClientCommandContext;
 
+#include "silcapi.h"
+
 /* Structure holding pending commands. If command is pending it will be
    executed after command reply has been executed. */
-/* XXX This support may added for commands as well and not just command
-   replies, if needed later. */
 typedef struct SilcClientCommandPendingStruct {
   SilcCommand reply_cmd;
+  SilcCommandCb callback;
+  SilcClientPendingDestructor destructor;
   void *context;
-  SilcClientCommandCallback callback;
-
+  uint16 ident;
   struct SilcClientCommandPendingStruct *next;
 } SilcClientCommandPending;
 
 /* List of pending commands */
 extern SilcClientCommandPending *silc_command_pending;
 
+#include "command_reply.h"
+
 /* Macros */
 
 /* Macro used for command declaration in command list structure */
@@ -99,42 +103,31 @@ extern SilcClientCommandPending *silc_command_pending;
 #define SILC_CLIENT_CMD_FUNC(func) \
 void silc_client_command_##func(void *context)
 
-/* Checks for pending commands */
-#define SILC_CLIENT_COMMAND_CHECK_PENDING(ctx)         \
-do {                                                   \
-  if (silc_command_pending) {                          \
-    SilcClientCommandPending *r;                       \
-    SilcCommand cmd;                                   \
-                                                       \
-    cmd = silc_command_get(payload);                   \
-    for (r = silc_command_pending; r; r = r->next) {   \
-      if (r->reply_cmd == cmd) {                       \
-       ctx->context = r->context;                      \
-       ctx->callback = r->callback;                    \
-       break;                                          \
-      }                                                        \
-    }                                                  \
-  }                                                    \
+/* Executed pending command callback */
+#define SILC_CLIENT_PENDING_EXEC(ctx, cmd)     \
+do {                                           \
+  if ((ctx)->callback)                         \
+    (*ctx->callback)(ctx->context);            \
 } while(0)
 
-/* Executed pending command */
-#define SILC_CLIENT_COMMAND_EXEC_PENDING(ctx, cmd)     \
-do {                                                   \
-  if (ctx->callback) {                                 \
-    (*ctx->callback)(ctx->context);                    \
-    silc_client_command_pending_del((cmd));            \
-  }                                                    \
+/* Execute destructor for pending command */
+#define SILC_CLIENT_PENDING_DESTRUCTOR(ctx, cmd)                       \
+do {                                                                   \
+  silc_client_command_pending_del((ctx)->sock->user_data, (cmd),       \
+                                 (ctx)->ident);                        \
+  if (ctx->destructor)                                                 \
+    (*ctx->destructor)(ctx->context);                                  \
 } while(0)
 
-/* Prototypes */
-void silc_client_command_free(SilcClientCommandContext cmd);
-void silc_client_send_command(SilcClient client, SilcClientConnection conn,
-                             SilcCommand command, unsigned int argc, ...);
-SilcClientCommand *silc_client_command_find(const char *name);
-void silc_client_command_pending(SilcCommand reply_cmd,
-                                SilcClientCommandCallback callback,
-                                void *context);
-void silc_client_command_pending_del(SilcCommand reply_cmd);
+/* Prototypes (some prototypes are in the silcapi.h file) */
+void silc_client_command_pending_del(SilcClientConnection conn,
+                                    SilcCommand reply_cmd,
+                                    uint16 ident);
+int silc_client_command_pending_check(SilcClientConnection conn,
+                                     SilcClientCommandReplyContext ctx,
+                                     SilcCommand command, 
+                                     uint16 ident);
+
 SILC_CLIENT_CMD_FUNC(whois);
 SILC_CLIENT_CMD_FUNC(whowas);
 SILC_CLIENT_CMD_FUNC(identify);
@@ -154,11 +147,12 @@ SILC_CLIENT_CMD_FUNC(umode);
 SILC_CLIENT_CMD_FUNC(cmode);
 SILC_CLIENT_CMD_FUNC(cumode);
 SILC_CLIENT_CMD_FUNC(kick);
-SILC_CLIENT_CMD_FUNC(restart);
+SILC_CLIENT_CMD_FUNC(ban);
 SILC_CLIENT_CMD_FUNC(close);
-SILC_CLIENT_CMD_FUNC(die);
+SILC_CLIENT_CMD_FUNC(shutdown);
 SILC_CLIENT_CMD_FUNC(silcoper);
 SILC_CLIENT_CMD_FUNC(leave);
-SILC_CLIENT_CMD_FUNC(names);
+SILC_CLIENT_CMD_FUNC(users);
+SILC_CLIENT_CMD_FUNC(getkey);
 
 #endif