2 * IRC - Internet Relay Chat, include/client.h
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * This program 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, or (at your option)
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 this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * @brief Structures and functions for handling local clients.
22 * @version $Id: client.h 1907 2009-02-09 04:11:04Z entrope $
24 #ifndef INCLUDED_client_h
25 #define INCLUDED_client_h
26 #ifndef INCLUDED_ircd_defs_h
27 #include "ircd_defs.h"
29 #ifndef INCLUDED_dbuf_h
32 #ifndef INCLUDED_msgq_h
35 #ifndef INCLUDED_ircd_events_h
36 #include "ircd_events.h"
38 #ifndef INCLUDED_ircd_handler_h
39 #include "ircd_handler.h"
41 #ifndef INCLUDED_res_h
44 #ifndef INCLUDED_sys_types_h
45 #include <sys/types.h> /* time_t, size_t */
46 #define INCLUDED_sys_types_h
63 * Only put structures here that are being used in a very large number of
64 * source files. Other structures go in the header file of there corresponding
65 * source file, or in the source file itself (when only used in that file).
68 /** Single element in a flag bitset array. */
69 typedef unsigned long flagpage_t;
71 /** Number of bits in a flagpage_t. */
72 #define FLAGSET_NBITS (8 * sizeof(flagpage_t))
73 /** Element number for flag \a flag. */
74 #define FLAGSET_INDEX(flag) ((flag) / FLAGSET_NBITS)
75 /** Element bit for flag \a flag. */
76 #define FLAGSET_MASK(flag) (1ul<<((flag) % FLAGSET_NBITS))
78 /** Declare a flagset structure of a particular size. */
79 #define DECLARE_FLAGSET(name,max) \
82 unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \
85 /** Test whether a flag is set in a flagset. */
86 #define FlagHas(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag))
87 /** Set a flag in a flagset. */
88 #define FlagSet(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag))
89 /** Clear a flag in a flagset. */
90 #define FlagClr(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag))
92 /** String containing valid user modes, in no particular order. */
93 #define infousermodes "dioswkgxnIXSHc"
95 /** Operator privileges. */
98 PRIV_CHAN_LIMIT, /**< no channel limit on oper */
99 PRIV_MODE_LCHAN, /**< oper can mode local chans */
100 PRIV_WALK_LCHAN, /**< oper can walk through local modes */
101 PRIV_DEOP_LCHAN, /**< no deop oper on local chans */
102 PRIV_SHOW_INVIS, /**< show local invisible users */
103 PRIV_SHOW_ALL_INVIS, /**< show all invisible users */
104 PRIV_UNLIMIT_QUERY, /**< unlimit who queries */
105 PRIV_KILL, /**< oper can KILL */
106 PRIV_LOCAL_KILL, /**< oper can local KILL */
107 PRIV_REHASH, /**< oper can REHASH */
108 PRIV_RESTART, /**< oper can RESTART */
109 PRIV_DIE, /**< oper can DIE */
110 PRIV_GLINE, /**< oper can GLINE */
111 PRIV_LOCAL_GLINE, /**< oper can local GLINE */
112 PRIV_JUPE, /**< oper can JUPE */
113 PRIV_LOCAL_JUPE, /**< oper can local JUPE */
114 PRIV_OPMODE, /**< oper can OP/CLEARMODE */
115 PRIV_LOCAL_OPMODE, /**< oper can local OP/CLEARMODE */
116 PRIV_SET, /**< oper can SET */
117 PRIV_WHOX, /**< oper can use /who x */
118 PRIV_BADCHAN, /**< oper can BADCHAN */
119 PRIV_LOCAL_BADCHAN, /**< oper can local BADCHAN */
120 PRIV_SEE_CHAN, /**< oper can see in secret chans */
121 PRIV_PROPAGATE, /**< propagate oper status */
122 PRIV_DISPLAY, /**< "Is an oper" displayed */
123 PRIV_SEE_OPERS, /**< display hidden opers */
124 PRIV_WIDE_GLINE, /**< oper can set wider G-lines */
125 PRIV_LIST_CHAN, /**< oper can list secret channels */
126 PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */
127 PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */
128 PRIV_APASS_OPMODE, /**< can hack modes +A/-A/+U/-U */
129 PRIV_UMODE_NOCHAN, /**< can set umode +n (hide channels) */
130 PRIV_UMODE_NOIDLE, /**< can set umode +I (hide idle time) */
131 PRIV_UMODE_CHSERV, /**< can set umode +k (channel service) */
132 PRIV_UMODE_XTRAOP, /**< can set umode +X (eXtra oper; override +k) */
133 PRIV_UMODE_NETSERV, /**< can set umode +S (network service) */
134 PRIV_SEE_IDLETIME, /**< can see idle time of +I users */
135 PRIV_HIDE_IDLETIME, /**< hide idle time in 2nd layer */
136 PRIV_HALFFLOOD, /**< user has less throttling */
137 PRIV_FLOOD, /**< no more excess floods */
138 PRIV_UNLIMITED_TARGET, /**< unlimited target changes */
139 PRIV_UMODE_OVERRIDECC, /**< can set umode +c (override cmodes +cC) */
140 PRIV_NOAMSG_OVERRIDE, /**< can override the +M channelmode */
141 PRIV_LAST_PRIV /**< number of privileges */
144 /** Client flags and modes.
145 * Note that flags at least FLAG_LOCAL_UMODES but less than
146 * FLAG_GLOBAL_UMODES are treated as local modes, and flags at least
147 * FLAG_GLOBAL_UMODES (but less than FLAG_LAST_FLAG) are treated as
152 FLAG_PINGSENT, /**< Unreplied ping sent */
153 FLAG_DEADSOCKET, /**< Local socket is dead--Exiting soon */
154 FLAG_KILLED, /**< Prevents "QUIT" from being sent for this */
155 FLAG_BLOCKED, /**< socket is in a blocked condition */
156 FLAG_CLOSING, /**< set when closing to suppress errors */
157 FLAG_UPING, /**< has active UDP ping request */
158 FLAG_HUB, /**< server is a hub */
159 FLAG_IPV6, /**< server understands P10 IPv6 addrs */
160 FLAG_SERVICE, /**< server is a service */
161 FLAG_MASTER, /**< server is a master */
162 FLAG_GOTID, /**< successful ident lookup achieved */
163 FLAG_DOID, /**< I-lines say must use ident return */
164 FLAG_NONL, /**< No \n in buffer */
165 FLAG_TS8, /**< Why do you want to know? */
166 FLAG_MAP, /**< Show server on the map */
167 FLAG_JUNCTION, /**< Junction causing the net.burst. */
168 FLAG_BURST, /**< Server is receiving a net.burst */
169 FLAG_BURST_ACK, /**< Server is waiting for eob ack */
170 FLAG_IPCHECK, /**< Added or updated IPregistry data */
171 FLAG_LOCOP, /**< Local operator -- SRB */
172 FLAG_SERVNOTICE, /**< server notices such as kill */
173 FLAG_OPER, /**< Operator */
174 FLAG_INVISIBLE, /**< makes user invisible */
175 FLAG_WALLOP, /**< send wallops to them */
176 FLAG_DEAF, /**< Makes user deaf */
177 FLAG_CHSERV, /**< Disallow KICK or MODE -o on the user;
178 don't display channels in /whois */
179 FLAG_DEBUG, /**< send global debug/anti-hack info */
180 FLAG_ACCOUNT, /**< account name has been set */
181 FLAG_HIDDENHOST, /**< user's host is hidden */
182 FLAG_NOTCONN, /**< nobody is connected to this client */
183 FLAG_FAKEHOST, /**< user has a fakehost */
184 FLAG_FAKEIDENT, /**< user has a fakeident */
185 FLAG_NOCHAN, /**< hide user's channels for non-opers */
186 FLAG_NOIDLE, /**< hide user's idle time for non-opers */
187 FLAG_XTRAOP, /**< allow overriding +k */
188 FLAG_NETSERV, /**< mark as service; no special rights */
189 FLAG_HIDDENOPER, /**< mark as hidden oper */
190 FLAG_OVERRIDECC, /**< can override chanmodes +cCN */
191 FLAG_SSL, /**< SSL user */
192 FLAG_WEBIRC, /**< Is a WebIRC client with spoofed host/ip */
193 FLAG_SEE_IDLETIME, /**< Can see idletime of +I users. */
194 FLAG_SECURITY_SERV, /**< Securityflag, that can only be set by IAuth */
195 FLAG_LAST_FLAG, /**< number of flags */
196 FLAG_LOCAL_UMODES = FLAG_LOCOP, /**< First local mode flag */
197 FLAG_GLOBAL_UMODES = FLAG_OPER /**< First global mode flag */
200 /** Declare flagset type for operator privileges. */
201 DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV);
202 /** Declare flagset type for user flags. */
203 DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG);
205 #include "capab.h" /* client capabilities */
207 /** Represents a local connection.
208 * This contains a lot of stuff irrelevant to server connections, but
209 * those are so rare as to not be worth special-casing.
213 unsigned long con_magic; /**< magic number */
214 struct Connection* con_next; /**< Next connection with queued data */
215 struct Connection** con_prev_p; /**< What points to us */
216 struct Client* con_client; /**< Client associated with connection */
217 unsigned int con_count; /**< Amount of data in buffer */
218 int con_freeflag; /**< indicates if connection can be freed */
219 int con_error; /**< last socket level error for client */
220 int con_sentalong; /**< sentalong marker for connection */
221 unsigned int con_snomask; /**< mask for server messages */
222 time_t con_nextnick; /**< Next time a nick change is allowed */
223 time_t con_nexttarget;/**< Next time a target change is allowed */
224 time_t con_lasttime; /**< Last time data read from socket */
225 time_t con_since; /**< Last time we accepted a command */
226 struct MsgQ con_sendQ; /**< Outgoing message queue */
227 struct DBuf con_recvQ; /**< Incoming data yet to be parsed */
228 unsigned int con_sendM; /**< Stats: protocol messages sent */
229 unsigned int con_receiveM; /**< Stats: protocol messages received */
230 uint64_t con_sendB; /**< Bytes sent. */
231 uint64_t con_receiveB; /**< Bytes received. */
232 struct Listener* con_listener; /**< Listening socket which we accepted
234 struct SLink* con_confs; /**< Associated configuration records. */
235 HandlerType con_handler; /**< Message index into command table
237 struct ListingArgs* con_listing; /**< Current LIST status. */
238 unsigned int con_max_sendq; /**< cached max send queue for client */
239 unsigned int con_ping_freq; /**< cached ping freq */
240 unsigned short con_lastsq; /**< # 2k blocks when sendqueued
242 unsigned char con_targets[MAXTARGETS]; /**< Hash values of
244 char con_sock_ip[SOCKIPLEN + 1]; /**< Remote IP address as a string. */
245 char con_real_sock_ip[SOCKIPLEN + 1]; /**< Unspoofed ip address as a string. */
246 char con_sockhost[HOSTLEN + 1]; /**< This is the host name from
247 the socket and after which the
248 connection was accepted. */
249 char con_real_sockhost[HOSTLEN + 1]; /**< Unspoofed host name from the socket. */
250 char con_passwd[PASSWDLEN + 1]; /**< Password given by user. */
251 char con_buffer[BUFSIZE]; /**< Incoming message buffer; or
252 the error that caused this
253 clients socket to close. */
254 struct Socket con_socket; /**< socket descriptor for
256 struct Timer con_proc; /**< process latent messages from
258 struct Privs con_privs; /**< Oper privileges */
259 struct CapSet con_capab; /**< Client capabilities (from us) */
260 struct CapSet con_active; /**< Active capabilities (to us) */
261 struct AuthRequest* con_auth; /**< Auth request for client */
264 /** Magic constant to identify valid Connection structures. */
265 #define CONNECTION_MAGIC 0x12f955f3
267 /** Represents a client anywhere on the network. */
269 unsigned long cli_magic; /**< magic number */
270 struct Client* cli_next; /**< link in GlobalClientList */
271 struct Client* cli_prev; /**< link in GlobalClientList */
272 struct Client* cli_hnext; /**< link in hash table bucket or this */
273 struct Connection* cli_connect; /**< Connection structure associated with us */
274 struct User* cli_user; /**< Defined if this client is a user */
275 struct Server* cli_serv; /**< Defined if this client is a server */
276 struct Whowas* cli_whowas; /**< Pointer to ww struct to be freed on quit */
277 char cli_webirc[NICKLEN + 1]; /**< Contains the name of the WebIRC block */
278 char cli_yxx[4]; /**< Numeric Nick: YY if this is a
279 server, XXX if this is a user */
280 unsigned int maxchans;
281 char cli_connclass[NICKLEN + 1];
282 time_t cli_firsttime; /**< time client was created */
283 time_t cli_lastnick; /**< TimeStamp on nick */
284 int cli_marker; /**< /who processing marker */
285 struct Flags cli_flags; /**< client flags */
286 unsigned int cli_hopcount; /**< number of servers to this 0 = local */
287 struct irc_in_addr cli_ip; /**< Real IP of client */
288 struct irc_in_addr cli_real_ip; /**< Unspoofed ip of the client. */
289 short cli_status; /**< Client type */
290 char cli_name[HOSTLEN + 1]; /**< Unique name of the client, nick or host */
291 char cli_username[USERLEN + 1]; /**< Username determined by ident lookup */
292 char cli_info[REALLEN + 1]; /**< Free form additional client information */
295 /** Magic constant to identify valid Client structures. */
296 #define CLIENT_MAGIC 0x4ca08286
298 /** Verify that a client is valid. */
299 #define cli_verify(cli) ((cli)->cli_magic == CLIENT_MAGIC)
300 /** Get client's magic number. */
301 #define cli_magic(cli) ((cli)->cli_magic)
302 /** Get global next client. */
303 #define cli_next(cli) ((cli)->cli_next)
304 /** Get global previous client. */
305 #define cli_prev(cli) ((cli)->cli_prev)
306 /** Get next client in hash bucket chain. */
307 #define cli_hnext(cli) ((cli)->cli_hnext)
308 /** Get connection associated with client. */
309 #define cli_connect(cli) ((cli)->cli_connect)
310 /** Get local client that links us to \a cli. */
311 #define cli_from(cli) con_client(cli_connect(cli))
312 /** Get User structure for client, if client is a user. */
313 #define cli_user(cli) ((cli)->cli_user)
314 /** Get Server structure for client, if client is a server. */
315 #define cli_serv(cli) ((cli)->cli_serv)
316 /** Get Whowas link for client. */
317 #define cli_whowas(cli) ((cli)->cli_whowas)
318 /** Get WebIRC block name for client. */
319 #define cli_webirc(cli) ((cli)->cli_webirc)
320 /** Get ConnectionClass. */
321 #define cli_connclass(cli) ((cli)->cli_connclass)
322 /** Get client numnick. */
323 #define cli_yxx(cli) ((cli)->cli_yxx)
324 /** Get time we last read data from the client socket. */
325 #define cli_lasttime(cli) con_lasttime(cli_connect(cli))
326 /** Get time we last parsed something from the client. */
327 #define cli_since(cli) con_since(cli_connect(cli))
328 /** Get time client was created. */
329 #define cli_firsttime(cli) ((cli)->cli_firsttime)
330 /** Get time client last changed nickname. */
331 #define cli_lastnick(cli) ((cli)->cli_lastnick)
332 /** Get WHO marker for client. */
333 #define cli_marker(cli) ((cli)->cli_marker)
334 /** Get flags flagset for client. */
335 #define cli_flags(cli) ((cli)->cli_flags)
336 /** Get hop count to client. */
337 #define cli_hopcount(cli) ((cli)->cli_hopcount)
338 /** Get client IP address. */
339 #define cli_ip(cli) ((cli)->cli_ip)
340 /** Get unspoofed client IP address. */
341 #define cli_real_ip(cli) ((cli)->cli_real_ip)
342 /** Get status bitmask for client. */
343 #define cli_status(cli) ((cli)->cli_status)
344 /** Return non-zero if the client is local. */
345 #define cli_local(cli) (cli_from(cli) == cli)
346 /** Get oper privileges for client. */
347 #define cli_privs(cli) con_privs(cli_connect(cli))
348 /** Get client capabilities for client */
349 #define cli_capab(cli) con_capab(cli_connect(cli))
350 /** Get active client capabilities for client */
351 #define cli_active(cli) con_active(cli_connect(cli))
352 /** Get client name. */
353 #define cli_name(cli) ((cli)->cli_name)
354 /** Get client username (ident). */
355 #define cli_username(cli) ((cli)->cli_username)
356 /** Get client realname (information field). */
357 #define cli_info(cli) ((cli)->cli_info)
359 /** Get number of incoming bytes queued for client. */
360 #define cli_count(cli) con_count(cli_connect(cli))
361 /** Get file descriptor for sending in client's direction. */
362 #define cli_fd(cli) con_fd(cli_connect(cli))
363 /** Get free flags for the client's connection. */
364 #define cli_freeflag(cli) con_freeflag(cli_connect(cli))
365 /** Get last error code for the client's connection. */
366 #define cli_error(cli) con_error(cli_connect(cli))
367 /** Get server notice mask for the client. */
368 #define cli_snomask(cli) con_snomask(cli_connect(cli))
369 /** Get next time a nick change is allowed for the client. */
370 #define cli_nextnick(cli) con_nextnick(cli_connect(cli))
371 /** Get next time a target change is allowed for the client. */
372 #define cli_nexttarget(cli) con_nexttarget(cli_connect(cli))
373 /** Get SendQ for client. */
374 #define cli_sendQ(cli) con_sendQ(cli_connect(cli))
375 /** Get RecvQ for client. */
376 #define cli_recvQ(cli) con_recvQ(cli_connect(cli))
377 /** Get count of messages sent to client. */
378 #define cli_sendM(cli) con_sendM(cli_connect(cli))
379 /** Get number of messages received from client. */
380 #define cli_receiveM(cli) con_receiveM(cli_connect(cli))
381 /** Get number of bytes (modulo 1024) sent to client. */
382 #define cli_sendB(cli) con_sendB(cli_connect(cli))
383 /** Get number of bytes (modulo 1024) received from client. */
384 #define cli_receiveB(cli) con_receiveB(cli_connect(cli))
385 /** Get listener that accepted the client's connection. */
386 #define cli_listener(cli) con_listener(cli_connect(cli))
387 /** Get list of attached conf lines. */
388 #define cli_confs(cli) con_confs(cli_connect(cli))
389 /** Get handler type for client. */
390 #define cli_handler(cli) con_handler(cli_connect(cli))
391 /** Get LIST status for client. */
392 #define cli_listing(cli) con_listing(cli_connect(cli))
393 /** Get cached max SendQ for client. */
394 #define cli_max_sendq(cli) con_max_sendq(cli_connect(cli))
395 /** Get ping frequency for client. */
396 #define cli_ping_freq(cli) con_ping_freq(cli_connect(cli))
397 /** Get lastsq for client's connection. */
398 #define cli_lastsq(cli) con_lastsq(cli_connect(cli))
399 /** Get the array of current targets for the client. */
400 #define cli_targets(cli) con_targets(cli_connect(cli))
401 /** Get the string form of the client's IP address. */
402 #define cli_sock_ip(cli) con_sock_ip(cli_connect(cli))
403 /** Get the unspoofed string form of the client's IP address. */
404 #define cli_real_sock_ip(cli) con_real_sock_ip(cli_connect(cli))
405 /** Get the resolved hostname for the client. */
406 #define cli_sockhost(cli) con_sockhost(cli_connect(cli))
407 /** Get the unspoofed resolved hostname for the client. */
408 #define cli_real_sockhost(cli) con_real_sockhost(cli_connect(cli))
409 /** Get the client's password. */
410 #define cli_passwd(cli) con_passwd(cli_connect(cli))
411 /** Get the unprocessed input buffer for a client's connection. */
412 #define cli_buffer(cli) con_buffer(cli_connect(cli))
413 /** Get the Socket structure for sending to a client. */
414 #define cli_socket(cli) con_socket(cli_connect(cli))
415 /** Get Timer for processing waiting messages from the client. */
416 #define cli_proc(cli) con_proc(cli_connect(cli))
417 /** Get auth request for client. */
418 #define cli_auth(cli) con_auth(cli_connect(cli))
419 /** Get sentalong marker for client. */
420 #define cli_sentalong(cli) con_sentalong(cli_connect(cli))
422 /** Verify that a connection is valid. */
423 #define con_verify(con) ((con)->con_magic == CONNECTION_MAGIC)
424 /** Get connection's magic number. */
425 #define con_magic(con) ((con)->con_magic)
426 /** Get global next connection. */
427 #define con_next(con) ((con)->con_next)
428 /** Get global previous connection. */
429 #define con_prev_p(con) ((con)->con_prev_p)
430 /** Get locally connected client for connection. */
431 #define con_client(con) ((con)->con_client)
432 /** Get number of unprocessed data bytes from connection. */
433 #define con_count(con) ((con)->con_count)
434 /** Get file descriptor for connection. */
435 #define con_fd(con) s_fd(&(con)->con_socket)
436 /** Get freeable flags for connection. */
437 #define con_freeflag(con) ((con)->con_freeflag)
438 /** Get last error code on connection. */
439 #define con_error(con) ((con)->con_error)
440 /** Get sentalong marker for connection. */
441 #define con_sentalong(con) ((con)->con_sentalong)
442 /** Get server notice mask for connection. */
443 #define con_snomask(con) ((con)->con_snomask)
444 /** Get next nick change time for connection. */
445 #define con_nextnick(con) ((con)->con_nextnick)
446 /** Get next new target time for connection. */
447 #define con_nexttarget(con) ((con)->con_nexttarget)
448 /** Get last time we read from the connection. */
449 #define con_lasttime(con) ((con)->con_lasttime)
450 /** Get last time we accepted a command from the connection. */
451 #define con_since(con) ((con)->con_since)
452 /** Get SendQ for connection. */
453 #define con_sendQ(con) ((con)->con_sendQ)
454 /** Get RecvQ for connection. */
455 #define con_recvQ(con) ((con)->con_recvQ)
456 /** Get number of messages sent to connection. */
457 #define con_sendM(con) ((con)->con_sendM)
458 /** Get number of messages received from connection. */
459 #define con_receiveM(con) ((con)->con_receiveM)
460 /** Get number of bytes (modulo 1024) sent to connection. */
461 #define con_sendB(con) ((con)->con_sendB)
462 /** Get number of bytes (modulo 1024) received from connection. */
463 #define con_receiveB(con) ((con)->con_receiveB)
464 /** Get listener that accepted the connection. */
465 #define con_listener(con) ((con)->con_listener)
466 /** Get list of ConfItems attached to the connection. */
467 #define con_confs(con) ((con)->con_confs)
468 /** Get command handler for the connection. */
469 #define con_handler(con) ((con)->con_handler)
470 /** Get the LIST status for the connection. */
471 #define con_listing(con) ((con)->con_listing)
472 /** Get the maximum permitted SendQ size for the connection. */
473 #define con_max_sendq(con) ((con)->con_max_sendq)
474 /** Get the ping frequency for the connection. */
475 #define con_ping_freq(con) ((con)->con_ping_freq)
476 /** Get the lastsq for the connection. */
477 #define con_lastsq(con) ((con)->con_lastsq)
478 /** Get the current targets array for the connection. */
479 #define con_targets(con) ((con)->con_targets)
480 /** Get the string-formatted IP address for the connection. */
481 #define con_sock_ip(con) ((con)->con_sock_ip)
482 /** Get the unspoofed string-formatted IP address for the connection. */
483 #define con_real_sock_ip(con) ((con)->con_real_sock_ip)
484 /** Get the resolved hostname for the connection. */
485 #define con_sockhost(con) ((con)->con_sockhost)
486 /** Get the unspoofed resolved hostname for the connection. */
487 #define con_real_sockhost(con) ((con)->con_real_sockhost)
488 /** Get the password sent by the remote end of the connection. */
489 #define con_passwd(con) ((con)->con_passwd)
490 /** Get the buffer of unprocessed incoming data from the connection. */
491 #define con_buffer(con) ((con)->con_buffer)
492 /** Get the Socket for the connection. */
493 #define con_socket(con) ((con)->con_socket)
494 /** Get the Timer for processing more data from the connection. */
495 #define con_proc(con) ((con)->con_proc)
496 /** Get the oper privilege set for the connection. */
497 #define con_privs(con) (&(con)->con_privs)
498 /** Get the peer's capabilities for the connection. */
499 #define con_capab(con) (&(con)->con_capab)
500 /** Get the active capabilities for the connection. */
501 #define con_active(con) (&(con)->con_active)
502 /** Get the auth request for the connection. */
503 #define con_auth(con) ((con)->con_auth)
505 #define STAT_CONNECTING 0x001 /**< connecting to another server */
506 #define STAT_HANDSHAKE 0x002 /**< pass - server sent */
507 #define STAT_ME 0x004 /**< this server */
508 #define STAT_UNKNOWN 0x008 /**< unidentified connection */
509 #define STAT_UNKNOWN_USER 0x010 /**< connection on a client port */
510 #define STAT_UNKNOWN_SERVER 0x020 /**< connection on a server port */
511 #define STAT_SERVER 0x040 /**< fully registered server */
512 #define STAT_USER 0x080 /**< fully registered user */
517 /** Return non-zero if the client is registered. */
518 #define IsRegistered(x) (cli_status(x) & (STAT_SERVER | STAT_USER))
519 /** Return non-zero if the client is an outbound connection that is
520 * still connecting. */
521 #define IsConnecting(x) (cli_status(x) == STAT_CONNECTING)
522 /** Return non-zero if the client is an outbound connection that has
523 * sent our password. */
524 #define IsHandshake(x) (cli_status(x) == STAT_HANDSHAKE)
525 /** Return non-zero if the client is this server. */
526 #define IsMe(x) (cli_status(x) == STAT_ME)
527 /** Return non-zero if the client has not yet registered. */
528 #define IsUnknown(x) (cli_status(x) & \
529 (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
530 /** Return non-zero if the client is an unregistered connection on a
532 #define IsServerPort(x) (cli_status(x) == STAT_UNKNOWN_SERVER )
533 /** Return non-zero if the client is an unregistered connection on a
535 #define IsUserPort(x) (cli_status(x) == STAT_UNKNOWN_USER )
536 /** Return non-zero if the client is a real client connection. */
537 #define IsClient(x) (cli_status(x) & \
538 (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
539 STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
540 /** Return non-zero if the client ignores flood limits. */
541 #define IsTrusted(x) (cli_status(x) & \
542 (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
543 /** Return non-zero if the client is a registered server. */
544 #define IsServer(x) (cli_status(x) == STAT_SERVER)
545 /** Return non-zero if the client is a registered user. */
546 #define IsUser(x) (cli_status(x) == STAT_USER)
549 /** Mark a client with STAT_CONNECTING. */
550 #define SetConnecting(x) (cli_status(x) = STAT_CONNECTING)
551 /** Mark a client with STAT_HANDSHAKE. */
552 #define SetHandshake(x) (cli_status(x) = STAT_HANDSHAKE)
553 /** Mark a client with STAT_SERVER. */
554 #define SetServer(x) (cli_status(x) = STAT_SERVER)
555 /** Mark a client with STAT_ME. */
556 #define SetMe(x) (cli_status(x) = STAT_ME)
557 /** Mark a client with STAT_USER. */
558 #define SetUser(x) (cli_status(x) = STAT_USER)
560 /** Return non-zero if a client is directly connected to me. */
561 #define MyConnect(x) (cli_from(x) == (x))
562 /** Return non-zero if a client is a locally connected user. */
563 #define MyUser(x) (MyConnect(x) && IsUser(x))
564 /** Return non-zero if a client is a locally connected IRC operator. */
565 #define MyOper(x) (MyConnect(x) && IsOper(x))
566 /** Return protocol version used by a server. */
567 #define Protocol(x) ((cli_serv(x))->prot)
572 /** Set a flag in a client's flags. */
573 #define SetFlag(cli, flag) FlagSet(&cli_flags(cli), flag)
574 /** Clear a flag from a client's flags. */
575 #define ClrFlag(cli, flag) FlagClr(&cli_flags(cli), flag)
576 /** Return non-zero if a flag is set in a client's flags. */
577 #define HasFlag(cli, flag) FlagHas(&cli_flags(cli), flag)
579 /** Return non-zero if the client is an IRC operator (global or local). */
580 #define IsAnOper(x) (IsOper(x) || IsLocOp(x))
581 /** Return non-zero if the client's connection is blocked. */
582 #define IsBlocked(x) HasFlag(x, FLAG_BLOCKED)
583 /** Return non-zero if the client's connection is still being burst. */
584 #define IsBurst(x) HasFlag(x, FLAG_BURST)
585 /** Return non-zero if we have received the peer's entire burst but
586 * not their EOB ack. */
587 #define IsBurstAck(x) HasFlag(x, FLAG_BURST_ACK)
588 /** Return non-zero if we are still bursting to the client. */
589 #define IsBurstOrBurstAck(x) (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK))
590 /** Return non-zero if the client has set mode +k (channel service). */
591 #define IsChannelService(x) HasFlag(x, FLAG_CHSERV)
592 /** Return non-zero if the client's socket is disconnected. */
593 #define IsDead(x) HasFlag(x, FLAG_DEADSOCKET)
594 /** Return non-zero if the client has set mode +d (deaf). */
595 #define IsDeaf(x) HasFlag(x, FLAG_DEAF)
596 /** Return non-zero if the client has been IP-checked for clones. */
597 #define IsIPChecked(x) HasFlag(x, FLAG_IPCHECK)
598 /** Return non-zero if we have received an ident response for the client. */
599 #define IsIdented(x) HasFlag(x, FLAG_GOTID)
600 /** Return non-zero if the client has set mode +i (invisible). */
601 #define IsInvisible(x) HasFlag(x, FLAG_INVISIBLE)
602 /** Return non-zero if the client caused a net.burst. */
603 #define IsJunction(x) HasFlag(x, FLAG_JUNCTION)
604 /** Return non-zero if the client has set mode +O (local operator) locally. */
605 #define IsLocOp(x) (MyConnect(x) && HasFlag(x, FLAG_LOCOP))
606 /** Return non-zero if the client has set mode +o (global operator). */
607 #define IsOper(x) HasFlag(x, FLAG_OPER)
608 /** Return non-zero if the client has an active UDP ping request. */
609 #define IsUPing(x) HasFlag(x, FLAG_UPING)
610 /** Return non-zero if the client has no '\n' in its buffer. */
611 #define NoNewLine(x) HasFlag(x, FLAG_NONL)
612 /** Return non-zero if the client has set mode +g (debugging). */
613 #define SendDebug(x) HasFlag(x, FLAG_DEBUG)
614 /** Return non-zero if the client has set mode +s (server notices). */
615 #define SendServNotice(x) HasFlag(x, FLAG_SERVNOTICE)
616 /** Return non-zero if the client has set mode +w (wallops). */
617 #define SendWallops(x) HasFlag(x, FLAG_WALLOP)
618 /** Return non-zero if the client claims to be a hub. */
619 #define IsHub(x) HasFlag(x, FLAG_HUB)
620 /** Return non-zero if the client understands IPv6 addresses in P10. */
621 #define IsIPv6(x) HasFlag(x, FLAG_IPV6)
622 /** Return non-zero if the client claims to be a services server. */
623 #define IsService(x) HasFlag(x, FLAG_SERVICE)
624 /** Return non-zero if the client claims to be a master server. */
625 #define IsMaster(x) HasFlag(x, FLAG_MASTER)
626 /** Return non-zero if the client has an account stamp. */
627 #define IsAccount(x) HasFlag(x, FLAG_ACCOUNT)
628 /** Return non-zero if the client has set mode +x (hidden host). */
629 #define IsHiddenHost(x) HasFlag(x, FLAG_HIDDENHOST)
630 /** Return non-zero if nobody is connected to this client structure */
631 #define IsNotConn(x) HasFlag(x, FLAG_NOTCONN)
632 /** Return non-zero if the client has an active PING request. */
633 #define IsPingSent(x) HasFlag(x, FLAG_PINGSENT)
634 /** Return non-zero if the client's channels are hidden. */
635 #define IsNoChan(x) HasFlag(x, FLAG_NOCHAN)
636 /** Return non-zero if the client's idle time is hidden. */
637 #define IsNoIdle(x) HasFlag(x, FLAG_NOIDLE)
638 /** Return non-zero if the client is an extra op. */
639 #define IsXtraOp(x) HasFlag(x, FLAG_XTRAOP)
640 /** Return non-zero if the client is a network service. */
641 #define IsNetServ(x) HasFlag(x, FLAG_NETSERV)
642 /** Return non-zero if the client is an hidden oper. */
643 #define IsHiddenOper(x) HasFlag(x, FLAG_HIDDENOPER)
644 /** Return non-zero if the client has set umode +c. */
645 #define IsOverrideCC(x) HasFlag(x, FLAG_OVERRIDECC)
646 /** Return non-zero if the client is connected via SSL. */
647 #define IsSSL(x) HasFlag(x, FLAG_SSL)
648 /** Return non-zero if the client is an WebIRC user with spoofed host/ip. */
649 #define IsWebIRC(x) HasFlag(x, FLAG_WEBIRC)
650 /** Return non-zero if the client can see idletime of +I users. */
651 #define IsSeeIdletime(x) HasFlag(x, FLAG_SEE_IDLETIME)
652 #define IsSecurityServ(x) HasFlag(x, FLAG_SECURITY_SERV)
653 /** Return non-zero if the client has a fakehost. */
654 #define IsFakeHost(x) HasFlag(x, FLAG_FAKEHOST)
655 #define IsFakeIdent(x) HasFlag(x, FLAG_FAKEIDENT)
657 /** Return non-zero if the client has operator or server privileges. */
658 #define IsPrivileged(x) (IsAnOper(x) || IsServer(x))
659 /** Return non-zero if the client's host is hidden. */
660 #define HasHiddenHost(x) (IsHiddenHost(x) && (IsAccount(x) || IsFakeHost(x)))
662 /** Mark a client as having an in-progress net.burst. */
663 #define SetBurst(x) SetFlag(x, FLAG_BURST)
664 /** Mark a client as being between EOB and EOB ACK. */
665 #define SetBurstAck(x) SetFlag(x, FLAG_BURST_ACK)
666 /** Mark a client as having mode +k (channel service). */
667 #define SetChannelService(x) SetFlag(x, FLAG_CHSERV)
668 /** Mark a client as having mode +d (deaf). */
669 #define SetDeaf(x) SetFlag(x, FLAG_DEAF)
670 /** Mark a client as having mode +g (debugging). */
671 #define SetDebug(x) SetFlag(x, FLAG_DEBUG)
672 /** Mark a client as having ident looked up. */
673 #define SetGotId(x) SetFlag(x, FLAG_GOTID)
674 /** Mark a client as being IP-checked. */
675 #define SetIPChecked(x) SetFlag(x, FLAG_IPCHECK)
676 /** Mark a client as having mode +i (invisible). */
677 #define SetInvisible(x) SetFlag(x, FLAG_INVISIBLE)
678 /** Mark a client as causing a net.join. */
679 #define SetJunction(x) SetFlag(x, FLAG_JUNCTION)
680 /** Mark a client as having mode +O (local operator). */
681 #define SetLocOp(x) SetFlag(x, FLAG_LOCOP)
682 /** Mark a client as having mode +o (global operator). */
683 #define SetOper(x) SetFlag(x, FLAG_OPER)
684 /** Mark a client as having a pending UDP ping. */
685 #define SetUPing(x) SetFlag(x, FLAG_UPING)
686 /** Mark a client as having mode +w (wallops). */
687 #define SetWallops(x) SetFlag(x, FLAG_WALLOP)
688 /** Mark a client as having mode +s (server notices). */
689 #define SetServNotice(x) SetFlag(x, FLAG_SERVNOTICE)
690 /** Mark a client as being a hub server. */
691 #define SetHub(x) SetFlag(x, FLAG_HUB)
692 /** Mark a client as being an IPv6-grokking server. */
693 #define SetIPv6(x) SetFlag(x, FLAG_IPV6)
694 /** Mark a client as being a services server. */
695 #define SetService(x) SetFlag(x, FLAG_SERVICE)
696 /** Mark a client as being a master server. */
697 #define SetMaster(x) SetFlag(x, FLAG_MASTER)
698 /** Mark a client as having an account stamp. */
699 #define SetAccount(x) SetFlag(x, FLAG_ACCOUNT)
700 /** Mark a client as having mode +x (hidden host). */
701 #define SetHiddenHost(x) SetFlag(x, FLAG_HIDDENHOST)
702 /** Mark a client as not having anyone connected to it */
703 #define SetNotConn(x) SetFlag(x, FLAG_NOTCONN)
704 /** Mark a client as having a fakehost. */
705 #define SetFakeHost(x) SetFlag(x, FLAG_FAKEHOST)
706 #define SetFakeIdent(x) SetFlag(x, FLAG_FAKEIDENT)
707 /** Mark a client as having a pending PING. */
708 #define SetPingSent(x) SetFlag(x, FLAG_PINGSENT)
709 /** Mark a client as having mode +n. */
710 #define SetNoChan(x) SetFlag(x, FLAG_NOCHAN)
711 /** Mark a client as having mode +I. */
712 #define SetNoIdle(x) SetFlag(x, FLAG_NOIDLE)
713 /** Mark a client as having mode +X. */
714 #define SetXtraOp(x) SetFlag(x, FLAG_XTRAOP)
715 /** Mark a client as having mode +S. */
716 #define SetNetServ(x) SetFlag(x, FLAG_NETSERV)
717 /** Mark a client as having mode +H. */
718 #define SetHiddenOper(x) SetFlag(x, FLAG_HIDDENOPER)
719 /** Mark a client as having umode +c. */
720 #define SetOverrideCC(x) SetFlag(x, FLAG_OVERRIDECC)
721 /** Mark a client as being connected via SSL. */
722 #define SetSSL(x) SetFlag(x, FLAG_SSL)
723 /** Mark a client as being an WebIRC user with spoofed host/ip. */
724 #define SetWebIRC(x) SetFlag(x, FLAG_WEBIRC)
725 /** Mark a client as being able to see idletime of +I users. */
726 #define SetSeeIdletime(x) SetFlag(x, FLAG_SEE_IDLETIME)
727 #define SetSecurityServ(x) SetFlag(x, FLAG_SECURITY_SERV)
729 /** Return non-zero if \a sptr sees \a acptr as an operator. */
730 #define SeeOper(sptr,acptr) ((IsAnOper(acptr) && \
731 (sptr == acptr || HasPriv(acptr, PRIV_DISPLAY) || HasPriv(sptr, PRIV_SEE_OPERS)) && \
732 (!IsHiddenOper(acptr) || IsAnOper(sptr))))
734 /** Clear the client's net.burst in-progress flag. */
735 #define ClearBurst(x) ClrFlag(x, FLAG_BURST)
736 /** Clear the client's between EOB and EOB ACK flag. */
737 #define ClearBurstAck(x) ClrFlag(x, FLAG_BURST_ACK)
738 /** Remove mode +k (channel service) from the client. */
739 #define ClearChannelService(x) ClrFlag(x, FLAG_CHSERV)
740 /** Remove mode +d (deaf) from the client. */
741 #define ClearDeaf(x) ClrFlag(x, FLAG_DEAF)
742 /** Remove mode +g (debugging) from the client. */
743 #define ClearDebug(x) ClrFlag(x, FLAG_DEBUG)
744 /** Remove the client's IP-checked flag. */
745 #define ClearIPChecked(x) ClrFlag(x, FLAG_IPCHECK)
746 /** Remove mode +i (invisible) from the client. */
747 #define ClearInvisible(x) ClrFlag(x, FLAG_INVISIBLE)
748 /** Remove mode +O (local operator) from the client. */
749 #define ClearLocOp(x) ClrFlag(x, FLAG_LOCOP)
750 /** Remove mode +o (global operator) from the client. */
751 #define ClearOper(x) ClrFlag(x, FLAG_OPER)
752 /** Clear the client's pending UDP ping flag. */
753 #define ClearUPing(x) ClrFlag(x, FLAG_UPING)
754 /** Remove mode +w (wallops) from the client. */
755 #define ClearWallops(x) ClrFlag(x, FLAG_WALLOP)
756 /** Remove mode +s (server notices) from the client. */
757 #define ClearServNotice(x) ClrFlag(x, FLAG_SERVNOTICE)
758 /** Remove mode +x (hidden host) from the client. */
759 #define ClearHiddenHost(x) ClrFlag(x, FLAG_HIDDENHOST)
760 /** Mark client as having someone connected to it */
761 #define ClearNotConn(x) ClrFlag(x, FLAG_NOTCONN)
762 /** Remove fakehost flag from the flient. */
763 #define ClearFakeHost(x) ClrFlag(x, FLAG_FAKEHOST)
764 #define ClearFakeIdent(x) ClrFlag(x, FLAG_FAKEIDENT)
765 /** Clear the client's pending PING flag. */
766 #define ClearPingSent(x) ClrFlag(x, FLAG_PINGSENT)
767 /** Clear the client's HUB flag. */
768 #define ClearHub(x) ClrFlag(x, FLAG_HUB)
769 /** Remove mode +n from the client. */
770 #define ClearNoChan(x) ClrFlag(x, FLAG_NOCHAN)
771 /** Remove mode +I from the client. */
772 #define ClearNoIdle(x) ClrFlag(x, FLAG_NOIDLE)
773 /** Remove mode +X from the client. */
774 #define ClearXtraOp(x) ClrFlag(x, FLAG_XTRAOP)
775 /** Remove mode +S from the client. */
776 #define ClearNetServ(x) ClrFlag(x, FLAG_NETSERV)
777 /** Remove mode +H from the client. */
778 #define ClearHiddenOper(x) ClrFlag(x, FLAG_HIDDENOPER)
779 /** Remove mode +c from the client. */
780 #define ClearOverrideCC(x) ClrFlag(x, FLAG_OVERRIDECC)
781 /** Remove ssl mode from the client. */
782 #define ClearSSL(x) ClrFlag(x, FLAG_SSL)
783 /** Remove mode +W (WebIRC user with spoofed host/ip) from the client. */
784 #define ClearWebIRC(x) ClrFlag(x, FLAG_WEBIRC)
785 /** Make client no longer being able to see idletime of +I users. */
786 #define ClearSeeIdletime(x) ClrFlag(x, FLAG_SEE_IDLETIME)
787 #define ClearSecurityServ(x) ClrFlag(x, FLAG_SECURITY_SERV)
790 #define FREEFLAG_SOCKET 0x0001 /**< socket needs to be freed */
791 #define FREEFLAG_TIMER 0x0002 /**< timer needs to be freed */
793 /* server notice stuff */
795 #define SNO_ADD 1 /**< Perform "or" on server notice mask. */
796 #define SNO_DEL 2 /**< Perform "and ~x" on server notice mask. */
797 #define SNO_SET 3 /**< Set server notice mask. */
798 /* DON'T CHANGE THESE VALUES ! */
799 /* THE CLIENTS DEPEND ON IT ! */
800 #define SNO_OLDSNO 0x1 /**< unsorted old messages */
801 #define SNO_SERVKILL 0x2 /**< server kills (nick collisions) */
802 #define SNO_OPERKILL 0x4 /**< oper kills */
803 #define SNO_HACK2 0x8 /**< desyncs */
804 #define SNO_HACK3 0x10 /**< temporary desyncs */
805 #define SNO_UNAUTH 0x20 /**< unauthorized connections */
806 #define SNO_TCPCOMMON 0x40 /**< common TCP or socket errors */
807 #define SNO_TOOMANY 0x80 /**< too many connections */
808 #define SNO_HACK4 0x100 /**< Uworld actions on channels */
809 #define SNO_GLINE 0x200 /**< glines */
810 #define SNO_NETWORK 0x400 /**< net join/break, etc */
811 #define SNO_IPMISMATCH 0x800 /**< IP mismatches */
812 #define SNO_THROTTLE 0x1000 /**< host throttle add/remove notices */
813 #define SNO_OLDREALOP 0x2000 /**< old oper-only messages */
814 #define SNO_CONNEXIT 0x4000 /**< client connect/exit (ugh) */
815 #define SNO_AUTO 0x8000 /**< AUTO G-Lines */
816 #define SNO_DEBUG 0x10000 /**< debugging messages (DEBUGMODE only) */
817 #define SNO_AUTH 0x20000 /**< IAuth notices */
819 /** Bitmask of all valid server notice bits. */
821 # define SNO_ALL 0x3ffff
823 # define SNO_ALL 0x2ffff
826 /** Server notice bits allowed to normal users. */
827 #define SNO_USER (SNO_ALL & ~SNO_OPER)
829 /** Server notice bits enabled by default for normal users. */
830 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
831 /** Server notice bits enabled by default for IRC operators. */
832 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
833 /** Server notice bits reserved to IRC operators. */
834 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP|SNO_AUTH)
835 /** Noisy server notice bits that cause other bits to be cleared during connect. */
836 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
838 /** Test whether a privilege has been granted to a client. */
839 #define HasPriv(cli, priv) FlagHas(cli_privs(cli), priv)
840 /** Grant a privilege to a client. */
841 #define SetPriv(cli, priv) FlagSet(cli_privs(cli), priv)
842 /** Revoke a privilege from a client. */
843 #define ClrPriv(cli, priv) FlagClr(cli_privs(cli), priv)
845 /** Test whether a client has a capability */
846 #define HasCap(cli, cap) CapHas(cli_capab(cli), (cap))
847 /** Test whether a client has the capability active */
848 #define CapActive(cli, cap) CapHas(cli_active(cli), (cap))
850 /** Returns 1 if cptr can see the idletime of acptr. */
851 #define HasNoIdlePriv(cptr) (MyUser(cptr) && HasPriv(cptr, PRIV_HIDE_IDLETIME))
852 #define CanSeeIdletime(cptr, acptr) ( \
855 (!feature_bool(FEAT_HIS_WHOIS_IDLETIME) && ( \
856 (!IsNoIdle(acptr) || !IsAnOper(acptr)) && \
857 (!IsNoIdle(acptr) || (IsSeeIdletime(cptr) && (!HasNoIdlePriv(acptr) || HasNoIdlePriv(cptr)))) \
860 #define HIDE_IP 0 /**< Do not show IP address in get_client_name() */
861 #define SHOW_IP 1 /**< Show ident and IP address in get_client_name() */
863 extern const char* get_client_name(const struct Client* sptr, int showip);
864 extern const char* client_get_default_umode(const struct Client* sptr);
865 extern int client_get_ping(const struct Client* local_client);
866 extern void client_drop_sendq(struct Connection* con);
867 extern void client_add_sendq(struct Connection* con,
868 struct Connection** con_p);
869 extern void client_set_privs(struct Client *client, struct ConfItem *oper);
870 extern void client_set_uprivs(struct Client *client, struct ConfItem *aconf);
871 extern int client_report_privs(struct Client* to, struct Client* client);
873 #endif /* INCLUDED_client_h */