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