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; 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.
21 /****h* silccore/SILC Command Interface
25 * Implementation of the Command Payload. The Command Payload is used to
26 * send commands and also command replies usually between client and
34 /****f* silccore/SilcCommandAPI/SilcCommandCb
38 * typedef void (*SilcCommandCb)(void *context, void *context2);
42 * Command function callback. The actual command function pointer.
43 * This is generic command callback that the application may choose to
44 * use with its command routines. However, none of the generic
45 * routines depend on this callback so application may freely define
46 * their own command callback if desired.
49 typedef void (*SilcCommandCb)(void *context, void *context2);
51 /****s* silccore/SilcCommandAPI/SilcCommandPayload
55 * typedef struct SilcCommandPayloadStruct *SilcCommandPayload;
59 * This context is the actual Command Payload and is allocated
60 * by silc_command_payload_parse and given as argument usually to
61 * all silc_command_payload_* functions. It is freed by the
62 * silc_command_payload_free function.
65 typedef struct SilcCommandPayloadStruct *SilcCommandPayload;
67 /****d* silccore/SilcCommandAPI/SilcCommandFlags
71 * typedef enum { ... } SilcCommandFlags;
75 * Command flags that set how the commands behave on different
76 * situations. These can be OR'es together to set multiple flags.
77 * The application is resoponsible of implementing the behaviour
78 * of these flags. These are here just to define generic flags.
79 * The server usually makes use of these flags.
86 /* Command may only be used once per (about) 2 seconds. Bursts up
87 to 5 commands are allowed though. */
88 SILC_CF_LAG = (1L << 1),
90 /* Command may only be used once per (about) 2 seconds. No bursts
91 are allowed at all. */
92 SILC_CF_LAG_STRICT = (1L << 2),
94 /* Command is available for registered connections (connections
95 whose ID has been created. */
96 SILC_CF_REG = (1L << 3),
98 /* Command is available only for server operators */
99 SILC_CF_OPER = (1L << 4),
101 /* Command is available only for SILC (router) operators. If this
102 is set SILC_CF_OPER is not necessary to be set. */
103 SILC_CF_SILC_OPER = (1L << 5),
108 /****d* silccore/SilcCommandAPI/SilcCommand
112 * typedef unsigned char SilcCommand;
116 * The SilcCommand type definition and the commands. The commands
117 * listed here are the official SILC Commands and they have client
118 * and server counterparts.
122 typedef unsigned char SilcCommand;
124 /* All SILC commands. These are commands that have client and server
126 #define SILC_COMMAND_NONE 0
127 #define SILC_COMMAND_WHOIS 1
128 #define SILC_COMMAND_WHOWAS 2
129 #define SILC_COMMAND_IDENTIFY 3
130 #define SILC_COMMAND_NICK 4
131 #define SILC_COMMAND_LIST 5
132 #define SILC_COMMAND_TOPIC 6
133 #define SILC_COMMAND_INVITE 7
134 #define SILC_COMMAND_QUIT 8
135 #define SILC_COMMAND_KILL 9
136 #define SILC_COMMAND_INFO 10
137 #define SILC_COMMAND_STATS 11
138 #define SILC_COMMAND_PING 12
139 #define SILC_COMMAND_OPER 13
140 #define SILC_COMMAND_JOIN 14
141 #define SILC_COMMAND_MOTD 15
142 #define SILC_COMMAND_UMODE 16
143 #define SILC_COMMAND_CMODE 17
144 #define SILC_COMMAND_CUMODE 18
145 #define SILC_COMMAND_KICK 19
146 #define SILC_COMMAND_BAN 20
147 #define SILC_COMMAND_SILCOPER 23
148 #define SILC_COMMAND_LEAVE 24
149 #define SILC_COMMAND_USERS 25
150 #define SILC_COMMAND_GETKEY 26
152 /* Private range start */
153 #define SILC_COMMAND_PRIV_CONNECT 200
154 #define SILC_COMMAND_PRIV_CLOSE 201
155 #define SILC_COMMAND_PRIV_SHUTDOWN 202
158 #define SILC_COMMAND_RESERVED 255
161 /****d* silccore/SilcCommandAPI/SilcCommandStatus
165 * typedef SilcUInt8 SilcCommandStatus;
169 * The SilcCommandStatus type definition and the status defines.
170 * The server returns a status in each Command Payload indicating
171 * the status of the command.
175 typedef SilcUInt8 SilcCommandStatus;
177 /* Command Status messages */
178 #define SILC_STATUS_OK 0
179 #define SILC_STATUS_LIST_START 1
180 #define SILC_STATUS_LIST_ITEM 2
181 #define SILC_STATUS_LIST_END 3
182 #define SILC_STATUS_ERR_NO_SUCH_NICK 10
183 #define SILC_STATUS_ERR_NO_SUCH_CHANNEL 11
184 #define SILC_STATUS_ERR_NO_SUCH_SERVER 12
185 #define SILC_STATUS_ERR_TOO_MANY_TARGETS 13
186 #define SILC_STATUS_ERR_NO_RECIPIENT 14
187 #define SILC_STATUS_ERR_UNKNOWN_COMMAND 15
188 #define SILC_STATUS_ERR_WILDCARDS 16
189 #define SILC_STATUS_ERR_NO_CLIENT_ID 17
190 #define SILC_STATUS_ERR_NO_CHANNEL_ID 18
191 #define SILC_STATUS_ERR_NO_SERVER_ID 19
192 #define SILC_STATUS_ERR_BAD_CLIENT_ID 20
193 #define SILC_STATUS_ERR_BAD_CHANNEL_ID 21
194 #define SILC_STATUS_ERR_NO_SUCH_CLIENT_ID 22
195 #define SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID 23
196 #define SILC_STATUS_ERR_NICKNAME_IN_USE 24
197 #define SILC_STATUS_ERR_NOT_ON_CHANNEL 25
198 #define SILC_STATUS_ERR_USER_NOT_ON_CHANNEL 26
199 #define SILC_STATUS_ERR_USER_ON_CHANNEL 27
200 #define SILC_STATUS_ERR_NOT_REGISTERED 28
201 #define SILC_STATUS_ERR_NOT_ENOUGH_PARAMS 29
202 #define SILC_STATUS_ERR_TOO_MANY_PARAMS 30
203 #define SILC_STATUS_ERR_PERM_DENIED 31
204 #define SILC_STATUS_ERR_BANNED_FROM_SERVER 32
205 #define SILC_STATUS_ERR_BAD_PASSWORD 33
206 #define SILC_STATUS_ERR_CHANNEL_IS_FULL 34
207 #define SILC_STATUS_ERR_NOT_INVITED 35
208 #define SILC_STATUS_ERR_BANNED_FROM_CHANNEL 36
209 #define SILC_STATUS_ERR_UNKNOWN_MODE 37
210 #define SILC_STATUS_ERR_NOT_YOU 38
211 #define SILC_STATUS_ERR_NO_CHANNEL_PRIV 39
212 #define SILC_STATUS_ERR_NO_CHANNEL_FOPRIV 40
213 #define SILC_STATUS_ERR_NO_SERVER_PRIV 41
214 #define SILC_STATUS_ERR_NO_ROUTER_PRIV 42
215 #define SILC_STATUS_ERR_BAD_NICKNAME 43
216 #define SILC_STATUS_ERR_BAD_CHANNEL 44
217 #define SILC_STATUS_ERR_AUTH_FAILED 45
218 #define SILC_STATUS_ERR_UNKNOWN_ALGORITHM 46
219 #define SILC_STATUS_ERR_NO_SUCH_SERVER_ID 47
224 /****f* silccore/SilcCommandAPI/silc_command_payload_parse
229 * silc_command_payload_parse(const unsigned char *payload,
230 * SilcUInt32 payload_len);
234 * Parses command payload returning new command payload structure. The
235 * `buffer' is the raw payload.
238 SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
239 SilcUInt32 payload_len);
241 /****f* silccore/SilcCommandAPI/silc_command_payload_encode
245 * SilcBuffer silc_command_payload_encode(SilcCommand cmd,
247 * unsigned char **argv,
248 * SilcUInt32 *argv_lens,
249 * SilcUInt32 *argv_types,
254 * Encodes Command Payload returning it to SilcBuffer.
257 SilcBuffer silc_command_payload_encode(SilcCommand cmd,
259 unsigned char **argv,
260 SilcUInt32 *argv_lens,
261 SilcUInt32 *argv_types,
264 /****f* silccore/SilcCommandAPI/silc_command_payload_encode_payload
269 * silc_command_payload_encode_payload(SilcCommandPayload payload);
273 * Same as silc_command_payload_encode but encodes the buffer from
274 * SilcCommandPayload structure instead of raw data.
277 SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload);
279 /****f* silccore/SilcCommandAPI/silc_command_payload_encode_va
283 * SilcBuffer silc_command_payload_encode_va(SilcCommand cmd,
285 * SilcUInt32 argc, ...);
289 * Encodes Command payload with variable argument list. The arguments
290 * must be: SilcUInt32, unsigned char *, unsigned int, ... One
291 * {SilcUInt32, unsigned char * and unsigned int} forms one argument,
292 * thus `argc' in case when sending one {SilcUInt32, unsigned char *
293 * and SilcUInt32} equals one (1) and when sending two of those it
294 * equals two (2), and so on. This has to be preserved or bad things
295 * will happen. The variable arguments is: {type, data, data_len}.
298 SilcBuffer silc_command_payload_encode_va(SilcCommand cmd,
300 SilcUInt32 argc, ...);
302 /****f* silccore/SilcCommandAPI/silc_command_payload_encode_vap
306 * SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
308 * SilcUInt32 argc, va_list ap);
312 * This is equivalent to the silc_command_payload_encode_va except
313 * takes the va_list as argument.
316 SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
318 SilcUInt32 argc, va_list ap);
320 /****f* silccore/SilcCommandAPI/silc_command_reply_payload_encode_va
325 * silc_command_reply_payload_encode_va(SilcCommand cmd,
326 * SilcCommandStatus status,
327 * SilcCommandStatus error,
329 * SilcUInt32 argc, ...);
333 * Same as silc_command_payload_encode_va except that this is used to
334 * encode strictly command reply packets. The `argc' must not count
335 * `status' and `error' as arguments. The `status' includes the
336 * command reply status. If single reply will be sent then it includes
337 * SILC_STATUS_OK if error did not occur. It includes an error value
338 * if error did occur. In this case `error' field is ignored. If
339 * there will be multiple successful command replies then the `status'
340 * includes a list value and `error' is ignored. If there will
341 * multiple error replies the `status' includes a list value, and
342 * the `error' includes an error value. Thus, the `error' value is
343 * specified only if there will be list of errors.
347 * Protocol defines that it is possible to send both list of successful
348 * and list of error replies at the same time, as long as the error
349 * replies are sent after the successful replies.
353 silc_command_reply_payload_encode_va(SilcCommand cmd,
354 SilcCommandStatus status,
355 SilcCommandStatus error,
357 SilcUInt32 argc, ...);
359 /****f* silccore/SilcCommandAPI/silc_command_reply_payload_encode_vap
364 * silc_command_reply_payload_encode_vap(SilcCommand cmd,
365 * SilcCommandStatus status,
366 * SilcCommandStatus error,
367 * SilcUInt16 ident, SilcUInt32 argc,
372 * This is equivalent to the silc_command_reply_payload_encode_va except
373 * takes the va_list as argument.
377 silc_command_reply_payload_encode_vap(SilcCommand cmd,
378 SilcCommandStatus status,
379 SilcCommandStatus error,
380 SilcUInt16 ident, SilcUInt32 argc,
383 /****f* silccore/SilcCommandAPI/silc_command_free
387 * void silc_command_payload_free(SilcCommandPayload payload);
391 * Frees the Command Payload and all data in it.
394 void silc_command_payload_free(SilcCommandPayload payload);
396 /****f* silccore/SilcCommandAPI/silc_command_get
400 * SilcCommand silc_command_get(SilcCommandPayload payload);
404 * Return the command from the payload.
407 SilcCommand silc_command_get(SilcCommandPayload payload);
409 /****f* silccore/SilcCommandAPI/silc_command_get_args
413 * SilcArgumentPayload silc_command_get_args(SilcCommandPayload payload);
417 * Return the Arguments Payload containing the arguments from the
418 * Command Payload. The caller must not free it.
421 SilcArgumentPayload silc_command_get_args(SilcCommandPayload payload);
423 /****f* silccore/SilcCommandAPI/silc_command_get_ident
427 * SilcUInt16 silc_command_get_ident(SilcCommandPayload payload);
431 * Return the command identifier from the payload. The identifier can
432 * be used to identify which command reply belongs to which command.
433 * The client sets the identifier to the payload and server must return
434 * the same identifier in the command reply.
437 SilcUInt16 silc_command_get_ident(SilcCommandPayload payload);
439 /****f* silccore/SilcCommandAPI/silc_command_get_status
443 * bool silc_command_get_status(SilcCommandPayload payload,
444 * SilcCommandStatus *status,
445 * SilcCommandStatus *error);
449 * This function returns the command reply status into `status' and
450 * error status, if error occurred into the `error'. The function
451 * returns TRUE if command reply status is not error, and FALSE if
452 * error occurred. In this case the `error' will include the actual
453 * error status. The `status' can be in this case some list value
454 * which indicates that there will be list of errors.
457 bool silc_command_get_status(SilcCommandPayload payload,
458 SilcCommandStatus *status,
459 SilcCommandStatus *error);
461 /****f* silccore/SilcCommandAPI/silc_command_set_ident
465 * void silc_command_set_ident(SilcCommandPayload payload,
470 * Function to set identifier to already allocated Command Payload. Command
471 * payloads are frequentlly resent in SILC and thusly this makes it easy
472 * to set the identifier without encoding new Command Payload.
475 void silc_command_set_ident(SilcCommandPayload payload, SilcUInt16 ident);
477 /****f* silccore/SilcCommandAPI/silc_command_set_command
481 * void silc_command_set_command(SilcCommandPayload payload,
482 * SilcCommand command);
486 * Function to set the command to already allocated Command Payload. This
487 * makes it easy to change the command in the payload without encoding new
491 void silc_command_set_command(SilcCommandPayload payload, SilcCommand command);