]> jfr.im git - irc/evilnet/x3.git/blame - src/proto.h
sync trunk to 1.6 changes
[irc/evilnet/x3.git] / src / proto.h
CommitLineData
d76ed9a9 1/* proto.h - IRC protocol output
2 * Copyright 2000-2004 srvx Development Team
3 *
83ff05c3 4 * This file is part of x3.
d76ed9a9 5 *
d0f04f71 6 * x3 is free software; you can redistribute it and/or modify
d76ed9a9 7 * it under the terms of the GNU General Public License as published by
348683aa 8 * the Free Software Foundation; either version 3 of the License, or
d76ed9a9 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
921592dd 26 * term use, not long term, since we are already developing x3,
d76ed9a9 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
0f6fe38c 35#ifdef HAVE_NETINET_IN_H
36#include <netinet/in.h>
37#endif
38
d76ed9a9 39struct gline;
d914d1cb 40struct shun;
d76ed9a9 41struct server;
42struct userNode;
43struct chanNode;
44
45/* connection manager state */
46
47enum cState
48{
49 DISCONNECTED,
50 AUTHENTICATING,
51 BURSTING,
52 CONNECTED
53};
54
55#define UPLINK_UNAVAILABLE 0x001
56
57struct uplinkNode
58{
59 char *name;
60
61 char *host;
62 int port;
63
2f61d1d7 64 struct sockaddr *bind_addr;
d76ed9a9 65 int bind_addr_len;
66
67 char *password;
68 char *their_password;
69
70 enum cState state;
71 int tries;
72 int max_tries;
73 long flags;
74
75 struct uplinkNode *prev;
76 struct uplinkNode *next;
77};
78
79struct cManagerNode
80{
81 struct uplinkNode *uplinks;
82 struct uplinkNode *uplink;
83
84 int cycles;
85 int enabled;
86};
87
88#ifdef WITH_PROTOCOL_P10
89struct server* GetServerN(const char *numeric);
90struct userNode* GetUserN(const char *numeric);
91#endif
92
93/* Basic protocol parsing support. */
94void init_parse(void);
95int parse_line(char *line, int recursive);
96
89d871d8 97char *client_report_privs(struct userNode *client);
6c34bb5a 98int check_priv(char *priv);
89d871d8 99
d76ed9a9 100/* Callback notifications for protocol support. */
0f6fe38c 101typedef void (*chanmsg_func_t) (struct userNode *user, struct chanNode *chan, char *text, struct userNode *bot);
d76ed9a9 102void reg_chanmsg_func(unsigned char prefix, struct userNode *service, chanmsg_func_t handler);
103void reg_allchanmsg_func(struct userNode *service, chanmsg_func_t handler);
104struct userNode *get_chanmsg_bot(unsigned char prefix);
105
0f6fe38c 106typedef void (*privmsg_func_t) (struct userNode *user, struct userNode *target, char *text, int server_qualified);
d76ed9a9 107void reg_privmsg_func(struct userNode *user, privmsg_func_t handler);
108void reg_notice_func(struct userNode *user, privmsg_func_t handler);
0f6fe38c 109void unreg_privmsg_func(struct userNode *user, privmsg_func_t handler);
110void unreg_notice_func(struct userNode *user, privmsg_func_t handler);
d76ed9a9 111
112typedef void (*oper_func_t) (struct userNode *user);
113void reg_oper_func(oper_func_t handler);
114
d76ed9a9 115/* replay silliness */
116void replay_read_line(void);
117void replay_event_loop(void);
118
119/* connection maintenance */
120void irc_server(struct server *srv);
121void irc_user(struct userNode *user);
122void irc_nick(struct userNode *user, const char *old_nick);
123void irc_introduce(const char *passwd);
124void irc_ping(const char *something);
125void irc_pong(const char *who, const char *data);
126void irc_quit(struct userNode *user, const char *message);
127void irc_squit(struct server *srv, const char *message, const char *service_message);
47956fc5 128void irc_squit_route(struct server *srv, const char *message, ...);
129void irc_connect(struct userNode *user, char *server, unsigned int port, struct server *target);
d76ed9a9 130
131/* messages */
132void irc_privmsg(struct userNode *from, const char *to, const char *message);
133void irc_notice(struct userNode *from, const char *to, const char *message);
134void irc_notice_user(struct userNode *from, struct userNode *to, const char *message);
0e08a8e0 135void irc_version_user(struct userNode *from, struct userNode *to);
d76ed9a9 136void irc_wallchops(struct userNode *from, const char *to, const char *message);
47956fc5 137void irc_wallops(const char *format, ...);
d76ed9a9 138
139/* channel maintenance */
140void irc_join(struct userNode *who, struct chanNode *what);
141void irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to);
142void irc_mode(struct userNode *who, struct chanNode *target, const char *modes);
5a1daaab 143void irc_umode(struct userNode *target, const char *modes);
d76ed9a9 144void irc_kick(struct userNode *who, struct userNode *target, struct chanNode *from, const char *msg);
145void irc_part(struct userNode *who, struct chanNode *what, const char *reason);
7fda2b52 146void irc_topic(struct userNode *service, struct userNode *who, struct chanNode *what, const char *topic);
d76ed9a9 147void irc_fetchtopic(struct userNode *from, const char *to);
cd25f2e9 148void irc_svsjoin(struct userNode *from, struct userNode *who, struct chanNode *to);
39c1a4ef 149void irc_svspart(struct userNode *from, struct userNode *who, struct chanNode *to);
5e6460e4 150void irc_svsquit(struct userNode *from, struct userNode *who, char *reason);
d76ed9a9 151
152/* network maintenance */
5177fd21 153void irc_silence(struct userNode *who, const char *mask, int add);
9a75756e 154void irc_gline(struct server *srv, struct gline *gline, int silent);
d914d1cb 155void irc_shun(struct server *srv, struct shun *shun);
d76ed9a9 156void irc_settime(const char *srv_name_mask, time_t new_time);
157void irc_ungline(const char *mask);
d914d1cb 158void irc_unshun(const char *mask);
d76ed9a9 159void irc_error(const char *to, const char *message);
160void irc_kill(struct userNode *from, struct userNode *target, const char *message);
161void irc_raw(const char *what);
162void irc_stats(struct userNode *from, struct server *target, char type);
163void irc_svsnick(struct userNode *from, struct userNode *target, const char *newnick);
56958740 164void irc_swhois(struct userNode *from, struct userNode *target, const char *message);
6c34bb5a 165void irc_privs(struct userNode *target, char *flag, int add);
d76ed9a9 166
167/* account maintenance */
a45e6ec7 168void irc_rename(struct userNode *user, const char *new_handle);
169void irc_delete(struct userNode *user);
b21e2cfe 170void irc_account(struct userNode *user, const char *stamp, time_t timestamp);
d76ed9a9 171void irc_regnick(struct userNode *user);
172void irc_fakehost(struct userNode *user, const char *host);
d82cf2f0 173void irc_mark(struct userNode *user, char *mark);
d76ed9a9 174
175/* numeric messages */
176void irc_numeric(struct userNode *user, unsigned int num, const char *format, ...);
177/* RFC1459-compliant numeric responses */
178#define RPL_ENDOFSTATS 219
179#define RPL_STATSUPTIME 242
180#define RPL_MAXCONNECTIONS 250
181#define RPL_WHOISUSER 311
182#define RPL_WHOISSERVER 312
183#define RPL_WHOISOPERATOR 313
184#define RPL_ENDOFWHOIS 318
185#define ERR_NOSUCHNICK 401
186
187/* stuff originally from other headers that is really protocol-specific */
188int IsChannelName(const char *name);
189int is_valid_nick(const char *nick);
0f6fe38c 190struct userNode *AddService(const char *nick, const char *modes, const char *desc, const char *hostname);
191struct userNode *AddClone(const char *nick, const char *ident, const char *hostname, const char *desc);
d76ed9a9 192struct server* AddServer(struct server* uplink, const char *name, int hops, time_t boot, time_t link, const char *numeric, const char *description);
193void DelServer(struct server* serv, int announce, const char *message);
194void DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why);
195/* Most protocols will want to make an AddUser helper function. */
196
197/* User modes */
198void mod_usermode(struct userNode *user, const char *modes);
199
200/* Channel mode manipulation */
201#define KEYLEN 23
202typedef unsigned long chan_mode_t;
203/* Rules for struct mod_chanmode:
204 * For a membership mode change, args[n].mode can contain more than
205 * one mode bit (e.g. MODE_CHANOP|MODE_VOICE). Hostmask strings are
206 * "owned" by the caller and are not freed by mod_chanmode_free().
207 */
208struct mod_chanmode {
209 chan_mode_t modes_set, modes_clear;
210 unsigned int new_limit, argc;
211#ifndef NDEBUG
212 unsigned int alloc_argc;
213#endif
214 char new_key[KEYLEN + 1];
2f61d1d7 215 char new_upass[KEYLEN + 1];
216 char new_apass[KEYLEN + 1];
d76ed9a9 217 struct {
218 unsigned int mode;
219 union {
220 struct modeNode *member;
221 const char *hostmask;
a32da4c7 222 } u;
d76ed9a9 223 } args[1];
224};
225#define MCP_ALLOW_OVB 0x0001 /* allow op, voice, ban manipulation */
226#define MCP_FROM_SERVER 0x0002 /* parse as from a server */
227#define MCP_KEY_FREE 0x0004 /* -k without a key argument */
a32da4c7 228#define MCP_REGISTERED 0x0008 /* chan is already registered; do not allow changes to MODE_REGISTERED */
2f61d1d7 229#define MCP_UPASS_FREE 0x0010 /* -U without a key argument */
230#define MCP_APASS_FREE 0x0020 /* -A without a key argument */
d76ed9a9 231#define MC_ANNOUNCE 0x0100 /* send a mod_chanmode() change out */
232#define MC_NOTIFY 0x0200 /* make local callbacks to announce */
233#ifdef NDEBUG
234#define mod_chanmode_init(CHANMODE) do { memset((CHANMODE), 0, sizeof(*CHANMODE)); } while (0)
235#else
236#define mod_chanmode_init(CHANMODE) do { memset((CHANMODE), 0, sizeof(*CHANMODE)); (CHANMODE)->alloc_argc = ArrayLength((CHANMODE)->args); } while (0)
237#endif
238
239struct mod_chanmode *mod_chanmode_alloc(unsigned int argc);
240struct mod_chanmode *mod_chanmode_dup(struct mod_chanmode *orig, unsigned int extra);
2f61d1d7 241struct mod_chanmode *mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags, short base_oplevel);
d76ed9a9 242void mod_chanmode_apply(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
243void mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
244char *mod_chanmode_format(struct mod_chanmode *desc, char *buffer);
245void mod_chanmode_free(struct mod_chanmode *change);
246int mod_chanmode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags);
247typedef void (*mode_change_func_t) (struct chanNode *channel, struct userNode *user, const struct mod_chanmode *change);
248void reg_mode_change_func(mode_change_func_t handler);
249int irc_make_chanmode(struct chanNode *chan, char *out);
250
251/* The "default" for generate_hostmask is to have all of these options off. */
252#define GENMASK_STRICT_HOST 1
253#define GENMASK_STRICT_IDENT 32
254#define GENMASK_ANY_IDENT 64
255#define GENMASK_STRICT (GENMASK_STRICT_IDENT|GENMASK_STRICT_HOST)
256#define GENMASK_USENICK 2
257#define GENMASK_OMITNICK 4 /* Hurray for Kevin! */
258#define GENMASK_BYIP 8
921592dd 259#define GENMASK_X3MASK 16
d76ed9a9 260#define GENMASK_NO_HIDING 128
261char *generate_hostmask(struct userNode *user, int options);
262
263#endif /* !defined(PROTO_H) */