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.
24 /* Command function callback. The actual command function pointer. */
25 typedef void (*SilcCommandCb)(void *context);
27 /* Typedefinition for SILC commands. */
28 typedef unsigned char SilcCommand;
30 /* Forward declaration for Command Payload parsed from packet. The
31 actual structure is defined in source file and is private data. */
32 typedef struct SilcCommandPayloadStruct *SilcCommandPayload;
34 /* Command flags. These set how the commands behave on different
35 situations. These can be OR'ed together to set multiple flags. */
39 /* Command may only be used once per (about) 2 seconds */
40 SILC_CF_LAG = (1L << 1),
42 /* Command is available for registered connections (connections
43 whose ID has been created. */
44 SILC_CF_REG = (1L << 2),
46 /* Command is available only for server operators */
47 SILC_CF_OPER = (1L << 3),
49 /* Command is available only for SILC (router) operators. If this
50 is set SILC_CF_OPER is not necessary to be set. */
51 SILC_CF_SILC_OPER = (1L << 4),
55 /* All SILC commands. These are commands that have client and server
56 counterparts. These are pretty much the same as in IRC. */
57 #define SILC_COMMAND_NONE 0
58 #define SILC_COMMAND_WHOIS 2
59 #define SILC_COMMAND_WHOWAS 3
60 #define SILC_COMMAND_IDENTIFY 4
61 #define SILC_COMMAND_NICK 5
62 #define SILC_COMMAND_LIST 6
63 #define SILC_COMMAND_TOPIC 7
64 #define SILC_COMMAND_INVITE 8
65 #define SILC_COMMAND_QUIT 9
66 #define SILC_COMMAND_KILL 10
67 #define SILC_COMMAND_INFO 11
68 #define SILC_COMMAND_CONNECT 12
69 #define SILC_COMMAND_PING 13
70 #define SILC_COMMAND_OPER 14
71 #define SILC_COMMAND_JOIN 15
72 #define SILC_COMMAND_MOTD 16
73 #define SILC_COMMAND_UMODE 17
74 #define SILC_COMMAND_CMODE 18
75 #define SILC_COMMAND_KICK 19
76 #define SILC_COMMAND_RESTART 20
77 #define SILC_COMMAND_CLOSE 21
78 #define SILC_COMMAND_DIE 22
79 #define SILC_COMMAND_SILCOPER 23
80 #define SILC_COMMAND_LEAVE 24
81 #define SILC_COMMAND_NAMES 25
83 /* Local commands. Local commands are unofficial commands and
84 are implementation specific commands. These are used only by the
85 SILC client to extend user commands. */
86 #define SILC_COMMAND_HELP 100
87 #define SILC_COMMAND_CLEAR 101
88 #define SILC_COMMAND_VERSION 102
89 #define SILC_COMMAND_SERVER 103
90 #define SILC_COMMAND_MSG 104
91 #define SILC_COMMAND_AWAY 105
94 #define SILC_COMMAND_RESERVED 255
96 /* Command Status type */
97 typedef unsigned short SilcCommandStatus;
99 /* Command Status messages */
100 #define SILC_STATUS_OK 0
101 #define SILC_STATUS_LIST_START 1
102 #define SILC_STATUS_LIST_END 2
103 #define SILC_STATUS_ERR_NO_SUCH_NICK 10
104 #define SILC_STATUS_ERR_NO_SUCH_CHANNEL 11
105 #define SILC_STATUS_ERR_NO_SUCH_SERVER 12
106 #define SILC_STATUS_ERR_TOO_MANY_TARGETS 13
107 #define SILC_STATUS_ERR_NO_RECIPIENT 14
108 #define SILC_STATUS_ERR_UNKNOWN_COMMAND 15
109 #define SILC_STATUS_ERR_WILDCARDS 16
110 #define SILC_STATUS_ERR_NO_CLIENT_ID 17
111 #define SILC_STATUS_ERR_NO_CHANNEL_ID 18
112 #define SILC_STATUS_ERR_BAD_CLIENT_ID 19
113 #define SILC_STATUS_ERR_BAD_CHANNEL_ID 20
114 #define SILC_STATUS_ERR_NO_SUCH_CLIENT_ID 21
115 #define SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID 22
116 #define SILC_STATUS_ERR_NICKNAME_IN_USE 23
117 #define SILC_STATUS_ERR_NOT_ON_CHANNEL 24
118 #define SILC_STATUS_ERR_USER_ON_CHANNEL 25
119 #define SILC_STATUS_ERR_NOT_REGISTERED 26
120 #define SILC_STATUS_ERR_NOT_ENOUGH_PARAMS 27
121 #define SILC_STATUS_ERR_TOO_MANY_PARAMS 28
122 #define SILC_STATUS_ERR_PERM_DENIED 29
123 #define SILC_STATUS_ERR_BANNED_FROM_SERVER 30
124 #define SILC_STATUS_ERR_BAD_PASSWORD 31
125 #define SILC_STATUS_ERR_CHANNEL_IS_FULL 32
126 #define SILC_STATUS_ERR_NOT_INVITED 33
127 #define SILC_STATUS_ERR_BANNED_FROM_CHANNEL 34
128 #define SILC_STATUS_ERR_UNKNOWN_MODE 35
129 #define SILC_STATUS_ERR_NOT_YOU 36
130 #define SILC_STATUS_ERR_NO_CHANNEL_PRIV 37
131 #define SILC_STATUS_ERR_NO_SERVER_PRIV 38
132 #define SILC_STATUS_ERR_NO_ROUTER_PRIV 39
133 #define SILC_STATUS_ERR_BAD_NICKNAME 40
134 #define SILC_STATUS_ERR_BAD_CHANNEL 41
135 #define SILC_STATUS_ERR_AUTH_FAILED 42
138 SilcCommandPayload silc_command_parse_payload(SilcBuffer buffer);
139 SilcBuffer silc_command_encode_payload(SilcCommand cmd,
141 unsigned char **argv,
142 unsigned int *argv_lens,
143 unsigned int *argv_types);
144 SilcBuffer silc_command_encode_payload_va(SilcCommand cmd,
145 unsigned int argc, ...);
146 void silc_command_free_payload(SilcCommandPayload payload);
147 SilcCommand silc_command_get(SilcCommandPayload payload);
148 unsigned int silc_command_get_arg_num(SilcCommandPayload payload);
149 unsigned char *silc_command_get_first_arg(SilcCommandPayload payload,
150 unsigned int *ret_len);
151 unsigned char *silc_command_get_next_arg(SilcCommandPayload payload,
152 unsigned int *ret_len);
153 unsigned char *silc_command_get_arg_type(SilcCommandPayload payload,
155 unsigned int *ret_len);
156 SilcBuffer silc_command_encode_status_payload(SilcCommandStatus status,