5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
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.
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.
23 /* Forward declarations */
24 typedef struct SilcClientCommandStruct *SilcClientCommand;
25 typedef struct SilcClientCommandContextStruct *SilcClientCommandContext;
28 #include "command_reply.h"
30 /* Structure holding one command and pointer to its function. This
31 structure is allocate into the commands list, and is returned
32 for example by silc_client_command_find function.
34 To call a command: command->command(cmd, NULL);
35 To call a command reply: command->reply(cmd, NULL);
38 struct SilcClientCommandStruct {
39 SilcCommand cmd; /* Command type */
40 SilcCommandCb command; /* Command function */
41 SilcCommandCb reply; /* Command reply callback */
42 char *name; /* Name of the command (optional) */
43 uint8 max_args; /* Maximum arguments (optional) */
44 uint16 ident; /* Identifier for command (optional) */
45 struct SilcClientCommandStruct *next;
48 /* Context sent as argument to all commands. This is used by the library
49 and application should use this as well. However, application may
50 choose to use some own context for its own local command. All library
51 commands, however, must use this context. */
52 struct SilcClientCommandContextStruct {
54 SilcClientConnection conn;
55 SilcClientCommand command;
60 int pending; /* Command is being re-processed when TRUE */
61 int users; /* Reference counter */
64 /* Structure holding pending commands. If command is pending it will be
65 executed after command reply has been executed. */
66 typedef struct SilcClientCommandPendingStruct {
67 SilcCommand reply_cmd;
68 SilcCommandCb callback;
69 SilcClientPendingDestructor destructor;
72 struct SilcClientCommandPendingStruct *next;
73 } SilcClientCommandPending;
75 /* List of pending commands */
76 extern SilcClientCommandPending *silc_command_pending;
81 /* Macro used for command registering and unregistering */
82 #define SILC_CLIENT_CMD(func, cmd, name, args) \
83 silc_client_command_register(client, SILC_COMMAND_##cmd, name, \
84 silc_client_command_##func, \
85 silc_client_command_reply_##func, args, 0)
86 #define SILC_CLIENT_CMDU(func, cmd, name) \
87 silc_client_command_unregister(client, SILC_COMMAND_##cmd, \
88 silc_client_command_##func, \
89 silc_client_command_reply_##func, 0)
91 /* Macro used to declare command functions */
92 #define SILC_CLIENT_CMD_FUNC(func) \
93 void silc_client_command_##func(void *context, void *context2)
95 /* Executed pending command callback */
96 #define SILC_CLIENT_PENDING_EXEC(ctx, cmd) \
98 if ((ctx)->callback) \
99 (*ctx->callback)(ctx->context, ctx); \
102 /* Execute destructor for pending command */
103 #define SILC_CLIENT_PENDING_DESTRUCTOR(ctx, cmd) \
105 silc_client_command_pending_del((ctx)->sock->user_data, (cmd), \
107 if (ctx->destructor) \
108 (*ctx->destructor)(ctx->context); \
111 bool silc_client_command_register(SilcClient client,
114 SilcCommandCb command_function,
115 SilcCommandCb command_reply_function,
118 bool silc_client_command_unregister(SilcClient client,
120 SilcCommandCb command_function,
121 SilcCommandCb command_reply_function,
123 void silc_client_commands_register(SilcClient client);
124 void silc_client_commands_unregister(SilcClient client);
125 void silc_client_command_pending_del(SilcClientConnection conn,
126 SilcCommand reply_cmd,
128 int silc_client_command_pending_check(SilcClientConnection conn,
129 SilcClientCommandReplyContext ctx,
133 SILC_CLIENT_CMD_FUNC(whois);
134 SILC_CLIENT_CMD_FUNC(whowas);
135 SILC_CLIENT_CMD_FUNC(identify);
136 SILC_CLIENT_CMD_FUNC(nick);
137 SILC_CLIENT_CMD_FUNC(list);
138 SILC_CLIENT_CMD_FUNC(topic);
139 SILC_CLIENT_CMD_FUNC(invite);
140 SILC_CLIENT_CMD_FUNC(quit);
141 SILC_CLIENT_CMD_FUNC(kill);
142 SILC_CLIENT_CMD_FUNC(info);
143 SILC_CLIENT_CMD_FUNC(connect);
144 SILC_CLIENT_CMD_FUNC(ping);
145 SILC_CLIENT_CMD_FUNC(oper);
146 SILC_CLIENT_CMD_FUNC(join);
147 SILC_CLIENT_CMD_FUNC(motd);
148 SILC_CLIENT_CMD_FUNC(umode);
149 SILC_CLIENT_CMD_FUNC(cmode);
150 SILC_CLIENT_CMD_FUNC(cumode);
151 SILC_CLIENT_CMD_FUNC(kick);
152 SILC_CLIENT_CMD_FUNC(ban);
153 SILC_CLIENT_CMD_FUNC(close);
154 SILC_CLIENT_CMD_FUNC(shutdown);
155 SILC_CLIENT_CMD_FUNC(silcoper);
156 SILC_CLIENT_CMD_FUNC(leave);
157 SILC_CLIENT_CMD_FUNC(users);
158 SILC_CLIENT_CMD_FUNC(getkey);