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-7.2/src/send.c (file contents), Revision 438 by michael, Sat Feb 11 21:53:46 2006 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 3335 by michael, Thu Apr 17 18:55:31 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"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "send.h"
30   #include "channel.h"
31   #include "client.h"
30 – #include "common.h"
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
34 – #include "handlers.h"
35   #include "numeric.h"
36   #include "fdlist.h"
37   #include "s_bsd.h"
38   #include "s_serv.h"
39 < #include "sprintf_irc.h"
40 < #include "s_conf.h"
41 < #include "list.h"
42 < #include "s_log.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "memory.h"
44 – #include "hook.h"
45 – #include "irc_getnameinfo.h"
42   #include "packet.h"
43  
48 – #define LOG_BUFSIZE 2048
44  
45 < struct Callback *iosend_cb = NULL;
51 < struct Callback *iosendctrl_cb = NULL;
45 > static unsigned int current_serial = 0;
46  
53 – static void send_message(struct Client *, char *, int);
54 – static void send_message_remote(struct Client *, struct Client *, char *, int);
55 –
56 – static unsigned long current_serial = 0L;
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   {
70 –  int len;
71 –
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);
85 <  if (len > bufsize - 2)
86 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
87 <
88 <  lsendbuf[len++] = '\r';
89 <  lsendbuf[len++] = '\n';
90 <  return (len);
91 < }
72 >  dbuf_put_args(buffer, pattern, args);
73  
74 < /*
75 < * iosend_default - append a packet to the client's sendq.
95 < */
96 < void *
97 < iosend_default(va_list args)
98 < {
99 <  struct Client *to = va_arg(args, struct Client *);
100 <  int length = va_arg(args, int);
101 <  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 110 | 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))
89 >  assert(!IsMe(to));
90    assert(to != &me);
91  
92 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
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,
96 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
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),
99 <                           get_sendq(to));
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 +
103      dead_link_on_write(to, 0);
104      return;
105    }
106  
107 <  execute_callback(iosend_cb, to, len, buf);
107 >  dbuf_add(&to->localClient->buf_sendq, buf);
108  
109    /*
110 <   ** Update statistics. The following is slightly incorrect
111 <   ** because it counts messages even if queued, but bytes
112 <   ** only really sent. Queued bytes get updated in SendQueued.
110 >   * Update statistics. The following is slightly incorrect because
111 >   * it counts messages even if queued, but bytes only really sent.
112 >   * Queued bytes get updated in send_queued_write().
113     */
114    ++to->localClient->send.messages;
115    ++me.localClient->send.messages;
116  
117 <  if (dbuf_length(&to->localClient->buf_sendq) >
143 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
144 <    send_queued_write(to);
117 >  send_queued_write(to);
118   }
119  
120   /* send_message_remote()
121   *
122   * inputs       - pointer to client from message is being sent
123   *              - pointer to client to send to
124 < *              - pointer to preformatted buffer
152 < *              - length of input buffer
124 > *              - pointer to buffer
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,
160 <                    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,
138 <                         "server send message to %s [%s] dropped from %s(Not local server)",
139 <                         to->name, to->from->name, from->name);
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);
140      return;
141    }
142  
170 –  if (ServerInfo.hub && IsCapable(to, CAP_LL))
171 –  {
172 –    if (((from->lazyLinkClientExists &
173 –          to->localClient->serverMask) == 0))
174 –      client_burst_if_needed(to, from);
175 –  }
176 –
143    /* Optimize by checking if (from && to) before everything */
144    /* we set to->from up there.. */
145  
# Line 181 | Line 147 | send_message_remote(struct Client *to, s
147    {
148      if (IsServer(from))
149      {
150 <      sendto_realops_flags(UMODE_ALL, L_ALL,
150 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
151                             "Send message to %s [%s] dropped from %s(Fake Dir)",
152                             to->name, to->from->name, from->name);
153        return;
154      }
155  
156 <    sendto_realops_flags(UMODE_ALL, L_ALL,
156 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
157                           "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
158                           to->name, to->username, to->host,
159                           from->name, from->username, from->host,
160                           to->from->name);
161  
162 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
162 >    sendto_server(NULL, NOCAPS, NOCAPS,
163                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
164 <                  me.id, to->name, me.name, to->name,
199 <                  to->username, to->host, to->from->name);
200 <    sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS,
201 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
202 <                  me.name, to->name, me.name, to->name,
164 >                  me.id, to->id, me.name, to->name,
165                    to->username, to->host, to->from->name);
166  
167 <    SetKilled(to);
167 >    AddFlag(to, FLAGS_KILLED);
168  
169      if (IsClient(from))
170 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
171 <                 me.name, from->name, to->name, to->username,
210 <                 to->host, to->from);
211 <
212 <    exit_client(to, &me, "Ghosted client");
170 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
171 >                         to->username, to->host, to->from);
172  
173 +    exit_client(to, "Ghosted client");
174      return;
175 <  }
175 >  }
176  
177 <  send_message(to, buf, len);
177 >  send_message(to, buf);
178   }
179  
180   /*
# Line 224 | Line 184 | send_message_remote(struct Client *to, s
184   void
185   sendq_unblocked(fde_t *fd, struct Client *client_p)
186   {
187 <  ClearSendqBlocked(client_p);
228 <  /* let send_queued_write be executed by send_queued_all */
229 <
230 < #ifdef HAVE_LIBCRYPTO
231 <  if (fd->flags.pending_read)
232 <  {
233 <    fd->flags.pending_read = 0;
234 <    read_packet(fd, client_p);
235 <  }
236 < #endif
237 < }
187 >  assert(fd == &client_p->localClient->fd);
188  
189 < /*
190 < ** slinkq_unblocked
241 < **      Called when a server control socket is ready for writing.
242 < */
243 < static void
244 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
245 < {
246 <  ClearSlinkqBlocked(client_p);
247 <  send_queued_slink_write(client_p);
189 >  DelFlag(client_p, FLAGS_BLOCKED);
190 >  send_queued_write(client_p);
191   }
192  
193   /*
# Line 256 | Line 199 | slinkq_unblocked(fde_t *fd, struct Clien
199   void
200   send_queued_write(struct Client *to)
201   {
202 <  int retlen;
260 <  struct dbuf_block *first;
202 >  int retlen = 0;
203  
204    /*
205     ** Once socket is marked dead, we cannot start writing to it,
206     ** even if the error is removed...
207     */
208 <  if (IsDead(to) || IsSendqBlocked(to))
208 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
209      return;  /* no use calling send() now */
210  
211    /* Next, lets try to write some data */
270 –
212    if (dbuf_length(&to->localClient->buf_sendq))
213    {
214 <    do {
215 <      first = to->localClient->buf_sendq.blocks.head->data;
214 >    do
215 >    {
216 >      struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data;
217  
218   #ifdef HAVE_LIBCRYPTO
219        if (to->localClient->fd.ssl)
220        {
221 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
221 >        retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos);
222  
223          /* translate openssl error codes, sigh */
224 <        if (retlen < 0)
225 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
226 <          {
224 >        if (retlen < 0)
225 >        {
226 >          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
227 >          {
228              case SSL_ERROR_WANT_READ:
229 <              return;  /* retry later, don't register for write events */
230 <
231 <            case SSL_ERROR_WANT_WRITE:
289 <              errno = EWOULDBLOCK;
229 >              return;  /* retry later, don't register for write events */
230 >            case SSL_ERROR_WANT_WRITE:
231 >              errno = EWOULDBLOCK;
232              case SSL_ERROR_SYSCALL:
233 <              break;
233 >              break;
234              case SSL_ERROR_SSL:
235                if (errno == EAGAIN)
236                  break;
237              default:
238 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
239 <          }
238 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
239 >          }
240 >        }
241        }
242        else
243   #endif
244 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
244 >        retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0);
245  
246        if (retlen <= 0)
304 –      {
305 – #ifdef _WIN32
306 –        errno = WSAGetLastError();
307 – #endif
247          break;
309 –      }
248  
249        dbuf_delete(&to->localClient->buf_sendq, retlen);
250  
# Line 315 | Line 253 | send_queued_write(struct Client *to)
253        me.localClient->send.bytes += retlen;
254      } while (dbuf_length(&to->localClient->buf_sendq));
255  
256 <    if ((retlen < 0) && (ignoreErrno(errno)))
256 >    if (retlen < 0 && ignoreErrno(errno))
257      {
258 +      AddFlag(to, FLAGS_BLOCKED);
259 +
260        /* we have a non-fatal error, reschedule a write */
321 –      SetSendqBlocked(to);
261        comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
262 <                     (PF *)sendq_unblocked, (void *)to, 0);
262 >                     (PF *)sendq_unblocked, to, 0);
263      }
264      else if (retlen <= 0)
265      {
# Line 330 | Line 269 | send_queued_write(struct Client *to)
269    }
270   }
271  
333 – /*
334 – ** send_queued_slink_write
335 – **      This is called when there is a chance the some output would
336 – **      be possible. This attempts to empty the send queue as far as
337 – **      possible, and then if any data is left, a write is rescheduled.
338 – */
339 – void
340 – send_queued_slink_write(struct Client *to)
341 – {
342 –  int retlen;
343 –
344 –  /*
345 –   ** Once socket is marked dead, we cannot start writing to it,
346 –   ** even if the error is removed...
347 –   */
348 –  if (IsDead(to) || IsSlinkqBlocked(to))
349 –    return;  /* no use calling send() now */
350 –
351 –  /* Next, lets try to write some data */
352 –  if (to->localClient->slinkq != NULL)
353 –  {
354 –    retlen = send(to->localClient->ctrlfd.fd,
355 –                   to->localClient->slinkq + to->localClient->slinkq_ofs,
356 –                   to->localClient->slinkq_len, 0);
357 –    if (retlen < 0)
358 –    {
359 –      /* If we have a fatal error */
360 –      if (!ignoreErrno(errno))
361 –      {
362 –        dead_link_on_write(to, errno);
363 –        return;
364 –      }
365 –    }
366 –    else if (retlen == 0)
367 –    {
368 –      /* 0 bytes is an EOF .. */
369 –      dead_link_on_write(to, 0);
370 –      return;
371 –    }
372 –    else
373 –    {
374 –      execute_callback(iosendctrl_cb, to, retlen,
375 –        to->localClient->slinkq + to->localClient->slinkq_ofs);
376 –      to->localClient->slinkq_len -= retlen;
377 –
378 –      assert(to->localClient->slinkq_len >= 0);
379 –      if (to->localClient->slinkq_len)
380 –        to->localClient->slinkq_ofs += retlen;
381 –      else
382 –      {
383 –        to->localClient->slinkq_ofs = 0;
384 –        MyFree(to->localClient->slinkq);
385 –        to->localClient->slinkq = NULL;
386 –      }
387 –    }
388 –
389 –    /* Finally, if we have any more data, reschedule a write */
390 –    if (to->localClient->slinkq_len)
391 –    {
392 –      SetSlinkqBlocked(to);
393 –      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
394 –                     (PF *)slinkq_unblocked, (void *)to, 0);
395 –    }
396 –  }
397 – }
398 –
272   /* send_queued_all()
273   *
274   * input        - NONE
# Line 411 | 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 438 | Line 311 | void
311   sendto_one(struct Client *to, const char *pattern, ...)
312   {
313    va_list args;
314 <  char buffer[IRCD_BUFSIZE];
442 <  int len;
314 >  struct dbuf_block *buffer = NULL;
315  
316 <  if (to->from != NULL)
317 <    to = to->from;
318 <  if (IsDead(to))
319 <    return; /* This socket has already been marked as dead */
316 >  if (IsDead(to->from))
317 >    return;  /* This socket has already been marked as dead */
318 >
319 >  buffer = dbuf_alloc();
320 >
321 >  va_start(args, pattern);
322 >  send_format(buffer, pattern, args);
323 >  va_end(args);
324 >
325 >  send_message(to->from, buffer);
326 >
327 >  dbuf_ref_free(buffer);
328 > }
329 >
330 > void
331 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
332 > {
333 >  struct dbuf_block *buffer = NULL;
334 >  const char *dest = NULL;
335 >  va_list args;
336 >
337 >  if (IsDead(to->from))
338 >    return;
339 >
340 >  dest = ID_or_name(to, to);
341 >
342 >  if (EmptyString(dest))
343 >    dest = "*";
344 >
345 >  buffer = dbuf_alloc();
346 >
347 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
348 >
349 >  va_start(args, numeric);
350 >  send_format(buffer, numeric_form(numeric), args);
351 >  va_end(args);
352 >
353 >  send_message(to->from, buffer);
354 >
355 >  dbuf_ref_free(buffer);
356 > }
357 >
358 > void
359 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
360 > {
361 >  struct dbuf_block *buffer = NULL;
362 >  const char *dest = NULL;
363 >  va_list args;
364 >
365 >  if (IsDead(to->from))
366 >    return;
367 >
368 >  dest = ID_or_name(to, to);
369 >
370 >  if (EmptyString(dest))
371 >    dest = "*";
372 >
373 >  buffer = dbuf_alloc();
374 >
375 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
376  
377    va_start(args, pattern);
378 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
378 >  send_format(buffer, pattern, args);
379    va_end(args);
380  
381 <  send_message(to, buffer, len);
381 >  send_message(to->from, buffer);
382 >
383 >  dbuf_ref_free(buffer);
384   }
385  
386   /* sendto_channel_butone()
# Line 466 | Line 396 | sendto_one(struct Client *to, const char
396   */
397   void
398   sendto_channel_butone(struct Client *one, struct Client *from,
399 <                      struct Channel *chptr, const char *command,
399 >                      struct Channel *chptr, unsigned int type,
400                        const char *pattern, ...)
401   {
402 <  va_list alocal, aremote, auid;
403 <  char local_buf[IRCD_BUFSIZE];
404 <  char remote_buf[IRCD_BUFSIZE];
405 <  char uid_buf[IRCD_BUFSIZE];
406 <  int local_len, remote_len, uid_len;
477 <  dlink_node *ptr;
478 <  dlink_node *ptr_next;
479 <  struct Client *target_p;
402 >  va_list alocal, aremote;
403 >  struct dbuf_block *local_buf, *remote_buf;
404 >  dlink_node *ptr = NULL, *ptr_next = NULL;
405 >
406 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
407  
408    if (IsServer(from))
409 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
483 <                           from->name, command, chptr->chname);
409 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
410    else
411 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
412 <                           from->name, from->username, from->host,
413 <                           command, chptr->chname);
488 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
489 <                          from->name, command, chptr->chname);
490 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
491 <                       ID(from), command, chptr->chname);
411 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
412 >
413 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
414  
415    va_start(alocal, pattern);
416    va_start(aremote, pattern);
417 <  va_start(auid, pattern);
418 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
419 <                           pattern, alocal);
498 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
499 <                            pattern, aremote);
500 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
501 <                         auid);
502 <  va_end(auid);
417 >  send_format(local_buf, pattern, alocal);
418 >  send_format(remote_buf, pattern, aremote);
419 >
420    va_end(aremote);
421    va_end(alocal);
422  
# Line 507 | Line 424 | sendto_channel_butone(struct Client *one
424  
425    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
426    {
427 <    target_p = ((struct Membership *)ptr->data)->client_p;
428 <    assert(target_p != NULL);
427 >    struct Membership *ms = ptr->data;
428 >    struct Client *target_p = ms->client_p;
429  
430 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
430 >    assert(IsClient(target_p));
431 >
432 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
433 >        (one && target_p->from == one->from))
434        continue;
435  
436 <    if (MyClient(target_p))
437 <    {
438 <      if (target_p->serial != current_serial)
439 <      {
440 <        send_message(target_p, local_buf, local_len);
441 <        target_p->serial = current_serial;
442 <      }
443 <    }
524 <    else
525 <    {
526 <      /* Now check whether a message has been sent to this
527 <       * remote link already
528 <       */
529 <      if (target_p->from->serial != current_serial)
530 <      {
531 <        if (IsCapable(target_p->from, CAP_TS6))
532 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
533 <        else
534 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
535 <        target_p->from->serial = current_serial;
536 <      }
537 <    }
436 >    if (type && (ms->flags & type) == 0)
437 >      continue;
438 >
439 >    if (MyConnect(target_p))
440 >      send_message(target_p, local_buf);
441 >    else if (target_p->from->localClient->serial != current_serial)
442 >      send_message_remote(target_p->from, from, remote_buf);
443 >    target_p->from->localClient->serial = current_serial;
444    }
445 +
446 +  dbuf_ref_free(local_buf);
447 +  dbuf_ref_free(remote_buf);
448   }
449  
450   /* sendto_server()
451 < *
451 > *
452   * inputs       - pointer to client to NOT send to
453 < *              - pointer to source client required by LL (if any)
545 < *              - pointer to channel required by LL (if any)
453 > *              - pointer to channel
454   *              - caps or'd together which must ALL be present
455   *              - caps or'd together which must ALL NOT be present
548 – *              - LL flags: LL_ICLIENT | LL_ICHAN
456   *              - printf style format string
457   *              - args to format string
458   * output       - NONE
459   * side effects - Send a message to all connected servers, except the
460   *                client 'one' (if non-NULL), as long as the servers
461   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
462 < *                If the server is a lazylink client, then it must know
556 < *                about source_p if non-NULL (unless LL_ICLIENT is specified,
557 < *                when source_p will be introduced where required) and
558 < *                chptr if non-NULL (unless LL_ICHANNEL is specified, when
559 < *                chptr will be introduced where required).
560 < *                Note: nothing will be introduced to a LazyLeaf unless
561 < *                the message is actually sent.
562 < *            
462 > *
463   * This function was written in an attempt to merge together the other
464   * billion sendto_*serv*() functions, which sprung up with capabs,
465   * lazylinks, uids, etc.
466   * -davidt
467   */
468 < void
469 < sendto_server(struct Client *one, struct Client *source_p,
470 <              struct Channel *chptr, unsigned long caps,
471 <              unsigned long nocaps, unsigned long llflags,
468 > void
469 > sendto_server(struct Client *one,
470 >              const unsigned int caps,
471 >              const unsigned int nocaps,
472                const char *format, ...)
473   {
474    va_list args;
475 <  struct Client *client_p;
476 <  dlink_node *ptr;
577 <  char buffer[IRCD_BUFSIZE];
578 <  int len;
475 >  dlink_node *ptr = NULL;
476 >  struct dbuf_block *buffer;
477  
478 <  if (chptr != NULL)
581 <  {
582 <    if (chptr->chname[0] != '#')
583 <      return;
584 <  }
478 >  buffer = dbuf_alloc();
479  
480    va_start(args, format);
481 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
481 >  send_format(buffer, format, args);
482    va_end(args);
483  
484    DLINK_FOREACH(ptr, serv_list.head)
485    {
486 <    client_p = ptr->data;
486 >    struct Client *client_p = ptr->data;
487  
488      /* If dead already skip */
489      if (IsDead(client_p))
490        continue;
491      /* check against 'one' */
492 <    if (one != NULL && (client_p == one->from))
492 >    if (one && (client_p == one->from))
493        continue;
494      /* check we have required capabs */
495      if ((client_p->localClient->caps & caps) != caps)
496        continue;
497      /* check we don't have any forbidden capabs */
498 <    if ((client_p->localClient->caps & nocaps) != 0)
498 >    if ((client_p->localClient->caps & nocaps))
499        continue;
500  
501 <    if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
608 <    {
609 <      /* check LL channel */
610 <      if (chptr != NULL &&
611 <          ((chptr->lazyLinkChannelExists &
612 <            client_p->localClient->serverMask) == 0))
613 <      {
614 <        /* Only introduce the channel if we really will send this message */
615 <        if (!(llflags & LL_ICLIENT) && source_p &&
616 <            ((source_p->lazyLinkClientExists &
617 <              client_p->localClient->serverMask) == 0))
618 <          continue; /* we can't introduce the unknown source_p, skip */
619 <
620 <        if (llflags & LL_ICHAN)
621 <          burst_channel(client_p, chptr);
622 <        else
623 <          continue; /* we can't introduce the unknown chptr, skip */
624 <      }
625 <      /* check LL client */
626 <      if (source_p &&
627 <          ((source_p->lazyLinkClientExists &
628 <            client_p->localClient->serverMask) == 0))
629 <      {
630 <        if (llflags & LL_ICLIENT)
631 <          client_burst_if_needed(client_p,source_p);
632 <        else
633 <          continue; /* we can't introduce the unknown source_p, skip */
634 <      }
635 <    }
636 <    send_message(client_p, buffer, len);
501 >    send_message(client_p, buffer);
502    }
503 +
504 +  dbuf_ref_free(buffer);
505   }
506  
507   /* sendto_common_channels_local()
# Line 643 | Line 510 | sendto_server(struct Client *one, struct
510   *              - pattern to send
511   * output       - NONE
512   * side effects - Sends a message to all people on local server who are
513 < *                in same channel with user.
513 > *                in same channel with user.
514   *                used by m_nick.c and exit_one_client.
515   */
516   void
517 < sendto_common_channels_local(struct Client *user, int touser,
517 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
518                               const char *pattern, ...)
519   {
520    va_list args;
# Line 656 | Line 523 | sendto_common_channels_local(struct Clie
523    struct Channel *chptr;
524    struct Membership *ms;
525    struct Client *target_p;
526 <  char buffer[IRCD_BUFSIZE];
527 <  int len;
526 >  struct dbuf_block *buffer;
527 >
528 >  buffer = dbuf_alloc();
529  
530    va_start(args, pattern);
531 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
531 >  send_format(buffer, pattern, args);
532    va_end(args);
533  
534    ++current_serial;
535  
536    DLINK_FOREACH(cptr, user->channel.head)
537    {
538 <    chptr = ((struct Membership *) cptr->data)->chptr;
671 <    assert(chptr != NULL);
538 >    chptr = ((struct Membership *)cptr->data)->chptr;
539  
540 <    DLINK_FOREACH(uptr, chptr->locmembers.head)
540 >    DLINK_FOREACH(uptr, chptr->members.head)
541      {
542        ms = uptr->data;
543        target_p = ms->client_p;
677 –      assert(target_p != NULL);
544  
545 <      if (target_p == user || IsDefunct(target_p) ||
546 <          target_p->serial == current_serial)
545 >      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
546 >          target_p->localClient->serial == current_serial)
547 >        continue;
548 >
549 >      if (HasCap(target_p, cap) != cap)
550          continue;
551  
552 <      target_p->serial = current_serial;
553 <      send_message(target_p, buffer, len);
552 >      target_p->localClient->serial = current_serial;
553 >      send_message(target_p, buffer);
554      }
555    }
556  
557    if (touser && MyConnect(user) && !IsDead(user) &&
558 <      user->serial != current_serial)
559 <    send_message(user, buffer, len);
558 >      user->localClient->serial != current_serial)
559 >    if (HasCap(user, cap) == cap)
560 >      send_message(user, buffer);
561 >
562 >  dbuf_ref_free(buffer);
563   }
564  
565   /* sendto_channel_local()
# Line 701 | 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;
712 <  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->locmembers.head)
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)
594 >    if (type && (ms->flags & type) == 0)
595        continue;
596  
597 <    if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
597 >    if (!MyConnect(target_p) || IsDefunct(target_p) ||
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 742 | Line 616 | sendto_channel_local(int type, int nodea
616   *
617   * WARNING - +D clients are omitted
618   */
745 – void      
746 – sendto_channel_local_butone(struct Client *one, int type,
747 –                            struct Channel *chptr, const char *pattern, ...)
748 – {
749 –  va_list args;
750 –  char buffer[IRCD_BUFSIZE];
751 –  int len;
752 –  struct Client *target_p;
753 –  struct Membership *ms;
754 –  dlink_node *ptr;
755 –
756 –  va_start(args, pattern);
757 –  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
758 –  va_end(args);
759 –
760 –  DLINK_FOREACH(ptr, chptr->locmembers.head)      
761 –  {  
762 –    ms = ptr->data;
763 –    target_p = ms->client_p;
764 –
765 –    if (type != 0 && (ms->flags & type) == 0)
766 –      continue;
767 –
768 –    if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p))
769 –      continue;
770 –    send_message(target_p, buffer, len);
771 –  }
772 – }
773 –
774 –
775 – /* sendto_channel_remote()
776 – *
777 – * inputs       - Client not to send towards
778 – *              - Client from whom message is from
779 – *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
780 – *              - pointer to channel to send to
781 – *              - var args pattern
782 – * output       - NONE
783 – * side effects - Send a message to all members of a channel that are
784 – *                remote to this server.
785 – */
619   void
620 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
621 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
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 <  dlink_node *ptr;
627 <  struct Client *target_p;
795 <  struct Membership *ms;
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);
630 >  send_format(buffer, pattern, args);
631    va_end(args);
632  
801 –  ++current_serial;
802 –
633    DLINK_FOREACH(ptr, chptr->members.head)
634    {
635 <    ms = ptr->data;
636 <    target_p = ms->client_p;
635 >    struct Membership *ms = ptr->data;
636 >    struct Client *target_p = ms->client_p;
637  
638 <    if (type != 0 && (ms->flags & type) == 0)
638 >    if (type && (ms->flags & type) == 0)
639        continue;
640  
641 <    if (MyConnect(target_p))
641 >    if (!MyConnect(target_p) || (one && target_p == one->from))
642        continue;
813 –    target_p = target_p->from;
643  
644 <    if (target_p == one->from ||
816 <        ((target_p->from->localClient->caps & caps) != caps) ||
817 <        ((target_p->from->localClient->caps & nocaps) != 0))
644 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
645        continue;
646 <    if (target_p->from->serial != current_serial)
647 <    {
648 <      send_message(target_p, buffer, len);
649 <      target_p->from->serial = current_serial;
650 <    }
651 <  }
646 >
647 >    if (HasCap(target_p, cap) != cap)
648 >      continue;
649 >
650 >    send_message(target_p, buffer);
651 >  }
652 >
653 >  dbuf_ref_free(buffer);
654   }
655  
656   /*
# Line 842 | Line 671 | sendto_channel_remote(struct Client *one
671   * side effects - NONE
672   */
673   static int
674 < match_it(const struct Client *one, const char *mask, int what)
674 > match_it(const struct Client *one, const char *mask, unsigned int what)
675   {
676    if (what == MATCH_HOST)
677 <    return(match(mask, one->host));
677 >    return !match(mask, one->host);
678  
679 <  return(match(mask, one->servptr->name));
679 >  return !match(mask, one->servptr->name);
680   }
681  
682   /* sendto_match_butone()
# Line 858 | Line 687 | match_it(const struct Client *one, const
687   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
688   */
689   void
690 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
690 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
691                      int what, const char *pattern, ...)
692   {
693    va_list alocal, aremote;
694 <  struct Client *client_p;
695 <  dlink_node *ptr, *ptr_next;
696 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
697 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
698 <                             from->username, from->host);
699 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
694 >  dlink_node *ptr = NULL, *ptr_next = NULL;
695 >  struct dbuf_block *local_buf, *remote_buf;
696 >
697 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
698 >
699 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
700 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
701  
702    va_start(alocal, pattern);
703    va_start(aremote, pattern);
704 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
705 <                           pattern, alocal);
876 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
877 <                            pattern, aremote);
704 >  send_format(local_buf, pattern, alocal);
705 >  send_format(remote_buf, pattern, aremote);
706    va_end(aremote);
707    va_end(alocal);
708  
709    /* scan the local clients */
710    DLINK_FOREACH(ptr, local_client_list.head)
711    {
712 <    client_p = ptr->data;
712 >    struct Client *client_p = ptr->data;
713  
714 <    if (client_p != one && !IsDefunct(client_p) &&
714 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
715          match_it(client_p, mask, what))
716 <      send_message(client_p, local_buf, local_len);
716 >      send_message(client_p, local_buf);
717    }
718  
719    /* Now scan servers */
720    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
721    {
722 <    client_p = ptr->data;
722 >    struct Client *client_p = ptr->data;
723  
724      /*
725       * The old code looped through every client on the
# Line 917 | Line 745 | sendto_match_butone(struct Client *one,
745       * server deal with it.
746       * -wnder
747       */
748 <    if (client_p != one && !IsDefunct(client_p))
749 <      send_message_remote(client_p, from, remote_buf, remote_len);
748 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
749 >      send_message_remote(client_p, from, remote_buf);
750    }
751 +
752 +  dbuf_ref_free(local_buf);
753 +  dbuf_ref_free(remote_buf);
754   }
755  
756   /* sendto_match_servs()
# Line 932 | Line 763 | sendto_match_butone(struct Client *one,
763   * side effects - data sent to servers matching with capab
764   */
765   void
766 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
766 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
767                     const char *pattern, ...)
768   {
769    va_list args;
770 <  struct Client *target_p;
771 <  dlink_node *ptr;
772 <  char buffer[IRCD_BUFSIZE];
773 <  int found = 0;
770 >  dlink_node *ptr = NULL;
771 >  struct dbuf_block *buff_suid;
772 >
773 >  buff_suid = dbuf_alloc();
774  
775    va_start(args, pattern);
776 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
776 >  dbuf_put_fmt(buff_suid, ":%s ", source_p->id);
777 >  dbuf_put_args(buff_suid, pattern, args);
778    va_end(args);
779  
780 <  current_serial++;
780 >  ++current_serial;
781  
782    DLINK_FOREACH(ptr, global_serv_list.head)
783    {
784 <    target_p = ptr->data;
784 >    struct Client *target_p = ptr->data;
785  
786      /* Do not attempt to send to ourselves, or the source */
787      if (IsMe(target_p) || target_p->from == source_p->from)
788        continue;
789  
790 <    if (target_p->from->serial == current_serial)
790 >    if (target_p->from->localClient->serial == current_serial)
791        continue;
792  
793 <    if (match(mask, target_p->name))
793 >    if (!match(mask, target_p->name))
794      {
795        /*
796         * if we set the serial here, then we'll never do a
797         * match() again, if !IsCapable()
798         */
799 <      target_p->from->serial = current_serial;
968 <      found++;
799 >      target_p->from->localClient->serial = current_serial;
800  
801        if (!IsCapable(target_p->from, cap))
802          continue;
803  
804 <      sendto_anywhere(target_p, source_p, "%s", buffer);
804 >      send_message_remote(target_p->from, source_p, buff_suid);
805      }
806    }
807 +
808 +  dbuf_ref_free(buff_suid);
809   }
810  
811   /* sendto_anywhere()
# Line 986 | Line 819 | sendto_match_servs(struct Client *source
819   */
820   void
821   sendto_anywhere(struct Client *to, struct Client *from,
822 +                const char *command,
823                  const char *pattern, ...)
824   {
825    va_list args;
826 <  char buffer[IRCD_BUFSIZE];
993 <  int len;
994 <  struct Client *send_to = (to->from != NULL ? to->from : to);
826 >  struct dbuf_block *buffer = NULL;
827  
828 <  if (IsDead(send_to))
828 >  if (IsDead(to->from))
829      return;
830  
831 <  if (MyClient(to))
832 <  {
833 <    if (IsServer(from))
834 <    {
835 <      if (IsCapable(to, CAP_TS6) && HasID(from))
836 <        len = ircsprintf(buffer, ":%s ", from->id);
837 <      else
838 <        len = ircsprintf(buffer, ":%s ", from->name);
1007 <    }
1008 <    else
1009 <      len = ircsprintf(buffer, ":%s!%s@%s ",
1010 <                       from->name, from->username, from->host);
1011 <  }
1012 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
831 >  buffer = dbuf_alloc();
832 >
833 >  if (MyClient(to) && IsClient(from))
834 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
835 >                 from->host, command, to->name);
836 >  else
837 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
838 >                 command, ID_or_name(to, to));
839  
840    va_start(args, pattern);
841 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
841 >  send_format(buffer, pattern, args);
842    va_end(args);
843  
844 <  if(MyClient(to))
845 <    send_message(send_to, buffer, len);
844 >  if (MyClient(to))
845 >    send_message(to, buffer);
846    else
847 <    send_message_remote(send_to, from, buffer, len);
847 >    send_message_remote(to, from, buffer);
848 >
849 >  dbuf_ref_free(buffer);
850   }
851  
852   /* sendto_realops_flags()
# Line 1030 | Line 858 | sendto_anywhere(struct Client *to, struc
858   * side effects - Send to *local* ops only but NOT +s nonopers.
859   */
860   void
861 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
861 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
862   {
863 <  struct Client *client_p;
864 <  char nbuf[IRCD_BUFSIZE];
865 <  dlink_node *ptr;
863 >  const char *ntype = NULL;
864 >  dlink_node *ptr = NULL;
865 >  char nbuf[IRCD_BUFSIZE] = "";
866    va_list args;
867  
868    va_start(args, pattern);
869 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
869 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
870    va_end(args);
871  
872 <  DLINK_FOREACH(ptr, oper_list.head)
872 >  switch (type)
873    {
874 <    client_p = ptr->data;
875 <    assert(client_p->umodes & UMODE_OPER);
876 <
877 <    /* If we're sending it to opers and theyre an admin, skip.
878 <     * If we're sending it to admins, and theyre not, skip.
879 <     */
880 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
881 <        ((level == L_OPER) && IsAdmin(client_p)))
882 <      continue;
883 <
884 <    if (client_p->umodes & flags)
1057 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1058 <                 me.name, client_p->name, nbuf);
874 >    case SEND_NOTICE:
875 >      ntype = "Notice";
876 >      break;
877 >    case SEND_GLOBAL:
878 >      ntype = "Global";
879 >      break;
880 >    case SEND_LOCOPS:
881 >      ntype = "LocOps";
882 >      break;
883 >    default:
884 >      assert(0);
885    }
1060 – }
1061 –
1062 – /* sendto_wallops_flags()
1063 – *
1064 – * inputs       - flag types of messages to show to real opers
1065 – *              - client sending request
1066 – *              - var args input message
1067 – * output       - NONE
1068 – * side effects - Send a wallops to local opers
1069 – */
1070 – void
1071 – sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1072 –                     const char *pattern, ...)
1073 – {
1074 –  struct Client *client_p;
1075 –  dlink_node *ptr;
1076 –  va_list args;
1077 –  char buffer[IRCD_BUFSIZE];
1078 –  int len;
1079 –
1080 –  if (IsClient(source_p))
1081 –    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1082 –                     source_p->name, source_p->username, source_p->host);
1083 –  else
1084 –    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
1085 –
1086 –  va_start(args, pattern);
1087 –  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1088 –  va_end(args);
886  
887    DLINK_FOREACH(ptr, oper_list.head)
888    {
889 <    client_p = ptr->data;
890 <    assert(client_p->umodes & UMODE_OPER);
889 >    struct Client *client_p = ptr->data;
890 >    assert(HasUMode(client_p, UMODE_OPER));
891  
892 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
893 <      send_message(client_p, buffer, len);
892 >    /*
893 >     * If we're sending it to opers and they're an admin, skip.
894 >     * If we're sending it to admins, and they're not, skip.
895 >     */
896 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
897 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
898 >      continue;
899 >
900 >    if (HasUMode(client_p, flags))
901 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
902 >                 me.name, client_p->name, ntype, nbuf);
903    }
904   }
905  
906   /* ts_warn()
907   *
908 < * inputs       - var args message
909 < * output       - NONE
910 < * side effects - Call sendto_realops_flags, with some flood checking
911 < *                (at most 5 warnings every 5 seconds)
908 > * inputs       - var args message
909 > * output       - NONE
910 > * side effects - Call sendto_realops_flags, with some flood checking
911 > *                (at most 5 warnings every 5 seconds)
912   */
913   void
914 < ts_warn(const char *pattern, ...)
914 > sendto_realops_flags_ratelimited(const char *pattern, ...)
915   {
916    va_list args;
917 <  char buffer[LOG_BUFSIZE];
917 >  char buffer[IRCD_BUFSIZE] = "";
918    static time_t last = 0;
919    static int warnings = 0;
920  
1115 –  /*
1116 –   ** if we're running with TS_WARNINGS enabled and someone does
1117 –   ** something silly like (remotely) connecting a nonTS server,
1118 –   ** we'll get a ton of warnings, so we make sure we don't send
1119 –   ** more than 5 every 5 seconds.  -orabidoo
1120 –   */
1121 –
921    if (CurrentTime - last < 5)
922    {
923      if (++warnings > 5)
# Line 1131 | Line 930 | ts_warn(const char *pattern, ...)
930    }
931  
932    va_start(args, pattern);
933 <  vsprintf_irc(buffer, pattern, args);
933 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
934    va_end(args);
935  
936 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
937 <  ilog(L_CRIT, "%s", buffer);
936 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
937 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
938   }
939  
940 < /* kill_client()
940 > /* sendto_wallops_flags()
941   *
942 < * inputs       - client to send kill towards
943 < *              - pointer to client to kill
944 < *              - reason for kill
945 < * output       - NONE
946 < * side effects - NONE
942 > * inputs       - flag types of messages to show to real opers
943 > *              - client sending request
944 > *              - var args input message
945 > * output       - NONE
946 > * side effects - Send a wallops to local opers
947   */
948   void
949 < kill_client(struct Client *client_p, struct Client *diedie,
950 <            const char *pattern, ...)
949 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
950 >                     const char *pattern, ...)
951   {
952 +  dlink_node *ptr = NULL;
953    va_list args;
954 <  char buffer[IRCD_BUFSIZE];
1155 <  int len;
1156 <
1157 <  if (client_p->from != NULL)
1158 <    client_p = client_p->from;
1159 <  if (IsDead(client_p))
1160 <    return;
1161 <
1162 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1163 <                   ID_or_name(diedie, client_p));
1164 <
1165 <  va_start(args, pattern);
1166 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1167 <  va_end(args);
954 >  struct dbuf_block *buffer;
955  
956 <  send_message(client_p, buffer, len);
1170 < }
956 >  buffer = dbuf_alloc();
957  
958 < /* kill_client_ll_serv_butone()
959 < *
960 < * inputs       - pointer to client to not send to
961 < *              - pointer to client to kill
1176 < * output       - NONE
1177 < * side effects - Send a KILL for the given client
1178 < *                message to all connected servers
1179 < *                except the client 'one'. Also deal with
1180 < *                client being unknown to leaf, as in lazylink...
1181 < */
1182 < void
1183 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1184 <                           const char *pattern, ...)
1185 < {
1186 <  va_list args;
1187 <  int have_uid = 0;
1188 <  struct Client *client_p;
1189 <  dlink_node *ptr;
1190 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1191 <  int len_uid = 0, len_nick;
1192 <
1193 <  if (HasID(source_p) && (me.id[0] != '\0'))
1194 <  {
1195 <    have_uid = 1;
1196 <    va_start(args, pattern);
1197 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1198 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1199 <                           args);
1200 <    va_end(args);
1201 <  }
958 >  if (IsClient(source_p))
959 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
960 >  else
961 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
962  
963    va_start(args, pattern);
964 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1205 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1206 <                          args);
964 >  send_format(buffer, pattern, args);
965    va_end(args);
966  
967 <  DLINK_FOREACH(ptr, serv_list.head)
967 >  DLINK_FOREACH(ptr, oper_list.head)
968    {
969 <    client_p = ptr->data;
970 <
1213 <    if (one != NULL && (client_p == one->from))
1214 <      continue;
1215 <    if (IsDefunct(client_p))
1216 <      continue;
969 >    struct Client *client_p = ptr->data;
970 >    assert(client_p->umodes & UMODE_OPER);
971  
972 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
973 <    if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) ||
1220 <        !ServerInfo.hub ||
1221 <        (source_p->lazyLinkClientExists & client_p->localClient->serverMask))
1222 <    {
1223 <      if (have_uid && IsCapable(client_p, CAP_TS6))
1224 <        send_message(client_p, buf_uid, len_uid);
1225 <      else
1226 <        send_message(client_p, buf_nick, len_nick);
1227 <    }
972 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
973 >      send_message(client_p, buffer);
974    }
975 < }
975 >
976 >  dbuf_ref_free(buffer);
977 > }

Diff Legend

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