/[svn]/branches/newio/src/send.c
ViewVC logotype

Diff of /branches/newio/src/send.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2414 by michael, Wed Jul 17 20:29:02 2013 UTC revision 2415 by michael, Sun Jul 21 14:33:22 2013 UTC
# Line 37  Line 37 
37  #include "log.h"  #include "log.h"
38  #include "memory.h"  #include "memory.h"
39  #include "packet.h"  #include "packet.h"
40    #include "xsnprintf.h"
41    
42    
43  static uint64_t current_serial = 0;  static uint64_t current_serial = 0;
# Line 97  static int Line 98  static int
98  can_send(struct Client *to)  can_send(struct Client *to)
99  {  {
100    assert(to);    assert(to);
101    return (IsDead(to) || IsMe(to) || s_fd(&client_p->localClient->socket) == -1) ? 0 : 1;    return (IsDead(to) || IsMe(to) || s_fd(&to->localClient->socket) == -1) ? 0 : 1;
102  }  }
103    
104  /** Close the connection with the highest sendq.  /** Close the connection with the highest sendq.
# Line 150  flush_connections(struct Client *client_ Line 151  flush_connections(struct Client *client_
151      send_queued(client_p);      send_queued(client_p);
152    else    else
153    {    {
154      struct Connection *con;      struct Connection *con = send_queues;
155      for (con = send_queues; con; con = con_next(con))      for (; con; con = con->con_next)
156      {      {
157        assert(MsgQLength(&con->sendQ) > 0);        assert(MsgQLength(&con->sendQ) > 0);
158        send_queued(con->client);        send_queued(con->client_p);
159      }      }
160    }    }
161  }  }
# Line 175  send_queued(struct Client *to) Line 176  send_queued(struct Client *to)
176    assert(to);    assert(to);
177    assert(to->localClient);    assert(to->localClient);
178    
179    if (IsBlocked(to) || !can_send(to))    if (HasFlag(to, FLAGS_BLOCKED) || !can_send(to))
180      return;  /* Don't bother */      return;  /* Don't bother */
181    
182    while (MsgQLength(&to->localClient->sendQ) > 0)    while (MsgQLength(&to->localClient->sendQ) > 0)
# Line 187  send_queued(struct Client *to) Line 188  send_queued(struct Client *to)
188        msgq_delete(&to->localClient->sendQ, len);        msgq_delete(&to->localClient->sendQ, len);
189        to->localClient->lastsq = MsgQLength(&to->localClient->sendQ) / 1024;        to->localClient->lastsq = MsgQLength(&to->localClient->sendQ) / 1024;
190    
191        if (IsBlocked(to))        if (HasFlag(to, FLAGS_BLOCKED))
192        {        {
193          update_write(to);          update_write(to);
194          return;          return;
# Line 199  send_queued(struct Client *to) Line 200  send_queued(struct Client *to)
200        {        {
201          char tmp[IRCD_BUFSIZE];          char tmp[IRCD_BUFSIZE];
202    
203          snprintf(tmp, "Write error: %s", (strerror(to->localClient->error)) ?          snprintf(tmp, sizeof(tmp), "Write error: %s",
204                                           (strerror(to->localClient->error)) :                   (strerror(to->localClient->error)) ?
205                                           "Unknown error" );                   (strerror(to->localClient->error)) :
206                     "Unknown error" );
207          dead_link(to, tmp);          dead_link(to, tmp);
208        }        }
209    
# Line 220  send_queued(struct Client *to) Line 222  send_queued(struct Client *to)
222   * @param[in] prio If non-zero, send as high priority.   * @param[in] prio If non-zero, send as high priority.
223   */   */
224  void  void
225  send_buffer(struct Client *to, struct MsgBuf *buf, int prio)  send_buffer(struct Client *to, struct MsgBuf *buf, const int prio)
226  {  {
227    assert(to);    assert(to);
228    assert(buf);    assert(buf);
# Line 283  send_buffer(struct Client *to, struct Ms Line 285  send_buffer(struct Client *to, struct Ms
285   */   */
286  static void  static void
287  send_buffer_remote(struct Client *to, struct Client *from,  send_buffer_remote(struct Client *to, struct Client *from,
288                     struct MsgBuf *buf)                     struct MsgBuf *buf, const int prio)
289  {  {
290    if (!MyConnect(to))    if (!MyConnect(to))
291    {    {
# Line 333  send_buffer_remote(struct Client *to, st Line 335  send_buffer_remote(struct Client *to, st
335      return;      return;
336    }    }
337    
338    send_message(to, buf, prio);    send_buffer(to, buf, prio);
339  }  }
340    
341  /* sendto_one()  /* sendto_one()
# Line 414  sendto_channel_butone(struct Client *one Line 416  sendto_channel_butone(struct Client *one
416    
417      assert(IsClient(target_p));      assert(IsClient(target_p));
418    
419      if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)      if (HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
420        continue;        continue;
421    
422      if (type != 0 && (ms->flags & type) == 0)      if (type != 0 && (ms->flags & type) == 0)
# Line 467  void Line 469  void
469  sendto_server(struct Client *one,  sendto_server(struct Client *one,
470                const unsigned int caps,                const unsigned int caps,
471                const unsigned int nocaps,                const unsigned int nocaps,
472                const char *format, ...)                const char *pattern, ...)
473  {  {
474    struct MsgBuf *mb;    dlink_node *ptr = NULL;
475      struct MsgBuf *mb = NULL;
476    va_list vl;    va_list vl;
477    
478    va_start(vl, pattern);    va_start(vl, pattern);
479    mb = msgq_vmake(to, pattern, vl);    mb = msgq_vmake(&me, pattern, vl);
480    va_end(vl);    va_end(vl);
481    
482    DLINK_FOREACH(ptr, serv_list.head)    DLINK_FOREACH(ptr, serv_list.head)
483    {    {
484      struct Client *client_p = ptr->data;      struct Client *client_p = ptr->data;
485    
     /* If dead already skip */  
     if (IsDead(client_p))  
       continue;  
486      /* check against 'one' */      /* check against 'one' */
487      if (one != NULL && (client_p == one->from))      if (one != NULL && (client_p == one->from))
488        continue;        continue;
# Line 538  sendto_common_channels_local(struct Clie Line 538  sendto_common_channels_local(struct Clie
538        target_p = ms->client_p;        target_p = ms->client_p;
539        assert(target_p != NULL);        assert(target_p != NULL);
540    
541        if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||        if (!MyConnect(target_p) || target_p == user ||
542            target_p->localClient->serial == current_serial)            target_p->localClient->serial == current_serial)
543          continue;          continue;
544    
# Line 550  sendto_common_channels_local(struct Clie Line 550  sendto_common_channels_local(struct Clie
550      }      }
551    }    }
552    
553    if (touser && MyConnect(user) && !IsDead(user) &&    if (touser && MyConnect(user) &&
554        user->localClient->serial != current_serial)        user->localClient->serial != current_serial)
555      if (HasCap(user, cap) == cap)      if (HasCap(user, cap) == cap)
556        send_message(user, buffer, len);        send_message(user, buffer, len);
# Line 571  sendto_channel_local(int type, int nodea Line 571  sendto_channel_local(int type, int nodea
571                       const char *pattern, ...)                       const char *pattern, ...)
572  {  {
573    dlink_node *ptr;    dlink_node *ptr;
   struct Membership *ms;  
   struct Client *target_p;  
574    struct MsgBuf *mb;    struct MsgBuf *mb;
575    va_list vl;    va_list vl;
576    
577    va_start(vl, pattern);    va_start(vl, pattern);
578    mb = msgq_vmake(to, pattern, vl);    mb = msgq_vmake(NULL, pattern, vl);
579    va_end(vl);    va_end(vl);
580    
581    DLINK_FOREACH(ptr, chptr->members.head)    DLINK_FOREACH(ptr, chptr->members.head)
582    {    {
583      ms = ptr->data;      struct Membership *ms = ptr->data;
     target_p = ms->client_p;  
584    
585      if (type != 0 && (ms->flags & type) == 0)      if (type != 0 && (ms->flags & type) == 0)
586        continue;        continue;
587    
588      if (!MyConnect(target_p) || IsDefunct(target_p) ||      if (!MyConnect(ms->client_p) ||
589          (nodeaf && HasUMode(target_p, UMODE_DEAF)))          (nodeaf && HasUMode(ms->client_p, UMODE_DEAF)))
590        continue;        continue;
591    
592      send_buffer(target_p, mb, 0);      send_buffer(ms->client_p, mb, 0);
593    }    }
594    
595    msgq_clean(mb);    msgq_clean(mb);
# Line 621  sendto_channel_local_butone(struct Clien Line 618  sendto_channel_local_butone(struct Clien
618    va_list vl;    va_list vl;
619    
620    va_start(vl, pattern);    va_start(vl, pattern);
621    mb = msgq_vmake(to, pattern, vl);    mb = msgq_vmake(NULL, pattern, vl);
622    va_end(vl);    va_end(vl);
623    
624    DLINK_FOREACH(ptr, chptr->members.head)          DLINK_FOREACH(ptr, chptr->members.head)      
# Line 633  sendto_channel_local_butone(struct Clien Line 630  sendto_channel_local_butone(struct Clien
630        continue;        continue;
631    
632      if (!MyConnect(target_p) || target_p == one ||      if (!MyConnect(target_p) || target_p == one ||
633          IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))          HasUMode(target_p, UMODE_DEAF))
634        continue;        continue;
635    
636      if (HasCap(target_p, cap) != cap)      if (HasCap(target_p, cap) != cap)
# Line 669  sendto_channel_remote(struct Client *one Line 666  sendto_channel_remote(struct Client *one
666    va_list vl;    va_list vl;
667    
668    va_start(vl, pattern);    va_start(vl, pattern);
669    mb = msgq_vmake(to, pattern, vl);    mb = msgq_vmake(&me, pattern, vl);
670    va_end(vl);    va_end(vl);
671    
672    ++current_serial;    ++current_serial;
# Line 718  sendto_channel_remote(struct Client *one Line 715  sendto_channel_remote(struct Client *one
715   * side effects - NONE   * side effects - NONE
716   */   */
717  static int  static int
718  match_it(const struct Client *one, const char *mask, int what)  match_it(const struct Client *one, const char *mask, const int what)
719  {  {
720    if (what == MATCH_HOST)    if (what == MATCH_HOST)
721      return !match(mask, one->host);      return !match(mask, one->host);
# Line 734  match_it(const struct Client *one, const Line 731  match_it(const struct Client *one, const
731   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
732   */   */
733  void  void
734  sendto_match_butone(struct Client *one, struct Client *from, char *mask,  sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
735                      int what, const char *pattern, ...)                      const int what, const char *pattern, ...)
736  {  {
737    va_list alocal, aremote;    struct VarData vd;
738    struct Client *client_p;    struct MsgBuf *user_mb = NULL;
739    dlink_node *ptr, *ptr_next;    struct MsgBuf *serv_mb = NULL;
740    char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];    dlink_node *ptr = NULL, *ptr_next = NULL;
   int local_len = sprintf(local_buf, ":%s!%s@%s ", from->name,  
                           from->username, from->host);  
   int remote_len = sprintf(remote_buf, ":%s ", from->name);  
741    
742    va_start(alocal, pattern);    vd.vd_format = pattern;
743    va_start(aremote, pattern);  
744    local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,    /* Build buffer to send to users */
745                             pattern, alocal);    va_start(vd.vd_args, pattern);
746    remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,    user_mb = msgq_make(NULL, ":%s!%s@%s %v",
747                              pattern, aremote);                        from->name,
748    va_end(aremote);                        from->username, from->host, &vd);
749    va_end(alocal);    va_end(vd.vd_args);
750    
751      /* Build buffer to send to servers */
752      va_start(vd.vd_args, pattern);
753      serv_mb = msgq_make(&me, ":%s %v", from->name, &vd);
754      va_end(vd.vd_args);
755    
756    /* scan the local clients */    /* scan the local clients */
757    DLINK_FOREACH(ptr, local_client_list.head)    DLINK_FOREACH(ptr, local_client_list.head)
758    {    {
759      client_p = ptr->data;      struct Client *client_p = ptr->data;
760    
761      if (client_p != one && !IsDefunct(client_p) &&      if (client_p != one && match_it(client_p, mask, what))
762          match_it(client_p, mask, what))        send_buffer(client_p, user_mb, 0);
       send_message(client_p, local_buf, local_len);  
763    }    }
764    
765    /* Now scan servers */    /* Now scan servers */
766    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
767    {    {
768      client_p = ptr->data;      struct Client *client_p = ptr->data;
769    
770      /*      /*
771       * The old code looped through every client on the       * The old code looped through every client on the
# Line 793  sendto_match_butone(struct Client *one, Line 791  sendto_match_butone(struct Client *one,
791       * server deal with it.       * server deal with it.
792       * -wnder       * -wnder
793       */       */
794      if (client_p != one && !IsDefunct(client_p))      if (client_p != one)
795        send_message_remote(client_p, from, remote_buf, remote_len);        send_message_remote(client_p, from, serv_mb, 0);
796    }    }
797    
798      msgq_clean(user_mb);
799      msgq_clean(serv_mb);
800  }  }
801    
802  /* sendto_match_servs()  /* sendto_match_servs()
# Line 975  sendto_wallops_flags(unsigned int flags, Line 976  sendto_wallops_flags(unsigned int flags,
976      len = sprintf(buffer, ":%s WALLOPS :", source_p->name);      len = sprintf(buffer, ":%s WALLOPS :", source_p->name);
977    
978    va_start(args, pattern);    va_start(args, pattern);
979    len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);    snprintf(&buffer[len], sizeof(buffer) - len, pattern, args);
980    va_end(args);    va_end(args);
981    
982    DLINK_FOREACH(ptr, oper_list.head)    DLINK_FOREACH(ptr, oper_list.head)
# Line 983  sendto_wallops_flags(unsigned int flags, Line 984  sendto_wallops_flags(unsigned int flags,
984      struct Client *client_p = ptr->data;      struct Client *client_p = ptr->data;
985      assert(client_p->umodes & UMODE_OPER);      assert(client_p->umodes & UMODE_OPER);
986    
987      if (HasUMode(client_p, flags) && !IsDefunct(client_p))      if (HasUMode(client_p, flags))
988        send_message(client_p, buffer, len);        sendto_one(client_p, "%s", buffer);
989    }    }
990  }  }
991    

Legend:
Removed from v.2414  
changed lines
  Added in v.2415

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28