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. This is used by the library
63 and application should use this as well. However, application may
64 choose to use some own context for its own local command. All library
65 commands, however, must use this context. */
68 SilcClientConnection conn;
69 SilcClientCommand *command;
72 unsigned int *argv_lens;
73 unsigned int *argv_types;
74 int pending; /* Command is being re-processed when TRUE */
75 int users; /* Reference counter */
76 } *SilcClientCommandContext;
80 /* Structure holding pending commands. If command is pending it will be
81 executed after command reply has been executed. */
82 typedef struct SilcClientCommandPendingStruct {
83 SilcCommand reply_cmd;
84 SilcCommandCb callback;
85 SilcClientPendingDestructor destructor;
88 struct SilcClientCommandPendingStruct *next;
89 } SilcClientCommandPending;
91 /* List of pending commands */
92 extern SilcClientCommandPending *silc_command_pending;
94 #include "command_reply.h"
98 /* Macro used for command declaration in command list structure */
99 #define SILC_CLIENT_CMD(func, cmd, name, flags, args) \
100 { silc_client_command_##func, SILC_COMMAND_##cmd, name, flags, args }
102 /* Macro used to declare command functions */
103 #define SILC_CLIENT_CMD_FUNC(func) \
104 void silc_client_command_##func(void *context)
106 /* Executed pending command callback */
107 #define SILC_CLIENT_PENDING_EXEC(ctx, cmd) \
109 if ((ctx)->callback) \
110 (*ctx->callback)(ctx->context); \
113 /* Execute destructor for pending command */
114 #define SILC_CLIENT_PENDING_DESTRUCTOR(ctx, cmd) \
116 silc_client_command_pending_del((ctx)->sock->user_data, (cmd), \
118 if (ctx->destructor) \
119 (*ctx->destructor)(ctx->context); \
122 /* Prototypes (some prototypes are in the silcapi.h file) */
123 void silc_client_command_pending_del(SilcClientConnection conn,
124 SilcCommand reply_cmd,
125 unsigned short ident);
126 int silc_client_command_pending_check(SilcClientConnection conn,
127 SilcClientCommandReplyContext ctx,
129 unsigned short ident);
130 SILC_CLIENT_CMD_FUNC(whois);
131 SILC_CLIENT_CMD_FUNC(whowas);
132 SILC_CLIENT_CMD_FUNC(identify);
133 SILC_CLIENT_CMD_FUNC(nick);
134 SILC_CLIENT_CMD_FUNC(list);
135 SILC_CLIENT_CMD_FUNC(topic);
136 SILC_CLIENT_CMD_FUNC(invite);
137 SILC_CLIENT_CMD_FUNC(quit);
138 SILC_CLIENT_CMD_FUNC(kill);
139 SILC_CLIENT_CMD_FUNC(info);
140 SILC_CLIENT_CMD_FUNC(connect);
141 SILC_CLIENT_CMD_FUNC(ping);
142 SILC_CLIENT_CMD_FUNC(oper);
143 SILC_CLIENT_CMD_FUNC(join);
144 SILC_CLIENT_CMD_FUNC(motd);
145 SILC_CLIENT_CMD_FUNC(umode);
146 SILC_CLIENT_CMD_FUNC(cmode);
147 SILC_CLIENT_CMD_FUNC(cumode);
148 SILC_CLIENT_CMD_FUNC(kick);
149 SILC_CLIENT_CMD_FUNC(restart);
150 SILC_CLIENT_CMD_FUNC(close);
151 SILC_CLIENT_CMD_FUNC(shutdown);
152 SILC_CLIENT_CMD_FUNC(silcoper);
153 SILC_CLIENT_CMD_FUNC(leave);
154 SILC_CLIENT_CMD_FUNC(users);