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 3112 by michael, Thu Mar 6 22:06:02 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 +  to = to->from;
134 +
135    if (!MyConnect(to))
136    {
137      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
138 <                         "server send message to %s [%s] dropped from %s(Not local server)",
139 <                         to->name, to->from->name, from->name);
138 >                         "Server send message to %s [%s] dropped from %s(Not local server)",
139 >                         to->name, to->from->name, from->name);
140      return;
141    }
142  
# Line 172 | Line 171 | send_message_remote(struct Client *to, s
171      AddFlag(to, FLAGS_KILLED);
172  
173      if (IsClient(from))
174 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
175 <                 me.name, from->name, to->name, to->username,
177 <                 to->host, to->from);
174 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
175 >                         to->username, to->host, to->from);
176  
177      exit_client(to, &me, "Ghosted client");
180
178      return;
179 <  }
179 >  }
180  
181 <  send_message(to, buf, len);
181 >  send_message(to, buf);
182   }
183  
184   /*
# Line 191 | Line 188 | send_message_remote(struct Client *to, s
188   void
189   sendq_unblocked(fde_t *fd, struct Client *client_p)
190   {
191 <  ClearSendqBlocked(client_p);
192 <  /* 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
191 >  assert(fd == &client_p->localClient->fd);
192 >  send_queued_write(client_p);
193   }
194  
195   /*
# Line 212 | Line 201 | sendq_unblocked(fde_t *fd, struct Client
201   void
202   send_queued_write(struct Client *to)
203   {
204 <  int retlen;
205 <  struct dbuf_block *first;
204 >  int retlen = 0;
205 >  struct dbuf_queue *sendq = &to->localClient->buf_sendq;
206  
207    /*
208     ** Once socket is marked dead, we cannot start writing to it,
209     ** even if the error is removed...
210     */
211 <  if (IsDead(to) || IsSendqBlocked(to))
211 >  if (IsDead(to))
212      return;  /* no use calling send() now */
213  
214    /* Next, lets try to write some data */
215 <
227 <  if (dbuf_length(&to->localClient->buf_sendq))
215 >  if (dbuf_length(sendq))
216    {
217 <    do {
218 <      first = to->localClient->buf_sendq.blocks.head->data;
217 >    do
218 >    {
219 >      struct dbuf_block *first = sendq->blocks.head->data;
220  
221   #ifdef HAVE_LIBCRYPTO
222        if (to->localClient->fd.ssl)
223        {
224 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
224 >        retlen = SSL_write(to->localClient->fd.ssl, first->data + sendq->pos, first->size - sendq->pos);
225  
226          /* translate openssl error codes, sigh */
227 <        if (retlen < 0)
228 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
229 <          {
227 >        if (retlen < 0)
228 >        {
229 >          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
230 >          {
231              case SSL_ERROR_WANT_READ:
232 <              return;  /* retry later, don't register for write events */
233 <
234 <            case SSL_ERROR_WANT_WRITE:
245 <              errno = EWOULDBLOCK;
232 >              return;  /* retry later, don't register for write events */
233 >            case SSL_ERROR_WANT_WRITE:
234 >              errno = EWOULDBLOCK;
235              case SSL_ERROR_SYSCALL:
236 <              break;
236 >              break;
237              case SSL_ERROR_SSL:
238                if (errno == EAGAIN)
239                  break;
240              default:
241 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
242 <          }
241 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
242 >          }
243 >        }
244        }
245        else
246   #endif
247 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
247 >        retlen = send(to->localClient->fd.fd, first->data + sendq->pos, first->size - sendq->pos, 0);
248  
249        if (retlen <= 0)
250          break;
# Line 269 | Line 259 | send_queued_write(struct Client *to)
259      if ((retlen < 0) && (ignoreErrno(errno)))
260      {
261        /* we have a non-fatal error, reschedule a write */
262 <      SetSendqBlocked(to);
273 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
274 <                     (PF *)sendq_unblocked, (void *)to, 0);
262 >      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, (PF *)sendq_unblocked, to, 0);
263      }
264      else if (retlen <= 0)
265      {
# Line 296 | Line 284 | send_queued_all(void)
284     * a notice to opers, which is to be delivered by this function.
285     */
286    DLINK_FOREACH(ptr, serv_list.head)
287 <    send_queued_write((struct Client *) ptr->data);
287 >    send_queued_write(ptr->data);
288  
289    DLINK_FOREACH(ptr, unknown_list.head)
290 <    send_queued_write((struct Client *) ptr->data);
290 >    send_queued_write(ptr->data);
291  
292    DLINK_FOREACH(ptr, local_client_list.head)
293 <    send_queued_write((struct Client *) ptr->data);
293 >    send_queued_write(ptr->data);
294  
295    /* NOTE: This can still put clients on aborted_list; unfortunately,
296     * exit_aborted_clients takes precedence over send_queued_all,
# Line 323 | Line 311 | void
311   sendto_one(struct Client *to, const char *pattern, ...)
312   {
313    va_list args;
314 <  char buffer[IRCD_BUFSIZE];
315 <  int len;
314 >  struct dbuf_block *buffer;
315 >
316 >  to = to->from;
317  
329  if (to->from != NULL)
330    to = to->from;
318    if (IsDead(to))
319 <    return; /* This socket has already been marked as dead */
319 >    return;  /* This socket has already been marked as dead */
320 >
321 >  buffer = dbuf_alloc();
322  
323    va_start(args, pattern);
324 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
324 >  send_format(buffer, pattern, args);
325    va_end(args);
326  
327 <  send_message(to, buffer, len);
327 >  send_message(to, buffer);
328 >
329 >  dbuf_ref_free(buffer);
330 > }
331 >
332 > void
333 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
334 > {
335 >  struct dbuf_block *buffer;
336 >  va_list args;
337 >  const char *dest;
338 >
339 >  to = to->from;
340 >
341 >  if (IsDead(to))
342 >    return;
343 >
344 >  dest = ID_or_name(to, to);
345 >  if (EmptyString(dest))
346 >    dest = "*";
347 >
348 >  buffer = dbuf_alloc();
349 >
350 >  dbuf_put(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
351 >
352 >  va_start(args, numeric);
353 >  send_format(buffer, numeric_form(numeric), args);
354 >  va_end(args);
355 >
356 >  send_message(to, buffer);
357 >
358 >  dbuf_ref_free(buffer);
359 > }
360 >
361 > void
362 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
363 > {
364 >  struct dbuf_block *buffer;
365 >  va_list args;
366 >  const char *dest;
367 >
368 >  to = to->from;
369 >
370 >  if (IsDead(to))
371 >    return;
372 >
373 >  dest = ID_or_name(to, to);
374 >  if (EmptyString(dest))
375 >    dest = "*";
376 >
377 >  buffer = dbuf_alloc();
378 >
379 >  dbuf_put(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
380 >
381 >  va_start(args, pattern);
382 >  send_format(buffer, pattern, args);
383 >  va_end(args);
384 >
385 >  send_message(to, buffer);
386 >
387 >  dbuf_ref_free(buffer);
388   }
389  
390   /* sendto_channel_butone()
# Line 355 | Line 404 | sendto_channel_butone(struct Client *one
404                        const char *pattern, ...)
405   {
406    va_list alocal, aremote, auid;
407 <  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;
407 >  struct dbuf_block *local_buf, *remote_buf, *uid_buf;
408    dlink_node *ptr = NULL, *ptr_next = NULL;
409  
410 +  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(), uid_buf = dbuf_alloc();
411 +
412    if (IsServer(from))
413 <    local_len = snprintf(local_buf, sizeof(local_buf), ":%s ",
366 <                        from->name);
413 >    dbuf_put(local_buf, ":%s ", from->name);
414    else
415 <    local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
416 <                         from->name, from->username, from->host);
417 <  remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
418 <                        from->name);
372 <  uid_len = snprintf(uid_buf, sizeof(uid_buf), ":%s ", ID(from));
415 >    dbuf_put(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
416 >
417 >  dbuf_put(remote_buf, ":%s ", from->name);
418 >  dbuf_put(uid_buf, ":%s ", ID(from));
419  
420    va_start(alocal, pattern);
421    va_start(aremote, pattern);
422    va_start(auid, pattern);
423 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
424 <                           pattern, alocal);
425 <  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);
423 >  send_format(local_buf, pattern, alocal);
424 >  send_format(remote_buf, pattern, aremote);
425 >  send_format(uid_buf, pattern, auid);
426    va_end(auid);
427    va_end(aremote);
428    va_end(alocal);
# Line 400 | Line 443 | sendto_channel_butone(struct Client *one
443        continue;
444  
445      if (MyConnect(target_p))
446 <    {
447 <      if (target_p->localClient->serial != current_serial)
448 <      {
449 <        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 <    }
446 >      send_message(target_p, local_buf);
447 >    else if (target_p->from->localClient->serial != current_serial)
448 >      send_message_remote(target_p->from, from, remote_buf);
449 >    target_p->from->localClient->serial = current_serial;
450    }
451 +
452 +  dbuf_ref_free(local_buf);
453 +  dbuf_ref_free(remote_buf);
454 +  dbuf_ref_free(uid_buf);
455   }
456  
457   /* sendto_server()
458 < *
458 > *
459   * inputs       - pointer to client to NOT send to
460   *              - pointer to channel
461   *              - caps or'd together which must ALL be present
# Line 436 | Line 466 | sendto_channel_butone(struct Client *one
466   * side effects - Send a message to all connected servers, except the
467   *                client 'one' (if non-NULL), as long as the servers
468   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
469 < *            
469 > *
470   * This function was written in an attempt to merge together the other
471   * billion sendto_*serv*() functions, which sprung up with capabs,
472   * lazylinks, uids, etc.
473   * -davidt
474   */
475 < void
475 > void
476   sendto_server(struct Client *one,
477                const unsigned int caps,
478                const unsigned int nocaps,
# Line 450 | Line 480 | sendto_server(struct Client *one,
480   {
481    va_list args;
482    dlink_node *ptr = NULL;
483 <  char buffer[IRCD_BUFSIZE];
484 <  int len = 0;
483 >  struct dbuf_block *buffer;
484 >
485 >  buffer = dbuf_alloc();
486  
487    va_start(args, format);
488 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
488 >  send_format(buffer, format, args);
489    va_end(args);
490  
491    DLINK_FOREACH(ptr, serv_list.head)
# Line 474 | Line 505 | sendto_server(struct Client *one,
505      if ((client_p->localClient->caps & nocaps) != 0)
506        continue;
507  
508 <    send_message(client_p, buffer, len);
508 >    send_message(client_p, buffer);
509    }
510 +
511 +  dbuf_ref_free(buffer);
512   }
513  
514   /* sendto_common_channels_local()
# Line 484 | Line 517 | sendto_server(struct Client *one,
517   *              - pattern to send
518   * output       - NONE
519   * side effects - Sends a message to all people on local server who are
520 < *                in same channel with user.
520 > *                in same channel with user.
521   *                used by m_nick.c and exit_one_client.
522   */
523   void
# Line 497 | Line 530 | sendto_common_channels_local(struct Clie
530    struct Channel *chptr;
531    struct Membership *ms;
532    struct Client *target_p;
533 <  char buffer[IRCD_BUFSIZE];
534 <  int len;
533 >  struct dbuf_block *buffer;
534 >
535 >  buffer = dbuf_alloc();
536  
537    va_start(args, pattern);
538 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
538 >  send_format(buffer, pattern, args);
539    va_end(args);
540  
541    ++current_serial;
542  
543    DLINK_FOREACH(cptr, user->channel.head)
544    {
545 <    chptr = ((struct Membership *) cptr->data)->chptr;
545 >    chptr = ((struct Membership *)cptr->data)->chptr;
546      assert(chptr != NULL);
547  
548      DLINK_FOREACH(uptr, chptr->members.head)
# Line 525 | Line 559 | sendto_common_channels_local(struct Clie
559          continue;
560  
561        target_p->localClient->serial = current_serial;
562 <      send_message(target_p, buffer, len);
562 >      send_message(target_p, buffer);
563      }
564    }
565  
566    if (touser && MyConnect(user) && !IsDead(user) &&
567        user->localClient->serial != current_serial)
568      if (HasCap(user, cap) == cap)
569 <      send_message(user, buffer, len);
569 >      send_message(user, buffer);
570 >
571 >  dbuf_ref_free(buffer);
572   }
573  
574   /* sendto_channel_local()
# Line 550 | Line 586 | sendto_channel_local(unsigned int type,
586                       const char *pattern, ...)
587   {
588    va_list args;
589 <  char buffer[IRCD_BUFSIZE];
590 <  int len;
591 <  dlink_node *ptr;
592 <  struct Membership *ms;
557 <  struct Client *target_p;
589 >  dlink_node *ptr = NULL;
590 >  struct dbuf_block *buffer;
591 >
592 >  buffer = dbuf_alloc();
593  
594    va_start(args, pattern);
595 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
595 >  send_format(buffer, pattern, args);
596    va_end(args);
597  
598    DLINK_FOREACH(ptr, chptr->members.head)
599    {
600 <    ms = ptr->data;
601 <    target_p = ms->client_p;
600 >    struct Membership *ms = ptr->data;
601 >    struct Client *target_p = ms->client_p;
602  
603      if (type != 0 && (ms->flags & type) == 0)
604        continue;
# Line 572 | Line 607 | sendto_channel_local(unsigned int type,
607          (nodeaf && HasUMode(target_p, UMODE_DEAF)))
608        continue;
609  
610 <    send_message(target_p, buffer, len);
610 >    send_message(target_p, buffer);
611    }
612 +
613 +  dbuf_ref_free(buffer);
614   }
615  
616   /* sendto_channel_local_butone()
# Line 588 | Line 625 | sendto_channel_local(unsigned int type,
625   *
626   * WARNING - +D clients are omitted
627   */
628 < void      
628 > void
629   sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
630 <                            struct Channel *chptr, const char *pattern, ...)
630 >                            struct Channel *chptr, const char *pattern, ...)
631   {
632    va_list args;
633 <  char buffer[IRCD_BUFSIZE];
634 <  int len;
635 <  struct Client *target_p;
636 <  struct Membership *ms;
600 <  dlink_node *ptr;
633 >  dlink_node *ptr = NULL;
634 >  struct dbuf_block *buffer;
635 >
636 >  buffer = dbuf_alloc();
637  
638 <  va_start(args, pattern);
639 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
638 >  va_start(args, pattern);
639 >  send_format(buffer, pattern, args);
640    va_end(args);
641  
642 <  DLINK_FOREACH(ptr, chptr->members.head)      
643 <  {  
644 <    ms = ptr->data;
645 <    target_p = ms->client_p;
642 >  DLINK_FOREACH(ptr, chptr->members.head)
643 >  {
644 >    struct Membership *ms = ptr->data;
645 >    struct Client *target_p = ms->client_p;
646  
647      if (type != 0 && (ms->flags & type) == 0)
648        continue;
# Line 616 | Line 652 | sendto_channel_local_butone(struct Clien
652        continue;
653  
654      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)
655        continue;
656  
657 <    if (MyConnect(target_p))
658 <      continue;
664 <    target_p = target_p->from;
657 >    send_message(target_p, buffer);
658 >  }
659  
660 <    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 <  }
660 >  dbuf_ref_free(buffer);
661   }
662  
663   /*
# Line 693 | Line 678 | sendto_channel_remote(struct Client *one
678   * side effects - NONE
679   */
680   static int
681 < match_it(const struct Client *one, const char *mask, int what)
681 > match_it(const struct Client *one, const char *mask, unsigned int what)
682   {
683    if (what == MATCH_HOST)
684      return !match(mask, one->host);
# Line 713 | Line 698 | sendto_match_butone(struct Client *one,
698                      int what, const char *pattern, ...)
699   {
700    va_list alocal, aremote;
701 <  struct Client *client_p;
702 <  dlink_node *ptr, *ptr_next;
703 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
704 <  int local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
705 <                           from->name, from->username, from->host);
706 <  int remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
707 <                            from->name);
701 >  dlink_node *ptr = NULL, *ptr_next = NULL;
702 >  struct dbuf_block *local_buf, *remote_buf;
703 >
704 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
705 >
706 >  dbuf_put(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
707 >  dbuf_put(remote_buf, ":%s ", from->name);
708  
709    va_start(alocal, pattern);
710    va_start(aremote, pattern);
711 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
712 <                           pattern, alocal);
728 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
729 <                            pattern, aremote);
711 >  send_format(local_buf, pattern, alocal);
712 >  send_format(remote_buf, pattern, aremote);
713    va_end(aremote);
714    va_end(alocal);
715  
716    /* scan the local clients */
717    DLINK_FOREACH(ptr, local_client_list.head)
718    {
719 <    client_p = ptr->data;
719 >    struct Client *client_p = ptr->data;
720  
721      if (client_p != one && !IsDefunct(client_p) &&
722          match_it(client_p, mask, what))
723 <      send_message(client_p, local_buf, local_len);
723 >      send_message(client_p, local_buf);
724    }
725  
726    /* Now scan servers */
727    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
728    {
729 <    client_p = ptr->data;
729 >    struct Client *client_p = ptr->data;
730  
731      /*
732       * The old code looped through every client on the
# Line 770 | Line 753 | sendto_match_butone(struct Client *one,
753       * -wnder
754       */
755      if (client_p != one && !IsDefunct(client_p))
756 <      send_message_remote(client_p, from, remote_buf, remote_len);
756 >      send_message_remote(client_p, from, remote_buf);
757    }
758 +
759 +  dbuf_ref_free(local_buf);
760 +  dbuf_ref_free(remote_buf);
761   }
762  
763   /* sendto_match_servs()
# Line 788 | Line 774 | sendto_match_servs(struct Client *source
774                     const char *pattern, ...)
775   {
776    va_list args;
777 <  struct Client *target_p;
778 <  dlink_node *ptr;
779 <  char buffer[IRCD_BUFSIZE];
780 <  int found = 0;
777 >  dlink_node *ptr = NULL;
778 >  struct dbuf_block *buff_suid, *buff_name;
779 >
780 >  buff_suid = dbuf_alloc(), buff_name = dbuf_alloc();
781  
782    va_start(args, pattern);
783 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
783 >  dbuf_put(buff_suid, ":%s ", ID(source_p));
784 >  dbuf_put_args(buff_suid, pattern, args);
785 >  va_end(args);
786 >
787 >  va_start(args, pattern);
788 >  dbuf_put(buff_name, ":%s ", source_p->name);
789 >  dbuf_put_args(buff_name, pattern, args);
790    va_end(args);
791  
792    ++current_serial;
793  
794    DLINK_FOREACH(ptr, global_serv_list.head)
795    {
796 <    target_p = ptr->data;
796 >    struct Client *target_p = ptr->data;
797  
798      /* Do not attempt to send to ourselves, or the source */
799      if (IsMe(target_p) || target_p->from == source_p->from)
# Line 817 | Line 809 | sendto_match_servs(struct Client *source
809         * match() again, if !IsCapable()
810         */
811        target_p->from->localClient->serial = current_serial;
820      found++;
812  
813        if (!IsCapable(target_p->from, cap))
814          continue;
815  
816 <      sendto_anywhere(target_p, source_p, "%s", buffer);
816 >      if (HasID(target_p->from))
817 >        send_message_remote(target_p->from, source_p, buff_suid);
818 >      else
819 >        send_message_remote(target_p->from, source_p, buff_name);
820      }
821    }
822 +
823 +  dbuf_ref_free(buff_suid);
824 +  dbuf_ref_free(buff_name);
825   }
826  
827   /* sendto_anywhere()
# Line 838 | Line 835 | sendto_match_servs(struct Client *source
835   */
836   void
837   sendto_anywhere(struct Client *to, struct Client *from,
838 +                const char *command,
839                  const char *pattern, ...)
840   {
841    va_list args;
842 <  char buffer[IRCD_BUFSIZE];
845 <  int len;
846 <  struct Client *send_to = (to->from != NULL ? to->from : to);
842 >  struct dbuf_block *buffer;
843  
844 <  if (IsDead(send_to))
844 >  if (IsDead(to->from))
845      return;
846  
847 +  buffer = dbuf_alloc();
848 +
849    if (MyClient(to))
850    {
851      if (IsServer(from))
852 <    {
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 <    }
852 >      dbuf_put(buffer, ":%s %s %s ", from->name, command, to->name);
853      else
854 <      len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s ",
862 <                     from->name, from->username, from->host);
854 >      dbuf_put(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name);
855    }
856 <  else len = snprintf(buffer, sizeof(buffer), ":%s ", ID_or_name(from, send_to));
856 >  else
857 >    dbuf_put(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to));
858  
859    va_start(args, pattern);
860 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
860 >  send_format(buffer, pattern, args);
861    va_end(args);
862  
863    if (MyClient(to))
864 <    send_message(send_to, buffer, len);
864 >    send_message(to, buffer);
865    else
866 <    send_message_remote(send_to, from, buffer, len);
866 >    send_message_remote(to, from, buffer);
867 >
868 >  dbuf_ref_free(buffer);
869   }
870  
871   /* sendto_realops_flags()
# Line 918 | Line 913 | sendto_realops_flags(unsigned int flags,
913       * If we're sending it to admins, and they're not, skip.
914       */
915      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
916 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
916 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
917        continue;
918  
919      if (HasUMode(client_p, flags))
# Line 941 | Line 936 | sendto_wallops_flags(unsigned int flags,
936   {
937    dlink_node *ptr = NULL;
938    va_list args;
939 <  char buffer[IRCD_BUFSIZE];
940 <  int len;
939 >  struct dbuf_block *buffer;
940 >
941 >  buffer = dbuf_alloc();
942  
943    if (IsClient(source_p))
944 <    len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s WALLOPS :",
949 <                   source_p->name, source_p->username,
950 <                   source_p->host);
944 >    dbuf_put(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
945    else
946 <    len = snprintf(buffer, sizeof(buffer), ":%s WALLOPS :",
953 <                   source_p->name);
946 >    dbuf_put(buffer, ":%s WALLOPS :", source_p->name);
947  
948    va_start(args, pattern);
949 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
949 >  send_format(buffer, pattern, args);
950    va_end(args);
951  
952    DLINK_FOREACH(ptr, oper_list.head)
# Line 962 | Line 955 | sendto_wallops_flags(unsigned int flags,
955      assert(client_p->umodes & UMODE_OPER);
956  
957      if (HasUMode(client_p, flags) && !IsDefunct(client_p))
958 <      send_message(client_p, buffer, len);
958 >      send_message(client_p, buffer);
959    }
960 +
961 +  dbuf_ref_free(buffer);
962   }
963  
964   /* ts_warn()
# Line 974 | Line 969 | sendto_wallops_flags(unsigned int flags,
969   *                (at most 5 warnings every 5 seconds)
970   */
971   void
972 < ts_warn(const char *pattern, ...)
972 > sendto_realops_flags_ratelimited(const char *pattern, ...)
973   {
974    va_list args;
975    char buffer[IRCD_BUFSIZE];
# Line 1020 | Line 1015 | kill_client(struct Client *client_p, str
1015              const char *pattern, ...)
1016   {
1017    va_list args;
1018 <  char buffer[IRCD_BUFSIZE];
1024 <  int len;
1018 >  struct dbuf_block *buffer;
1019  
1020    if (client_p->from != NULL)
1021      client_p = client_p->from;
1022    if (IsDead(client_p))
1023      return;
1024  
1025 <  len = snprintf(buffer, sizeof(buffer), ":%s KILL %s :",
1026 <                 ID_or_name(&me, client_p->from),
1027 <                 ID_or_name(diedie, client_p));
1025 >  buffer = dbuf_alloc();
1026 >
1027 >  dbuf_put(buffer, ":%s KILL %s :",
1028 >           ID_or_name(&me, client_p),
1029 >           ID_or_name(diedie, client_p));
1030  
1031    va_start(args, pattern);
1032 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1032 >  send_format(buffer, pattern, args);
1033    va_end(args);
1034  
1035 <  send_message(client_p, buffer, len);
1035 >  send_message(client_p, buffer);
1036 >
1037 >  dbuf_ref_free(buffer);
1038   }
1039  
1040   /* kill_client_ll_serv_butone()
# Line 1056 | Line 1054 | kill_client_serv_butone(struct Client *o
1054    va_list args;
1055    int have_uid = 0;
1056    dlink_node *ptr = NULL;
1057 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1058 <  int len_uid = 0, len_nick = 0;
1057 >  struct dbuf_block *uid_buffer, *nick_buffer;
1058 >
1059 >  uid_buffer = dbuf_alloc(), nick_buffer = dbuf_alloc();
1060  
1061    if (HasID(source_p))
1062    {
1063      have_uid = 1;
1064      va_start(args, pattern);
1065 <    len_uid = snprintf(buf_uid, sizeof(buf_uid), ":%s KILL %s :",
1066 <                       me.id, ID(source_p));
1068 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1069 <                           args);
1065 >    dbuf_put(uid_buffer, ":%s KILL %s :", me.id, ID(source_p));
1066 >    send_format(uid_buffer, pattern, args);
1067      va_end(args);
1068    }
1069  
1070    va_start(args, pattern);
1071 <  len_nick = snprintf(buf_nick, sizeof(buf_nick), ":%s KILL %s :",
1072 <                      me.name, source_p->name);
1076 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1077 <                          args);
1071 >  dbuf_put(nick_buffer, ":%s KILL %s :", me.name, source_p->name);
1072 >  send_format(nick_buffer, pattern, args);
1073    va_end(args);
1074  
1075    DLINK_FOREACH(ptr, serv_list.head)
# Line 1087 | Line 1082 | kill_client_serv_butone(struct Client *o
1082        continue;
1083  
1084      if (have_uid && IsCapable(client_p, CAP_TS6))
1085 <      send_message(client_p, buf_uid, len_uid);
1085 >      send_message(client_p, uid_buffer);
1086      else
1087 <      send_message(client_p, buf_nick, len_nick);
1087 >      send_message(client_p, nick_buffer);
1088    }
1089 < }
1089 >
1090 >  dbuf_ref_free(uid_buffer);
1091 >  dbuf_ref_free(nick_buffer);
1092 > }

Diff Legend

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