5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
25 Structure holding one command and pointer to its function.
29 Callback function called when this command is executed.
33 The actual command. These are defined in silccore/silccommand.h
37 Logical name of the command. This is the visible command name
38 that user uses when calling command. Eg. NICK.
42 Flags for the command. These set how command behaves on different
43 situations. Server sets these flags as well, but to be sure
44 that our client never sends wrong commands we preserve the
45 flags on client side as well (actually we preserve them but
53 SilcCommandFlag flags;
57 /* All client commands */
58 extern SilcClientCommand silc_command_list[];
60 /* Context sent as argument to all commands. This is used by the library
61 and application should use this as well. However, application may
62 choose to use some own context for its own local command. All library
63 commands, however, must use this context. */
66 SilcClientConnection conn;
67 SilcClientCommand *command;
72 int pending; /* Command is being re-processed when TRUE */
73 int users; /* Reference counter */
74 } *SilcClientCommandContext;
78 /* Structure holding pending commands. If command is pending it will be
79 executed after command reply has been executed. */
80 typedef struct SilcClientCommandPendingStruct {
81 SilcCommand reply_cmd;
82 SilcCommandCb callback;
83 SilcClientPendingDestructor destructor;
86 struct SilcClientCommandPendingStruct *next;
87 } SilcClientCommandPending;
89 /* List of pending commands */
90 extern SilcClientCommandPending *silc_command_pending;
92 #include "command_reply.h"
96 /* Macro used for command declaration in command list structure */
97 #define SILC_CLIENT_CMD(func, cmd, name, flags, args) \
98 { silc_client_command_##func, SILC_COMMAND_##cmd, name, flags, args }
100 /* Macro used to declare command functions */
101 #define SILC_CLIENT_CMD_FUNC(func) \
102 void silc_client_command_##func(void *context, void *context2)
104 /* Executed pending command callback */
105 #define SILC_CLIENT_PENDING_EXEC(ctx, cmd) \
107 if ((ctx)->callback) \
108 (*ctx->callback)(ctx->context, ctx); \
111 /* Execute destructor for pending command */
112 #define SILC_CLIENT_PENDING_DESTRUCTOR(ctx, cmd) \
114 silc_client_command_pending_del((ctx)->sock->user_data, (cmd), \
116 if (ctx->destructor) \
117 (*ctx->destructor)(ctx->context); \
120 /* Prototypes (some prototypes are in the silcapi.h file) */
121 void silc_client_command_pending_del(SilcClientConnection conn,
122 SilcCommand reply_cmd,
124 int silc_client_command_pending_check(SilcClientConnection conn,
125 SilcClientCommandReplyContext ctx,
129 SILC_CLIENT_CMD_FUNC(whois);
130 SILC_CLIENT_CMD_FUNC(whowas);
131 SILC_CLIENT_CMD_FUNC(identify);
132 SILC_CLIENT_CMD_FUNC(nick);
133 SILC_CLIENT_CMD_FUNC(list);
134 SILC_CLIENT_CMD_FUNC(topic);
135 SILC_CLIENT_CMD_FUNC(invite);
136 SILC_CLIENT_CMD_FUNC(quit);
137 SILC_CLIENT_CMD_FUNC(kill);
138 SILC_CLIENT_CMD_FUNC(info);
139 SILC_CLIENT_CMD_FUNC(connect);
140 SILC_CLIENT_CMD_FUNC(ping);
141 SILC_CLIENT_CMD_FUNC(oper);
142 SILC_CLIENT_CMD_FUNC(join);
143 SILC_CLIENT_CMD_FUNC(motd);
144 SILC_CLIENT_CMD_FUNC(umode);
145 SILC_CLIENT_CMD_FUNC(cmode);
146 SILC_CLIENT_CMD_FUNC(cumode);
147 SILC_CLIENT_CMD_FUNC(kick);
148 SILC_CLIENT_CMD_FUNC(ban);
149 SILC_CLIENT_CMD_FUNC(close);
150 SILC_CLIENT_CMD_FUNC(shutdown);
151 SILC_CLIENT_CMD_FUNC(silcoper);
152 SILC_CLIENT_CMD_FUNC(leave);
153 SILC_CLIENT_CMD_FUNC(users);
154 SILC_CLIENT_CMD_FUNC(getkey);