Author: Kev <klmitch@mit.edu>
[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_config_h
29 #include "config.h"
30 #endif
31 #ifndef INCLUDED_dbuf_h
32 #include "dbuf.h"
33 #endif
34 #ifndef INCLUDED_msgq_h
35 #include "msgq.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
59 /*-----------------------------------------------------------------------------
60  * Macros
61  */
62 #define CLIENT_LOCAL_SIZE sizeof(struct Client)
63 #define CLIENT_REMOTE_SIZE offsetof(struct Client, cli_count)
64
65 /*
66  * Structures
67  *
68  * Only put structures here that are being used in a very large number of
69  * source files. Other structures go in the header file of there corresponding
70  * source file, or in the source file itself (when only used in that file).
71  */
72
73 struct Client {
74   struct Client* cli_next;          /* link in GlobalClientList */
75   struct Client* cli_prev;          /* link in GlobalClientList */
76   struct Client* cli_hnext;         /* link in hash table bucket or this */
77   struct Client* cli_from;          /* == self, if Local Client, *NEVER* NULL! */
78   struct User*   cli_user;          /* ...defined, if this is a User */
79   struct Server* cli_serv;          /* ...defined, if this is a server */
80   struct Whowas* cli_whowas;        /* Pointer to ww struct to be freed on quit */
81   char           cli_yxx[4];        /* Numeric Nick: YMM if this is a server,
82                                    XX0 if this is a user */
83   /*
84    * XXX - move these to local part for next release
85    * (lasttime, since)
86    */
87   time_t         cli_lasttime;      /* last time data read from socket */
88   time_t         cli_since;         /* last time we parsed something, flood control */
89
90   time_t         cli_firsttime;     /* time client was created */
91   time_t         cli_lastnick;      /* TimeStamp on nick */
92   int            cli_marker;        /* /who processing marker */
93   unsigned int   cli_flags;         /* client flags */
94   unsigned int   cli_hopcount;      /* number of servers to this 0 = local */
95   struct in_addr cli_ip;            /* Real ip# NOT defined for remote servers! */
96   short          cli_status;        /* Client type */
97   unsigned char  cli_local;         /* local or remote client */
98   char cli_name[HOSTLEN + 1];       /* Unique name of the client, nick or host */
99   char cli_username[USERLEN + 1];   /* username here now for auth stuff */
100   char cli_info[REALLEN + 1];       /* Free form additional client information */
101   /*
102    *  The following fields are allocated only for local clients
103    *  (directly connected to *this* server with a socket.
104    *  The first of them *MUST* be the "count"--it is the field
105    *  to which the allocation is tied to! *Never* refer to
106    *  these fields, if (from != self).
107    */
108   unsigned int cli_count;            /* Amount of data in buffer, DON'T PUT
109                                     variables ABOVE this one! */
110   int                 cli_fd;        /* >= 0, for local clients */
111   int                 cli_error;     /* last socket level error for client */
112   unsigned int        cli_snomask;   /* mask for server messages */
113   time_t              cli_nextnick;  /* Next time a nick change is allowed */
114   time_t              cli_nexttarget; /* Next time a target change is allowed */
115   unsigned int        cli_cookie;    /* Random number the user must PONG */
116   struct MsgQ         cli_sendQ;     /* Outgoing message queue--if socket full */
117   struct DBuf         cli_recvQ;     /* Hold for data incoming yet to be parsed */
118   unsigned int        cli_sendM;     /* Statistics: protocol messages send */
119   unsigned int        cli_sendK;     /* Statistics: total k-bytes send */
120   unsigned int        cli_receiveM;  /* Statistics: protocol messages received */
121   unsigned int        cli_receiveK;  /* Statistics: total k-bytes received */
122   unsigned short      cli_sendB;     /* counters to count upto 1-k lots of bytes */
123   unsigned short      cli_receiveB;  /* sent and received. */
124   struct Listener*    cli_listener;  /* listening client which we accepted from */
125   struct SLink*       cli_confs;     /* Configuration record associated */
126   HandlerType         cli_handler;   /* message index into command table for parsing */
127   struct DNSReply*    cli_dns_reply; /* DNS reply used during client registration */
128   struct ListingArgs* cli_listing;
129   unsigned int        cli_max_sendq; /* cached max send queue for client */
130   unsigned int        cli_ping_freq; /* cached ping freq from client conf class */
131   unsigned short      cli_lastsq;    /* # 2k blocks when sendqueued called last */
132   unsigned short      cli_port;      /* and the remote port# too :-) */
133   unsigned char       cli_targets[MAXTARGETS]; /* Hash values of current targets */
134   char cli_sock_ip[SOCKIPLEN + 1];  /* this is the ip address as a string */
135   char cli_sockhost[HOSTLEN + 1];   /* This is the host name from the socket and
136                                    after which the connection was accepted. */
137   char cli_passwd[PASSWDLEN + 1];
138   char cli_buffer[BUFSIZE];         /* Incoming message buffer; or the error that
139                                    caused this clients socket to be `dead' */
140 };
141
142 #define cli_next(cli)           ((cli)->cli_next)
143 #define cli_prev(cli)           ((cli)->cli_prev)
144 #define cli_hnext(cli)          ((cli)->cli_hnext)
145 #define cli_from(cli)           ((cli)->cli_from)
146 #define cli_user(cli)           ((cli)->cli_user)
147 #define cli_serv(cli)           ((cli)->cli_serv)
148 #define cli_whowas(cli)         ((cli)->cli_whowas)
149 #define cli_yxx(cli)            ((cli)->cli_yxx)
150 #define cli_lasttime(cli)       ((cli)->cli_lasttime)
151 #define cli_since(cli)          ((cli)->cli_since)
152 #define cli_firsttime(cli)      ((cli)->cli_firsttime)
153 #define cli_lastnick(cli)       ((cli)->cli_lastnick)
154 #define cli_marker(cli)         ((cli)->cli_marker)
155 #define cli_flags(cli)          ((cli)->cli_flags)
156 #define cli_hopcount(cli)       ((cli)->cli_hopcount)
157 #define cli_ip(cli)             ((cli)->cli_ip)
158 #define cli_status(cli)         ((cli)->cli_status)
159 #define cli_local(cli)          ((cli)->cli_local)
160 #define cli_name(cli)           ((cli)->cli_name)
161 #define cli_username(cli)       ((cli)->cli_username)
162 #define cli_info(cli)           ((cli)->cli_info)
163
164 #define cli_count(cli)          ((cli)->cli_count)
165 #define cli_fd(cli)             ((cli)->cli_fd)
166 #define cli_error(cli)          ((cli)->cli_error)
167 #define cli_snomask(cli)        ((cli)->cli_snomask)
168 #define cli_nextnick(cli)       ((cli)->cli_nextnick)
169 #define cli_nexttarget(cli)     ((cli)->cli_nexttarget)
170 #define cli_cookie(cli)         ((cli)->cli_cookie)
171 #define cli_sendQ(cli)          ((cli)->cli_sendQ)
172 #define cli_recvQ(cli)          ((cli)->cli_recvQ)
173 #define cli_sendM(cli)          ((cli)->cli_sendM)
174 #define cli_sendK(cli)          ((cli)->cli_sendK)
175 #define cli_receiveM(cli)       ((cli)->cli_receiveM)
176 #define cli_receiveK(cli)       ((cli)->cli_receiveK)
177 #define cli_sendB(cli)          ((cli)->cli_sendB)
178 #define cli_receiveB(cli)       ((cli)->cli_receiveB)
179 #define cli_listener(cli)       ((cli)->cli_listener)
180 #define cli_confs(cli)          ((cli)->cli_confs)
181 #define cli_handler(cli)        ((cli)->cli_handler)
182 #define cli_dns_reply(cli)      ((cli)->cli_dns_reply)
183 #define cli_listing(cli)        ((cli)->cli_listing)
184 #define cli_max_sendq(cli)      ((cli)->cli_max_sendq)
185 #define cli_ping_freq(cli)      ((cli)->cli_ping_freq)
186 #define cli_lastsq(cli)         ((cli)->cli_lastsq)
187 #define cli_port(cli)           ((cli)->cli_port)
188 #define cli_targets(cli)        ((cli)->cli_targets)
189 #define cli_sock_ip(cli)        ((cli)->cli_sock_ip)
190 #define cli_sockhost(cli)       ((cli)->cli_sockhost)
191 #define cli_passwd(cli)         ((cli)->cli_passwd)
192 #define cli_buffer(cli)         ((cli)->cli_buffer)
193
194 #define STAT_CONNECTING         0x001 /* connecting to another server */
195 #define STAT_HANDSHAKE          0x002 /* pass - server sent */
196 #define STAT_ME                 0x004 /* this server */
197 #define STAT_UNKNOWN            0x008 /* unidentified connection */
198 #define STAT_UNKNOWN_USER       0x010 /* Connect to client port */
199 #define STAT_UNKNOWN_SERVER     0x020 /* Connect to server port */
200 #define STAT_SERVER             0x040
201 #define STAT_USER               0x080
202
203 /*
204  * status macros.
205  */
206 #define IsRegistered(x)         (cli_status(x) & (STAT_SERVER | STAT_USER))
207 #define IsConnecting(x)         (cli_status(x) == STAT_CONNECTING)
208 #define IsHandshake(x)          (cli_status(x) == STAT_HANDSHAKE)
209 #define IsMe(x)                 (cli_status(x) == STAT_ME)
210 #define IsUnknown(x)            (cli_status(x) & \
211         (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
212
213 #define IsServerPort(x)         (cli_status(x) == STAT_UNKNOWN_SERVER )
214 #define IsUserPort(x)           (cli_status(x) == STAT_UNKNOWN_USER )
215 #define IsClient(x)             (cli_status(x) & \
216         (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
217          STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
218
219 #define IsTrusted(x)            (cli_status(x) & \
220         (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
221
222 #define IsServer(x)             (cli_status(x) == STAT_SERVER)
223 #define IsUser(x)               (cli_status(x) == STAT_USER)
224
225
226 #define SetConnecting(x)        (cli_status(x) = STAT_CONNECTING)
227 #define SetHandshake(x)         (cli_status(x) = STAT_HANDSHAKE)
228 #define SetServer(x)            (cli_status(x) = STAT_SERVER)
229 #define SetMe(x)                (cli_status(x) = STAT_ME)
230 #define SetUser(x)              (cli_status(x) = STAT_USER)
231
232 #define MyConnect(x)    (cli_from(x) == (x))
233 #define MyUser(x)       (MyConnect(x) && IsUser(x))
234 #define MyOper(x)       (MyConnect(x) && IsOper(x))
235 #define Protocol(x)     ((cli_serv(x))->prot)
236
237 #define PARSE_AS_SERVER(x) (cli_status(x) & \
238             (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
239
240 /*
241  * FLAGS macros
242  */
243 #define FLAGS_PINGSENT   0x0001 /* Unreplied ping sent */
244 #define FLAGS_DEADSOCKET 0x0002 /* Local socket is dead--Exiting soon */
245 #define FLAGS_KILLED     0x0004 /* Prevents "QUIT" from being sent for this */
246 #define FLAGS_OPER       0x0008 /* Operator */
247 #define FLAGS_LOCOP      0x0010 /* Local operator -- SRB */
248 #define FLAGS_INVISIBLE  0x0020 /* makes user invisible */
249 #define FLAGS_WALLOP     0x0040 /* send wallops to them */
250 #define FLAGS_SERVNOTICE 0x0080 /* server notices such as kill */
251 #define FLAGS_BLOCKED    0x0100 /* socket is in a blocked condition */
252 #define FLAGS_CLOSING    0x0400 /* set when closing to suppress errors */
253 #define FLAGS_UPING      0x0800 /* has active UDP ping request */
254 #define FLAGS_CHKACCESS  0x1000 /* ok to check clients access if set */
255 #define FLAGS_LOCAL     0x00010000      /* set for local clients */
256 #define FLAGS_GOTID     0x00020000      /* successful ident lookup achieved */
257 #define FLAGS_DOID      0x00040000      /* I-lines say must use ident return */
258 #define FLAGS_NONL      0x00080000      /* No \n in buffer */
259 #define FLAGS_TS8       0x00100000      /* Why do you want to know? */
260 #define FLAGS_MAP       0x00800000      /* Show server on the map */
261 #define FLAGS_JUNCTION  0x01000000      /* Junction causing the net.burst */
262 #define FLAGS_DEAF      0x02000000      /* Makes user deaf */
263 #define FLAGS_CHSERV    0x04000000      /* Disallow KICK or MODE -o on the user;
264                                            don't display channels in /whois */
265 #define FLAGS_BURST     0x08000000      /* Server is receiving a net.burst */
266 #define FLAGS_BURST_ACK 0x10000000      /* Server is waiting for eob ack */
267 #define FLAGS_DEBUG     0x20000000      /* send global debug/anti-hack info */
268 #define FLAGS_IPCHECK   0x40000000      /* Added or updated IPregistry data */
269
270 #define SEND_UMODES \
271     (FLAGS_INVISIBLE|FLAGS_OPER|FLAGS_WALLOP|FLAGS_DEAF|FLAGS_CHSERV|FLAGS_DEBUG)
272 #define ALL_UMODES (SEND_UMODES|FLAGS_SERVNOTICE|FLAGS_LOCOP)
273 #define FLAGS_ID (FLAGS_DOID|FLAGS_GOTID)
274
275 /*
276  * flags macros.
277  */
278 #define DoAccess(x)             (cli_flags(x) & FLAGS_CHKACCESS)
279 #define IsAnOper(x)             (cli_flags(x) & (FLAGS_OPER|FLAGS_LOCOP))
280 #define IsBlocked(x)            (cli_flags(x) & FLAGS_BLOCKED)
281 #define IsBurst(x)              (cli_flags(x) & FLAGS_BURST)
282 #define IsBurstAck(x)           (cli_flags(x) & FLAGS_BURST_ACK)
283 #define IsBurstOrBurstAck(x)    (cli_flags(x) & (FLAGS_BURST|FLAGS_BURST_ACK))
284 #define IsChannelService(x)     (cli_flags(x) & FLAGS_CHSERV)
285 #define IsDead(x)               (cli_flags(x) & FLAGS_DEADSOCKET)
286 #define IsDeaf(x)               (cli_flags(x) & FLAGS_DEAF)
287 #define IsIPChecked(x)          (cli_flags(x) & FLAGS_IPCHECK)
288 #define IsIdented(x)            (cli_flags(x) & FLAGS_GOTID)
289 #define IsInvisible(x)          (cli_flags(x) & FLAGS_INVISIBLE)
290 #define IsJunction(x)           (cli_flags(x) & FLAGS_JUNCTION)
291 #define IsLocOp(x)              (cli_flags(x) & FLAGS_LOCOP)
292 #define IsLocal(x)              (cli_flags(x) & FLAGS_LOCAL)
293 #define IsOper(x)               (cli_flags(x) & FLAGS_OPER)
294 #define IsUPing(x)              (cli_flags(x) & FLAGS_UPING)
295 #define NoNewLine(x)            (cli_flags(x) & FLAGS_NONL)
296 #define SendDebug(x)            (cli_flags(x) & FLAGS_DEBUG)
297 #define SendServNotice(x)       (cli_flags(x) & FLAGS_SERVNOTICE)
298 #define SendWallops(x)          (cli_flags(x) & FLAGS_WALLOP)
299
300 #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
301
302 #define SetAccess(x)            (cli_flags(x) |= FLAGS_CHKACCESS)
303 #define SetBurst(x)             (cli_flags(x) |= FLAGS_BURST)
304 #define SetBurstAck(x)          (cli_flags(x) |= FLAGS_BURST_ACK)
305 #define SetChannelService(x)    (cli_flags(x) |= FLAGS_CHSERV)
306 #define SetDeaf(x)              (cli_flags(x) |= FLAGS_DEAF)
307 #define SetDebug(x)             (cli_flags(x) |= FLAGS_DEBUG)
308 #define SetGotId(x)             (cli_flags(x) |= FLAGS_GOTID)
309 #define SetIPChecked(x)         (cli_flags(x) |= FLAGS_IPCHECK)
310 #define SetInvisible(x)         (cli_flags(x) |= FLAGS_INVISIBLE)
311 #define SetJunction(x)          (cli_flags(x) |= FLAGS_JUNCTION)
312 #define SetLocOp(x)             (cli_flags(x) |= FLAGS_LOCOP)
313 #define SetOper(x)              (cli_flags(x) |= FLAGS_OPER)
314 #define SetUPing(x)             (cli_flags(x) |= FLAGS_UPING)
315 #define SetWallops(x)           (cli_flags(x) |= FLAGS_WALLOP)
316
317 #define ClearAccess(x)          (cli_flags(x) &= ~FLAGS_CHKACCESS)
318 #define ClearBurst(x)           (cli_flags(x) &= ~FLAGS_BURST)
319 #define ClearBurstAck(x)        (cli_flags(x) &= ~FLAGS_BURST_ACK)
320 #define ClearChannelService(x)  (cli_flags(x) &= ~FLAGS_CHSERV)
321 #define ClearDeaf(x)            (cli_flags(x) &= ~FLAGS_DEAF)
322 #define ClearDebug(x)           (cli_flags(x) &= ~FLAGS_DEBUG)
323 #define ClearIPChecked(x)       (cli_flags(x) &= ~FLAGS_IPCHECK)
324 #define ClearInvisible(x)       (cli_flags(x) &= ~FLAGS_INVISIBLE)
325 #define ClearLocOp(x)           (cli_flags(x) &= ~FLAGS_LOCOP)
326 #define ClearOper(x)            (cli_flags(x) &= ~FLAGS_OPER)
327 #define ClearUPing(x)           (cli_flags(x) &= ~FLAGS_UPING)
328 #define ClearWallops(x)         (cli_flags(x) &= ~FLAGS_WALLOP)
329
330 /* server notice stuff */
331
332 #define SNO_ADD         1
333 #define SNO_DEL         2
334 #define SNO_SET         3
335                                 /* DON'T CHANGE THESE VALUES ! */
336                                 /* THE CLIENTS DEPEND ON IT  ! */
337 #define SNO_OLDSNO      0x1     /* unsorted old messages */
338 #define SNO_SERVKILL    0x2     /* server kills (nick collisions) */
339 #define SNO_OPERKILL    0x4     /* oper kills */
340 #define SNO_HACK2       0x8     /* desyncs */
341 #define SNO_HACK3       0x10    /* temporary desyncs */
342 #define SNO_UNAUTH      0x20    /* unauthorized connections */
343 #define SNO_TCPCOMMON   0x40    /* common TCP or socket errors */
344 #define SNO_TOOMANY     0x80    /* too many connections */
345 #define SNO_HACK4       0x100   /* Uworld actions on channels */
346 #define SNO_GLINE       0x200   /* glines */
347 #define SNO_NETWORK     0x400   /* net join/break, etc */
348 #define SNO_IPMISMATCH  0x800   /* IP mismatches */
349 #define SNO_THROTTLE    0x1000  /* host throttle add/remove notices */
350 #define SNO_OLDREALOP   0x2000  /* old oper-only messages */
351 #define SNO_CONNEXIT    0x4000  /* client connect/exit (ugh) */
352 #define SNO_DEBUG       0x8000  /* debugging messages (DEBUGMODE only) */
353
354 #ifdef DEBUGMODE
355 # define SNO_ALL        0xffff  /* Don't make it larger then significant,
356                                  * that looks nicer */
357 #else
358 # define SNO_ALL        0x7fff
359 #endif
360
361 #define SNO_USER        (SNO_ALL & ~SNO_OPER)
362
363 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
364 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
365 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
366 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
367
368 typedef enum ShowIPType {
369   HIDE_IP,
370   SHOW_IP,
371   MASK_IP
372 } ShowIPType;
373
374 extern const char* get_client_name(const struct Client* sptr, int showip);
375 extern int client_get_ping(const struct Client* local_client);
376
377
378 #endif /* INCLUDED_client_h */
379