ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/client.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/client.c (file contents):
Revision 1783 by michael, Thu Jan 24 19:26:51 2013 UTC vs.
Revision 5551 by michael, Thu Feb 12 21:43:47 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  client.c: Controls clients.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
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
# Line 16 | Line 15
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file client.c
23 > * \brief Controls clients.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "client.h"
28 – #include "channel_mode.h"
30   #include "event.h"
30 – #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
33   #include "ircd.h"
34 – #include "s_gline.h"
34   #include "numeric.h"
35 < #include "packet.h"
37 < #include "s_auth.h"
35 > #include "auth.h"
36   #include "s_bsd.h"
37   #include "conf.h"
38   #include "log.h"
39 < #include "s_misc.h"
40 < #include "s_serv.h"
39 > #include "misc.h"
40 > #include "server.h"
41   #include "send.h"
42   #include "whowas.h"
43 < #include "s_user.h"
46 < #include "dbuf.h"
43 > #include "user.h"
44   #include "memory.h"
45   #include "mempool.h"
46   #include "hostmask.h"
47   #include "listener.h"
51 – #include "irc_res.h"
48   #include "userhost.h"
49   #include "watch.h"
50   #include "rng_mt.h"
51 + #include "parse.h"
52 + #include "ipcache.h"
53  
56 – dlink_list listing_client_list = { NULL, NULL, 0 };
57 – /* Pointer to beginning of Client list */
58 – dlink_list global_client_list = {NULL, NULL, 0};
59 – /* unknown/client pointer lists */
60 – dlink_list unknown_list = {NULL, NULL, 0};
61 – dlink_list local_client_list = {NULL, NULL, 0};
62 – dlink_list serv_list = {NULL, NULL, 0};
63 – dlink_list global_serv_list = {NULL, NULL, 0};
64 – dlink_list oper_list = {NULL, NULL, 0};
65 –
66 – static EVH check_pings;
54  
55 < static mp_pool_t *client_pool  = NULL;
56 < static mp_pool_t *lclient_pool = NULL;
57 <
58 < static dlink_list dead_list  = { NULL, NULL, 0};
59 < static dlink_list abort_list = { NULL, NULL, 0};
55 > dlink_list listing_client_list;
56 > dlink_list unknown_list;
57 > dlink_list local_client_list;
58 > dlink_list local_server_list;
59 > dlink_list global_client_list;
60 > dlink_list global_server_list;
61 > dlink_list oper_list;
62  
63 + static mp_pool_t *client_pool, *connection_pool;
64 + static dlink_list dead_list, abort_list;
65   static dlink_node *eac_next;  /* next aborted client to exit */
66  
76 – static void check_pings_list(dlink_list *);
77 – static void check_unknowns_list(void);
78 – static void ban_them(struct Client *, struct MaskItem *);
79 –
80 –
81 – /* init_client()
82 – *
83 – * inputs       - NONE
84 – * output       - NONE
85 – * side effects - initialize client free memory
86 – */
87 – void
88 – init_client(void)
89 – {
90 –  /* start off the check ping event ..  -- adrian
91 –   * Every 30 seconds is plenty -- db
92 –   */
93 –  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
94 –  lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT);
95 –  eventAdd("check_pings", check_pings, NULL, 5);
96 – }
67  
68   /*
69   * make_client - create a new Client struct and set it to initial state.
# Line 113 | Line 83 | init_client(void)
83   struct Client *
84   make_client(struct Client *from)
85   {
86 <  struct Client *client_p = mp_pool_get(client_pool);
117 <
118 <  memset(client_p, 0, sizeof(*client_p));
86 >  struct Client *const client_p = mp_pool_get(client_pool);
87  
88 <  if (from == NULL)
88 >  if (!from)
89    {
90 <    client_p->from                      = client_p; /* 'from' of local client is self! */
91 <    client_p->localClient               = mp_pool_get(lclient_pool);
92 <
93 <    memset(client_p->localClient, 0, sizeof(*client_p->localClient));
94 <
95 <    client_p->localClient->since        = CurrentTime;
128 <    client_p->localClient->lasttime     = CurrentTime;
129 <    client_p->localClient->firsttime    = CurrentTime;
130 <    client_p->localClient->registration = REG_INIT;
90 >    client_p->from = client_p;  /* 'from' of local client is self! */
91 >    client_p->connection = mp_pool_get(connection_pool);
92 >    client_p->connection->since = CurrentTime;
93 >    client_p->connection->lasttime = CurrentTime;
94 >    client_p->connection->firsttime = CurrentTime;
95 >    client_p->connection->registration = REG_INIT;
96  
97      /* as good a place as any... */
98 <    dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
98 >    dlinkAdd(client_p, &client_p->connection->lclient_node, &unknown_list);
99    }
100    else
101 <    client_p->from = from; /* 'from' of local client is self! */
101 >    client_p->from = from;
102  
103    client_p->idhnext = client_p;
104 <  client_p->hnext  = client_p;
105 <  client_p->status = STAT_UNKNOWN;
104 >  client_p->hnext = client_p;
105 >  SetUnknown(client_p);
106    strcpy(client_p->username, "unknown");
107 <  strcpy(client_p->svid, "0");
107 >  strcpy(client_p->account, "0");
108  
109    return client_p;
110   }
# Line 154 | Line 119 | make_client(struct Client *from)
119   static void
120   free_client(struct Client *client_p)
121   {
157 –  assert(client_p != NULL);
122    assert(client_p != &me);
123    assert(client_p->hnext == client_p);
124    assert(client_p->idhnext == client_p);
125    assert(client_p->channel.head == NULL);
126    assert(dlink_list_length(&client_p->channel) == 0);
127    assert(dlink_list_length(&client_p->whowas) == 0);
128 <  assert(!IsServer(client_p) || (IsServer(client_p) && client_p->serv));
128 >  assert(!IsServer(client_p) || client_p->serv);
129  
130    MyFree(client_p->serv);
131 +  MyFree(client_p->certfp);
132  
133    if (MyConnect(client_p))
134    {
135 <    assert(client_p->localClient->invited.head == NULL);
136 <    assert(dlink_list_length(&client_p->localClient->invited) == 0);
137 <    assert(dlink_list_length(&client_p->localClient->watches) == 0);
135 >    assert(client_p->connection->invited.head == NULL);
136 >    assert(dlink_list_length(&client_p->connection->invited) == 0);
137 >    assert(dlink_list_length(&client_p->connection->watches) == 0);
138      assert(IsClosing(client_p) && IsDead(client_p));
139  
140 <    MyFree(client_p->localClient->response);
141 <    MyFree(client_p->localClient->auth_oper);
140 >    MyFree(client_p->connection->challenge_response);
141 >    client_p->connection->challenge_response = NULL;
142 >    MyFree(client_p->connection->challenge_operator);
143 >    client_p->connection->challenge_operator = NULL;
144  
145      /*
146 <     * clean up extra sockets from P-lines which have been discarded.
146 >     * Clean up extra sockets from listen{} blocks which have been discarded.
147       */
148 <    if (client_p->localClient->listener)
148 >    if (client_p->connection->listener)
149      {
150 <      assert(0 < client_p->localClient->listener->ref_count);
151 <      if (0 == --client_p->localClient->listener->ref_count &&
185 <          !client_p->localClient->listener->active)
186 <        free_listener(client_p->localClient->listener);
150 >      listener_release(client_p->connection->listener);
151 >      client_p->connection->listener = NULL;
152      }
153  
154 <    dbuf_clear(&client_p->localClient->buf_recvq);
155 <    dbuf_clear(&client_p->localClient->buf_sendq);
154 >    dbuf_clear(&client_p->connection->buf_recvq);
155 >    dbuf_clear(&client_p->connection->buf_sendq);
156  
157 <    mp_pool_release(client_p->localClient);
157 >    mp_pool_release(client_p->connection);
158    }
159  
160    mp_pool_release(client_p);
161   }
162  
163 < /*
164 < * check_pings - go through the local client list and check activity
165 < * kill off stuff that should die
166 < *
202 < * inputs       - NOT USED (from event)
203 < * output       - next time_t when check_pings() should be called again
204 < * side effects -
205 < *
206 < *
207 < * A PING can be sent to clients as necessary.
208 < *
209 < * Client/Server ping outs are handled.
210 < */
163 > void
164 > client_clear_svstags(struct Client *client_p)
165 > {
166 >  dlink_node *node = NULL, *node_next = NULL;
167  
168 < /*
169 < * Addon from adrian. We used to call this after nextping seconds,
170 < * however I've changed it to run once a second. This is only for
215 < * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
216 < * run once a second makes life a lot easier - when a new client connects
217 < * and they need a ping in 4 seconds, if nextping was set to 20 seconds
218 < * we end up waiting 20 seconds. This is stupid. :-)
219 < * I will optimise (hah!) check_pings() once I've finished working on
220 < * tidying up other network IO evilnesses.
221 < *     -- adrian
222 < */
168 >  DLINK_FOREACH_SAFE(node, node_next, client_p->svstags.head)
169 >  {
170 >    struct ServicesTag *svstag = node->data;
171  
172 < static void
173 < check_pings(void *notused)
174 < {              
175 <  check_pings_list(&local_client_list);
228 <  check_pings_list(&serv_list);
229 <  check_unknowns_list();
172 >    dlinkDelete(&svstag->node, &client_p->svstags);
173 >    MyFree(svstag->tag);
174 >    MyFree(svstag);
175 >  }
176   }
177  
178   /* check_pings_list()
179   *
180   * inputs       - pointer to list to check
181   * output       - NONE
182 < * side effects -
182 > * side effects -
183   */
184   static void
185   check_pings_list(dlink_list *list)
186   {
187 <  char scratch[32];        /* way too generous but... */
187 >  char buf[IRCD_BUFSIZE] = "";
188    int ping = 0;      /* ping time value from client */
189 <  dlink_node *ptr = NULL, *next_ptr = NULL;
189 >  dlink_node *node = NULL, *node_next = NULL;
190  
191 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
191 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
192    {
193 <    struct Client *client_p = ptr->data;
193 >    struct Client *client_p = node->data;
194  
249 –    /*
250 –    ** Note: No need to notify opers here. It's
251 –    ** already done when "FLAGS_DEADSOCKET" is set.
252 –    */
195      if (IsDead(client_p))
196 <    {
255 <      /* Ignore it, its been exited already */
256 <      continue;
257 <    }
196 >      continue;  /* Ignore it, its been exited already */
197  
198      if (!IsRegistered(client_p))
199        ping = CONNECTTIMEOUT;
200      else
201 <      ping = get_client_ping(&client_p->localClient->confs);
201 >      ping = get_client_ping(&client_p->connection->confs);
202  
203 <    if (ping < CurrentTime - client_p->localClient->lasttime)
203 >    if (ping < CurrentTime - client_p->connection->lasttime)
204      {
205        if (!IsPingSent(client_p))
206        {
207 <        /*
208 <         * if we havent PINGed the connection and we havent
209 <         * heard from it in a while, PING it to make sure
210 <         * it is still alive.
211 <         */
212 <        SetPingSent(client_p);
213 <        client_p->localClient->lasttime = CurrentTime - ping;
214 <        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
207 >        /*
208 >         * If we haven't PINGed the connection and we haven't
209 >         * heard from it in a while, PING it to make sure
210 >         * it is still alive.
211 >         */
212 >        SetPingSent(client_p);
213 >        client_p->connection->lasttime = CurrentTime - ping;
214 >        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
215        }
216        else
217        {
218 <        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
218 >        if (CurrentTime - client_p->connection->lasttime >= 2 * ping)
219          {
220            /*
221             * If the client/server hasn't talked to us in 2*ping seconds
222             * and it has a ping time, then close its connection.
223             */
224            if (IsServer(client_p) || IsHandshake(client_p))
225 <          {
226 <            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
227 <                                 "No response from %s, closing link",
228 <                                 get_client_name(client_p, HIDE_IP));
229 <            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
230 <                                 "No response from %s, closing link",
231 <                                 get_client_name(client_p, MASK_IP));
232 <            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
233 <                 get_client_name(client_p, HIDE_IP));
234 <          }
235 <
236 <          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
237 <                   (int)(CurrentTime - client_p->localClient->lasttime));
238 <          exit_client(client_p, &me, scratch);
225 >          {
226 >            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
227 >                                 "No response from %s, closing link",
228 >                                 get_client_name(client_p, HIDE_IP));
229 >            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
230 >                                 "No response from %s, closing link",
231 >                                 get_client_name(client_p, MASK_IP));
232 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
233 >                 get_client_name(client_p, HIDE_IP));
234 >          }
235 >
236 >          snprintf(buf, sizeof(buf), "Ping timeout: %d seconds",
237 >                   (int)(CurrentTime - client_p->connection->lasttime));
238 >          exit_client(client_p, buf);
239          }
240        }
241      }
# Line 312 | Line 251 | check_pings_list(dlink_list *list)
251   static void
252   check_unknowns_list(void)
253   {
254 <  dlink_node *ptr, *next_ptr;
254 >  dlink_node *node = NULL, *node_next = NULL;
255  
256 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
256 >  DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
257    {
258 <    struct Client *client_p = ptr->data;
258 >    struct Client *client_p = node->data;
259  
260      /*
261       * Check UNKNOWN connections - if they have been in this state
262       * for > 30s, close them.
263       */
264 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
265 <      exit_client(client_p, &me, "Registration timed out");
264 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->connection->firsttime) > 30)
265 >      exit_client(client_p, "Registration timed out");
266    }
267   }
268  
269 + /*
270 + * check_pings - go through the local client list and check activity
271 + * kill off stuff that should die
272 + *
273 + * inputs       - NOT USED (from event)
274 + * output       - next time_t when check_pings() should be called again
275 + * side effects -
276 + *
277 + *
278 + * A PING can be sent to clients as necessary.
279 + *
280 + * Client/Server ping outs are handled.
281 + */
282 +
283 + /*
284 + * Addon from adrian. We used to call this after nextping seconds,
285 + * however I've changed it to run once a second. This is only for
286 + * PING timeouts, not K/etc-line checks (thanks dianora!). Having it
287 + * run once a second makes life a lot easier - when a new client connects
288 + * and they need a ping in 4 seconds, if nextping was set to 20 seconds
289 + * we end up waiting 20 seconds. This is stupid. :-)
290 + * I will optimise (hah!) check_pings() once I've finished working on
291 + * tidying up other network IO evilnesses.
292 + *     -- adrian
293 + */
294 +
295 + static void
296 + check_pings(void *unused)
297 + {
298 +  check_pings_list(&local_client_list);
299 +  check_pings_list(&local_server_list);
300 +  check_unknowns_list();
301 + }
302 +
303   /* check_conf_klines()
304   *
305   * inputs       - NONE
# Line 334 | Line 307 | check_unknowns_list(void)
307   * side effects - Check all connections for a pending kline against the
308   *                client, exit the client if a kline matches.
309   */
310 < void
310 > void
311   check_conf_klines(void)
312 < {              
340 <  struct Client *client_p = NULL;       /* current local client_p being examined */
312 > {
313    struct MaskItem *conf = NULL;
314 <  dlink_node *ptr, *next_ptr;
314 >  dlink_node *node = NULL, *node_next = NULL;
315  
316 <  DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
316 >  DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
317    {
318 <    client_p = ptr->data;
318 >    struct Client *client_p = node->data;
319  
320 <    /* If a client is already being exited
321 <     */
350 <    if (IsDead(client_p) || !IsClient(client_p))
320 >    /* If a client is already being exited */
321 >    if (IsDead(client_p))
322        continue;
323  
324 <    if ((conf = find_dline_conf(&client_p->localClient->ip,
325 <                                  client_p->localClient->aftype)) != NULL)
324 >    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
325 >                                     client_p->connection->aftype, NULL, NULL, 1)))
326      {
327 <      if (conf->type == CONF_EXEMPT)
357 <        continue;
358 <
359 <      ban_them(client_p, conf);
327 >      conf_try_ban(client_p, conf);
328        continue; /* and go examine next fd/client_p */
329      }
330  
331 <    if (ConfigFileEntry.glines && (conf = find_gline(client_p)))
331 >    if (ConfigGeneral.glines)
332      {
333 <      if (IsExemptKline(client_p) ||
334 <          IsExemptGline(client_p))
333 >      if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
334 >                                       CONF_GLINE, client_p->connection->aftype,
335 >                                       client_p->username, NULL, 1)))
336        {
337 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
338 <                             "GLINE over-ruled for %s, client is %sline_exempt",
370 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
337 >        conf_try_ban(client_p, conf);
338 >        /* and go examine next fd/client_p */
339          continue;
340        }
341 +    }
342  
343 <      ban_them(client_p, conf);
344 <      /* and go examine next fd/client_p */    
345 <      continue;
377 <    }
378 <
379 <    if ((conf = find_kill(client_p)) != NULL)
343 >    if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip,
344 >                                     CONF_KLINE, client_p->connection->aftype,
345 >                                     client_p->username, NULL, 1)))
346      {
347 <      if (IsExemptKline(client_p))
348 <      {
383 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
384 <                             "KLINE over-ruled for %s, client is kline_exempt",
385 <                             get_client_name(client_p, HIDE_IP));
386 <        continue;
387 <      }
388 <
389 <      ban_them(client_p, conf);
390 <      continue;
347 >      conf_try_ban(client_p, conf);
348 >      continue;
349      }
350  
351      if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
352 <                                        NULL, NULL, 0)) != NULL ||
395 <        (conf = find_matching_name_conf(CONF_RXLINE, client_p->info,
396 <                                        NULL, NULL, 0)) != NULL)
352 >                                        NULL, NULL, 0)))
353      {
354 <      ban_them(client_p, conf);
354 >      conf_try_ban(client_p, conf);
355        continue;
356      }
357    }
358  
359    /* also check the unknowns list for new dlines */
360 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
360 >  DLINK_FOREACH_SAFE(node, node_next, unknown_list.head)
361    {
362 <    client_p = ptr->data;
362 >    struct Client *client_p = node->data;
363  
364 <    if ((conf = find_dline_conf(&client_p->localClient->ip,
365 <                                 client_p->localClient->aftype)))
364 >    if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE,
365 >                                     client_p->connection->aftype, NULL, NULL, 1)))
366      {
367 <      if (conf->type == CONF_EXEMPT)
368 <        continue;
413 <
414 <      exit_client(client_p, &me, "D-lined");
367 >      conf_try_ban(client_p, conf);
368 >      continue; /* and go examine next fd/client_p */
369      }
370    }
371   }
372  
373   /*
374 < * ban_them
374 > * conf_try_ban
375   *
376   * inputs       - pointer to client to ban
377   *              - pointer to MaskItem
378   * output       - NONE
379   * side effects - given client_p is banned
380   */
381 < static void
382 < ban_them(struct Client *client_p, struct MaskItem *conf)
381 > void
382 > conf_try_ban(struct Client *client_p, struct MaskItem *conf)
383   {
384 <  const char *user_reason = NULL;       /* What is sent to user */
384 >  const char *user_reason = NULL;  /* What is sent to user */
385    const char *type_string = NULL;
386    const char dline_string[] = "D-line";
387    const char kline_string[] = "K-line";
# Line 436 | Line 390 | ban_them(struct Client *client_p, struct
390  
391    switch (conf->type)
392    {
439 –    case CONF_RKLINE:
393      case CONF_KLINE:
394 +      if (IsExemptKline(client_p))
395 +      {
396 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
397 +                             "KLINE over-ruled for %s, client is kline_exempt",
398 +                             get_client_name(client_p, HIDE_IP));
399 +        return;
400 +      }
401 +
402        type_string = kline_string;
403        break;
404      case CONF_DLINE:
405 +      if (find_conf_by_address(NULL, &client_p->connection->ip, CONF_EXEMPT,
406 +                               client_p->connection->aftype, NULL, NULL, 1))
407 +        return;
408        type_string = dline_string;
409        break;
410      case CONF_GLINE:
411 +      if (IsExemptKline(client_p) ||
412 +          IsExemptGline(client_p))
413 +      {
414 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
415 +                             "GLINE over-ruled for %s, client is %sline_exempt",
416 +                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
417 +        return;
418 +      }
419 +
420        type_string = gline_string;
421        break;
449 –    case CONF_RXLINE:
422      case CONF_XLINE:
423        type_string = xline_string;
424        ++conf->count;
# Line 462 | Line 434 | ban_them(struct Client *client_p, struct
434                         type_string, get_client_name(client_p, HIDE_IP));
435  
436    if (IsClient(client_p))
437 <    sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
466 <               me.name, client_p->name, user_reason);
437 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
438  
439 <  exit_client(client_p, &me, user_reason);
439 >  exit_client(client_p, user_reason);
440   }
441  
442   /* update_client_exit_stats()
443   *
444   * input        - pointer to client
445   * output       - NONE
446 < * side effects -
446 > * side effects -
447   */
448   static void
449   update_client_exit_stats(struct Client *client_p)
# Line 480 | Line 451 | update_client_exit_stats(struct Client *
451    if (IsClient(client_p))
452    {
453      assert(Count.total > 0);
454 +
455      --Count.total;
456      if (HasUMode(client_p, UMODE_OPER))
457        --Count.oper;
# Line 502 | Line 474 | update_client_exit_stats(struct Client *
474   * side effects - find person by (nick)name
475   */
476   struct Client *
477 < find_person(const struct Client *client_p, const char *name)
477 > find_person(const struct Client *const source_p, const char *name)
478   {
479 <  struct Client *c2ptr = NULL;
479 >  struct Client *target_p = NULL;
480  
481    if (IsDigit(*name))
482    {
483 <    if ((c2ptr = hash_find_id(name)) != NULL)
484 <    {
513 <      /* invisible users shall not be found by UID guessing */
514 <      if (HasUMode(c2ptr, UMODE_INVISIBLE))
515 <        if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE))
516 <          c2ptr = NULL;
517 <    }
483 >    if (IsServer(source_p->from))
484 >      target_p = hash_find_id(name);
485    }
486    else
487 <    c2ptr = hash_find_client(name);
487 >    target_p = hash_find_client(name);
488  
489 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
489 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
490   }
491  
492   /*
493 < * find_chasing - find the client structure for a nick name (user)
494 < *      using history mechanism if necessary. If the client is not found,
495 < *      an error message (NO SUCH NICK) is generated. If the client was found
529 < *      through the history, chasing will be 1 and otherwise 0.
493 > * find_chasing - find the client structure for a nick name (name)
494 > *      using history mechanism if necessary. If the client is not found,
495 > *      an error message (NO SUCH NICK) is generated.
496   */
497   struct Client *
498 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
498 > find_chasing(struct Client *source_p, const char *name)
499   {
500 <  struct Client *who = find_person(client_p, user);
500 >  struct Client *target_p = find_person(source_p, name);
501  
502 <  if (chasing)
503 <    *chasing = 0;
502 >  if (target_p)
503 >    return target_p;
504  
505 <  if (who)
540 <    return who;
541 <
542 <  if (IsDigit(*user))
505 >  if (IsDigit(*name))
506      return NULL;
507  
508 <  if ((who = get_history(user,
509 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
510 <                         == NULL)
508 >  target_p = whowas_get_history(name, (time_t)ConfigGeneral.kill_chase_time_limit);
509 >
510 >  if (!target_p)
511    {
512 <    sendto_one(source_p, form_str(ERR_NOSUCHNICK),
550 <               me.name, source_p->name, user);
512 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
513      return NULL;
514    }
515  
516 <  if (chasing)
555 <    *chasing = 1;
556 <
557 <  return who;
516 >  return target_p;
517   }
518  
519   /*
# Line 566 | Line 525 | find_chasing(struct Client *client_p, st
525   *        But, this can be used to any client structure.
526   *
527   * NOTE 1:
528 < *        Watch out the allocation of "nbuf", if either source_p->name
528 > *        Watch out the allocation of "buf", if either source_p->name
529   *        or source_p->sockhost gets changed into pointers instead of
530   *        directly allocated within the structure...
531   *
532   * NOTE 2:
533   *        Function return either a pointer to the structure (source_p) or
534 < *        to internal buffer (nbuf). *NEVER* use the returned pointer
534 > *        to internal buffer (buf). *NEVER* use the returned pointer
535   *        to modify what it points!!!
536   */
537   const char *
538 < get_client_name(const struct Client *client, enum addr_mask_type type)
538 > get_client_name(const struct Client *client_p, enum addr_mask_type type)
539   {
540 <  static char nbuf[HOSTLEN * 2 + USERLEN + 5];
582 <
583 <  assert(client != NULL);
540 >  static char buf[HOSTLEN * 2 + USERLEN + 5];
541  
542 <  if (!MyConnect(client))
543 <    return client->name;
542 >  if (!MyConnect(client_p))
543 >    return client_p->name;
544  
545 <  if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
545 >  if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
546    {
547 <    if (!irccmp(client->name, client->host))
548 <      return client->name;
547 >    if (!irccmp(client_p->name, client_p->host))
548 >      return client_p->name;
549      else if (ConfigServerHide.hide_server_ips)
550        type = MASK_IP;
551    }
552  
596 –  if (ConfigFileEntry.hide_spoof_ips)
597 –    if (type == SHOW_IP && IsIPSpoof(client))
598 –      type = MASK_IP;
599 –
553    /* And finally, let's get the host information, ip or name */
554    switch (type)
555    {
556      case SHOW_IP:
557 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
558 <               client->name,
559 <               client->username, client->sockhost);
557 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
558 >               client_p->name,
559 >               client_p->username, client_p->sockhost);
560        break;
561      case MASK_IP:
562 <      if (client->localClient->aftype == AF_INET)
563 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
564 <                 client->name, client->username);
562 >      if (client_p->connection->aftype == AF_INET)
563 >        snprintf(buf, sizeof(buf), "%s[%s@255.255.255.255]",
564 >                 client_p->name, client_p->username);
565        else
566 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
567 <                 client->name, client->username);
566 >        snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
567 >                 client_p->name, client_p->username);
568        break;
569      default:
570 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
571 <               client->name,
572 <               client->username, client->host);
570 >      snprintf(buf, sizeof(buf), "%s[%s@%s]",
571 >               client_p->name,
572 >               client_p->username, client_p->host);
573    }
574  
575 <  return nbuf;
575 >  return buf;
576   }
577  
578   void
579   free_exited_clients(void)
580   {
581 <  dlink_node *ptr = NULL, *next = NULL;
582 <  
583 <  DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
581 >  dlink_node *node = NULL, *node_next = NULL;
582 >
583 >  DLINK_FOREACH_SAFE(node, node_next, dead_list.head)
584    {
585 <    free_client(ptr->data);
586 <    dlinkDelete(ptr, &dead_list);
587 <    free_dlink_node(ptr);
585 >    free_client(node->data);
586 >    dlinkDelete(node, &dead_list);
587 >    free_dlink_node(node);
588    }
589   }
590  
# Line 642 | Line 595 | free_exited_clients(void)
595   * The only messages generated are QUITs on channels.
596   */
597   static void
598 < exit_one_client(struct Client *source_p, const char *quitmsg)
598 > exit_one_client(struct Client *source_p, const char *comment)
599   {
600 <  dlink_node *lp = NULL, *next_lp = NULL;
600 >  dlink_node *node = NULL, *node_next = NULL;
601  
602    assert(!IsMe(source_p));
603 +  assert(source_p != &me);
604  
605    if (IsClient(source_p))
606    {
607 <    if (source_p->servptr->serv != NULL)
608 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
607 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
608 >    dlinkDelete(&source_p->node, &global_client_list);
609  
610      /*
611       * If a person is on a channel, send a QUIT notice
# Line 661 | Line 615 | exit_one_client(struct Client *source_p,
615       */
616      sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
617                                   source_p->name, source_p->username,
618 <                                 source_p->host, quitmsg);
619 <    DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
620 <      remove_user_from_channel(lp->data);
618 >                                 source_p->host, comment);
619 >
620 >    DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
621 >      remove_user_from_channel(node->data);
622  
623 <    add_history(source_p, 0);
624 <    off_history(source_p);
623 >    whowas_add_history(source_p, 0);
624 >    whowas_off_history(source_p);
625  
626      watch_check_hash(source_p, RPL_LOGOFF);
627  
628      if (MyConnect(source_p))
629      {
630        /* Clean up invitefield */
631 <      DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
632 <        del_invite(lp->data, source_p);
631 >      DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head)
632 >        del_invite(node->data, source_p);
633  
634        del_all_accepts(source_p);
635      }
# Line 682 | Line 637 | exit_one_client(struct Client *source_p,
637    else if (IsServer(source_p))
638    {
639      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
640 +    dlinkDelete(&source_p->node, &global_client_list);
641  
642 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
643 <      free_dlink_node(lp);
642 >    if ((node = dlinkFindDelete(&global_server_list, source_p)))
643 >      free_dlink_node(node);
644    }
645  
646    /* Remove source_p from the client lists */
647 <  if (HasID(source_p))
647 >  if (source_p->id[0])
648      hash_del_id(source_p);
649 +
650    if (source_p->name[0])
651      hash_del_client(source_p);
652  
653    if (IsUserHostIp(source_p))
654      delete_user_host(source_p->username, source_p->host, !MyConnect(source_p));
655  
699 –  /* remove from global client list
700 –   * NOTE: source_p->node.next cannot be NULL if the client is added
701 –   *       to global_client_list (there is always &me at its end)
702 –   */
703 –  if (source_p != NULL && source_p->node.next != NULL)
704 –    dlinkDelete(&source_p->node, &global_client_list);
705 –
656    update_client_exit_stats(source_p);
657  
658    /* Check to see if the client isn't already on the dead list */
# Line 713 | Line 663 | exit_one_client(struct Client *source_p,
663    dlinkAdd(source_p, make_dlink_node(), &dead_list);
664   }
665  
666 < /* Recursively send QUITs and SQUITs for source_p and all its dependent clients
717 < * and servers to those servers that need them.  A server needs the client
718 < * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
719 < * isn't getting the SQUIT because of @#(*&@)# hostmasking.  With TS4, once
720 < * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
721 < * on that one -orabidoo
722 < *
723 < * This is now called on each local server -adx
724 < */
725 < static void
726 < recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
727 <                   struct Client *from, struct Client *to, const char *comment,
728 <                   const char *splitstr)
729 < {
730 <  dlink_node *ptr, *next;
731 <  struct Client *target_p;
732 <
733 <  assert(to != source_p);  /* should be already removed from serv_list */
734 <
735 <  /* If this server can handle quit storm (QS) removal
736 <   * of dependents, just send the SQUIT
737 <   */
738 <  if (!IsCapable(to, CAP_QS))
739 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
740 <    {
741 <      target_p = ptr->data;
742 <      sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
743 <    }
744 <
745 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
746 <    recurse_send_quits(original_source_p, ptr->data, from, to,
747 <                       comment, splitstr);
748 <
749 <  if ((source_p == original_source_p && to != from) ||
750 <                  !IsCapable(to, CAP_QS))
751 <  {
752 <    /* don't use a prefix here - we have to be 100% sure the message
753 <     * will be accepted without Unknown prefix etc.. */
754 <    sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
755 <  }
756 < }
757 <
758 < /*
666 > /*
667   * Remove all clients that depend on source_p; assumes all (S)QUITs have
668 < * already been sent.  we make sure to exit a server's dependent clients
669 < * and servers before the server itself; exit_one_client takes care of
668 > * already been sent.  we make sure to exit a server's dependent clients
669 > * and servers before the server itself; exit_one_client takes care of
670   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
671   */
672   static void
673 < recurse_remove_clients(struct Client *source_p, const char *quitmsg)
673 > recurse_remove_clients(struct Client *source_p, const char *comment)
674   {
675 <  dlink_node *ptr, *next;
675 >  dlink_node *node = NULL, *node_next = NULL;
676  
677 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
678 <    exit_one_client(ptr->data, quitmsg);
677 >  DLINK_FOREACH_SAFE(node, node_next, source_p->serv->client_list.head)
678 >    exit_one_client(node->data, comment);
679  
680 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
680 >  DLINK_FOREACH_SAFE(node, node_next, source_p->serv->server_list.head)
681    {
682 <    recurse_remove_clients(ptr->data, quitmsg);
683 <    exit_one_client(ptr->data, quitmsg);
682 >    recurse_remove_clients(node->data, comment);
683 >    exit_one_client(node->data, comment);
684    }
685   }
686  
687   /*
780 – ** Remove *everything* that depends on source_p, from all lists, and sending
781 – ** all necessary QUITs and SQUITs.  source_p itself is still on the lists,
782 – ** and its SQUITs have been sent except for the upstream one  -orabidoo
783 – */
784 – static void
785 – remove_dependents(struct Client *source_p, struct Client *from,
786 –                  const char *comment, const char *splitstr)
787 – {
788 –  dlink_node *ptr = NULL;
789 –
790 –  DLINK_FOREACH(ptr, serv_list.head)
791 –    recurse_send_quits(source_p, source_p, from, ptr->data,
792 –                       comment, splitstr);
793 –
794 –  recurse_remove_clients(source_p, splitstr);
795 – }
796 –
797 – /*
688   * exit_client - exit a client of any type. Generally, you can use
689   * this on any struct Client, regardless of its state.
690   *
691   * Note, you shouldn't exit remote _users_ without first doing
692   * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
693 + *
694   * However, it is perfectly correct to call exit_client to force a _server_
695   * quit (either local or remote one).
696   *
697 + *
698   * inputs:       - a client pointer that is going to be exited
807 – *               - for servers, the second argument is a pointer to who
808 – *                 is firing the server. This side won't get any generated
809 – *                 messages. NEVER NULL!
699   * output:       none
700   * side effects: the client is delinked from all lists, disconnected,
701   *               and the rest of IRC network is notified of the exit.
702   *               Client memory is scheduled to be freed
703   */
704   void
705 < exit_client(struct Client *source_p, struct Client *from, const char *comment)
705 > exit_client(struct Client *source_p, const char *comment)
706   {
707 <  dlink_node *m = NULL;
707 >  dlink_node *node = NULL;
708 >
709 >  assert(!IsMe(source_p));
710 >  assert(source_p != &me);
711  
712    if (MyConnect(source_p))
713    {
# Line 827 | Line 719 | exit_client(struct Client *source_p, str
719  
720      SetClosing(source_p);
721  
722 <    if (IsIpHash(source_p))
831 <      remove_one_ip(&source_p->localClient->ip);
832 <
833 <    if (source_p->localClient->auth)
722 >    if (HasFlag(source_p, FLAGS_IPHASH))
723      {
724 <      delete_auth(source_p->localClient->auth);
725 <      source_p->localClient->auth = NULL;
724 >      DelFlag(source_p, FLAGS_IPHASH);
725 >      ipcache_remove_address(&source_p->connection->ip);
726      }
727  
728 +    delete_auth(&source_p->connection->auth);
729 +
730      /*
731       * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
732       * STAT_HANDSHAKE or STAT_UNKNOWN
# Line 847 | Line 738 | exit_client(struct Client *source_p, str
738      {
739        assert(dlinkFind(&unknown_list, source_p));
740  
741 <      dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
741 >      dlinkDelete(&source_p->connection->lclient_node, &unknown_list);
742      }
743      else if (IsClient(source_p))
744      {
745 <      time_t on_for = CurrentTime - source_p->localClient->firsttime;
745 >      time_t on_for = CurrentTime - source_p->connection->firsttime;
746 >
747        assert(Count.local > 0);
748 <      Count.local--;
748 >
749 >      --Count.local;
750  
751        if (HasUMode(source_p, UMODE_OPER))
752 <        if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
753 <          free_dlink_node(m);
752 >        if ((node = dlinkFindDelete(&oper_list, source_p)))
753 >          free_dlink_node(node);
754  
755        assert(dlinkFind(&local_client_list, source_p));
756 <      dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
756 >      dlinkDelete(&source_p->connection->lclient_node, &local_client_list);
757  
758 <      if (source_p->localClient->list_task != NULL)
759 <        free_list_task(source_p->localClient->list_task, source_p);
758 >      if (source_p->connection->list_task)
759 >        free_list_task(source_p);
760  
761        watch_del_watch_list(source_p);
762 +      client_clear_svstags(source_p);
763 +
764        sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
765                             "Client exiting: %s (%s@%s) [%s] [%s]",
766                             source_p->name, source_p->username, source_p->host, comment,
767 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
768 <                           "255.255.255.255" : source_p->sockhost);
874 <      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, SEND_NOTICE,
875 <                           "CLIEXIT: %s %s %s %s 0 %s",
876 <                           source_p->name,
877 <                           source_p->username,
878 <                           source_p->host,
879 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
880 <                           "255.255.255.255" : source_p->sockhost,
881 <                           comment);
767 >                           source_p->sockhost);
768 >
769        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
770 <           myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
770 >           myctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600),
771             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
772             source_p->name, source_p->username, source_p->host,
773 <           source_p->localClient->send.bytes>>10,
774 <           source_p->localClient->recv.bytes>>10);
773 >           source_p->connection->send.bytes>>10,
774 >           source_p->connection->recv.bytes>>10);
775      }
776      else if (IsServer(source_p))
777      {
778        assert(Count.myserver > 0);
779 +
780        --Count.myserver;
781  
782 <      assert(dlinkFind(&serv_list, source_p));
783 <      dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
896 <      unset_chcap_usage_counts(source_p);
782 >      assert(dlinkFind(&local_server_list, source_p));
783 >      dlinkDelete(&source_p->connection->lclient_node, &local_server_list);
784      }
785  
786      if (!IsDead(source_p))
787      {
788        if (IsServer(source_p))
789        {
790 <        /* for them, we are exiting the network */
791 <        sendto_one(source_p, ":%s SQUIT %s :%s",
792 <                   ID_or_name(from, source_p), me.name, comment);
790 >        if (!HasFlag(source_p, FLAGS_SQUIT))
791 >        {
792 >          /* for them, we are exiting the network */
793 >          sendto_one(source_p, ":%s SQUIT %s :%s",
794 >                     me.id, me.id, comment);
795 >        }
796        }
797  
798        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
799                   source_p->host, comment);
800      }
801  
912 –    /*
913 –    ** Currently only server connections can have
914 –    ** depending remote clients here, but it does no
915 –    ** harm to check for all local clients. In
916 –    ** future some other clients than servers might
917 –    ** have remotes too...
918 –    **
919 –    ** Close the Client connection first and mark it
920 –    ** so that no messages are attempted to send to it.
921 –    ** Remember it makes source_p->from == NULL.
922 –    */
802      close_connection(source_p);
803    }
804 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
805 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
806 +                         "Client exiting at %s: %s (%s@%s) [%s]",
807 +                         source_p->servptr->name, source_p->name,
808 +                         source_p->username, source_p->host, comment);
809  
810    if (IsServer(source_p))
811    {
812 <    char splitstr[HOSTLEN + HOSTLEN + 2];
812 >    char splitstr[HOSTLEN + HOSTLEN + 2] = "";
813  
814      /* This shouldn't ever happen */
815 <    assert(source_p->serv != NULL && source_p->servptr != NULL);
815 >    assert(source_p->serv && source_p->servptr);
816  
817      if (ConfigServerHide.hide_servers)
818        /*
819 <       * Set netsplit message to "*.net *.split" to still show
819 >       * Set netsplit message to "*.net *.split" to still show
820         * that its a split, but hide the servers splitting
821         */
822 <      strcpy(splitstr, "*.net *.split");
822 >      strlcpy(splitstr, "*.net *.split", sizeof(splitstr));
823      else
824        snprintf(splitstr, sizeof(splitstr), "%s %s",
825                 source_p->servptr->name, source_p->name);
826  
827 <    remove_dependents(source_p, from->from, comment, splitstr);
827 >    /* Send SQUIT for source_p in every direction. source_p is already off of local_server_list here */
828 >    if (!HasFlag(source_p, FLAGS_SQUIT))
829 >      sendto_server(NULL, 0, 0, "SQUIT %s :%s", source_p->id, comment);
830 >
831 >    /* Now exit the clients internally */
832 >    recurse_remove_clients(source_p, splitstr);
833  
834 <    if (source_p->servptr == &me)
834 >    if (MyConnect(source_p))
835      {
836 +      int connected = CurrentTime - source_p->connection->firsttime;
837        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
838 <                           "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
839 <                           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
840 <                           source_p->localClient->send.bytes >> 10,
841 <                           source_p->localClient->recv.bytes >> 10);
842 <      ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
843 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
844 <           source_p->localClient->send.bytes >> 10,
845 <           source_p->localClient->recv.bytes >> 10);
838 >                           "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
839 >                           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
840 >                           (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
841 >                           source_p->connection->send.bytes >> 10,
842 >                           source_p->connection->recv.bytes >> 10);
843 >      ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.",
844 >           source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s",
845 >          (connected % 86400) / 3600, (connected % 3600) / 60, connected % 60,
846 >          source_p->connection->send.bytes >> 10,
847 >          source_p->connection->recv.bytes >> 10);
848      }
849    }
850    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
851 <  {
852 <    sendto_server(from->from, CAP_TS6, NOCAPS,
961 <                  ":%s QUIT :%s", ID(source_p), comment);
962 <    sendto_server(from->from, NOCAPS, CAP_TS6,
963 <                  ":%s QUIT :%s", source_p->name, comment);
964 <  }
851 >    sendto_server(source_p->from, 0, 0, ":%s QUIT :%s",
852 >                  source_p->id, comment);
853  
854    /* The client *better* be off all of the lists */
855    assert(dlinkFind(&unknown_list, source_p) == NULL);
856    assert(dlinkFind(&local_client_list, source_p) == NULL);
857 <  assert(dlinkFind(&serv_list, source_p) == NULL);
857 >  assert(dlinkFind(&local_server_list, source_p) == NULL);
858    assert(dlinkFind(&oper_list, source_p) == NULL);
859  
860    exit_one_client(source_p, comment);
# Line 979 | Line 867 | exit_client(struct Client *source_p, str
867   void
868   dead_link_on_write(struct Client *client_p, int ierrno)
869   {
870 <  dlink_node *ptr;
870 >  dlink_node *node;
871  
872    if (IsDefunct(client_p))
873      return;
874  
875 <  dbuf_clear(&client_p->localClient->buf_recvq);
876 <  dbuf_clear(&client_p->localClient->buf_sendq);
875 >  dbuf_clear(&client_p->connection->buf_recvq);
876 >  dbuf_clear(&client_p->connection->buf_sendq);
877  
878    assert(dlinkFind(&abort_list, client_p) == NULL);
879 <  ptr = make_dlink_node();
879 >  node = make_dlink_node();
880    /* don't let exit_aborted_clients() finish yet */
881 <  dlinkAddTail(client_p, ptr, &abort_list);
881 >  dlinkAddTail(client_p, node, &abort_list);
882  
883    if (eac_next == NULL)
884 <    eac_next = ptr;
884 >    eac_next = node;
885  
886    SetDead(client_p); /* You are dead my friend */
887   }
# Line 1005 | Line 893 | dead_link_on_write(struct Client *client
893   void
894   dead_link_on_read(struct Client *client_p, int error)
895   {
896 <  char errmsg[255];
896 >  char errmsg[IRCD_BUFSIZE];
897    int current_error;
898  
899    if (IsDefunct(client_p))
900      return;
901  
902 <  dbuf_clear(&client_p->localClient->buf_recvq);
903 <  dbuf_clear(&client_p->localClient->buf_sendq);
902 >  dbuf_clear(&client_p->connection->buf_recvq);
903 >  dbuf_clear(&client_p->connection->buf_sendq);
904  
905 <  current_error = get_sockerr(client_p->localClient->fd.fd);
905 >  current_error = get_sockerr(client_p->connection->fd.fd);
906  
907    if (IsServer(client_p) || IsHandshake(client_p))
908    {
909 <    int connected = CurrentTime - client_p->localClient->firsttime;
910 <      
909 >    int connected = CurrentTime - client_p->connection->firsttime;
910 >
911      if (error == 0)
912      {
913        /* Admins get the real IP */
914        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
915 <                           "Server %s closed the connection",
916 <                           get_client_name(client_p, SHOW_IP));
915 >                           "Server %s closed the connection",
916 >                           get_client_name(client_p, SHOW_IP));
917  
918        /* Opers get a masked IP */
919        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
920 <                           "Server %s closed the connection",
921 <                           get_client_name(client_p, MASK_IP));
920 >                           "Server %s closed the connection",
921 >                           get_client_name(client_p, MASK_IP));
922  
923        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
924 <           get_client_name(client_p, SHOW_IP));
924 >           get_client_name(client_p, SHOW_IP));
925      }
926      else
927      {
928        report_error(L_ADMIN, "Lost connection to %s: %s",
929 <                   get_client_name(client_p, SHOW_IP), current_error);
929 >                   get_client_name(client_p, SHOW_IP), current_error);
930        report_error(L_OPER, "Lost connection to %s: %s",
931 <                   get_client_name(client_p, MASK_IP), current_error);
931 >                   get_client_name(client_p, MASK_IP), current_error);
932      }
933  
934      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
935 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
936 <                         client_p->name, connected/86400,
937 <                         (connected/86400 == 1) ? "" : "s",
938 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
939 <                         connected % 60);
935 >                         "%s was connected for %d day%s, %2d:%02d:%02d",
936 >                         client_p->name, connected/86400,
937 >                         (connected/86400 == 1) ? "" : "s",
938 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
939 >                         connected % 60);
940    }
941  
942    if (error == 0)
# Line 1058 | Line 946 | dead_link_on_read(struct Client *client_
946      snprintf(errmsg, sizeof(errmsg), "Read error: %s",
947               strerror(current_error));
948  
949 <  exit_client(client_p, &me, errmsg);
949 >  exit_client(client_p, errmsg);
950   }
951  
952   void
# Line 1089 | Line 977 | exit_aborted_clients(void)
977      else
978        notice = "Write error: connection closed";
979  
980 <    exit_client(target_p, &me, notice);  
980 >    exit_client(target_p, notice);
981      free_dlink_node(ptr);
982    }
983   }
# Line 1107 | Line 995 | exit_aborted_clients(void)
995   void
996   del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
997   {
998 <  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
998 >  dlinkDelete(&accept_p->node, &client_p->connection->acceptlist);
999  
1000    MyFree(accept_p->nickptr);
1001    MyFree(accept_p->userptr);
# Line 1117 | Line 1005 | del_accept(struct split_nuh_item *accept
1005  
1006   struct split_nuh_item *
1007   find_accept(const char *nick, const char *user,
1008 <            const char *host, struct Client *client_p, int do_match)
1008 >            const char *host, struct Client *client_p,
1009 >            int (*cmpfunc)(const char *, const char *))
1010   {
1011 <  dlink_node *ptr = NULL;
1123 <  /* XXX We wouldn't need that if match() would return 0 on match */
1124 <  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1011 >  dlink_node *node = NULL;
1012  
1013 <  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1013 >  DLINK_FOREACH(node, client_p->connection->acceptlist.head)
1014    {
1015 <    struct split_nuh_item *accept_p = ptr->data;
1015 >    struct split_nuh_item *accept_p = node->data;
1016  
1017      if (!cmpfunc(accept_p->nickptr, nick) &&
1018          !cmpfunc(accept_p->userptr, user) &&
# Line 1147 | Line 1034 | int
1034   accept_message(struct Client *source,
1035                 struct Client *target)
1036   {
1037 <  dlink_node *ptr = NULL;
1037 >  dlink_node *node = NULL;
1038 >
1039 >  if (HasFlag(source, FLAGS_SERVICE) ||
1040 >      (HasUMode(source, UMODE_OPER) && ConfigGeneral.opers_bypass_callerid))
1041 >    return 1;
1042  
1043    if (source == target || find_accept(source->name, source->username,
1044 <                                      source->host, target, 1))
1044 >                                      source->host, target, match))
1045      return 1;
1046  
1047 <  if (HasUMode(target, UMODE_SOFTCALLERID))
1048 <    DLINK_FOREACH(ptr, target->channel.head)
1049 <      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1047 >  if (!HasUMode(target, UMODE_CALLERID) && HasUMode(target, UMODE_SOFTCALLERID))
1048 >    DLINK_FOREACH(node, target->channel.head)
1049 >      if (IsMember(source, ((struct Membership *)node->data)->chptr))
1050          return 1;
1051  
1052    return 0;
# Line 1170 | Line 1061 | accept_message(struct Client *source,
1061   void
1062   del_all_accepts(struct Client *client_p)
1063   {
1064 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1064 >  dlink_node *node = NULL, *node_next = NULL;
1065  
1066 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1067 <    del_accept(ptr->data, client_p);
1066 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->acceptlist.head)
1067 >    del_accept(node->data, client_p);
1068   }
1069  
1070   unsigned int
1071 < idle_time_get(const struct Client *source_p, const struct Client *target_p)
1071 > client_get_idle_time(const struct Client *source_p,
1072 >                     const struct Client *target_p)
1073   {
1074    unsigned int idle = 0;
1075    unsigned int min_idle = 0;
1076    unsigned int max_idle = 0;
1077 <  struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1077 >  const struct ClassItem *const class = get_class_ptr(&target_p->connection->confs);
1078 >
1079 >  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1080 >    return CurrentTime - target_p->connection->last_privmsg;
1081  
1187 –  if (target_p == source_p)
1188 –    return CurrentTime - target_p->localClient->last_privmsg;
1082    if (HasUMode(source_p, UMODE_OPER) &&
1083 <      (!(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS)))
1084 <    return CurrentTime - target_p->localClient->last_privmsg;
1083 >      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1084 >    return CurrentTime - target_p->connection->last_privmsg;
1085  
1086    min_idle = class->min_idle;
1087    max_idle = class->max_idle;
# Line 1199 | Line 1092 | idle_time_get(const struct Client *sourc
1092    if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1093      idle = genrand_int32();
1094    else
1095 <    idle = CurrentTime - target_p->localClient->last_privmsg;
1095 >    idle = CurrentTime - target_p->connection->last_privmsg;
1096  
1097 <  if (max_idle == 0)
1097 >  if (!max_idle)
1098      idle = 0;
1099    else
1100      idle %= max_idle;
# Line 1211 | Line 1104 | idle_time_get(const struct Client *sourc
1104  
1105    return idle;
1106   }
1107 +
1108 + /* client_init()
1109 + *
1110 + * inputs       - NONE
1111 + * output       - NONE
1112 + * side effects - initialize client free memory
1113 + */
1114 + void
1115 + client_init(void)
1116 + {
1117 +  static struct event event_ping =
1118 +  {
1119 +    .name = "check_pings",
1120 +    .handler = check_pings,
1121 +    .when = 5
1122 +  };
1123 +
1124 +  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
1125 +  connection_pool = mp_pool_new(sizeof(struct Connection), MP_CHUNK_SIZE_CONNECTION);
1126 +  event_add(&event_ping, NULL);
1127 + }

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)