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/trunk/src/send.c (file contents):
Revision 7222 by michael, Wed Feb 3 15:40:58 2016 UTC vs.
Revision 8599 by michael, Sun Oct 28 18:09:37 2018 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2016 ircd-hybrid development team
4 > *  Copyright (c) 1997-2018 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 33 | Line 33
33   #include "irc_string.h"
34   #include "ircd.h"
35   #include "s_bsd.h"
36 < #include "server.h"
36 > #include "server_capab.h"
37   #include "conf_class.h"
38   #include "log.h"
39  
# Line 91 | Line 91 | send_message(struct Client *to, struct d
91      if (IsServer(to))
92        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
93                             "Max SendQ limit exceeded for %s: %zu > %u",
94 <                           get_client_name(to, HIDE_IP),
94 >                           client_get_name(to, HIDE_IP),
95                             (dbuf_length(&to->connection->buf_sendq) + buf->size),
96                             get_sendq(&to->connection->confs));
97  
# Line 126 | Line 126 | send_message(struct Client *to, struct d
126   *
127   */
128   static void
129 < send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
129 > send_message_remote(struct Client *to, const struct Client *from, struct dbuf_block *buf)
130   {
131    assert(MyConnect(to));
132    assert(IsServer(to));
# Line 149 | Line 149 | send_message_remote(struct Client *to, s
149   **      Called when a socket is ready for writing.
150   */
151   void
152 < sendq_unblocked(fde_t *fd, void *data)
152 > sendq_unblocked(fde_t *F, void *data)
153   {
154    struct Client *const client_p = data;
155 <  assert(fd == &client_p->connection->fd);
155 >
156 >  assert(client_p);
157 >  assert(client_p->connection);
158 >  assert(client_p->connection->fd);
159 >  assert(client_p->connection->fd == F);
160  
161    DelFlag(client_p, FLAGS_BLOCKED);
162    send_queued_write(client_p);
# Line 168 | Line 172 | void
172   send_queued_write(struct Client *to)
173   {
174    int retlen = 0;
171  int want_read = 0;
175  
176    /*
177     ** Once socket is marked dead, we cannot start writing to it,
# Line 182 | Line 185 | send_queued_write(struct Client *to)
185    {
186      do
187      {
188 +      int want_read = 0;
189        const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
190  
191 <      if (tls_isusing(&to->connection->fd.ssl))
191 >      if (tls_isusing(&to->connection->fd->ssl))
192        {
193 <        retlen = tls_write(&to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, &want_read);
193 >        retlen = tls_write(&to->connection->fd->ssl, first->data + to->connection->buf_sendq.pos,
194 >                                                     first->size - to->connection->buf_sendq.pos, &want_read);
195  
196          if (want_read)
197            return;  /* Retry later, don't register for write events */
198        }
199        else
200 <        retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
200 >        retlen = send(to->connection->fd->fd, first->data + to->connection->buf_sendq.pos,
201 >                                              first->size - to->connection->buf_sendq.pos, 0);
202  
203        if (retlen <= 0)
204          break;
# Line 204 | Line 210 | send_queued_write(struct Client *to)
210        me.connection->send.bytes += retlen;
211      } while (dbuf_length(&to->connection->buf_sendq));
212  
213 <    if (retlen < 0 && ignoreErrno(errno))
213 >    if (retlen < 0 && comm_ignore_errno(errno))
214      {
215        AddFlag(to, FLAGS_BLOCKED);
216  
217        /* we have a non-fatal error, reschedule a write */
218 <      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
213 <                     sendq_unblocked, to, 0);
218 >      comm_setselect(to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
219      }
220      else if (retlen <= 0)
221      {
# Line 229 | Line 234 | send_queued_write(struct Client *to)
234   void
235   send_queued_all(void)
236   {
237 <  dlink_node *node = NULL;
237 >  dlink_node *node;
238  
239    /* Servers are processed first, mainly because this can generate
240     * a notice to opers, which is to be delivered by this function.
# Line 262 | Line 267 | void
267   sendto_one(struct Client *to, const char *pattern, ...)
268   {
269    va_list args;
265  struct dbuf_block *buffer = NULL;
270  
271    if (IsDead(to->from))
272      return;  /* This socket has already been marked as dead */
273  
270  buffer = dbuf_alloc();
271
274    va_start(args, pattern);
275 +
276 +  struct dbuf_block *buffer = dbuf_alloc();
277    send_format(buffer, pattern, args);
278 +
279    va_end(args);
280  
281    send_message(to->from, buffer);
# Line 279 | Line 284 | sendto_one(struct Client *to, const char
284   }
285  
286   void
287 < sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
287 > sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
288   {
284  struct dbuf_block *buffer = NULL;
285  const char *dest = NULL, *numstr = NULL;
289    va_list args;
290 +  const char *numstr = NULL;
291  
292    if (IsDead(to->from))
293      return;
294  
295 <  dest = ID_or_name(to, to);
292 <
295 >  const char *dest = ID_or_name(to, to);
296    if (EmptyString(dest))
297      dest = "*";
298  
299 <  buffer = dbuf_alloc();
297 <
299 >  struct dbuf_block *buffer = dbuf_alloc();
300    dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
301  
302    va_start(args, numeric);
# Line 313 | Line 315 | sendto_one_numeric(struct Client *to, st
315   }
316  
317   void
318 < sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
318 > sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
319   {
318  struct dbuf_block *buffer = NULL;
319  const char *dest = NULL;
320    va_list args;
321  
322    if (IsDead(to->from))
323      return;
324  
325 <  dest = ID_or_name(to, to);
326 <
325 >  const char *dest = ID_or_name(to, to);
326    if (EmptyString(dest))
327      dest = "*";
328  
329 <  buffer = dbuf_alloc();
331 <
329 >  struct dbuf_block *buffer = dbuf_alloc();
330    dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
331  
332    va_start(args, pattern);
# Line 352 | Line 350 | sendto_one_notice(struct Client *to, str
350   * WARNING - +D clients are ignored
351   */
352   void
353 < sendto_channel_butone(struct Client *one, struct Client *from,
353 > sendto_channel_butone(struct Client *one, const struct Client *from,
354                        struct Channel *chptr, unsigned int type,
355                        const char *pattern, ...)
356   {
357    va_list alocal, aremote;
358    struct dbuf_block *local_buf, *remote_buf;
359 <  dlink_node *node = NULL;
359 >  dlink_node *node;
360  
361    local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
362  
# Line 386 | Line 384 | sendto_channel_butone(struct Client *one
384  
385      assert(IsClient(target_p));
386  
387 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
388 <        (one && target_p->from == one->from))
387 >    if (IsDefunct(target_p->from))
388 >      continue;
389 >
390 >    if (one && (target_p->from == one->from))
391        continue;
392  
393      if (type && (member->flags & type) == 0)
394        continue;
395  
396 +    if (HasUMode(target_p, UMODE_DEAF))
397 +      continue;
398 +
399      if (MyConnect(target_p))
400        send_message(target_p, local_buf);
401      else if (target_p->from->connection->serial != current_serial)
# Line 424 | Line 427 | sendto_channel_butone(struct Client *one
427   * -davidt
428   */
429   void
430 < sendto_server(struct Client *one,
430 > sendto_server(const struct Client *one,
431                const unsigned int caps,
432                const unsigned int nocaps,
433                const char *format, ...)
434   {
435    va_list args;
436 <  dlink_node *node = NULL;
434 <  struct dbuf_block *buffer = dbuf_alloc();
436 >  dlink_node *node;
437  
438    va_start(args, format);
439 +
440 +  struct dbuf_block *buffer = dbuf_alloc();
441    send_format(buffer, format, args);
442 +
443    va_end(args);
444  
445    DLINK_FOREACH(node, local_server_list.head)
# Line 494 | Line 499 | sendto_common_channels_local(struct Clie
499    {
500      chptr = ((struct Membership *)cptr->data)->chptr;
501  
502 <    DLINK_FOREACH(uptr, chptr->locmembers.head)
502 >    DLINK_FOREACH(uptr, chptr->members_local.head)
503      {
504        member = uptr->data;
505        target_p = member->client_p;
# Line 535 | Line 540 | sendto_channel_local(const struct Client
540                       unsigned int poscap, unsigned int negcap, const char *pattern, ...)
541   {
542    va_list args;
543 <  dlink_node *node = NULL;
543 >  dlink_node *node;
544    struct dbuf_block *buffer = dbuf_alloc();
545  
546    va_start(args, pattern);
547    send_format(buffer, pattern, args);
548    va_end(args);
549  
550 <  DLINK_FOREACH(node, chptr->locmembers.head)
550 >  DLINK_FOREACH(node, chptr->members_local.head)
551    {
552      struct Membership *member = node->data;
553      struct Client *target_p = member->client_p;
# Line 589 | Line 594 | static int
594   match_it(const struct Client *one, const char *mask, unsigned int what)
595   {
596    if (what == MATCH_HOST)
597 <    return !match(mask, one->host);
597 >    return match(mask, one->host) == 0;
598  
599 <  return !match(mask, one->servptr->name);
599 >  return match(mask, one->servptr->name) == 0;
600   }
601  
602   /* sendto_match_butone()
# Line 602 | Line 607 | match_it(const struct Client *one, const
607   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
608   */
609   void
610 < sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
611 <                    int what, const char *pattern, ...)
610 > sendto_match_butone(const struct Client *one, const struct Client *from,
611 >                    const char *mask, int what, const char *pattern, ...)
612   {
613    va_list alocal, aremote;
614 <  dlink_node *node = NULL;
614 >  dlink_node *node;
615    struct dbuf_block *local_buf, *remote_buf;
616  
617    local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
# Line 626 | Line 631 | sendto_match_butone(struct Client *one,
631    {
632      struct Client *client_p = node->data;
633  
634 <    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
635 <        match_it(client_p, mask, what))
636 <      send_message(client_p, local_buf);
634 >    if ((one == NULL || client_p != one->from) && !IsDefunct(client_p))
635 >      if (match_it(client_p, mask, what))
636 >        send_message(client_p, local_buf);
637    }
638  
639    /* Now scan servers */
# Line 660 | Line 665 | sendto_match_butone(struct Client *one,
665       * server deal with it.
666       * -wnder
667       */
668 <    if ((!one || client_p != one->from) && !IsDefunct(client_p))
668 >    if ((one == NULL || client_p != one->from) && !IsDefunct(client_p))
669        send_message_remote(client_p, from, remote_buf);
670    }
671  
# Line 678 | Line 683 | sendto_match_butone(struct Client *one,
683   * side effects - data sent to servers matching with capab
684   */
685   void
686 < sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
686 > sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
687                     const char *pattern, ...)
688   {
689    va_list args;
690 <  dlink_node *node = NULL;
690 >  dlink_node *node;
691    struct dbuf_block *buffer = dbuf_alloc();
692  
693    dbuf_put_fmt(buffer, ":%s ", source_p->id);
# Line 706 | Line 711 | sendto_match_servs(struct Client *source
711      if (match(mask, target_p->name))
712        continue;
713  
709    /*
710     * If we set the serial here, then we'll never do a
711     * match() again, if !IsCapable()
712     */
713    target_p->from->connection->serial = current_serial;
714
714      if (cap && IsCapable(target_p->from, cap) != cap)
715        continue;
716  
717 +    target_p->from->connection->serial = current_serial;
718      send_message_remote(target_p->from, source_p, buffer);
719    }
720  
# Line 731 | Line 731 | sendto_match_servs(struct Client *source
731   *                but useful when one does not know where target "lives"
732   */
733   void
734 < sendto_anywhere(struct Client *to, struct Client *from,
734 > sendto_anywhere(struct Client *to, const struct Client *from,
735                  const char *command,
736                  const char *pattern, ...)
737   {
738    va_list args;
739  struct dbuf_block *buffer = NULL;
739  
740    if (IsDead(to->from))
741      return;
742  
743 <  buffer = dbuf_alloc();
745 <
743 >  struct dbuf_block *buffer = dbuf_alloc();
744    if (MyClient(to) && IsClient(from))
745      dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
746                   from->host, command, to->name);
# Line 773 | Line 771 | sendto_anywhere(struct Client *to, struc
771   void
772   sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
773   {
774 <  const char *ntype = NULL;
775 <  dlink_node *node = NULL;
778 <  char nbuf[IRCD_BUFSIZE] = "";
774 >  const char *ntype = "???";
775 >  dlink_node *node;
776    va_list args;
777  
781  va_start(args, pattern);
782  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
783  va_end(args);
784
778    switch (type)
779    {
780      case SEND_NOTICE:
# Line 797 | Line 790 | sendto_realops_flags(unsigned int flags,
790        assert(0);
791    }
792  
793 +  struct dbuf_block *buffer = dbuf_alloc();
794 +  dbuf_put_fmt(buffer, ":%s NOTICE * :*** %s -- ", me.name, ntype);
795 +
796 +  va_start(args, pattern);
797 +  send_format(buffer, pattern, args);
798 +  va_end(args);
799 +
800    DLINK_FOREACH(node, oper_list.head)
801    {
802      struct Client *client_p = node->data;
# Line 810 | Line 810 | sendto_realops_flags(unsigned int flags,
810          ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
811        continue;
812  
813 <    if (HasUMode(client_p, flags))
814 <      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
815 <                 me.name, client_p->name, ntype, nbuf);
813 >    if (HasUMode(client_p, flags) && !IsDead(client_p))
814 >      send_message(client_p, buffer);
815    }
816 +
817 +  dbuf_ref_free(buffer);
818   }
819  
820   /* ts_warn()
# Line 824 | Line 825 | sendto_realops_flags(unsigned int flags,
825   *                (at most 5 warnings every 5 seconds)
826   */
827   void
828 < sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
828 > sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
829   {
830    va_list args;
831    char buffer[IRCD_BUFSIZE] = "";
# Line 851 | Line 852 | sendto_realops_flags_ratelimited(time_t
852   * side effects - Send a wallops to local opers
853   */
854   void
855 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
855 > sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
856                       const char *pattern, ...)
857   {
858 <  dlink_node *node = NULL;
858 >  dlink_node *node;
859    va_list args;
860    struct dbuf_block *buffer = dbuf_alloc();
861  
# Line 872 | Line 873 | sendto_wallops_flags(unsigned int flags,
873      struct Client *client_p = node->data;
874      assert(client_p->umodes & UMODE_OPER);
875  
876 <    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
876 >    if (HasUMode(client_p, flags) && !IsDead(client_p))
877        send_message(client_p, buffer);
878    }
879  

Comparing ircd-hybrid/trunk/src/send.c (property svn:keywords):
Revision 7222 by michael, Wed Feb 3 15:40:58 2016 UTC vs.
Revision 8599 by michael, Sun Oct 28 18:09:37 2018 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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