]> jfr.im git - irc/quakenet/snircd.git/blame - include/client.h
forward port of asuka-kX.patch to .12
[irc/quakenet/snircd.git] / include / client.h
CommitLineData
189935b1 1/*
2 * IRC - Internet Relay Chat, include/client.h
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 *
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)
9 * any later version.
10 *
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.
15 *
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.
19 */
20/** @file
21 * @brief Structures and functions for handling local clients.
22 * @version $Id: client.h,v 1.48 2005/06/27 13:25:51 entrope Exp $
23 */
24#ifndef INCLUDED_client_h
25#define INCLUDED_client_h
26#ifndef INCLUDED_ircd_defs_h
27#include "ircd_defs.h"
28#endif
29#ifndef INCLUDED_dbuf_h
30#include "dbuf.h"
31#endif
32#ifndef INCLUDED_msgq_h
33#include "msgq.h"
34#endif
35#ifndef INCLUDED_ircd_events_h
36#include "ircd_events.h"
37#endif
38#ifndef INCLUDED_ircd_handler_h
39#include "ircd_handler.h"
40#endif
41#ifndef INCLUDED_res_h
42#include "res.h"
43#endif
44#ifndef INCLUDED_sys_types_h
45#include <sys/types.h> /* time_t, size_t */
46#define INCLUDED_sys_types_h
47#endif
48
49struct ConfItem;
50struct Listener;
51struct ListingArgs;
52struct SLink;
53struct Server;
54struct User;
55struct Whowas;
56struct hostent;
57struct Privs;
58struct AuthRequest;
59
60/*
61 * Structures
62 *
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).
66 */
67
68/** Single element in a flag bitset array. */
69typedef unsigned long flagpage_t;
70
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))
77
78/** Declare a flagset structure of a particular size. */
79#define DECLARE_FLAGSET(name,max) \
80 struct name \
81 { \
82 unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \
83 }
84
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))
91
92/** String containing valid user modes, in no particular order. */
943fcf70 93#define infousermodes "dioswkgxRXIn"
189935b1 94
95/** Operator privileges. */
96enum Priv
97 {
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_LAST_PRIV /**< number of privileges */
130 };
131
132/** Client flags and modes.
133 * Note that flags at least FLAG_LOCAL_UMODES but less than
134 * FLAG_GLOBAL_UMODES are treated as local modes, and flags at least
135 * FLAG_GLOBAL_UMODES (but less than FLAG_LAST_FLAG) are treated as
136 * global modes.
137 */
138enum Flag
139 {
140 FLAG_PINGSENT, /**< Unreplied ping sent */
141 FLAG_DEADSOCKET, /**< Local socket is dead--Exiting soon */
142 FLAG_KILLED, /**< Prevents "QUIT" from being sent for this */
143 FLAG_BLOCKED, /**< socket is in a blocked condition */
144 FLAG_CLOSING, /**< set when closing to suppress errors */
145 FLAG_UPING, /**< has active UDP ping request */
146 FLAG_HUB, /**< server is a hub */
147 FLAG_IPV6, /**< server understands P10 IPv6 addrs */
148 FLAG_SERVICE, /**< server is a service */
149 FLAG_GOTID, /**< successful ident lookup achieved */
150 FLAG_DOID, /**< I-lines say must use ident return */
151 FLAG_NONL, /**< No \n in buffer */
152 FLAG_TS8, /**< Why do you want to know? */
153 FLAG_MAP, /**< Show server on the map */
154 FLAG_JUNCTION, /**< Junction causing the net.burst. */
155 FLAG_BURST, /**< Server is receiving a net.burst */
156 FLAG_BURST_ACK, /**< Server is waiting for eob ack */
157 FLAG_IPCHECK, /**< Added or updated IPregistry data */
158 FLAG_IAUTHED, /**< Got IAUTH response for user */
159 FLAG_LOCOP, /**< Local operator -- SRB */
160 FLAG_SERVNOTICE, /**< server notices such as kill */
161 FLAG_OPER, /**< Operator */
162 FLAG_INVISIBLE, /**< makes user invisible */
163 FLAG_WALLOP, /**< send wallops to them */
164 FLAG_DEAF, /**< Makes user deaf */
165 FLAG_CHSERV, /**< Disallow KICK or MODE -o on the user;
166 don't display channels in /whois */
167 FLAG_DEBUG, /**< send global debug/anti-hack info */
168 FLAG_ACCOUNT, /**< account name has been set */
08d23967 169 FLAG_ACCOUNTONLY, /**< ASUKA_R: hide privmsgs/notices if
170 user is not authed or opered */
189935b1 171 FLAG_HIDDENHOST, /**< user's host is hidden */
943fcf70 172 FLAG_NOCHAN, /**< user's channels are hidden */
173 FLAG_NOIDLE, /**< user's idletime is hidden */
174 FLAG_XTRAOP, /**< oper has special powers */
175
189935b1 176 FLAG_LAST_FLAG, /**< number of flags */
177 FLAG_LOCAL_UMODES = FLAG_LOCOP, /**< First local mode flag */
178 FLAG_GLOBAL_UMODES = FLAG_OPER /**< First global mode flag */
179 };
180
181/** Declare flagset type for operator privileges. */
182DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV);
183/** Declare flagset type for user flags. */
184DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG);
185
186#include "capab.h" /* client capabilities */
187
188/** Represents a local connection.
189 * This contains a lot of stuff irrelevant to server connections, but
190 * those are so rare as to not be worth special-casing.
191 */
192struct Connection
193{
194 unsigned long con_magic; /**< magic number */
195 struct Connection* con_next; /**< Next connection with queued data */
196 struct Connection** con_prev_p; /**< What points to us */
197 struct Client* con_client; /**< Client associated with connection */
198 unsigned int con_count; /**< Amount of data in buffer */
199 int con_freeflag; /**< indicates if connection can be freed */
200 int con_error; /**< last socket level error for client */
201 int con_sentalong; /**< sentalong marker for connection */
202 unsigned int con_snomask; /**< mask for server messages */
203 time_t con_nextnick; /**< Next time a nick change is allowed */
204 time_t con_nexttarget;/**< Next time a target change is allowed */
205 time_t con_lasttime; /**< Last time data read from socket */
206 time_t con_since; /**< Last time we accepted a command */
207 unsigned int con_cookie; /**< Random number the user must PONG */
208 struct MsgQ con_sendQ; /**< Outgoing message queue */
209 struct DBuf con_recvQ; /**< Incoming data yet to be parsed */
210 unsigned int con_sendM; /**< Stats: protocol messages sent */
211 unsigned int con_receiveM; /**< Stats: protocol messages received */
212 uint64_t con_sendB; /**< Bytes sent. */
213 uint64_t con_receiveB; /**< Bytes received. */
214 struct Listener* con_listener; /**< Listening socket which we accepted
215 from. */
216 struct SLink* con_confs; /**< Associated configuration records. */
217 HandlerType con_handler; /**< Message index into command table
218 for parsing. */
219 struct ListingArgs* con_listing; /**< Current LIST status. */
220 unsigned long con_unreg; /**< Indicate what still needs to be done */
221 unsigned int con_max_sendq; /**< cached max send queue for client */
222 unsigned int con_ping_freq; /**< cached ping freq */
223 unsigned short con_lastsq; /**< # 2k blocks when sendqueued
224 called last. */
225 unsigned char con_targets[MAXTARGETS]; /**< Hash values of
226 current targets. */
227 char con_sock_ip[SOCKIPLEN + 1]; /**< Remote IP address as a string. */
228 char con_sockhost[HOSTLEN + 1]; /**< This is the host name from
229 the socket and after which the
230 connection was accepted. */
231 char con_passwd[PASSWDLEN + 1]; /**< Password given by user. */
232 char con_buffer[BUFSIZE]; /**< Incoming message buffer; or
233 the error that caused this
234 clients socket to close. */
235 struct Socket con_socket; /**< socket descriptor for
236 client */
237 struct Timer con_proc; /**< process latent messages from
238 client */
239 struct Privs con_privs; /**< Oper privileges */
240 struct CapSet con_capab; /**< Client capabilities (from us) */
241 struct CapSet con_active; /**< Active capabilities (to us) */
242 struct AuthRequest* con_auth; /**< auth request for client */
243 struct IAuthRequest* con_iauth; /**< iauth request for client */
244};
245
246/** Magic constant to identify valid Connection structures. */
247#define CONNECTION_MAGIC 0x12f955f3
248
249/** Represents a client anywhere on the network. */
250struct Client {
251 unsigned long cli_magic; /**< magic number */
252 struct Client* cli_next; /**< link in GlobalClientList */
253 struct Client* cli_prev; /**< link in GlobalClientList */
254 struct Client* cli_hnext; /**< link in hash table bucket or this */
255 struct Connection* cli_connect; /**< Connection structure associated with us */
256 struct User* cli_user; /**< Defined if this client is a user */
257 struct Server* cli_serv; /**< Defined if this client is a server */
258 struct Whowas* cli_whowas; /**< Pointer to ww struct to be freed on quit */
259 char cli_yxx[4]; /**< Numeric Nick: YY if this is a
260 server, XXX if this is a user */
261 time_t cli_firsttime; /**< time client was created */
262 time_t cli_lastnick; /**< TimeStamp on nick */
263 int cli_marker; /**< /who processing marker */
264 struct Flags cli_flags; /**< client flags */
265 unsigned int cli_hopcount; /**< number of servers to this 0 = local */
266 struct irc_in_addr cli_ip; /**< Real IP of client */
267 short cli_status; /**< Client type */
268 char cli_name[HOSTLEN + 1]; /**< Unique name of the client, nick or host */
269 char cli_username[USERLEN + 1]; /**< Username determined by ident lookup */
270 char cli_info[REALLEN + 1]; /**< Free form additional client information */
271};
272
273#define CLIREG_NICK 0x0001 /**< Client must set nickname */
274#define CLIREG_USER 0x0002 /**< Client must set username */
275#define CLIREG_COOKIE 0x0004 /**< Client must return cookie */
276#define CLIREG_CAP 0x0008 /**< Client in capability negotiation */
277
278#define CLIREG_INIT (CLIREG_NICK | CLIREG_USER | CLIREG_COOKIE)
279
280/** Magic constant to identify valid Client structures. */
281#define CLIENT_MAGIC 0x4ca08286
282
283/** Verify that a client is valid. */
284#define cli_verify(cli) ((cli)->cli_magic == CLIENT_MAGIC)
285/** Get client's magic number. */
286#define cli_magic(cli) ((cli)->cli_magic)
287/** Get global next client. */
288#define cli_next(cli) ((cli)->cli_next)
289/** Get global previous client. */
290#define cli_prev(cli) ((cli)->cli_prev)
291/** Get next client in hash bucket chain. */
292#define cli_hnext(cli) ((cli)->cli_hnext)
293/** Get connection associated with client. */
294#define cli_connect(cli) ((cli)->cli_connect)
295/** Get local client that links us to \a cli. */
296#define cli_from(cli) con_client(cli_connect(cli))
297/** Get User structure for client, if client is a user. */
298#define cli_user(cli) ((cli)->cli_user)
299/** Get Server structure for client, if client is a server. */
300#define cli_serv(cli) ((cli)->cli_serv)
301/** Get Whowas link for client. */
302#define cli_whowas(cli) ((cli)->cli_whowas)
303/** Get client numnick. */
304#define cli_yxx(cli) ((cli)->cli_yxx)
305/** Get time we last read data from the client socket. */
306#define cli_lasttime(cli) con_lasttime(cli_connect(cli))
307/** Get time we last parsed something from the client. */
308#define cli_since(cli) con_since(cli_connect(cli))
309/** Get time client was created. */
310#define cli_firsttime(cli) ((cli)->cli_firsttime)
311/** Get time client last changed nickname. */
312#define cli_lastnick(cli) ((cli)->cli_lastnick)
313/** Get WHO marker for client. */
314#define cli_marker(cli) ((cli)->cli_marker)
315/** Get flags flagset for client. */
316#define cli_flags(cli) ((cli)->cli_flags)
317/** Get hop count to client. */
318#define cli_hopcount(cli) ((cli)->cli_hopcount)
319/** Get client IP address. */
320#define cli_ip(cli) ((cli)->cli_ip)
321/** Get status bitmask for client. */
322#define cli_status(cli) ((cli)->cli_status)
323/** Return non-zero if the client is local. */
324#define cli_local(cli) (cli_from(cli) == cli)
325/** Get oper privileges for client. */
326#define cli_privs(cli) con_privs(cli_connect(cli))
327/** Get client capabilities for client */
328#define cli_capab(cli) con_capab(cli_connect(cli))
329/** Get active client capabilities for client */
330#define cli_active(cli) con_active(cli_connect(cli))
331/** Get flags for remaining registration tasks */
332#define cli_unreg(cli) con_unreg(cli_connect(cli))
333/** Get client name. */
334#define cli_name(cli) ((cli)->cli_name)
335/** Get client username (ident). */
336#define cli_username(cli) ((cli)->cli_username)
337/** Get client realname (information field). */
338#define cli_info(cli) ((cli)->cli_info)
339
340/** Get number of incoming bytes queued for client. */
341#define cli_count(cli) con_count(cli_connect(cli))
342/** Get file descriptor for sending in client's direction. */
343#define cli_fd(cli) con_fd(cli_connect(cli))
344/** Get free flags for the client's connection. */
345#define cli_freeflag(cli) con_freeflag(cli_connect(cli))
346/** Get last error code for the client's connection. */
347#define cli_error(cli) con_error(cli_connect(cli))
348/** Get server notice mask for the client. */
349#define cli_snomask(cli) con_snomask(cli_connect(cli))
350/** Get next time a nick change is allowed for the client. */
351#define cli_nextnick(cli) con_nextnick(cli_connect(cli))
352/** Get next time a target change is allowed for the client. */
353#define cli_nexttarget(cli) con_nexttarget(cli_connect(cli))
354/** Get required PING/PONG cookie for client. */
355#define cli_cookie(cli) con_cookie(cli_connect(cli))
356/** Get SendQ for client. */
357#define cli_sendQ(cli) con_sendQ(cli_connect(cli))
358/** Get RecvQ for client. */
359#define cli_recvQ(cli) con_recvQ(cli_connect(cli))
360/** Get count of messages sent to client. */
361#define cli_sendM(cli) con_sendM(cli_connect(cli))
362/** Get number of messages received from client. */
363#define cli_receiveM(cli) con_receiveM(cli_connect(cli))
364/** Get number of bytes (modulo 1024) sent to client. */
365#define cli_sendB(cli) con_sendB(cli_connect(cli))
366/** Get number of bytes (modulo 1024) received from client. */
367#define cli_receiveB(cli) con_receiveB(cli_connect(cli))
368/** Get listener that accepted the client's connection. */
369#define cli_listener(cli) con_listener(cli_connect(cli))
370/** Get list of attached conf lines. */
371#define cli_confs(cli) con_confs(cli_connect(cli))
372/** Get handler type for client. */
373#define cli_handler(cli) con_handler(cli_connect(cli))
374/** Get LIST status for client. */
375#define cli_listing(cli) con_listing(cli_connect(cli))
376/** Get cached max SendQ for client. */
377#define cli_max_sendq(cli) con_max_sendq(cli_connect(cli))
378/** Get ping frequency for client. */
379#define cli_ping_freq(cli) con_ping_freq(cli_connect(cli))
380/** Get lastsq for client's connection. */
381#define cli_lastsq(cli) con_lastsq(cli_connect(cli))
382/** Get the array of current targets for the client. */
383#define cli_targets(cli) con_targets(cli_connect(cli))
384/** Get the string form of the client's IP address. */
385#define cli_sock_ip(cli) con_sock_ip(cli_connect(cli))
386/** Get the resolved hostname for the client. */
387#define cli_sockhost(cli) con_sockhost(cli_connect(cli))
388/** Get the client's password. */
389#define cli_passwd(cli) con_passwd(cli_connect(cli))
390/** Get the unprocessed input buffer for a client's connection. */
391#define cli_buffer(cli) con_buffer(cli_connect(cli))
392/** Get the Socket structure for sending to a client. */
393#define cli_socket(cli) con_socket(cli_connect(cli))
394/** Get Timer for processing waiting messages from the client. */
395#define cli_proc(cli) con_proc(cli_connect(cli))
396/** Get auth request for client. */
397#define cli_auth(cli) con_auth(cli_connect(cli))
398/** Get iauth request for client. */
399#define cli_iauth(cli) con_iauth(cli_connect(cli))
400/** Get sentalong marker for client. */
401#define cli_sentalong(cli) con_sentalong(cli_connect(cli))
402
403/** Verify that a connection is valid. */
404#define con_verify(con) ((con)->con_magic == CONNECTION_MAGIC)
405/** Get connection's magic number. */
406#define con_magic(con) ((con)->con_magic)
407/** Get global next connection. */
408#define con_next(con) ((con)->con_next)
409/** Get global previous connection. */
410#define con_prev_p(con) ((con)->con_prev_p)
411/** Get locally connected client for connection. */
412#define con_client(con) ((con)->con_client)
413/** Get number of unprocessed data bytes from connection. */
414#define con_count(con) ((con)->con_count)
415/** Get file descriptor for connection. */
416#define con_fd(con) s_fd(&(con)->con_socket)
417/** Get freeable flags for connection. */
418#define con_freeflag(con) ((con)->con_freeflag)
419/** Get last error code on connection. */
420#define con_error(con) ((con)->con_error)
421/** Get sentalong marker for connection. */
422#define con_sentalong(con) ((con)->con_sentalong)
423/** Get server notice mask for connection. */
424#define con_snomask(con) ((con)->con_snomask)
425/** Get next nick change time for connection. */
426#define con_nextnick(con) ((con)->con_nextnick)
427/** Get next new target time for connection. */
428#define con_nexttarget(con) ((con)->con_nexttarget)
429/** Get last time we read from the connection. */
430#define con_lasttime(con) ((con)->con_lasttime)
431/** Get last time we accepted a command from the connection. */
432#define con_since(con) ((con)->con_since)
433/** Get PING/PONG confirmation cookie for connection. */
434#define con_cookie(con) ((con)->con_cookie)
435/** Get SendQ for connection. */
436#define con_sendQ(con) ((con)->con_sendQ)
437/** Get RecvQ for connection. */
438#define con_recvQ(con) ((con)->con_recvQ)
439/** Get number of messages sent to connection. */
440#define con_sendM(con) ((con)->con_sendM)
441/** Get number of messages received from connection. */
442#define con_receiveM(con) ((con)->con_receiveM)
443/** Get number of bytes (modulo 1024) sent to connection. */
444#define con_sendB(con) ((con)->con_sendB)
445/** Get number of bytes (modulo 1024) received from connection. */
446#define con_receiveB(con) ((con)->con_receiveB)
447/** Get listener that accepted the connection. */
448#define con_listener(con) ((con)->con_listener)
449/** Get list of ConfItems attached to the connection. */
450#define con_confs(con) ((con)->con_confs)
451/** Get command handler for the connection. */
452#define con_handler(con) ((con)->con_handler)
453/** Get the LIST status for the connection. */
454#define con_listing(con) ((con)->con_listing)
455/** Get remining steps before registration completes. */
456#define con_unreg(con) ((con)->con_unreg)
457/** Get the maximum permitted SendQ size for the connection. */
458#define con_max_sendq(con) ((con)->con_max_sendq)
459/** Get the ping frequency for the connection. */
460#define con_ping_freq(con) ((con)->con_ping_freq)
461/** Get the lastsq for the connection. */
462#define con_lastsq(con) ((con)->con_lastsq)
463/** Get the current targets array for the connection. */
464#define con_targets(con) ((con)->con_targets)
465/** Get the string-formatted IP address for the connection. */
466#define con_sock_ip(con) ((con)->con_sock_ip)
467/** Get the resolved hostname for the connection. */
468#define con_sockhost(con) ((con)->con_sockhost)
469/** Get the password sent by the remote end of the connection. */
470#define con_passwd(con) ((con)->con_passwd)
471/** Get the buffer of unprocessed incoming data from the connection. */
472#define con_buffer(con) ((con)->con_buffer)
473/** Get the Socket for the connection. */
474#define con_socket(con) ((con)->con_socket)
475/** Get the Timer for processing more data from the connection. */
476#define con_proc(con) ((con)->con_proc)
477/** Get the oper privilege set for the connection. */
478#define con_privs(con) (&(con)->con_privs)
479/** Get the peer's capabilities for the connection. */
480#define con_capab(con) (&(con)->con_capab)
481/** Get the active capabilities for the connection. */
482#define con_active(con) (&(con)->con_active)
483/** Get the auth request for the connection. */
484#define con_auth(con) ((con)->con_auth)
485/** Get the iauth request for the connection. */
486#define con_iauth(con) ((con)->con_iauth)
487
488#define STAT_CONNECTING 0x001 /**< connecting to another server */
489#define STAT_HANDSHAKE 0x002 /**< pass - server sent */
490#define STAT_ME 0x004 /**< this server */
491#define STAT_UNKNOWN 0x008 /**< unidentified connection */
492#define STAT_UNKNOWN_USER 0x010 /**< connection on a client port */
493#define STAT_UNKNOWN_SERVER 0x020 /**< connection on a server port */
494#define STAT_SERVER 0x040 /**< fully registered server */
495#define STAT_USER 0x080 /**< fully registered user */
496
497/*
498 * status macros.
499 */
500/** Return non-zero if the client is registered. */
501#define IsRegistered(x) (cli_status(x) & (STAT_SERVER | STAT_USER))
502/** Return non-zero if the client is an outbound connection that is
503 * still connecting. */
504#define IsConnecting(x) (cli_status(x) == STAT_CONNECTING)
505/** Return non-zero if the client is an outbound connection that has
506 * sent our password. */
507#define IsHandshake(x) (cli_status(x) == STAT_HANDSHAKE)
508/** Return non-zero if the client is this server. */
509#define IsMe(x) (cli_status(x) == STAT_ME)
510/** Return non-zero if the client has not yet registered. */
511#define IsUnknown(x) (cli_status(x) & \
512 (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
513/** Return non-zero if the client is an unregistered connection on a
514 * server port. */
515#define IsServerPort(x) (cli_status(x) == STAT_UNKNOWN_SERVER )
516/** Return non-zero if the client is an unregistered connection on a
517 * user port. */
518#define IsUserPort(x) (cli_status(x) == STAT_UNKNOWN_USER )
519/** Return non-zero if the client is a real client connection. */
520#define IsClient(x) (cli_status(x) & \
521 (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
522 STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
523/** Return non-zero if the client ignores flood limits. */
524#define IsTrusted(x) (cli_status(x) & \
525 (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
526/** Return non-zero if the client is a registered server. */
527#define IsServer(x) (cli_status(x) == STAT_SERVER)
528/** Return non-zero if the client is a registered user. */
529#define IsUser(x) (cli_status(x) == STAT_USER)
530
531
532/** Mark a client with STAT_CONNECTING. */
533#define SetConnecting(x) (cli_status(x) = STAT_CONNECTING)
534/** Mark a client with STAT_HANDSHAKE. */
535#define SetHandshake(x) (cli_status(x) = STAT_HANDSHAKE)
536/** Mark a client with STAT_SERVER. */
537#define SetServer(x) (cli_status(x) = STAT_SERVER)
538/** Mark a client with STAT_ME. */
539#define SetMe(x) (cli_status(x) = STAT_ME)
540/** Mark a client with STAT_USER. */
541#define SetUser(x) (cli_status(x) = STAT_USER)
542
543/** Return non-zero if a client is directly connected to me. */
544#define MyConnect(x) (cli_from(x) == (x))
545/** Return non-zero if a client is a locally connected user. */
546#define MyUser(x) (MyConnect(x) && IsUser(x))
547/** Return non-zero if a client is a locally connected IRC operator. */
548#define MyOper(x) (MyConnect(x) && IsOper(x))
549/** Return protocol version used by a server. */
550#define Protocol(x) ((cli_serv(x))->prot)
551
552/*
553 * flags macros
554 */
555/** Set a flag in a client's flags. */
556#define SetFlag(cli, flag) FlagSet(&cli_flags(cli), flag)
557/** Clear a flag from a client's flags. */
558#define ClrFlag(cli, flag) FlagClr(&cli_flags(cli), flag)
559/** Return non-zero if a flag is set in a client's flags. */
560#define HasFlag(cli, flag) FlagHas(&cli_flags(cli), flag)
561
562/** Return non-zero if the client is an IRC operator (global or local). */
563#define IsAnOper(x) (HasFlag(x, FLAG_OPER) || HasFlag(x, FLAG_LOCOP))
564/** Return non-zero if the client's connection is blocked. */
565#define IsBlocked(x) HasFlag(x, FLAG_BLOCKED)
566/** Return non-zero if the client's connection is still being burst. */
567#define IsBurst(x) HasFlag(x, FLAG_BURST)
568/** Return non-zero if we have received the peer's entire burst but
569 * not their EOB ack. */
570#define IsBurstAck(x) HasFlag(x, FLAG_BURST_ACK)
571/** Return non-zero if we are still bursting to the client. */
572#define IsBurstOrBurstAck(x) (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK))
573/** Return non-zero if the client has set mode +k (channel service). */
574#define IsChannelService(x) HasFlag(x, FLAG_CHSERV)
575/** Return non-zero if the client's socket is disconnected. */
576#define IsDead(x) HasFlag(x, FLAG_DEADSOCKET)
577/** Return non-zero if the client has set mode +d (deaf). */
578#define IsDeaf(x) HasFlag(x, FLAG_DEAF)
579/** Return non-zero if the client has been IP-checked for clones. */
580#define IsIPChecked(x) HasFlag(x, FLAG_IPCHECK)
581/** Return non-zero if the client has been okayed by iauth. */
582#define IsIAuthed(x) HasFlag(x, FLAG_IAUTHED)
583/** Return non-zero if we have received an ident response for the client. */
584#define IsIdented(x) HasFlag(x, FLAG_GOTID)
585/** Return non-zero if the client has set mode +i (invisible). */
586#define IsInvisible(x) HasFlag(x, FLAG_INVISIBLE)
587/** Return non-zero if the client caused a net.burst. */
588#define IsJunction(x) HasFlag(x, FLAG_JUNCTION)
589/** Return non-zero if the client has set mode +O (local operator). */
590#define IsLocOp(x) HasFlag(x, FLAG_LOCOP)
591/** Return non-zero if the client has set mode +o (global operator). */
592#define IsOper(x) HasFlag(x, FLAG_OPER)
593/** Return non-zero if the client has an active UDP ping request. */
594#define IsUPing(x) HasFlag(x, FLAG_UPING)
595/** Return non-zero if the client has no '\n' in its buffer. */
596#define NoNewLine(x) HasFlag(x, FLAG_NONL)
597/** Return non-zero if the client has set mode +g (debugging). */
598#define SendDebug(x) HasFlag(x, FLAG_DEBUG)
599/** Return non-zero if the client has set mode +s (server notices). */
600#define SendServNotice(x) HasFlag(x, FLAG_SERVNOTICE)
601/** Return non-zero if the client has set mode +w (wallops). */
602#define SendWallops(x) HasFlag(x, FLAG_WALLOP)
603/** Return non-zero if the client claims to be a hub. */
604#define IsHub(x) HasFlag(x, FLAG_HUB)
605/** Return non-zero if the client understands IPv6 addresses in P10. */
606#define IsIPv6(x) HasFlag(x, FLAG_IPV6)
607/** Return non-zero if the client claims to be a services server. */
608#define IsService(x) HasFlag(x, FLAG_SERVICE)
609/** Return non-zero if the client has an account stamp. */
610#define IsAccount(x) HasFlag(x, FLAG_ACCOUNT)
611/** Return non-zero if the client has set mode +x (hidden host). */
612#define IsHiddenHost(x) HasFlag(x, FLAG_HIDDENHOST)
943fcf70 613/** Return non-zero if the client has set mode +X (xtraop) */
614#define IsXtraOp(x) HasFlag(x, FLAG_XTRAOP)
615/** Return non-zero if the client has set mode +n (hide channels) */
616#define IsNoChan(x) HasFlag(x, FLAG_NOCHAN)
617/** Return non-zero if the client has set mode +I (hide idletime) */
618#define IsNoIdle(x) HasFlag(x, FLAG_NOIDLE)
189935b1 619/** Return non-zero if the client has an active PING request. */
620#define IsPingSent(x) HasFlag(x, FLAG_PINGSENT)
08d23967 621/** Return non-zero if the client should not receive privmsgs/notices
622 * from unauthed users */
623#define IsAccountOnly(x) HasFlag(x, FLAG_ACCOUNTONLY)
189935b1 624
625/** Return non-zero if the client has operator or server privileges. */
626#define IsPrivileged(x) (IsAnOper(x) || IsServer(x))
627/** Return non-zero if the client's host is hidden. */
628#define HasHiddenHost(x) (IsHiddenHost(x) && IsAccount(x))
629
630/** Mark a client as having an in-progress net.burst. */
631#define SetBurst(x) SetFlag(x, FLAG_BURST)
632/** Mark a client as being between EOB and EOB ACK. */
633#define SetBurstAck(x) SetFlag(x, FLAG_BURST_ACK)
634/** Mark a client as having mode +k (channel service). */
635#define SetChannelService(x) SetFlag(x, FLAG_CHSERV)
636/** Mark a client as having mode +d (deaf). */
637#define SetDeaf(x) SetFlag(x, FLAG_DEAF)
638/** Mark a client as having mode +g (debugging). */
639#define SetDebug(x) SetFlag(x, FLAG_DEBUG)
640/** Mark a client as having ident looked up. */
641#define SetGotId(x) SetFlag(x, FLAG_GOTID)
642/** Mark a client as being IP-checked. */
643#define SetIPChecked(x) SetFlag(x, FLAG_IPCHECK)
644/** Mark a client as being iauth-checked. */
645#define SetIAuthed(x) SetFlag(x, FLAG_IAUTHED)
646/** Mark a client as having mode +i (invisible). */
647#define SetInvisible(x) SetFlag(x, FLAG_INVISIBLE)
648/** Mark a client as causing a net.join. */
649#define SetJunction(x) SetFlag(x, FLAG_JUNCTION)
650/** Mark a client as having mode +O (local operator). */
651#define SetLocOp(x) SetFlag(x, FLAG_LOCOP)
652/** Mark a client as having mode +o (global operator). */
653#define SetOper(x) SetFlag(x, FLAG_OPER)
654/** Mark a client as having a pending UDP ping. */
655#define SetUPing(x) SetFlag(x, FLAG_UPING)
656/** Mark a client as having mode +w (wallops). */
657#define SetWallops(x) SetFlag(x, FLAG_WALLOP)
658/** Mark a client as having mode +s (server notices). */
659#define SetServNotice(x) SetFlag(x, FLAG_SERVNOTICE)
660/** Mark a client as being a hub server. */
661#define SetHub(x) SetFlag(x, FLAG_HUB)
662/** Mark a client as being an IPv6-grokking server. */
663#define SetIPv6(x) SetFlag(x, FLAG_IPV6)
664/** Mark a client as being a services server. */
665#define SetService(x) SetFlag(x, FLAG_SERVICE)
666/** Mark a client as having an account stamp. */
667#define SetAccount(x) SetFlag(x, FLAG_ACCOUNT)
668/** Mark a client as having mode +x (hidden host). */
669#define SetHiddenHost(x) SetFlag(x, FLAG_HIDDENHOST)
943fcf70 670/** Mark a client as having mode +X (xtraop). */
671#define SetXtraOp(x) SetFlag(x, FLAG_XTRAOP)
672/** Mark a client as having mode +n (hide channels). */
673#define SetNoChan(x) SetFlag(x, FLAG_NOCHAN)
674/** Mark a client as having mode +I (hide idletime). */
675#define SetNoIdle(x) SetFlag(x, FLAG_NOIDLE)
189935b1 676/** Mark a client as having a pending PING. */
677#define SetPingSent(x) SetFlag(x, FLAG_PINGSENT)
08d23967 678/** Mark a client as having mode +R (account only). */
679#define SetAccountOnly(x) SetFlag(x, FLAG_ACCOUNTONLY)
189935b1 680
681/** Return non-zero if \a sptr sees \a acptr as an operator. */
682#define SeeOper(sptr,acptr) (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) \
683 || HasPriv(sptr, PRIV_SEE_OPERS)))
684
685/** Clear the client's net.burst in-progress flag. */
686#define ClearBurst(x) ClrFlag(x, FLAG_BURST)
687/** Clear the client's between EOB and EOB ACK flag. */
688#define ClearBurstAck(x) ClrFlag(x, FLAG_BURST_ACK)
689/** Remove mode +k (channel service) from the client. */
690#define ClearChannelService(x) ClrFlag(x, FLAG_CHSERV)
691/** Remove mode +d (deaf) from the client. */
692#define ClearDeaf(x) ClrFlag(x, FLAG_DEAF)
693/** Remove mode +g (debugging) from the client. */
694#define ClearDebug(x) ClrFlag(x, FLAG_DEBUG)
695/** Remove the client's IP-checked flag. */
696#define ClearIPChecked(x) ClrFlag(x, FLAG_IPCHECK)
697/** Remove mode +i (invisible) from the client. */
698#define ClearInvisible(x) ClrFlag(x, FLAG_INVISIBLE)
699/** Remove mode +O (local operator) from the client. */
700#define ClearLocOp(x) ClrFlag(x, FLAG_LOCOP)
701/** Remove mode +o (global operator) from the client. */
702#define ClearOper(x) ClrFlag(x, FLAG_OPER)
703/** Clear the client's pending UDP ping flag. */
704#define ClearUPing(x) ClrFlag(x, FLAG_UPING)
705/** Remove mode +w (wallops) from the client. */
706#define ClearWallops(x) ClrFlag(x, FLAG_WALLOP)
707/** Remove mode +s (server notices) from the client. */
708#define ClearServNotice(x) ClrFlag(x, FLAG_SERVNOTICE)
709/** Remove mode +x (hidden host) from the client. */
710#define ClearHiddenHost(x) ClrFlag(x, FLAG_HIDDENHOST)
943fcf70 711/** Remove mode +X (xtraop) from a client. */
712#define ClearXtraOp(x) ClrFlag(x, FLAG_XTRAOP)
713/** Remove mode +n (hide channels) from a client. */
714#define ClearNoChan(x) ClrFlag(x, FLAG_NOCHAN)
715/** Remove mode +I (hide idletime) from a client. */
716#define ClearNoIdle(x) ClrFlag(x, FLAG_NOIDLE)
189935b1 717/** Clear the client's pending PING flag. */
718#define ClearPingSent(x) ClrFlag(x, FLAG_PINGSENT)
08d23967 719/** Remove mode +R (account only) from a client */
720#define ClearAccountOnly(x) ClrFlag(x, FLAG_ACCOUNTONLY)
189935b1 721
722/* free flags */
723#define FREEFLAG_SOCKET 0x0001 /**< socket needs to be freed */
724#define FREEFLAG_TIMER 0x0002 /**< timer needs to be freed */
725
726/* server notice stuff */
727
728#define SNO_ADD 1 /**< Perform "or" on server notice mask. */
729#define SNO_DEL 2 /**< Perform "and ~x" on server notice mask. */
730#define SNO_SET 3 /**< Set server notice mask. */
731 /* DON'T CHANGE THESE VALUES ! */
732 /* THE CLIENTS DEPEND ON IT ! */
733#define SNO_OLDSNO 0x1 /**< unsorted old messages */
734#define SNO_SERVKILL 0x2 /**< server kills (nick collisions) */
735#define SNO_OPERKILL 0x4 /**< oper kills */
736#define SNO_HACK2 0x8 /**< desyncs */
737#define SNO_HACK3 0x10 /**< temporary desyncs */
738#define SNO_UNAUTH 0x20 /**< unauthorized connections */
739#define SNO_TCPCOMMON 0x40 /**< common TCP or socket errors */
740#define SNO_TOOMANY 0x80 /**< too many connections */
741#define SNO_HACK4 0x100 /**< Uworld actions on channels */
742#define SNO_GLINE 0x200 /**< glines */
743#define SNO_NETWORK 0x400 /**< net join/break, etc */
744#define SNO_IPMISMATCH 0x800 /**< IP mismatches */
745#define SNO_THROTTLE 0x1000 /**< host throttle add/remove notices */
746#define SNO_OLDREALOP 0x2000 /**< old oper-only messages */
747#define SNO_CONNEXIT 0x4000 /**< client connect/exit (ugh) */
748#define SNO_AUTO 0x8000 /**< AUTO G-Lines */
749#define SNO_DEBUG 0x10000 /**< debugging messages (DEBUGMODE only) */
750
751#ifdef DEBUGMODE
752# define SNO_ALL 0x1ffff /**< Bitmask of all valid server
753 * notice bits. */
754#else
755# define SNO_ALL 0xffff
756#endif
757
758/** Server notice bits allowed to normal users. */
759#define SNO_USER (SNO_ALL & ~SNO_OPER)
760
761/** Server notice bits enabled by default for normal users. */
762#define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
763/** Server notice bits enabled by default for IRC operators. */
f9a0d470 764#define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_THROTTLE|SNO_OLDSNO)
189935b1 765/** Server notice bits reserved to IRC operators. */
766#define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
767/** Noisy server notice bits that cause other bits to be cleared during connect. */
768#define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
769
770/** Test whether a privilege has been granted to a client. */
771#define HasPriv(cli, priv) FlagHas(cli_privs(cli), priv)
772/** Grant a privilege to a client. */
773#define SetPriv(cli, priv) FlagSet(cli_privs(cli), priv)
774/** Revoke a privilege from a client. */
775#define ClrPriv(cli, priv) FlagClr(cli_privs(cli), priv)
776
777/** Test whether a client has a capability */
778#define HasCap(cli, cap) CapHas(cli_capab(cli), (cap))
779/** Test whether a client has the capability active */
780#define CapActive(cli, cap) CapHas(cli_active(cli), (cap))
781
782#define HIDE_IP 0 /**< Do not show IP address in get_client_name() */
783#define SHOW_IP 1 /**< Show ident and IP address in get_client_name() */
784
785extern const char* get_client_name(const struct Client* sptr, int showip);
786extern const char* client_get_default_umode(const struct Client* sptr);
787extern int client_get_ping(const struct Client* local_client);
788extern void client_drop_sendq(struct Connection* con);
789extern void client_add_sendq(struct Connection* con,
790 struct Connection** con_p);
791extern void client_set_privs(struct Client *client, struct ConfItem *oper);
792extern int client_report_privs(struct Client* to, struct Client* client);
793
794#endif /* INCLUDED_client_h */
795