Initial import (again)
[srvx.git] / src / proto.h
1 /* proto.h - IRC protocol output
2  * Copyright 2000-2004 srvx Development Team
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  */
18
19 #if !defined(PROTO_H)
20 #define PROTO_H
21
22 /* Warning for those looking at how this code does multi-protocol
23  * support: It's an awful, nasty hack job.  It is intended for short
24  * term use, not long term, since we are already developing srvx2,
25  * which has much nicer interfaces that hide most of the ugly
26  * differences between protocol dialects. */
27
28 #define COMBO_NUMERIC_LEN 5   /* 1/2, 1/3 or 2/3 digits for server/client parts */
29 #define MAXLEN          512   /* Maximum IRC line length */
30 #define MAXNUMPARAMS    200
31
32 #ifdef HAVE_NETINET_IN_H
33 #include <netinet/in.h>
34 #endif
35
36 struct gline;
37 struct server;
38 struct userNode;
39 struct chanNode;
40
41 /* connection manager state */
42
43 enum cState
44 {
45     DISCONNECTED,
46     AUTHENTICATING,
47     BURSTING,
48     CONNECTED
49 };
50
51 #define UPLINK_UNAVAILABLE      0x001
52
53 struct uplinkNode
54 {
55     char                *name;
56
57     char                *host;
58     int                 port;
59
60     struct sockaddr_in  *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
75 struct cManagerNode
76 {
77     struct uplinkNode   *uplinks;
78     struct uplinkNode   *uplink;
79
80     int                 cycles;
81     int                 enabled;
82 };
83
84 #ifdef WITH_PROTOCOL_P10
85 struct server* GetServerN(const char *numeric);
86 struct userNode* GetUserN(const char *numeric);
87 #endif
88
89 /* Basic protocol parsing support. */
90 void init_parse(void);
91 int parse_line(char *line, int recursive);
92
93 /* Callback notifications for protocol support. */
94 typedef void (*chanmsg_func_t) (struct userNode *user, struct chanNode *chan, char *text, struct userNode *bot);
95 void reg_chanmsg_func(unsigned char prefix, struct userNode *service, chanmsg_func_t handler);
96 struct userNode *get_chanmsg_bot(unsigned char prefix);
97
98 typedef void (*privmsg_func_t) (struct userNode *user, struct userNode *target, char *text, int server_qualified);
99 void reg_privmsg_func(struct userNode *user, privmsg_func_t handler);
100 void reg_notice_func(struct userNode *user, privmsg_func_t handler);
101
102 typedef void (*oper_func_t) (struct userNode *user);
103 void reg_oper_func(oper_func_t handler);
104
105 extern struct userList dead_users;
106
107 /* replay silliness */
108 void replay_read_line(void);
109 void replay_event_loop(void);
110
111 /* connection maintenance */
112 void irc_server(struct server *srv);
113 void irc_user(struct userNode *user);
114 void irc_nick(struct userNode *user, const char *old_nick);
115 void irc_introduce(const char *passwd);
116 void irc_ping(const char *something);
117 void irc_pong(const char *who, const char *data);
118 void irc_quit(struct userNode *user, const char *message);
119 void irc_squit(struct server *srv, const char *message, const char *service_message);
120
121 /* messages */
122 void irc_privmsg(struct userNode *from, const char *to, const char *message);
123 void irc_notice(struct userNode *from, const char *to, const char *message);
124 void irc_wallchops(struct userNode *from, const char *to, const char *message);
125
126 /* channel maintenance */
127 void irc_join(struct userNode *who, struct chanNode *what);
128 void irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to);
129 void irc_mode(struct userNode *who, struct chanNode *target, const char *modes);
130 void irc_kick(struct userNode *who, struct userNode *target, struct chanNode *from, const char *msg);
131 void irc_part(struct userNode *who, struct chanNode *what, const char *reason);
132 void irc_topic(struct userNode *who, struct chanNode *what, const char *topic);
133 void irc_fetchtopic(struct userNode *from, const char *to);
134
135 /* network maintenance */
136 void irc_gline(struct server *srv, struct gline *gline);
137 void irc_settime(const char *srv_name_mask, time_t new_time);
138 void irc_ungline(const char *mask);
139 void irc_error(const char *to, const char *message);
140 void irc_kill(struct userNode *from, struct userNode *target, const char *message);
141 void irc_raw(const char *what);
142 void irc_stats(struct userNode *from, struct server *target, char type);
143 void irc_svsnick(struct userNode *from, struct userNode *target, const char *newnick);
144
145 /* account maintenance */
146 void irc_account(struct userNode *user, const char *stamp);
147 void irc_regnick(struct userNode *user);
148
149 /* numeric messages */
150 void irc_numeric(struct userNode *user, unsigned int num, const char *format, ...);
151 /* RFC1459-compliant numeric responses */
152 #define RPL_ENDOFSTATS          219
153 #define RPL_STATSUPTIME         242
154 #define RPL_MAXCONNECTIONS      250
155 #define RPL_WHOISUSER           311
156 #define RPL_WHOISSERVER         312
157 #define RPL_WHOISOPERATOR       313
158 #define RPL_ENDOFWHOIS          318
159 #define ERR_NOSUCHNICK          401
160
161 /* stuff originally from other headers that is really protocol-specific */
162 int IsChannelName(const char *name);
163 int is_valid_nick(const char *nick);
164 struct userNode *AddService(const char *nick, const char *desc);
165 struct userNode *AddClone(const char *nick, const char *ident, const char *hostname, const char *desc);
166 struct server* AddServer(struct server* uplink, const char *name, int hops, time_t boot, time_t link, const char *numeric, const char *description);
167 void DelServer(struct server* serv, int announce, const char *message);
168 void DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why);
169 /* Most protocols will want to make an AddUser helper function. */
170
171 /* User modes */
172 void mod_usermode(struct userNode *user, const char *modes);
173
174 /* Channel mode manipulation */
175 #define KEYLEN          23
176 typedef unsigned long chan_mode_t;
177 /* Rules for struct mod_chanmode:
178  * For a membership mode change, args[n].mode can contain more than
179  * one mode bit (e.g. MODE_CHANOP|MODE_VOICE).  Hostmask strings are
180  * "owned" by the caller and are not freed by mod_chanmode_free().
181  */
182 struct mod_chanmode {
183     chan_mode_t modes_set, modes_clear;
184     unsigned int new_limit, argc;
185     char new_key[KEYLEN + 1];
186     struct {
187         unsigned int mode;
188         union {
189             struct modeNode *member;
190             const char *hostmask;
191         };
192     } args[1];
193 };
194 #define MCP_ALLOW_OVB     0x0001 /* allow op, voice, ban manipulation */
195 #define MCP_FROM_SERVER   0x0002 /* parse as from a server */
196 #define MCP_KEY_FREE      0x0004 /* -k without a key argument */
197 #define MC_ANNOUNCE       0x0100 /* send a mod_chanmode() change out */
198 #define MC_NOTIFY         0x0200 /* make local callbacks to announce */
199 struct mod_chanmode *mod_chanmode_alloc(unsigned int argc);
200 struct mod_chanmode *mod_chanmode_dup(struct mod_chanmode *orig, unsigned int extra);
201 struct mod_chanmode *mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags);
202 void mod_chanmode_apply(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
203 void mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
204 char *mod_chanmode_format(struct mod_chanmode *desc, char *buffer);
205 void mod_chanmode_free(struct mod_chanmode *change);
206 int mod_chanmode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags);
207 typedef void (*mode_change_func_t) (struct chanNode *channel, struct userNode *user, const struct mod_chanmode *change);
208 void reg_mode_change_func(mode_change_func_t handler);
209 int irc_make_chanmode(struct chanNode *chan, char *out);
210
211 /* The "default" for generate_hostmask is to have all of these options off. */
212 #define GENMASK_STRICT_HOST   1
213 #define GENMASK_STRICT_IDENT  32
214 #define GENMASK_ANY_IDENT     64
215 #define GENMASK_STRICT   (GENMASK_STRICT_IDENT|GENMASK_STRICT_HOST)
216 #define GENMASK_USENICK  2
217 #define GENMASK_OMITNICK 4  /* Hurray for Kevin! */
218 #define GENMASK_BYIP     8
219 #define GENMASK_SRVXMASK 16
220 #define GENMASK_NO_HIDING 128
221 char *generate_hostmask(struct userNode *user, int options);
222
223 #endif /* !defined(PROTO_H) */