1 /* proto.h - IRC protocol output
2 * Copyright 2000-2006 srvx Development Team
4 * This file is part of srvx.
6 * srvx 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 2 of the License, or
9 * (at your option) any later version.
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.
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.
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 srvx2,
27 * which has much nicer interfaces that hide most of the ugly
28 * differences between protocol dialects. */
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 */
40 /* connection manager state */
50 #define UPLINK_UNAVAILABLE 0x001
59 struct sockaddr *bind_addr;
70 struct uplinkNode *prev;
71 struct uplinkNode *next;
76 struct uplinkNode *uplinks;
77 struct uplinkNode *uplink;
83 #ifdef WITH_PROTOCOL_P10
84 struct server* GetServerN(const char *numeric);
85 struct userNode* GetUserN(const char *numeric);
88 /* Basic protocol parsing support. */
89 void init_parse(void);
90 int parse_line(char *line, int recursive);
92 /* Callback notifications for protocol support. */
93 typedef void (*chanmsg_func_t) (struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice);
94 void reg_chanmsg_func(unsigned char prefix, struct userNode *service, chanmsg_func_t handler);
95 void reg_allchanmsg_func(struct userNode *service, chanmsg_func_t handler);
96 struct userNode *get_chanmsg_bot(unsigned char prefix);
98 typedef void (*privmsg_func_t) (struct userNode *user, struct userNode *target, const 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 void unreg_privmsg_func(struct userNode *user);
102 void unreg_notice_func(struct userNode *user);
104 typedef void (*oper_func_t) (struct userNode *user);
105 void reg_oper_func(oper_func_t handler);
107 typedef void (*xquery_func_t) (struct server *source, const char routing[], const char query[]);
108 void reg_xquery_func(xquery_func_t handler);
110 /* replay silliness */
111 void replay_read_line(void);
112 void replay_event_loop(void);
114 /* connection maintenance */
115 void irc_server(struct server *srv);
116 void irc_user(struct userNode *user);
117 void irc_nick(struct userNode *user, const char *old_nick);
118 void irc_introduce(const char *passwd);
119 void irc_ping(const char *something);
120 void irc_pong(const char *who, const char *data);
121 void irc_quit(struct userNode *user, const char *message);
122 void irc_squit(struct server *srv, const char *message, const char *service_message);
125 void irc_privmsg(struct userNode *from, const char *to, const char *message);
126 void irc_notice(struct userNode *from, const char *to, const char *message);
127 void irc_notice_user(struct userNode *from, struct userNode *to, const char *message);
128 void irc_wallchops(struct userNode *from, const char *to, const char *message);
130 /* channel maintenance */
131 void irc_join(struct userNode *who, struct chanNode *what);
132 void irc_invite(struct userNode *from, struct userNode *who, struct chanNode *to);
133 void irc_mode(struct userNode *who, struct chanNode *target, const char *modes);
134 void irc_kick(struct userNode *who, struct userNode *target, struct chanNode *from, const char *msg);
135 void irc_part(struct userNode *who, struct chanNode *what, const char *reason);
136 void irc_topic(struct userNode *who, struct chanNode *what, const char *topic);
137 void irc_fetchtopic(struct userNode *from, const char *to);
139 /* network maintenance */
140 void irc_gline(struct server *srv, struct gline *gline);
141 void irc_settime(const char *srv_name_mask, unsigned long new_time);
142 void irc_ungline(const char *mask);
143 void irc_error(const char *to, const char *message);
144 void irc_kill(struct userNode *from, struct userNode *target, const char *message);
145 void irc_raw(const char *what);
146 void irc_stats(struct userNode *from, struct server *target, char type);
147 void irc_svsnick(struct userNode *from, struct userNode *target, const char *newnick);
148 void irc_xresponse(struct server *target, const char *routing, const char *response);
150 /* account maintenance */
151 void irc_account(struct userNode *user, const char *stamp, unsigned long timestamp, unsigned long serial);
152 void irc_regnick(struct userNode *user);
153 void irc_fakehost(struct userNode *user, const char *host, const char *ident, int force);
154 void irc_keepconn(struct userNode *target, unsigned int timeout);
156 /* svs maintenance */
157 void irc_svsmode(struct userNode *from, struct userNode *user, const char *modes);
158 void irc_svsjoin(struct userNode *from, struct userNode *user, struct chanNode *chan);
159 void irc_svsjoinchan(struct userNode *from, struct userNode *user, const char *chan);
160 void irc_relay(char *message);
161 void irc_simul(struct userNode *target, char *command);
163 /* numeric messages */
164 void irc_numeric(struct userNode *user, unsigned int num, const char *format, ...);
165 /* RFC1459-compliant numeric responses */
166 #define RPL_ENDOFSTATS 219
167 #define RPL_STATSUPTIME 242
168 #define RPL_MAXCONNECTIONS 250
170 #define RPL_WHOISUSER 311
171 #define RPL_WHOISSERVER 312
172 #define RPL_WHOISOPERATOR 313
173 #define RPL_WHOISIDLE 317
174 #define RPL_ENDOFWHOIS 318
175 #define RPL_WHOISCHANNELS 319
176 #define RPL_WHOISACCOUNT 330
177 #define RPL_WHOISACTUALLY 338
178 #define ERR_NOSUCHNICK 401
180 /* stuff originally from other headers that is really protocol-specific */
181 int IsChannelName(const char *name);
182 int is_valid_nick(const char *nick);
183 struct userNode *AddLocalUser(const char *nick, const char *ident, const char *hostname, const char *desc, const char *modes);
184 struct server* AddServer(struct server* uplink, const char *name, int hops, unsigned long boot, unsigned long link, const char *numeric, const char *description);
185 void DelServer(struct server* serv, int announce, const char *message);
186 void DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why);
187 /* Most protocols will want to make an AddUser helper function. */
190 extern const char irc_user_mode_chars[];
191 void mod_usermode(struct userNode *user, const char *modes);
192 unsigned int irc_user_modes(const struct userNode *user, char modes[], size_t length);
194 /* Channel mode manipulation */
196 #define NOFLOODLEN 15
197 #define CHANNELLEN 200
198 typedef unsigned long chan_mode_t;
199 /* Rules for struct mod_chanmode:
200 * For a membership mode change, args[n].mode can contain more than
201 * one mode bit (e.g. MODE_CHANOP|MODE_VOICE). Hostmask strings are
202 * "owned" by the caller and are not freed by mod_chanmode_free().
204 struct mod_chanmode {
205 chan_mode_t modes_set, modes_clear;
206 unsigned int new_limit, new_access, argc;
208 unsigned int alloc_argc;
210 char new_key[KEYLEN + 1];
211 char new_altchan[CHANNELLEN + 1];
212 char new_noflood[NOFLOODLEN + 1];
213 char new_upass[KEYLEN + 1];
214 char new_apass[KEYLEN + 1];
218 struct modeNode *member;
219 const char *hostmask;
223 #define MCP_ALLOW_OVB 0x0001 /* allow op, voice, ban manipulation */
224 #define MCP_FROM_SERVER 0x0002 /* parse as from a server */
225 #define MCP_KEY_FREE 0x0004 /* -k without a key argument */
226 #define MCP_REGISTERED 0x0008 /* chan is already registered; do not allow changes to MODE_REGISTERED */
227 #define MCP_UPASS_FREE 0x0010 /* -U without a key argument */
228 #define MCP_APASS_FREE 0x0020 /* -A without a key argument */
229 #define MCP_NO_APASS 0x0040 /* Do not allow +/-A or +/-U */
230 #define MCP_IGN_REGISTERED 0x0080 /* chan is already registered; ignore changes to MODE_REGISTERED */
231 #define MC_ANNOUNCE 0x0100 /* send a mod_chanmode() change out */
232 #define MC_NOTIFY 0x0200 /* make local callbacks to announce */
233 #define MCP_OPERMODE 0x0400
235 #define mod_chanmode_init(CHANMODE) do { memset((CHANMODE), 0, sizeof(*CHANMODE)); } while (0)
237 #define mod_chanmode_init(CHANMODE) do { memset((CHANMODE), 0, sizeof(*CHANMODE)); (CHANMODE)->alloc_argc = ArrayLength((CHANMODE)->args); } while (0)
240 struct mod_chanmode *mod_chanmode_alloc(unsigned int argc);
241 struct mod_chanmode *mod_chanmode_dup(struct mod_chanmode *orig, unsigned int extra);
242 struct mod_chanmode *mod_chanmode_parse(struct chanNode *channel, struct userNode *user, char **modes, unsigned int argc, unsigned int flags, short base_oplevel);
243 void mod_chanmode_apply(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
244 void mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change);
245 char *mod_chanmode_format(struct mod_chanmode *desc, char *buffer);
246 void mod_chanmode_free(struct mod_chanmode *change);
247 int mod_chanmode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags);
248 typedef void (*mode_change_func_t) (struct chanNode *channel, struct userNode *user, const struct mod_chanmode *change);
249 void reg_mode_change_func(mode_change_func_t handler);
250 int irc_make_chanmode(struct chanNode *chan, char *out);
252 /* The "default" for generate_hostmask is to have all of these options off. */
253 #define GENMASK_STRICT_HOST 1
254 #define GENMASK_STRICT_IDENT 32
255 #define GENMASK_ANY_IDENT 64
256 #define GENMASK_STRICT (GENMASK_STRICT_IDENT|GENMASK_STRICT_HOST)
257 #define GENMASK_USENICK 2
258 #define GENMASK_OMITNICK 4 /* Hurray for Kevin! */
259 #define GENMASK_BYIP 8
260 #define GENMASK_SRVXMASK 16
261 #define GENMASK_NO_HIDING 128
262 char *generate_hostmask(struct userNode *user, int options);
264 #endif /* !defined(PROTO_H) */