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

Comparing:
ircd-hybrid-8/src/channel.c (file contents), Revision 1429 by michael, Thu Jun 7 19:14:14 2012 UTC vs.
ircd-hybrid/trunk/src/channel.c (file contents), Revision 1826 by michael, Mon Apr 15 09:09:09 2013 UTC

# Line 30 | Line 30
30   #include "channel_mode.h"
31   #include "client.h"
32   #include "hash.h"
33 + #include "conf.h"
34   #include "hostmask.h"
35   #include "irc_string.h"
35 #include "sprintf_irc.h"
36   #include "ircd.h"
37   #include "numeric.h"
38   #include "s_serv.h"             /* captab */
39   #include "s_user.h"
40   #include "send.h"
41 #include "conf.h"             /* ConfigFileEntry, ConfigChannel */
41   #include "event.h"
42   #include "memory.h"
43 < #include "balloc.h"
43 > #include "mempool.h"
44 > #include "s_misc.h"
45 > #include "resv.h"
46  
47   struct config_channel_entry ConfigChannel;
48   dlink_list global_channel_list = { NULL, NULL, 0 };
49 < BlockHeap *ban_heap;    /*! \todo ban_heap shouldn't be a global var */
49 > mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
50  
51 < static BlockHeap *member_heap = NULL;
52 < static BlockHeap *channel_heap = NULL;
51 > static mp_pool_t *member_pool = NULL;
52 > static mp_pool_t *channel_pool = NULL;
53  
54   static char buf[IRCD_BUFSIZE];
55   static char modebuf[MODEBUFLEN];
# Line 58 | Line 59 | static char parabuf[MODEBUFLEN];
59   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
60   */
61   void
62 < init_channels(void)
62 > channel_init(void)
63   {
64    add_capability("EX", CAP_EX, 1);
65    add_capability("IE", CAP_IE, 1);
66    add_capability("CHW", CAP_CHW, 1);
67  
68 <  channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
69 <  ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
70 <  member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
68 >  channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
69 >  ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
70 >  member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
71   }
72  
73   /*! \brief adds a user to a channel by adding another link to the
# Line 103 | Line 104 | add_user_to_channel(struct Channel *chpt
104        if (!IsSetJoinFloodNoticed(chptr))
105        {
106          SetJoinFloodNoticed(chptr);
107 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
107 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
108                               "Possible Join Flooder %s on %s target: %s",
109                               get_client_name(who, HIDE_IP),
110                               who->servptr->name, chptr->chname);
# Line 113 | Line 114 | add_user_to_channel(struct Channel *chpt
114      chptr->last_join_time = CurrentTime;
115    }
116  
117 <  ms = BlockHeapAlloc(member_heap);
117 >  ms = mp_pool_get(member_pool);
118 >  memset(ms, 0, sizeof(*ms));
119 >
120    ms->client_p = who;
121    ms->chptr = chptr;
122    ms->flags = flags;
# Line 135 | Line 138 | remove_user_from_channel(struct Membersh
138    dlinkDelete(&member->channode, &chptr->members);
139    dlinkDelete(&member->usernode, &client_p->channel);
140  
141 <  BlockHeapFree(member_heap, member);
141 >  mp_pool_release(member);
142  
143    if (chptr->members.head == NULL)
144      destroy_channel(chptr);
# Line 156 | Line 159 | send_members(struct Client *client_p, st
159    int tlen;              /* length of text to append */
160    char *t, *start;       /* temp char pointer */
161  
162 <  start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
163 <                               ID_or_name(&me, client_p),
164 <                               (unsigned long)chptr->channelts,
165 <                               chptr->chname, lmodebuf, lparabuf);
162 >  start = t = buf + sprintf(buf, ":%s SJOIN %lu %s %s %s:",
163 >                            ID_or_name(&me, client_p),
164 >                            (unsigned long)chptr->channelts,
165 >                            chptr->chname, lmodebuf, lparabuf);
166  
167    DLINK_FOREACH(ptr, chptr->members.head)
168    {
# Line 229 | Line 232 | send_mode_list(struct Client *client_p,
232      return;
233  
234    if (ts5)
235 <    mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
235 >    mlen = sprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
236    else
237 <    mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id,
238 <                      (unsigned long)chptr->channelts, chptr->chname, flag);
237 >    mlen = sprintf(buf, ":%s BMASK %lu %s %c :", me.id,
238 >                   (unsigned long)chptr->channelts, chptr->chname, flag);
239  
240    /* MODE needs additional one byte for space between buf and pbuf */
241    cur_len = mlen + ts5;
# Line 270 | Line 273 | send_mode_list(struct Client *client_p,
273        *mp = '\0';
274      }
275  
276 <    pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
277 <                     banptr->host);
276 >    pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
277 >                  banptr->host);
278      cur_len += tlen;
279    }
280  
# Line 286 | Line 289 | send_mode_list(struct Client *client_p,
289   void
290   send_channel_modes(struct Client *client_p, struct Channel *chptr)
291   {
289  if (chptr->chname[0] != '#')
290    return;
291
292    *modebuf = *parabuf = '\0';
293    channel_modes(chptr, client_p, modebuf, parabuf);
294    send_members(client_p, chptr, modebuf, parabuf);
295  
296    send_mode_list(client_p, chptr, &chptr->banlist, 'b');
297 <
298 <  if (IsCapable(client_p, CAP_EX))
299 <    send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
300 <  if (IsCapable(client_p, CAP_IE))
301 <    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
297 >  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
298 >  send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
299   }
300  
301   /*! \brief check channel name for invalid characters
# Line 310 | Line 307 | int
307   check_channel_name(const char *name, int local)
308   {
309    const char *p = name;
310 <  int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
310 >  const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
311    assert(name != NULL);
312  
313    if (!IsChanPrefix(*p))
# Line 342 | Line 339 | remove_ban(struct Ban *bptr, dlink_list
339    MyFree(bptr->host);
340    MyFree(bptr->who);
341  
342 <  BlockHeapFree(ban_heap, bptr);
342 >  mp_pool_release(bptr);
343   }
344  
345   /* free_channel_list()
# Line 374 | Line 371 | make_channel(const char *chname)
371  
372    assert(!EmptyString(chname));
373  
374 <  chptr = BlockHeapAlloc(channel_heap);
374 >  chptr = mp_pool_get(channel_pool);
375 >
376 >  memset(chptr, 0, sizeof(*chptr));
377  
378    /* doesn't hurt to set it here */
379    chptr->channelts = CurrentTime;
# Line 407 | Line 406 | destroy_channel(struct Channel *chptr)
406    dlinkDelete(&chptr->node, &global_channel_list);
407    hash_del_channel(chptr);
408  
409 <  BlockHeapFree(channel_heap, chptr);
409 >  mp_pool_release(chptr);
410   }
411  
412   /*!
# Line 445 | Line 444 | channel_member_names(struct Client *sour
444  
445    if (PubChannel(chptr) || is_member)
446    {
447 <    t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
448 <                          me.name, source_p->name,
449 <                          channel_pub_or_secret(chptr),
450 <                          chptr->chname);
447 >    t = lbuf + sprintf(lbuf, form_str(RPL_NAMREPLY),
448 >                       me.name, source_p->name,
449 >                       channel_pub_or_secret(chptr),
450 >                       chptr->chname);
451      start = t;
452  
453      DLINK_FOREACH(ptr, chptr->members.head)
# Line 483 | Line 482 | channel_member_names(struct Client *sour
482          t = start;
483        }
484  
485 <      t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
486 <                      target_p->name);
485 >      t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
486 >                   target_p->name);
487      }
488  
489      if (tlen != 0)
# Line 596 | Line 595 | find_bmask(const struct Client *who, con
595  
596    DLINK_FOREACH(ptr, list->head)
597    {
598 <    struct Ban *bp = ptr->data;
598 >    const struct Ban *bp = ptr->data;
599  
600 <    if (match(bp->name, who->name) && match(bp->username, who->username))
600 >    if (!match(bp->name, who->name) && !match(bp->username, who->username))
601      {
602        switch (bp->type)
603        {
604          case HM_HOST:
605 <          if (match(bp->host, who->host) || match(bp->host, who->sockhost))
605 >          if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
606              return 1;
607            break;
608          case HM_IPV4:
# Line 636 | Line 635 | int
635   is_banned(const struct Channel *chptr, const struct Client *who)
636   {
637    if (find_bmask(who, &chptr->banlist))
638 <    if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist))
638 >    if (!find_bmask(who, &chptr->exceptlist))
639        return 1;
640  
641    return 0;
# Line 668 | Line 667 | can_join(struct Client *source_p, struct
667  
668    if (chptr->mode.mode & MODE_INVITEONLY)
669      if (!dlinkFind(&source_p->localClient->invited, chptr))
670 <      if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
670 >      if (!find_bmask(source_p, &chptr->invexlist))
671          return ERR_INVITEONLYCHAN;
672  
673 <  if (chptr->mode.key[0] && (!key || irccmp(chptr->mode.key, key)))
673 >  if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
674      return ERR_BADCHANNELKEY;
675  
676    if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
# Line 720 | Line 719 | can_send(struct Channel *chptr, struct C
719  
720    if (MyClient(source_p) && !IsExemptResv(source_p))
721      if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
722 <      if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)
722 >      if (!match_find_resv(chptr->chname) == ConfigChannel.restrict_channels)
723          return ERR_CANNOTSENDTOCHAN;
724  
725    if (ms != NULL || (ms = find_channel_link(source_p, chptr)))
# Line 728 | Line 727 | can_send(struct Channel *chptr, struct C
727      if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
728        return CAN_SEND_OPV;
729  
731    if (chptr->mode.mode & MODE_REGONLY)
732      if (!HasUMode(source_p, UMODE_REGISTERED))
733        return ERR_NEEDREGGEDNICK;
734
730      /* cache can send if quiet_on_ban and banned */
731      if (ConfigChannel.quiet_on_ban && MyClient(source_p))
732      {
# Line 756 | Line 751 | can_send(struct Channel *chptr, struct C
751    if (chptr->mode.mode & MODE_MODERATED)
752      return ERR_CANNOTSENDTOCHAN;
753  
759  if (chptr->mode.mode & MODE_REGONLY)
760    if (!HasUMode(source_p, UMODE_REGISTERED))
761      return ERR_NEEDREGGEDNICK;
762
754    return CAN_SEND_NONOP;
755   }
756  
# Line 788 | Line 779 | check_spambot_warning(struct Client *sou
779      {
780        /* Its already known as a possible spambot */
781        if (name != NULL)
782 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
782 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
783                               "User %s (%s@%s) trying to join %s is a possible spambot",
784                               source_p->name, source_p->username,
785                               source_p->host, name);
786        else
787 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
787 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
788                               "User %s (%s@%s) is a possible spambot",
789                               source_p->name, source_p->username,
790                               source_p->host);
# Line 844 | Line 835 | check_splitmode(void *unused)
835      {
836        splitmode = 1;
837  
838 <      sendto_realops_flags(UMODE_ALL,L_ALL,
838 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
839                             "Network split, activating splitmode");
840        eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
841      }
# Line 852 | Line 843 | check_splitmode(void *unused)
843      {
844        splitmode = 0;
845  
846 <      sendto_realops_flags(UMODE_ALL, L_ALL,
846 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
847                             "Network rejoined, deactivating splitmode");
848        eventDelete(check_splitmode, NULL);
849      }
# Line 867 | Line 858 | check_splitmode(void *unused)
858   */
859   void
860   set_channel_topic(struct Channel *chptr, const char *topic,
861 <                  const char *topic_info, time_t topicts)
861 >                  const char *topic_info, time_t topicts, int local)
862   {
863 <  strlcpy(chptr->topic, topic, sizeof(chptr->topic));
863 >  if (local)
864 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
865 >  else
866 >    strlcpy(chptr->topic, topic, sizeof(chptr->topic));
867 >
868    strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
869    chptr->topic_time = topicts;
870   }

Diff Legend

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