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 439 by michael, Sat Feb 11 21:58:40 2006 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 4923 by michael, Tue Nov 25 14:38:08 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 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
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"
38 > #include "server.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 uint64_t current_serial;
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 > IRCD_BUFSIZE - 2)
75 >    buffer->size = IRCD_BUFSIZE - 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));
90    assert(to != &me);
91 +  assert(MyConnect(to));
92  
93 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
93 >  if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs))
94    {
95      if (IsServer(to))
96 <      sendto_realops_flags(UMODE_ALL, L_ALL,
97 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
96 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
97 >                           "Max SendQ limit exceeded for %s: %lu > %u",
98                             get_client_name(to, HIDE_IP),
99 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
100 <                           get_sendq(to));
99 >                           (unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size),
100 >                           get_sendq(&to->connection->confs));
101 >
102      if (IsClient(to))
103        SetSendQExceeded(to);
104 +
105      dead_link_on_write(to, 0);
106      return;
107    }
108  
109 <  execute_callback(iosend_cb, to, len, buf);
109 >  dbuf_add(&to->connection->buf_sendq, buf);
110  
111    /*
112 <   ** Update statistics. The following is slightly incorrect
113 <   ** because it counts messages even if queued, but bytes
114 <   ** only really sent. Queued bytes get updated in SendQueued.
112 >   * Update statistics. The following is slightly incorrect because
113 >   * it counts messages even if queued, but bytes only really sent.
114 >   * Queued bytes get updated in send_queued_write().
115     */
116 <  ++to->localClient->send.messages;
117 <  ++me.localClient->send.messages;
116 >  ++to->connection->send.messages;
117 >  ++me.connection->send.messages;
118  
119 <  if (dbuf_length(&to->localClient->buf_sendq) >
143 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
144 <    send_queued_write(to);
119 >  send_queued_write(to);
120   }
121  
122   /* send_message_remote()
123   *
124   * inputs       - pointer to client from message is being sent
125   *              - pointer to client to send to
126 < *              - pointer to preformatted buffer
152 < *              - length of input buffer
126 > *              - pointer to buffer
127   * output       - none
128   * side effects - Despite the function name, this only sends to directly
129   *                connected clients.
130 < *
130 > *
131   */
132   static void
133 < send_message_remote(struct Client *to, struct Client *from,
160 <                    char *buf, int len)
133 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
134   {
135 <  if (!MyConnect(to))
136 <  {
137 <    sendto_realops_flags(UMODE_ALL, L_ALL,
165 <                         "server send message to %s [%s] dropped from %s(Not local server)",
166 <                         to->name, to->from->name, from->name);
167 <    return;
168 <  }
169 <
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 <
177 <  /* Optimize by checking if (from && to) before everything */
178 <  /* we set to->from up there.. */
135 >  assert(MyConnect(to));
136 >  assert(!IsMe(to));
137 >  assert(to->from == to);
138  
139 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
139 >  if (!MyConnect(from) && to == from->from)
140    {
141 <    if (IsServer(from))
142 <    {
143 <      sendto_realops_flags(UMODE_ALL, L_ALL,
185 <                           "Send message to %s [%s] dropped from %s(Fake Dir)",
186 <                           to->name, to->from->name, from->name);
187 <      return;
188 <    }
189 <
190 <    sendto_realops_flags(UMODE_ALL, L_ALL,
191 <                         "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
192 <                         to->name, to->username, to->host,
193 <                         from->name, from->username, from->host,
194 <                         to->from->name);
195 <
196 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
197 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
198 <                  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,
203 <                  to->username, to->host, to->from->name);
204 <
205 <    SetKilled(to);
206 <
207 <    if (IsClient(from))
208 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
209 <                 me.name, from->name, to->name, to->username,
210 <                 to->host, to->from);
211 <
212 <    exit_client(to, &me, "Ghosted client");
213 <
141 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
142 >                         "Send message to %s dropped from %s (Fake Dir)",
143 >                         to->name, from->name);
144      return;
145 <  }
145 >  }
146  
147 <  send_message(to, buf, len);
147 >  send_message(to, buf);
148   }
149  
150   /*
# Line 222 | Line 152 | send_message_remote(struct Client *to, s
152   **      Called when a socket is ready for writing.
153   */
154   void
155 < sendq_unblocked(fde_t *fd, struct Client *client_p)
155 > sendq_unblocked(fde_t *fd, void *data)
156   {
157 <  ClearSendqBlocked(client_p);
158 <  /* let send_queued_write be executed by send_queued_all */
157 >  struct Client *client_p = data;
158 >  assert(fd == &client_p->connection->fd);
159  
160 < #ifdef HAVE_LIBCRYPTO
161 <  if (fd->flags.pending_read)
232 <  {
233 <    fd->flags.pending_read = 0;
234 <    read_packet(fd, client_p);
235 <  }
236 < #endif
237 < }
238 <
239 < /*
240 < ** 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);
160 >  DelFlag(client_p, FLAGS_BLOCKED);
161 >  send_queued_write(client_p);
162   }
163  
164   /*
# Line 256 | Line 170 | slinkq_unblocked(fde_t *fd, struct Clien
170   void
171   send_queued_write(struct Client *to)
172   {
173 <  int retlen;
260 <  struct dbuf_block *first;
173 >  int retlen = 0;
174  
175    /*
176     ** Once socket is marked dead, we cannot start writing to it,
177     ** even if the error is removed...
178     */
179 <  if (IsDead(to) || IsSendqBlocked(to))
179 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
180      return;  /* no use calling send() now */
181  
182    /* Next, lets try to write some data */
183 <
271 <  if (dbuf_length(&to->localClient->buf_sendq))
183 >  if (dbuf_length(&to->connection->buf_sendq))
184    {
185 <    do {
186 <      first = to->localClient->buf_sendq.blocks.head->data;
185 >    do
186 >    {
187 >      struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
188  
189   #ifdef HAVE_LIBCRYPTO
190 <      if (to->localClient->fd.ssl)
190 >      if (to->connection->fd.ssl)
191        {
192 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
192 >        retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos);
193  
194          /* translate openssl error codes, sigh */
195 <        if (retlen < 0)
196 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
197 <          {
195 >        if (retlen < 0)
196 >        {
197 >          switch (SSL_get_error(to->connection->fd.ssl, retlen))
198 >          {
199              case SSL_ERROR_WANT_READ:
200 <              return;  /* retry later, don't register for write events */
201 <
202 <            case SSL_ERROR_WANT_WRITE:
289 <              errno = EWOULDBLOCK;
200 >              return;  /* retry later, don't register for write events */
201 >            case SSL_ERROR_WANT_WRITE:
202 >              errno = EWOULDBLOCK;
203              case SSL_ERROR_SYSCALL:
204 <              break;
204 >              break;
205              case SSL_ERROR_SSL:
206                if (errno == EAGAIN)
207                  break;
208              default:
209 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
210 <          }
209 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
210 >          }
211 >        }
212        }
213        else
214   #endif
215 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
215 >        retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
216  
217        if (retlen <= 0)
304      {
305 #ifdef _WIN32
306        errno = WSAGetLastError();
307 #endif
218          break;
309      }
219  
220 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
220 >      dbuf_delete(&to->connection->buf_sendq, retlen);
221  
222        /* We have some data written .. update counters */
223 <      to->localClient->send.bytes += retlen;
224 <      me.localClient->send.bytes += retlen;
225 <    } while (dbuf_length(&to->localClient->buf_sendq));
223 >      to->connection->send.bytes += retlen;
224 >      me.connection->send.bytes += retlen;
225 >    } while (dbuf_length(&to->connection->buf_sendq));
226  
227 <    if ((retlen < 0) && (ignoreErrno(errno)))
227 >    if (retlen < 0 && ignoreErrno(errno))
228      {
229 +      AddFlag(to, FLAGS_BLOCKED);
230 +
231        /* we have a non-fatal error, reschedule a write */
232 <      SetSendqBlocked(to);
233 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
323 <                     (PF *)sendq_unblocked, (void *)to, 0);
232 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
233 >                     sendq_unblocked, to, 0);
234      }
235      else if (retlen <= 0)
236      {
# Line 330 | Line 240 | send_queued_write(struct Client *to)
240    }
241   }
242  
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
243   /* send_queued_all()
244   *
245   * input        - NONE
# Line 405 | Line 249 | send_queued_slink_write(struct Client *t
249   void
250   send_queued_all(void)
251   {
252 <  dlink_node *ptr;
252 >  dlink_node *node = NULL;
253  
254    /* Servers are processed first, mainly because this can generate
255     * a notice to opers, which is to be delivered by this function.
256     */
257 <  DLINK_FOREACH(ptr, serv_list.head)
258 <    send_queued_write((struct Client *) ptr->data);
257 >  DLINK_FOREACH(node, local_server_list.head)
258 >    send_queued_write(node->data);
259  
260 <  DLINK_FOREACH(ptr, unknown_list.head)
261 <    send_queued_write((struct Client *) ptr->data);
260 >  DLINK_FOREACH(node, unknown_list.head)
261 >    send_queued_write(node->data);
262  
263 <  DLINK_FOREACH(ptr, local_client_list.head)
264 <    send_queued_write((struct Client *) ptr->data);
263 >  DLINK_FOREACH(node, local_client_list.head)
264 >    send_queued_write(node->data);
265  
266    /* NOTE: This can still put clients on aborted_list; unfortunately,
267     * exit_aborted_clients takes precedence over send_queued_all,
# Line 438 | Line 282 | void
282   sendto_one(struct Client *to, const char *pattern, ...)
283   {
284    va_list args;
285 <  char buffer[IRCD_BUFSIZE];
286 <  int len;
285 >  struct dbuf_block *buffer = NULL;
286 >
287 >  if (IsDead(to->from))
288 >    return;  /* This socket has already been marked as dead */
289 >
290 >  buffer = dbuf_alloc();
291 >
292 >  va_start(args, pattern);
293 >  send_format(buffer, pattern, args);
294 >  va_end(args);
295 >
296 >  send_message(to->from, buffer);
297 >
298 >  dbuf_ref_free(buffer);
299 > }
300 >
301 > void
302 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
303 > {
304 >  struct dbuf_block *buffer = NULL;
305 >  const char *dest = NULL, *numstr = NULL;
306 >  va_list args;
307 >
308 >  if (IsDead(to->from))
309 >    return;
310 >
311 >  dest = ID_or_name(to, to);
312 >
313 >  if (EmptyString(dest))
314 >    dest = "*";
315 >
316 >  buffer = dbuf_alloc();
317 >
318 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
319 >
320 >  va_start(args, numeric);
321 >
322 >  if (numeric & SND_EXPLICIT)
323 >    numstr = va_arg(args, const char *);
324 >  else
325 >    numstr = numeric_form(numeric);
326 >
327 >  send_format(buffer, numstr, args);
328 >  va_end(args);
329 >
330 >  send_message(to->from, buffer);
331 >
332 >  dbuf_ref_free(buffer);
333 > }
334 >
335 > void
336 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
337 > {
338 >  struct dbuf_block *buffer = NULL;
339 >  const char *dest = NULL;
340 >  va_list args;
341 >
342 >  if (IsDead(to->from))
343 >    return;
344 >
345 >  dest = ID_or_name(to, to);
346 >
347 >  if (EmptyString(dest))
348 >    dest = "*";
349  
350 <  if (to->from != NULL)
351 <    to = to->from;
352 <  if (IsDead(to))
447 <    return; /* This socket has already been marked as dead */
350 >  buffer = dbuf_alloc();
351 >
352 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
353  
354    va_start(args, pattern);
355 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
355 >  send_format(buffer, pattern, args);
356    va_end(args);
357  
358 <  send_message(to, buffer, len);
358 >  send_message(to->from, buffer);
359 >
360 >  dbuf_ref_free(buffer);
361   }
362  
363   /* sendto_channel_butone()
# Line 466 | Line 373 | sendto_one(struct Client *to, const char
373   */
374   void
375   sendto_channel_butone(struct Client *one, struct Client *from,
376 <                      struct Channel *chptr, const char *command,
376 >                      struct Channel *chptr, unsigned int type,
377                        const char *pattern, ...)
378   {
379 <  va_list alocal, aremote, auid;
380 <  char local_buf[IRCD_BUFSIZE];
381 <  char remote_buf[IRCD_BUFSIZE];
475 <  char uid_buf[IRCD_BUFSIZE];
476 <  int local_len, remote_len, uid_len;
477 <  dlink_node *ptr;
478 <  dlink_node *ptr_next;
479 <  struct Client *target_p;
379 >  va_list alocal, aremote;
380 >  struct dbuf_block *local_buf, *remote_buf;
381 >  dlink_node *node = NULL, *node_next = NULL;
382  
383 <  if (IsServer(from))
384 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
385 <                           from->name, command, chptr->chname);
383 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
384 >
385 >  if (IsClient(from))
386 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
387    else
388 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
389 <                           from->name, from->username, from->host,
390 <                           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);
388 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
389 >
390 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
391  
392    va_start(alocal, pattern);
393    va_start(aremote, pattern);
394 <  va_start(auid, pattern);
395 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
396 <                           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);
394 >  send_format(local_buf, pattern, alocal);
395 >  send_format(remote_buf, pattern, aremote);
396 >
397    va_end(aremote);
398    va_end(alocal);
399  
400    ++current_serial;
401  
402 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
402 >  DLINK_FOREACH_SAFE(node, node_next, chptr->members.head)
403    {
404 <    target_p = ((struct Membership *)ptr->data)->client_p;
405 <    assert(target_p != NULL);
404 >    struct Membership *member = node->data;
405 >    struct Client *target_p = member->client_p;
406  
407 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
407 >    assert(IsClient(target_p));
408 >
409 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
410 >        (one && target_p->from == one->from))
411        continue;
412  
413 <    if (MyClient(target_p))
414 <    {
415 <      if (target_p->serial != current_serial)
416 <      {
417 <        send_message(target_p, local_buf, local_len);
418 <        target_p->serial = current_serial;
419 <      }
420 <    }
421 <    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 <    }
413 >    if (type && (member->flags & type) == 0)
414 >      continue;
415 >
416 >    if (MyConnect(target_p))
417 >      send_message(target_p, local_buf);
418 >    else if (target_p->from->connection->serial != current_serial)
419 >      send_message_remote(target_p->from, from, remote_buf);
420 >
421 >    target_p->from->connection->serial = current_serial;
422    }
423 +
424 +  dbuf_ref_free(local_buf);
425 +  dbuf_ref_free(remote_buf);
426   }
427  
428   /* sendto_server()
429 < *
429 > *
430   * inputs       - pointer to client to NOT send to
431 < *              - pointer to source client required by LL (if any)
545 < *              - pointer to channel required by LL (if any)
431 > *              - pointer to channel
432   *              - caps or'd together which must ALL be present
433   *              - caps or'd together which must ALL NOT be present
548 *              - LL flags: LL_ICLIENT | LL_ICHAN
434   *              - printf style format string
435   *              - args to format string
436   * output       - NONE
437   * side effects - Send a message to all connected servers, except the
438   *                client 'one' (if non-NULL), as long as the servers
439   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
440 < *                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 < *            
440 > *
441   * This function was written in an attempt to merge together the other
442   * billion sendto_*serv*() functions, which sprung up with capabs,
443   * lazylinks, uids, etc.
444   * -davidt
445   */
446 < void
447 < sendto_server(struct Client *one, struct Client *source_p,
448 <              struct Channel *chptr, unsigned long caps,
449 <              unsigned long nocaps, unsigned long llflags,
446 > void
447 > sendto_server(struct Client *one,
448 >              const unsigned int caps,
449 >              const unsigned int nocaps,
450                const char *format, ...)
451   {
452    va_list args;
453 <  struct Client *client_p;
454 <  dlink_node *ptr;
577 <  char buffer[IRCD_BUFSIZE];
578 <  int len;
579 <
580 <  if (chptr != NULL)
581 <  {
582 <    if (chptr->chname[0] != '#')
583 <      return;
584 <  }
453 >  dlink_node *node = NULL;
454 >  struct dbuf_block *buffer = dbuf_alloc();
455  
456    va_start(args, format);
457 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
457 >  send_format(buffer, format, args);
458    va_end(args);
459  
460 <  DLINK_FOREACH(ptr, serv_list.head)
460 >  DLINK_FOREACH(node, local_server_list.head)
461    {
462 <    client_p = ptr->data;
462 >    struct Client *client_p = node->data;
463  
464      /* If dead already skip */
465      if (IsDead(client_p))
466        continue;
467 +
468      /* check against 'one' */
469 <    if (one != NULL && (client_p == one->from))
469 >    if (one && (client_p == one->from))
470        continue;
471 +
472      /* check we have required capabs */
473 <    if ((client_p->localClient->caps & caps) != caps)
473 >    if ((client_p->connection->caps & caps) != caps)
474        continue;
475 +
476      /* check we don't have any forbidden capabs */
477 <    if ((client_p->localClient->caps & nocaps) != 0)
477 >    if ((client_p->connection->caps & nocaps))
478        continue;
479  
480 <    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);
480 >    send_message(client_p, buffer);
481    }
482 +
483 +  dbuf_ref_free(buffer);
484   }
485  
486   /* sendto_common_channels_local()
# Line 643 | Line 489 | sendto_server(struct Client *one, struct
489   *              - pattern to send
490   * output       - NONE
491   * side effects - Sends a message to all people on local server who are
492 < *                in same channel with user.
492 > *                in same channel with user.
493   *                used by m_nick.c and exit_one_client.
494   */
495   void
496 < sendto_common_channels_local(struct Client *user, int touser,
496 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
497                               const char *pattern, ...)
498   {
499    va_list args;
500    dlink_node *uptr;
501    dlink_node *cptr;
502    struct Channel *chptr;
503 <  struct Membership *ms;
503 >  struct Membership *member;
504    struct Client *target_p;
505 <  char buffer[IRCD_BUFSIZE];
660 <  int len;
505 >  struct dbuf_block *buffer = dbuf_alloc();
506  
507    va_start(args, pattern);
508 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
508 >  send_format(buffer, pattern, args);
509    va_end(args);
510  
511    ++current_serial;
512  
513    DLINK_FOREACH(cptr, user->channel.head)
514    {
515 <    chptr = ((struct Membership *) cptr->data)->chptr;
671 <    assert(chptr != NULL);
515 >    chptr = ((struct Membership *)cptr->data)->chptr;
516  
517      DLINK_FOREACH(uptr, chptr->locmembers.head)
518      {
519 <      ms = uptr->data;
520 <      target_p = ms->client_p;
677 <      assert(target_p != NULL);
519 >      member = uptr->data;
520 >      target_p = member->client_p;
521  
522        if (target_p == user || IsDefunct(target_p) ||
523 <          target_p->serial == current_serial)
523 >          target_p->connection->serial == current_serial)
524          continue;
525  
526 <      target_p->serial = current_serial;
527 <      send_message(target_p, buffer, len);
526 >      if (HasCap(target_p, cap) != cap)
527 >        continue;
528 >
529 >      target_p->connection->serial = current_serial;
530 >      send_message(target_p, buffer);
531      }
532    }
533  
534    if (touser && MyConnect(user) && !IsDead(user) &&
535 <      user->serial != current_serial)
536 <    send_message(user, buffer, len);
535 >      user->connection->serial != current_serial)
536 >    if (HasCap(user, cap) == cap)
537 >      send_message(user, buffer);
538 >
539 >  dbuf_ref_free(buffer);
540   }
541  
542   /* sendto_channel_local()
543   *
544   * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
696 *              - whether to ignore +D clients (YES/NO)
545   *              - pointer to channel to send to
546   *              - var args pattern
547   * output       - NONE
# Line 701 | Line 549 | sendto_common_channels_local(struct Clie
549   *                locally connected to this server.
550   */
551   void
552 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
552 > sendto_channel_local(unsigned int type, struct Channel *chptr,
553                       const char *pattern, ...)
554   {
555    va_list args;
556 <  char buffer[IRCD_BUFSIZE];
557 <  int len;
710 <  dlink_node *ptr;
711 <  struct Membership *ms;
712 <  struct Client *target_p;
556 >  dlink_node *node = NULL;
557 >  struct dbuf_block *buffer = dbuf_alloc();
558  
559    va_start(args, pattern);
560 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
560 >  send_format(buffer, pattern, args);
561    va_end(args);
562  
563 <  DLINK_FOREACH(ptr, chptr->locmembers.head)
563 >  DLINK_FOREACH(node, chptr->locmembers.head)
564    {
565 <    ms = ptr->data;
566 <    target_p = ms->client_p;
565 >    struct Membership *member = node->data;
566 >    struct Client *target_p = member->client_p;
567  
568 <    if (type != 0 && (ms->flags & type) == 0)
568 >    if (type && (member->flags & type) == 0)
569        continue;
570  
571 <    if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
571 >    if (IsDefunct(target_p))
572        continue;
573  
574 <    send_message(target_p, buffer, len);
574 >    send_message(target_p, buffer);
575    }
576 +
577 +  dbuf_ref_free(buffer);
578   }
579  
580   /* sendto_channel_local_butone()
# Line 742 | Line 589 | sendto_channel_local(int type, int nodea
589   *
590   * WARNING - +D clients are omitted
591   */
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 */
592   void
593 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
594 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
593 > sendto_channel_local_butone(struct Client *one, unsigned int poscap, unsigned int negcap,
594 >                            struct Channel *chptr, const char *pattern, ...)
595   {
596    va_list args;
597 <  char buffer[IRCD_BUFSIZE];
598 <  int len;
793 <  dlink_node *ptr;
794 <  struct Client *target_p;
795 <  struct Membership *ms;
597 >  dlink_node *node = NULL;
598 >  struct dbuf_block *buffer = dbuf_alloc();
599  
600    va_start(args, pattern);
601 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
601 >  send_format(buffer, pattern, args);
602    va_end(args);
603  
604 <  ++current_serial;
802 <
803 <  DLINK_FOREACH(ptr, chptr->members.head)
604 >  DLINK_FOREACH(node, chptr->locmembers.head)
605    {
606 <    ms = ptr->data;
607 <    target_p = ms->client_p;
606 >    struct Membership *member = node->data;
607 >    struct Client *target_p = member->client_p;
608  
609 <    if (type != 0 && (ms->flags & type) == 0)
609 >    if (one && target_p == one->from)
610        continue;
611  
612 <    if (MyConnect(target_p))
612 >    if (IsDefunct(target_p))
613        continue;
813    target_p = target_p->from;
614  
615 <    if (target_p == one->from ||
816 <        ((target_p->from->localClient->caps & caps) != caps) ||
817 <        ((target_p->from->localClient->caps & nocaps) != 0))
615 >    if (poscap && HasCap(target_p, poscap) != poscap)
616        continue;
617 <    if (target_p->from->serial != current_serial)
618 <    {
619 <      send_message(target_p, buffer, len);
620 <      target_p->from->serial = current_serial;
621 <    }
622 <  }
617 >
618 >    if (negcap && HasCap(target_p, negcap))
619 >      continue;
620 >
621 >    send_message(target_p, buffer);
622 >  }
623 >
624 >  dbuf_ref_free(buffer);
625   }
626  
627   /*
# Line 842 | Line 642 | sendto_channel_remote(struct Client *one
642   * side effects - NONE
643   */
644   static int
645 < match_it(const struct Client *one, const char *mask, int what)
645 > match_it(const struct Client *one, const char *mask, unsigned int what)
646   {
647    if (what == MATCH_HOST)
648 <    return(match(mask, one->host));
648 >    return !match(mask, one->host);
649  
650 <  return(match(mask, one->servptr->name));
650 >  return !match(mask, one->servptr->name);
651   }
652  
653   /* sendto_match_butone()
# Line 858 | Line 658 | match_it(const struct Client *one, const
658   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
659   */
660   void
661 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
661 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
662                      int what, const char *pattern, ...)
663   {
664    va_list alocal, aremote;
665 <  struct Client *client_p;
666 <  dlink_node *ptr, *ptr_next;
667 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
668 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
669 <                             from->username, from->host);
670 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
665 >  dlink_node *node = NULL, *node_next = NULL;
666 >  struct dbuf_block *local_buf, *remote_buf;
667 >
668 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
669 >
670 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
671 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
672  
673    va_start(alocal, pattern);
674    va_start(aremote, pattern);
675 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
676 <                           pattern, alocal);
876 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
877 <                            pattern, aremote);
675 >  send_format(local_buf, pattern, alocal);
676 >  send_format(remote_buf, pattern, aremote);
677    va_end(aremote);
678    va_end(alocal);
679  
680    /* scan the local clients */
681 <  DLINK_FOREACH(ptr, local_client_list.head)
681 >  DLINK_FOREACH(node, local_client_list.head)
682    {
683 <    client_p = ptr->data;
683 >    struct Client *client_p = node->data;
684  
685 <    if (client_p != one && !IsDefunct(client_p) &&
685 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
686          match_it(client_p, mask, what))
687 <      send_message(client_p, local_buf, local_len);
687 >      send_message(client_p, local_buf);
688    }
689  
690    /* Now scan servers */
691 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
691 >  DLINK_FOREACH_SAFE(node, node_next, local_server_list.head)
692    {
693 <    client_p = ptr->data;
693 >    struct Client *client_p = node->data;
694  
695      /*
696       * The old code looped through every client on the
# Line 917 | Line 716 | sendto_match_butone(struct Client *one,
716       * server deal with it.
717       * -wnder
718       */
719 <    if (client_p != one && !IsDefunct(client_p))
720 <      send_message_remote(client_p, from, remote_buf, remote_len);
719 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
720 >      send_message_remote(client_p, from, remote_buf);
721    }
722 +
723 +  dbuf_ref_free(local_buf);
724 +  dbuf_ref_free(remote_buf);
725   }
726  
727   /* sendto_match_servs()
# Line 932 | Line 734 | sendto_match_butone(struct Client *one,
734   * side effects - data sent to servers matching with capab
735   */
736   void
737 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
737 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
738                     const char *pattern, ...)
739   {
740    va_list args;
741 <  struct Client *target_p;
742 <  dlink_node *ptr;
941 <  char buffer[IRCD_BUFSIZE];
942 <  int found = 0;
741 >  dlink_node *node = NULL, *node_next = NULL;
742 >  struct dbuf_block *buffer = dbuf_alloc();
743  
744 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
745    va_start(args, pattern);
746 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
746 >  send_format(buffer, pattern, args);
747    va_end(args);
748  
749 <  current_serial++;
749 >  ++current_serial;
750  
751 <  DLINK_FOREACH(ptr, global_serv_list.head)
751 >  DLINK_FOREACH_SAFE(node, node_next, global_server_list.head)
752    {
753 <    target_p = ptr->data;
753 >    struct Client *target_p = node->data;
754  
755      /* Do not attempt to send to ourselves, or the source */
756      if (IsMe(target_p) || target_p->from == source_p->from)
757        continue;
758  
759 <    if (target_p->from->serial == current_serial)
759 >    if (target_p->from->connection->serial == current_serial)
760        continue;
761  
762      if (match(mask, target_p->name))
763 <    {
963 <      /*
964 <       * if we set the serial here, then we'll never do a
965 <       * match() again, if !IsCapable()
966 <       */
967 <      target_p->from->serial = current_serial;
968 <      found++;
763 >      continue;
764  
765 <      if (!IsCapable(target_p->from, cap))
766 <        continue;
765 >    /*
766 >     * If we set the serial here, then we'll never do a
767 >     * match() again, if !IsCapable()
768 >     */
769 >    target_p->from->connection->serial = current_serial;
770  
771 <      sendto_anywhere(target_p, source_p, "%s", buffer);
772 <    }
771 >    if (!IsCapable(target_p->from, cap))
772 >      continue;
773 >
774 >    send_message_remote(target_p->from, source_p, buffer);
775    }
776 +
777 +  dbuf_ref_free(buffer);
778   }
779  
780   /* sendto_anywhere()
# Line 986 | Line 788 | sendto_match_servs(struct Client *source
788   */
789   void
790   sendto_anywhere(struct Client *to, struct Client *from,
791 +                const char *command,
792                  const char *pattern, ...)
793   {
794    va_list args;
795 <  char buffer[IRCD_BUFSIZE];
993 <  int len;
994 <  struct Client *send_to = (to->from != NULL ? to->from : to);
795 >  struct dbuf_block *buffer = NULL;
796  
797 <  if (IsDead(send_to))
797 >  if (IsDead(to->from))
798      return;
799  
800 <  if (MyClient(to))
801 <  {
802 <    if (IsServer(from))
803 <    {
804 <      if (IsCapable(to, CAP_TS6) && HasID(from))
805 <        len = ircsprintf(buffer, ":%s ", from->id);
806 <      else
807 <        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));
800 >  buffer = dbuf_alloc();
801 >
802 >  if (MyClient(to) && IsClient(from))
803 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
804 >                 from->host, command, to->name);
805 >  else
806 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
807 >                 command, ID_or_name(to, to));
808  
809    va_start(args, pattern);
810 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
810 >  send_format(buffer, pattern, args);
811    va_end(args);
812  
813 <  if(MyClient(to))
814 <    send_message(send_to, buffer, len);
813 >  if (MyConnect(to))
814 >    send_message(to, buffer);
815    else
816 <    send_message_remote(send_to, from, buffer, len);
816 >    send_message_remote(to->from, from, buffer);
817 >
818 >  dbuf_ref_free(buffer);
819   }
820  
821   /* sendto_realops_flags()
# Line 1030 | Line 827 | sendto_anywhere(struct Client *to, struc
827   * side effects - Send to *local* ops only but NOT +s nonopers.
828   */
829   void
830 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
830 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
831   {
832 <  struct Client *client_p;
833 <  char nbuf[IRCD_BUFSIZE];
834 <  dlink_node *ptr;
832 >  const char *ntype = NULL;
833 >  dlink_node *node = NULL;
834 >  char nbuf[IRCD_BUFSIZE] = "";
835    va_list args;
836  
837    va_start(args, pattern);
838 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
838 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
839    va_end(args);
840  
841 <  DLINK_FOREACH(ptr, oper_list.head)
841 >  switch (type)
842    {
843 <    client_p = ptr->data;
844 <    assert(client_p->umodes & UMODE_OPER);
845 <
846 <    /* If we're sending it to opers and theyre an admin, skip.
847 <     * If we're sending it to admins, and theyre not, skip.
848 <     */
849 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
850 <        ((level == L_OPER) && IsAdmin(client_p)))
851 <      continue;
852 <
853 <    if (client_p->umodes & flags)
1057 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1058 <                 me.name, client_p->name, nbuf);
843 >    case SEND_NOTICE:
844 >      ntype = "Notice";
845 >      break;
846 >    case SEND_GLOBAL:
847 >      ntype = "Global";
848 >      break;
849 >    case SEND_LOCOPS:
850 >      ntype = "LocOps";
851 >      break;
852 >    default:
853 >      assert(0);
854    }
1060 }
855  
856 < /* 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);
1089 <
1090 <  DLINK_FOREACH(ptr, oper_list.head)
856 >  DLINK_FOREACH(node, oper_list.head)
857    {
858 <    client_p = ptr->data;
859 <    assert(client_p->umodes & UMODE_OPER);
1094 <
1095 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
1096 <      send_message(client_p, buffer, len);
1097 <  }
1098 < }
1099 <
1100 < /* ts_warn()
1101 < *
1102 < * inputs       - var args message
1103 < * output       - NONE
1104 < * side effects - Call sendto_realops_flags, with some flood checking
1105 < *                (at most 5 warnings every 5 seconds)
1106 < */
1107 < void
1108 < ts_warn(const char *pattern, ...)
1109 < {
1110 <  va_list args;
1111 <  char buffer[LOG_BUFSIZE];
1112 <  static time_t last = 0;
1113 <  static int warnings = 0;
858 >    struct Client *client_p = node->data;
859 >    assert(HasUMode(client_p, UMODE_OPER));
860  
861 <  /*
862 <   ** if we're running with TS_WARNINGS enabled and someone does
863 <   ** something silly like (remotely) connecting a nonTS server,
864 <   ** we'll get a ton of warnings, so we make sure we don't send
865 <   ** more than 5 every 5 seconds.  -orabidoo
866 <   */
861 >    /*
862 >     * If we're sending it to opers and they're an admin, skip.
863 >     * If we're sending it to admins, and they're not, skip.
864 >     */
865 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
866 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
867 >      continue;
868  
869 <  if (CurrentTime - last < 5)
870 <  {
871 <    if (++warnings > 5)
1125 <      return;
1126 <  }
1127 <  else
1128 <  {
1129 <    last = CurrentTime;
1130 <    warnings = 0;
869 >    if (HasUMode(client_p, flags))
870 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
871 >                 me.name, client_p->name, ntype, nbuf);
872    }
1132
1133  va_start(args, pattern);
1134  vsprintf_irc(buffer, pattern, args);
1135  va_end(args);
1136
1137  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1138  ilog(L_CRIT, "%s", buffer);
873   }
874  
875 < /* kill_client()
875 > /* ts_warn()
876   *
877 < * inputs       - client to send kill towards
878 < *              - pointer to client to kill
879 < *              - reason for kill
880 < * output       - NONE
1147 < * side effects - NONE
877 > * inputs       - var args message
878 > * output       - NONE
879 > * side effects - Call sendto_realops_flags, with some flood checking
880 > *                (at most 5 warnings every 5 seconds)
881   */
882   void
883 < kill_client(struct Client *client_p, struct Client *diedie,
1151 <            const char *pattern, ...)
883 > sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
884   {
885    va_list args;
886 <  char buffer[IRCD_BUFSIZE];
1155 <  int len;
886 >  char buffer[IRCD_BUFSIZE] = "";
887  
888 <  if (client_p->from != NULL)
1158 <    client_p = client_p->from;
1159 <  if (IsDead(client_p))
888 >  if ((CurrentTime - *rate) < 20)
889      return;
890  
891 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1163 <                   ID_or_name(diedie, client_p));
891 >  *rate = CurrentTime;
892  
893    va_start(args, pattern);
894 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
894 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
895    va_end(args);
896  
897 <  send_message(client_p, buffer, len);
897 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
898 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
899   }
900  
901 < /* kill_client_ll_serv_butone()
901 > /* sendto_wallops_flags()
902   *
903 < * inputs       - pointer to client to not send to
904 < *              - pointer to client to kill
905 < * output       - NONE
906 < * side effects - Send a KILL for the given client
907 < *                message to all connected servers
1179 < *                except the client 'one'. Also deal with
1180 < *                client being unknown to leaf, as in lazylink...
903 > * inputs       - flag types of messages to show to real opers
904 > *              - client sending request
905 > *              - var args input message
906 > * output       - NONE
907 > * side effects - Send a wallops to local opers
908   */
909   void
910 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
911 <                           const char *pattern, ...)
910 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
911 >                     const char *pattern, ...)
912   {
913 +  dlink_node *node = NULL;
914    va_list args;
915 <  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;
915 >  struct dbuf_block *buffer = dbuf_alloc();
916  
917 <  if (HasID(source_p) && (me.id[0] != '\0'))
918 <  {
919 <    have_uid = 1;
920 <    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 <  }
917 >  if (IsClient(source_p))
918 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
919 >  else
920 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
921  
922    va_start(args, pattern);
923 <  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);
923 >  send_format(buffer, pattern, args);
924    va_end(args);
925  
926 <  DLINK_FOREACH(ptr, serv_list.head)
926 >  DLINK_FOREACH(node, oper_list.head)
927    {
928 <    client_p = ptr->data;
929 <
1213 <    if (one != NULL && (client_p == one->from))
1214 <      continue;
1215 <    if (IsDefunct(client_p))
1216 <      continue;
928 >    struct Client *client_p = node->data;
929 >    assert(client_p->umodes & UMODE_OPER);
930  
931 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
932 <    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 <    }
931 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
932 >      send_message(client_p, buffer);
933    }
934 < }
934 >
935 >  dbuf_ref_free(buffer);
936 > }

Diff Legend

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