Integer type name change.
[silc.git] / lib / silcclient / command.h
1 /*
2
3   command.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2001 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef COMMAND_H
21 #define COMMAND_H
22
23 #include "command_reply.h"
24
25 /* Structure holding one command and pointer to its function. This
26    structure is allocate into the commands list, and is returned
27    for example by silc_client_command_find function.
28
29    To call a command: command->command(cmd, NULL);
30    To call a command reply: command->reply(cmd, NULL);
31
32 */
33 struct SilcClientCommandStruct {
34   SilcCommand cmd;                 /* Command type */
35   SilcCommandCb command;           /* Command function */
36   SilcCommandCb reply;             /* Command reply callback */
37   char *name;                      /* Name of the command (optional) */
38   SilcUInt8 max_args;              /* Maximum arguments (optional)  */
39   SilcUInt16 ident;                        /* Identifier for command (optional)  */
40   struct SilcClientCommandStruct *next;
41 };
42
43 /* Context sent as argument to all commands. This is used by the library
44    and application should use this as well. However, application may
45    choose to use some own context for its own local command. All library
46    commands, however, must use this context. */
47 struct SilcClientCommandContextStruct {
48   SilcClient client;
49   SilcClientConnection conn;
50   SilcClientCommand command;
51   SilcUInt32 argc;
52   unsigned char **argv;
53   SilcUInt32 *argv_lens;
54   SilcUInt32 *argv_types;
55   int pending;                  /* Command is being re-processed when TRUE */
56   int users;                    /* Reference counter */
57 };
58
59 /* Structure holding pending commands. If command is pending it will be
60    executed after command reply has been executed. */
61 typedef struct SilcClientCommandPendingStruct {
62   SilcCommand reply_cmd;
63   SilcCommandCb callback;
64   void *context;
65   SilcUInt16 ident;
66   struct SilcClientCommandPendingStruct *next;
67 } SilcClientCommandPending;
68
69 /* List of pending commands */
70 extern SilcClientCommandPending *silc_command_pending;
71
72
73 /* Macros */
74
75 /* Macro used for command registering and unregistering */
76 #define SILC_CLIENT_CMD(func, cmd, name, args)                          \
77 silc_client_command_register(client, SILC_COMMAND_##cmd, name,          \
78                              silc_client_command_##func,                \
79                              silc_client_command_reply_##func, args, 0)
80 #define SILC_CLIENT_CMDU(func, cmd, name)                               \
81 silc_client_command_unregister(client, SILC_COMMAND_##cmd,              \
82                                silc_client_command_##func,              \
83                                silc_client_command_reply_##func, 0)
84
85 /* Macro used to declare command functions */
86 #define SILC_CLIENT_CMD_FUNC(func)                              \
87 void silc_client_command_##func(void *context, void *context2)
88
89 /* Executed pending command callback */
90 #define SILC_CLIENT_PENDING_EXEC(ctx, cmd)                              \
91 do {                                                                    \
92   if ((ctx)->callback)                                                  \
93     (*ctx->callback)(ctx->context, ctx);                                \
94   silc_client_command_pending_del((ctx)->sock->user_data, (cmd),        \
95                                   (ctx)->ident);                        \
96 } while(0)
97
98 bool silc_client_command_register(SilcClient client,
99                                   SilcCommand command,
100                                   const char *name,
101                                   SilcCommandCb command_function,
102                                   SilcCommandCb command_reply_function,
103                                   SilcUInt8 max_args,
104                                   SilcUInt16 ident);
105 bool silc_client_command_unregister(SilcClient client,
106                                     SilcCommand command,
107                                     SilcCommandCb command_function,
108                                     SilcCommandCb command_reply_function,
109                                     SilcUInt16 ident);
110 void silc_client_commands_register(SilcClient client);
111 void silc_client_commands_unregister(SilcClient client);
112 void silc_client_command_pending_del(SilcClientConnection conn,
113                                      SilcCommand reply_cmd,
114                                      SilcUInt16 ident);
115 int silc_client_command_pending_check(SilcClientConnection conn,
116                                       SilcClientCommandReplyContext ctx,
117                                       SilcCommand command, 
118                                       SilcUInt16 ident);
119
120 SILC_CLIENT_CMD_FUNC(whois);
121 SILC_CLIENT_CMD_FUNC(whowas);
122 SILC_CLIENT_CMD_FUNC(identify);
123 SILC_CLIENT_CMD_FUNC(nick);
124 SILC_CLIENT_CMD_FUNC(list);
125 SILC_CLIENT_CMD_FUNC(topic);
126 SILC_CLIENT_CMD_FUNC(invite);
127 SILC_CLIENT_CMD_FUNC(quit);
128 SILC_CLIENT_CMD_FUNC(kill);
129 SILC_CLIENT_CMD_FUNC(info);
130 SILC_CLIENT_CMD_FUNC(connect);
131 SILC_CLIENT_CMD_FUNC(ping);
132 SILC_CLIENT_CMD_FUNC(oper);
133 SILC_CLIENT_CMD_FUNC(join);
134 SILC_CLIENT_CMD_FUNC(motd);
135 SILC_CLIENT_CMD_FUNC(umode);
136 SILC_CLIENT_CMD_FUNC(cmode);
137 SILC_CLIENT_CMD_FUNC(cumode);
138 SILC_CLIENT_CMD_FUNC(kick);
139 SILC_CLIENT_CMD_FUNC(ban);
140 SILC_CLIENT_CMD_FUNC(close);
141 SILC_CLIENT_CMD_FUNC(shutdown);
142 SILC_CLIENT_CMD_FUNC(silcoper);
143 SILC_CLIENT_CMD_FUNC(leave);
144 SILC_CLIENT_CMD_FUNC(users);
145 SILC_CLIENT_CMD_FUNC(getkey);
146
147 #endif