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 1734 by michael, Fri Jan 11 12:59:24 2013 UTC vs.
Revision 3136 by michael, Tue Mar 11 18:24:03 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 34 | Line 36
36   #include "fdlist.h"
37   #include "s_bsd.h"
38   #include "s_serv.h"
37 #include "sprintf_irc.h"
39   #include "conf.h"
40   #include "log.h"
41   #include "memory.h"
41 #include "hook.h"
42   #include "packet.h"
43  
44  
45 struct Callback *iosend_cb = NULL;
45   static unsigned int current_serial = 0;
46  
47  
48   /* send_format()
49   *
50 < * inputs       - buffer to format into
51 < *              - size of the buffer
50 > * inputs
51 > *              - buffer
52   *              - format pattern to use
53   *              - var args
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   {
61  int len;
62
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);
76 <  if (len > bufsize - 2)
77 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
78 <
79 <  lsendbuf[len++] = '\r';
80 <  lsendbuf[len++] = '\n';
81 <  return len;
82 < }
72 >  dbuf_put_args(buffer, pattern, args);
73  
74 < /*
75 < * iosend_default - append a packet to the client's sendq.
86 < */
87 < void *
88 < iosend_default(va_list args)
89 < {
90 <  struct Client *to = va_arg(args, struct Client *);
91 <  int length = va_arg(args, int);
92 <  char *buf = va_arg(args, char *);
74 >  if (buffer->size > sizeof(buffer->data) - 2)
75 >    buffer->size = sizeof(buffer->data) - 2;
76  
77 <  dbuf_put(&to->localClient->buf_sendq, buf, length);
78 <  return NULL;
77 >  buffer->data[buffer->size++] = '\r';
78 >  buffer->data[buffer->size++] = '\n';
79   }
80  
81   /*
# Line 101 | Line 84 | iosend_default(va_list args)
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 > %lu",
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);
# Line 120 | Line 103 | send_message(struct Client *to, char *bu
103      return;
104    }
105  
106 <  execute_callback(iosend_cb, to, len, buf);
106 >  dbuf_add(&to->localClient->buf_sendq, buf);
107  
108    /*
109     ** Update statistics. The following is slightly incorrect
# Line 130 | 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) >
134 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
135 <    send_queued_write(to);
116 >  send_queued_write(to);
117   }
118  
119   /* send_message_remote()
120   *
121   * inputs       - pointer to client from message is being sent
122   *              - pointer to client to send to
123 < *              - pointer to preformatted buffer
143 < *              - length of input buffer
123 > *              - pointer to buffer
124   * output       - none
125   * side effects - Despite the function name, this only sends to directly
126   *                connected clients.
127 < *
127 > *
128   */
129   static void
130 < send_message_remote(struct Client *to, struct Client *from,
151 <                    char *buf, int len)
130 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
131   {
132 +  to = to->from;
133 +
134    if (!MyConnect(to))
135    {
136      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
137 <                         "server send message to %s [%s] dropped from %s(Not local server)",
138 <                         to->name, to->from->name, from->name);
137 >                         "Server send message to %s [%s] dropped from %s(Not local server)",
138 >                         to->name, to->from->name, from->name);
139      return;
140    }
141  
# Line 177 | Line 158 | send_message_remote(struct Client *to, s
158                           from->name, from->username, from->host,
159                           to->from->name);
160  
161 <    sendto_server(NULL, CAP_TS6, NOCAPS,
161 >    sendto_server(NULL, NOCAPS, NOCAPS,
162                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
163                    me.id, to->name, me.name, to->name,
164                    to->username, to->host, to->from->name);
184    sendto_server(NULL, NOCAPS, CAP_TS6,
185                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
186                  me.name, to->name, me.name, to->name,
187                  to->username, to->host, to->from->name);
165  
166      AddFlag(to, FLAGS_KILLED);
167  
168      if (IsClient(from))
169 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
170 <                 me.name, from->name, to->name, to->username,
194 <                 to->host, to->from);
169 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
170 >                         to->username, to->host, to->from);
171  
172      exit_client(to, &me, "Ghosted client");
197
173      return;
174 <  }
174 >  }
175  
176 <  send_message(to, buf, len);
176 >  send_message(to, buf);
177   }
178  
179   /*
# Line 208 | Line 183 | send_message_remote(struct Client *to, s
183   void
184   sendq_unblocked(fde_t *fd, struct Client *client_p)
185   {
186 <  ClearSendqBlocked(client_p);
187 <  /* let send_queued_write be executed by send_queued_all */
213 <
214 < #ifdef HAVE_LIBCRYPTO
215 <  if (fd->flags.pending_read)
216 <  {
217 <    fd->flags.pending_read = 0;
218 <    read_packet(fd, client_p);
219 <  }
220 < #endif
186 >  assert(fd == &client_p->localClient->fd);
187 >  send_queued_write(client_p);
188   }
189  
190   /*
# Line 229 | Line 196 | sendq_unblocked(fde_t *fd, struct Client
196   void
197   send_queued_write(struct Client *to)
198   {
199 <  int retlen;
233 <  struct dbuf_block *first;
199 >  int retlen = 0;
200  
201    /*
202     ** Once socket is marked dead, we cannot start writing to it,
203     ** even if the error is removed...
204     */
205 <  if (IsDead(to) || IsSendqBlocked(to))
205 >  if (IsDead(to))
206      return;  /* no use calling send() now */
207  
208    /* Next, lets try to write some data */
243
209    if (dbuf_length(&to->localClient->buf_sendq))
210    {
211 <    do {
212 <      first = to->localClient->buf_sendq.blocks.head->data;
211 >    do
212 >    {
213 >      struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data;
214  
215   #ifdef HAVE_LIBCRYPTO
216        if (to->localClient->fd.ssl)
217        {
218 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
218 >        retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos);
219  
220          /* translate openssl error codes, sigh */
221 <        if (retlen < 0)
222 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
223 <          {
221 >        if (retlen < 0)
222 >        {
223 >          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
224 >          {
225              case SSL_ERROR_WANT_READ:
226 <              return;  /* retry later, don't register for write events */
227 <
228 <            case SSL_ERROR_WANT_WRITE:
262 <              errno = EWOULDBLOCK;
226 >              return;  /* retry later, don't register for write events */
227 >            case SSL_ERROR_WANT_WRITE:
228 >              errno = EWOULDBLOCK;
229              case SSL_ERROR_SYSCALL:
230 <              break;
230 >              break;
231              case SSL_ERROR_SSL:
232                if (errno == EAGAIN)
233                  break;
234              default:
235 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
236 <          }
235 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
236 >          }
237 >        }
238        }
239        else
240   #endif
241 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
241 >        retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0);
242  
243        if (retlen <= 0)
244          break;
# Line 286 | Line 253 | send_queued_write(struct Client *to)
253      if ((retlen < 0) && (ignoreErrno(errno)))
254      {
255        /* we have a non-fatal error, reschedule a write */
289      SetSendqBlocked(to);
256        comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
257 <                     (PF *)sendq_unblocked, (void *)to, 0);
257 >                     (PF *)sendq_unblocked, to, 0);
258      }
259      else if (retlen <= 0)
260      {
# Line 313 | Line 279 | send_queued_all(void)
279     * a notice to opers, which is to be delivered by this function.
280     */
281    DLINK_FOREACH(ptr, serv_list.head)
282 <    send_queued_write((struct Client *) ptr->data);
282 >    send_queued_write(ptr->data);
283  
284    DLINK_FOREACH(ptr, unknown_list.head)
285 <    send_queued_write((struct Client *) ptr->data);
285 >    send_queued_write(ptr->data);
286  
287    DLINK_FOREACH(ptr, local_client_list.head)
288 <    send_queued_write((struct Client *) ptr->data);
288 >    send_queued_write(ptr->data);
289  
290    /* NOTE: This can still put clients on aborted_list; unfortunately,
291     * exit_aborted_clients takes precedence over send_queued_all,
# Line 340 | Line 306 | void
306   sendto_one(struct Client *to, const char *pattern, ...)
307   {
308    va_list args;
309 <  char buffer[IRCD_BUFSIZE];
310 <  int len;
309 >  struct dbuf_block *buffer;
310 >
311 >  to = to->from;
312 >
313 >  if (IsDead(to))
314 >    return;  /* This socket has already been marked as dead */
315 >
316 >  buffer = dbuf_alloc();
317 >
318 >  va_start(args, pattern);
319 >  send_format(buffer, pattern, args);
320 >  va_end(args);
321 >
322 >  send_message(to, buffer);
323 >
324 >  dbuf_ref_free(buffer);
325 > }
326 >
327 > void
328 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
329 > {
330 >  struct dbuf_block *buffer;
331 >  va_list args;
332 >  const char *dest;
333 >
334 >  to = to->from;
335 >
336 >  if (IsDead(to))
337 >    return;
338 >
339 >  dest = ID_or_name(to, to);
340 >  if (EmptyString(dest))
341 >    dest = "*";
342 >
343 >  buffer = dbuf_alloc();
344 >
345 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
346 >
347 >  va_start(args, numeric);
348 >  send_format(buffer, numeric_form(numeric), args);
349 >  va_end(args);
350 >
351 >  send_message(to, buffer);
352 >
353 >  dbuf_ref_free(buffer);
354 > }
355 >
356 > void
357 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
358 > {
359 >  struct dbuf_block *buffer;
360 >  va_list args;
361 >  const char *dest;
362 >
363 >  to = to->from;
364  
346  if (to->from != NULL)
347    to = to->from;
365    if (IsDead(to))
366 <    return; /* This socket has already been marked as dead */
366 >    return;
367 >
368 >  dest = ID_or_name(to, to);
369 >  if (EmptyString(dest))
370 >    dest = "*";
371 >
372 >  buffer = dbuf_alloc();
373 >
374 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
375  
376    va_start(args, pattern);
377 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
377 >  send_format(buffer, pattern, args);
378    va_end(args);
379  
380 <  send_message(to, buffer, len);
380 >  send_message(to, buffer);
381 >
382 >  dbuf_ref_free(buffer);
383   }
384  
385   /* sendto_channel_butone()
# Line 371 | Line 398 | sendto_channel_butone(struct Client *one
398                        struct Channel *chptr, unsigned int type,
399                        const char *pattern, ...)
400   {
401 <  va_list alocal, aremote, auid;
402 <  char local_buf[IRCD_BUFSIZE];
376 <  char remote_buf[IRCD_BUFSIZE];
377 <  char uid_buf[IRCD_BUFSIZE];
378 <  int local_len, remote_len, uid_len;
401 >  va_list alocal, aremote;
402 >  struct dbuf_block *local_buf, *remote_buf;
403    dlink_node *ptr = NULL, *ptr_next = NULL;
404  
405 +  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
406 +
407    if (IsServer(from))
408 <    local_len = ircsprintf(local_buf, ":%s ",
383 <                           from->name);
408 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
409    else
410 <    local_len = ircsprintf(local_buf, ":%s!%s@%s ",
411 <                           from->name, from->username, from->host);
412 <  remote_len = ircsprintf(remote_buf, ":%s ",
388 <                          from->name);
389 <  uid_len = ircsprintf(uid_buf, ":%s ",
390 <                       ID(from));
410 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
411 >
412 >  dbuf_put_fmt(remote_buf, ":%s ", ID(from));
413  
414    va_start(alocal, pattern);
415    va_start(aremote, pattern);
416 <  va_start(auid, pattern);
417 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
418 <                           pattern, alocal);
397 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
398 <                            pattern, aremote);
399 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
400 <                         auid);
401 <  va_end(auid);
416 >  send_format(local_buf, pattern, alocal);
417 >  send_format(remote_buf, pattern, aremote);
418 >
419    va_end(aremote);
420    va_end(alocal);
421  
# Line 418 | Line 435 | sendto_channel_butone(struct Client *one
435        continue;
436  
437      if (MyConnect(target_p))
438 <    {
439 <      if (target_p->localClient->serial != current_serial)
440 <      {
441 <        send_message(target_p, local_buf, local_len);
425 <        target_p->localClient->serial = current_serial;
426 <      }
427 <    }
428 <    else
429 <    {
430 <      /* Now check whether a message has been sent to this
431 <       * remote link already
432 <       */
433 <      if (target_p->from->localClient->serial != current_serial)
434 <      {
435 <        if (IsCapable(target_p->from, CAP_TS6))
436 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
437 <        else
438 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
439 <        target_p->from->localClient->serial = current_serial;
440 <      }
441 <    }
438 >      send_message(target_p, local_buf);
439 >    else if (target_p->from->localClient->serial != current_serial)
440 >      send_message_remote(target_p->from, from, remote_buf);
441 >    target_p->from->localClient->serial = current_serial;
442    }
443 +
444 +  dbuf_ref_free(local_buf);
445 +  dbuf_ref_free(remote_buf);
446   }
447  
448   /* sendto_server()
449 < *
449 > *
450   * inputs       - pointer to client to NOT send to
451   *              - pointer to channel
452   *              - caps or'd together which must ALL be present
# Line 454 | Line 457 | sendto_channel_butone(struct Client *one
457   * side effects - Send a message to all connected servers, except the
458   *                client 'one' (if non-NULL), as long as the servers
459   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
460 < *            
460 > *
461   * This function was written in an attempt to merge together the other
462   * billion sendto_*serv*() functions, which sprung up with capabs,
463   * lazylinks, uids, etc.
464   * -davidt
465   */
466 < void
466 > void
467   sendto_server(struct Client *one,
468                const unsigned int caps,
469                const unsigned int nocaps,
# Line 468 | Line 471 | sendto_server(struct Client *one,
471   {
472    va_list args;
473    dlink_node *ptr = NULL;
474 <  char buffer[IRCD_BUFSIZE];
475 <  int len = 0;
474 >  struct dbuf_block *buffer;
475 >
476 >  buffer = dbuf_alloc();
477  
478    va_start(args, format);
479 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
479 >  send_format(buffer, format, args);
480    va_end(args);
481  
482    DLINK_FOREACH(ptr, serv_list.head)
# Line 492 | Line 496 | sendto_server(struct Client *one,
496      if ((client_p->localClient->caps & nocaps) != 0)
497        continue;
498  
499 <    send_message(client_p, buffer, len);
499 >    send_message(client_p, buffer);
500    }
501 +
502 +  dbuf_ref_free(buffer);
503   }
504  
505   /* sendto_common_channels_local()
# Line 502 | Line 508 | sendto_server(struct Client *one,
508   *              - pattern to send
509   * output       - NONE
510   * side effects - Sends a message to all people on local server who are
511 < *                in same channel with user.
511 > *                in same channel with user.
512   *                used by m_nick.c and exit_one_client.
513   */
514   void
# Line 515 | Line 521 | sendto_common_channels_local(struct Clie
521    struct Channel *chptr;
522    struct Membership *ms;
523    struct Client *target_p;
524 <  char buffer[IRCD_BUFSIZE];
525 <  int len;
524 >  struct dbuf_block *buffer;
525 >
526 >  buffer = dbuf_alloc();
527  
528    va_start(args, pattern);
529 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
529 >  send_format(buffer, pattern, args);
530    va_end(args);
531  
532    ++current_serial;
533  
534    DLINK_FOREACH(cptr, user->channel.head)
535    {
536 <    chptr = ((struct Membership *) cptr->data)->chptr;
536 >    chptr = ((struct Membership *)cptr->data)->chptr;
537      assert(chptr != NULL);
538  
539      DLINK_FOREACH(uptr, chptr->members.head)
# Line 543 | Line 550 | sendto_common_channels_local(struct Clie
550          continue;
551  
552        target_p->localClient->serial = current_serial;
553 <      send_message(target_p, buffer, len);
553 >      send_message(target_p, buffer);
554      }
555    }
556  
557    if (touser && MyConnect(user) && !IsDead(user) &&
558        user->localClient->serial != current_serial)
559 <    if (HasCap(target_p, cap) == cap)
560 <      send_message(user, buffer, len);
559 >    if (HasCap(user, cap) == cap)
560 >      send_message(user, buffer);
561 >
562 >  dbuf_ref_free(buffer);
563   }
564  
565   /* sendto_channel_local()
# Line 564 | Line 573 | sendto_common_channels_local(struct Clie
573   *                locally connected to this server.
574   */
575   void
576 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
576 > sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
577                       const char *pattern, ...)
578   {
579    va_list args;
580 <  char buffer[IRCD_BUFSIZE];
581 <  int len;
582 <  dlink_node *ptr;
583 <  struct Membership *ms;
575 <  struct Client *target_p;
580 >  dlink_node *ptr = NULL;
581 >  struct dbuf_block *buffer;
582 >
583 >  buffer = dbuf_alloc();
584  
585    va_start(args, pattern);
586 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
586 >  send_format(buffer, pattern, args);
587    va_end(args);
588  
589    DLINK_FOREACH(ptr, chptr->members.head)
590    {
591 <    ms = ptr->data;
592 <    target_p = ms->client_p;
591 >    struct Membership *ms = ptr->data;
592 >    struct Client *target_p = ms->client_p;
593  
594      if (type != 0 && (ms->flags & type) == 0)
595        continue;
# Line 590 | Line 598 | sendto_channel_local(int type, int nodea
598          (nodeaf && HasUMode(target_p, UMODE_DEAF)))
599        continue;
600  
601 <    send_message(target_p, buffer, len);
601 >    send_message(target_p, buffer);
602    }
603 +
604 +  dbuf_ref_free(buffer);
605   }
606  
607   /* sendto_channel_local_butone()
# Line 606 | Line 616 | sendto_channel_local(int type, int nodea
616   *
617   * WARNING - +D clients are omitted
618   */
619 < void      
620 < sendto_channel_local_butone(struct Client *one, int type, unsigned int cap,
621 <                            struct Channel *chptr, const char *pattern, ...)
619 > void
620 > sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
621 >                            struct Channel *chptr, const char *pattern, ...)
622   {
623    va_list args;
624 <  char buffer[IRCD_BUFSIZE];
625 <  int len;
626 <  struct Client *target_p;
627 <  struct Membership *ms;
618 <  dlink_node *ptr;
624 >  dlink_node *ptr = NULL;
625 >  struct dbuf_block *buffer;
626 >
627 >  buffer = dbuf_alloc();
628  
629 <  va_start(args, pattern);
630 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
629 >  va_start(args, pattern);
630 >  send_format(buffer, pattern, args);
631    va_end(args);
632  
633 <  DLINK_FOREACH(ptr, chptr->members.head)      
634 <  {  
635 <    ms = ptr->data;
636 <    target_p = ms->client_p;
633 >  DLINK_FOREACH(ptr, chptr->members.head)
634 >  {
635 >    struct Membership *ms = ptr->data;
636 >    struct Client *target_p = ms->client_p;
637  
638      if (type != 0 && (ms->flags & type) == 0)
639        continue;
# Line 634 | Line 643 | sendto_channel_local_butone(struct Clien
643        continue;
644  
645      if (HasCap(target_p, cap) != cap)
637        continue;
638    send_message(target_p, buffer, len);
639  }
640 }
641
642
643 /* sendto_channel_remote()
644 *
645 * inputs       - Client not to send towards
646 *              - Client from whom message is from
647 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
648 *              - pointer to channel to send to
649 *              - var args pattern
650 * output       - NONE
651 * side effects - Send a message to all members of a channel that are
652 *                remote to this server.
653 */
654 void
655 sendto_channel_remote(struct Client *one, struct Client *from, int type,
656                      const unsigned int caps, const unsigned int nocaps,
657                      struct Channel *chptr, const char *pattern, ...)
658 {
659  va_list args;
660  char buffer[IRCD_BUFSIZE];
661  int len;
662  dlink_node *ptr;
663  struct Client *target_p;
664  struct Membership *ms;
665
666  va_start(args, pattern);
667  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
668  va_end(args);
669
670  ++current_serial;
671
672  DLINK_FOREACH(ptr, chptr->members.head)
673  {
674    ms = ptr->data;
675    target_p = ms->client_p;
676
677    if (type != 0 && (ms->flags & type) == 0)
646        continue;
647  
648 <    if (MyConnect(target_p))
649 <      continue;
682 <    target_p = target_p->from;
648 >    send_message(target_p, buffer);
649 >  }
650  
651 <    if (target_p == one->from ||
685 <        ((target_p->from->localClient->caps & caps) != caps) ||
686 <        ((target_p->from->localClient->caps & nocaps) != 0))
687 <      continue;
688 <    if (target_p->from->localClient->serial != current_serial)
689 <    {
690 <      send_message(target_p, buffer, len);
691 <      target_p->from->localClient->serial = current_serial;
692 <    }
693 <  }
651 >  dbuf_ref_free(buffer);
652   }
653  
654   /*
# Line 711 | Line 669 | sendto_channel_remote(struct Client *one
669   * side effects - NONE
670   */
671   static int
672 < match_it(const struct Client *one, const char *mask, int what)
672 > match_it(const struct Client *one, const char *mask, unsigned int what)
673   {
674    if (what == MATCH_HOST)
675      return !match(mask, one->host);
# Line 731 | Line 689 | sendto_match_butone(struct Client *one,
689                      int what, const char *pattern, ...)
690   {
691    va_list alocal, aremote;
692 <  struct Client *client_p;
693 <  dlink_node *ptr, *ptr_next;
694 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
695 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
696 <                             from->username, from->host);
697 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
692 >  dlink_node *ptr = NULL, *ptr_next = NULL;
693 >  struct dbuf_block *local_buf, *remote_buf;
694 >
695 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
696 >
697 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
698 >  dbuf_put_fmt(remote_buf, ":%s ", ID(from));
699  
700    va_start(alocal, pattern);
701    va_start(aremote, pattern);
702 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
703 <                           pattern, alocal);
745 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
746 <                            pattern, aremote);
702 >  send_format(local_buf, pattern, alocal);
703 >  send_format(remote_buf, pattern, aremote);
704    va_end(aremote);
705    va_end(alocal);
706  
707    /* scan the local clients */
708    DLINK_FOREACH(ptr, local_client_list.head)
709    {
710 <    client_p = ptr->data;
710 >    struct Client *client_p = ptr->data;
711  
712      if (client_p != one && !IsDefunct(client_p) &&
713          match_it(client_p, mask, what))
714 <      send_message(client_p, local_buf, local_len);
714 >      send_message(client_p, local_buf);
715    }
716  
717    /* Now scan servers */
718    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
719    {
720 <    client_p = ptr->data;
720 >    struct Client *client_p = ptr->data;
721  
722      /*
723       * The old code looped through every client on the
# Line 787 | Line 744 | sendto_match_butone(struct Client *one,
744       * -wnder
745       */
746      if (client_p != one && !IsDefunct(client_p))
747 <      send_message_remote(client_p, from, remote_buf, remote_len);
747 >      send_message_remote(client_p, from, remote_buf);
748    }
749 +
750 +  dbuf_ref_free(local_buf);
751 +  dbuf_ref_free(remote_buf);
752   }
753  
754   /* sendto_match_servs()
# Line 801 | Line 761 | sendto_match_butone(struct Client *one,
761   * side effects - data sent to servers matching with capab
762   */
763   void
764 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
764 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
765                     const char *pattern, ...)
766   {
767    va_list args;
768 <  struct Client *target_p;
769 <  dlink_node *ptr;
770 <  char buffer[IRCD_BUFSIZE];
771 <  int found = 0;
768 >  dlink_node *ptr = NULL;
769 >  struct dbuf_block *buff_suid;
770 >
771 >  buff_suid = dbuf_alloc();
772  
773    va_start(args, pattern);
774 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
774 >  dbuf_put_fmt(buff_suid, ":%s ", ID(source_p));
775 >  dbuf_put_args(buff_suid, pattern, args);
776    va_end(args);
777  
778    ++current_serial;
779  
780    DLINK_FOREACH(ptr, global_serv_list.head)
781    {
782 <    target_p = ptr->data;
782 >    struct Client *target_p = ptr->data;
783  
784      /* Do not attempt to send to ourselves, or the source */
785      if (IsMe(target_p) || target_p->from == source_p->from)
# Line 834 | Line 795 | sendto_match_servs(struct Client *source
795         * match() again, if !IsCapable()
796         */
797        target_p->from->localClient->serial = current_serial;
837      found++;
798  
799        if (!IsCapable(target_p->from, cap))
800          continue;
801  
802 <      sendto_anywhere(target_p, source_p, "%s", buffer);
802 >      send_message_remote(target_p->from, source_p, buff_suid);
803      }
804    }
805 +
806 +  dbuf_ref_free(buff_suid);
807   }
808  
809   /* sendto_anywhere()
# Line 855 | Line 817 | sendto_match_servs(struct Client *source
817   */
818   void
819   sendto_anywhere(struct Client *to, struct Client *from,
820 +                const char *command,
821                  const char *pattern, ...)
822   {
823    va_list args;
824 <  char buffer[IRCD_BUFSIZE];
862 <  int len;
863 <  struct Client *send_to = (to->from != NULL ? to->from : to);
824 >  struct dbuf_block *buffer;
825  
826 <  if (IsDead(send_to))
826 >  if (IsDead(to->from))
827      return;
828  
829 +  buffer = dbuf_alloc();
830 +
831    if (MyClient(to))
832    {
833      if (IsServer(from))
834 <    {
872 <      if (IsCapable(to, CAP_TS6) && HasID(from))
873 <        len = ircsprintf(buffer, ":%s ", from->id);
874 <      else
875 <        len = ircsprintf(buffer, ":%s ", from->name);
876 <    }
834 >      dbuf_put_fmt(buffer, ":%s %s %s ", from->name, command, to->name);
835      else
836 <      len = ircsprintf(buffer, ":%s!%s@%s ",
879 <                       from->name, from->username, from->host);
836 >      dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name);
837    }
838 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
838 >  else
839 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to));
840  
841    va_start(args, pattern);
842 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
842 >  send_format(buffer, pattern, args);
843    va_end(args);
844  
845 <  if(MyClient(to))
846 <    send_message(send_to, buffer, len);
845 >  if (MyClient(to))
846 >    send_message(to, buffer);
847    else
848 <    send_message_remote(send_to, from, buffer, len);
848 >    send_message_remote(to, from, buffer);
849 >
850 >  dbuf_ref_free(buffer);
851   }
852  
853   /* sendto_realops_flags()
# Line 935 | Line 895 | sendto_realops_flags(unsigned int flags,
895       * If we're sending it to admins, and they're not, skip.
896       */
897      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
898 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
898 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
899        continue;
900  
901      if (HasUMode(client_p, flags))
# Line 958 | Line 918 | sendto_wallops_flags(unsigned int flags,
918   {
919    dlink_node *ptr = NULL;
920    va_list args;
921 <  char buffer[IRCD_BUFSIZE];
922 <  int len;
921 >  struct dbuf_block *buffer;
922 >
923 >  buffer = dbuf_alloc();
924  
925    if (IsClient(source_p))
926 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
966 <                     source_p->name, source_p->username, source_p->host);
926 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
927    else
928 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
928 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
929  
930    va_start(args, pattern);
931 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
931 >  send_format(buffer, pattern, args);
932    va_end(args);
933  
934    DLINK_FOREACH(ptr, oper_list.head)
# Line 977 | Line 937 | sendto_wallops_flags(unsigned int flags,
937      assert(client_p->umodes & UMODE_OPER);
938  
939      if (HasUMode(client_p, flags) && !IsDefunct(client_p))
940 <      send_message(client_p, buffer, len);
940 >      send_message(client_p, buffer);
941    }
942 +
943 +  dbuf_ref_free(buffer);
944   }
945  
946   /* ts_warn()
# Line 989 | Line 951 | sendto_wallops_flags(unsigned int flags,
951   *                (at most 5 warnings every 5 seconds)
952   */
953   void
954 < ts_warn(const char *pattern, ...)
954 > sendto_realops_flags_ratelimited(const char *pattern, ...)
955   {
956    va_list args;
957    char buffer[IRCD_BUFSIZE];
# Line 1035 | Line 997 | kill_client(struct Client *client_p, str
997              const char *pattern, ...)
998   {
999    va_list args;
1000 <  char buffer[IRCD_BUFSIZE];
1001 <  int len;
1000 >  struct dbuf_block *buffer;
1001 >
1002 >  client_p = client_p->from;
1003  
1041  if (client_p->from != NULL)
1042    client_p = client_p->from;
1004    if (IsDead(client_p))
1005      return;
1006  
1007 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1008 <                   ID_or_name(diedie, client_p));
1007 >  buffer = dbuf_alloc();
1008 >
1009 >  dbuf_put_fmt(buffer, ":%s KILL %s :",
1010 >               ID_or_name(&me, client_p),
1011 >               ID_or_name(diedie, client_p));
1012  
1013    va_start(args, pattern);
1014 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1014 >  send_format(buffer, pattern, args);
1015    va_end(args);
1016  
1017 <  send_message(client_p, buffer, len);
1017 >  send_message(client_p, buffer);
1018 >
1019 >  dbuf_ref_free(buffer);
1020   }
1021  
1022 < /* kill_client_ll_serv_butone()
1022 > /* kill_client_serv_butone()
1023   *
1024   * inputs       - pointer to client to not send to
1025   *              - pointer to client to kill
# Line 1064 | Line 1030 | kill_client(struct Client *client_p, str
1030   *                client being unknown to leaf, as in lazylink...
1031   */
1032   void
1033 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1034 <                           const char *pattern, ...)
1033 > kill_client_serv_butone(struct Client *one, struct Client *source_p,
1034 >                        const char *pattern, ...)
1035   {
1036    va_list args;
1071  int have_uid = 0;
1037    dlink_node *ptr = NULL;
1038 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1074 <  int len_uid = 0, len_nick = 0;
1075 <
1076 <  if (HasID(source_p))
1077 <  {
1078 <    have_uid = 1;
1079 <    va_start(args, pattern);
1080 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1081 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1082 <                           args);
1083 <    va_end(args);
1084 <  }
1038 >  struct dbuf_block *uid_buffer = dbuf_alloc();
1039  
1040    va_start(args, pattern);
1041 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1042 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1089 <                          args);
1041 >  dbuf_put_fmt(uid_buffer, ":%s KILL %s :", ID(&me), ID(source_p));
1042 >  send_format(uid_buffer, pattern, args);
1043    va_end(args);
1044  
1045    DLINK_FOREACH(ptr, serv_list.head)
# Line 1098 | Line 1051 | kill_client_ll_serv_butone(struct Client
1051      if (IsDefunct(client_p))
1052        continue;
1053  
1054 <    if (have_uid && IsCapable(client_p, CAP_TS6))
1102 <      send_message(client_p, buf_uid, len_uid);
1103 <    else
1104 <      send_message(client_p, buf_nick, len_nick);
1054 >    send_message(client_p, uid_buffer);
1055    }
1056 < }
1056 >
1057 >  dbuf_ref_free(uid_buffer);
1058 > }

Diff Legend

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