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 1243 by michael, Fri Sep 30 10:47:53 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"
# Line 39 | 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;
48 < 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 58 | 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];
61 static struct ResvChannel *resvchannelTable[HASHSIZE];
60  
61  
62   /* init_hash()
# Line 69 | Line 67 | static struct ResvChannel *resvchannelTa
67   *                functions and clear the tables
68   */
69   void
70 < init_hash(void)
70 > hash_init(void)
71   {
74  unsigned int i;
75
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 96 | 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 156 | Line 152 | hash_add_channel(struct Channel *chptr)
152   }
153  
154   void
159 hash_add_resv(struct ResvChannel *chptr)
160 {
161  unsigned int hashv = strhash(chptr->name);
162
163  chptr->hnext = resvchannelTable[hashv];
164  resvchannelTable[hashv] = chptr;
165 }
166
167 void
155   hash_add_userhost(struct UserHost *userhost)
156   {
157    unsigned int hashv = strhash(userhost->host);
# Line 307 | Line 294 | hash_del_channel(struct Channel *chptr)
294    }
295   }
296  
310 void
311 hash_del_resv(struct ResvChannel *chptr)
312 {
313  unsigned int hashv = strhash(chptr->name);
314  struct ResvChannel *tmp = resvchannelTable[hashv];
315
316  if (tmp != NULL)
317  {
318    if (tmp == chptr)
319    {
320      resvchannelTable[hashv] = chptr->hnext;
321      chptr->hnext = chptr;
322    }
323    else
324    {
325      while (tmp->hnext != chptr)
326        if ((tmp = tmp->hnext) == NULL)
327          return;
328
329      tmp->hnext = tmp->hnext->hnext;
330      chptr->hnext = chptr;
331    }
332  }
333 }
334
297   /* hash_find_client()
298   *
299   * inputs       - pointer to name
# Line 403 | Line 365 | hash_find_server(const char *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 496 | Line 458 | hash_get_bucket(int type, unsigned int h
458      case HASH_TYPE_USERHOST:
459        return userhostTable[hashv];
460        break;
499    case HASH_TYPE_RESERVED:
500      return resvchannelTable[hashv];
501      break;
461      default:
462        assert(0);
463    }
# Line 506 | Line 465 | hash_get_bucket(int type, unsigned int h
465    return NULL;
466   }
467  
509 /* hash_find_resv()
510 *
511 * inputs       - pointer to name
512 * output       - NONE
513 * side effects - New semantics: finds a reserved channel whose name is 'name',
514 *                if can't find one returns NULL, if can find it moves
515 *                it to the top of the list and returns it.
516 */
517 struct ResvChannel *
518 hash_find_resv(const char *name)
519 {
520  unsigned int hashv = strhash(name);
521  struct ResvChannel *chptr;
522
523  if ((chptr = resvchannelTable[hashv]) != NULL)
524  {
525    if (irccmp(name, chptr->name))
526    {
527      struct ResvChannel *prev;
528
529      while (prev = chptr, (chptr = chptr->hnext) != NULL)
530      {
531        if (!irccmp(name, chptr->name))
532        {
533          prev->hnext = chptr->hnext;
534          chptr->hnext = resvchannelTable[hashv];
535          resvchannelTable[hashv] = chptr;
536          break;
537        }
538      }
539    }
540  }
541
542  return chptr;
543 }
544
468   struct UserHost *
469   hash_find_userhost(const char *host)
470   {
# Line 582 | 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 609 | 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 641 | 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 700 | 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 723 | Line 673 | delete_user_host(const char *user, const
673    }
674   }
675  
726 /* find_or_add_userhost()
727 *
728 * inputs       - host name
729 * output       - none
730 * side effects - find UserHost * for given host name
731 */
732 static struct UserHost *
733 find_or_add_userhost(const char *host)
734 {
735  struct UserHost *userhost;
736
737  if ((userhost = hash_find_userhost(host)) != NULL)
738    return userhost;
739
740  userhost = BlockHeapAlloc(userhost_heap);
741  strlcpy(userhost->host, host, sizeof(userhost->host));
742  hash_add_userhost(userhost);
743
744  return userhost;
745 }
746
676   /*
677   * Safe list code.
678   *
# Line 769 | 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 778 | 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 810 | 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;

Diff Legend

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