Doxyfy client.h and client.c.
[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$
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) (1<<((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 FLAGSET_ISSET(set,flag) ((set).bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag))
87 /** Set a flag in a flagset. */
88 #define FLAGSET_SET(set, flag) (set).bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag)
89 /** Clear a flag in a flagset. */
90 #define FLAGSET_CLEAR(set, flag) (set).bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag)
91
92 /** String containig valid user modes, in no particular order. */
93 #define infousermodes "dioswkgx"
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_LAST_PRIV /**< number of privileges */
129   };
130
131 /** Client flags and modes.
132  * Note that flags at least FLAG_LOCAL_UMODES but less than
133  * FLAG_GLOBAL_UMODES are treated as local modes, and flags at least
134  * FLAG_GLOBAL_UMODES (but less than FLAG_LAST_FLAG) are treated as
135  * global modes.
136  */
137 enum Flag
138   {
139     FLAG_PINGSENT,                  /**< Unreplied ping sent */
140     FLAG_DEADSOCKET,                /**< Local socket is dead--Exiting soon */
141     FLAG_KILLED,                    /**< Prevents "QUIT" from being sent for this */
142     FLAG_BLOCKED,                   /**< socket is in a blocked condition */
143     FLAG_CLOSING,                   /**< set when closing to suppress errors */
144     FLAG_UPING,                     /**< has active UDP ping request */
145     FLAG_CHKACCESS,                 /**< ok to check clients access if set
146                                      * @todo Remove (never set). */
147     FLAG_HUB,                       /**< server is a hub */
148     FLAG_SERVICE,                   /**< server is a service */
149     FLAG_LOCAL,                     /**< set for local clients
150                                      * @todo Remove (never used). */
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_IAUTHED,                   /**< Got IAUTH response for user */
161     FLAG_LOCOP,                     /**< Local operator -- SRB */
162     FLAG_SERVNOTICE,                /**< server notices such as kill */
163     FLAG_OPER,                      /**< Operator */
164     FLAG_INVISIBLE,                 /**< makes user invisible */
165     FLAG_WALLOP,                    /**< send wallops to them */
166     FLAG_DEAF,                      /**< Makes user deaf */
167     FLAG_CHSERV,                    /**< Disallow KICK or MODE -o on the user;
168                                        don't display channels in /whois */
169     FLAG_DEBUG,                     /**< send global debug/anti-hack info */
170     FLAG_ACCOUNT,                   /**< account name has been set */
171     FLAG_HIDDENHOST,                /**< user's host is hidden */
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 */
175   };
176
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);
181
182 /** Represents a local connection.
183  * This contains a lot of stuff irrelevant to server connections, but
184  * those are so rare as to not be worth special-casing.
185  */
186 struct Connection
187 {
188   unsigned long       con_magic;     /**< magic number */
189   struct Connection*  con_next;      /**< Next connection with queued data */
190   struct Connection** con_prev_p;    /**< What points to us */
191   struct Client*      con_client;    /**< Client associated with connection */
192   unsigned int        con_count;     /**< Amount of data in buffer */
193   int                 con_fd;        /**< >= 0, for local clients */
194   int                 con_freeflag;  /**< indicates if connection can be freed */
195   int                 con_error;     /**< last socket level error for client */
196   unsigned int        con_snomask;   /**< mask for server messages */
197   time_t              con_nextnick;  /**< Next time a nick change is allowed */
198   time_t              con_nexttarget;/**< Next time a target change is allowed */
199   unsigned int        con_cookie;    /**< Random number the user must PONG */
200   struct MsgQ         con_sendQ;     /**< Outgoing message queue */
201   struct DBuf         con_recvQ;     /**< Incoming data yet to be parsed */
202   unsigned int        con_sendM;     /**< Stats: protocol messages sent */
203   unsigned int        con_sendK;     /**< Stats: total k-bytes sent */
204   unsigned int        con_receiveM;  /**< Stats: protocol messages received */
205   unsigned int        con_receiveK;  /**< Stats: total k-bytes received */
206   unsigned short      con_sendB;     /**< Bytes sent, mod 1024. */
207   unsigned short      con_receiveB;  /**< Bytes received, mod 1024. */
208   struct Listener*    con_listener;  /**< Listening socket which we accepted
209                                         from. */
210   struct SLink*       con_confs;     /**< Associated configuration records. */
211   HandlerType         con_handler;   /**< Message index into command table
212                                         for parsing. */
213   struct DNSReply*    con_dns_reply; /**< DNS reply received during client
214                                         registration. */
215   struct ListingArgs* con_listing;   /**< Current LIST status. */
216   unsigned int        con_max_sendq; /**< cached max send queue for client */
217   unsigned int        con_ping_freq; /**< cached ping freq */
218   unsigned short      con_lastsq;    /**< # 2k blocks when sendqueued
219                                         called last. */
220   unsigned short      con_port;      /**< Remote port number. */
221   unsigned char       con_targets[MAXTARGETS]; /**< Hash values of
222                                                   current targets. */
223   char con_sock_ip[SOCKIPLEN + 1];   /**< Remote IP address as a string. */
224   char con_sockhost[HOSTLEN + 1];    /**< This is the host name from
225                                         the socket and after which the
226                                         connection was accepted. */
227   char con_passwd[PASSWDLEN + 1];    /**< Password given by user. */
228   char con_buffer[BUFSIZE];          /**< Incoming message buffer; or
229                                         the error that caused this
230                                         clients socket to close. */
231   struct Socket       con_socket;    /**< socket descriptor for
232                                       client */
233   struct Timer        con_proc;      /**< process latent messages from
234                                       client */
235   struct AuthRequest* con_auth;      /**< auth request for client */
236   struct IAuthRequest* con_iauth;    /**< iauth request for client */
237 };
238
239 /** Magic constant to identify valid Connection structures. */
240 #define CONNECTION_MAGIC 0x12f955f3
241
242 /** Represents a client anywhere on the network. */
243 struct Client {
244   unsigned long  cli_magic;       /**< magic number */
245   struct Client* cli_next;        /**< link in GlobalClientList */
246   struct Client* cli_prev;        /**< link in GlobalClientList */
247   struct Client* cli_hnext;       /**< link in hash table bucket or this */
248   struct Connection* cli_connect; /**< Connection structure associated with us */
249   struct User*   cli_user;        /**< Defined if this client is a user */
250   struct Server* cli_serv;        /**< Defined if this client is a server */
251   struct Whowas* cli_whowas;      /**< Pointer to ww struct to be freed on quit */
252   char           cli_yxx[4];      /**< Numeric Nick: YY if this is a
253                                      server, XXX if this is a user */
254   /*
255    * XXX - move these to local part for next release
256    * (lasttime, since)
257    */
258   time_t         cli_lasttime;     /**< last time data read from socket */
259   time_t         cli_since;        /**< last time we parsed something, flood control */
260
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   unsigned char  cli_local;        /**< local or remote client */
269   struct Privs   cli_privs;        /**< Oper privileges */
270   char cli_name[HOSTLEN + 1];      /**< Unique name of the client, nick or host */
271   char cli_username[USERLEN + 1];  /**< username here now for auth stuff */
272   char cli_info[REALLEN + 1];      /**< Free form additional client information */
273 };
274
275 /** Magic constant to identify valid Client structures. */
276 #define CLIENT_MAGIC 0x4ca08286
277
278 /** Verify that a client is valid. */
279 #define cli_verify(cli)         ((cli)->cli_magic == CLIENT_MAGIC)
280 /** Get client's magic number. */
281 #define cli_magic(cli)          ((cli)->cli_magic)
282 /** Get global next client. */
283 #define cli_next(cli)           ((cli)->cli_next)
284 /** Get global previous client. */
285 #define cli_prev(cli)           ((cli)->cli_prev)
286 /** Get next client in hash bucket chain. */
287 #define cli_hnext(cli)          ((cli)->cli_hnext)
288 /** Get connection associated with client. */
289 #define cli_connect(cli)        ((cli)->cli_connect)
290 /** Get local client that links us to \a cli. */
291 #define cli_from(cli)           ((cli)->cli_connect->con_client)
292 /** Get User structure for client, if client is a user. */
293 #define cli_user(cli)           ((cli)->cli_user)
294 /** Get Server structure for client, if client is a server. */
295 #define cli_serv(cli)           ((cli)->cli_serv)
296 /** Get Whowas link for client. */
297 #define cli_whowas(cli)         ((cli)->cli_whowas)
298 /** Get client numnick. */
299 #define cli_yxx(cli)            ((cli)->cli_yxx)
300 /** Get time we last read data from the client socket. */
301 #define cli_lasttime(cli)       ((cli)->cli_lasttime)
302 /** Get time we last parsed something from the client. */
303 #define cli_since(cli)          ((cli)->cli_since)
304 /** Get time client was created. */
305 #define cli_firsttime(cli)      ((cli)->cli_firsttime)
306 /** Get time client last changed nickname. */
307 #define cli_lastnick(cli)       ((cli)->cli_lastnick)
308 /** Get WHO marker for client. */
309 #define cli_marker(cli)         ((cli)->cli_marker)
310 /** Get flags flagset for client. */
311 #define cli_flags(cli)          ((cli)->cli_flags)
312 /** Get hop count to client. */
313 #define cli_hopcount(cli)       ((cli)->cli_hopcount)
314 /** Get client IP address. */
315 #define cli_ip(cli)             ((cli)->cli_ip)
316 /** Get status bitmask for client. */
317 #define cli_status(cli)         ((cli)->cli_status)
318 /** Get local status flag for client. */
319 #define cli_local(cli)          ((cli)->cli_local)
320 /** Get oper privileges for client. */
321 #define cli_privs(cli)          ((cli)->cli_privs)
322 /** Get client name. */
323 #define cli_name(cli)           ((cli)->cli_name)
324 /** Get client username (ident). */
325 #define cli_username(cli)       ((cli)->cli_username)
326 /** Get client realname (information field). */
327 #define cli_info(cli)           ((cli)->cli_info)
328
329 /** Get number of incoming bytes queued for client. */
330 #define cli_count(cli)          ((cli)->cli_connect->con_count)
331 /** Get file descriptor for sending in client's direction. */
332 #define cli_fd(cli)             ((cli)->cli_connect->con_fd)
333 /** Get free flags for the client's connection. */
334 #define cli_freeflag(cli)       ((cli)->cli_connect->con_freeflag)
335 /** Get last error code for the client's connection. */
336 #define cli_error(cli)          ((cli)->cli_connect->con_error)
337 /** Get server notice mask for the client. */
338 #define cli_snomask(cli)        ((cli)->cli_connect->con_snomask)
339 /** Get next time a nick change is allowed for the client. */
340 #define cli_nextnick(cli)       ((cli)->cli_connect->con_nextnick)
341 /** Get next time a target change is allowed for the client. */
342 #define cli_nexttarget(cli)     ((cli)->cli_connect->con_nexttarget)
343 /** Get required PING/PONG cookie for client. */
344 #define cli_cookie(cli)         ((cli)->cli_connect->con_cookie)
345 /** Get SendQ for client. */
346 #define cli_sendQ(cli)          ((cli)->cli_connect->con_sendQ)
347 /** Get RecvQ for client. */
348 #define cli_recvQ(cli)          ((cli)->cli_connect->con_recvQ)
349 /** Get count of messages sent to client. */
350 #define cli_sendM(cli)          ((cli)->cli_connect->con_sendM)
351 /** Get number of kilobytes sent to client. */
352 #define cli_sendK(cli)          ((cli)->cli_connect->con_sendK)
353 /** Get number of messages received from client. */
354 #define cli_receiveM(cli)       ((cli)->cli_connect->con_receiveM)
355 /** Get number of kilobytes received from client. */
356 #define cli_receiveK(cli)       ((cli)->cli_connect->con_receiveK)
357 /** Get number of bytes (modulo 1024) sent to client. */
358 #define cli_sendB(cli)          ((cli)->cli_connect->con_sendB)
359 /** Get number of bytes (modulo 1024) received from client. */
360 #define cli_receiveB(cli)       ((cli)->cli_connect->con_receiveB)
361 /** Get listener that accepted the client's connection. */
362 #define cli_listener(cli)       ((cli)->cli_connect->con_listener)
363 /** Get list of attached conf lines. */
364 #define cli_confs(cli)          ((cli)->cli_connect->con_confs)
365 /** Get handler type for client. */
366 #define cli_handler(cli)        ((cli)->cli_connect->con_handler)
367 /** Get DNS reply for client. */
368 #define cli_dns_reply(cli)      ((cli)->cli_connect->con_dns_reply)
369 /** Get LIST status for client. */
370 #define cli_listing(cli)        ((cli)->cli_connect->con_listing)
371 /** Get cached max SendQ for client. */
372 #define cli_max_sendq(cli)      ((cli)->cli_connect->con_max_sendq)
373 /** Get ping frequency for client. */
374 #define cli_ping_freq(cli)      ((cli)->cli_connect->con_ping_freq)
375 /** Get lastsq for client's connection. */
376 #define cli_lastsq(cli)         ((cli)->cli_connect->con_lastsq)
377 /** Get remote port number for client. */
378 #define cli_port(cli)           ((cli)->cli_connect->con_port)
379 /** Get the array of current targets for the client.  */
380 #define cli_targets(cli)        ((cli)->cli_connect->con_targets)
381 /** Get the string form of the client's IP address. */
382 #define cli_sock_ip(cli)        ((cli)->cli_connect->con_sock_ip)
383 /** Get the resolved hostname for the client. */
384 #define cli_sockhost(cli)       ((cli)->cli_connect->con_sockhost)
385 /** Get the client's password. */
386 #define cli_passwd(cli)         ((cli)->cli_connect->con_passwd)
387 /** Get the unprocessed input buffer for a client's connection.  */
388 #define cli_buffer(cli)         ((cli)->cli_connect->con_buffer)
389 /** Get the Socket structure for sending to a client. */
390 #define cli_socket(cli)         ((cli)->cli_connect->con_socket)
391 /** Get Timer for processing waiting messages from the client. */
392 #define cli_proc(cli)           ((cli)->cli_connect->con_proc)
393 /** Get auth request for client. */
394 #define cli_auth(cli)           ((cli)->cli_connect->con_auth)
395 /** Get iauth request for client. */
396 #define cli_iauth(cli)          ((cli)->cli_connect->con_iauth)
397
398 /** Verify that a connection is valid. */
399 #define con_verify(con)         ((con)->con_magic == CONNECTION_MAGIC)
400 /** Get connection's magic number. */
401 #define con_magic(con)          ((con)->con_magic)
402 /** Get global next connection. */
403 #define con_next(con)           ((con)->con_next)
404 /** Get global previous connection. */
405 #define con_prev_p(con)         ((con)->con_prev_p)
406 /** Get locally connected client for connection. */
407 #define con_client(con)         ((con)->con_client)
408 /** Get number of unprocessed data bytes from connection. */
409 #define con_count(con)          ((con)->con_count)
410 /** Get file descriptor for connection. */
411 #define con_fd(con)             ((con)->con_fd)
412 /** Get freeable flags for connection. */
413 #define con_freeflag(con)       ((con)->con_freeflag)
414 /** Get last error code on connection. */
415 #define con_error(con)          ((con)->con_error)
416 /** Get server notice mask for connection. */
417 #define con_snomask(con)        ((con)->con_snomask)
418 /** Get next nick change time for connection. */
419 #define con_nextnick(con)       ((con)->con_nextnick)
420 /** Get next new target time for connection. */
421 #define con_nexttarget(con)     ((con)->con_nexttarget)
422 /** Get PING/PONG confirmation cookie for connection. */
423 #define con_cookie(con)         ((con)->con_cookie)
424 /** Get SendQ for connection. */
425 #define con_sendQ(con)          ((con)->con_sendQ)
426 /** Get RecvQ for connection. */
427 #define con_recvQ(con)          ((con)->con_recvQ)
428 /** Get number of messages sent to connection. */
429 #define con_sendM(con)          ((con)->con_sendM)
430 /** Get number of kilobytes sent to connection. */
431 #define con_sendK(con)          ((con)->con_sendK)
432 /** Get number of messages received from connection. */
433 #define con_receiveM(con)       ((con)->con_receiveM)
434 /** Get number of kilobytes received from connection. */
435 #define con_receiveK(con)       ((con)->con_receiveK)
436 /** Get number of bytes (modulo 1024) sent to connection. */
437 #define con_sendB(con)          ((con)->con_sendB)
438 /** Get number of bytes (modulo 1024) received from connection. */
439 #define con_receiveB(con)       ((con)->con_receiveB)
440 /** Get listener that accepted the connection. */
441 #define con_listener(con)       ((con)->con_listener)
442 /** Get list of ConfItems attached to the connection. */
443 #define con_confs(con)          ((con)->con_confs)
444 /** Get command handler for the connection. */
445 #define con_handler(con)        ((con)->con_handler)
446 /** Get DNS reply for the connection. */
447 #define con_dns_reply(con)      ((con)->con_dns_reply)
448 /** Get the LIST status for the connection. */
449 #define con_listing(con)        ((con)->con_listing)
450 /** Get the maximum permitted SendQ size for the connection. */
451 #define con_max_sendq(con)      ((con)->con_max_sendq)
452 /** Get the ping frequency for the connection. */
453 #define con_ping_freq(con)      ((con)->con_ping_freq)
454 /** Get the lastsq for the connection. */
455 #define con_lastsq(con)         ((con)->con_lastsq)
456 /** Get the remote port number for the connection. */
457 #define con_port(con)           ((con)->con_port)
458 /** Get the current targets array for the connection. */
459 #define con_targets(con)        ((con)->con_targets)
460 /** Get the string-formatted IP address for the connection. */
461 #define con_sock_ip(con)        ((con)->con_sock_ip)
462 /** Get the resolved hostname for the connection. */
463 #define con_sockhost(con)       ((con)->con_sockhost)
464 /** Get the password sent by the remote end of the connection.  */
465 #define con_passwd(con)         ((con)->con_passwd)
466 /** Get the buffer of unprocessed incoming data from the connection. */
467 #define con_buffer(con)         ((con)->con_buffer)
468 /** Get the Socket for the connection. */
469 #define con_socket(con)         ((con)->con_socket)
470 /** Get the Timer for processing more data from the connection. */
471 #define con_proc(con)           ((con)->con_proc)
472 /** Get the auth request for the connection. */
473 #define con_auth(con)           ((con)->con_auth)
474 /** Get the iauth request for the connection. */
475 #define con_iauth(con)          ((con)->con_iauth)
476
477 #define STAT_CONNECTING         0x001 /**< connecting to another server */
478 #define STAT_HANDSHAKE          0x002 /**< pass - server sent */
479 #define STAT_ME                 0x004 /**< this server */
480 #define STAT_UNKNOWN            0x008 /**< unidentified connection */
481 #define STAT_UNKNOWN_USER       0x010 /**< connection on a client port */
482 #define STAT_UNKNOWN_SERVER     0x020 /**< connection on a server port */
483 #define STAT_SERVER             0x040 /**< fully registered server */
484 #define STAT_USER               0x080 /**< fully registered user */
485
486 /*
487  * status macros.
488  */
489 /** Return non-zero if the client is registered. */
490 #define IsRegistered(x)         (cli_status(x) & (STAT_SERVER | STAT_USER))
491 /** Return non-zero if the client is an outbound connection that is
492  * still connecting. */
493 #define IsConnecting(x)         (cli_status(x) == STAT_CONNECTING)
494 /** Return non-zero if the client is an outbound connection that has
495  * sent our password. */
496 #define IsHandshake(x)          (cli_status(x) == STAT_HANDSHAKE)
497 /** Return non-zero if the client is this server. */
498 #define IsMe(x)                 (cli_status(x) == STAT_ME)
499 /** Return non-zero if the client has not yet registered. */
500 #define IsUnknown(x)            (cli_status(x) & \
501         (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
502 /** Return non-zero if the client is an unregistered connection on a
503  * server port. */
504 #define IsServerPort(x)         (cli_status(x) == STAT_UNKNOWN_SERVER )
505 /** Return non-zero if the client is an unregistered connection on a
506  * user port. */
507 #define IsUserPort(x)           (cli_status(x) == STAT_UNKNOWN_USER )
508 /** Return non-zero if the client is a real client connection. */
509 #define IsClient(x)             (cli_status(x) & \
510         (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
511          STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
512 /** Return non-zero if the client ignores flood limits. */
513 #define IsTrusted(x)            (cli_status(x) & \
514         (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
515 /** Return non-zero if the client is a registered server. */
516 #define IsServer(x)             (cli_status(x) == STAT_SERVER)
517 /** Return non-zero if the client is a registered user. */
518 #define IsUser(x)               (cli_status(x) == STAT_USER)
519
520
521 /** Mark a client with STAT_CONNECTING. */
522 #define SetConnecting(x)        (cli_status(x) = STAT_CONNECTING)
523 /** Mark a client with STAT_HANDSHAKE. */
524 #define SetHandshake(x)         (cli_status(x) = STAT_HANDSHAKE)
525 /** Mark a client with STAT_SERVER. */
526 #define SetServer(x)            (cli_status(x) = STAT_SERVER)
527 /** Mark a client with STAT_ME. */
528 #define SetMe(x)                (cli_status(x) = STAT_ME)
529 /** Mark a client with STAT_USER. */
530 #define SetUser(x)              (cli_status(x) = STAT_USER)
531
532 /** Return non-zero if a client is directly connected to me. */
533 #define MyConnect(x)    (cli_from(x) == (x))
534 /** Return non-zero if a client is a locally connected user. */
535 #define MyUser(x)       (MyConnect(x) && IsUser(x))
536 /** Return non-zero if a client is a locally connected IRC operator. */
537 #define MyOper(x)       (MyConnect(x) && IsOper(x))
538 /** Return protocol version used by a server. */
539 #define Protocol(x)     ((cli_serv(x))->prot)
540
541 /*
542  * flags macros
543  */
544 /** Set a flag in a flagset. */
545 #define FlagSet(fset, flag) FLAGSET_SET(*fset, flag)
546 /** Clear a flag from a flagset. */
547 #define FlagClr(fset, flag) FLAGSET_CLEAR(*fset, flag)
548 /** Return non-zero if a flag is set in a flagset. */
549 #define FlagHas(fset, flag) FLAGSET_ISSET(*fset, flag)
550 /** Set a flag in a client's flags. */
551 #define SetFlag(cli, flag)      FlagSet(&cli_flags(cli), flag)
552 /** Clear a flag from a client's flags. */
553 #define ClrFlag(cli, flag)      FlagClr(&cli_flags(cli), flag)
554 /** Return non-zero if a flag is set in a client's flags. */
555 #define HasFlag(cli, flag)      FlagHas(&cli_flags(cli), flag)
556
557 /** Return non-zero if we can check the client's access. */
558 #define DoAccess(x)             HasFlag(x, FLAG_CHKACCESS)
559 /** Return non-zero if the client is an IRC operator (global or local). */
560 #define IsAnOper(x)             (HasFlag(x, FLAG_OPER) || HasFlag(x, FLAG_LOCOP))
561 /** Return non-zero if the client's connection is blocked. */
562 #define IsBlocked(x)            HasFlag(x, FLAG_BLOCKED)
563 /** Return non-zero if the client's connection is still being burst. */
564 #define IsBurst(x)              HasFlag(x, FLAG_BURST)
565 /** Return non-zero if we have received the peer's entire burst but
566  * not their EOB ack. */
567 #define IsBurstAck(x)           HasFlag(x, FLAG_BURST_ACK)
568 /** Return non-zero if we are still bursting to the client. */
569 #define IsBurstOrBurstAck(x)    (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK))
570 /** Return non-zero if the client has set mode +k (channel service). */
571 #define IsChannelService(x)     HasFlag(x, FLAG_CHSERV)
572 /** Return non-zero if the client's socket is disconnected. */
573 #define IsDead(x)               HasFlag(x, FLAG_DEADSOCKET)
574 /** Return non-zero if the client has set mode +d (deaf). */
575 #define IsDeaf(x)               HasFlag(x, FLAG_DEAF)
576 /** Return non-zero if the client has been IP-checked for clones. */
577 #define IsIPChecked(x)          HasFlag(x, FLAG_IPCHECK)
578 /** Return non-zero if the client has been okayed by iauth. */
579 #define IsIAuthed(x)            HasFlag(x, FLAG_IAUTHED)
580 /** Return non-zero if we have received an ident response for the client. */
581 #define IsIdented(x)            HasFlag(x, FLAG_GOTID)
582 /** Return non-zero if the client has set mode +i (invisible). */
583 #define IsInvisible(x)          HasFlag(x, FLAG_INVISIBLE)
584 /** Return non-zero if the client caused a net.burst. */
585 #define IsJunction(x)           HasFlag(x, FLAG_JUNCTION)
586 /** Return non-zero if the client has set mode +O (local operator). */
587 #define IsLocOp(x)              HasFlag(x, FLAG_LOCOP)
588 /** Return non-zero if the client is directly connected. */
589 #define IsLocal(x)              HasFlag(x, FLAG_LOCAL)
590 /** Return non-zero if the client has set mode +o (global operator). */
591 #define IsOper(x)               HasFlag(x, FLAG_OPER)
592 /** Return non-zero if the client has an active UDP ping request. */
593 #define IsUPing(x)              HasFlag(x, FLAG_UPING)
594 /** Return non-zero if the client has no '\n' in its buffer. */
595 #define NoNewLine(x)            HasFlag(x, FLAG_NONL)
596 /** Return non-zero if the client has set mode +g (debugging). */
597 #define SendDebug(x)            HasFlag(x, FLAG_DEBUG)
598 /** Return non-zero if the client has set mode +s (server notices). */
599 #define SendServNotice(x)       HasFlag(x, FLAG_SERVNOTICE)
600 /** Return non-zero if the client has set mode +w (wallops). */
601 #define SendWallops(x)          HasFlag(x, FLAG_WALLOP)
602 /** Return non-zero if the client claims to be a hub. */
603 #define IsHub(x)                HasFlag(x, FLAG_HUB)
604 /** Return non-zero if the client claims to be a services server. */
605 #define IsService(x)            HasFlag(x, FLAG_SERVICE)
606 /** Return non-zero if the client has an account stamp. */
607 #define IsAccount(x)            HasFlag(x, FLAG_ACCOUNT)
608 /** Return non-zero if the client has set mode +x (hidden host). */
609 #define IsHiddenHost(x)         HasFlag(x, FLAG_HIDDENHOST)
610 /** Return non-zero if the client has an active PING request. */
611 #define IsPingSent(x)           HasFlag(x, FLAG_PINGSENT)
612
613 /** Return non-zero if the client has operator or server privileges. */
614 #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
615 /** Return non-zero if the client's host is hidden. */
616 #define HasHiddenHost(x)        (IsHiddenHost(x) && IsAccount(x))
617
618 /** Mark a client as being okay to check access. */
619 #define SetAccess(x)            SetFlag(x, FLAG_CHKACCESS)
620 /** Mark a client as having an in-progress net.burst. */
621 #define SetBurst(x)             SetFlag(x, FLAG_BURST)
622 /** Mark a client as being between EOB and EOB ACK. */
623 #define SetBurstAck(x)          SetFlag(x, FLAG_BURST_ACK)
624 /** Mark a client as having mode +k (channel service). */
625 #define SetChannelService(x)    SetFlag(x, FLAG_CHSERV)
626 /** Mark a client as having mode +d (deaf). */
627 #define SetDeaf(x)              SetFlag(x, FLAG_DEAF)
628 /** Mark a client as having mode +g (debugging). */
629 #define SetDebug(x)             SetFlag(x, FLAG_DEBUG)
630 /** Mark a client as having ident looked up. */
631 #define SetGotId(x)             SetFlag(x, FLAG_GOTID)
632 /** Mark a client as being IP-checked. */
633 #define SetIPChecked(x)         SetFlag(x, FLAG_IPCHECK)
634 /** Mark a client as being iauth-checked. */
635 #define SetIAuthed(x)           SetFlag(x, FLAG_IAUTHED)
636 /** Mark a client as having mode +i (invisible). */
637 #define SetInvisible(x)         SetFlag(x, FLAG_INVISIBLE)
638 /** Mark a client as causing a net.join. */
639 #define SetJunction(x)          SetFlag(x, FLAG_JUNCTION)
640 /** Mark a client as having mode +O (local operator). */
641 #define SetLocOp(x)             SetFlag(x, FLAG_LOCOP)
642 /** Mark a client as having mode +o (global operator). */
643 #define SetOper(x)              SetFlag(x, FLAG_OPER)
644 /** Mark a client as having a pending UDP ping. */
645 #define SetUPing(x)             SetFlag(x, FLAG_UPING)
646 /** Mark a client as having mode +w (wallops). */
647 #define SetWallops(x)           SetFlag(x, FLAG_WALLOP)
648 /** Mark a client as having mode +s (server notices). */
649 #define SetServNotice(x)        SetFlag(x, FLAG_SERVNOTICE)
650 /** Mark a client as being a hub server. */
651 #define SetHub(x)               SetFlag(x, FLAG_HUB)
652 /** Mark a client as being a services server. */
653 #define SetService(x)           SetFlag(x, FLAG_SERVICE)
654 /** Mark a client as having an account stamp. */
655 #define SetAccount(x)           SetFlag(x, FLAG_ACCOUNT)
656 /** Mark a client as having mode +x (hidden host). */
657 #define SetHiddenHost(x)        SetFlag(x, FLAG_HIDDENHOST)
658 /** Mark a client as having a pending PING. */
659 #define SetPingSent(x)          SetFlag(x, FLAG_PINGSENT)
660
661 /** Return non-zero if \a sptr sees \a acptr as an operator. */
662 #define SeeOper(sptr,acptr) (IsAnOper(acptr) && (HasPriv(acptr, PRIV_DISPLAY) \
663                             || HasPriv(sptr, PRIV_SEE_OPERS)))
664
665 /** Clear the client's okay to check access flag. */
666 #define ClearAccess(x)          ClrFlag(x, FLAG_CHKACCESS)
667 /** Clear the client's net.burst in-progress flag. */
668 #define ClearBurst(x)           ClrFlag(x, FLAG_BURST)
669 /** Clear the client's between EOB and EOB ACK flag. */
670 #define ClearBurstAck(x)        ClrFlag(x, FLAG_BURST_ACK)
671 /** Remove mode +k (channel service) from the client. */
672 #define ClearChannelService(x)  ClrFlag(x, FLAG_CHSERV)
673 /** Remove mode +d (deaf) from the client. */
674 #define ClearDeaf(x)            ClrFlag(x, FLAG_DEAF)
675 /** Remove mode +g (debugging) from the client. */
676 #define ClearDebug(x)           ClrFlag(x, FLAG_DEBUG)
677 /** Remove the client's IP-checked flag. */
678 #define ClearIPChecked(x)       ClrFlag(x, FLAG_IPCHECK)
679 /** Remove mode +i (invisible) from the client. */
680 #define ClearInvisible(x)       ClrFlag(x, FLAG_INVISIBLE)
681 /** Remove mode +O (local operator) from the client. */
682 #define ClearLocOp(x)           ClrFlag(x, FLAG_LOCOP)
683 /** Remove mode +o (global operator) from the client. */
684 #define ClearOper(x)            ClrFlag(x, FLAG_OPER)
685 /** Clear the client's pending UDP ping flag. */
686 #define ClearUPing(x)           ClrFlag(x, FLAG_UPING)
687 /** Remove mode +w (wallops) from the client. */
688 #define ClearWallops(x)         ClrFlag(x, FLAG_WALLOP)
689 /** Remove mode +s (server notices) from the client. */
690 #define ClearServNotice(x)      ClrFlag(x, FLAG_SERVNOTICE)
691 /** Remove mode +x (hidden host) from the client. */
692 #define ClearHiddenHost(x)      ClrFlag(x, FLAG_HIDDENHOST)
693 /** Clear the client's pending PING flag. */
694 #define ClearPingSent(x)        ClrFlag(x, FLAG_PINGSENT)
695
696 /* free flags */
697 #define FREEFLAG_SOCKET 0x0001  /**< socket needs to be freed */
698 #define FREEFLAG_TIMER  0x0002  /**< timer needs to be freed */
699
700 /* server notice stuff */
701
702 #define SNO_ADD         1       /**< Perform "or" on server notice mask. */
703 #define SNO_DEL         2       /**< Perform "and ~x" on server notice mask. */
704 #define SNO_SET         3       /**< Set server notice mask. */
705                                 /* DON'T CHANGE THESE VALUES ! */
706                                 /* THE CLIENTS DEPEND ON IT  ! */
707 #define SNO_OLDSNO      0x1     /**< unsorted old messages */
708 #define SNO_SERVKILL    0x2     /**< server kills (nick collisions) */
709 #define SNO_OPERKILL    0x4     /**< oper kills */
710 #define SNO_HACK2       0x8     /**< desyncs */
711 #define SNO_HACK3       0x10    /**< temporary desyncs */
712 #define SNO_UNAUTH      0x20    /**< unauthorized connections */
713 #define SNO_TCPCOMMON   0x40    /**< common TCP or socket errors */
714 #define SNO_TOOMANY     0x80    /**< too many connections */
715 #define SNO_HACK4       0x100   /**< Uworld actions on channels */
716 #define SNO_GLINE       0x200   /**< glines */
717 #define SNO_NETWORK     0x400   /**< net join/break, etc */
718 #define SNO_IPMISMATCH  0x800   /**< IP mismatches */
719 #define SNO_THROTTLE    0x1000  /**< host throttle add/remove notices */
720 #define SNO_OLDREALOP   0x2000  /**< old oper-only messages */
721 #define SNO_CONNEXIT    0x4000  /**< client connect/exit (ugh) */
722 #define SNO_AUTO        0x8000  /**< AUTO G-Lines */
723 #define SNO_DEBUG       0x10000 /**< debugging messages (DEBUGMODE only) */
724
725 #ifdef DEBUGMODE
726 # define SNO_ALL        0x1ffff  /**< Bitmask of all valid server
727                                   * notice bits. */
728 #else
729 # define SNO_ALL        0xffff
730 #endif
731
732 /** Server notice bits allowed to normal users. */
733 #define SNO_USER        (SNO_ALL & ~SNO_OPER)
734
735 /** Server notice bits enabled by default for normal users. */
736 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
737 /** Server notice bits enabled by default for IRC operators. */
738 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
739 /** Server notice bits reserved to IRC operators. */
740 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
741 /** Noisy server notice bits that cause other bits to be cleared during connect. */
742 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
743
744 /** Set a privilege flag on a privilege flagset. */
745 #define PrivSet(fset, flag) FLAGSET_SET(*fset, flag)
746 /** Clear a privilege flag from a privilege flagset. */
747 #define PrivClr(fset, flag) FLAGSET_CLEAR(*fset, flag)
748 /** Test a privilege flag in a privilege flagset. */
749 #define PrivHas(fset, flag) FLAGSET_ISSET(*fset, flag)
750
751 /** Grant a privilege to a client. */
752 #define GrantPriv(cli, priv)    (PrivSet(&(cli_privs(cli)), priv))
753 /** Revoke a privilege from a client. */
754 #define RevokePriv(cli, priv)   (PrivClr(&(cli_privs(cli)), priv))
755 /** Test whether a privilege has been grated to a client. */
756 #define HasPriv(cli, priv)      (PrivHas(&(cli_privs(cli)), priv))
757
758 #define HIDE_IP 0 /**< Do not show IP address in get_client_name() */
759 #define SHOW_IP 1 /**< Show ident and IP address in get_client_name() */
760
761 extern const char* get_client_name(const struct Client* sptr, int showip);
762 extern const char* client_get_default_umode(const struct Client* sptr);
763 extern int client_get_ping(const struct Client* local_client);
764 extern void client_drop_sendq(struct Connection* con);
765 extern void client_add_sendq(struct Connection* con,
766                              struct Connection** con_p);
767 extern void client_set_privs(struct Client *client, struct ConfItem *oper);
768 extern int client_report_privs(struct Client* to, struct Client* client);
769
770 #endif /* INCLUDED_client_h */
771