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-7.2/src/send.c (file contents), Revision 430 by michael, Sat Feb 11 12:52:34 2006 UTC vs.
ircd-hybrid-8/src/send.c (file contents), Revision 1206 by michael, Wed Aug 24 21:41:23 2011 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 < #include "tools.h"
26 > #include "list.h"
27   #include "send.h"
28   #include "channel.h"
29   #include "client.h"
# Line 38 | Line 38
38   #include "s_serv.h"
39   #include "sprintf_irc.h"
40   #include "s_conf.h"
41 #include "list.h"
41   #include "s_log.h"
42   #include "memory.h"
43   #include "hook.h"
45 #include "irc_getnameinfo.h"
44   #include "packet.h"
45  
48 #define LOG_BUFSIZE 2048
46  
47   struct Callback *iosend_cb = NULL;
48   struct Callback *iosendctrl_cb = NULL;
49 + static unsigned int current_serial = 0;
50  
53 static void send_message(struct Client *, char *, int);
54 static void send_message_remote(struct Client *, struct Client *, char *, int);
55
56 static unsigned long current_serial = 0L;
51  
52   /* send_format()
53   *
# Line 87 | Line 81 | send_format(char *lsendbuf, int bufsize,
81  
82    lsendbuf[len++] = '\r';
83    lsendbuf[len++] = '\n';
84 <  return (len);
84 >  return len;
85   }
86  
87   /*
# Line 112 | Line 106 | iosend_default(va_list args)
106   static void
107   send_message(struct Client *to, char *buf, int len)
108   {
109 < #ifdef INVARIANTS
110 <  if (IsMe(to))
117 <  {
118 <    sendto_realops_flags(UMODE_ALL, L_ALL,
119 <                         "Trying to send message to myself!");
120 <    return;
121 <  }
122 < #endif
109 >  assert(!IsMe(to));
110 >  assert(to != &me);
111  
112    if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
113    {
# Line 173 | Line 161 | send_message_remote(struct Client *to, s
161      return;
162    }
163  
176  if (ServerInfo.hub && IsCapable(to, CAP_LL))
177  {
178    if (((from->lazyLinkClientExists &
179          to->localClient->serverMask) == 0))
180      client_burst_if_needed(to, from);
181  }
182
164    /* Optimize by checking if (from && to) before everything */
165    /* we set to->from up there.. */
166  
# Line 199 | Line 180 | send_message_remote(struct Client *to, s
180                           from->name, from->username, from->host,
181                           to->from->name);
182  
183 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
183 >    sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
184                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
185                    me.id, to->name, me.name, to->name,
186                    to->username, to->host, to->from->name);
187 <    sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS,
187 >    sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
188                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
189                    me.name, to->name, me.name, to->name,
190                    to->username, to->host, to->from->name);
# Line 307 | Line 288 | send_queued_write(struct Client *to)
288          retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
289  
290        if (retlen <= 0)
310      {
311 #ifdef _WIN32
312        errno = WSAGetLastError();
313 #endif
291          break;
315      }
292  
293        dbuf_delete(&to->localClient->buf_sendq, retlen);
294  
# Line 480 | Line 456 | sendto_channel_butone(struct Client *one
456    char remote_buf[IRCD_BUFSIZE];
457    char uid_buf[IRCD_BUFSIZE];
458    int local_len, remote_len, uid_len;
459 <  dlink_node *ptr;
484 <  dlink_node *ptr_next;
485 <  struct Client *target_p;
459 >  dlink_node *ptr = NULL, *ptr_next = NULL;
460  
461    if (IsServer(from))
462      local_len = ircsprintf(local_buf, ":%s %s %s ",
# Line 513 | Line 487 | sendto_channel_butone(struct Client *one
487  
488    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
489    {
490 <    target_p = ((struct Membership *)ptr->data)->client_p;
491 <    assert(target_p != NULL);
490 >    struct Client *target_p = ((struct Membership *)ptr->data)->client_p;
491 >
492 >    assert(IsClient(target_p));
493  
494      if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
495        continue;
496  
497 <    if (MyClient(target_p))
497 >    if (MyConnect(target_p))
498      {
499 <      if (target_p->serial != current_serial)
499 >      if (target_p->localClient->serial != current_serial)
500        {
501          send_message(target_p, local_buf, local_len);
502 <        target_p->serial = current_serial;
502 >        target_p->localClient->serial = current_serial;
503        }
504      }
505      else
# Line 532 | Line 507 | sendto_channel_butone(struct Client *one
507        /* Now check whether a message has been sent to this
508         * remote link already
509         */
510 <      if (target_p->from->serial != current_serial)
510 >      if (target_p->from->localClient->serial != current_serial)
511        {
512          if (IsCapable(target_p->from, CAP_TS6))
513            send_message_remote(target_p->from, from, uid_buf, uid_len);
514          else
515            send_message_remote(target_p->from, from, remote_buf, remote_len);
516 <        target_p->from->serial = current_serial;
516 >        target_p->from->localClient->serial = current_serial;
517        }
518      }
519    }
# Line 547 | Line 522 | sendto_channel_butone(struct Client *one
522   /* sendto_server()
523   *
524   * inputs       - pointer to client to NOT send to
525 < *              - pointer to source client required by LL (if any)
551 < *              - pointer to channel required by LL (if any)
525 > *              - pointer to channel
526   *              - caps or'd together which must ALL be present
527   *              - caps or'd together which must ALL NOT be present
554 *              - LL flags: LL_ICLIENT | LL_ICHAN
528   *              - printf style format string
529   *              - args to format string
530   * output       - NONE
531   * side effects - Send a message to all connected servers, except the
532   *                client 'one' (if non-NULL), as long as the servers
533   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
561 *                If the server is a lazylink client, then it must know
562 *                about source_p if non-NULL (unless LL_ICLIENT is specified,
563 *                when source_p will be introduced where required) and
564 *                chptr if non-NULL (unless LL_ICHANNEL is specified, when
565 *                chptr will be introduced where required).
566 *                Note: nothing will be introduced to a LazyLeaf unless
567 *                the message is actually sent.
534   *            
535   * This function was written in an attempt to merge together the other
536   * billion sendto_*serv*() functions, which sprung up with capabs,
# Line 572 | Line 538 | sendto_channel_butone(struct Client *one
538   * -davidt
539   */
540   void
541 < sendto_server(struct Client *one, struct Client *source_p,
542 <              struct Channel *chptr, unsigned long caps,
543 <              unsigned long nocaps, unsigned long llflags,
541 > sendto_server(struct Client *one, const struct Channel *chptr,
542 >              const unsigned int caps,
543 >              const unsigned int nocaps,
544                const char *format, ...)
545   {
546    va_list args;
547 <  struct Client *client_p;
582 <  dlink_node *ptr;
547 >  dlink_node *ptr = NULL;
548    char buffer[IRCD_BUFSIZE];
549 <  int len;
549 >  int len = 0;
550  
551 <  if (chptr != NULL)
552 <  {
588 <    if (chptr->chname[0] != '#')
589 <      return;
590 <  }
551 >  if (chptr && chptr->chname[0] != '#')
552 >    return;
553  
554    va_start(args, format);
555    len = send_format(buffer, IRCD_BUFSIZE, format, args);
# Line 595 | Line 557 | sendto_server(struct Client *one, struct
557  
558    DLINK_FOREACH(ptr, serv_list.head)
559    {
560 <    client_p = ptr->data;
560 >    struct Client *client_p = ptr->data;
561  
562      /* If dead already skip */
563      if (IsDead(client_p))
# Line 610 | Line 572 | sendto_server(struct Client *one, struct
572      if ((client_p->localClient->caps & nocaps) != 0)
573        continue;
574  
613    if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
614    {
615      /* check LL channel */
616      if (chptr != NULL &&
617          ((chptr->lazyLinkChannelExists &
618            client_p->localClient->serverMask) == 0))
619      {
620        /* Only introduce the channel if we really will send this message */
621        if (!(llflags & LL_ICLIENT) && source_p &&
622            ((source_p->lazyLinkClientExists &
623              client_p->localClient->serverMask) == 0))
624          continue; /* we can't introduce the unknown source_p, skip */
625
626        if (llflags & LL_ICHAN)
627          burst_channel(client_p, chptr);
628        else
629          continue; /* we can't introduce the unknown chptr, skip */
630      }
631      /* check LL client */
632      if (source_p &&
633          ((source_p->lazyLinkClientExists &
634            client_p->localClient->serverMask) == 0))
635      {
636        if (llflags & LL_ICLIENT)
637          client_burst_if_needed(client_p,source_p);
638        else
639          continue; /* we can't introduce the unknown source_p, skip */
640      }
641    }
575      send_message(client_p, buffer, len);
576    }
577   }
# Line 676 | Line 609 | sendto_common_channels_local(struct Clie
609      chptr = ((struct Membership *) cptr->data)->chptr;
610      assert(chptr != NULL);
611  
612 <    DLINK_FOREACH(uptr, chptr->locmembers.head)
612 >    DLINK_FOREACH(uptr, chptr->members.head)
613      {
614        ms = uptr->data;
615        target_p = ms->client_p;
616        assert(target_p != NULL);
617  
618 <      if (target_p == user || IsDefunct(target_p) ||
619 <          target_p->serial == current_serial)
618 >      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
619 >          target_p->localClient->serial == current_serial)
620          continue;
621  
622 <      target_p->serial = current_serial;
622 >      target_p->localClient->serial = current_serial;
623        send_message(target_p, buffer, len);
624      }
625    }
626  
627    if (touser && MyConnect(user) && !IsDead(user) &&
628 <      user->serial != current_serial)
628 >      user->localClient->serial != current_serial)
629      send_message(user, buffer, len);
630   }
631  
# Line 721 | Line 654 | sendto_channel_local(int type, int nodea
654    len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
655    va_end(args);
656  
657 <  DLINK_FOREACH(ptr, chptr->locmembers.head)
657 >  DLINK_FOREACH(ptr, chptr->members.head)
658    {
659      ms = ptr->data;
660      target_p = ms->client_p;
# Line 729 | Line 662 | sendto_channel_local(int type, int nodea
662      if (type != 0 && (ms->flags & type) == 0)
663        continue;
664  
665 <    if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
665 >    if (!MyConnect(target_p) || IsDefunct(target_p) ||
666 >        (nodeaf && IsDeaf(target_p)))
667        continue;
668  
669      send_message(target_p, buffer, len);
# Line 763 | Line 697 | sendto_channel_local_butone(struct Clien
697    len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
698    va_end(args);
699  
700 <  DLINK_FOREACH(ptr, chptr->locmembers.head)      
700 >  DLINK_FOREACH(ptr, chptr->members.head)      
701    {  
702      ms = ptr->data;
703      target_p = ms->client_p;
# Line 771 | Line 705 | sendto_channel_local_butone(struct Clien
705      if (type != 0 && (ms->flags & type) == 0)
706        continue;
707  
708 <    if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p))
708 >    if (!MyConnect(target_p) || target_p == one ||
709 >        IsDefunct(target_p) || IsDeaf(target_p))
710        continue;
711      send_message(target_p, buffer, len);
712    }
# Line 790 | Line 725 | sendto_channel_local_butone(struct Clien
725   *                remote to this server.
726   */
727   void
728 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
729 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
728 > sendto_channel_remote(struct Client *one, struct Client *from, int type,
729 >                      const unsigned int caps, const unsigned int nocaps,
730 >                      struct Channel *chptr, const char *pattern, ...)
731   {
732    va_list args;
733    char buffer[IRCD_BUFSIZE];
# Line 822 | Line 758 | sendto_channel_remote(struct Client *one
758          ((target_p->from->localClient->caps & caps) != caps) ||
759          ((target_p->from->localClient->caps & nocaps) != 0))
760        continue;
761 <    if (target_p->from->serial != current_serial)
761 >    if (target_p->from->localClient->serial != current_serial)
762      {
763        send_message(target_p, buffer, len);
764 <      target_p->from->serial = current_serial;
764 >      target_p->from->localClient->serial = current_serial;
765      }
766    }
767   }
# Line 851 | Line 787 | static int
787   match_it(const struct Client *one, const char *mask, int what)
788   {
789    if (what == MATCH_HOST)
790 <    return(match(mask, one->host));
790 >    return match(mask, one->host);
791  
792 <  return(match(mask, one->servptr->name));
792 >  return match(mask, one->servptr->name);
793   }
794  
795   /* sendto_match_butone()
# Line 951 | Line 887 | sendto_match_servs(struct Client *source
887    vsnprintf(buffer, sizeof(buffer), pattern, args);
888    va_end(args);
889  
890 <  current_serial++;
890 >  ++current_serial;
891  
892    DLINK_FOREACH(ptr, global_serv_list.head)
893    {
# Line 961 | Line 897 | sendto_match_servs(struct Client *source
897      if (IsMe(target_p) || target_p->from == source_p->from)
898        continue;
899  
900 <    if (target_p->from->serial == current_serial)
900 >    if (target_p->from->localClient->serial == current_serial)
901        continue;
902  
903      if (match(mask, target_p->name))
# Line 970 | Line 906 | sendto_match_servs(struct Client *source
906         * if we set the serial here, then we'll never do a
907         * match() again, if !IsCapable()
908         */
909 <      target_p->from->serial = current_serial;
909 >      target_p->from->localClient->serial = current_serial;
910        found++;
911  
912        if (!IsCapable(target_p->from, cap))
# Line 1038 | Line 974 | sendto_anywhere(struct Client *to, struc
974   void
975   sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
976   {
977 <  struct Client *client_p;
977 >  dlink_node *ptr = NULL;
978    char nbuf[IRCD_BUFSIZE];
1043  dlink_node *ptr;
979    va_list args;
980  
981    va_start(args, pattern);
# Line 1049 | Line 984 | sendto_realops_flags(unsigned int flags,
984  
985    DLINK_FOREACH(ptr, oper_list.head)
986    {
987 <    client_p = ptr->data;
987 >    struct Client *client_p = ptr->data;
988      assert(client_p->umodes & UMODE_OPER);
989  
990      /* If we're sending it to opers and theyre an admin, skip.
# Line 1065 | Line 1000 | sendto_realops_flags(unsigned int flags,
1000    }
1001   }
1002  
1003 + void
1004 + sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...)
1005 + {
1006 +  dlink_node *ptr = NULL;
1007 +  char nbuf[IRCD_BUFSIZE];
1008 +  va_list args;
1009 +
1010 +  va_start(args, pattern);
1011 +  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
1012 +  va_end(args);
1013 +
1014 +  DLINK_FOREACH(ptr, oper_list.head)
1015 +  {
1016 +    struct Client *client_p = ptr->data;
1017 +    assert(client_p->umodes & UMODE_OPER);
1018 +
1019 +    /* If we're sending it to opers and theyre an admin, skip.
1020 +     * If we're sending it to admins, and theyre not, skip.
1021 +     */
1022 +    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
1023 +        ((level == L_OPER) && IsAdmin(client_p)))
1024 +      continue;
1025 +
1026 +    if (client_p->umodes & flags)
1027 +      sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s",
1028 +                 me.name, client_p->name, nbuf);
1029 +  }
1030 + }
1031 +
1032   /* sendto_wallops_flags()
1033   *
1034   * inputs       - flag types of messages to show to real opers
# Line 1077 | Line 1041 | void
1041   sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1042                       const char *pattern, ...)
1043   {
1044 <  struct Client *client_p;
1081 <  dlink_node *ptr;
1044 >  dlink_node *ptr = NULL;
1045    va_list args;
1046    char buffer[IRCD_BUFSIZE];
1047    int len;
# Line 1095 | Line 1058 | sendto_wallops_flags(unsigned int flags,
1058  
1059    DLINK_FOREACH(ptr, oper_list.head)
1060    {
1061 <    client_p = ptr->data;
1061 >    struct Client *client_p = ptr->data;
1062      assert(client_p->umodes & UMODE_OPER);
1063  
1064      if ((client_p->umodes & flags) && !IsDefunct(client_p))
# Line 1114 | Line 1077 | void
1077   ts_warn(const char *pattern, ...)
1078   {
1079    va_list args;
1080 <  char buffer[LOG_BUFSIZE];
1080 >  char buffer[IRCD_BUFSIZE];
1081    static time_t last = 0;
1082    static int warnings = 0;
1083  
# Line 1137 | Line 1100 | ts_warn(const char *pattern, ...)
1100    }
1101  
1102    va_start(args, pattern);
1103 <  vsprintf_irc(buffer, pattern, args);
1103 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
1104    va_end(args);
1105  
1106    sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
# Line 1191 | Line 1154 | kill_client_ll_serv_butone(struct Client
1154   {
1155    va_list args;
1156    int have_uid = 0;
1157 <  struct Client *client_p;
1195 <  dlink_node *ptr;
1157 >  dlink_node *ptr = NULL;
1158    char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1159 <  int len_uid = 0, len_nick;
1159 >  int len_uid = 0, len_nick = 0;
1160  
1161 <  if (HasID(source_p) && (me.id[0] != '\0'))
1161 >  if (HasID(source_p))
1162    {
1163      have_uid = 1;
1164      va_start(args, pattern);
# Line 1214 | Line 1176 | kill_client_ll_serv_butone(struct Client
1176  
1177    DLINK_FOREACH(ptr, serv_list.head)
1178    {
1179 <    client_p = ptr->data;
1179 >    struct Client *client_p = ptr->data;
1180  
1181      if (one != NULL && (client_p == one->from))
1182        continue;
1183      if (IsDefunct(client_p))
1184        continue;
1185  
1186 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
1187 <    if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) ||
1188 <        !ServerInfo.hub ||
1189 <        (source_p->lazyLinkClientExists & client_p->localClient->serverMask))
1228 <    {
1229 <      if (have_uid && IsCapable(client_p, CAP_TS6))
1230 <        send_message(client_p, buf_uid, len_uid);
1231 <      else
1232 <        send_message(client_p, buf_nick, len_nick);
1233 <    }
1186 >    if (have_uid && IsCapable(client_p, CAP_TS6))
1187 >      send_message(client_p, buf_uid, len_uid);
1188 >    else
1189 >      send_message(client_p, buf_nick, len_nick);
1190    }
1191   }

Diff Legend

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