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 2565 by michael, Sun Nov 17 18:40:26 2013 UTC vs.
Revision 3110 by michael, Thu Mar 6 20:33:17 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  send.c: Functions for sending messages.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file send.c
23 > * \brief Functions for sending messages.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 52 | Line 54 | static unsigned int current_serial = 0;
54   * output       - number of bytes formatted output
55   * side effects - modifies sendbuf
56   */
57 < static inline int
58 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
57 > static void
58 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
59   {
58  int len;
59
60    /*
61     * from rfc1459
62     *
63     * IRC messages are always lines of characters terminated with a CR-LF
64     * (Carriage Return - Line Feed) pair, and these messages shall not
65 <   * exceed 512 characters in length,  counting all characters
65 >   * exceed 512 characters in length,  counting all characters
66     * including the trailing CR-LF.
67     * Thus, there are 510 characters maximum allowed
68     * for the command and its parameters.  There is no provision for
69     * continuation message lines.  See section 7 for more details about
70     * current implementations.
71     */
72 <  len = vsnprintf(lsendbuf, bufsize - 1, pattern, args);
73 <  if (len > bufsize - 2)
74 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
75 <
76 <  lsendbuf[len++] = '\r';
77 <  lsendbuf[len++] = '\n';
78 <  return len;
72 >  dbuf_put_args(buffer, pattern, args);
73 >
74 >  if (buffer->size > sizeof(buffer->data) - 2)
75 >    buffer->size = sizeof(buffer->data) - 2;
76 >
77 >  buffer->data[buffer->size++] = '\r';
78 >  buffer->data[buffer->size++] = '\n';
79   }
80  
81   /*
# Line 84 | Line 84 | send_format(char *lsendbuf, int bufsize,
84   **      sendq.
85   */
86   static void
87 < send_message(struct Client *to, char *buf, int len)
87 > send_message(struct Client *to, struct dbuf_block *buf)
88   {
89    assert(!IsMe(to));
90    assert(to != &me);
91  
92 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs))
92 >  if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs))
93    {
94      if (IsServer(to))
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),
98 >                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size),
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 <  dbuf_put(&to->localClient->buf_sendq, buf, len);
105 >
106 >  dbuf_add(&to->localClient->buf_sendq, buf);
107  
108    /*
109     ** Update statistics. The following is slightly incorrect
# Line 113 | Line 113 | send_message(struct Client *to, char *bu
113    ++to->localClient->send.messages;
114    ++me.localClient->send.messages;
115  
116 <  if (dbuf_length(&to->localClient->buf_sendq) >
117 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
118 <    send_queued_write(to);
116 >  send_queued_write(to);
117   }
118  
119   /* send_message_remote()
# Line 127 | Line 125 | send_message(struct Client *to, char *bu
125   * output       - none
126   * side effects - Despite the function name, this only sends to directly
127   *                connected clients.
128 < *
128 > *
129   */
130   static void
131 < send_message_remote(struct Client *to, struct Client *from,
134 <                    char *buf, int len)
131 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
132   {
133 +  if (to->from)
134 +    to = to->from;
135 +
136    if (!MyConnect(to))
137    {
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);
139 >                         "Server send message to %s [%s] dropped from %s(Not local server)",
140 >                         to->name, to->from->name, from->name);
141      return;
142    }
143  
# Line 172 | Line 172 | send_message_remote(struct Client *to, s
172      AddFlag(to, FLAGS_KILLED);
173  
174      if (IsClient(from))
175 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
176 <                 me.name, from->name, to->name, to->username,
177 <                 to->host, to->from);
175 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
176 >                         to->username, to->host, to->from);
177  
178      exit_client(to, &me, "Ghosted client");
180
179      return;
180 <  }
180 >  }
181  
182 <  send_message(to, buf, len);
182 >  send_message(to, buf);
183   }
184  
185   /*
# Line 191 | Line 189 | send_message_remote(struct Client *to, s
189   void
190   sendq_unblocked(fde_t *fd, struct Client *client_p)
191   {
192 <  ClearSendqBlocked(client_p);
193 <  /* let send_queued_write be executed by send_queued_all */
196 <
197 < #ifdef HAVE_LIBCRYPTO
198 <  if (fd->flags.pending_read)
199 <  {
200 <    fd->flags.pending_read = 0;
201 <    read_packet(fd, client_p);
202 <  }
203 < #endif
192 >  assert(fd == &client_p->localClient->fd);
193 >  send_queued_write(client_p);
194   }
195  
196   /*
# Line 212 | Line 202 | sendq_unblocked(fde_t *fd, struct Client
202   void
203   send_queued_write(struct Client *to)
204   {
205 <  int retlen;
206 <  struct dbuf_block *first;
205 >  int retlen = 0;
206 >  struct dbuf_queue *sendq = &to->localClient->buf_sendq;
207  
208    /*
209     ** Once socket is marked dead, we cannot start writing to it,
210     ** even if the error is removed...
211     */
212 <  if (IsDead(to) || IsSendqBlocked(to))
212 >  if (IsDead(to))
213      return;  /* no use calling send() now */
214  
215    /* Next, lets try to write some data */
216 <
227 <  if (dbuf_length(&to->localClient->buf_sendq))
216 >  if (dbuf_length(sendq))
217    {
218 <    do {
219 <      first = to->localClient->buf_sendq.blocks.head->data;
218 >    do
219 >    {
220 >      struct dbuf_block *first = sendq->blocks.head->data;
221  
222   #ifdef HAVE_LIBCRYPTO
223        if (to->localClient->fd.ssl)
224        {
225 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
225 >        retlen = SSL_write(to->localClient->fd.ssl, first->data + sendq->pos, first->size - sendq->pos);
226  
227          /* translate openssl error codes, sigh */
228 <        if (retlen < 0)
229 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
230 <          {
228 >        if (retlen < 0)
229 >        {
230 >          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
231 >          {
232              case SSL_ERROR_WANT_READ:
233 <              return;  /* retry later, don't register for write events */
234 <
235 <            case SSL_ERROR_WANT_WRITE:
245 <              errno = EWOULDBLOCK;
233 >              return;  /* retry later, don't register for write events */
234 >            case SSL_ERROR_WANT_WRITE:
235 >              errno = EWOULDBLOCK;
236              case SSL_ERROR_SYSCALL:
237 <              break;
237 >              break;
238              case SSL_ERROR_SSL:
239                if (errno == EAGAIN)
240                  break;
241              default:
242 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
243 <          }
242 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
243 >          }
244 >        }
245        }
246        else
247   #endif
248 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
248 >        retlen = send(to->localClient->fd.fd, first->data + sendq->pos, first->size - sendq->pos, 0);
249  
250        if (retlen <= 0)
251          break;
# Line 269 | Line 260 | send_queued_write(struct Client *to)
260      if ((retlen < 0) && (ignoreErrno(errno)))
261      {
262        /* we have a non-fatal error, reschedule a write */
263 <      SetSendqBlocked(to);
273 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
274 <                     (PF *)sendq_unblocked, (void *)to, 0);
263 >      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, (PF *)sendq_unblocked, to, 0);
264      }
265      else if (retlen <= 0)
266      {
# Line 296 | Line 285 | send_queued_all(void)
285     * a notice to opers, which is to be delivered by this function.
286     */
287    DLINK_FOREACH(ptr, serv_list.head)
288 <    send_queued_write((struct Client *) ptr->data);
288 >    send_queued_write(ptr->data);
289  
290    DLINK_FOREACH(ptr, unknown_list.head)
291 <    send_queued_write((struct Client *) ptr->data);
291 >    send_queued_write(ptr->data);
292  
293    DLINK_FOREACH(ptr, local_client_list.head)
294 <    send_queued_write((struct Client *) ptr->data);
294 >    send_queued_write(ptr->data);
295  
296    /* NOTE: This can still put clients on aborted_list; unfortunately,
297     * exit_aborted_clients takes precedence over send_queued_all,
# Line 323 | Line 312 | void
312   sendto_one(struct Client *to, const char *pattern, ...)
313   {
314    va_list args;
315 <  char buffer[IRCD_BUFSIZE];
316 <  int len;
315 >  struct dbuf_block *buffer;
316 >
317 >  if (to->from != NULL)
318 >    to = to->from;
319 >  if (IsDead(to))
320 >    return;  /* This socket has already been marked as dead */
321 >
322 >  buffer = dbuf_alloc();
323 >
324 >  va_start(args, pattern);
325 >  send_format(buffer, pattern, args);
326 >  va_end(args);
327 >
328 >  send_message(to, buffer);
329 >
330 >  dbuf_ref_free(buffer);
331 > }
332 >
333 > void
334 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
335 > {
336 >  struct dbuf_block *buffer;
337 >  va_list args;
338 >  const char *dest;
339 >
340 >  if (to->from != NULL)
341 >    to = to->from;
342 >  if (IsDead(to))
343 >    return;
344 >
345 >  dest = ID_or_name(to, to);
346 >  if (EmptyString(dest))
347 >    dest = "*";
348 >
349 >  buffer = dbuf_alloc();
350 >
351 >  dbuf_put(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
352 >
353 >  va_start(args, numeric);
354 >  send_format(buffer, numeric_form(numeric), args);
355 >  va_end(args);
356 >
357 >  send_message(to, buffer);
358 >
359 >  dbuf_ref_free(buffer);
360 > }
361 >
362 > void
363 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
364 > {
365 >  struct dbuf_block *buffer;
366 >  va_list args;
367 >  const char *dest;
368  
369    if (to->from != NULL)
370      to = to->from;
371    if (IsDead(to))
372 <    return; /* This socket has already been marked as dead */
372 >    return;
373 >
374 >  dest = ID_or_name(to, to);
375 >  if (EmptyString(dest))
376 >    dest = "*";
377 >
378 >  buffer = dbuf_alloc();
379 >
380 >  dbuf_put(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
381  
382    va_start(args, pattern);
383 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
383 >  send_format(buffer, pattern, args);
384    va_end(args);
385  
386 <  send_message(to, buffer, len);
386 >  send_message(to, buffer);
387 >
388 >  dbuf_ref_free(buffer);
389   }
390  
391   /* sendto_channel_butone()
# Line 355 | Line 405 | sendto_channel_butone(struct Client *one
405                        const char *pattern, ...)
406   {
407    va_list alocal, aremote, auid;
408 <  char local_buf[IRCD_BUFSIZE];
359 <  char remote_buf[IRCD_BUFSIZE];
360 <  char uid_buf[IRCD_BUFSIZE];
361 <  int local_len, remote_len, uid_len;
408 >  struct dbuf_block *local_buf, *remote_buf, *uid_buf;
409    dlink_node *ptr = NULL, *ptr_next = NULL;
410  
411 +  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(), uid_buf = dbuf_alloc();
412 +
413    if (IsServer(from))
414 <    local_len = snprintf(local_buf, sizeof(local_buf), ":%s ",
366 <                        from->name);
414 >    dbuf_put(local_buf, ":%s ", from->name);
415    else
416 <    local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
417 <                         from->name, from->username, from->host);
418 <  remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
419 <                        from->name);
372 <  uid_len = snprintf(uid_buf, sizeof(uid_buf), ":%s ", ID(from));
416 >    dbuf_put(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
417 >
418 >  dbuf_put(remote_buf, ":%s ", from->name);
419 >  dbuf_put(uid_buf, ":%s ", ID(from));
420  
421    va_start(alocal, pattern);
422    va_start(aremote, pattern);
423    va_start(auid, pattern);
424 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
425 <                           pattern, alocal);
426 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
380 <                            pattern, aremote);
381 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
382 <                         auid);
424 >  send_format(local_buf, pattern, alocal);
425 >  send_format(remote_buf, pattern, aremote);
426 >  send_format(uid_buf, pattern, auid);
427    va_end(auid);
428    va_end(aremote);
429    va_end(alocal);
# Line 400 | Line 444 | sendto_channel_butone(struct Client *one
444        continue;
445  
446      if (MyConnect(target_p))
447 <    {
448 <      if (target_p->localClient->serial != current_serial)
449 <      {
450 <        send_message(target_p, local_buf, local_len);
407 <        target_p->localClient->serial = current_serial;
408 <      }
409 <    }
410 <    else
411 <    {
412 <      /* Now check whether a message has been sent to this
413 <       * remote link already
414 <       */
415 <      if (target_p->from->localClient->serial != current_serial)
416 <      {
417 <        if (IsCapable(target_p->from, CAP_TS6))
418 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
419 <        else
420 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
421 <        target_p->from->localClient->serial = current_serial;
422 <      }
423 <    }
447 >      send_message(target_p, local_buf);
448 >    else if (target_p->from->localClient->serial != current_serial)
449 >      send_message_remote(target_p->from, from, remote_buf);
450 >    target_p->from->localClient->serial = current_serial;
451    }
452 +
453 +  dbuf_ref_free(local_buf);
454 +  dbuf_ref_free(remote_buf);
455 +  dbuf_ref_free(uid_buf);
456   }
457  
458   /* sendto_server()
459 < *
459 > *
460   * inputs       - pointer to client to NOT send to
461   *              - pointer to channel
462   *              - caps or'd together which must ALL be present
# Line 436 | Line 467 | sendto_channel_butone(struct Client *one
467   * side effects - Send a message to all connected servers, except the
468   *                client 'one' (if non-NULL), as long as the servers
469   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
470 < *            
470 > *
471   * This function was written in an attempt to merge together the other
472   * billion sendto_*serv*() functions, which sprung up with capabs,
473   * lazylinks, uids, etc.
474   * -davidt
475   */
476 < void
476 > void
477   sendto_server(struct Client *one,
478                const unsigned int caps,
479                const unsigned int nocaps,
# Line 450 | Line 481 | sendto_server(struct Client *one,
481   {
482    va_list args;
483    dlink_node *ptr = NULL;
484 <  char buffer[IRCD_BUFSIZE];
485 <  int len = 0;
484 >  struct dbuf_block *buffer;
485 >
486 >  buffer = dbuf_alloc();
487  
488    va_start(args, format);
489 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
489 >  send_format(buffer, format, args);
490    va_end(args);
491  
492    DLINK_FOREACH(ptr, serv_list.head)
# Line 474 | Line 506 | sendto_server(struct Client *one,
506      if ((client_p->localClient->caps & nocaps) != 0)
507        continue;
508  
509 <    send_message(client_p, buffer, len);
509 >    send_message(client_p, buffer);
510    }
511 +
512 +  dbuf_ref_free(buffer);
513   }
514  
515   /* sendto_common_channels_local()
# Line 484 | Line 518 | sendto_server(struct Client *one,
518   *              - pattern to send
519   * output       - NONE
520   * side effects - Sends a message to all people on local server who are
521 < *                in same channel with user.
521 > *                in same channel with user.
522   *                used by m_nick.c and exit_one_client.
523   */
524   void
# Line 497 | Line 531 | sendto_common_channels_local(struct Clie
531    struct Channel *chptr;
532    struct Membership *ms;
533    struct Client *target_p;
534 <  char buffer[IRCD_BUFSIZE];
535 <  int len;
534 >  struct dbuf_block *buffer;
535 >
536 >  buffer = dbuf_alloc();
537  
538    va_start(args, pattern);
539 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
539 >  send_format(buffer, pattern, args);
540    va_end(args);
541  
542    ++current_serial;
543  
544    DLINK_FOREACH(cptr, user->channel.head)
545    {
546 <    chptr = ((struct Membership *) cptr->data)->chptr;
546 >    chptr = ((struct Membership *)cptr->data)->chptr;
547      assert(chptr != NULL);
548  
549      DLINK_FOREACH(uptr, chptr->members.head)
# Line 525 | Line 560 | sendto_common_channels_local(struct Clie
560          continue;
561  
562        target_p->localClient->serial = current_serial;
563 <      send_message(target_p, buffer, len);
563 >      send_message(target_p, buffer);
564      }
565    }
566  
567    if (touser && MyConnect(user) && !IsDead(user) &&
568        user->localClient->serial != current_serial)
569      if (HasCap(user, cap) == cap)
570 <      send_message(user, buffer, len);
570 >      send_message(user, buffer);
571 >
572 >  dbuf_ref_free(buffer);
573   }
574  
575   /* sendto_channel_local()
# Line 550 | Line 587 | sendto_channel_local(unsigned int type,
587                       const char *pattern, ...)
588   {
589    va_list args;
590 <  char buffer[IRCD_BUFSIZE];
591 <  int len;
592 <  dlink_node *ptr;
593 <  struct Membership *ms;
557 <  struct Client *target_p;
590 >  dlink_node *ptr = NULL;
591 >  struct dbuf_block *buffer;
592 >
593 >  buffer = dbuf_alloc();
594  
595    va_start(args, pattern);
596 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
596 >  send_format(buffer, pattern, args);
597    va_end(args);
598  
599    DLINK_FOREACH(ptr, chptr->members.head)
600    {
601 <    ms = ptr->data;
602 <    target_p = ms->client_p;
601 >    struct Membership *ms = ptr->data;
602 >    struct Client *target_p = ms->client_p;
603  
604      if (type != 0 && (ms->flags & type) == 0)
605        continue;
# Line 572 | Line 608 | sendto_channel_local(unsigned int type,
608          (nodeaf && HasUMode(target_p, UMODE_DEAF)))
609        continue;
610  
611 <    send_message(target_p, buffer, len);
611 >    send_message(target_p, buffer);
612    }
613 +
614 +  dbuf_ref_free(buffer);
615   }
616  
617   /* sendto_channel_local_butone()
# Line 588 | Line 626 | sendto_channel_local(unsigned int type,
626   *
627   * WARNING - +D clients are omitted
628   */
629 < void      
629 > void
630   sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
631 <                            struct Channel *chptr, const char *pattern, ...)
631 >                            struct Channel *chptr, const char *pattern, ...)
632   {
633    va_list args;
634 <  char buffer[IRCD_BUFSIZE];
635 <  int len;
598 <  struct Client *target_p;
599 <  struct Membership *ms;
600 <  dlink_node *ptr;
634 >  dlink_node *ptr = NULL;
635 >  struct dbuf_block *buffer;
636  
637 <  va_start(args, pattern);
638 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
637 >  buffer = dbuf_alloc();
638 >
639 >  va_start(args, pattern);
640 >  send_format(buffer, pattern, args);
641    va_end(args);
642  
643 <  DLINK_FOREACH(ptr, chptr->members.head)      
644 <  {  
645 <    ms = ptr->data;
646 <    target_p = ms->client_p;
643 >  DLINK_FOREACH(ptr, chptr->members.head)
644 >  {
645 >    struct Membership *ms = ptr->data;
646 >    struct Client *target_p = ms->client_p;
647  
648      if (type != 0 && (ms->flags & type) == 0)
649        continue;
# Line 616 | Line 653 | sendto_channel_local_butone(struct Clien
653        continue;
654  
655      if (HasCap(target_p, cap) != cap)
619        continue;
620    send_message(target_p, buffer, len);
621  }
622 }
623
624
625 /* sendto_channel_remote()
626 *
627 * inputs       - Client not to send towards
628 *              - Client from whom message is from
629 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
630 *              - pointer to channel to send to
631 *              - var args pattern
632 * output       - NONE
633 * side effects - Send a message to all members of a channel that are
634 *                remote to this server.
635 */
636 void
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 {
641  va_list args;
642  char buffer[IRCD_BUFSIZE];
643  int len;
644  dlink_node *ptr;
645  struct Client *target_p;
646  struct Membership *ms;
647
648  va_start(args, pattern);
649  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
650  va_end(args);
651
652  ++current_serial;
653
654  DLINK_FOREACH(ptr, chptr->members.head)
655  {
656    ms = ptr->data;
657    target_p = ms->client_p;
658
659    if (type != 0 && (ms->flags & type) == 0)
656        continue;
657  
658 <    if (MyConnect(target_p))
659 <      continue;
664 <    target_p = target_p->from;
658 >    send_message(target_p, buffer);
659 >  }
660  
661 <    if (target_p == one->from ||
667 <        ((target_p->from->localClient->caps & caps) != caps) ||
668 <        ((target_p->from->localClient->caps & nocaps) != 0))
669 <      continue;
670 <    if (target_p->from->localClient->serial != current_serial)
671 <    {
672 <      send_message(target_p, buffer, len);
673 <      target_p->from->localClient->serial = current_serial;
674 <    }
675 <  }
661 >  dbuf_ref_free(buffer);
662   }
663  
664   /*
# Line 693 | Line 679 | sendto_channel_remote(struct Client *one
679   * side effects - NONE
680   */
681   static int
682 < match_it(const struct Client *one, const char *mask, int what)
682 > match_it(const struct Client *one, const char *mask, unsigned int what)
683   {
684    if (what == MATCH_HOST)
685      return !match(mask, one->host);
# Line 713 | Line 699 | sendto_match_butone(struct Client *one,
699                      int what, const char *pattern, ...)
700   {
701    va_list alocal, aremote;
702 <  struct Client *client_p;
703 <  dlink_node *ptr, *ptr_next;
704 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
705 <  int local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
706 <                           from->name, from->username, from->host);
707 <  int remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
708 <                            from->name);
702 >  dlink_node *ptr = NULL, *ptr_next = NULL;
703 >  struct dbuf_block *local_buf, *remote_buf;
704 >
705 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
706 >
707 >  dbuf_put(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
708 >  dbuf_put(remote_buf, ":%s ", from->name);
709  
710    va_start(alocal, pattern);
711    va_start(aremote, pattern);
712 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
713 <                           pattern, alocal);
728 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
729 <                            pattern, aremote);
712 >  send_format(local_buf, pattern, alocal);
713 >  send_format(remote_buf, pattern, aremote);
714    va_end(aremote);
715    va_end(alocal);
716  
717    /* scan the local clients */
718    DLINK_FOREACH(ptr, local_client_list.head)
719    {
720 <    client_p = ptr->data;
720 >    struct Client *client_p = ptr->data;
721  
722      if (client_p != one && !IsDefunct(client_p) &&
723          match_it(client_p, mask, what))
724 <      send_message(client_p, local_buf, local_len);
724 >      send_message(client_p, local_buf);
725    }
726  
727    /* Now scan servers */
728    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
729    {
730 <    client_p = ptr->data;
730 >    struct Client *client_p = ptr->data;
731  
732      /*
733       * The old code looped through every client on the
# Line 770 | Line 754 | sendto_match_butone(struct Client *one,
754       * -wnder
755       */
756      if (client_p != one && !IsDefunct(client_p))
757 <      send_message_remote(client_p, from, remote_buf, remote_len);
757 >      send_message_remote(client_p, from, remote_buf);
758    }
759 +
760 +  dbuf_ref_free(local_buf);
761 +  dbuf_ref_free(remote_buf);
762   }
763  
764   /* sendto_match_servs()
# Line 788 | Line 775 | sendto_match_servs(struct Client *source
775                     const char *pattern, ...)
776   {
777    va_list args;
778 <  struct Client *target_p;
779 <  dlink_node *ptr;
780 <  char buffer[IRCD_BUFSIZE];
781 <  int found = 0;
778 >  dlink_node *ptr = NULL;
779 >  struct dbuf_block *buff_suid, *buff_name;
780 >
781 >  buff_suid = dbuf_alloc(), buff_name = dbuf_alloc();
782  
783    va_start(args, pattern);
784 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
784 >  dbuf_put(buff_suid, ":%s ", ID(source_p));
785 >  dbuf_put_args(buff_suid, pattern, args);
786 >  va_end(args);
787 >
788 >  va_start(args, pattern);
789 >  dbuf_put(buff_name, ":%s ", source_p->name);
790 >  dbuf_put_args(buff_name, pattern, args);
791    va_end(args);
792  
793    ++current_serial;
794  
795    DLINK_FOREACH(ptr, global_serv_list.head)
796    {
797 <    target_p = ptr->data;
797 >    struct Client *target_p = ptr->data;
798  
799      /* Do not attempt to send to ourselves, or the source */
800      if (IsMe(target_p) || target_p->from == source_p->from)
# Line 817 | Line 810 | sendto_match_servs(struct Client *source
810         * match() again, if !IsCapable()
811         */
812        target_p->from->localClient->serial = current_serial;
820      found++;
813  
814        if (!IsCapable(target_p->from, cap))
815          continue;
816  
817 <      sendto_anywhere(target_p, source_p, "%s", buffer);
817 >      if (HasID(target_p->from))
818 >        send_message_remote(target_p->from, source_p, buff_suid);
819 >      else
820 >        send_message_remote(target_p->from, source_p, buff_name);
821      }
822    }
823 +
824 +  dbuf_ref_free(buff_suid);
825 +  dbuf_ref_free(buff_name);
826   }
827  
828   /* sendto_anywhere()
# Line 838 | Line 836 | sendto_match_servs(struct Client *source
836   */
837   void
838   sendto_anywhere(struct Client *to, struct Client *from,
839 +                const char *command,
840                  const char *pattern, ...)
841   {
842    va_list args;
843 <  char buffer[IRCD_BUFSIZE];
845 <  int len;
846 <  struct Client *send_to = (to->from != NULL ? to->from : to);
843 >  struct dbuf_block *buffer;
844  
845 <  if (IsDead(send_to))
845 >  if (IsDead(to->from))
846      return;
847  
848 +  buffer = dbuf_alloc();
849 +
850    if (MyClient(to))
851    {
852      if (IsServer(from))
853 <    {
855 <      if (IsCapable(to, CAP_TS6) && HasID(from))
856 <        len = snprintf(buffer, sizeof(buffer), ":%s ", from->id);
857 <      else
858 <        len = snprintf(buffer, sizeof(buffer), ":%s ", from->name);
859 <    }
853 >      dbuf_put(buffer, ":%s %s %s ", from->name, command, to->name);
854      else
855 <      len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s ",
862 <                     from->name, from->username, from->host);
855 >      dbuf_put(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name);
856    }
857 <  else len = snprintf(buffer, sizeof(buffer), ":%s ", ID_or_name(from, send_to));
857 >  else
858 >    dbuf_put(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to));
859  
860    va_start(args, pattern);
861 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
861 >  send_format(buffer, pattern, args);
862    va_end(args);
863  
864    if (MyClient(to))
865 <    send_message(send_to, buffer, len);
865 >    send_message(to, buffer);
866    else
867 <    send_message_remote(send_to, from, buffer, len);
867 >    send_message_remote(to, from, buffer);
868 >
869 >  dbuf_ref_free(buffer);
870   }
871  
872   /* sendto_realops_flags()
# Line 918 | Line 914 | sendto_realops_flags(unsigned int flags,
914       * If we're sending it to admins, and they're not, skip.
915       */
916      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
917 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
917 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
918        continue;
919  
920      if (HasUMode(client_p, flags))
# Line 941 | Line 937 | sendto_wallops_flags(unsigned int flags,
937   {
938    dlink_node *ptr = NULL;
939    va_list args;
940 <  char buffer[IRCD_BUFSIZE];
941 <  int len;
940 >  struct dbuf_block *buffer;
941 >
942 >  buffer = dbuf_alloc();
943  
944    if (IsClient(source_p))
945 <    len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s WALLOPS :",
949 <                   source_p->name, source_p->username,
950 <                   source_p->host);
945 >    dbuf_put(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
946    else
947 <    len = snprintf(buffer, sizeof(buffer), ":%s WALLOPS :",
953 <                   source_p->name);
947 >    dbuf_put(buffer, ":%s WALLOPS :", source_p->name);
948  
949    va_start(args, pattern);
950 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
950 >  send_format(buffer, pattern, args);
951    va_end(args);
952  
953    DLINK_FOREACH(ptr, oper_list.head)
# Line 962 | Line 956 | sendto_wallops_flags(unsigned int flags,
956      assert(client_p->umodes & UMODE_OPER);
957  
958      if (HasUMode(client_p, flags) && !IsDefunct(client_p))
959 <      send_message(client_p, buffer, len);
959 >      send_message(client_p, buffer);
960    }
961 +
962 +  dbuf_ref_free(buffer);
963   }
964  
965   /* ts_warn()
# Line 974 | Line 970 | sendto_wallops_flags(unsigned int flags,
970   *                (at most 5 warnings every 5 seconds)
971   */
972   void
973 < ts_warn(const char *pattern, ...)
973 > sendto_realops_flags_ratelimited(const char *pattern, ...)
974   {
975    va_list args;
976    char buffer[IRCD_BUFSIZE];
# Line 1020 | Line 1016 | kill_client(struct Client *client_p, str
1016              const char *pattern, ...)
1017   {
1018    va_list args;
1019 <  char buffer[IRCD_BUFSIZE];
1024 <  int len;
1019 >  struct dbuf_block *buffer;
1020  
1021    if (client_p->from != NULL)
1022      client_p = client_p->from;
1023    if (IsDead(client_p))
1024      return;
1025  
1026 <  len = snprintf(buffer, sizeof(buffer), ":%s KILL %s :",
1027 <                 ID_or_name(&me, client_p->from),
1028 <                 ID_or_name(diedie, client_p));
1026 >  buffer = dbuf_alloc();
1027 >
1028 >  dbuf_put(buffer, ":%s KILL %s :",
1029 >           ID_or_name(&me, client_p),
1030 >           ID_or_name(diedie, client_p));
1031  
1032    va_start(args, pattern);
1033 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1033 >  send_format(buffer, pattern, args);
1034    va_end(args);
1035  
1036 <  send_message(client_p, buffer, len);
1036 >  send_message(client_p, buffer);
1037 >
1038 >  dbuf_ref_free(buffer);
1039   }
1040  
1041   /* kill_client_ll_serv_butone()
# Line 1056 | Line 1055 | kill_client_serv_butone(struct Client *o
1055    va_list args;
1056    int have_uid = 0;
1057    dlink_node *ptr = NULL;
1058 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1059 <  int len_uid = 0, len_nick = 0;
1058 >  struct dbuf_block *uid_buffer, *nick_buffer;
1059 >
1060 >  uid_buffer = dbuf_alloc(), nick_buffer = dbuf_alloc();
1061  
1062    if (HasID(source_p))
1063    {
1064      have_uid = 1;
1065      va_start(args, pattern);
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);
1066 >    dbuf_put(uid_buffer, ":%s KILL %s :", me.id, ID(source_p));
1067 >    send_format(uid_buffer, pattern, args);
1068      va_end(args);
1069    }
1070  
1071    va_start(args, pattern);
1072 <  len_nick = snprintf(buf_nick, sizeof(buf_nick), ":%s KILL %s :",
1073 <                      me.name, source_p->name);
1076 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1077 <                          args);
1072 >  dbuf_put(nick_buffer, ":%s KILL %s :", me.name, source_p->name);
1073 >  send_format(nick_buffer, pattern, args);
1074    va_end(args);
1075  
1076    DLINK_FOREACH(ptr, serv_list.head)
# Line 1087 | Line 1083 | kill_client_serv_butone(struct Client *o
1083        continue;
1084  
1085      if (have_uid && IsCapable(client_p, CAP_TS6))
1086 <      send_message(client_p, buf_uid, len_uid);
1086 >      send_message(client_p, uid_buffer);
1087      else
1088 <      send_message(client_p, buf_nick, len_nick);
1088 >      send_message(client_p, nick_buffer);
1089    }
1090 < }
1090 >
1091 >  dbuf_ref_free(uid_buffer);
1092 >  dbuf_ref_free(nick_buffer);
1093 > }

Diff Legend

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