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 1632 by michael, Sun Nov 4 15:37:10 2012 UTC vs.
Revision 1785 by michael, Sat Jan 26 22:40:55 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 89 | Line 90 | init_client(void)
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->localClient->confs, &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 367 | Line 353 | check_conf_klines(void)
353      if ((conf = find_dline_conf(&client_p->localClient->ip,
354                                    client_p->localClient->aftype)) != NULL)
355      {
356 <      if (conf->status & CONF_EXEMPT)
356 >      if (conf->type == CONF_EXEMPT)
357          continue;
358  
359        ban_them(client_p, conf);
# Line 422 | Line 408 | check_conf_klines(void)
408      if ((conf = find_dline_conf(&client_p->localClient->ip,
409                                   client_p->localClient->aftype)))
410      {
411 <      if (conf->status & CONF_EXEMPT)
411 >      if (conf->type == CONF_EXEMPT)
412          continue;
413  
414        exit_client(client_p, &me, "D-lined");
# Line 673 | Line 659 | exit_one_client(struct Client *source_p,
659       * that the client can show the "**signoff" message).
660       * (Note: The notice is to the local clients *only*)
661       */
662 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
662 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
663                                   source_p->name, source_p->username,
664                                   source_p->host, quitmsg);
665      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
# Line 1141 | Line 1127 | find_accept(const char *nick, const char
1127    {
1128      struct split_nuh_item *accept_p = ptr->data;
1129  
1130 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1131 <        cmpfunc(accept_p->userptr, user) == do_match &&
1132 <        cmpfunc(accept_p->hostptr, host) == do_match)
1130 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1131 >        !cmpfunc(accept_p->userptr, user) &&
1132 >        !cmpfunc(accept_p->hostptr, host))
1133        return accept_p;
1134    }
1135  
# Line 1189 | Line 1175 | del_all_accepts(struct Client *client_p)
1175    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1176      del_accept(ptr->data, client_p);
1177   }
1178 +
1179 + unsigned int
1180 + idle_time_get(const struct Client *source_p, const struct Client *target_p)
1181 + {
1182 +  unsigned int idle = 0;
1183 +  unsigned int min_idle = 0;
1184 +  unsigned int max_idle = 0;
1185 +  struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1186 +
1187 +  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1188 +    return CurrentTime - target_p->localClient->last_privmsg;
1189 +  if (HasUMode(source_p, UMODE_OPER) &&
1190 +      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1191 +    return CurrentTime - target_p->localClient->last_privmsg;
1192 +
1193 +  min_idle = class->min_idle;
1194 +  max_idle = class->max_idle;
1195 +
1196 +  if (min_idle == max_idle)
1197 +    return min_idle;
1198 +
1199 +  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1200 +    idle = genrand_int32();
1201 +  else
1202 +    idle = CurrentTime - target_p->localClient->last_privmsg;
1203 +
1204 +  if (max_idle == 0)
1205 +    idle = 0;
1206 +  else
1207 +    idle %= max_idle;
1208 +
1209 +  if (idle < min_idle)
1210 +    idle = min_idle + (idle % (max_idle - min_idle));
1211 +
1212 +  return idle;
1213 + }

Diff Legend

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