Removed resolver cache, cleanup client code
[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  *
21  * $Id$
22  */
23 #ifndef INCLUDED_client_h
24 #define INCLUDED_client_h
25 #ifndef INCLUDED_ircd_defs_h
26 #include "ircd_defs.h"
27 #endif
28 #ifndef INCLUDED_dbuf_h
29 #include "dbuf.h"
30 #endif
31 #ifndef INCLUDED_msgq_h
32 #include "msgq.h"
33 #endif
34 #ifndef INCLUDED_ircd_events_h
35 #include "ircd_events.h"
36 #endif
37 #ifndef INCLUDED_ircd_handler_h
38 #include "ircd_handler.h"
39 #endif
40 #ifndef INCLUDED_sys_types_h
41 #include <sys/types.h>          /* time_t, size_t */
42 #define INCLUDED_sys_types_h
43 #endif
44 #ifndef INCLUDED_netinet_in_h
45 #include <netinet/in.h>         /* in_addr */
46 #define INCLUDED_netinet_in_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 typedef unsigned long flagpage_t;
69
70 #define FLAGSET_NBITS (8 * sizeof(flagpage_t))
71 #define FLAGSET_INDEX(flag) (flag / FLAGSET_NBITS)
72 #define FLAGSET_MASK(flag) (1<<(flag % FLAGSET_NBITS))
73
74 #define DECLARE_FLAGSET(name,max) \
75   struct name \
76   { \
77     unsigned long bits[((max + FLAGSET_NBITS - 1) / FLAGSET_NBITS)]; \
78   };
79
80 #define FLAGSET_ISSET(set,flag) ((set).bits[FLAGSET_INDEX(flag)] & FLAGSET_MASK(flag))
81 #define FLAGSET_SET(set, flag) (set).bits[FLAGSET_INDEX(flag)] |= FLAGSET_MASK(flag)
82 #define FLAGSET_CLEAR(set, flag) (set).bits[FLAGSET_INDEX(flag)] &= ~FLAGSET_MASK(flag)
83
84 enum Priv
85   {
86     PRIV_CHAN_LIMIT, /* no channel limit on oper */
87     PRIV_MODE_LCHAN, /* oper can mode local chans */
88     PRIV_WALK_LCHAN, /* oper can walk thru local modes */
89     PRIV_DEOP_LCHAN, /* no deop oper on local chans */
90     PRIV_SHOW_INVIS, /* show local invisible users */
91     PRIV_SHOW_ALL_INVIS, /* show all invisible users */
92     PRIV_UNLIMIT_QUERY, /* unlimit who queries */
93     PRIV_KILL, /* oper can KILL */
94     PRIV_LOCAL_KILL, /* oper can local KILL */
95     PRIV_REHASH, /* oper can REHASH */
96     PRIV_RESTART, /* oper can RESTART */
97     PRIV_DIE, /* oper can DIE */
98     PRIV_GLINE, /* oper can GLINE */
99     PRIV_LOCAL_GLINE, /* oper can local GLINE */
100     PRIV_JUPE, /* oper can JUPE */
101     PRIV_LOCAL_JUPE, /* oper can local JUPE */
102     PRIV_OPMODE, /* oper can OP/CLEARMODE */
103     PRIV_LOCAL_OPMODE, /* oper can local OP/CLEARMODE */
104     PRIV_SET,  /* oper can SET */
105     PRIV_WHOX, /* oper can use /who x */
106     PRIV_BADCHAN, /* oper can BADCHAN */
107     PRIV_LOCAL_BADCHAN, /* oper can local BADCHAN */
108     PRIV_SEE_CHAN, /* oper can see in secret chans */
109     PRIV_PROPAGATE, /* propagate oper status */
110     PRIV_DISPLAY, /* "Is an oper" displayed */
111     PRIV_SEE_OPERS, /* display hidden opers */
112     PRIV_WIDE_GLINE, /* oper can set wider G-lines */
113     PRIV_LIST_CHAN, /* oper can list secret channels */
114     PRIV_FORCE_OPMODE,
115     PRIV_FORCE_LOCAL_OPMODE,
116     PRIV_LAST_PRIV /* must be the same as the last priv */
117   };
118
119 enum Flag
120   {
121     FLAG_PINGSENT,                  /* Unreplied ping sent */
122     FLAG_DEADSOCKET,                /* Local socket is dead--Exiting soon */
123     FLAG_KILLED,                    /* Prevents "QUIT" from being sent for this */
124     FLAG_BLOCKED,                   /* socket is in a blocked condition */
125     FLAG_CLOSING,                   /* set when closing to suppress errors */
126     FLAG_UPING,                     /* has active UDP ping request */
127     FLAG_CHKACCESS,                 /* ok to check clients access if set */
128     FLAG_HUB,                       /* server is a hub */
129     FLAG_SERVICE,                   /* server is a service */
130     FLAG_LOCAL,                     /* set for local clients */
131     FLAG_GOTID,                     /* successful ident lookup achieved */
132     FLAG_DOID,                      /* I-lines say must use ident return */
133     FLAG_NONL,                      /* No \n in buffer */
134     FLAG_TS8,                       /* Why do you want to know? */
135     FLAG_MAP,                       /* Show server on the map */
136     FLAG_JUNCTION,                  /* Junction causing the net.burst */
137     FLAG_BURST,                     /* Server is receiving a net.burst */
138     FLAG_BURST_ACK,                 /* Server is waiting for eob ack */
139     FLAG_IPCHECK,                   /* Added or updated IPregistry data */
140     FLAG_LOCOP,                     /* Local operator -- SRB */
141     FLAG_SERVNOTICE,                /* server notices such as kill */
142     FLAG_OPER,                      /* Operator */
143     FLAG_INVISIBLE,                 /* makes user invisible */
144     FLAG_WALLOP,                    /* send wallops to them */
145     FLAG_DEAF,                      /* Makes user deaf */
146     FLAG_CHSERV,                    /* Disallow KICK or MODE -o on the user;
147                                        don't display channels in /whois */
148     FLAG_DEBUG,                     /* send global debug/anti-hack info */
149     FLAG_ACCOUNT,                   /* account name has been set */
150     FLAG_HIDDENHOST,                /* user's host is hidden */
151     FLAG_LAST_FLAG,
152     FLAG_LOCAL_UMODES = FLAG_LOCOP, /* First local mode flag */
153     FLAG_GLOBAL_UMODES = FLAG_OPER  /* First global mode flag */
154   };
155
156 DECLARE_FLAGSET(Privs, PRIV_LAST_PRIV);
157 DECLARE_FLAGSET(Flags, FLAG_LAST_FLAG);
158
159 struct Connection
160 {
161   /*
162    *  The following fields are allocated only for local clients
163    *  (directly connected to *this* server with a socket.
164    *  The first of them *MUST* be the "count"--it is the field
165    *  to which the allocation is tied to! *Never* refer to
166    *  these fields, if (from != self).
167    */
168   unsigned long       con_magic; /* magic number */
169   struct Connection*  con_next;  /* Next connection with queued data */
170   struct Connection** con_prev_p; /* What points to us */
171   struct Client*      con_client; /* Client associated with connection */
172   unsigned int        con_count; /* Amount of data in buffer */
173   int                 con_fd;    /* >= 0, for local clients */
174   int                 con_freeflag; /* indicates if connection can be freed */
175   int                 con_error; /* last socket level error for client */
176   unsigned int        con_snomask; /* mask for server messages */
177   time_t              con_nextnick; /* Next time a nick change is allowed */
178   time_t              con_nexttarget;/* Next time a target change is allowed */
179   unsigned int        con_cookie; /* Random number the user must PONG */
180   struct MsgQ         con_sendQ; /* Outgoing message queue--if socket full */
181   struct DBuf         con_recvQ; /* Hold for data incoming yet to be parsed */
182   unsigned int        con_sendM; /* Statistics: protocol messages send */
183   unsigned int        con_sendK; /* Statistics: total k-bytes send */
184   unsigned int        con_receiveM;/* Statistics: protocol messages received */
185   unsigned int        con_receiveK; /* Statistics: total k-bytes received */
186   unsigned short      con_sendB; /* counters to count upto 1-k lots of bytes */
187   unsigned short      con_receiveB; /* sent and received. */
188   struct Listener*    con_listener; /* listening client which we accepted
189                                        from */
190   struct SLink*       con_confs; /* Configuration record associated */
191   HandlerType         con_handler; /* message index into command table
192                                       for parsing */
193   struct hostent*    con_dns_reply; /* DNS reply used during client
194                                         registration */
195   struct ListingArgs* con_listing;
196   unsigned int        con_max_sendq; /* cached max send queue for client */
197   unsigned int        con_ping_freq; /* cached ping freq from client conf
198                                         class */
199   unsigned short      con_lastsq; /* # 2k blocks when sendqueued called last */
200   unsigned short      con_port;  /* and the remote port# too :-) */
201   unsigned char       con_targets[MAXTARGETS]; /* Hash values of current
202                                                   targets */
203   char con_sock_ip[SOCKIPLEN + 1]; /* this is the ip address as a string */
204   char con_sockhost[HOSTLEN + 1]; /* This is the host name from the socket and
205                                     after which the connection was accepted. */
206   char con_passwd[PASSWDLEN + 1];
207   char con_buffer[BUFSIZE];     /* Incoming message buffer; or the error that
208                                    caused this clients socket to be `dead' */
209   struct Socket       con_socket; /* socket descriptor for client */
210   struct Timer        con_proc; /* process latent messages from client */
211   struct AuthRequest* con_auth; /* auth request for client */
212 };
213
214 #define CONNECTION_MAGIC 0x12f955f3
215
216 struct Client {
217   unsigned long  cli_magic;     /* magic number */
218   struct Client* cli_next;      /* link in GlobalClientList */
219   struct Client* cli_prev;      /* link in GlobalClientList */
220   struct Client* cli_hnext;     /* link in hash table bucket or this */
221   struct Connection* cli_connect; /* Connection structure associated with us */
222   struct User*   cli_user;      /* ...defined, if this is a User */
223   struct Server* cli_serv;      /* ...defined, if this is a server */
224   struct Whowas* cli_whowas;    /* Pointer to ww struct to be freed on quit */
225   char           cli_yxx[4];    /* Numeric Nick: YMM if this is a server,
226                                    XX0 if this is a user */
227   /*
228    * XXX - move these to local part for next release
229    * (lasttime, since)
230    */
231   time_t         cli_lasttime;  /* last time data read from socket */
232   time_t         cli_since;     /* last time we parsed something, flood control */
233                                 
234   time_t         cli_firsttime; /* time client was created */
235   time_t         cli_lastnick;  /* TimeStamp on nick */
236   int            cli_marker;    /* /who processing marker */
237   struct Flags   cli_flags;     /* client flags */
238   unsigned int   cli_hopcount;  /* number of servers to this 0 = local */
239   struct in_addr cli_ip;        /* Real ip# NOT defined for remote servers! */
240   short          cli_status;    /* Client type */
241   unsigned char  cli_local;     /* local or remote client */
242   struct Privs   cli_privs;     /* Oper privileges */
243   char cli_name[HOSTLEN + 1];   /* Unique name of the client, nick or host */
244   char cli_username[USERLEN + 1]; /* username here now for auth stuff */
245   char cli_info[REALLEN + 1];   /* Free form additional client information */
246 };
247
248 #define CLIENT_MAGIC 0x4ca08286
249
250 #define cli_verify(cli)         ((cli)->cli_magic == CLIENT_MAGIC)
251 #define cli_magic(cli)          ((cli)->cli_magic)
252 #define cli_next(cli)           ((cli)->cli_next)
253 #define cli_prev(cli)           ((cli)->cli_prev)
254 #define cli_hnext(cli)          ((cli)->cli_hnext)
255 #define cli_connect(cli)        ((cli)->cli_connect)
256 #define cli_from(cli)           ((cli)->cli_connect->con_client)
257 #define cli_user(cli)           ((cli)->cli_user)
258 #define cli_serv(cli)           ((cli)->cli_serv)
259 #define cli_whowas(cli)         ((cli)->cli_whowas)
260 #define cli_yxx(cli)            ((cli)->cli_yxx)
261 #define cli_lasttime(cli)       ((cli)->cli_lasttime)
262 #define cli_since(cli)          ((cli)->cli_since)
263 #define cli_firsttime(cli)      ((cli)->cli_firsttime)
264 #define cli_lastnick(cli)       ((cli)->cli_lastnick)
265 #define cli_marker(cli)         ((cli)->cli_marker)
266 #define cli_flags(cli)          ((cli)->cli_flags)
267 #define cli_hopcount(cli)       ((cli)->cli_hopcount)
268 #define cli_ip(cli)             ((cli)->cli_ip)
269 #define cli_status(cli)         ((cli)->cli_status)
270 #define cli_local(cli)          ((cli)->cli_local)
271 #define cli_privs(cli)          ((cli)->cli_privs)
272 #define cli_name(cli)           ((cli)->cli_name)
273 #define cli_username(cli)       ((cli)->cli_username)
274 #define cli_info(cli)           ((cli)->cli_info)
275
276 #define cli_count(cli)          ((cli)->cli_connect->con_count)
277 #define cli_fd(cli)             ((cli)->cli_connect->con_fd)
278 #define cli_freeflag(cli)       ((cli)->cli_connect->con_freeflag)
279 #define cli_error(cli)          ((cli)->cli_connect->con_error)
280 #define cli_snomask(cli)        ((cli)->cli_connect->con_snomask)
281 #define cli_nextnick(cli)       ((cli)->cli_connect->con_nextnick)
282 #define cli_nexttarget(cli)     ((cli)->cli_connect->con_nexttarget)
283 #define cli_cookie(cli)         ((cli)->cli_connect->con_cookie)
284 #define cli_sendQ(cli)          ((cli)->cli_connect->con_sendQ)
285 #define cli_recvQ(cli)          ((cli)->cli_connect->con_recvQ)
286 #define cli_sendM(cli)          ((cli)->cli_connect->con_sendM)
287 #define cli_sendK(cli)          ((cli)->cli_connect->con_sendK)
288 #define cli_receiveM(cli)       ((cli)->cli_connect->con_receiveM)
289 #define cli_receiveK(cli)       ((cli)->cli_connect->con_receiveK)
290 #define cli_sendB(cli)          ((cli)->cli_connect->con_sendB)
291 #define cli_receiveB(cli)       ((cli)->cli_connect->con_receiveB)
292 #define cli_listener(cli)       ((cli)->cli_connect->con_listener)
293 #define cli_confs(cli)          ((cli)->cli_connect->con_confs)
294 #define cli_handler(cli)        ((cli)->cli_connect->con_handler)
295 #define cli_dns_reply(cli)      ((cli)->cli_connect->con_dns_reply)
296 #define cli_listing(cli)        ((cli)->cli_connect->con_listing)
297 #define cli_max_sendq(cli)      ((cli)->cli_connect->con_max_sendq)
298 #define cli_ping_freq(cli)      ((cli)->cli_connect->con_ping_freq)
299 #define cli_lastsq(cli)         ((cli)->cli_connect->con_lastsq)
300 #define cli_port(cli)           ((cli)->cli_connect->con_port)
301 #define cli_targets(cli)        ((cli)->cli_connect->con_targets)
302 #define cli_sock_ip(cli)        ((cli)->cli_connect->con_sock_ip)
303 #define cli_sockhost(cli)       ((cli)->cli_connect->con_sockhost)
304 #define cli_passwd(cli)         ((cli)->cli_connect->con_passwd)
305 #define cli_buffer(cli)         ((cli)->cli_connect->con_buffer)
306 #define cli_socket(cli)         ((cli)->cli_connect->con_socket)
307 #define cli_proc(cli)           ((cli)->cli_connect->con_proc)
308 #define cli_auth(cli)           ((cli)->cli_connect->con_auth)
309
310 #define con_verify(con)         ((con)->con_magic == CONNECTION_MAGIC)
311 #define con_magic(con)          ((con)->con_magic)
312 #define con_next(con)           ((con)->con_next)
313 #define con_prev_p(con)         ((con)->con_prev_p)
314 #define con_client(con)         ((con)->con_client)
315 #define con_count(con)          ((con)->con_count)
316 #define con_fd(con)             ((con)->con_fd)
317 #define con_freeflag(con)       ((con)->con_freeflag)
318 #define con_error(con)          ((con)->con_error)
319 #define con_snomask(con)        ((con)->con_snomask)
320 #define con_nextnick(con)       ((con)->con_nextnick)
321 #define con_nexttarget(con)     ((con)->con_nexttarget)
322 #define con_cookie(con)         ((con)->con_cookie)
323 #define con_sendQ(con)          ((con)->con_sendQ)
324 #define con_recvQ(con)          ((con)->con_recvQ)
325 #define con_sendM(con)          ((con)->con_sendM)
326 #define con_sendK(con)          ((con)->con_sendK)
327 #define con_receiveM(con)       ((con)->con_receiveM)
328 #define con_receiveK(con)       ((con)->con_receiveK)
329 #define con_sendB(con)          ((con)->con_sendB)
330 #define con_receiveB(con)       ((con)->con_receiveB)
331 #define con_listener(con)       ((con)->con_listener)
332 #define con_confs(con)          ((con)->con_confs)
333 #define con_handler(con)        ((con)->con_handler)
334 #define con_dns_reply(con)      ((con)->con_dns_reply)
335 #define con_listing(con)        ((con)->con_listing)
336 #define con_max_sendq(con)      ((con)->con_max_sendq)
337 #define con_ping_freq(con)      ((con)->con_ping_freq)
338 #define con_lastsq(con)         ((con)->con_lastsq)
339 #define con_port(con)           ((con)->con_port)
340 #define con_targets(con)        ((con)->con_targets)
341 #define con_sock_ip(con)        ((con)->con_sock_ip)
342 #define con_sockhost(con)       ((con)->con_sockhost)
343 #define con_passwd(con)         ((con)->con_passwd)
344 #define con_buffer(con)         ((con)->con_buffer)
345 #define con_socket(con)         ((con)->con_socket)
346 #define con_proc(con)           ((con)->con_proc)
347 #define con_auth(con)           ((con)->con_auth)
348
349 #define STAT_CONNECTING         0x001 /* connecting to another server */
350 #define STAT_HANDSHAKE          0x002 /* pass - server sent */
351 #define STAT_ME                 0x004 /* this server */
352 #define STAT_UNKNOWN            0x008 /* unidentified connection */
353 #define STAT_UNKNOWN_USER       0x010 /* Connect to client port */
354 #define STAT_UNKNOWN_SERVER     0x020 /* Connect to server port */
355 #define STAT_SERVER             0x040
356 #define STAT_USER               0x080
357
358 /*
359  * status macros.
360  */
361 #define IsRegistered(x)         (cli_status(x) & (STAT_SERVER | STAT_USER))
362 #define IsConnecting(x)         (cli_status(x) == STAT_CONNECTING)
363 #define IsHandshake(x)          (cli_status(x) == STAT_HANDSHAKE)
364 #define IsMe(x)                 (cli_status(x) == STAT_ME)
365 #define IsUnknown(x)            (cli_status(x) & \
366         (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
367
368 #define IsServerPort(x)         (cli_status(x) == STAT_UNKNOWN_SERVER )
369 #define IsUserPort(x)           (cli_status(x) == STAT_UNKNOWN_USER )
370 #define IsClient(x)             (cli_status(x) & \
371         (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
372          STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
373
374 #define IsTrusted(x)            (cli_status(x) & \
375         (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
376
377 #define IsServer(x)             (cli_status(x) == STAT_SERVER)
378 #define IsUser(x)               (cli_status(x) == STAT_USER)
379
380
381 #define SetConnecting(x)        (cli_status(x) = STAT_CONNECTING)
382 #define SetHandshake(x)         (cli_status(x) = STAT_HANDSHAKE)
383 #define SetServer(x)            (cli_status(x) = STAT_SERVER)
384 #define SetMe(x)                (cli_status(x) = STAT_ME)
385 #define SetUser(x)              (cli_status(x) = STAT_USER)
386
387 #define MyConnect(x)    (cli_from(x) == (x))
388 #define MyUser(x)       (MyConnect(x) && IsUser(x))
389 #define MyOper(x)       (MyConnect(x) && IsOper(x))
390 #define Protocol(x)     ((cli_serv(x))->prot)
391
392 #define PARSE_AS_SERVER(x) (cli_status(x) & \
393             (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
394
395 /*
396  * flags macros
397  */
398 #define FlagSet(fset, flag) FLAGSET_SET(*fset, flag)
399 #define FlagClr(fset, flag) FLAGSET_CLEAR(*fset, flag)
400 #define FlagHas(fset, flag) FLAGSET_ISSET(*fset, flag)
401 #define SetFlag(cli, flag)      FlagSet(&cli_flags(cli), flag)
402 #define ClrFlag(cli, flag)      FlagClr(&cli_flags(cli), flag)
403 #define HasFlag(cli, flag)      FlagHas(&cli_flags(cli), flag)
404
405 #define DoAccess(x)             HasFlag(x, FLAG_CHKACCESS)
406 #define IsAnOper(x)             (HasFlag(x, FLAG_OPER) || HasFlag(x, FLAG_LOCOP))
407 #define IsBlocked(x)            HasFlag(x, FLAG_BLOCKED)
408 #define IsBurst(x)              HasFlag(x, FLAG_BURST)
409 #define IsBurstAck(x)           HasFlag(x, FLAG_BURST_ACK)
410 #define IsBurstOrBurstAck(x)    (HasFlag(x, FLAG_BURST) || HasFlag(x, FLAG_BURST_ACK))
411 #define IsChannelService(x)     HasFlag(x, FLAG_CHSERV)
412 #define IsDead(x)               HasFlag(x, FLAG_DEADSOCKET)
413 #define IsDeaf(x)               HasFlag(x, FLAG_DEAF)
414 #define IsIPChecked(x)          HasFlag(x, FLAG_IPCHECK)
415 #define IsIdented(x)            HasFlag(x, FLAG_GOTID)
416 #define IsInvisible(x)          HasFlag(x, FLAG_INVISIBLE)
417 #define IsJunction(x)           HasFlag(x, FLAG_JUNCTION)
418 #define IsLocOp(x)              HasFlag(x, FLAG_LOCOP)
419 #define IsLocal(x)              HasFlag(x, FLAG_LOCAL)
420 #define IsOper(x)               HasFlag(x, FLAG_OPER)
421 #define IsUPing(x)              HasFlag(x, FLAG_UPING)
422 #define NoNewLine(x)            HasFlag(x, FLAG_NONL)
423 #define SendDebug(x)            HasFlag(x, FLAG_DEBUG)
424 #define SendServNotice(x)       HasFlag(x, FLAG_SERVNOTICE)
425 #define SendWallops(x)          HasFlag(x, FLAG_WALLOP)
426 #define IsHub(x)                HasFlag(x, FLAG_HUB)
427 #define IsService(x)            HasFlag(x, FLAG_SERVICE)
428 #define IsAccount(x)            HasFlag(x, FLAG_ACCOUNT)
429 #define IsHiddenHost(x)         HasFlag(x, FLAG_HIDDENHOST)
430 #define IsPingSent(x)           HasFlag(x, FLAG_PINGSENT)
431
432 #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
433 #define HasHiddenHost(x)        (IsHiddenHost(x) && IsAccount(x))
434
435 #define SetAccess(x)            SetFlag(x, FLAG_CHKACCESS)
436 #define SetBurst(x)             SetFlag(x, FLAG_BURST)
437 #define SetBurstAck(x)          SetFlag(x, FLAG_BURST_ACK)
438 #define SetChannelService(x)    SetFlag(x, FLAG_CHSERV)
439 #define SetDeaf(x)              SetFlag(x, FLAG_DEAF)
440 #define SetDebug(x)             SetFlag(x, FLAG_DEBUG)
441 #define SetGotId(x)             SetFlag(x, FLAG_GOTID)
442 #define SetIPChecked(x)         SetFlag(x, FLAG_IPCHECK)
443 #define SetInvisible(x)         SetFlag(x, FLAG_INVISIBLE)
444 #define SetJunction(x)          SetFlag(x, FLAG_JUNCTION)
445 #define SetLocOp(x)             SetFlag(x, FLAG_LOCOP)
446 #define SetOper(x)              SetFlag(x, FLAG_OPER)
447 #define SetUPing(x)             SetFlag(x, FLAG_UPING)
448 #define SetWallops(x)           SetFlag(x, FLAG_WALLOP)
449 #define SetServNotice(x)        SetFlag(x, FLAG_SERVNOTICE)
450 #define SetHub(x)               SetFlag(x, FLAG_HUB)
451 #define SetService(x)           SetFlag(x, FLAG_SERVICE)
452 #define SetAccount(x)           SetFlag(x, FLAG_ACCOUNT)
453 #define SetHiddenHost(x)        SetFlag(x, FLAG_HIDDENHOST)
454 #define SetPingSent(x)          SetFlag(x, FLAG_PINGSENT)
455
456 #define ClearAccess(x)          ClrFlag(x, FLAG_CHKACCESS)
457 #define ClearBurst(x)           ClrFlag(x, FLAG_BURST)
458 #define ClearBurstAck(x)        ClrFlag(x, FLAG_BURST_ACK)
459 #define ClearChannelService(x)  ClrFlag(x, FLAG_CHSERV)
460 #define ClearDeaf(x)            ClrFlag(x, FLAG_DEAF)
461 #define ClearDebug(x)           ClrFlag(x, FLAG_DEBUG)
462 #define ClearIPChecked(x)       ClrFlag(x, FLAG_IPCHECK)
463 #define ClearInvisible(x)       ClrFlag(x, FLAG_INVISIBLE)
464 #define ClearLocOp(x)           ClrFlag(x, FLAG_LOCOP)
465 #define ClearOper(x)            ClrFlag(x, FLAG_OPER)
466 #define ClearUPing(x)           ClrFlag(x, FLAG_UPING)
467 #define ClearWallops(x)         ClrFlag(x, FLAG_WALLOP)
468 #define ClearServNotice(x)      ClrFlag(x, FLAG_SERVNOTICE)
469 #define ClearHiddenHost(x)      ClrFlag(x, FLAG_HIDDENHOST)
470 #define ClearPingSent(x)        ClrFlag(x, FLAG_PINGSENT)
471
472 /* free flags */
473 #define FREEFLAG_SOCKET 0x0001  /* socket needs to be freed */
474 #define FREEFLAG_TIMER  0x0002  /* timer needs to be freed */
475
476 /* server notice stuff */
477
478 #define SNO_ADD         1
479 #define SNO_DEL         2
480 #define SNO_SET         3
481                                 /* DON'T CHANGE THESE VALUES ! */
482                                 /* THE CLIENTS DEPEND ON IT  ! */
483 #define SNO_OLDSNO      0x1     /* unsorted old messages */
484 #define SNO_SERVKILL    0x2     /* server kills (nick collisions) */
485 #define SNO_OPERKILL    0x4     /* oper kills */
486 #define SNO_HACK2       0x8     /* desyncs */
487 #define SNO_HACK3       0x10    /* temporary desyncs */
488 #define SNO_UNAUTH      0x20    /* unauthorized connections */
489 #define SNO_TCPCOMMON   0x40    /* common TCP or socket errors */
490 #define SNO_TOOMANY     0x80    /* too many connections */
491 #define SNO_HACK4       0x100   /* Uworld actions on channels */
492 #define SNO_GLINE       0x200   /* glines */
493 #define SNO_NETWORK     0x400   /* net join/break, etc */
494 #define SNO_IPMISMATCH  0x800   /* IP mismatches */
495 #define SNO_THROTTLE    0x1000  /* host throttle add/remove notices */
496 #define SNO_OLDREALOP   0x2000  /* old oper-only messages */
497 #define SNO_CONNEXIT    0x4000  /* client connect/exit (ugh) */
498 #define SNO_AUTO        0x8000  /* AUTO G-Lines */
499 #define SNO_DEBUG       0x10000 /* debugging messages (DEBUGMODE only) */
500
501 #ifdef DEBUGMODE
502 # define SNO_ALL        0x1ffff  /* Don't make it larger then significant,
503                                   * that looks nicer */
504 #else
505 # define SNO_ALL        0xffff
506 #endif
507
508 #define SNO_USER        (SNO_ALL & ~SNO_OPER)
509
510 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
511 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
512 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
513 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
514
515 #define PrivSet(fset, flag) FLAGSET_SET(*fset, flag)
516 #define PrivClr(fset, flag) FLAGSET_CLEAR(*fset, flag)
517 #define PrivHas(fset, flag) FLAGSET_ISSET(*fset, flag)
518
519 #define GrantPriv(cli, priv)    (PrivSet(&(cli_privs(cli)), priv))
520 #define RevokePriv(cli, priv)   (PrivClr(&(cli_privs(cli)), priv))
521 #define HasPriv(cli, priv)      (PrivHas(&(cli_privs(cli)), priv))
522
523 typedef enum ShowIPType {
524   HIDE_IP,
525   SHOW_IP,
526   MASK_IP
527 } ShowIPType;
528
529 extern const char* get_client_name(const struct Client* sptr, int showip);
530 extern int client_get_ping(const struct Client* local_client);
531 extern void client_drop_sendq(struct Connection* con);
532 extern void client_add_sendq(struct Connection* con,
533                              struct Connection** con_p);
534 extern void client_set_privs(struct Client *client, struct ConfItem *oper);
535 extern int client_report_privs(struct Client* to, struct Client* client);
536
537 #endif /* INCLUDED_client_h */
538