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

Comparing:
ircd-hybrid-7.2/src/channel.c (file contents), Revision 633 by db, Thu Jun 1 12:30:29 2006 UTC vs.
ircd-hybrid-8/src/channel.c (file contents), Revision 1330 by michael, Sun Apr 1 12:12:00 2012 UTC

# Line 25 | Line 25
25   */
26  
27   #include "stdinc.h"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "channel.h"
30   #include "channel_mode.h"
31   #include "client.h"
32 #include "common.h"
32   #include "hash.h"
33   #include "hostmask.h"
34   #include "irc_string.h"
35   #include "sprintf_irc.h"
36   #include "ircd.h"
38 #include "list.h"
37   #include "numeric.h"
38   #include "s_serv.h"             /* captab */
39   #include "s_user.h"
40   #include "send.h"
41 < #include "s_conf.h"             /* ConfigFileEntry, ConfigChannel */
41 > #include "conf.h"             /* ConfigFileEntry, ConfigChannel */
42   #include "event.h"
43   #include "memory.h"
44   #include "balloc.h"
45  
46   struct config_channel_entry ConfigChannel;
47   dlink_list global_channel_list = { NULL, NULL, 0 };
50 dlink_list lazylink_channels = { NULL, NULL, 0 };
48   BlockHeap *ban_heap;    /*! \todo ban_heap shouldn't be a global var */
49  
53 static BlockHeap *topic_heap = NULL;
50   static BlockHeap *member_heap = NULL;
51   static BlockHeap *channel_heap = NULL;
52  
# Line 70 | Line 66 | init_channels(void)
66  
67    channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
68    ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
73  topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE);
69    member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
70   }
71  
# Line 142 | Line 137 | remove_user_from_channel(struct Membersh
137  
138    BlockHeapFree(member_heap, member);
139  
140 <  if (dlink_list_length(&chptr->members) == 0)
140 >  if (chptr->members.head == NULL)
141      destroy_channel(chptr);
142   }
143  
# Line 185 | Line 180 | send_members(struct Client *client_p, st
180      /* space will be converted into CR, but we also need space for LF..
181       * That's why we use '- 1' here
182       * -adx */
183 <    if (t + tlen - buf > sizeof(buf) - 1)
183 >    if (t + tlen - buf > IRCD_BUFSIZE - 1)
184      {
185        *(t - 1) = '\0';  /* kill the space and terminate the string */
186        sendto_one(client_p, "%s", buf);
# Line 324 | Line 319 | check_channel_name(const char *name, int
319    if (!local || !ConfigChannel.disable_fake_channels)
320    {
321      while (*++p)
322 <      if (!IsVisibleChanChar(*p))
322 >      if (!IsChanChar(*p))
323          return 0;
324    }
325    else
326    {
327      while (*++p)
328 <      if (!IsChanChar(*p))
328 >      if (!IsVisibleChanChar(*p))
329          return 0;
330    }
331  
# Line 409 | Line 404 | destroy_channel(struct Channel *chptr)
404    free_channel_list(&chptr->exceptlist);
405    free_channel_list(&chptr->invexlist);
406  
412  /* Free the topic */
413  free_topic(chptr);
414
407    dlinkDelete(&chptr->node, &global_channel_list);
408    hash_del_channel(chptr);
409  
418  if (ServerInfo.hub)
419    if ((ptr = dlinkFindDelete(&lazylink_channels, chptr)))
420      free_dlink_node(ptr);
421
410    BlockHeapFree(channel_heap, chptr);
411   }
412  
# Line 427 | Line 415 | destroy_channel(struct Channel *chptr)
415   * \return string pointer "=" if public, "@" if secret else "*"
416   */
417   static const char *
418 < channel_pub_or_secret(struct Channel *chptr)
418 > channel_pub_or_secret(const struct Channel *chptr)
419   {
420    if (SecretChannel(chptr))
421      return "@";
# Line 453 | Line 441 | channel_member_names(struct Client *sour
441    char *t = NULL, *start = NULL;
442    int tlen = 0;
443    int is_member = IsMember(source_p, chptr);
444 <  int multi_prefix = (source_p->localClient->cap_active & CAP_MULTI_PREFIX) != 0;
444 >  int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
445  
446    if (PubChannel(chptr) || is_member)
447    {
# Line 468 | Line 456 | channel_member_names(struct Client *sour
456        ms       = ptr->data;
457        target_p = ms->client_p;
458  
459 <      if (IsInvisible(target_p) && !is_member)
459 >      if (HasUMode(target_p, UMODE_INVISIBLE) && !is_member)
460          continue;
461  
462        tlen = strlen(target_p->name) + 1;  /* nick + space */
# Line 488 | Line 476 | channel_member_names(struct Client *sour
476            ++tlen;
477        }
478  
479 <      if (t + tlen - lbuf > IRCD_BUFSIZE)
479 >      if (t + tlen - lbuf > IRCD_BUFSIZE - 2)
480        {
481          *(t - 1) = '\0';
482          sendto_one(source_p, "%s", lbuf);
# Line 645 | Line 633 | find_bmask(const struct Client *who, con
633   * \return 0 if not banned, 1 otherwise
634   */
635   int
636 < is_banned(struct Channel *chptr, struct Client *who)
636 > is_banned(const struct Channel *chptr, const struct Client *who)
637   {
638    if (find_bmask(who, &chptr->banlist))
639      if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist))
# Line 667 | Line 655 | can_join(struct Client *source_p, struct
655    if (is_banned(chptr, source_p))
656      return ERR_BANNEDFROMCHAN;
657  
658 + #ifdef HAVE_LIBCRYPTO
659 +  if ((chptr->mode.mode & MODE_SSLONLY) && !source_p->localClient->fd.ssl)
660 +    return ERR_SSLONLYCHAN;
661 + #endif
662 +
663 +  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
664 +    return ERR_NEEDREGGEDNICK;
665 +
666 +  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
667 +    return ERR_OPERONLYCHAN;
668 +
669    if (chptr->mode.mode & MODE_INVITEONLY)
670      if (!dlinkFind(&source_p->localClient->invited, chptr))
671        if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
# Line 700 | Line 699 | find_channel_link(struct Client *client_
699  
700    DLINK_FOREACH(ptr, client_p->channel.head)
701      if (((struct Membership *)ptr->data)->chptr == chptr)
702 <      return (struct Membership *)ptr->data;
702 >      return ptr->data;
703  
704    return NULL;
705   }
# Line 711 | Line 710 | find_channel_link(struct Client *client_
710   * \param ms       pointer to Membership struct (can be NULL)
711   * \return CAN_SEND_OPV if op or voiced on channel\n
712   *         CAN_SEND_NONOP if can send to channel but is not an op\n
713 < *         CAN_SEND_NO if they cannot send to channel\n
713 > *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
714   */
715   int
716   can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms)
717   {
718 <  if (IsServer(source_p))
718 >  if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
719      return CAN_SEND_OPV;
720  
721    if (MyClient(source_p) && !IsExemptResv(source_p))
722 <    if (!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv))
722 >    if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
723        if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)
724 <        return CAN_SEND_NO;
724 >        return ERR_CANNOTSENDTOCHAN;
725  
726    if (ms != NULL || (ms = find_channel_link(source_p, chptr)))
727    {
# Line 733 | Line 732 | can_send(struct Channel *chptr, struct C
732      if (ConfigChannel.quiet_on_ban && MyClient(source_p))
733      {
734        if (ms->flags & CHFL_BAN_SILENCED)
735 <        return CAN_SEND_NO;
735 >        return ERR_CANNOTSENDTOCHAN;
736  
737        if (!(ms->flags & CHFL_BAN_CHECKED))
738        {
739          if (is_banned(chptr, source_p))
740          {
741            ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
742 <          return CAN_SEND_NO;
742 >          return ERR_CANNOTSENDTOCHAN;
743          }
744  
745          ms->flags |= CHFL_BAN_CHECKED;
# Line 748 | Line 747 | can_send(struct Channel *chptr, struct C
747      }
748    }
749    else if (chptr->mode.mode & MODE_NOPRIVMSGS)
750 <    return CAN_SEND_NO;
750 >    return ERR_CANNOTSENDTOCHAN;
751  
752    if (chptr->mode.mode & MODE_MODERATED)
753 <    return CAN_SEND_NO;
753 >    return ERR_CANNOTSENDTOCHAN;
754  
755    return CAN_SEND_NONOP;
756   }
# Line 852 | Line 851 | check_splitmode(void *unused)
851    }
852   }
853  
855 /*! \brief Allocates a new topic
856 * \param chptr Channel to allocate a new topic for
857 */
858 static void
859 allocate_topic(struct Channel *chptr)
860 {
861  void *ptr = NULL;
862
863  if (chptr == NULL)
864    return;
865
866  ptr = BlockHeapAlloc(topic_heap);  
867
868  /* Basically we allocate one large block for the topic and
869   * the topic info.  We then split it up into two and shove it
870   * in the chptr
871   */
872  chptr->topic       = ptr;
873  chptr->topic_info  = (char *)ptr + TOPICLEN+1;
874  *chptr->topic      = '\0';
875  *chptr->topic_info = '\0';
876 }
877
878 void
879 free_topic(struct Channel *chptr)
880 {
881  void *ptr = NULL;
882  assert(chptr);
883  if (chptr->topic == NULL)
884    return;
885
886  /*
887   * If you change allocate_topic you MUST change this as well
888   */
889  ptr = chptr->topic;
890  BlockHeapFree(topic_heap, ptr);    
891  chptr->topic      = NULL;
892  chptr->topic_info = NULL;
893 }
894
854   /*! \brief Sets the channel topic for chptr
855   * \param chptr      Pointer to struct Channel
856   * \param topic      The topic string
# Line 902 | Line 861 | void
861   set_channel_topic(struct Channel *chptr, const char *topic,
862                    const char *topic_info, time_t topicts)
863   {
864 <  if (!EmptyString(topic))
865 <  {
866 <    if (chptr->topic == NULL)
908 <      allocate_topic(chptr);
909 <
910 <    strlcpy(chptr->topic, topic, TOPICLEN+1);
911 <    strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
912 <    chptr->topic_time = topicts;
913 <  }
914 <  else
915 <  {
916 <    /*
917 <     * Do not reset chptr->topic_time here, it's required for
918 <     * bursting topics properly.
919 <     */
920 <    if (chptr->topic != NULL)
921 <      free_topic(chptr);
922 <  }
864 >  strlcpy(chptr->topic, topic, sizeof(chptr->topic));
865 >  strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
866 >  chptr->topic_time = topicts;
867   }

Diff Legend

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