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.
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
64 * Only put structures here that are being used in a very large number of
65 * source files. Other structures go in the header file of there corresponding
66 * source file, or in the source file itself (when only used in that file).
69 /** Single element in a flag bitset array. */
70 typedef unsigned long flagpage_t;
72 /** Number of bits in a flagpage_t. */
73 #define FLAGSET_NBITS (8 * sizeof(flagpage_t))
74 /** Element number for flag \a flag. */
75 #define FLAGSET_INDEX(flag) ((flag) / FLAGSET_NBITS)
76 /** Element bit for flag \a flag. */
77 #define FLAGSET_MASK(flag) (1ul<<((flag) % FLAGSET_NBITS))
79 /** Declare a flagset structure of a particular size. */
80 #define DECLARE_FLAGSET(name,max) \
83 unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \
86 /** Test whether a flag is set in a flagset. */
87 #define FlagHas(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag))
88 /** Set a flag in a flagset. */
89 #define FlagSet(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag))
90 /** Clear a flag in a flagset. */
91 #define FlagClr(set,flag) ((set)->bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag))
93 /** String containing valid user modes, in no particular order. */
94 #define infousermodes "diOoswkgx"
96 /** Operator privileges. */
99 PRIV_CHAN_LIMIT, /**< no channel limit on oper */
100 PRIV_MODE_LCHAN, /**< oper can mode local chans */
101 PRIV_WALK_LCHAN, /**< oper can walk through local modes */
102 PRIV_DEOP_LCHAN, /**< no deop oper on local chans */
103 PRIV_SHOW_INVIS, /**< show local invisible users */
104 PRIV_SHOW_ALL_INVIS, /**< show all invisible users */
105 PRIV_UNLIMIT_QUERY, /**< unlimit who queries */
106 PRIV_KILL, /**< oper can KILL */
107 PRIV_LOCAL_KILL, /**< oper can local KILL */
108 PRIV_REHASH, /**< oper can REHASH */
109 PRIV_RESTART, /**< oper can RESTART */
110 PRIV_DIE, /**< oper can DIE */
111 PRIV_GLINE, /**< oper can GLINE */
112 PRIV_LOCAL_GLINE, /**< oper can local GLINE */
113 PRIV_JUPE, /**< oper can JUPE */
114 PRIV_LOCAL_JUPE, /**< oper can local JUPE */
115 PRIV_OPMODE, /**< oper can OP/CLEARMODE */
116 PRIV_LOCAL_OPMODE, /**< oper can local OP/CLEARMODE */
117 PRIV_SET, /**< oper can SET */
118 PRIV_WHOX, /**< oper can use /who x */
119 PRIV_BADCHAN, /**< oper can BADCHAN */
120 PRIV_LOCAL_BADCHAN, /**< oper can local BADCHAN */
121 PRIV_SEE_CHAN, /**< oper can see in secret chans */
122 PRIV_PROPAGATE, /**< propagate oper status */
123 PRIV_DISPLAY, /**< "Is an oper" displayed */
124 PRIV_SEE_OPERS, /**< display hidden opers */
125 PRIV_WIDE_GLINE, /**< oper can set wider G-lines */
126 PRIV_LIST_CHAN, /**< oper can list secret channels */
127 PRIV_FORCE_OPMODE, /**< can hack modes on quarantined channels */
128 PRIV_FORCE_LOCAL_OPMODE, /**< can hack modes on quarantined local channels */
129 PRIV_APASS_OPMODE, /**< can hack modes +A/-A/+U/-U */
130 PRIV_UNLIMIT_FLOOD, /**< user won't get excess flooded */
131 PRIV_LAST_PRIV /**< number of privileges */
134 /** Client flags and modes.
135 * Note that flags at least FLAG_LOCAL_UMODES but less than
136 * FLAG_GLOBAL_UMODES are treated as local modes, and flags at least
137 * FLAG_GLOBAL_UMODES (but less than FLAG_LAST_FLAG) are treated as
142 FLAG_PINGSENT, /**< Unreplied ping sent */
143 FLAG_DEADSOCKET, /**< Local socket is dead--Exiting soon */
144 FLAG_KILLED, /**< Prevents "QUIT" from being sent for this */
145 FLAG_BLOCKED, /**< socket is in a blocked condition */
146 FLAG_CLOSING, /**< set when closing to suppress errors */
147 FLAG_UPING, /**< has active UDP ping request */
148 FLAG_HUB, /**< server is a hub */
149 FLAG_IPV6, /**< server understands P10 IPv6 addrs */
150 FLAG_SERVICE, /**< server is a service */
151 FLAG_GOTID, /**< successful ident lookup achieved */
152 FLAG_DOID, /**< I-lines say must use ident return */
153 FLAG_NONL, /**< No \n in buffer */
154 FLAG_TS8, /**< Why do you want to know? */
155 FLAG_MAP, /**< Show server on the map */
156 FLAG_JUNCTION, /**< Junction causing the net.burst. */
157 FLAG_BURST, /**< Server is receiving a net.burst */
158 FLAG_BURST_ACK, /**< Server is waiting for eob ack */
159 FLAG_IPCHECK, /**< Added or updated IPregistry data */
160 FLAG_LOCOP, /**< Local operator -- SRB */
161 FLAG_SERVNOTICE, /**< server notices such as kill */
162 FLAG_OPER, /**< Operator */
163 FLAG_INVISIBLE, /**< makes user invisible */
164 FLAG_WALLOP, /**< send wallops to them */
165 FLAG_DEAF, /**< Makes user deaf */
166 FLAG_CHSERV, /**< Disallow KICK or MODE -o on the user;
167 don't display channels in /whois */
168 FLAG_DEBUG, /**< send global debug/anti-hack info */
169 FLAG_ACCOUNT, /**< account name has been set */
170 FLAG_HIDDENHOST, /**< user's host is hidden */
171 FLAG_SSLCONN, /**< SSL Connection */
172 FLAG_LAST_FLAG, /**< number of flags */
173 FLAG_LOCAL_UMODES = FLAG_LOCOP, /**< First local mode flag */
174 FLAG_GLOBAL_UMODES = FLAG_OPER /**< First global mode flag */
177 /** Declare flagset type for operator privileges. */
178 DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV);
179 /** Declare flagset type for user flags. */
180 DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG);
182 #include "capab.h" /* client capabilities */
184 /** Represents a local connection.
185 * This contains a lot of stuff irrelevant to server connections, but
186 * those are so rare as to not be worth special-casing.
190 unsigned long con_magic; /**< magic number */
191 struct Connection* con_next; /**< Next connection with queued data */
192 struct Connection** con_prev_p; /**< What points to us */
193 struct Client* con_client; /**< Client associated with connection */
194 unsigned int con_count; /**< Amount of data in buffer */
195 int con_freeflag; /**< indicates if connection can be freed */
196 int con_error; /**< last socket level error for client */
197 int con_sentalong; /**< sentalong marker for connection */
198 unsigned int con_snomask; /**< mask for server messages */
199 time_t con_nextnick; /**< Next time a nick change is allowed */
200 time_t con_nexttarget;/**< Next time a target change is allowed */
201 time_t con_lasttime; /**< Last time data read from socket */
202 time_t con_since; /**< Last time we accepted a command */
203 struct MsgQ con_sendQ; /**< Outgoing message queue */
204 struct DBuf con_recvQ; /**< Incoming data yet to be parsed */
205 unsigned int con_sendM; /**< Stats: protocol messages sent */
206 unsigned int con_receiveM; /**< Stats: protocol messages received */
207 uint64_t con_sendB; /**< Bytes sent. */
208 uint64_t con_receiveB; /**< Bytes received. */
209 struct Listener* con_listener; /**< Listening socket which we accepted
211 struct SLink* con_confs; /**< Associated configuration records. */
212 HandlerType con_handler; /**< Message index into command table
214 struct ListingArgs* con_listing; /**< Current LIST status. */
215 unsigned int con_max_sendq; /**< cached max send queue for client */
216 unsigned int con_ping_freq; /**< cached ping freq */
217 unsigned short con_lastsq; /**< # 2k blocks when sendqueued
219 unsigned char con_targets[MAXTARGETS]; /**< Hash values of
221 char con_sock_ip[SOCKIPLEN + 1]; /**< Remote IP address as a string. */
222 char con_sockhost[HOSTLEN + 1]; /**< This is the host name from
223 the socket and after which the
224 connection was accepted. */
225 char con_passwd[PASSWDLEN + 1]; /**< Password given by user. */
226 char con_buffer[BUFSIZE]; /**< Incoming message buffer; or
227 the error that caused this
228 clients socket to close. */
229 struct Socket con_socket; /**< socket descriptor for
231 struct Timer con_proc; /**< process latent messages from
233 struct Privs con_privs; /**< Oper privileges */
234 struct CapSet con_capab; /**< Client capabilities (from us) */
235 struct CapSet con_active; /**< Active capabilities (to us) */
236 struct AuthRequest* con_auth; /**< Auth request for client */
237 struct SSLConnection* con_ssl; /**< SSL connection for client */
240 /** Magic constant to identify valid Connection structures. */
241 #define CONNECTION_MAGIC 0x12f955f3
243 /** Represents a client anywhere on the network. */
245 unsigned long cli_magic; /**< magic number */
246 struct Client* cli_next; /**< link in GlobalClientList */
247 struct Client* cli_prev; /**< link in GlobalClientList */
248 struct Client* cli_hnext; /**< link in hash table bucket or this */
249 struct Connection* cli_connect; /**< Connection structure associated with us */
250 struct User* cli_user; /**< Defined if this client is a user */
251 struct Server* cli_serv; /**< Defined if this client is a server */
252 struct Whowas* cli_whowas; /**< Pointer to ww struct to be freed on quit */
253 char cli_yxx[4]; /**< Numeric Nick: YY if this is a
254 server, XXX if this is a user */
255 time_t cli_firsttime; /**< time client was created */
256 time_t cli_lastnick; /**< TimeStamp on nick */
257 int cli_marker; /**< /who processing marker */
258 struct Flags cli_flags; /**< client flags */
259 unsigned int cli_hopcount; /**< number of servers to this 0 = local */
260 struct irc_in_addr cli_ip; /**< Real IP of client */
261 short cli_status; /**< Client type */
262 char cli_name[HOSTLEN + 1]; /**< Unique name of the client, nick or host */
263 char cli_username[USERLEN + 1]; /**< Username determined by ident lookup */
264 char cli_info[REALLEN + 1]; /**< Free form additional client information */
267 /** Magic constant to identify valid Client structures. */
268 #define CLIENT_MAGIC 0x4ca08286
270 /** Verify that a client is valid. */
271 #define cli_verify(cli) ((cli)->cli_magic == CLIENT_MAGIC)
272 /** Get client's magic number. */
273 #define cli_magic(cli) ((cli)->cli_magic)
274 /** Get global next client. */
275 #define cli_next(cli) ((cli)->cli_next)
276 /** Get global previous client. */
277 #define cli_prev(cli) ((cli)->cli_prev)
278 /** Get next client in hash bucket chain. */
279 #define cli_hnext(cli) ((cli)->cli_hnext)
280 /** Get connection associated with client. */
281 #define cli_connect(cli) ((cli)->cli_connect)
282 /** Get local client that links us to \a cli. */
283 #define cli_from(cli) con_client(cli_connect(cli))
284 /** Get User structure for client, if client is a user. */
285 #define cli_user(cli) ((cli)->cli_user)
286 /** Get Server structure for client, if client is a server. */
287 #define cli_serv(cli) ((cli)->cli_serv)
288 /** Get Whowas link for client. */
289 #define cli_whowas(cli) ((cli)->cli_whowas)
290 /** Get client numnick. */
291 #define cli_yxx(cli) ((cli)->cli_yxx)
292 /** Get time we last read data from the client socket. */
293 #define cli_lasttime(cli) con_lasttime(cli_connect(cli))
294 /** Get time we last parsed something from the client. */
295 #define cli_since(cli) con_since(cli_connect(cli))
296 /** Get time client was created. */
297 #define cli_firsttime(cli) ((cli)->cli_firsttime)
298 /** Get time client last changed nickname. */
299 #define cli_lastnick(cli) ((cli)->cli_lastnick)
300 /** Get WHO marker for client. */
301 #define cli_marker(cli) ((cli)->cli_marker)
302 /** Get flags flagset for client. */
303 #define cli_flags(cli) ((cli)->cli_flags)
304 /** Get hop count to client. */
305 #define cli_hopcount(cli) ((cli)->cli_hopcount)
306 /** Get client IP address. */
307 #define cli_ip(cli) ((cli)->cli_ip)
308 /** Get status bitmask for client. */
309 #define cli_status(cli) ((cli)->cli_status)
310 /** Return non-zero if the client is local. */
311 #define cli_local(cli) (cli_from(cli) == cli)
312 /** Get oper privileges for client. */
313 #define cli_privs(cli) con_privs(cli_connect(cli))
314 /** Get client capabilities for client */
315 #define cli_capab(cli) con_capab(cli_connect(cli))
316 /** Get active client capabilities for client */
317 #define cli_active(cli) con_active(cli_connect(cli))
318 /** Get client name. */
319 #define cli_name(cli) ((cli)->cli_name)
320 /** Get client username (ident). */
321 #define cli_username(cli) ((cli)->cli_username)
322 /** Get client realname (information field). */
323 #define cli_info(cli) ((cli)->cli_info)
324 /** Get client account string. */
325 #define cli_account(cli) (cli_user(cli) ? cli_user(cli)->account : "0")
327 /** Get number of incoming bytes queued for client. */
328 #define cli_count(cli) con_count(cli_connect(cli))
329 /** Get file descriptor for sending in client's direction. */
330 #define cli_fd(cli) con_fd(cli_connect(cli))
331 /** Get free flags for the client's connection. */
332 #define cli_freeflag(cli) con_freeflag(cli_connect(cli))
333 /** Get last error code for the client's connection. */
334 #define cli_error(cli) con_error(cli_connect(cli))
335 /** Get server notice mask for the client. */
336 #define cli_snomask(cli) con_snomask(cli_connect(cli))
337 /** Get next time a nick change is allowed for the client. */
338 #define cli_nextnick(cli) con_nextnick(cli_connect(cli))
339 /** Get next time a target change is allowed for the client. */
340 #define cli_nexttarget(cli) con_nexttarget(cli_connect(cli))
341 /** Get SendQ for client. */
342 #define cli_sendQ(cli) con_sendQ(cli_connect(cli))
343 /** Get RecvQ for client. */
344 #define cli_recvQ(cli) con_recvQ(cli_connect(cli))
345 /** Get count of messages sent to client. */
346 #define cli_sendM(cli) con_sendM(cli_connect(cli))
347 /** Get number of messages received from client. */
348 #define cli_receiveM(cli) con_receiveM(cli_connect(cli))
349 /** Get number of bytes (modulo 1024) sent to client. */
350 #define cli_sendB(cli) con_sendB(cli_connect(cli))
351 /** Get number of bytes (modulo 1024) received from client. */
352 #define cli_receiveB(cli) con_receiveB(cli_connect(cli))
353 /** Get listener that accepted the client's connection. */
354 #define cli_listener(cli) con_listener(cli_connect(cli))
355 /** Get list of attached conf lines. */
356 #define cli_confs(cli) con_confs(cli_connect(cli))
357 /** Get handler type for client. */
358 #define cli_handler(cli) con_handler(cli_connect(cli))
359 /** Get LIST status for client. */
360 #define cli_listing(cli) con_listing(cli_connect(cli))
361 /** Get cached max SendQ for client. */
362 #define cli_max_sendq(cli) con_max_sendq(cli_connect(cli))
363 /** Get ping frequency for client. */
364 #define cli_ping_freq(cli) con_ping_freq(cli_connect(cli))
365 /** Get lastsq for client's connection. */
366 #define cli_lastsq(cli) con_lastsq(cli_connect(cli))
367 /** Get the array of current targets for the client. */
368 #define cli_targets(cli) con_targets(cli_connect(cli))
369 /** Get the string form of the client's IP address. */
370 #define cli_sock_ip(cli) con_sock_ip(cli_connect(cli))
371 /** Get the resolved hostname for the client. */
372 #define cli_sockhost(cli) con_sockhost(cli_connect(cli))
373 /** Get the client's password. */
374 #define cli_passwd(cli) con_passwd(cli_connect(cli))
375 /** Get the unprocessed input buffer for a client's connection. */
376 #define cli_buffer(cli) con_buffer(cli_connect(cli))
377 /** Get the Socket structure for sending to a client. */
378 #define cli_socket(cli) con_socket(cli_connect(cli))
379 /** Get Timer for processing waiting messages from the client. */
380 #define cli_proc(cli) con_proc(cli_connect(cli))
381 /** Get auth request for client. */
382 #define cli_auth(cli) con_auth(cli_connect(cli))
383 /** Get sentalong marker for client. */
384 #define cli_sentalong(cli) con_sentalong(cli_connect(cli))
386 /** Verify that a connection is valid. */
387 #define con_verify(con) ((con)->con_magic == CONNECTION_MAGIC)
388 /** Get connection's magic number. */
389 #define con_magic(con) ((con)->con_magic)
390 /** Get global next connection. */
391 #define con_next(con) ((con)->con_next)
392 /** Get global previous connection. */
393 #define con_prev_p(con) ((con)->con_prev_p)
394 /** Get locally connected client for connection. */
395 #define con_client(con) ((con)->con_client)
396 /** Get number of unprocessed data bytes from connection. */
397 #define con_count(con) ((con)->con_count)
398 /** Get file descriptor for connection. */
399 #define con_fd(con) s_fd(&(con)->con_socket)
400 /** Get freeable flags for connection. */
401 #define con_freeflag(con) ((con)->con_freeflag)
402 /** Get last error code on connection. */
403 #define con_error(con) ((con)->con_error)
404 /** Get sentalong marker for connection. */
405 #define con_sentalong(con) ((con)->con_sentalong)
406 /** Get server notice mask for connection. */
407 #define con_snomask(con) ((con)->con_snomask)
408 /** Get next nick change time for connection. */
409 #define con_nextnick(con) ((con)->con_nextnick)
410 /** Get next new target time for connection. */
411 #define con_nexttarget(con) ((con)->con_nexttarget)
412 /** Get last time we read from the connection. */
413 #define con_lasttime(con) ((con)->con_lasttime)
414 /** Get last time we accepted a command from the connection. */
415 #define con_since(con) ((con)->con_since)
416 /** Get SendQ for connection. */
417 #define con_sendQ(con) ((con)->con_sendQ)
418 /** Get RecvQ for connection. */
419 #define con_recvQ(con) ((con)->con_recvQ)
420 /** Get number of messages sent to connection. */
421 #define con_sendM(con) ((con)->con_sendM)
422 /** Get number of messages received from connection. */
423 #define con_receiveM(con) ((con)->con_receiveM)
424 /** Get number of bytes (modulo 1024) sent to connection. */
425 #define con_sendB(con) ((con)->con_sendB)
426 /** Get number of bytes (modulo 1024) received from connection. */
427 #define con_receiveB(con) ((con)->con_receiveB)
428 /** Get listener that accepted the connection. */
429 #define con_listener(con) ((con)->con_listener)
430 /** Get list of ConfItems attached to the connection. */
431 #define con_confs(con) ((con)->con_confs)
432 /** Get command handler for the connection. */
433 #define con_handler(con) ((con)->con_handler)
434 /** Get the LIST status for the connection. */
435 #define con_listing(con) ((con)->con_listing)
436 /** Get the maximum permitted SendQ size for the connection. */
437 #define con_max_sendq(con) ((con)->con_max_sendq)
438 /** Get the ping frequency for the connection. */
439 #define con_ping_freq(con) ((con)->con_ping_freq)
440 /** Get the lastsq for the connection. */
441 #define con_lastsq(con) ((con)->con_lastsq)
442 /** Get the current targets array for the connection. */
443 #define con_targets(con) ((con)->con_targets)
444 /** Get the string-formatted IP address for the connection. */
445 #define con_sock_ip(con) ((con)->con_sock_ip)
446 /** Get the resolved hostname for the connection. */
447 #define con_sockhost(con) ((con)->con_sockhost)
448 /** Get the password sent by the remote end of the connection. */
449 #define con_passwd(con) ((con)->con_passwd)
450 /** Get the buffer of unprocessed incoming data from the connection. */
451 #define con_buffer(con) ((con)->con_buffer)
452 /** Get the Socket for the connection. */
453 #define con_socket(con) ((con)->con_socket)
454 /** Get the Timer for processing more data from the connection. */
455 #define con_proc(con) ((con)->con_proc)
456 /** Get the oper privilege set for the connection. */
457 #define con_privs(con) (&(con)->con_privs)
458 /** Get the peer's capabilities for the connection. */
459 #define con_capab(con) (&(con)->con_capab)
460 /** Get the active capabilities for the connection. */
461 #define con_active(con) (&(con)->con_active)
462 /** Get the auth request for the connection. */
463 #define con_auth(con) ((con)->con_auth)
464 /** Get the ssl connection for the connection. */
465 #define con_ssl(con) ((con)->con_ssl)
467 #define STAT_CONNECTING 0x001 /**< connecting to another server */
468 #define STAT_HANDSHAKE 0x002 /**< pass - server sent */
469 #define STAT_ME 0x004 /**< this server */
470 #define STAT_UNKNOWN 0x008 /**< unidentified connection */
471 #define STAT_UNKNOWN_USER 0x010 /**< connection on a client port */
472 #define STAT_UNKNOWN_SERVER 0x020 /**< connection on a server port */
473 #define STAT_SERVER 0x040 /**< fully registered server */
474 #define STAT_USER 0x080 /**< fully registered user */
479 /** Return non-zero if the client is registered. */
480 #define IsRegistered(x) (cli_status(x) & (STAT_SERVER | STAT_USER))
481 /** Return non-zero if the client is an outbound connection that is
482 * still connecting. */
483 #define IsConnecting(x) (cli_status(x) == STAT_CONNECTING)
484 /** Return non-zero if the client is an outbound connection that has
485 * sent our password. */
486 #define IsHandshake(x) (cli_status(x) == STAT_HANDSHAKE)
487 /** Return non-zero if the client is this server. */
488 #define IsMe(x) (cli_status(x) == STAT_ME)
489 /** Return non-zero if the client has not yet registered. */
490 #define IsUnknown(x) (cli_status(x) & \
491 (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
492 /** Return non-zero if the client is an unregistered connection on a
494 #define IsServerPort(x) (cli_status(x) == STAT_UNKNOWN_SERVER )
495 /** Return non-zero if the client is an unregistered connection on a
497 #define IsUserPort(x) (cli_status(x) == STAT_UNKNOWN_USER )
498 /** Return non-zero if the client is a real client connection. */
499 #define IsClient(x) (cli_status(x) & \
500 (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
501 STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
502 /** Return non-zero if the client ignores flood limits. */
503 #define IsTrusted(x) (cli_status(x) & \
504 (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
505 /** Return non-zero if the client is a registered server. */
506 #define IsServer(x) (cli_status(x) == STAT_SERVER)
507 /** Return non-zero if the client is a registered user. */
508 #define IsUser(x) (cli_status(x) == STAT_USER)
511 /** Mark a client with STAT_CONNECTING. */
512 #define SetConnecting(x) (cli_status(x) = STAT_CONNECTING)
513 /** Mark a client with STAT_HANDSHAKE. */
514 #define SetHandshake(x) (cli_status(x) = STAT_HANDSHAKE)
515 /** Mark a client with STAT_SERVER. */
516 #define SetServer(x) (cli_status(x) = STAT_SERVER)
517 /** Mark a client with STAT_ME. */
518 #define SetMe(x) (cli_status(x) = STAT_ME)
519 /** Mark a client with STAT_USER. */
520 #define SetUser(x) (cli_status(x) = STAT_USER)
522 /** Return non-zero if a client is directly connected to me. */
523 #define MyConnect(x) (cli_from(x) == (x))
524 /** Return non-zero if a client is a locally connected user. */
525 #define MyUser(x) (MyConnect(x) && IsUser(x))
526 /** Return non-zero if a client is a locally connected IRC operator. */
527 #define MyOper(x) (MyConnect(x) && IsOper(x))
528 /** Return protocol version used by a server. */
529 #define Protocol(x) ((cli_serv(x))->prot)
534 /** Set a flag in a client's flags. */
535 #define SetFlag(cli, flag) FlagSet(&cli_flags(cli), flag)
536 /** Clear a flag from a client's flags. */
537 #define ClrFlag(cli, flag) FlagClr(&cli_flags(cli), flag)
538 /** Return non-zero if a flag is set in a client's flags. */
539 #define HasFlag(cli, flag) FlagHas(&cli_flags(cli), flag)
541 /** Return non-zero if the client is an IRC operator (global or local). */
542 #define IsAnOper(x) (IsOper(x) || IsLocOp(x))
543 /** Return non-zero if the client's connection is blocked. */
544 #define IsBlocked(x) HasFlag(x, FLAG_BLOCKED)
545 /** Return non-zero if the client's connection is still being burst. */
546 #define IsBurst(x) HasFlag(x, FLAG_BURST)
547 /** Return non-zero if we have received the peer's entire burst but
548 * not their EOB ack. */
549 #define IsBurstAck(x) HasFlag(x, FLAG_BURST_ACK)
550 /** Return non-zero if we are still bursting to the client. */
551 #define IsBurstOrBurstAck(x) (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK))
552 /** Return non-zero if the client has set mode +k (channel service). */
553 #define IsChannelService(x) HasFlag(x, FLAG_CHSERV)
554 /** Return non-zero if the client's socket is disconnected. */
555 #define IsDead(x) HasFlag(x, FLAG_DEADSOCKET)
556 /** Return non-zero if the client has set mode +d (deaf). */
557 #define IsDeaf(x) HasFlag(x, FLAG_DEAF)
558 /** Return non-zero if the client has been IP-checked for clones. */
559 #define IsIPChecked(x) HasFlag(x, FLAG_IPCHECK)
560 /** Return non-zero if we have received an ident response for the client. */
561 #define IsIdented(x) HasFlag(x, FLAG_GOTID)
562 /** Return non-zero if the client has set mode +i (invisible). */
563 #define IsInvisible(x) HasFlag(x, FLAG_INVISIBLE)
564 /** Return non-zero if the client caused a net.burst. */
565 #define IsJunction(x) HasFlag(x, FLAG_JUNCTION)
566 /** Return non-zero if the client has set mode +O (local operator) locally. */
567 #define IsLocOp(x) (MyConnect(x) && HasFlag(x, FLAG_LOCOP))
568 /** Return non-zero if the client has set mode +o (global operator). */
569 #define IsOper(x) HasFlag(x, FLAG_OPER)
570 /** Return non-zero if the client has an active UDP ping request. */
571 #define IsUPing(x) HasFlag(x, FLAG_UPING)
572 /** Return non-zero if the client has no '\n' in its buffer. */
573 #define NoNewLine(x) HasFlag(x, FLAG_NONL)
574 /** Return non-zero if the client has set mode +g (debugging). */
575 #define SendDebug(x) HasFlag(x, FLAG_DEBUG)
576 /** Return non-zero if the client has set mode +s (server notices). */
577 #define SendServNotice(x) HasFlag(x, FLAG_SERVNOTICE)
578 /** Return non-zero if the client has set mode +w (wallops). */
579 #define SendWallops(x) HasFlag(x, FLAG_WALLOP)
580 /** Return non-zero if the client claims to be a hub. */
581 #define IsHub(x) HasFlag(x, FLAG_HUB)
582 /** Return non-zero if the client understands IPv6 addresses in P10. */
583 #define IsIPv6(x) HasFlag(x, FLAG_IPV6)
584 /** Return non-zero if the client claims to be a services server. */
585 #define IsService(x) HasFlag(x, FLAG_SERVICE)
586 /** Return non-zero if the client has an account stamp. */
587 #define IsAccount(x) HasFlag(x, FLAG_ACCOUNT)
588 /** Return non-zero if the client has set mode +x (hidden host). */
589 #define IsHiddenHost(x) HasFlag(x, FLAG_HIDDENHOST)
590 /** Return non-zero if the client has set mode +S (SSL Connection). */
591 #define IsSSLConn(x) HasFlag(x, FLAG_SSLCONN)
592 /** Return non-zero if the client has an active PING request. */
593 #define IsPingSent(x) HasFlag(x, FLAG_PINGSENT)
595 /** Return non-zero if the client has operator or server privileges. */
596 #define IsPrivileged(x) (IsAnOper(x) || IsServer(x))
597 /** Return non-zero if the client's host is hidden. */
598 #define HasHiddenHost(x) (IsHiddenHost(x) && IsAccount(x))
600 /** Mark a client as having an in-progress net.burst. */
601 #define SetBurst(x) SetFlag(x, FLAG_BURST)
602 /** Mark a client as being between EOB and EOB ACK. */
603 #define SetBurstAck(x) SetFlag(x, FLAG_BURST_ACK)
604 /** Mark a client as having mode +k (channel service). */
605 #define SetChannelService(x) SetFlag(x, FLAG_CHSERV)
606 /** Mark a client as having mode +d (deaf). */
607 #define SetDeaf(x) SetFlag(x, FLAG_DEAF)
608 /** Mark a client as having mode +g (debugging). */
609 #define SetDebug(x) SetFlag(x, FLAG_DEBUG)
610 /** Mark a client as having ident looked up. */
611 #define SetGotId(x) SetFlag(x, FLAG_GOTID)
612 /** Mark a client as being IP-checked. */
613 #define SetIPChecked(x) SetFlag(x, FLAG_IPCHECK)
614 /** Mark a client as having mode +i (invisible). */
615 #define SetInvisible(x) SetFlag(x, FLAG_INVISIBLE)
616 /** Mark a client as causing a net.join. */
617 #define SetJunction(x) SetFlag(x, FLAG_JUNCTION)
618 /** Mark a client as having mode +O (local operator). */
619 #define SetLocOp(x) SetFlag(x, FLAG_LOCOP)
620 /** Mark a client as having mode +o (global operator). */
621 #define SetOper(x) SetFlag(x, FLAG_OPER)
622 /** Mark a client as having a pending UDP ping. */
623 #define SetUPing(x) SetFlag(x, FLAG_UPING)
624 /** Mark a client as having mode +w (wallops). */
625 #define SetWallops(x) SetFlag(x, FLAG_WALLOP)
626 /** Mark a client as having mode +s (server notices). */
627 #define SetServNotice(x) SetFlag(x, FLAG_SERVNOTICE)
628 /** Mark a client as being a hub server. */
629 #define SetHub(x) SetFlag(x, FLAG_HUB)
630 /** Mark a client as being an IPv6-grokking server. */
631 #define SetIPv6(x) SetFlag(x, FLAG_IPV6)
632 /** Mark a client as being a services server. */
633 #define SetService(x) SetFlag(x, FLAG_SERVICE)
634 /** Mark a client as having an account stamp. */
635 #define SetAccount(x) SetFlag(x, FLAG_ACCOUNT)
636 /** Mark a client as having mode +x (hidden host). */
637 #define SetHiddenHost(x) SetFlag(x, FLAG_HIDDENHOST)
638 /** Mark a client as having mode +S (SSL Connection). */
639 #define SetSSLConn(x) SetFlag(x, FLAG_SSLCONN)
641 /** Mark a client as having a pending PING. */
642 #define SetPingSent(x) SetFlag(x, FLAG_PINGSENT)
644 /** Return non-zero if \a sptr sees \a acptr as an operator. */
645 #define SeeOper(sptr,acptr) (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) \
646 || HasPriv(sptr, PRIV_SEE_OPERS)))
648 /** Clear the client's net.burst in-progress flag. */
649 #define ClearBurst(x) ClrFlag(x, FLAG_BURST)
650 /** Clear the client's between EOB and EOB ACK flag. */
651 #define ClearBurstAck(x) ClrFlag(x, FLAG_BURST_ACK)
652 /** Remove mode +k (channel service) from the client. */
653 #define ClearChannelService(x) ClrFlag(x, FLAG_CHSERV)
654 /** Remove mode +d (deaf) from the client. */
655 #define ClearDeaf(x) ClrFlag(x, FLAG_DEAF)
656 /** Remove mode +g (debugging) from the client. */
657 #define ClearDebug(x) ClrFlag(x, FLAG_DEBUG)
658 /** Remove the client's IP-checked flag. */
659 #define ClearIPChecked(x) ClrFlag(x, FLAG_IPCHECK)
660 /** Remove mode +i (invisible) from the client. */
661 #define ClearInvisible(x) ClrFlag(x, FLAG_INVISIBLE)
662 /** Remove mode +O (local operator) from the client. */
663 #define ClearLocOp(x) ClrFlag(x, FLAG_LOCOP)
664 /** Remove mode +o (global operator) from the client. */
665 #define ClearOper(x) ClrFlag(x, FLAG_OPER)
666 /** Clear the client's pending UDP ping flag. */
667 #define ClearUPing(x) ClrFlag(x, FLAG_UPING)
668 /** Remove mode +w (wallops) from the client. */
669 #define ClearWallops(x) ClrFlag(x, FLAG_WALLOP)
670 /** Remove mode +s (server notices) from the client. */
671 #define ClearServNotice(x) ClrFlag(x, FLAG_SERVNOTICE)
672 /** Remove mode +x (hidden host) from the client. */
673 #define ClearHiddenHost(x) ClrFlag(x, FLAG_HIDDENHOST)
674 /** Remove mode +S (SSL Connection) from the client. */
675 #define ClearSSLConn(x) ClrFlag(x, FLAG_SSLCONN)
676 /** Clear the client's pending PING flag. */
677 #define ClearPingSent(x) ClrFlag(x, FLAG_PINGSENT)
678 /** Clear the client's HUB flag. */
679 #define ClearHub(x) ClrFlag(x, FLAG_HUB)
682 #define FREEFLAG_SOCKET 0x0001 /**< socket needs to be freed */
683 #define FREEFLAG_TIMER 0x0002 /**< timer needs to be freed */
685 /* server notice stuff */
687 #define SNO_ADD 1 /**< Perform "or" on server notice mask. */
688 #define SNO_DEL 2 /**< Perform "and ~x" on server notice mask. */
689 #define SNO_SET 3 /**< Set server notice mask. */
690 /* DON'T CHANGE THESE VALUES ! */
691 /* THE CLIENTS DEPEND ON IT ! */
692 #define SNO_OLDSNO 0x1 /**< unsorted old messages */
693 #define SNO_SERVKILL 0x2 /**< server kills (nick collisions) */
694 #define SNO_OPERKILL 0x4 /**< oper kills */
695 #define SNO_HACK2 0x8 /**< desyncs */
696 #define SNO_HACK3 0x10 /**< temporary desyncs */
697 #define SNO_UNAUTH 0x20 /**< unauthorized connections */
698 #define SNO_TCPCOMMON 0x40 /**< common TCP or socket errors */
699 #define SNO_TOOMANY 0x80 /**< too many connections */
700 #define SNO_HACK4 0x100 /**< Uworld actions on channels */
701 #define SNO_GLINE 0x200 /**< glines */
702 #define SNO_NETWORK 0x400 /**< net join/break, etc */
703 #define SNO_IPMISMATCH 0x800 /**< IP mismatches */
704 #define SNO_THROTTLE 0x1000 /**< host throttle add/remove notices */
705 #define SNO_OLDREALOP 0x2000 /**< old oper-only messages */
706 #define SNO_CONNEXIT 0x4000 /**< client connect/exit (ugh) */
707 #define SNO_AUTO 0x8000 /**< AUTO G-Lines */
708 #define SNO_DEBUG 0x10000 /**< debugging messages (DEBUGMODE only) */
709 #define SNO_AUTH 0x20000 /**< IAuth notices */
711 /** Bitmask of all valid server notice bits. */
713 # define SNO_ALL 0x3ffff
715 # define SNO_ALL 0x2ffff
718 /** Server notice bits allowed to normal users. */
719 #define SNO_USER (SNO_ALL & ~SNO_OPER)
721 /** Server notice bits enabled by default for normal users. */
722 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
723 /** Server notice bits enabled by default for IRC operators. */
724 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
725 /** Server notice bits reserved to IRC operators. */
726 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP|SNO_AUTH)
727 /** Noisy server notice bits that cause other bits to be cleared during connect. */
728 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
730 /** Test whether a privilege has been granted to a client. */
731 #define HasPriv(cli, priv) client_get_priv(cli, priv)
732 /** Grant a privilege to a client. */
733 #define SetPriv(cli, priv) FlagSet(cli_privs(cli), priv)
734 /** Revoke a privilege from a client. */
735 #define ClrPriv(cli, priv) FlagClr(cli_privs(cli), priv)
737 /** Test whether a client has a capability */
738 #define HasCap(cli, cap) CapHas(cli_capab(cli), (cap))
739 /** Test whether a client has the capability active */
740 #define CapActive(cli, cap) CapHas(cli_active(cli), (cap))
742 #define HIDE_IP 0 /**< Do not show IP address in get_client_name() */
743 #define SHOW_IP 1 /**< Show ident and IP address in get_client_name() */
745 extern const char* get_client_name(const struct Client* sptr, int showip);
746 extern const char* client_get_default_umode(const struct Client* sptr);
747 extern int client_get_ping(const struct Client* local_client);
748 extern void client_drop_sendq(struct Connection* con);
749 extern void client_add_sendq(struct Connection* con,
750 struct Connection** con_p);
751 extern void client_set_privs(struct Client *client, struct ConfItem *oper);
752 extern int client_report_privs(struct Client* to, struct Client* client);
754 extern int client_get_priv(struct Client* client, enum Priv priv);
756 #endif /* INCLUDED_client_h */