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