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

Comparing:
ircd-hybrid-8/src/send.c (file contents), Revision 1474 by michael, Sun Jul 22 14:44:07 2012 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 2565 by michael, Sun Nov 17 18:40:26 2013 UTC

# Line 34 | Line 34
34   #include "fdlist.h"
35   #include "s_bsd.h"
36   #include "s_serv.h"
37 #include "sprintf_irc.h"
37   #include "conf.h"
38   #include "log.h"
39   #include "memory.h"
41 #include "hook.h"
40   #include "packet.h"
41  
42  
45 struct Callback *iosend_cb = NULL;
43   static unsigned int current_serial = 0;
44  
45  
# Line 82 | Line 79 | send_format(char *lsendbuf, int bufsize,
79   }
80  
81   /*
85 * iosend_default - append a packet to the client's sendq.
86 */
87 void *
88 iosend_default(va_list args)
89 {
90  struct Client *to = va_arg(args, struct Client *);
91  int length = va_arg(args, int);
92  char *buf = va_arg(args, char *);
93
94  dbuf_put(&to->localClient->buf_sendq, buf, length);
95  return NULL;
96 }
97
98 /*
82   ** send_message
83   **      Internal utility which appends given buffer to the sockets
84   **      sendq.
# Line 106 | Line 89 | send_message(struct Client *to, char *bu
89    assert(!IsMe(to));
90    assert(to != &me);
91  
92 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
92 >  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs))
93    {
94      if (IsServer(to))
95 <      sendto_realops_flags(UMODE_ALL, L_ALL,
96 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
95 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
96 >                           "Max SendQ limit exceeded for %s: %lu > %u",
97                             get_client_name(to, HIDE_IP),
98                             (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
99 <                           get_sendq(to));
99 >                           get_sendq(&to->localClient->confs));
100      if (IsClient(to))
101        SetSendQExceeded(to);
102      dead_link_on_write(to, 0);
103      return;
104    }
105 <
106 <  execute_callback(iosend_cb, to, len, buf);
105 >
106 >  dbuf_put(&to->localClient->buf_sendq, buf, len);
107  
108    /*
109     ** Update statistics. The following is slightly incorrect
# Line 152 | Line 135 | send_message_remote(struct Client *to, s
135   {
136    if (!MyConnect(to))
137    {
138 <    sendto_realops_flags(UMODE_ALL, L_ALL,
138 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
139                           "server send message to %s [%s] dropped from %s(Not local server)",
140                           to->name, to->from->name, from->name);
141      return;
# Line 165 | Line 148 | send_message_remote(struct Client *to, s
148    {
149      if (IsServer(from))
150      {
151 <      sendto_realops_flags(UMODE_ALL, L_ALL,
151 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
152                             "Send message to %s [%s] dropped from %s(Fake Dir)",
153                             to->name, to->from->name, from->name);
154        return;
155      }
156  
157 <    sendto_realops_flags(UMODE_ALL, L_ALL,
157 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
158                           "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
159                           to->name, to->username, to->host,
160                           from->name, from->username, from->host,
# Line 368 | Line 351 | sendto_one(struct Client *to, const char
351   */
352   void
353   sendto_channel_butone(struct Client *one, struct Client *from,
354 <                      struct Channel *chptr, const char *command,
354 >                      struct Channel *chptr, unsigned int type,
355                        const char *pattern, ...)
356   {
357    va_list alocal, aremote, auid;
# Line 379 | Line 362 | sendto_channel_butone(struct Client *one
362    dlink_node *ptr = NULL, *ptr_next = NULL;
363  
364    if (IsServer(from))
365 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
366 <                           from->name, command, chptr->chname);
365 >    local_len = snprintf(local_buf, sizeof(local_buf), ":%s ",
366 >                        from->name);
367    else
368 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
369 <                           from->name, from->username, from->host,
370 <                           command, chptr->chname);
371 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
372 <                          from->name, command, chptr->chname);
390 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
391 <                       ID(from), command, chptr->chname);
368 >    local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
369 >                         from->name, from->username, from->host);
370 >  remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
371 >                        from->name);
372 >  uid_len = snprintf(uid_buf, sizeof(uid_buf), ":%s ", ID(from));
373  
374    va_start(alocal, pattern);
375    va_start(aremote, pattern);
# Line 407 | Line 388 | sendto_channel_butone(struct Client *one
388  
389    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
390    {
391 <    struct Client *target_p = ((struct Membership *)ptr->data)->client_p;
391 >    struct Membership *ms = ptr->data;
392 >    struct Client *target_p = ms->client_p;
393  
394      assert(IsClient(target_p));
395  
396      if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
397        continue;
398  
399 +    if (type != 0 && (ms->flags & type) == 0)
400 +      continue;
401 +
402      if (MyConnect(target_p))
403      {
404        if (target_p->localClient->serial != current_serial)
# Line 503 | Line 488 | sendto_server(struct Client *one,
488   *                used by m_nick.c and exit_one_client.
489   */
490   void
491 < sendto_common_channels_local(struct Client *user, int touser,
491 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
492                               const char *pattern, ...)
493   {
494    va_list args;
# Line 536 | Line 521 | sendto_common_channels_local(struct Clie
521            target_p->localClient->serial == current_serial)
522          continue;
523  
524 +      if (HasCap(target_p, cap) != cap)
525 +        continue;
526 +
527        target_p->localClient->serial = current_serial;
528        send_message(target_p, buffer, len);
529      }
# Line 543 | Line 531 | sendto_common_channels_local(struct Clie
531  
532    if (touser && MyConnect(user) && !IsDead(user) &&
533        user->localClient->serial != current_serial)
534 <    send_message(user, buffer, len);
534 >    if (HasCap(user, cap) == cap)
535 >      send_message(user, buffer, len);
536   }
537  
538   /* sendto_channel_local()
# Line 557 | Line 546 | sendto_common_channels_local(struct Clie
546   *                locally connected to this server.
547   */
548   void
549 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
549 > sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
550                       const char *pattern, ...)
551   {
552    va_list args;
# Line 600 | Line 589 | sendto_channel_local(int type, int nodea
589   * WARNING - +D clients are omitted
590   */
591   void      
592 < sendto_channel_local_butone(struct Client *one, int type,
592 > sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
593                              struct Channel *chptr, const char *pattern, ...)
594   {
595    va_list args;
# Line 625 | Line 614 | sendto_channel_local_butone(struct Clien
614      if (!MyConnect(target_p) || target_p == one ||
615          IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
616        continue;
617 +
618 +    if (HasCap(target_p, cap) != cap)
619 +        continue;
620      send_message(target_p, buffer, len);
621    }
622   }
# Line 642 | Line 634 | sendto_channel_local_butone(struct Clien
634   *                remote to this server.
635   */
636   void
637 < sendto_channel_remote(struct Client *one, struct Client *from, int type,
637 > sendto_channel_remote(struct Client *one, struct Client *from, unsigned int type,
638                        const unsigned int caps, const unsigned int nocaps,
639                        struct Channel *chptr, const char *pattern, ...)
640   {
# Line 704 | Line 696 | static int
696   match_it(const struct Client *one, const char *mask, int what)
697   {
698    if (what == MATCH_HOST)
699 <    return match(mask, one->host);
699 >    return !match(mask, one->host);
700  
701 <  return match(mask, one->servptr->name);
701 >  return !match(mask, one->servptr->name);
702   }
703  
704   /* sendto_match_butone()
# Line 724 | Line 716 | sendto_match_butone(struct Client *one,
716    struct Client *client_p;
717    dlink_node *ptr, *ptr_next;
718    char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
719 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
720 <                             from->username, from->host);
721 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
719 >  int local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
720 >                           from->name, from->username, from->host);
721 >  int remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
722 >                            from->name);
723  
724    va_start(alocal, pattern);
725    va_start(aremote, pattern);
# Line 791 | Line 784 | sendto_match_butone(struct Client *one,
784   * side effects - data sent to servers matching with capab
785   */
786   void
787 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
787 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
788                     const char *pattern, ...)
789   {
790    va_list args;
# Line 817 | Line 810 | sendto_match_servs(struct Client *source
810      if (target_p->from->localClient->serial == current_serial)
811        continue;
812  
813 <    if (match(mask, target_p->name))
813 >    if (!match(mask, target_p->name))
814      {
815        /*
816         * if we set the serial here, then we'll never do a
# Line 860 | Line 853 | sendto_anywhere(struct Client *to, struc
853      if (IsServer(from))
854      {
855        if (IsCapable(to, CAP_TS6) && HasID(from))
856 <        len = ircsprintf(buffer, ":%s ", from->id);
856 >        len = snprintf(buffer, sizeof(buffer), ":%s ", from->id);
857        else
858 <        len = ircsprintf(buffer, ":%s ", from->name);
858 >        len = snprintf(buffer, sizeof(buffer), ":%s ", from->name);
859      }
860      else
861 <      len = ircsprintf(buffer, ":%s!%s@%s ",
862 <                       from->name, from->username, from->host);
861 >      len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s ",
862 >                     from->name, from->username, from->host);
863    }
864 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
864 >  else len = snprintf(buffer, sizeof(buffer), ":%s ", ID_or_name(from, send_to));
865  
866    va_start(args, pattern);
867    len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
868    va_end(args);
869  
870 <  if(MyClient(to))
870 >  if (MyClient(to))
871      send_message(send_to, buffer, len);
872    else
873      send_message_remote(send_to, from, buffer, len);
# Line 889 | Line 882 | sendto_anywhere(struct Client *to, struc
882   * side effects - Send to *local* ops only but NOT +s nonopers.
883   */
884   void
885 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
885 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
886   {
887 +  const char *ntype = NULL;
888    dlink_node *ptr = NULL;
889    char nbuf[IRCD_BUFSIZE];
890    va_list args;
891  
892    va_start(args, pattern);
893 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
893 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
894    va_end(args);
895  
896 <  DLINK_FOREACH(ptr, oper_list.head)
896 >  switch (type)
897    {
898 <    struct Client *client_p = ptr->data;
899 <    assert(HasUMode(client_p, UMODE_OPER));
900 <
901 <    /* If we're sending it to opers and theyre an admin, skip.
902 <     * If we're sending it to admins, and theyre not, skip.
903 <     */
904 <    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
905 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
906 <      continue;
907 <
908 <    if (HasUMode(client_p, flags))
915 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
916 <                 me.name, client_p->name, nbuf);
898 >    case SEND_NOTICE:
899 >      ntype = "Notice";
900 >      break;
901 >    case SEND_GLOBAL:
902 >      ntype = "Global";
903 >      break;
904 >    case SEND_LOCOPS:
905 >      ntype = "LocOps";
906 >      break;
907 >    default:
908 >      assert(0);
909    }
918 }
919
920 void
921 sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...)
922 {
923  dlink_node *ptr = NULL;
924  char nbuf[IRCD_BUFSIZE];
925  va_list args;
926
927  va_start(args, pattern);
928  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
929  va_end(args);
910  
911    DLINK_FOREACH(ptr, oper_list.head)
912    {
913      struct Client *client_p = ptr->data;
914 <    assert(client_p->umodes & UMODE_OPER);
914 >    assert(HasUMode(client_p, UMODE_OPER));
915  
916 <    /* If we're sending it to opers and theyre an admin, skip.
917 <     * If we're sending it to admins, and theyre not, skip.
916 >    /*
917 >     * If we're sending it to opers and they're an admin, skip.
918 >     * If we're sending it to admins, and they're not, skip.
919       */
920      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
921 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
921 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
922        continue;
923  
924      if (HasUMode(client_p, flags))
925 <      sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s",
926 <                 me.name, client_p->name, nbuf);
925 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
926 >                 me.name, client_p->name, ntype, nbuf);
927    }
928   }
929  
# Line 964 | Line 945 | sendto_wallops_flags(unsigned int flags,
945    int len;
946  
947    if (IsClient(source_p))
948 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
949 <                     source_p->name, source_p->username, source_p->host);
948 >    len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s WALLOPS :",
949 >                   source_p->name, source_p->username,
950 >                   source_p->host);
951    else
952 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
952 >    len = snprintf(buffer, sizeof(buffer), ":%s WALLOPS :",
953 >                   source_p->name);
954  
955    va_start(args, pattern);
956    len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
# Line 1020 | Line 1003 | ts_warn(const char *pattern, ...)
1003    vsnprintf(buffer, sizeof(buffer), pattern, args);
1004    va_end(args);
1005  
1006 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1006 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
1007    ilog(LOG_TYPE_IRCD, "%s", buffer);
1008   }
1009  
# Line 1045 | Line 1028 | kill_client(struct Client *client_p, str
1028    if (IsDead(client_p))
1029      return;
1030  
1031 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1032 <                   ID_or_name(diedie, client_p));
1031 >  len = snprintf(buffer, sizeof(buffer), ":%s KILL %s :",
1032 >                 ID_or_name(&me, client_p->from),
1033 >                 ID_or_name(diedie, client_p));
1034  
1035    va_start(args, pattern);
1036    len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
# Line 1066 | Line 1050 | kill_client(struct Client *client_p, str
1050   *                client being unknown to leaf, as in lazylink...
1051   */
1052   void
1053 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1054 <                           const char *pattern, ...)
1053 > kill_client_serv_butone(struct Client *one, struct Client *source_p,
1054 >                        const char *pattern, ...)
1055   {
1056    va_list args;
1057    int have_uid = 0;
# Line 1079 | Line 1063 | kill_client_ll_serv_butone(struct Client
1063    {
1064      have_uid = 1;
1065      va_start(args, pattern);
1066 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1066 >    len_uid = snprintf(buf_uid, sizeof(buf_uid), ":%s KILL %s :",
1067 >                       me.id, ID(source_p));
1068      len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1069                             args);
1070      va_end(args);
1071    }
1072  
1073    va_start(args, pattern);
1074 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1074 >  len_nick = snprintf(buf_nick, sizeof(buf_nick), ":%s KILL %s :",
1075 >                      me.name, source_p->name);
1076    len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1077                            args);
1078    va_end(args);

Diff Legend

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