2 * IRC - Internet Relay Chat, include/client.h
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
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)
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.
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.
23 #ifndef INCLUDED_client_h
24 #define INCLUDED_client_h
25 #ifndef INCLUDED_ircd_defs_h
26 #include "ircd_defs.h"
28 #ifndef INCLUDED_config_h
31 #ifndef INCLUDED_dbuf_h
34 #ifndef INCLUDED_msgq_h
37 #ifndef INCLUDED_ircd_handler_h
38 #include "ircd_handler.h"
40 #ifndef INCLUDED_sys_types_h
41 #include <sys/types.h> /* time_t, size_t */
42 #define INCLUDED_sys_types_h
44 #ifndef INCLUDED_netinet_in_h
45 #include <netinet/in.h> /* in_addr */
46 #define INCLUDED_netinet_in_h
59 /*-----------------------------------------------------------------------------
62 #define CLIENT_LOCAL_SIZE sizeof(struct Client)
63 #define CLIENT_REMOTE_SIZE offsetof(struct Client, count)
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).
74 struct Client* next; /* link in GlobalClientList */
75 struct Client* prev; /* link in GlobalClientList */
76 struct Client* hnext; /* link in hash table bucket or this */
77 struct Client* from; /* == self, if Local Client, *NEVER* NULL! */
78 struct User* user; /* ...defined, if this is a User */
79 struct Server* serv; /* ...defined, if this is a server */
80 struct Whowas* whowas; /* Pointer to ww struct to be freed on quit */
81 char yxx[4]; /* Numeric Nick: YMM if this is a server,
82 XX0 if this is a user */
84 * XXX - move these to local part for next release
87 time_t lasttime; /* last time data read from socket */
88 time_t since; /* last time we parsed something, flood control */
90 time_t firsttime; /* time client was created */
91 time_t lastnick; /* TimeStamp on nick */
92 int marker; /* /who processing marker */
93 unsigned int flags; /* client flags */
94 unsigned int hopcount; /* number of servers to this 0 = local */
95 struct in_addr ip; /* Real ip# NOT defined for remote servers! */
96 short status; /* Client type */
97 unsigned char local; /* local or remote client */
98 char name[HOSTLEN + 1]; /* Unique name of the client, nick or host */
99 char username[USERLEN + 1]; /* username here now for auth stuff */
100 char info[REALLEN + 1]; /* Free form additional client information */
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).
108 unsigned int count; /* Amount of data in buffer, DON'T PUT
109 variables ABOVE this one! */
110 int fd; /* >= 0, for local clients */
111 int error; /* last socket level error for client */
112 unsigned int snomask; /* mask for server messages */
113 time_t nextnick; /* Next time a nick change is allowed */
114 time_t nexttarget; /* Next time a target change is allowed */
115 unsigned int cookie; /* Random number the user must PONG */
116 struct MsgQ sendQ; /* Outgoing message queue--if socket full */
117 struct DBuf recvQ; /* Hold for data incoming yet to be parsed */
118 unsigned int sendM; /* Statistics: protocol messages send */
119 unsigned int sendK; /* Statistics: total k-bytes send */
120 unsigned int receiveM; /* Statistics: protocol messages received */
121 unsigned int receiveK; /* Statistics: total k-bytes received */
122 unsigned short sendB; /* counters to count upto 1-k lots of bytes */
123 unsigned short receiveB; /* sent and received. */
124 struct Listener* listener; /* listening client which we accepted from */
125 struct SLink* confs; /* Configuration record associated */
126 HandlerType handler; /* message index into command table for parsing */
127 struct DNSReply* dns_reply; /* DNS reply used during client registration */
128 struct ListingArgs* listing;
129 unsigned int max_sendq; /* cached max send queue for client */
130 unsigned int ping_freq; /* cached ping freq from client conf class */
131 unsigned short lastsq; /* # 2k blocks when sendqueued called last */
132 unsigned short port; /* and the remote port# too :-) */
133 unsigned char targets[MAXTARGETS]; /* Hash values of current targets */
134 char sock_ip[SOCKIPLEN + 1]; /* this is the ip address as a string */
135 char sockhost[HOSTLEN + 1]; /* This is the host name from the socket and
136 after which the connection was accepted. */
137 char passwd[PASSWDLEN + 1];
138 char buffer[BUFSIZE]; /* Incoming message buffer; or the error that
139 caused this clients socket to be `dead' */
142 #define cli_next(cli) ((cli)->next)
143 #define cli_prev(cli) ((cli)->prev)
144 #define cli_hnext(cli) ((cli)->hnext)
145 #define cli_from(cli) ((cli)->from)
146 #define cli_user(cli) ((cli)->user)
147 #define cli_serv(cli) ((cli)->serv)
148 #define cli_whowas(cli) ((cli)->whowas)
149 #define cli_yxx(cli) ((cli)->yxx)
150 #define cli_lasttime(cli) ((cli)->lasttime)
151 #define cli_since(cli) ((cli)->since)
152 #define cli_firsttime(cli) ((cli)->firsttime)
153 #define cli_lastnick(cli) ((cli)->lastnick)
154 #define cli_marker(cli) ((cli)->marker)
155 #define cli_flags(cli) ((cli)->flags)
156 #define cli_hopcount(cli) ((cli)->hopcount)
157 #define cli_ip(cli) ((cli)->ip)
158 #define cli_status(cli) ((cli)->status)
159 #define cli_local(cli) ((cli)->local)
160 #define cli_name(cli) ((cli)->name)
161 #define cli_username(cli) ((cli)->username)
162 #define cli_info(cli) ((cli)->info)
164 #define con_count(con) ((con)->count)
165 #define con_fd(con) ((con)->fd)
166 #define con_error(con) ((con)->error)
167 #define con_snomask(con) ((con)->snomask)
168 #define con_nextnick(con) ((con)->nextnick)
169 #define con_nexttarget(con) ((con)->nexttarget)
170 #define con_cookie(con) ((con)->cookie)
171 #define con_sendQ(con) ((con)->sendQ)
172 #define con_recvQ(con) ((con)->recvQ)
173 #define con_sendM(con) ((con)->sendM)
174 #define con_sendK(con) ((con)->sendK)
175 #define con_receiveM(con) ((con)->receiveM)
176 #define con_receiveK(con) ((con)->receiveK)
177 #define con_sendB(con) ((con)->sendB)
178 #define con_receiveB(con) ((con)->receiveB)
179 #define con_listener(con) ((con)->listener)
180 #define con_confs(con) ((con)->confs)
181 #define con_handler(con) ((con)->handler)
182 #define con_dns_reply(con) ((con)->dns_reply)
183 #define con_listing(con) ((con)->listing)
184 #define con_max_sendq(con) ((con)->max_sendq)
185 #define con_ping_freq(con) ((con)->ping_freq)
186 #define con_lastsq(con) ((con)->lastsq)
187 #define con_port(con) ((con)->port)
188 #define con_targets(con) ((con)->targets)
189 #define con_sock_ip(con) ((con)->sock_ip)
190 #define con_sockhost(con) ((con)->sockhost)
191 #define con_passwd(con) ((con)->passwd)
192 #define con_buffer(con) ((con)->buffer)
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
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))
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))
219 #define IsTrusted(x) (cli_status(x) & \
220 (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
222 #define IsServer(x) (cli_status(x) == STAT_SERVER)
223 #define IsUser(x) (cli_status(x) == STAT_USER)
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)
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)
237 #define PARSE_AS_SERVER(x) (cli_status(x) & \
238 (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
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 */
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)
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)
300 #define IsPrivileged(x) (IsAnOper(x) || IsServer(x))
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)
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)
330 /* server notice stuff */
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) */
355 # define SNO_ALL 0xffff /* Don't make it larger then significant,
356 * that looks nicer */
358 # define SNO_ALL 0x7fff
361 #define SNO_USER (SNO_ALL & ~SNO_OPER)
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)
368 typedef enum ShowIPType {
374 extern const char* get_client_name(const struct Client* sptr, int showip);
375 extern int client_get_ping(const struct Client* local_client);
378 #endif /* INCLUDED_client_h */