Initial client library rewrite, connects to remote server already.
[silc.git] / lib / silcclient / command.h
index ca9c584ed3dc3609474a668df7978216a9fb5785..dfcb60c20bb0827ae74454a5adeee50acd37354d 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 2006 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
 #ifndef COMMAND_H
 #define COMMAND_H
 
-#include "command_reply.h"
+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);
 
-/* Structure holding one command and pointer to its function. This
-   structure is allocate into the commands list, and is returned
-   for example by silc_client_command_find function.
-
-   To call a command: command->command(cmd, NULL);
-   To call a command reply: command->reply(cmd, NULL);
-
-*/
-struct SilcClientCommandStruct {
-  SilcCommand cmd;                /* Command type */
-  SilcCommandCb command;          /* Command function */
-  SilcCommandCb reply;            /* Command reply callback */
-  char *name;                     /* Name of the command (optional) */
-  SilcUInt8 max_args;             /* Maximum arguments (optional)  */
-  SilcUInt16 ident;               /* Identifier for command (optional)  */
-  struct SilcClientCommandStruct *next;
-};
-
-/* 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. */
-struct SilcClientCommandContextStruct {
-  SilcClient client;
-  SilcClientConnection conn;
-  SilcClientCommand command;
-  SilcUInt32 argc;
-  unsigned char **argv;
-  SilcUInt32 *argv_lens;
-  SilcUInt32 *argv_types;
-  int pending;                 /* Command is being re-processed when TRUE */
-  int users;                   /* Reference counter */
-};
-
-/* Structure holding pending commands. If command is pending it will be
-   executed after command reply has been executed. */
-typedef struct SilcClientCommandPendingStruct {
-  SilcCommand reply_cmd;
-  SilcUInt16 ident;
-  unsigned int reply_check : 8;
-  SilcCommandCb callback;
-  void *context;
-  struct SilcClientCommandPendingStruct *next;
-} SilcClientCommandPending;
-
-/* List of pending commands */
-extern SilcClientCommandPending *silc_command_pending;
-
-
-/* Macros */
-
-/* Macro used for command registering and unregistering */
-#define SILC_CLIENT_CMD(func, cmd, name, args)                         \
-silc_client_command_register(client, SILC_COMMAND_##cmd, name,                 \
-                            silc_client_command_##func,                \
-                            silc_client_command_reply_##func, args, 0)
-#define SILC_CLIENT_CMDU(func, cmd, name)                              \
-silc_client_command_unregister(client, SILC_COMMAND_##cmd,             \
-                              silc_client_command_##func,              \
-                              silc_client_command_reply_##func, 0)
-
-/* Macro used to declare command functions */
-#define SILC_CLIENT_CMD_FUNC(func)                             \
-void silc_client_command_##func(void *context, void *context2)
-
-/* Executed pending command callback */
-#define SILC_CLIENT_PENDING_EXEC(ctx, cmd)                               \
-do {                                                                     \
-  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_client_command_pending_del(ctx->sock->user_data, cmd, ctx->ident); \
-} while(0)
-
-SilcClientCommandContext silc_client_command_alloc(void);
-void silc_client_command_free(SilcClientCommandContext ctx);
-SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx);
-SilcClientCommand silc_client_command_find(SilcClient client,
-                                          const char *name);
-SilcBool silc_client_command_register(SilcClient client,
-                                 SilcCommand command,
-                                 const char *name,
-                                 SilcCommandCb command_function,
-                                 SilcCommandCb command_reply_function,
-                                 SilcUInt8 max_args,
-                                 SilcUInt16 ident);
-SilcBool silc_client_command_unregister(SilcClient client,
-                                   SilcCommand command,
-                                   SilcCommandCb command_function,
-                                   SilcCommandCb command_reply_function,
-                                   SilcUInt16 ident);
 void silc_client_commands_register(SilcClient client);
 void silc_client_commands_unregister(SilcClient client);
-void silc_client_command_pending_del(SilcClientConnection conn,
-                                    SilcCommand reply_cmd,
-                                    SilcUInt16 ident);
-SilcClientCommandPendingCallbacks
-silc_client_command_pending_check(SilcClientConnection conn,
-                                 SilcClientCommandReplyContext ctx,
-                                 SilcCommand command,
-                                 SilcUInt16 ident,
-                                 SilcUInt32 *callbacks_count);
-void silc_client_command_process(SilcClient client,
-                                SilcSocketConnection sock,
-                                SilcPacketContext *packet);
-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(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(ban);
-SILC_CLIENT_CMD_FUNC(detach);
-SILC_CLIENT_CMD_FUNC(watch);
-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);
-SILC_CLIENT_CMD_FUNC(connect);
 
-#endif
+#endif /* COMMAND_H */