Splitted SILC core library. Core library includes now only
[silc.git] / lib / silccore / silccommand.h
1 /*
2
3   silccommand.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
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.
13   
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.
18
19 */
20
21 #ifndef SILCCOMMAND_H
22 #define SILCCOMMAND_H
23
24 /* Command function callback. The actual command function pointer. */
25 typedef void (*SilcCommandCb)(void *context);
26
27 /* Typedefinition for SILC commands. */
28 typedef unsigned char SilcCommand;
29
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;
33
34 /* Command flags. These set how the commands behave on different
35    situations. These can be OR'ed together to set multiple flags. */
36 typedef enum {
37   SILC_CF_NONE = 0,
38
39   /* Command may only be used once per (about) 2 seconds */
40   SILC_CF_LAG = (1L << 1),
41
42   /* Command is available for registered connections (connections
43      whose ID has been created. */
44   SILC_CF_REG = (1L << 2),
45
46   /* Command is available only for server operators */
47   SILC_CF_OPER = (1L << 3),
48
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),
52
53 } SilcCommandFlag;
54
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              1
59 #define SILC_COMMAND_WHOWAS             2
60 #define SILC_COMMAND_IDENTIFY           3
61 #define SILC_COMMAND_NICK               4
62 #define SILC_COMMAND_LIST               5
63 #define SILC_COMMAND_TOPIC              6
64 #define SILC_COMMAND_INVITE             7
65 #define SILC_COMMAND_QUIT               8
66 #define SILC_COMMAND_KILL               9
67 #define SILC_COMMAND_INFO               10
68 #define SILC_COMMAND_CONNECT            11
69 #define SILC_COMMAND_PING               12
70 #define SILC_COMMAND_OPER               13
71 #define SILC_COMMAND_JOIN               14
72 #define SILC_COMMAND_MOTD               15
73 #define SILC_COMMAND_UMODE              16
74 #define SILC_COMMAND_CMODE              17
75 #define SILC_COMMAND_KICK               18
76 #define SILC_COMMAND_RESTART            19
77 #define SILC_COMMAND_CLOSE              20
78 #define SILC_COMMAND_DIE                21
79 #define SILC_COMMAND_SILCOPER           22
80 #define SILC_COMMAND_LEAVE              23
81 #define SILC_COMMAND_NAMES              24
82
83 /* Reserved */
84 #define SILC_COMMAND_RESERVED           255
85
86 /* Command Status type */
87 typedef unsigned short SilcCommandStatus;
88
89 /* Command Status messages */
90 #define SILC_STATUS_OK                      0
91 #define SILC_STATUS_LIST_START              1
92 #define SILC_STATUS_LIST_END                2
93 #define SILC_STATUS_ERR_NO_SUCH_NICK        10
94 #define SILC_STATUS_ERR_NO_SUCH_CHANNEL     11
95 #define SILC_STATUS_ERR_NO_SUCH_SERVER      12
96 #define SILC_STATUS_ERR_TOO_MANY_TARGETS    13
97 #define SILC_STATUS_ERR_NO_RECIPIENT        14
98 #define SILC_STATUS_ERR_UNKNOWN_COMMAND     15
99 #define SILC_STATUS_ERR_WILDCARDS           16
100 #define SILC_STATUS_ERR_NO_CLIENT_ID        17
101 #define SILC_STATUS_ERR_NO_CHANNEL_ID       18
102 #define SILC_STATUS_ERR_NO_SERVER_ID        19
103 #define SILC_STATUS_ERR_BAD_CLIENT_ID       20
104 #define SILC_STATUS_ERR_BAD_CHANNEL_ID      21
105 #define SILC_STATUS_ERR_NO_SUCH_CLIENT_ID   22
106 #define SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID  23
107 #define SILC_STATUS_ERR_NICKNAME_IN_USE     24
108 #define SILC_STATUS_ERR_NOT_ON_CHANNEL      25
109 #define SILC_STATUS_ERR_USER_ON_CHANNEL     26
110 #define SILC_STATUS_ERR_NOT_REGISTERED      27
111 #define SILC_STATUS_ERR_NOT_ENOUGH_PARAMS   28
112 #define SILC_STATUS_ERR_TOO_MANY_PARAMS     29
113 #define SILC_STATUS_ERR_PERM_DENIED         30
114 #define SILC_STATUS_ERR_BANNED_FROM_SERVER  31
115 #define SILC_STATUS_ERR_BAD_PASSWORD        32
116 #define SILC_STATUS_ERR_CHANNEL_IS_FULL     33
117 #define SILC_STATUS_ERR_NOT_INVITED         34
118 #define SILC_STATUS_ERR_BANNED_FROM_CHANNEL 35
119 #define SILC_STATUS_ERR_UNKNOWN_MODE        36
120 #define SILC_STATUS_ERR_NOT_YOU             37
121 #define SILC_STATUS_ERR_NO_CHANNEL_PRIV     38
122 #define SILC_STATUS_ERR_NO_SERVER_PRIV      39
123 #define SILC_STATUS_ERR_NO_ROUTER_PRIV      40
124 #define SILC_STATUS_ERR_BAD_NICKNAME        41
125 #define SILC_STATUS_ERR_BAD_CHANNEL         42
126 #define SILC_STATUS_ERR_AUTH_FAILED         43
127
128 /* Prototypes */
129 SilcCommandPayload silc_command_parse_payload(SilcBuffer buffer);
130 SilcBuffer silc_command_encode_payload(SilcCommand cmd,
131                                        unsigned int argc,
132                                        unsigned char **argv,
133                                        unsigned int *argv_lens,
134                                        unsigned int *argv_types);
135 SilcBuffer silc_command_encode_payload_va(SilcCommand cmd, 
136                                           unsigned int argc, ...);
137 SilcBuffer 
138 silc_command_encode_reply_payload_va(SilcCommand cmd, 
139                                      SilcCommandStatus status,
140                                      unsigned int argc, ...);
141 void silc_command_free_payload(SilcCommandPayload payload);
142 SilcCommand silc_command_get(SilcCommandPayload payload);
143 unsigned int silc_command_get_arg_num(SilcCommandPayload payload);
144 unsigned char *silc_command_get_first_arg(SilcCommandPayload payload,
145                                           unsigned int *ret_len);
146 unsigned char *silc_command_get_next_arg(SilcCommandPayload payload,
147                                          unsigned int *ret_len);
148 unsigned char *silc_command_get_arg_type(SilcCommandPayload payload,
149                                          unsigned int type,
150                                          unsigned int *ret_len);
151
152 #endif