Merge commit 'origin/silc.1.1.branch'
[silc.git] / lib / silcclient / command.h
index a47c7461f420a0edc6f6bacbda15544e86a451b4..4937e746769f43eeb216ead932fddcd0f1d07abd 100644 (file)
@@ -2,15 +2,14 @@
 
   command.h
 
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2000 Pekka Riikonen
+  Copyright (C) 2006 - 2007 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
 #ifndef COMMAND_H
 #define COMMAND_H
 
-/* 
-   Structure holding one command and pointer to its function. 
-
-   SilcCommandCb cb
-
-       Callback function called when this command is executed.
-
-   SilcCommand cmd
-
-       The actual command. These are defined in silccore/silccommand.h
-
-   char *name
-
-       Logical name of the command. This is the visible command name
-       that user uses when calling command. Eg. NICK.
-
-   SilcCommandFlag flags
-
-       Flags for the command. These set how command behaves on different
-       situations. Server sets these flags as well, but to be sure
-       that our client never sends wrong commands we preserve the
-       flags on client side as well.
-
-       XXX: We preserve these so that we define them but currently we
-       don't check the flags at all.
-
-*/
-typedef struct {
-  SilcCommandCb cb;
-  SilcCommand cmd;
-  char *name;
-  SilcCommandFlag flags;
-  unsigned int max_args;
-} SilcClientCommand;
-
-/* All client commands */
-extern SilcClientCommand silc_command_list[];
-
-/* Context sent as argument to all commands */
-typedef struct {
-  SilcClient client;
-  SilcClientConnection conn;
-  SilcClientCommand *command;
-  unsigned int argc;
-  unsigned char **argv;
-  unsigned int *argv_lens;
-  unsigned int *argv_types;
-  int pending;                 /* Command is being re-processed when TRUE */
-  int users;                   /* Reference counter */
-} *SilcClientCommandContext;
-
-/* Pending Command callback destructor. This is called after calling the
-   pending callback or if error occurs while processing the pending command.
-   If error occurs then the callback won't be called at all, and only this
-   destructor is called. The `context' is the context given for the function
-   silc_client_command_pending. */
-typedef void (*SilcClientPendingDestructor)(void *context);
-
-/* Structure holding pending commands. If command is pending it will be
-   executed after command reply has been executed. */
-typedef struct SilcClientCommandPendingStruct {
-  SilcCommand reply_cmd;
-  SilcCommandCb callback;
-  SilcClientPendingDestructor destructor;
-  void *context;
-  unsigned short 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 */
-#define SILC_CLIENT_CMD(func, cmd, name, flags, args) \
-{ silc_client_command_##func, SILC_COMMAND_##cmd, name, flags, args }
-
-/* Macro used to declare command functions */
-#define SILC_CLIENT_CMD_FUNC(func) \
-void silc_client_command_##func(void *context)
-
-/* Executed pending command callback */
-#define SILC_CLIENT_PENDING_EXEC(ctx, cmd)     \
-do {                                           \
-  if ((ctx)->callback)                         \
-    (*ctx->callback)(ctx->context);            \
-} while(0)
-
-/* 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_send_command(SilcClient client, SilcClientConnection conn,
-                             SilcCommand command, unsigned short ident,
-                             unsigned int argc, ...);
-SilcClientCommand *silc_client_command_find(const char *name);
-SilcClientCommandContext silc_client_command_alloc();
-void silc_client_command_free(SilcClientCommandContext ctx);
-SilcClientCommandContext 
-silc_client_command_dup(SilcClientCommandContext ctx);
-void silc_client_command_pending(SilcClientConnection conn,
-                                SilcCommand reply_cmd,
-                                unsigned short ident,
-                                SilcClientPendingDestructor destructor,
-                                SilcCommandCb callback,
-                                void *context);
-void silc_client_command_pending_del(SilcClientConnection conn,
-                                    SilcCommand reply_cmd,
-                                    unsigned short ident);
-int silc_client_command_pending_check(SilcClientConnection conn,
-                                     SilcClientCommandReplyContext ctx,
-                                     SilcCommand command, 
-                                     unsigned short ident);
-SILC_CLIENT_CMD_FUNC(whois);
-SILC_CLIENT_CMD_FUNC(whowas);
-SILC_CLIENT_CMD_FUNC(identify);
-SILC_CLIENT_CMD_FUNC(nick);
-SILC_CLIENT_CMD_FUNC(list);
-SILC_CLIENT_CMD_FUNC(topic);
-SILC_CLIENT_CMD_FUNC(invite);
-SILC_CLIENT_CMD_FUNC(quit);
-SILC_CLIENT_CMD_FUNC(kill);
-SILC_CLIENT_CMD_FUNC(info);
-SILC_CLIENT_CMD_FUNC(connect);
-SILC_CLIENT_CMD_FUNC(ping);
-SILC_CLIENT_CMD_FUNC(oper);
-SILC_CLIENT_CMD_FUNC(join);
-SILC_CLIENT_CMD_FUNC(motd);
-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(close);
-SILC_CLIENT_CMD_FUNC(shutdown);
-SILC_CLIENT_CMD_FUNC(silcoper);
-SILC_CLIENT_CMD_FUNC(leave);
-SILC_CLIENT_CMD_FUNC(users);
-
-#endif
+SILC_FSM_STATE(silc_client_command);
+SILC_FSM_STATE(silc_client_command_whois);
+SILC_FSM_STATE(silc_client_command_whowas);
+SILC_FSM_STATE(silc_client_command_identify);
+SILC_FSM_STATE(silc_client_command_nick);
+SILC_FSM_STATE(silc_client_command_list);
+SILC_FSM_STATE(silc_client_command_topic);
+SILC_FSM_STATE(silc_client_command_invite);
+SILC_FSM_STATE(silc_client_command_quit);
+SILC_FSM_STATE(silc_client_command_kill);
+SILC_FSM_STATE(silc_client_command_info);
+SILC_FSM_STATE(silc_client_command_ping);
+SILC_FSM_STATE(silc_client_command_oper);
+SILC_FSM_STATE(silc_client_command_join);
+SILC_FSM_STATE(silc_client_command_motd);
+SILC_FSM_STATE(silc_client_command_umode);
+SILC_FSM_STATE(silc_client_command_cmode);
+SILC_FSM_STATE(silc_client_command_cumode);
+SILC_FSM_STATE(silc_client_command_kick);
+SILC_FSM_STATE(silc_client_command_ban);
+SILC_FSM_STATE(silc_client_command_detach);
+SILC_FSM_STATE(silc_client_command_watch);
+SILC_FSM_STATE(silc_client_command_silcoper);
+SILC_FSM_STATE(silc_client_command_leave);
+SILC_FSM_STATE(silc_client_command_users);
+SILC_FSM_STATE(silc_client_command_getkey);
+SILC_FSM_STATE(silc_client_command_service);
+
+SilcUInt16 silc_client_command_send_argv(SilcClient client,
+                                        SilcClientConnection conn,
+                                        SilcCommand command,
+                                        SilcClientCommandReply reply,
+                                        void *reply_context,
+                                        SilcUInt32 argc,
+                                        unsigned char **argv,
+                                        SilcUInt32 *argv_lens,
+                                        SilcUInt32 *argv_types);
+void silc_client_commands_register(SilcClient client);
+void silc_client_commands_unregister(SilcClient client);
+SilcBool silc_client_command_called_dummy(SilcClient client,
+                                         SilcClientConnection conn,
+                                         SilcCommand command,
+                                         SilcStatus status,
+                                         SilcStatus error,
+                                         void *context,
+                                         va_list ap);
+void silc_client_command_resolve_dummy(SilcClient client,
+                                      SilcClientConnection conn,
+                                      SilcStatus status,
+                                      SilcDList clients,
+                                      void *context);
+
+#endif /* COMMAND_H */