]> jfr.im git - irc/evilnet/x3.git/blame_incremental - src/proto.h
Couple of srvx updates.
[irc/evilnet/x3.git] / src / proto.h
... / ...
CommitLineData
1/* proto.h - IRC protocol output
2 * Copyright 2000-2004 srvx Development Team
3 *
4 * This file is part of x3.
5 *
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */
20
21#if !defined(PROTO_H)
22#define PROTO_H
23
24/* Warning for those looking at how this code does multi-protocol
25 * support: It's an awful, nasty hack job. It is intended for short
26 * term use, not long term, since we are already developing x3,
27 * which has much nicer interfaces that hide most of the ugly
28 * differences between protocol dialects. */
29
30#define COMBO_NUMERIC_LEN 5 /* 1/2, 1/3 or 2/3 digits for server/client parts */
31#define MAXLEN 512 /* Maximum IRC line length */
32#define MAXNUMPARAMS 200
33#define ALLCHANMSG_FUNCS_MAX 4 /* +1 == 5 potential 'allchanmsg' funcs */
34
35struct gline;
36struct shun;
37struct server;
38struct userNode;
39struct chanNode;
40
41/* connection manager state */
42
43enum cState
44{
45 DISCONNECTED,
46 AUTHENTICATING,
47 BURSTING,
48 CONNECTED
49};
50
51#define UPLINK_UNAVAILABLE 0x001
52
53struct uplinkNode
54{
55 char *name;
56
57 char *host;
58 int port;
59
60 struct sockaddr *bind_addr;
61 int bind_addr_len;
62
63 char *password;
64 char *their_password;
65
66 enum cState state;
67 int tries;
68 int max_tries;
69 long flags;
70
71 struct uplinkNode *prev;
72 struct uplinkNode *next;
73};
74
75struct cManagerNode
76{
77 struct uplinkNode *uplinks;
78 struct uplinkNode *uplink;
79
80 int cycles;
81 int enabled;
82};
83
84#ifdef WITH_PROTOCOL_P10
85struct server* GetServerN(const char *numeric);
86struct userNode* GetUserN(const char *numeric);
87#endif
88
89/* Basic protocol parsing support. */
90void init_parse(void);
91int parse_line(char *line, int recursive);
92
93char *client_report_privs(struct userNode *client);
94int check_priv(char *priv);
95
96/* Callback notifications for protocol support. */
97typedef void (*chanmsg_func_t) (struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice, void *extra);
98void reg_chanmsg_func(unsigned char prefix, struct userNode *service, chanmsg_func_t handler, void *extra);
99void reg_allchanmsg_func(struct userNode *service, chanmsg_func_t handler);
100struct userNode *get_chanmsg_bot(unsigned char prefix);
101
102typedef void (*privmsg_func_t) (struct userNode *user, struct userNode *target, const char *text, int server_qualified);
103void reg_privmsg_func(struct userNode *user, privmsg_func_t handler);
104void reg_notice_func(struct userNode *user, privmsg_func_t handler);
105void unreg_privmsg_func(struct userNode *user);
106void unreg_notice_func(struct userNode *user);
107
108typedef void (*oper_func_t) (struct userNode *user, void *extra);
109void reg_oper_func(oper_func_t handler, void *extra);
110
111/* replay silliness */
112void replay_read_line(void);
113void replay_event_loop(void);
114
115/* connection maintenance */
116void irc_server(struct server *srv);
117void irc_user(struct userNode *user);
118void irc_nick(struct userNode *user, const char *old_nick);
119void irc_introduce(const char *passwd);
120void irc_ping(const char *something);
121void irc_pong(const char *who, const char *data);
122void irc_quit(struct userNode *user, const char *message);
123void irc_squit(struct server *srv, const char *message, const char *service_message);
124void irc_squit_route(struct server *srv, const char *message, ...);
125void irc_connect(struct userNode *user, char *server, unsigned int port, struct server *target);
126
127/* messages */
128void irc_privmsg(struct userNode *from, const char *to, const char *message);
129void irc_privmsg_user(struct userNode *from, struct userNode *to, const char *message);
130void irc_notice(struct userNode *from, const char *to, const char *message);
131void irc_notice_user(struct userNode *from, struct userNode *to, const char *message);
132void irc_version_user(struct userNode *from, struct userNode *to);
133void irc_wallchops(struct userNode *from, const char *to, const char *message);
134void irc_wallops(const char *format, ...);
135
136/* channel maintenance */
137void irc_join(struct userNode *who, struct chanNode *what);
138void irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to);
139void irc_mode(struct userNode *who, struct chanNode *target, const char *modes);
140void irc_umode(struct userNode *target, const char *modes);
141void irc_kick(struct userNode *who, struct userNode *target, struct chanNode *from, const char *msg);
142void irc_part(struct userNode *who, struct chanNode *what, const char *reason);
143void irc_topic(struct userNode *service, struct userNode *who, struct chanNode *what, const char *topic);
144void irc_fetchtopic(struct userNode *from, const char *to);
145void irc_svsjoin(struct userNode *from, struct userNode *who, struct chanNode *to);
146void irc_svspart(struct userNode *from, struct userNode *who, struct chanNode *to);
147void irc_svsquit(struct userNode *from, struct userNode *who, char const *reason);
148
149/* network maintenance */
150void irc_silence(struct userNode *who, const char *mask, int add);
151void irc_gline(struct server *srv, struct gline *gline, int silent);
152void irc_shun(struct server *srv, struct shun *shun);
153void irc_settime(const char *srv_name_mask, time_t new_time);
154void irc_ungline(const char *mask);
155void irc_unshun(const char *mask);
156void irc_error(const char *to, const char *message);
157void irc_kill(struct userNode *from, struct userNode *target, const char *message);
158void irc_raw(const char *what);
159void irc_stats(struct userNode *from, struct server *target, char type);
160void irc_svsnick(struct userNode *from, struct userNode *target, const char *newnick);
161void irc_swhois(struct userNode *from, struct userNode *target, const char *message);
162void irc_privs(struct userNode *target, char *flag, int add);
163void irc_raw_privs(struct userNode *target, const char *privs);
164
165/* account maintenance */
166void irc_rename(struct userNode *user, const char *new_handle);
167void irc_delete(struct userNode *user);
168void irc_account(struct userNode *user, const char *stamp, time_t timestamp);
169void irc_regnick(struct userNode *user);
170void irc_fakehost(struct userNode *user, const char *host);
171void irc_mark(struct userNode *user, char *mark);
172void irc_sno(unsigned int mask, char const* format, ...);
173
174/* numeric messages */
175void irc_numeric(struct userNode *user, unsigned int num, const char *format, ...);
176/* RFC1459-compliant numeric responses */
177#define RPL_ENDOFSTATS 219
178#define RPL_STATSUPTIME 242
179#define RPL_MAXCONNECTIONS 250
180#define RPL_AWAY 301
181#define RPL_WHOISUSER 311
182#define RPL_WHOISSERVER 312
183#define RPL_WHOISOPERATOR 313
184#define RPL_WHOISIDLE 317
185#define RPL_ENDOFWHOIS 318
186#define RPL_WHOISCHANNELS 319
187#define RPL_WHOISACCOUNT 330
188#define RPL_WHOISACTUALLY 338
189#define ERR_NOSUCHNICK 401
190
191/* stuff originally from other headers that is really protocol-specific */
192int IsChannelName(const char *name);
193int is_valid_nick(const char *nick);
194struct userNode *AddLocalUser(const char *nick, const char *ident, const char *hostname, const char *desc, const char *modes);
195struct server* AddServer(struct server* uplink, const char *name, int hops, time_t boot, time_t link, const char *numeric, const char *description);
196void DelServer(struct server* serv, int announce, const char *message);
197void DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why);
198/* Most protocols will want to make an AddUser helper function. */
199
200/* User modes */
201void mod_usermode(struct userNode *user, const char *modes);
202extern const char irc_user_mode_chars[];
203unsigned int irc_user_modes(const struct userNode *user, char modes[], size_t length);
204
205/* Channel mode manipulation */
206#define KEYLEN 23
207typedef unsigned long chan_mode_t;
208/* Rules for struct mod_chanmode:
209 * For a membership mode change, args[n].mode can contain more than
210 * one mode bit (e.g. MODE_CHANOP|MODE_VOICE). Hostmask strings are
211 * "owned" by the caller and are not freed by mod_chanmode_free().
212 */
213struct mod_chanmode {
214 chan_mode_t modes_set, modes_clear;
215 unsigned int new_limit, argc;
216#ifndef NDEBUG
217 unsigned int alloc_argc;
218#endif
219 char new_key[KEYLEN + 1];
220 char new_upass[KEYLEN + 1];
221 char new_apass[KEYLEN + 1];
222 struct {
223 unsigned int mode;
224 union {
225 struct modeNode *member;
226 const char *hostmask;
227 } u;
228 } args[1];
229};
230#define MCP_ALLOW_OVB 0x0001 /* allow op, voice, ban manipulation */
231#define MCP_FROM_SERVER 0x0002 /* parse as from a server */
232#define MCP_KEY_FREE 0x0004 /* -k without a key argument */
233#define MCP_REGISTERED 0x0008 /* chan is already registered; do not allow changes to MODE_REGISTERED */
234#define MCP_UPASS_FREE 0x0010 /* -U without a key argument */
235#define MCP_APASS_FREE 0x0020 /* -A without a key argument */
236#define MC_ANNOUNCE 0x0100 /* send a mod_chanmode() change out */
237#define MC_NOTIFY 0x0200 /* make local callbacks to announce */
238#ifdef NDEBUG
239#define mod_chanmode_init(CHANMODE) do { memset((CHANMODE), 0, sizeof(*CHANMODE)); } while (0)
240#else
241#define mod_chanmode_init(CHANMODE) do { memset((CHANMODE), 0, sizeof(*CHANMODE)); (CHANMODE)->alloc_argc = ArrayLength((CHANMODE)->args); } while (0)
242#endif
243
244struct mod_chanmode *mod_chanmode_alloc(unsigned int argc);
245struct mod_chanmode *mod_chanmode_dup(struct mod_chanmode *orig, unsigned int extra);
246struct mod_chanmode *mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags, short base_oplevel);
247void mod_chanmode_apply(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
248void mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
249char *mod_chanmode_format(struct mod_chanmode *desc, char *buffer);
250void mod_chanmode_free(struct mod_chanmode *change);
251int mod_chanmode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags);
252typedef void (*mode_change_func_t) (struct chanNode *channel, struct userNode *user, const struct mod_chanmode *change, void *extra);
253void reg_mode_change_func(mode_change_func_t handler, void *extra);
254int irc_make_chanmode(struct chanNode *chan, char *out);
255int client_modify_priv_by_name(struct userNode *who, char *priv, int what);
256
257/* The "default" for generate_hostmask is to have all of these options off. */
258#define GENMASK_STRICT_HOST 1
259#define GENMASK_STRICT_IDENT 32
260#define GENMASK_ANY_IDENT 64
261#define GENMASK_STRICT (GENMASK_STRICT_IDENT|GENMASK_STRICT_HOST)
262#define GENMASK_USENICK 2
263#define GENMASK_OMITNICK 4 /* Hurray for Kevin! */
264#define GENMASK_BYIP 8
265#define GENMASK_X3MASK 16
266#define GENMASK_NO_HIDING 128
267char *generate_hostmask(struct userNode *user, int options);
268
269#endif /* !defined(PROTO_H) */