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 1618 by michael, Tue Oct 30 21:04:38 2012 UTC vs.
Revision 1991 by michael, Thu May 9 16:01:15 2013 UTC

# Line 45 | Line 45
45   #include "s_user.h"
46   #include "dbuf.h"
47   #include "memory.h"
48 + #include "mempool.h"
49   #include "hostmask.h"
49 – #include "balloc.h"
50   #include "listener.h"
51   #include "irc_res.h"
52   #include "userhost.h"
53   #include "watch.h"
54 + #include "rng_mt.h"
55  
56   dlink_list listing_client_list = { NULL, NULL, 0 };
57   /* Pointer to beginning of Client list */
# Line 64 | Line 65 | dlink_list oper_list = {NULL, NULL, 0};
65  
66   static EVH check_pings;
67  
68 < static BlockHeap *client_heap  = NULL;
69 < static BlockHeap *lclient_heap = NULL;
68 > static mp_pool_t *client_pool  = NULL;
69 > static mp_pool_t *lclient_pool = NULL;
70  
71   static dlink_list dead_list  = { NULL, NULL, 0};
72   static dlink_list abort_list = { NULL, NULL, 0};
# Line 74 | Line 75 | static dlink_node *eac_next;  /* next ab
75  
76   static void check_pings_list(dlink_list *);
77   static void check_unknowns_list(void);
78 < static void ban_them(struct Client *, struct ConfItem *);
78 > static void ban_them(struct Client *, struct MaskItem *);
79  
80  
81 < /* init_client()
81 > /* client_init()
82   *
83   * inputs       - NONE
84   * output       - NONE
85   * side effects - initialize client free memory
86   */
87   void
88 < init_client(void)
88 > client_init(void)
89   {
90    /* start off the check ping event ..  -- adrian
91     * Every 30 seconds is plenty -- db
92     */
93 <  client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE);
94 <  lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE);
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   }
97  
# Line 112 | Line 113 | init_client(void)
113   struct Client *
114   make_client(struct Client *from)
115   {
116 <  struct Client *client_p = BlockHeapAlloc(client_heap);
116 >  struct Client *client_p = mp_pool_get(client_pool);
117 >
118 >  memset(client_p, 0, sizeof(*client_p));
119  
120    if (from == NULL)
121    {
122      client_p->from                      = client_p; /* 'from' of local client is self! */
123 <    client_p->localClient               = BlockHeapAlloc(lclient_heap);
123 >    client_p->localClient               = mp_pool_get(lclient_pool);
124 >
125 >    memset(client_p->localClient, 0, sizeof(*client_p->localClient));
126 >
127      client_p->localClient->since        = CurrentTime;
128      client_p->localClient->lasttime     = CurrentTime;
129      client_p->localClient->firsttime    = CurrentTime;
# Line 155 | Line 161 | free_client(struct Client *client_p)
161    assert(client_p->channel.head == NULL);
162    assert(dlink_list_length(&client_p->channel) == 0);
163    assert(dlink_list_length(&client_p->whowas) == 0);
164 <  assert(!IsServer(client_p) || IsServer(client_p) && client_p->serv);
164 >  assert(!IsServer(client_p) || (IsServer(client_p) && client_p->serv));
165  
166    MyFree(client_p->serv);
167  
# Line 183 | Line 189 | free_client(struct Client *client_p)
189      dbuf_clear(&client_p->localClient->buf_recvq);
190      dbuf_clear(&client_p->localClient->buf_sendq);
191  
192 <    BlockHeapFree(lclient_heap, client_p->localClient);
192 >    mp_pool_release(client_p->localClient);
193    }
194  
195 <  BlockHeapFree(client_heap, client_p);
195 >  mp_pool_release(client_p);
196   }
197  
198   /*
# Line 233 | Line 239 | static void
239   check_pings_list(dlink_list *list)
240   {
241    char scratch[32];        /* way too generous but... */
242 <  struct Client *client_p; /* current local client_p being examined */
243 <  int ping, pingwarn;      /* ping time value from client */
238 <  dlink_node *ptr, *next_ptr;
242 >  int ping = 0;      /* ping time value from client */
243 >  dlink_node *ptr = NULL, *next_ptr = NULL;
244  
245    DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
246    {
247 <    client_p = ptr->data;
247 >    struct Client *client_p = ptr->data;
248  
249      /*
250      ** Note: No need to notify opers here. It's
# Line 252 | Line 257 | check_pings_list(dlink_list *list)
257      }
258  
259      if (!IsRegistered(client_p))
260 <      ping = CONNECTTIMEOUT, pingwarn = 0;
260 >      ping = CONNECTTIMEOUT;
261      else
262 <      ping = get_client_ping(client_p, &pingwarn);
262 >      ping = get_client_ping(&client_p->localClient->confs);
263  
264      if (ping < CurrentTime - client_p->localClient->lasttime)
265      {
# Line 266 | Line 271 | check_pings_list(dlink_list *list)
271           * it is still alive.
272           */
273          SetPingSent(client_p);
269 –        ClearPingWarning(client_p);
274          client_p->localClient->lasttime = CurrentTime - ping;
275          sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
276        }
# Line 294 | Line 298 | check_pings_list(dlink_list *list)
298                     (int)(CurrentTime - client_p->localClient->lasttime));
299            exit_client(client_p, &me, scratch);
300          }
297 –        else if (!IsPingWarning(client_p) && pingwarn > 0 &&
298 –                 (IsServer(client_p) || IsHandshake(client_p)) &&
299 –                 CurrentTime - client_p->localClient->lasttime >= ping + pingwarn)
300 –        {
301 –          /*
302 –           * If the server hasn't replied in pingwarn seconds after sending
303 –           * the PING, notify the opers so that they are aware of the problem.
304 –           */
305 –          SetPingWarning(client_p);
306 –          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
307 –                               "Warning, no response from %s in %d seconds",
308 –                               get_client_name(client_p, HIDE_IP), pingwarn);
309 –          sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
310 –                               "Warning, no response from %s in %d seconds",
311 –                               get_client_name(client_p, MASK_IP), pingwarn);
312 –          ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds",
313 –               get_client_name(client_p, HIDE_IP), pingwarn);
314 –        }
301        }
302      }
303    }
# Line 352 | Line 338 | void
338   check_conf_klines(void)
339   {              
340    struct Client *client_p = NULL;       /* current local client_p being examined */
341 <  struct AccessItem *aconf = NULL;
356 <  struct ConfItem *conf = NULL;
341 >  struct MaskItem *conf = NULL;
342    dlink_node *ptr, *next_ptr;
343  
344    DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
# Line 365 | Line 350 | check_conf_klines(void)
350      if (IsDead(client_p) || !IsClient(client_p))
351        continue;
352  
353 <    /* if there is a returned struct ConfItem then kill it */
369 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
353 >    if ((conf = find_dline_conf(&client_p->localClient->ip,
354                                    client_p->localClient->aftype)) != NULL)
355      {
356 <      if (aconf->status & CONF_EXEMPTDLINE)
356 >      if (conf->type == CONF_EXEMPT)
357          continue;
358  
375 –      conf = unmap_conf_item(aconf);
359        ban_them(client_p, conf);
360        continue; /* and go examine next fd/client_p */
361      }
362  
363 <    if (ConfigFileEntry.glines && (aconf = find_gline(client_p)))
363 >    if (ConfigFileEntry.glines && (conf = find_gline(client_p)))
364      {
365        if (IsExemptKline(client_p) ||
366            IsExemptGline(client_p))
# Line 388 | Line 371 | check_conf_klines(void)
371          continue;
372        }
373  
391 –      conf = unmap_conf_item(aconf);
374        ban_them(client_p, conf);
375        /* and go examine next fd/client_p */    
376        continue;
377      }
378  
379 <    if ((aconf = find_kill(client_p)) != NULL)
379 >    if ((conf = find_kill(client_p)) != NULL)
380      {
399 –
400 –      /* if there is a returned struct AccessItem.. then kill it */
381        if (IsExemptKline(client_p))
382        {
383          sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
# Line 406 | Line 386 | check_conf_klines(void)
386          continue;
387        }
388  
409 –      conf = unmap_conf_item(aconf);
389        ban_them(client_p, conf);
390        continue;
391      }
392  
393 <    /* if there is a returned struct MatchItem then kill it */
394 <    if ((conf = find_matching_name_conf(XLINE_TYPE,  client_p->info,
416 <                                        NULL, NULL, 0)) != NULL ||
417 <        (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
418 <                                        NULL, NULL, 0)) != NULL)
393 >    if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
394 >                                        NULL, NULL, 0)))
395      {
396        ban_them(client_p, conf);
397        continue;
# Line 427 | Line 403 | check_conf_klines(void)
403    {
404      client_p = ptr->data;
405  
406 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
407 <                                  client_p->localClient->aftype)))
406 >    if ((conf = find_dline_conf(&client_p->localClient->ip,
407 >                                 client_p->localClient->aftype)))
408      {
409 <      if (aconf->status & CONF_EXEMPTDLINE)
409 >      if (conf->type == CONF_EXEMPT)
410          continue;
411  
412        exit_client(client_p, &me, "D-lined");
# Line 442 | Line 418 | check_conf_klines(void)
418   * ban_them
419   *
420   * inputs       - pointer to client to ban
421 < *              - pointer to ConfItem
421 > *              - pointer to MaskItem
422   * output       - NONE
423   * side effects - given client_p is banned
424   */
425   static void
426 < ban_them(struct Client *client_p, struct ConfItem *conf)
426 > ban_them(struct Client *client_p, struct MaskItem *conf)
427   {
428    const char *user_reason = NULL;       /* What is sent to user */
453 –  struct AccessItem *aconf = NULL;
454 –  struct MatchItem *xconf = NULL;
429    const char *type_string = NULL;
430    const char dline_string[] = "D-line";
431    const char kline_string[] = "K-line";
# Line 460 | Line 434 | ban_them(struct Client *client_p, struct
434  
435    switch (conf->type)
436    {
437 <    case RKLINE_TYPE:
464 <    case KLINE_TYPE:
437 >    case CONF_KLINE:
438        type_string = kline_string;
466 –      aconf = map_to_conf(conf);
439        break;
440 <    case DLINE_TYPE:
440 >    case CONF_DLINE:
441        type_string = dline_string;
470 –      aconf = map_to_conf(conf);
442        break;
443 <    case GLINE_TYPE:
443 >    case CONF_GLINE:
444        type_string = gline_string;
474 –      aconf = map_to_conf(conf);
445        break;
446 <    case RXLINE_TYPE:
477 <    case XLINE_TYPE:
446 >    case CONF_XLINE:
447        type_string = xline_string;
448 <      xconf = map_to_conf(conf);
480 <      ++xconf->count;
448 >      ++conf->count;
449        break;
450      default:
451        assert(0);
452        break;
453    }
454  
455 <  if (aconf != NULL)
488 <    user_reason = aconf->reason ? aconf->reason : type_string;
489 <  if (xconf != NULL)
490 <    user_reason = xconf->reason ? xconf->reason : type_string;
455 >  user_reason = conf->reason ? conf->reason : type_string;
456  
457    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
458                         type_string, get_client_name(client_p, HIDE_IP));
# Line 690 | Line 655 | exit_one_client(struct Client *source_p,
655       * that the client can show the "**signoff" message).
656       * (Note: The notice is to the local clients *only*)
657       */
658 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
658 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
659                                   source_p->name, source_p->username,
660                                   source_p->host, quitmsg);
661      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
# Line 953 | Line 918 | exit_client(struct Client *source_p, str
918      */
919      close_connection(source_p);
920    }
921 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
922 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
923 +                         "Client exiting at %s: %s (%s@%s) [%s]",
924 +                         source_p->servptr->name, source_p->name,
925 +                         source_p->username, source_p->host, comment);
926  
927    if (IsServer(source_p))
928    {
# Line 1158 | Line 1128 | find_accept(const char *nick, const char
1128    {
1129      struct split_nuh_item *accept_p = ptr->data;
1130  
1131 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1132 <        cmpfunc(accept_p->userptr, user) == do_match &&
1133 <        cmpfunc(accept_p->hostptr, host) == do_match)
1131 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1132 >        !cmpfunc(accept_p->userptr, user) &&
1133 >        !cmpfunc(accept_p->hostptr, host))
1134        return accept_p;
1135    }
1136  
# Line 1206 | Line 1176 | del_all_accepts(struct Client *client_p)
1176    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1177      del_accept(ptr->data, client_p);
1178   }
1179 +
1180 + unsigned int
1181 + idle_time_get(const struct Client *source_p, const struct Client *target_p)
1182 + {
1183 +  unsigned int idle = 0;
1184 +  unsigned int min_idle = 0;
1185 +  unsigned int max_idle = 0;
1186 +  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1187 +
1188 +  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1189 +    return CurrentTime - target_p->localClient->last_privmsg;
1190 +  if (HasUMode(source_p, UMODE_OPER) &&
1191 +      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1192 +    return CurrentTime - target_p->localClient->last_privmsg;
1193 +
1194 +  min_idle = class->min_idle;
1195 +  max_idle = class->max_idle;
1196 +
1197 +  if (min_idle == max_idle)
1198 +    return min_idle;
1199 +
1200 +  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1201 +    idle = genrand_int32();
1202 +  else
1203 +    idle = CurrentTime - target_p->localClient->last_privmsg;
1204 +
1205 +  if (max_idle == 0)
1206 +    idle = 0;
1207 +  else
1208 +    idle %= max_idle;
1209 +
1210 +  if (idle < min_idle)
1211 +    idle = min_idle + (idle % (max_idle - min_idle));
1212 +
1213 +  return idle;
1214 + }

Diff Legend

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