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 1644 by michael, Tue Nov 6 22:20:16 2012 UTC vs.
Revision 2229 by michael, Thu Jun 13 20:10:27 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 77 | Line 78 | static void check_unknowns_list(void);
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 +  MyFree(client_p->certfp);
168  
169    if (MyConnect(client_p))
170    {
# Line 183 | Line 190 | free_client(struct Client *client_p)
190      dbuf_clear(&client_p->localClient->buf_recvq);
191      dbuf_clear(&client_p->localClient->buf_sendq);
192  
193 <    BlockHeapFree(lclient_heap, client_p->localClient);
193 >    mp_pool_release(client_p->localClient);
194    }
195  
196 <  BlockHeapFree(client_heap, client_p);
196 >  mp_pool_release(client_p);
197   }
198  
199   /*
# Line 259 | Line 266 | check_pings_list(dlink_list *list)
266      {
267        if (!IsPingSent(client_p))
268        {
269 <        /*
270 <         * if we havent PINGed the connection and we havent
271 <         * heard from it in a while, PING it to make sure
272 <         * it is still alive.
273 <         */
274 <        SetPingSent(client_p);
275 <        client_p->localClient->lasttime = CurrentTime - ping;
276 <        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
269 >        /*
270 >         * if we havent PINGed the connection and we havent
271 >         * heard from it in a while, PING it to make sure
272 >         * it is still alive.
273 >         */
274 >        SetPingSent(client_p);
275 >        client_p->localClient->lasttime = CurrentTime - ping;
276 >        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
277        }
278        else
279        {
# Line 277 | Line 284 | check_pings_list(dlink_list *list)
284             * and it has a ping time, then close its connection.
285             */
286            if (IsServer(client_p) || IsHandshake(client_p))
287 <          {
288 <            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
289 <                                 "No response from %s, closing link",
290 <                                 get_client_name(client_p, HIDE_IP));
291 <            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
292 <                                 "No response from %s, closing link",
293 <                                 get_client_name(client_p, MASK_IP));
294 <            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
295 <                 get_client_name(client_p, HIDE_IP));
296 <          }
287 >          {
288 >            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
289 >                                 "No response from %s, closing link",
290 >                                 get_client_name(client_p, HIDE_IP));
291 >            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
292 >                                 "No response from %s, closing link",
293 >                                 get_client_name(client_p, MASK_IP));
294 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
295 >                 get_client_name(client_p, HIDE_IP));
296 >          }
297  
298            snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
299                     (int)(CurrentTime - client_p->localClient->lasttime));
# Line 348 | Line 355 | check_conf_klines(void)
355                                    client_p->localClient->aftype)) != NULL)
356      {
357        if (conf->type == CONF_EXEMPT)
358 <        continue;
358 >        continue;
359  
360        ban_them(client_p, conf);
361        continue; /* and go examine next fd/client_p */
# Line 385 | Line 392 | check_conf_klines(void)
392      }
393  
394      if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
395 <                                        NULL, NULL, 0)) != NULL ||
389 <        (conf = find_matching_name_conf(CONF_RXLINE, client_p->info,
390 <                                        NULL, NULL, 0)) != NULL)
395 >                                        NULL, NULL, 0)))
396      {
397        ban_them(client_p, conf);
398        continue;
# Line 421 | Line 426 | check_conf_klines(void)
426   static void
427   ban_them(struct Client *client_p, struct MaskItem *conf)
428   {
429 <  const char *user_reason = NULL;       /* What is sent to user */
429 >  const char *user_reason = NULL;  /* What is sent to user */
430    const char *type_string = NULL;
431    const char dline_string[] = "D-line";
432    const char kline_string[] = "K-line";
# Line 430 | Line 435 | ban_them(struct Client *client_p, struct
435  
436    switch (conf->type)
437    {
433    case CONF_RKLINE:
438      case CONF_KLINE:
439        type_string = kline_string;
440        break;
# Line 440 | Line 444 | ban_them(struct Client *client_p, struct
444      case CONF_GLINE:
445        type_string = gline_string;
446        break;
443    case CONF_RXLINE:
447      case CONF_XLINE:
448        type_string = xline_string;
449        ++conf->count;
# Line 457 | Line 460 | ban_them(struct Client *client_p, struct
460  
461    if (IsClient(client_p))
462      sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
463 <               me.name, client_p->name, user_reason);
463 >               me.name, client_p->name, user_reason);
464  
465    exit_client(client_p, &me, user_reason);
466   }
# Line 537 | Line 540 | find_chasing(struct Client *client_p, st
540      return NULL;
541  
542    if ((who = get_history(user,
543 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
544 <                         == NULL)
543 >                         (time_t)ConfigFileEntry.kill_chase_time_limit))
544 >                         == NULL)
545    {
546      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
547                 me.name, source_p->name, user);
# Line 653 | Line 656 | exit_one_client(struct Client *source_p,
656       * that the client can show the "**signoff" message).
657       * (Note: The notice is to the local clients *only*)
658       */
659 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
659 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
660                                   source_p->name, source_p->username,
661                                   source_p->host, quitmsg);
662      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
# Line 824 | Line 827 | exit_client(struct Client *source_p, str
827      if (IsIpHash(source_p))
828        remove_one_ip(&source_p->localClient->ip);
829  
830 <    if (source_p->localClient->auth)
828 <    {
829 <      delete_auth(source_p->localClient->auth);
830 <      source_p->localClient->auth = NULL;
831 <    }
830 >    delete_auth(&source_p->localClient->auth);
831  
832      /*
833       * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
# Line 865 | Line 864 | exit_client(struct Client *source_p, str
864                             source_p->name, source_p->username, source_p->host, comment,
865                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
866                             "255.255.255.255" : source_p->sockhost);
868      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, SEND_NOTICE,
869                           "CLIEXIT: %s %s %s %s 0 %s",
870                           source_p->name,
871                           source_p->username,
872                           source_p->host,
873                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
874                           "255.255.255.255" : source_p->sockhost,
875                           comment);
867        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
868             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
869             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
# Line 896 | Line 887 | exit_client(struct Client *source_p, str
887        {
888          /* for them, we are exiting the network */
889          sendto_one(source_p, ":%s SQUIT %s :%s",
890 <                   ID_or_name(from, source_p), me.name, comment);
890 >                   ID_or_name(from, source_p), me.name, comment);
891        }
892  
893        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
# Line 916 | Line 907 | exit_client(struct Client *source_p, str
907      */
908      close_connection(source_p);
909    }
910 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
911 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
912 +                         "Client exiting at %s: %s (%s@%s) [%s]",
913 +                         source_p->servptr->name, source_p->name,
914 +                         source_p->username, source_p->host, comment);
915  
916    if (IsServer(source_p))
917    {
# Line 1018 | Line 1014 | dead_link_on_read(struct Client *client_
1014      {
1015        /* Admins get the real IP */
1016        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1017 <                           "Server %s closed the connection",
1018 <                           get_client_name(client_p, SHOW_IP));
1017 >                           "Server %s closed the connection",
1018 >                           get_client_name(client_p, SHOW_IP));
1019  
1020        /* Opers get a masked IP */
1021        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1022 <                           "Server %s closed the connection",
1023 <                           get_client_name(client_p, MASK_IP));
1022 >                           "Server %s closed the connection",
1023 >                           get_client_name(client_p, MASK_IP));
1024  
1025        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1026 <           get_client_name(client_p, SHOW_IP));
1026 >           get_client_name(client_p, SHOW_IP));
1027      }
1028      else
1029      {
1030        report_error(L_ADMIN, "Lost connection to %s: %s",
1031 <                   get_client_name(client_p, SHOW_IP), current_error);
1031 >                   get_client_name(client_p, SHOW_IP), current_error);
1032        report_error(L_OPER, "Lost connection to %s: %s",
1033 <                   get_client_name(client_p, MASK_IP), current_error);
1033 >                   get_client_name(client_p, MASK_IP), current_error);
1034      }
1035  
1036      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1037 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1038 <                         client_p->name, connected/86400,
1039 <                         (connected/86400 == 1) ? "" : "s",
1040 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
1041 <                         connected % 60);
1037 >                         "%s had been connected for %d day%s, %2d:%02d:%02d",
1038 >                         client_p->name, connected/86400,
1039 >                         (connected/86400 == 1) ? "" : "s",
1040 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
1041 >                         connected % 60);
1042    }
1043  
1044    if (error == 0)
# Line 1121 | Line 1117 | find_accept(const char *nick, const char
1117    {
1118      struct split_nuh_item *accept_p = ptr->data;
1119  
1120 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1121 <        cmpfunc(accept_p->userptr, user) == do_match &&
1122 <        cmpfunc(accept_p->hostptr, host) == do_match)
1120 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1121 >        !cmpfunc(accept_p->userptr, user) &&
1122 >        !cmpfunc(accept_p->hostptr, host))
1123        return accept_p;
1124    }
1125  
# Line 1169 | Line 1165 | del_all_accepts(struct Client *client_p)
1165    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1166      del_accept(ptr->data, client_p);
1167   }
1168 +
1169 + unsigned int
1170 + idle_time_get(const struct Client *source_p, const struct Client *target_p)
1171 + {
1172 +  unsigned int idle = 0;
1173 +  unsigned int min_idle = 0;
1174 +  unsigned int max_idle = 0;
1175 +  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1176 +
1177 +  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1178 +    return CurrentTime - target_p->localClient->last_privmsg;
1179 +  if (HasUMode(source_p, UMODE_OPER) &&
1180 +      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1181 +    return CurrentTime - target_p->localClient->last_privmsg;
1182 +
1183 +  min_idle = class->min_idle;
1184 +  max_idle = class->max_idle;
1185 +
1186 +  if (min_idle == max_idle)
1187 +    return min_idle;
1188 +
1189 +  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1190 +    idle = genrand_int32();
1191 +  else
1192 +    idle = CurrentTime - target_p->localClient->last_privmsg;
1193 +
1194 +  if (max_idle == 0)
1195 +    idle = 0;
1196 +  else
1197 +    idle %= max_idle;
1198 +
1199 +  if (idle < min_idle)
1200 +    idle = min_idle + (idle % (max_idle - min_idle));
1201 +
1202 +  return idle;
1203 + }

Diff Legend

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