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

Comparing ircd-hybrid/trunk/src/channel_mode.c (file contents):
Revision 4800 by michael, Tue Oct 28 13:59:43 2014 UTC vs.
Revision 5031 by michael, Sat Dec 13 15:13:16 2014 UTC

# Line 83 | Line 83 | const struct mode_letter chan_modes[] =
83   static char *
84   check_string(char *s)
85   {
86 <  char *str = s;
86 >  char *const str = s;
87    static char star[] = "*";
88  
89    if (EmptyString(str))
# Line 113 | Line 113 | add_id(struct Client *client_p, struct C
113   {
114    dlink_list *list = NULL;
115    dlink_node *node = NULL;
116 <  struct Ban *banptr = NULL;
116 >  struct Ban *ban = NULL;
117    size_t len = 0;
118    char name[NICKLEN + 1] = "";
119    char user[USERLEN + 1] = "";
# Line 151 | Line 151 | add_id(struct Client *client_p, struct C
151     * Re-assemble a new n!u@h and print it back to banid for sending
152     * the mode to the channel.
153     */
154 <  len = sprintf(banid, "%s!%s@%s", name, user, host);
154 >  len = snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host);
155  
156    switch (type)
157    {
158      case CHFL_BAN:
159        list = &chptr->banlist;
160 <      clear_ban_cache(chptr);
160 >      clear_ban_cache_channel(chptr);
161        break;
162      case CHFL_EXCEPTION:
163        list = &chptr->exceptlist;
164 <      clear_ban_cache(chptr);
164 >      clear_ban_cache_channel(chptr);
165        break;
166      case CHFL_INVEX:
167        list = &chptr->invexlist;
# Line 173 | Line 173 | add_id(struct Client *client_p, struct C
173  
174    DLINK_FOREACH(node, list->head)
175    {
176 <    banptr = node->data;
176 >    ban = node->data;
177  
178 <    if (!irccmp(banptr->name, name) &&
179 <        !irccmp(banptr->user, user) &&
180 <        !irccmp(banptr->host, host))
178 >    if (!irccmp(ban->name, name) &&
179 >        !irccmp(ban->user, user) &&
180 >        !irccmp(ban->host, host))
181        return 0;
182    }
183  
184 <  banptr = mp_pool_get(ban_pool);
185 <  banptr->name = xstrdup(name);
186 <  banptr->user = xstrdup(user);
187 <  banptr->host = xstrdup(host);
188 <  banptr->when = CurrentTime;
189 <  banptr->len = len - 2;  /* -2 for ! + @ */
190 <  banptr->type = parse_netmask(host, &banptr->addr, &banptr->bits);
184 >  ban = mp_pool_get(ban_pool);
185 >  ban->name = xstrdup(name);
186 >  ban->user = xstrdup(user);
187 >  ban->host = xstrdup(host);
188 >  ban->when = CurrentTime;
189 >  ban->len = len - 2;  /* -2 for ! + @ */
190 >  ban->type = parse_netmask(host, &ban->addr, &ban->bits);
191  
192    if (IsClient(client_p))
193    {
194 <    banptr->who = MyCalloc(strlen(client_p->name) +
195 <                           strlen(client_p->username) +
196 <                           strlen(client_p->host) + 3);
197 <    sprintf(banptr->who, "%s!%s@%s", client_p->name,
194 >    ban->who = MyCalloc(strlen(client_p->name) +
195 >                        strlen(client_p->username) +
196 >                        strlen(client_p->host) + 3);
197 >    sprintf(ban->who, "%s!%s@%s", client_p->name,
198              client_p->username, client_p->host);
199    }
200    else if (IsHidden(client_p) || (IsServer(client_p) && ConfigServerHide.hide_servers))
201 <    banptr->who = xstrdup(me.name);
201 >    ban->who = xstrdup(me.name);
202    else
203 <    banptr->who = xstrdup(client_p->name);
203 >    ban->who = xstrdup(client_p->name);
204  
205 <  dlinkAdd(banptr, &banptr->node, list);
205 >  dlinkAdd(ban, &ban->node, list);
206  
207    return 1;
208   }
# Line 241 | Line 241 | del_id(struct Channel *chptr, char *bani
241     * Re-assemble a new n!u@h and print it back to banid for sending
242     * the mode to the channel.
243     */
244 <  sprintf(banid, "%s!%s@%s", name, user, host);
244 >  snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host);
245  
246    switch (type)
247    {
248      case CHFL_BAN:
249        list = &chptr->banlist;
250 <      clear_ban_cache(chptr);
250 >      clear_ban_cache_channel(chptr);
251        break;
252      case CHFL_EXCEPTION:
253        list = &chptr->exceptlist;
254 <      clear_ban_cache(chptr);
254 >      clear_ban_cache_channel(chptr);
255        break;
256      case CHFL_INVEX:
257        list = &chptr->invexlist;
# Line 263 | Line 263 | del_id(struct Channel *chptr, char *bani
263  
264    DLINK_FOREACH(node, list->head)
265    {
266 <    struct Ban *banptr = node->data;
266 >    struct Ban *ban = node->data;
267  
268 <    if (!irccmp(name, banptr->name) &&
269 <        !irccmp(user, banptr->user) &&
270 <        !irccmp(host, banptr->host))
268 >    if (!irccmp(name, ban->name) &&
269 >        !irccmp(user, ban->user) &&
270 >        !irccmp(host, ban->host))
271      {
272 <      remove_ban(banptr, list);
272 >      remove_ban(ban, list);
273        return 1;
274      }
275    }
# Line 347 | Line 347 | fix_key(char *arg)
347   * side effects - clear ban cache
348   */
349   void
350 < clear_ban_cache(struct Channel *chptr)
350 > clear_ban_cache_channel(struct Channel *chptr)
351   {
352    dlink_node *node = NULL;
353  
354    DLINK_FOREACH(node, chptr->locmembers.head)
355    {
356 <    struct Membership *ms = node->data;
357 <    ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
356 >    struct Membership *member = node->data;
357 >    member->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
358    }
359   }
360  
# Line 365 | Line 365 | clear_ban_cache_client(struct Client *cl
365  
366    DLINK_FOREACH(node, client_p->channel.head)
367    {
368 <    struct Membership *ms = node->data;
369 <    ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
368 >    struct Membership *member = node->data;
369 >    member->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
370    }
371   }
372  
# Line 408 | Line 408 | chm_simple(struct Client *source_p, stru
408        sendto_one_numeric(source_p, &me,
409                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
410                           ERR_CHANOPRIVSNEEDED, chptr->name);
411 +
412      *errors |= SM_ERR_NOOPS;
413      return;
414    }
# Line 458 | Line 459 | chm_registered(struct Client *source_p,
459        sendto_one_numeric(source_p, &me,
460                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
461                           ERR_ONLYSERVERSCANCHANGE, chptr->name);
462 +
463      *errors |= SM_ERR_ONLYSERVER;
464      return;
465    }
# Line 567 | Line 569 | chm_ban(struct Client *source_p, struct
569  
570      DLINK_FOREACH(node, chptr->banlist.head)
571      {
572 <      const struct Ban *banptr = node->data;
572 >      const struct Ban *ban = node->data;
573        sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name,
574 <                         banptr->name, banptr->user, banptr->host,
575 <                         banptr->who, banptr->when);
574 >                         ban->name, ban->user, ban->host,
575 >                         ban->who, ban->when);
576      }
577  
578      sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name);
# Line 583 | Line 585 | chm_ban(struct Client *source_p, struct
585        sendto_one_numeric(source_p, &me,
586                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
587                           ERR_CHANOPRIVSNEEDED, chptr->name);
588 +
589      *errors |= SM_ERR_NOOPS;
590      return;
591    }
# Line 594 | Line 597 | chm_ban(struct Client *source_p, struct
597    memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
598    ++(*parn);
599  
600 <  if (!MyConnect(source_p))
601 <    if (strchr(mask, ' '))
599 <      return;
600 >  if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
601 >    return;
602  
603    switch (dir)
604    {
# Line 635 | Line 637 | chm_except(struct Client *source_p, stru
637  
638      DLINK_FOREACH(node, chptr->exceptlist.head)
639      {
640 <      const struct Ban *banptr = node->data;
640 >      const struct Ban *ban = node->data;
641  
642        sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name,
643 <                         banptr->name, banptr->user, banptr->host,
644 <                         banptr->who, banptr->when);
643 >                         ban->name, ban->user, ban->host,
644 >                         ban->who, ban->when);
645      }
646  
647      sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name);
# Line 652 | Line 654 | chm_except(struct Client *source_p, stru
654        sendto_one_numeric(source_p, &me,
655                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
656                           ERR_CHANOPRIVSNEEDED, chptr->name);
657 +
658      *errors |= SM_ERR_NOOPS;
659      return;
660    }
# Line 663 | Line 666 | chm_except(struct Client *source_p, stru
666    memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
667    ++(*parn);
668  
669 <  if (!MyConnect(source_p))
670 <    if (strchr(mask, ' '))
668 <      return;
669 >  if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
670 >    return;
671  
672    switch (dir)
673    {
# Line 704 | Line 706 | chm_invex(struct Client *source_p, struc
706  
707      DLINK_FOREACH(node, chptr->invexlist.head)
708      {
709 <      const struct Ban *banptr = node->data;
709 >      const struct Ban *ban = node->data;
710  
711        sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name,
712 <                         banptr->name, banptr->user, banptr->host,
713 <                         banptr->who, banptr->when);
712 >                         ban->name, ban->user, ban->host,
713 >                         ban->who, ban->when);
714      }
715  
716      sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name);
# Line 721 | Line 723 | chm_invex(struct Client *source_p, struc
723        sendto_one_numeric(source_p, &me,
724                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
725                           ERR_CHANOPRIVSNEEDED, chptr->name);
726 +
727      *errors |= SM_ERR_NOOPS;
728      return;
729    }
# Line 732 | Line 735 | chm_invex(struct Client *source_p, struc
735    memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
736    ++(*parn);
737  
738 <  if (!MyConnect(source_p))
739 <    if (strchr(mask, ' '))
737 <      return;
738 >  if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
739 >    return;
740  
741    switch (dir)
742    {
# Line 769 | Line 771 | chm_voice(struct Client *source_p, struc
771        sendto_one_numeric(source_p, &me,
772                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
773                           ERR_CHANOPRIVSNEEDED, chptr->name);
774 +
775      *errors |= SM_ERR_NOOPS;
776      return;
777    }
# Line 783 | Line 786 | chm_voice(struct Client *source_p, struc
786    {
787      if (!(*errors & SM_ERR_NOTONCHANNEL))
788        sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
789 +
790      *errors |= SM_ERR_NOTONCHANNEL;
791      return;
792    }
# Line 793 | Line 797 | chm_voice(struct Client *source_p, struc
797    /* no redundant mode changes */
798    if (dir == MODE_ADD &&  has_member_flags(member, CHFL_VOICE))
799      return;
800 +
801    if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
802      return;
803  
# Line 820 | Line 825 | chm_hop(struct Client *source_p, struct
825        sendto_one_numeric(source_p, &me,
826                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
827                           ERR_CHANOPRIVSNEEDED, chptr->name);
828 +
829      *errors |= SM_ERR_NOOPS;
830      return;
831    }
# Line 834 | Line 840 | chm_hop(struct Client *source_p, struct
840    {
841      if (!(*errors & SM_ERR_NOTONCHANNEL))
842        sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
843 +
844      *errors |= SM_ERR_NOTONCHANNEL;
845      return;
846    }
# Line 844 | Line 851 | chm_hop(struct Client *source_p, struct
851    /* no redundant mode changes */
852    if (dir == MODE_ADD &&  has_member_flags(member, CHFL_HALFOP))
853      return;
854 +
855    if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
856      return;
857  
# Line 871 | Line 879 | chm_op(struct Client *source_p, struct C
879        sendto_one_numeric(source_p, &me,
880                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
881                           ERR_CHANOPRIVSNEEDED, chptr->name);
882 +
883      *errors |= SM_ERR_NOOPS;
884      return;
885    }
# Line 885 | Line 894 | chm_op(struct Client *source_p, struct C
894    {
895      if (!(*errors & SM_ERR_NOTONCHANNEL))
896        sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
897 +
898      *errors |= SM_ERR_NOTONCHANNEL;
899      return;
900    }
# Line 895 | Line 905 | chm_op(struct Client *source_p, struct C
905    /* no redundant mode changes */
906    if (dir == MODE_ADD &&  has_member_flags(member, CHFL_CHANOP))
907      return;
908 +
909    if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
910      return;
911  
# Line 930 | Line 941 | chm_limit(struct Client *source_p, struc
941  
942    if (dir == MODE_ADD && parc > *parn)
943    {
944 <    char *lstr = parv[(*parn)++];
944 >    char *const lstr = parv[(*parn)++];
945  
946      if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
947        return;
# Line 982 | Line 993 | chm_key(struct Client *source_p, struct
993  
994    if (dir == MODE_ADD && parc > *parn)
995    {
996 <    char *key = fix_key(parv[(*parn)++]);
996 >    char *const key = fix_key(parv[(*parn)++]);
997  
998      if (EmptyString(key))
999        return;
# Line 1328 | Line 1339 | send_mode_changes_server(struct Client *
1339    parptr = parabuf;
1340  
1341    mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1342 <                 (unsigned long)chptr->channelts, chptr->name);
1342 >                 (unsigned long)chptr->creationtime, chptr->name);
1343  
1344    /* Loop the list of modes we have */
1345    for (unsigned i = 0; i < mode_count; ++i)
# Line 1355 | Line 1366 | send_mode_changes_server(struct Client *
1366          (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1367      {
1368        if (nc)
1369 <        sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1369 >        sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1370  
1371        nc = 0;
1372        mc = 0;
1373  
1374        mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1375 <                     (unsigned long)chptr->channelts, chptr->name);
1375 >                     (unsigned long)chptr->creationtime, chptr->name);
1376  
1377        pbl = 0;
1378        parabuf[0] = '\0';
# Line 1392 | Line 1403 | send_mode_changes_server(struct Client *
1403      parabuf[pbl - 1] = '\0';
1404  
1405    if (nc)
1406 <    sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1406 >    sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1407   }
1408  
1409   /* void send_mode_changes(struct Client *client_p,

Diff Legend

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