1 /* hash.h - IRC network state database
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
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.
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.
26 #include "eventhooks.h"
30 #define MODE_CHANOP 0x00000001 /* +o USER */
31 #define MODE_VOICE 0x00000002 /* +v USER */
32 #define MODE_PRIVATE 0x00000004 /* +p */
33 #define MODE_SECRET 0x00000008 /* +s */
34 #define MODE_MODERATED 0x00000010 /* +m */
35 #define MODE_TOPICLIMIT 0x00000020 /* +t */
36 #define MODE_INVITEONLY 0x00000040 /* +i */
37 #define MODE_NOPRIVMSGS 0x00000080 /* +n */
38 #define MODE_KEY 0x00000100 /* +k KEY */
39 #define MODE_BAN 0x00000200 /* +b BAN */
40 #define MODE_LIMIT 0x00000400 /* +l LIMIT */
41 #define MODE_DELAYJOINS 0x00000800 /* +D */
42 #define MODE_REGONLY 0x00001000 /* ircu +r */
43 #define MODE_NOCOLORS 0x00002000 /* +c */
44 #define MODE_NOCTCPS 0x00004000 /* +C */
45 #define MODE_REGISTERED 0x00008000 /* Bahamut +r */
46 #define MODE_STRIPCOLOR 0x00010000 /* +S Strip mirc color codes */
47 #define MODE_MODUNREG 0x00020000 /* +M mod unregister */
48 #define MODE_NONOTICE 0x00040000 /* +N no notices */
49 #define MODE_OPERSONLY 0x00080000 /* +O Opers only */
50 #define MODE_NOQUITMSGS 0x00100000 /* +Q suppress messages from quit notices */
51 #define MODE_NOAMSG 0x00200000 /* +T no multi-target messages */
52 #define MODE_SSLONLY 0x00400000 /* +Z ssl only */
53 #define MODE_HALFOP 0x00800000 /* +h USER */
54 #define MODE_EXEMPT 0x01000000 /* +e exempt */
55 #define MODE_HIDEMODE 0x02000000 /* +L hide modes */
56 #define MODE_APASS 0x04000000 /* +A adminpass */
57 #define MODE_UPASS 0x08000000 /* +U userpass */
58 #define MODE_ADMINSONLY 0x10000000 /* +a Admins only */
59 #define MODE_REMOVE 0x80000000
61 #define FLAGS_OPER 0x00000001 /* Operator +o */
62 #define FLAGS_LOCOP 0x00000002 /* Local operator +O */
63 #define FLAGS_INVISIBLE 0x00000004 /* invisible +i */
64 #define FLAGS_WALLOP 0x00000008 /* receives wallops +w */
65 #define FLAGS_DUMMY 0x00000010 /* user is not announced to other servers */
66 #define FLAGS_DEAF 0x00000020 /* deaf +d */
67 #define FLAGS_SERVICE 0x00000040 /* cannot be kicked, killed or deoped +k */
68 #define FLAGS_GLOBAL 0x00000080 /* receives global messages +g */
69 #define FLAGS_SETHOST 0x00000100 /* sethost +h */
70 #define FLAGS_PERSISTENT 0x00000200 /* for reserved nicks, this isn't just one-shot */
71 #define FLAGS_GAGGED 0x00000400 /* for gagged users */
72 #define FLAGS_AWAY 0x00000800 /* for away users */
73 #define FLAGS_STAMPED 0x00001000 /* for users who have been stamped */
74 #define FLAGS_HIDDEN_HOST 0x00002000 /* user's host is masked by their account +x */
75 #define FLAGS_REGNICK 0x00004000 /* user owns their current nick */
76 #define FLAGS_REGISTERING 0x00008000 /* user has issued account register command, is waiting for email cookie */
77 #define FLAGS_BOT 0x00010000 /* Bot +B */
78 #define FLAGS_HIDECHANS 0x00020000 /* Hidden channels +n */
79 #define FLAGS_HIDEIDLE 0x00040000 /* Hidden idle time +I */
80 #define FLAGS_XTRAOP 0x00080000 /* user is XtraOP +X */
81 #define FLAGS_CLOAKHOST 0x00100000 /* user has cloaked host +C */
82 #define FLAGS_CLOAKIP 0x00200000 /* user has cloaked ip +c */
83 #define FLAGS_ADMIN 0x00400000 /* Admin +a */
84 #define FLAGS_SSL 0x00800000 /* user is using a secure connection +z */
85 #define FLAGS_PRIVDEAF 0x01000000 /* user is deaf to private messages +D */
86 #define FLAGS_ACCOUNTONLY 0x02000000 /* user only receives PMs from authed users +R */
87 #define FLAGS_WHOIS 0x04000000 /* user receives notices when /whois'ed +W */
88 #define FLAGS_HIDEOPER 0x08000000 /* user is a hidden IRCop +H */
89 #define FLAGS_NOLINK 0x10000000 /* user has opted out of channel redirection +L */
90 #define FLAGS_COMMONCHANSONLY 0x20000000 /* user only receives PMs from users on same cahnnels +q */
92 #define IsOper(x) ((x)->modes & FLAGS_OPER)
93 #define IsService(x) ((x)->modes & FLAGS_SERVICE)
94 #define IsDeaf(x) ((x)->modes & FLAGS_DEAF)
95 #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE)
96 #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL)
97 #define IsWallOp(x) ((x)->modes & FLAGS_WALLOP)
98 #define IsBotM(x) ((x)->modes & FLAGS_BOT)
99 #define IsHideChans(x) ((x)->modes & FLAGS_HIDECHANS)
100 #define IsHideIdle(x) ((x)->modes & FLAGS_HIDEIDLE)
101 #define IsXtraOp(x) ((x)->modes & FLAGS_XTRAOP)
102 #define IsSetHost(x) ((x)->modes & FLAGS_SETHOST)
103 #define IsGagged(x) ((x)->modes & FLAGS_GAGGED)
104 #define IsPersistent(x) ((x)->modes & FLAGS_PERSISTENT)
105 #define IsAway(x) ((x)->modes & FLAGS_AWAY)
106 #define IsStamped(x) ((x)->modes & FLAGS_STAMPED)
107 #define IsHiddenHost(x) ((x)->modes & FLAGS_HIDDEN_HOST)
108 #define IsReggedNick(x) ((x)->modes & FLAGS_REGNICK)
109 #define IsRegistering(x) ((x)->modes & FLAGS_REGISTERING)
110 #define IsDummy(x) ((x)->modes & FLAGS_DUMMY)
111 #define IsFakeHost(x) ((x)->fakehost[0] != '\0')
112 #define IsLocal(x) ((x)->uplink == self)
113 #define IsAdmin(x) ((x)->modes & FLAGS_ADMIN)
114 #define IsSSL(x) ((x)->modes & FLAGS_SSL)
115 #define IsPrivDeaf(x) ((x)->modes & FLAGS_PRIVDEAF)
116 #define IsAccountOnly(x) ((x)->modes & FLAGS_ACCOUNTONLY)
117 #define IsWhoisNotice(x) ((x)->modes & FLAGS_WHOIS)
118 #define IsHideOper(x) ((x)->modes & FLAGS_HIDEOPER)
119 #define IsNoRedirect(x) ((x)->modes & FLAGS_NOLINK)
120 #define IsCommonChansOnly(x) ((x)->modes & FLAGS_COMMONCHANSONLY)
126 #define ACCOUNTLEN 15
129 #define CHANNELLEN 200
131 #define MAXOPLEVEL 999
133 #define MAXMODEPARAMS 6
135 #define MAXEXEMPTS 45
137 /* IDLEN is 6 because it takes 5.33 Base64 digits to store 32 bytes. */
140 /** Operator privileges. */
142 PRIV_CHAN_LIMIT
, /**< no channel limit on oper */
143 PRIV_MODE_LCHAN
, /**< oper can mode local chans */
144 PRIV_WALK_LCHAN
, /**< oper can walk through local modes */
145 PRIV_DEOP_LCHAN
, /**< no deop oper on local chans */
146 PRIV_SHOW_INVIS
, /**< show local invisible users */
147 PRIV_SHOW_ALL_INVIS
, /**< show all invisible users */
148 PRIV_UNLIMIT_QUERY
, /**< unlimit who queries */
149 PRIV_KILL
, /**< oper can KILL */
150 PRIV_LOCAL_KILL
, /**< oper can local KILL */
151 PRIV_REHASH
, /**< oper can REHASH */
152 PRIV_REMOTEREHASH
, /**< oper can remote REHASH */
153 PRIV_RESTART
, /**< oper can RESTART */
154 PRIV_DIE
, /**< oper can DIE */
155 PRIV_ZLINE
, /**< oper can ZLINE */
156 PRIV_LOCAL_ZLINE
, /**< oper can local ZLINE */
157 PRIV_GLINE
, /**< oper can GLINE */
158 PRIV_LOCAL_GLINE
, /**< oper can local GLINE */
159 PRIV_SHUN
, /**< oper can SHUN */
160 PRIV_LOCAL_SHUN
, /**< oper can local SHUN */
161 PRIV_JUPE
, /**< oper can JUPE */
162 PRIV_LOCAL_JUPE
, /**< oper can local JUPE */
163 PRIV_OPMODE
, /**< oper can OP/CLEARMODE */
164 PRIV_LOCAL_OPMODE
, /**< oper can local OP/CLEARMODE */
165 PRIV_SET
, /**< oper can SET */
166 PRIV_WHOX
, /**< oper can use /who x */
167 PRIV_BADCHAN
, /**< oper can BADCHAN */
168 PRIV_LOCAL_BADCHAN
, /**< oper can local BADCHAN */
169 PRIV_SEE_CHAN
, /**< oper can see in secret chans */
170 PRIV_PROPAGATE
, /**< propagate oper status */
171 PRIV_DISPLAY
, /**< "Is an oper" displayed */
172 PRIV_DISPLAY_MODE
, /**< oper can set +H hide oper */
173 PRIV_SEE_OPERS
, /**< display hidden opers */
174 PRIV_WIDE_GLINE
, /**< oper can set wider G-lines */
175 PRIV_WIDE_ZLINE
, /**< oper can set wider Z-Lines */
176 PRIV_WIDE_SHUN
, /**< oper can set wider G-lines */
177 PRIV_LIST_CHAN
, /**< oper can list secret channels */
178 PRIV_FORCE_OPMODE
, /**< can hack modes on quarantined channels */
179 PRIV_FORCE_LOCAL_OPMODE
, /**< can hack modes on quarantined local channels */
180 PRIV_CHECK
, /**< oper can use CHECK */
181 PRIV_SEE_SECRET_CHAN
, /**< oper can see +s channels in whois */
182 PRIV_WHOIS_NOTICE
, /**< oper can set/unset user mode +W */
183 PRIV_HIDE_IDLE
, /**< oper can set/unset user mode +I */
184 PRIV_XTRAOP
, /**< oper can set/unset user mode +X */
185 PRIV_HIDE_CHANNELS
, /**< oper can set/unset user mode +n */
186 PRIV_FREEFORM
, /**< oper can set any host on themseves using set host
187 as long as its a valid host */
188 PRIV_REMOVE
, /**< oper can force remove deactivated glines,
190 PRIV_SPAMFILTER
, /**< oper can set spamfilters via SPAMFILTER */
191 PRIV_ADMIN
, /**< oper is an IRC Admin */
192 PRIV_APASS_OPMODE
, /**< oper can use OPMODE to set/unset channel modes +A and +U */
193 PRIV_HIDE_OPER
, /**< oper can set/unset user mode +H */
194 PRIV_REMOTE
, /**< oper can use his/her operator block from a remote server */
195 PRIV_SERVICE
, /**< oper can set/unset user mode +k */
196 PRIV_LAST_PRIV
/**< number of privileges */
199 /** Number of bits */
200 #define _PRIV_NBITS (8 * sizeof(unsigned long))
201 /** Element number for priv \a priv. */
202 #define _PRIV_IDX(priv) ((priv) / _PRIV_NBITS)
203 /** Element bit for priv \a priv. */
204 #define _PRIV_BIT(priv) (1UL << ((priv) % _PRIV_NBITS))
206 /** Operator privileges. */
208 unsigned long priv_mask
[(PRIV_LAST_PRIV
+ _PRIV_NBITS
- 1) / _PRIV_NBITS
];
211 DECLARE_LIST(userList
, struct userNode
*);
212 DECLARE_LIST(modeList
, struct modeNode
*);
213 DECLARE_LIST(banList
, struct banNode
*);
214 DECLARE_LIST(exemptList
, struct exemptNode
*);
215 DECLARE_LIST(channelList
, struct chanNode
*);
216 DECLARE_LIST(serverList
, struct server
*);
219 char *nick
; /* Unique name of the client, nick or host */
220 char ident
[USERLEN
+ 1]; /* Per-host identification for user */
221 char info
[REALLEN
+ 1]; /* Free form additional client information */
222 char hostname
[HOSTLEN
+ 1]; /* DNS name or IP address */
223 char fakehost
[HOSTLEN
+ 1]; /* Assigned fake host */
224 char crypthost
[HOSTLEN
+ 30]; /* Crypted hostname */
225 char cryptip
[SOCKIPLEN
+ 30]; /* Crypted IP */
226 #ifdef WITH_PROTOCOL_P10
227 char numeric
[COMBO_NUMERIC_LEN
+1];
228 unsigned int num_local
: 18;
230 unsigned int loc
; /* Is user connecting via LOC? */
231 unsigned int no_notice
; /* Does the users client not see notices? */
232 unsigned int dead
: 1; /* Is user waiting to be recycled? */
233 irc_in_addr_t ip
; /* User's IP address */
234 long modes
; /* user flags +isw etc... */
236 // sethost - reed/apples
237 char sethost
[USERLEN
+ HOSTLEN
+ 2]; /* 1 for '\0' and 1 for @ = 2 */
242 /* GeoIP City Data */
252 char *mark
; /* only filled if they are marked */
253 char *version_reply
; /* only filled in if a version query was triggered */
254 char *sslfp
; /* only filled in if a mark SSLCLIFP is received */
256 struct string_list
*marks
; /* list of user's marks */
258 time_t timestamp
; /* Time of last nick change */
260 struct server
*uplink
; /* Server that user is connected to */
261 struct modeList channels
; /* Vector of channels user is in */
265 struct handle_info
*handle_info
;
266 struct userNode
*next_authed
;
267 struct policer auth_policer
;
270 #define privs(cli) ((cli)->privs)
271 #define PrivSet(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] |= \
273 #define PrivClr(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] &= \
275 #define PrivHas(pset, priv) ((pset)->priv_mask[_PRIV_IDX(priv)] & \
281 #define GrantPriv(cli, priv) (PrivSet(&(privs(cli)), priv))
282 #define RevokePriv(cli, priv) (PrivClr(&(privs(cli)), priv))
283 #define HasPriv(cli, priv) (PrivHas(&(privs(cli)), priv))
287 unsigned int limit
, locks
;
288 char key
[KEYLEN
+ 1];
289 char upass
[KEYLEN
+ 1];
290 char apass
[KEYLEN
+ 1];
291 time_t timestamp
; /* creation time */
293 char topic
[TOPICLEN
+ 1];
294 char topic_nick
[NICKLEN
+ 1];
297 struct modeList members
;
298 struct banList banlist
;
299 struct exemptList exemptlist
;
300 struct policer join_policer
;
301 unsigned int join_flooded
: 1;
302 unsigned int bad_channel
: 1;
304 struct chanData
*channel_info
;
305 struct channel_help
*channel_help
;
310 char ban
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
311 char who
[NICKLEN
+ 1]; /* who set ban */
312 time_t set
; /* time ban was set */
316 char exempt
[NICKLEN
+ USERLEN
+ HOSTLEN
+ 3]; /* 1 for '\0', 1 for ! and 1 for @ = 3 */
317 char who
[NICKLEN
+ 1]; /* who set exempt */
318 time_t set
; /* time exempt was set */
322 struct chanNode
*channel
;
323 struct userNode
*user
;
329 #define SERVERNAMEMAX 64
330 #define SERVERDESCRIPTMAX 128
333 char name
[SERVERNAMEMAX
+1];
336 char description
[SERVERDESCRIPTMAX
+1];
337 #ifdef WITH_PROTOCOL_P10
338 char numeric
[COMBO_NUMERIC_LEN
+1];
339 unsigned int num_mask
;
341 unsigned int hops
, clients
, max_clients
;
342 unsigned int burst
: 1, self_burst
: 1;
343 struct server
*uplink
;
344 #ifdef WITH_PROTOCOL_P10
345 struct userNode
**users
; /* flat indexed by numeric */
347 dict_t users
; /* indexed by nick */
349 struct serverList children
;
352 struct waitingConnection
{
361 struct routingPlanServer
{
363 char *secondaryuplink
;
371 char* server
; /* Name of the server */
372 unsigned int port
; /* connection port */
373 char *uplink
; /* Server its linked to (towards us) */
374 char *secondaryuplink
;
375 int outsideness
; /* 0 means leaf, 1 second layer, etc. my uplink is highest */
376 struct routeList
*next
;
381 int count
; /* how many servers we have */
382 int maxdepth
; /* biggest outsideness value */
383 int centered
; /* set to TRUE when changerouteUplinks is run */
384 struct routeList
*servers
;
387 /* generic hook function args */
393 extern struct server
*self
;
394 extern dict_t channels
;
395 extern dict_t clients
;
396 extern dict_t servers
;
397 extern unsigned int max_clients
, invis_clients
;
398 extern time_t max_clients_time
;
399 extern struct userList curr_opers
, curr_helpers
;
401 extern unsigned int count_opers
;
403 struct server
* GetServerH(const char *name
); /* using full name */
404 struct userNode
* GetUserH(const char *nick
); /* using nick */
405 struct chanNode
* GetChannel(const char *name
);
406 struct modeNode
* GetUserMode(struct chanNode
* channel
, struct userNode
* user
);
407 int userList_contains(struct userList
*list
, struct userNode
*user
);
408 unsigned int IsUserP(struct userNode
*user
);
410 typedef int (*server_link_func_t
) (struct server
*server
, void *extra
);
411 void reg_server_link_func(server_link_func_t handler
, void *extra
);
412 void call_server_link_funcs(struct server
*server
);
414 typedef void (*sasl_input_func_t
) (struct server
* source
,const char *identifier
, const char *subcmd
, const char *data
, const char *ext
, void *extra
);
415 void reg_sasl_input_func(sasl_input_func_t handler
, void *extra
);
416 void call_sasl_input_func(struct server
* source
,const char *identifier
, const char *subcmd
, const char *data
, const char *ext
);
417 void unreg_sasl_input_func(sasl_input_func_t handler
, void *extra
);
419 typedef int (*new_user_func_t
) (struct userNode
*user
, void *extra
);
420 void reg_new_user_func(new_user_func_t handler
, void *extra
);
421 void reg_new_user_func_pos(new_user_func_t handler
, void *extra
, int pos
);
422 void call_new_user_funcs(struct userNode
*user
);
423 typedef void (*del_user_func_t
) (struct userNode
*user
, struct userNode
*killer
, const char *why
, void *extra
);
424 void reg_del_user_func(del_user_func_t handler
, void *extra
);
425 void call_del_user_funcs(struct userNode
*user
, struct userNode
*killer
, const char *why
);
426 void unreg_del_user_func(del_user_func_t handler
, void *extra
);
427 void ReintroduceUser(struct userNode
* user
);
428 typedef void (*nick_change_func_t
)(struct userNode
*user
, const char *old_nick
, void *extra
);
429 void reg_nick_change_func(nick_change_func_t handler
, void *extra
);
430 void NickChange(struct userNode
* user
, const char *new_nick
, int no_announce
);
431 void SVSNickChange(struct userNode
* user
, const char *new_nick
);
433 typedef void (*account_func_t
) (struct userNode
*user
, const char *stamp
);
434 void reg_account_func(account_func_t handler
);
435 void call_account_func(struct userNode
*user
, const char *stamp
);
436 void StampUser(struct userNode
*user
, const char *stamp
, time_t timestamp
);
437 void assign_fakehost(struct userNode
*user
, const char *host
, int announce
);
438 void set_geoip_info(struct userNode
*user
);
440 typedef void (*new_channel_func_t
) (struct chanNode
*chan
, void *extra
);
441 void reg_new_channel_func(new_channel_func_t handler
, void *extra
);
442 typedef int (*join_func_t
) (struct modeNode
*mNode
, void *extra
);
443 void reg_join_func_pos(join_func_t handler
, void *extra
, int pos
);
444 void reg_join_func(join_func_t handler
, void *extra
);
445 typedef void (*del_channel_func_t
) (struct chanNode
*chan
, void *extra
);
446 void reg_del_channel_func(del_channel_func_t handler
, void *extra
);
448 struct chanNode
* AddChannel(const char *name
, time_t time_
, const char *modes
, char *banlist
, char *exemptlist
);
449 void LockChannel(struct chanNode
*channel
);
450 void UnlockChannel(struct chanNode
*channel
);
452 struct modeNode
* AddChannelUser(struct userNode
* user
, struct chanNode
* channel
);
454 typedef void (*part_func_t
) (struct modeNode
*mn
, const char *reason
, void *extra
);
455 void reg_part_func(part_func_t handler
, void *extra
);
456 void unreg_part_func(part_func_t handler
, void *extra
);
457 void DelChannelUser(struct userNode
* user
, struct chanNode
* channel
, const char *reason
, int deleting
);
458 void KickChannelUser(struct userNode
* target
, struct chanNode
* channel
, struct userNode
*kicker
, const char *why
);
460 typedef void (*kick_func_t
) (struct userNode
*kicker
, struct userNode
*user
, struct chanNode
*chan
, void *extra
);
461 void reg_kick_func(kick_func_t handler
, void *extra
);
462 void ChannelUserKicked(struct userNode
* kicker
, struct userNode
* victim
, struct chanNode
* channel
);
464 int ChannelBanExists(struct chanNode
*channel
, const char *ban
);
465 int ChannelExemptExists(struct chanNode
*channel
, const char *exempt
);
467 typedef int (*topic_func_t
)(struct userNode
*who
, struct chanNode
*chan
, const char *old_topic
, void *extra
);
468 void reg_topic_func(topic_func_t handler
, void *extra
);
469 void SetChannelTopic(struct chanNode
*channel
, struct userNode
*service
, struct userNode
*user
, const char *topic
, int announce
);
470 struct userNode
*IsInChannel(struct chanNode
*channel
, struct userNode
*user
);
472 void init_structs(void);