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

Comparing:
ircd-hybrid-8/src/hash.c (file contents), Revision 1156 by michael, Tue Aug 9 20:29:20 2011 UTC vs.
ircd-hybrid/trunk/src/hash.c (file contents), Revision 1834 by michael, Fri Apr 19 19:50:27 2013 UTC

# Line 24 | Line 24
24  
25   #include "stdinc.h"
26   #include "list.h"
27 < #include "balloc.h"
28 < #include "s_conf.h"
27 > #include "conf.h"
28   #include "channel.h"
29   #include "channel_mode.h"
30   #include "client.h"
32 #include "common.h"
33 #include "handlers.h"
31   #include "modules.h"
32   #include "hash.h"
33   #include "resv.h"
# Line 41 | Line 38
38   #include "numeric.h"
39   #include "send.h"
40   #include "memory.h"
41 + #include "mempool.h"
42   #include "dbuf.h"
43   #include "s_user.h"
44  
45  
46 < static BlockHeap *userhost_heap = NULL;
47 < static BlockHeap *namehost_heap = NULL;
50 < static struct UserHost *find_or_add_userhost(const char *);
46 > static mp_pool_t *userhost_pool = NULL;
47 > static mp_pool_t *namehost_pool = NULL;
48  
49   static unsigned int hashf_xor_key = 0;
50  
# Line 60 | Line 57 | static struct Client *idTable[HASHSIZE];
57   static struct Client *clientTable[HASHSIZE];
58   static struct Channel *channelTable[HASHSIZE];
59   static struct UserHost *userhostTable[HASHSIZE];
63 static struct ResvChannel *resvchannelTable[HASHSIZE];
60  
61  
62   /* init_hash()
# Line 71 | Line 67 | static struct ResvChannel *resvchannelTa
67   *                functions and clear the tables
68   */
69   void
70 < init_hash(void)
70 > hash_init(void)
71   {
76  unsigned int i;
77
72    /* Default the userhost/namehost sizes to CLIENT_HEAP_SIZE for now,
73     * should be a good close approximation anyway
74     * - Dianora
75     */
76 <  userhost_heap = BlockHeapCreate("userhost", sizeof(struct UserHost), CLIENT_HEAP_SIZE);
77 <  namehost_heap = BlockHeapCreate("namehost", sizeof(struct NameHost), CLIENT_HEAP_SIZE);
76 >  userhost_pool = mp_pool_new(sizeof(struct UserHost), MP_CHUNK_SIZE_CLIENT);
77 >  namehost_pool = mp_pool_new(sizeof(struct NameHost), MP_CHUNK_SIZE_CLIENT);
78  
79    hashf_xor_key = genrand_int32() % 256;  /* better than nothing --adx */
80   }
# Line 98 | Line 92 | strhash(const char *name)
92    const unsigned char *p = (const unsigned char *)name;
93    unsigned int hval = FNV1_32_INIT;
94  
95 <  if (*p == '\0')
95 >  if (EmptyString(p))
96      return 0;
97    for (; *p != '\0'; ++p)
98    {
# Line 158 | Line 152 | hash_add_channel(struct Channel *chptr)
152   }
153  
154   void
161 hash_add_resv(struct ResvChannel *chptr)
162 {
163  unsigned int hashv = strhash(chptr->name);
164
165  chptr->hnext = resvchannelTable[hashv];
166  resvchannelTable[hashv] = chptr;
167 }
168
169 void
155   hash_add_userhost(struct UserHost *userhost)
156   {
157    unsigned int hashv = strhash(userhost->host);
# Line 309 | Line 294 | hash_del_channel(struct Channel *chptr)
294    }
295   }
296  
297 < void
313 < hash_del_resv(struct ResvChannel *chptr)
314 < {
315 <  unsigned int hashv = strhash(chptr->name);
316 <  struct ResvChannel *tmp = resvchannelTable[hashv];
317 <
318 <  if (tmp != NULL)
319 <  {
320 <    if (tmp == chptr)
321 <    {
322 <      resvchannelTable[hashv] = chptr->hnext;
323 <      chptr->hnext = chptr;
324 <    }
325 <    else
326 <    {
327 <      while (tmp->hnext != chptr)
328 <        if ((tmp = tmp->hnext) == NULL)
329 <          return;
330 <
331 <      tmp->hnext = tmp->hnext->hnext;
332 <      chptr->hnext = chptr;
333 <    }
334 <  }
335 < }
336 <
337 < /* find_client()
297 > /* hash_find_client()
298   *
299   * inputs       - pointer to name
300   * output       - NONE
# Line 343 | Line 303 | hash_del_resv(struct ResvChannel *chptr)
303   *                it to the top of the list and returns it.
304   */
305   struct Client *
306 < find_client(const char *name)
306 > hash_find_client(const char *name)
307   {
308    unsigned int hashv = strhash(name);
309    struct Client *client_p;
# Line 399 | Line 359 | hash_find_id(const char *name)
359   }
360  
361   struct Client *
362 < find_server(const char *name)
362 > hash_find_server(const char *name)
363   {
364    unsigned int hashv = strhash(name);
365    struct Client *client_p = NULL;
366  
367    if (IsDigit(*name) && strlen(name) == IRC_MAXSID)
368 <    client_p = hash_find_id(name);
368 >    return hash_find_id(name);
369  
370 <  if ((client_p == NULL) && (client_p = clientTable[hashv]) != NULL)
370 >  if ((client_p = clientTable[hashv]) != NULL)
371    {
372      if ((!IsServer(client_p) && !IsMe(client_p)) ||
373          irccmp(name, client_p->name))
# Line 498 | Line 458 | hash_get_bucket(int type, unsigned int h
458      case HASH_TYPE_USERHOST:
459        return userhostTable[hashv];
460        break;
501    case HASH_TYPE_RESERVED:
502      return resvchannelTable[hashv];
503      break;
461      default:
462        assert(0);
463    }
# Line 508 | Line 465 | hash_get_bucket(int type, unsigned int h
465    return NULL;
466   }
467  
511 /* hash_find_resv()
512 *
513 * inputs       - pointer to name
514 * output       - NONE
515 * side effects - New semantics: finds a reserved channel whose name is 'name',
516 *                if can't find one returns NULL, if can find it moves
517 *                it to the top of the list and returns it.
518 */
519 struct ResvChannel *
520 hash_find_resv(const char *name)
521 {
522  unsigned int hashv = strhash(name);
523  struct ResvChannel *chptr;
524
525  if ((chptr = resvchannelTable[hashv]) != NULL)
526  {
527    if (irccmp(name, chptr->name))
528    {
529      struct ResvChannel *prev;
530
531      while (prev = chptr, (chptr = chptr->hnext) != NULL)
532      {
533        if (!irccmp(name, chptr->name))
534        {
535          prev->hnext = chptr->hnext;
536          chptr->hnext = resvchannelTable[hashv];
537          resvchannelTable[hashv] = chptr;
538          break;
539        }
540      }
541    }
542  }
543
544  return chptr;
545 }
546
468   struct UserHost *
469   hash_find_userhost(const char *host)
470   {
# Line 584 | Line 505 | hash_find_userhost(const char *host)
505   * side effects -
506   */
507   void
508 < count_user_host(const char *user, const char *host, int *global_p,
509 <                int *local_p, int *icount_p)
508 > count_user_host(const char *user, const char *host, unsigned int *global_p,
509 >                unsigned int *local_p, unsigned int *icount_p)
510   {
511    dlink_node *ptr;
512    struct UserHost *found_userhost;
# Line 611 | Line 532 | count_user_host(const char *user, const
532    }
533   }
534  
535 + /* find_or_add_userhost()
536 + *
537 + * inputs       - host name
538 + * output       - none
539 + * side effects - find UserHost * for given host name
540 + */
541 + static struct UserHost *
542 + find_or_add_userhost(const char *host)
543 + {
544 +  struct UserHost *userhost;
545 +
546 +  if ((userhost = hash_find_userhost(host)) != NULL)
547 +    return userhost;
548 +
549 +  userhost = mp_pool_get(userhost_pool);
550 +
551 +  memset(userhost, 0, sizeof(*userhost));
552 +  strlcpy(userhost->host, host, sizeof(userhost->host));
553 +  hash_add_userhost(userhost);
554 +
555 +  return userhost;
556 + }
557 +
558   /* add_user_host()
559   *
560   * inputs       - user name
# Line 643 | Line 587 | add_user_host(const char *user, const ch
587      if (!irccmp(user, nameh->name))
588      {
589        nameh->gcount++;
590 +
591        if (!global)
592        {
593 <        if (hasident)
594 <          nameh->icount++;
595 <        nameh->lcount++;
593 >        if (hasident)
594 >          nameh->icount++;
595 >        nameh->lcount++;
596        }
597 +
598        return;
599      }
600    }
601  
602 <  nameh = BlockHeapAlloc(namehost_heap);
602 >  nameh = mp_pool_get(namehost_pool);
603 >  memset(nameh, 0, sizeof(*nameh));
604    strlcpy(nameh->name, user, sizeof(nameh->name));
605  
606    nameh->gcount = 1;
607 +
608    if (!global)
609    {
610      if (hasident)
# Line 702 | Line 650 | delete_user_host(const char *user, const
650          nameh->gcount--;
651        if (!global)
652        {
653 <        if (nameh->lcount > 0)
654 <          nameh->lcount--;
655 <        if (hasident && nameh->icount > 0)
656 <          nameh->icount--;
653 >        if (nameh->lcount > 0)
654 >          nameh->lcount--;
655 >        if (hasident && nameh->icount > 0)
656 >          nameh->icount--;
657        }
658  
659        if (nameh->gcount == 0 && nameh->lcount == 0)
660        {
661 <        dlinkDelete(&nameh->node, &found_userhost->list);
662 <        BlockHeapFree(namehost_heap, nameh);
661 >        dlinkDelete(&nameh->node, &found_userhost->list);
662 >        mp_pool_release(nameh);
663        }
664  
665        if (dlink_list_length(&found_userhost->list) == 0)
666        {
667 <        hash_del_userhost(found_userhost);
668 <        BlockHeapFree(userhost_heap, found_userhost);
667 >        hash_del_userhost(found_userhost);
668 >        mp_pool_release(found_userhost);
669        }
670  
671        return;
# Line 725 | Line 673 | delete_user_host(const char *user, const
673    }
674   }
675  
728 /* find_or_add_userhost()
729 *
730 * inputs       - host name
731 * output       - none
732 * side effects - find UserHost * for given host name
733 */
734 static struct UserHost *
735 find_or_add_userhost(const char *host)
736 {
737  struct UserHost *userhost;
738
739  if ((userhost = hash_find_userhost(host)) != NULL)
740    return userhost;
741
742  userhost = BlockHeapAlloc(userhost_heap);
743  strlcpy(userhost->host, host, sizeof(userhost->host));
744  hash_add_userhost(userhost);
745
746  return userhost;
747 }
748
676   /*
677   * Safe list code.
678   *
# Line 771 | Line 698 | find_or_add_userhost(const char *host)
698   static int
699   exceeding_sendq(struct Client *to)
700   {
701 <  if (dbuf_length(&to->localClient->buf_sendq) > (get_sendq(to) / 2))
701 >  if (dbuf_length(&to->localClient->buf_sendq) > (get_sendq(&to->localClient->confs) / 2))
702      return 1;
703    else
704      return 0;
# Line 780 | Line 707 | exceeding_sendq(struct Client *to)
707   void
708   free_list_task(struct ListTask *lt, struct Client *source_p)
709   {
710 <  dlink_node *dl, *dln;
710 >  dlink_node *dl = NULL, *dln = NULL;
711  
712    if ((dl = dlinkFindDelete(&listing_client_list, source_p)) != NULL)
713      free_dlink_node(dl);
# Line 812 | Line 739 | free_list_task(struct ListTask *lt, stru
739   * side effects -
740   */
741   static int
742 < list_allow_channel(const char *chname, struct ListTask *lt)
742 > list_allow_channel(const char *chname, const struct ListTask *lt)
743   {
744 <  dlink_node *dl = NULL;
744 >  const dlink_node *dl = NULL;
745  
746    DLINK_FOREACH(dl, lt->show_mask.head)
747 <    if (!match_chan(dl->data, chname))
747 >    if (match(dl->data, chname) != 0)
748        return 0;
749  
750    DLINK_FOREACH(dl, lt->hide_mask.head)
751 <    if (match_chan(dl->data, chname))
751 >    if (match(dl->data, chname) == 0)
752        return 0;
753  
754    return 1;
# Line 855 | Line 782 | list_one_channel(struct Client *source_p
782      return;
783    sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name,
784               chptr->chname, dlink_list_length(&chptr->members),
785 <             chptr->topic == NULL ? "" : chptr->topic);
785 >             chptr->topic);
786   }
787  
788   /* safe_list_channels()

Diff Legend

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