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.
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 /* Context sent as argument to all commands */
65 SilcClientConnection conn;
66 SilcClientCommand *command;
69 unsigned int *argv_lens;
70 unsigned int *argv_types;
71 int pending; /* Command is being re-processed when TRUE */
72 int users; /* Reference counter */
73 } *SilcClientCommandContext;
75 /* Pending Command callback destructor. This is called after calling the
76 pending callback or if error occurs while processing the pending command.
77 If error occurs then the callback won't be called at all, and only this
78 destructor is called. The `context' is the context given for the function
79 silc_client_command_pending. */
80 typedef void (*SilcClientPendingDestructor)(void *context);
82 /* Structure holding pending commands. If command is pending it will be
83 executed after command reply has been executed. */
84 typedef struct SilcClientCommandPendingStruct {
85 SilcCommand reply_cmd;
86 SilcCommandCb callback;
87 SilcClientPendingDestructor destructor;
90 struct SilcClientCommandPendingStruct *next;
91 } SilcClientCommandPending;
93 /* List of pending commands */
94 extern SilcClientCommandPending *silc_command_pending;
96 #include "command_reply.h"
100 /* Macro used for command declaration in command list structure */
101 #define SILC_CLIENT_CMD(func, cmd, name, flags, args) \
102 { silc_client_command_##func, SILC_COMMAND_##cmd, name, flags, args }
104 /* Macro used to declare command functions */
105 #define SILC_CLIENT_CMD_FUNC(func) \
106 void silc_client_command_##func(void *context)
108 /* Executed pending command callback */
109 #define SILC_CLIENT_PENDING_EXEC(ctx, cmd) \
111 if ((ctx)->callback) \
112 (*ctx->callback)(ctx->context); \
115 /* Execute destructor for pending command */
116 #define SILC_CLIENT_PENDING_DESTRUCTOR(ctx, cmd) \
118 silc_client_command_pending_del((ctx)->sock->user_data, (cmd), \
120 if (ctx->destructor) \
121 (*ctx->destructor)(ctx->context); \
125 void silc_client_send_command(SilcClient client, SilcClientConnection conn,
126 SilcCommand command, unsigned short ident,
127 unsigned int argc, ...);
128 SilcClientCommand *silc_client_command_find(const char *name);
129 SilcClientCommandContext silc_client_command_alloc();
130 void silc_client_command_free(SilcClientCommandContext ctx);
131 SilcClientCommandContext
132 silc_client_command_dup(SilcClientCommandContext ctx);
133 void silc_client_command_pending(SilcClientConnection conn,
134 SilcCommand reply_cmd,
135 unsigned short ident,
136 SilcClientPendingDestructor destructor,
137 SilcCommandCb callback,
139 void silc_client_command_pending_del(SilcClientConnection conn,
140 SilcCommand reply_cmd,
141 unsigned short ident);
142 int silc_client_command_pending_check(SilcClientConnection conn,
143 SilcClientCommandReplyContext ctx,
145 unsigned short ident);
146 SILC_CLIENT_CMD_FUNC(whois);
147 SILC_CLIENT_CMD_FUNC(whowas);
148 SILC_CLIENT_CMD_FUNC(identify);
149 SILC_CLIENT_CMD_FUNC(nick);
150 SILC_CLIENT_CMD_FUNC(list);
151 SILC_CLIENT_CMD_FUNC(topic);
152 SILC_CLIENT_CMD_FUNC(invite);
153 SILC_CLIENT_CMD_FUNC(quit);
154 SILC_CLIENT_CMD_FUNC(kill);
155 SILC_CLIENT_CMD_FUNC(info);
156 SILC_CLIENT_CMD_FUNC(connect);
157 SILC_CLIENT_CMD_FUNC(ping);
158 SILC_CLIENT_CMD_FUNC(oper);
159 SILC_CLIENT_CMD_FUNC(join);
160 SILC_CLIENT_CMD_FUNC(motd);
161 SILC_CLIENT_CMD_FUNC(umode);
162 SILC_CLIENT_CMD_FUNC(cmode);
163 SILC_CLIENT_CMD_FUNC(cumode);
164 SILC_CLIENT_CMD_FUNC(kick);
165 SILC_CLIENT_CMD_FUNC(restart);
166 SILC_CLIENT_CMD_FUNC(close);
167 SILC_CLIENT_CMD_FUNC(shutdown);
168 SILC_CLIENT_CMD_FUNC(silcoper);
169 SILC_CLIENT_CMD_FUNC(leave);
170 SILC_CLIENT_CMD_FUNC(users);