Integer type name change.
[silc.git] / apps / silcd / command.h
index 5e6858a43f48d96807e371df86fbb5d5fde0eb60..cd317f79e285c968bc042d6d09db49b4e19e0d27 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
@@ -21,8 +21,6 @@
 #ifndef COMMAND_H
 #define COMMAND_H
 
-#include "command_reply.h"
-
 /* 
    Structure holding one command and pointer to its function. 
 
@@ -57,6 +55,7 @@ typedef struct {
   SilcArgumentPayload args;
   SilcPacketContext *packet;
   int pending;                 /* Command is being re-processed when TRUE */
+  int users;                   /* Reference counter */
 } *SilcServerCommandContext;
 
 /* Structure holding pending commands. If command is pending it will be
@@ -66,45 +65,60 @@ typedef struct SilcServerCommandPendingStruct {
   SilcCommand reply_cmd;
   SilcCommandCb callback;
   void *context;
-  unsigned short ident;
+  SilcUInt16 ident;
   struct SilcServerCommandPendingStruct *next;
 } SilcServerCommandPending;
 
+#include "command_reply.h"
+
 /* Macros */
 
 /* Macro used for command declaration in command list structure */
 #define SILC_SERVER_CMD(func, cmd, flags) \
 { silc_server_command_##func, SILC_COMMAND_##cmd, flags }
 
-/* Macro used to declare command functions */
+/* Macro used to declare command functions. The `context' will be the
+   SilcServerCommandContext and the `context2' is the 
+   SilcServerCommandReplyContext if this function is called from the
+   command reply as pending command callback. Otherwise `context2' 
+   is NULL. */
 #define SILC_SERVER_CMD_FUNC(func) \
-void silc_server_command_##func(void *context)
+void silc_server_command_##func(void *context, void *context2)
 
-/* Executed pending command */
-#define SILC_SERVER_COMMAND_EXEC_PENDING(ctx, cmd)                     \
+/* Executed pending command. The first argument to the callback function
+   is the user specified context. The second argument is always the
+   SilcServerCommandReply context. */
+#define SILC_SERVER_PENDING_EXEC(ctx, cmd)                             \
 do {                                                                   \
-  if (ctx->callback) {                                                 \
-    (*ctx->callback)(ctx->context);                                    \
-    silc_server_command_pending_del(ctx->server, cmd, ctx->ident);     \
-  }                                                                    \
+  int _i;                                                              \
+  for (_i = 0; _i < ctx->callbacks_count; _i++)                                \
+    if (ctx->callbacks[_i].callback)                                   \
+      (*ctx->callbacks[_i].callback)(ctx->callbacks[_i].context, ctx); \
+  silc_server_command_pending_del(ctx->server, cmd, ctx->ident);       \
 } while(0)
 
 /* Prototypes */
 void silc_server_command_process(SilcServer server,
                                 SilcSocketConnection sock,
                                 SilcPacketContext *packet);
-void silc_server_command_pending(SilcServer server,
+SilcServerCommandContext silc_server_command_alloc();
+void silc_server_command_free(SilcServerCommandContext ctx);
+SilcServerCommandContext 
+silc_server_command_dup(SilcServerCommandContext ctx);
+bool silc_server_command_pending(SilcServer server,
                                 SilcCommand reply_cmd,
-                                unsigned short ident,
+                                SilcUInt16 ident,
                                 SilcCommandCb callback,
                                 void *context);
 void silc_server_command_pending_del(SilcServer server,
                                     SilcCommand reply_cmd,
-                                    unsigned short ident);
-int silc_server_command_pending_check(SilcServer server,
-                                     SilcServerCommandReplyContext ctx,
-                                     SilcCommand command, 
-                                     unsigned short ident);
+                                    SilcUInt16 ident);
+SilcServerCommandPendingCallbacks
+silc_server_command_pending_check(SilcServer server,
+                                 SilcServerCommandReplyContext ctx,
+                                 SilcCommand command, 
+                                 SilcUInt16 ident,
+                                 SilcUInt32 *callbacks_count);
 SILC_SERVER_CMD_FUNC(whois);
 SILC_SERVER_CMD_FUNC(whowas);
 SILC_SERVER_CMD_FUNC(identify);
@@ -128,11 +142,12 @@ SILC_SERVER_CMD_FUNC(cmode);
 SILC_SERVER_CMD_FUNC(cumode);
 SILC_SERVER_CMD_FUNC(kick);
 SILC_SERVER_CMD_FUNC(ignore);
-SILC_SERVER_CMD_FUNC(restart);
+SILC_SERVER_CMD_FUNC(ban);
 SILC_SERVER_CMD_FUNC(close);
-SILC_SERVER_CMD_FUNC(die);
+SILC_SERVER_CMD_FUNC(shutdown);
 SILC_SERVER_CMD_FUNC(silcoper);
 SILC_SERVER_CMD_FUNC(leave);
 SILC_SERVER_CMD_FUNC(users);
+SILC_SERVER_CMD_FUNC(getkey);
 
 #endif