5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 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.
47 XXX: We preserve these so that we define them but currently we
48 don't check the flags at all.
55 SilcCommandFlag flags;
56 unsigned int max_args;
59 /* All client commands */
60 extern SilcClientCommand silc_command_list[];
62 /* Client command callback function. This included into Command Context,
63 and if it is defined it will be executed when executing the command. */
64 typedef void (*SilcClientCommandCallback)(void *context);
66 /* Context sent as argument to all commands */
69 SilcClientConnection conn;
70 SilcClientCommand *command;
73 unsigned int *argv_lens;
74 unsigned int *argv_types;
75 } *SilcClientCommandContext;
77 /* Structure holding pending commands. If command is pending it will be
78 executed after command reply has been executed. */
79 /* XXX This support may added for commands as well and not just command
80 replies, if needed later. */
81 typedef struct SilcClientCommandPendingStruct {
82 SilcCommand reply_cmd;
84 SilcClientCommandCallback callback;
86 struct SilcClientCommandPendingStruct *next;
87 } SilcClientCommandPending;
89 /* List of pending commands */
90 extern SilcClientCommandPending *silc_command_pending;
94 /* Macro used for command declaration in command list structure */
95 #define SILC_CLIENT_CMD(func, cmd, name, flags, args) \
96 { silc_client_command_##func, SILC_COMMAND_##cmd, name, flags, args }
98 /* Macro used to declare command functions */
99 #define SILC_CLIENT_CMD_FUNC(func) \
100 void silc_client_command_##func(void *context)
102 /* Checks for pending commands */
103 #define SILC_CLIENT_COMMAND_CHECK_PENDING(ctx) \
105 if (silc_command_pending) { \
106 SilcClientCommandPending *r; \
109 cmd = silc_command_get(payload); \
110 for (r = silc_command_pending; r; r = r->next) { \
111 if (r->reply_cmd == cmd) { \
112 ctx->context = r->context; \
113 ctx->callback = r->callback; \
120 /* Executed pending command */
121 #define SILC_CLIENT_COMMAND_EXEC_PENDING(ctx, cmd) \
123 if (ctx->callback) { \
124 (*ctx->callback)(ctx->context); \
125 silc_client_command_pending_del((cmd)); \
130 void silc_client_command_free(SilcClientCommandContext cmd);
131 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
132 SilcCommand command, unsigned int argc, ...);
133 SilcClientCommand *silc_client_command_find(const char *name);
134 void silc_client_command_pending(SilcCommand reply_cmd,
135 SilcClientCommandCallback callback,
137 void silc_client_command_pending_del(SilcCommand reply_cmd);
138 SILC_CLIENT_CMD_FUNC(whois);
139 SILC_CLIENT_CMD_FUNC(whowas);
140 SILC_CLIENT_CMD_FUNC(identify);
141 SILC_CLIENT_CMD_FUNC(nick);
142 SILC_CLIENT_CMD_FUNC(list);
143 SILC_CLIENT_CMD_FUNC(topic);
144 SILC_CLIENT_CMD_FUNC(invite);
145 SILC_CLIENT_CMD_FUNC(quit);
146 SILC_CLIENT_CMD_FUNC(kill);
147 SILC_CLIENT_CMD_FUNC(info);
148 SILC_CLIENT_CMD_FUNC(connect);
149 SILC_CLIENT_CMD_FUNC(ping);
150 SILC_CLIENT_CMD_FUNC(oper);
151 SILC_CLIENT_CMD_FUNC(join);
152 SILC_CLIENT_CMD_FUNC(motd);
153 SILC_CLIENT_CMD_FUNC(umode);
154 SILC_CLIENT_CMD_FUNC(cmode);
155 SILC_CLIENT_CMD_FUNC(cumode);
156 SILC_CLIENT_CMD_FUNC(kick);
157 SILC_CLIENT_CMD_FUNC(restart);
158 SILC_CLIENT_CMD_FUNC(close);
159 SILC_CLIENT_CMD_FUNC(die);
160 SILC_CLIENT_CMD_FUNC(silcoper);
161 SILC_CLIENT_CMD_FUNC(leave);
162 SILC_CLIENT_CMD_FUNC(users);