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