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.3/src/send.c (file contents), Revision 1086 by michael, Sat Mar 13 23:59:10 2010 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 4890 by michael, Wed Nov 19 17:10:46 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"
# Line 27 | Line 29
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 "s_log.h"
38 > #include "server.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "memory.h"
43 #include "hook.h"
44 #include "irc_getnameinfo.h"
42   #include "packet.h"
43  
44  
45 < struct Callback *iosend_cb = NULL;
49 < struct Callback *iosendctrl_cb = NULL;
50 < static unsigned int current_serial = 0;
45 > static uint64_t current_serial;
46  
47  
48   /* send_format()
49   *
50 < * inputs       - buffer to format into
51 < *              - size of the buffer
50 > * inputs
51 > *              - buffer
52   *              - format pattern to use
53   *              - var args
54   * output       - number of bytes formatted output
55   * side effects - modifies sendbuf
56   */
57 < static inline int
58 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
57 > static void
58 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
59   {
65  int len;
66
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);
80 <  if (len > bufsize - 2)
81 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
82 <
83 <  lsendbuf[len++] = '\r';
84 <  lsendbuf[len++] = '\n';
85 <  return len;
86 < }
72 >  dbuf_put_args(buffer, pattern, args);
73  
74 < /*
75 < * iosend_default - append a packet to the client's sendq.
90 < */
91 < void *
92 < iosend_default(va_list args)
93 < {
94 <  struct Client *to = va_arg(args, struct Client *);
95 <  int length = va_arg(args, int);
96 <  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 105 | 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) >
138 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
139 <    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
147 < *              - 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,
155 <                    char *buf, int len)
133 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
134   {
135 <  if (!MyConnect(to))
158 <  {
159 <    sendto_realops_flags(UMODE_ALL, L_ALL,
160 <                         "server send message to %s [%s] dropped from %s(Not local server)",
161 <                         to->name, to->from->name, from->name);
162 <    return;
163 <  }
135 >  assert(MyConnect(to));
136  
137    /* Optimize by checking if (from && to) before everything */
138    /* we set to->from up there.. */
# Line 169 | Line 141 | send_message_remote(struct Client *to, s
141    {
142      if (IsServer(from))
143      {
144 <      sendto_realops_flags(UMODE_ALL, L_ALL,
144 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
145                             "Send message to %s [%s] dropped from %s(Fake Dir)",
146                             to->name, to->from->name, from->name);
147        return;
148      }
149  
150 <    sendto_realops_flags(UMODE_ALL, L_ALL,
150 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
151                           "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
152                           to->name, to->username, to->host,
153                           from->name, from->username, from->host,
154                           to->from->name);
155  
156 <    sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
185 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
186 <                  me.id, to->name, me.name, to->name,
187 <                  to->username, to->host, to->from->name);
188 <    sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
156 >    sendto_server(NULL, NOCAPS, NOCAPS,
157                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
158 <                  me.name, to->name, me.name, to->name,
158 >                  me.id, to->id, me.name, to->name,
159                    to->username, to->host, to->from->name);
160  
161 <    SetKilled(to);
161 >    AddFlag(to, FLAGS_KILLED);
162  
163      if (IsClient(from))
164 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
165 <                 me.name, from->name, to->name, to->username,
198 <                 to->host, to->from);
199 <
200 <    exit_client(to, &me, "Ghosted client");
164 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
165 >                         to->username, to->host, to->from);
166  
167 +    exit_client(to, "Ghosted client");
168      return;
169 <  }
169 >  }
170  
171 <  send_message(to, buf, len);
171 >  send_message(to, buf);
172   }
173  
174   /*
# Line 210 | Line 176 | send_message_remote(struct Client *to, s
176   **      Called when a socket is ready for writing.
177   */
178   void
179 < sendq_unblocked(fde_t *fd, struct Client *client_p)
179 > sendq_unblocked(fde_t *fd, void *data)
180   {
181 <  ClearSendqBlocked(client_p);
182 <  /* let send_queued_write be executed by send_queued_all */
217 <
218 < #ifdef HAVE_LIBCRYPTO
219 <  if (fd->flags.pending_read)
220 <  {
221 <    fd->flags.pending_read = 0;
222 <    read_packet(fd, client_p);
223 <  }
224 < #endif
225 < }
181 >  struct Client *client_p = data;
182 >  assert(fd == &client_p->connection->fd);
183  
184 < /*
185 < ** slinkq_unblocked
229 < **      Called when a server control socket is ready for writing.
230 < */
231 < static void
232 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
233 < {
234 <  ClearSlinkqBlocked(client_p);
235 <  send_queued_slink_write(client_p);
184 >  DelFlag(client_p, FLAGS_BLOCKED);
185 >  send_queued_write(client_p);
186   }
187  
188   /*
# Line 244 | Line 194 | slinkq_unblocked(fde_t *fd, struct Clien
194   void
195   send_queued_write(struct Client *to)
196   {
197 <  int retlen;
248 <  struct dbuf_block *first;
197 >  int retlen = 0;
198  
199    /*
200     ** Once socket is marked dead, we cannot start writing to it,
201     ** even if the error is removed...
202     */
203 <  if (IsDead(to) || IsSendqBlocked(to))
203 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
204      return;  /* no use calling send() now */
205  
206    /* Next, lets try to write some data */
207 <
259 <  if (dbuf_length(&to->localClient->buf_sendq))
207 >  if (dbuf_length(&to->connection->buf_sendq))
208    {
209 <    do {
210 <      first = to->localClient->buf_sendq.blocks.head->data;
209 >    do
210 >    {
211 >      struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
212  
213   #ifdef HAVE_LIBCRYPTO
214 <      if (to->localClient->fd.ssl)
214 >      if (to->connection->fd.ssl)
215        {
216 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
216 >        retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos);
217  
218          /* translate openssl error codes, sigh */
219 <        if (retlen < 0)
220 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
221 <          {
219 >        if (retlen < 0)
220 >        {
221 >          switch (SSL_get_error(to->connection->fd.ssl, retlen))
222 >          {
223              case SSL_ERROR_WANT_READ:
224 <              return;  /* retry later, don't register for write events */
225 <
226 <            case SSL_ERROR_WANT_WRITE:
277 <              errno = EWOULDBLOCK;
224 >              return;  /* retry later, don't register for write events */
225 >            case SSL_ERROR_WANT_WRITE:
226 >              errno = EWOULDBLOCK;
227              case SSL_ERROR_SYSCALL:
228 <              break;
228 >              break;
229              case SSL_ERROR_SSL:
230                if (errno == EAGAIN)
231                  break;
232              default:
233 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
234 <          }
233 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
234 >          }
235 >        }
236        }
237        else
238   #endif
239 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
239 >        retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
240  
241        if (retlen <= 0)
242          break;
243  
244 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
244 >      dbuf_delete(&to->connection->buf_sendq, retlen);
245  
246        /* We have some data written .. update counters */
247 <      to->localClient->send.bytes += retlen;
248 <      me.localClient->send.bytes += retlen;
249 <    } while (dbuf_length(&to->localClient->buf_sendq));
247 >      to->connection->send.bytes += retlen;
248 >      me.connection->send.bytes += retlen;
249 >    } while (dbuf_length(&to->connection->buf_sendq));
250  
251 <    if ((retlen < 0) && (ignoreErrno(errno)))
251 >    if (retlen < 0 && ignoreErrno(errno))
252      {
253 +      AddFlag(to, FLAGS_BLOCKED);
254 +
255        /* we have a non-fatal error, reschedule a write */
256 <      SetSendqBlocked(to);
257 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
306 <                     (PF *)sendq_unblocked, (void *)to, 0);
256 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
257 >                     sendq_unblocked, to, 0);
258      }
259      else if (retlen <= 0)
260      {
# Line 313 | Line 264 | send_queued_write(struct Client *to)
264    }
265   }
266  
316 /*
317 ** send_queued_slink_write
318 **      This is called when there is a chance the some output would
319 **      be possible. This attempts to empty the send queue as far as
320 **      possible, and then if any data is left, a write is rescheduled.
321 */
322 void
323 send_queued_slink_write(struct Client *to)
324 {
325  int retlen;
326
327  /*
328   ** Once socket is marked dead, we cannot start writing to it,
329   ** even if the error is removed...
330   */
331  if (IsDead(to) || IsSlinkqBlocked(to))
332    return;  /* no use calling send() now */
333
334  /* Next, lets try to write some data */
335  if (to->localClient->slinkq != NULL)
336  {
337    retlen = send(to->localClient->ctrlfd.fd,
338                   to->localClient->slinkq + to->localClient->slinkq_ofs,
339                   to->localClient->slinkq_len, 0);
340    if (retlen < 0)
341    {
342      /* If we have a fatal error */
343      if (!ignoreErrno(errno))
344      {
345        dead_link_on_write(to, errno);
346        return;
347      }
348    }
349    else if (retlen == 0)
350    {
351      /* 0 bytes is an EOF .. */
352      dead_link_on_write(to, 0);
353      return;
354    }
355    else
356    {
357      execute_callback(iosendctrl_cb, to, retlen,
358        to->localClient->slinkq + to->localClient->slinkq_ofs);
359      to->localClient->slinkq_len -= retlen;
360
361      assert(to->localClient->slinkq_len >= 0);
362      if (to->localClient->slinkq_len)
363        to->localClient->slinkq_ofs += retlen;
364      else
365      {
366        to->localClient->slinkq_ofs = 0;
367        MyFree(to->localClient->slinkq);
368        to->localClient->slinkq = NULL;
369      }
370    }
371
372    /* Finally, if we have any more data, reschedule a write */
373    if (to->localClient->slinkq_len)
374    {
375      SetSlinkqBlocked(to);
376      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
377                     (PF *)slinkq_unblocked, (void *)to, 0);
378    }
379  }
380 }
381
267   /* send_queued_all()
268   *
269   * input        - NONE
# Line 388 | Line 273 | send_queued_slink_write(struct Client *t
273   void
274   send_queued_all(void)
275   {
276 <  dlink_node *ptr;
276 >  dlink_node *node = NULL;
277  
278    /* Servers are processed first, mainly because this can generate
279     * a notice to opers, which is to be delivered by this function.
280     */
281 <  DLINK_FOREACH(ptr, serv_list.head)
282 <    send_queued_write((struct Client *) ptr->data);
281 >  DLINK_FOREACH(node, local_server_list.head)
282 >    send_queued_write(node->data);
283  
284 <  DLINK_FOREACH(ptr, unknown_list.head)
285 <    send_queued_write((struct Client *) ptr->data);
284 >  DLINK_FOREACH(node, unknown_list.head)
285 >    send_queued_write(node->data);
286  
287 <  DLINK_FOREACH(ptr, local_client_list.head)
288 <    send_queued_write((struct Client *) ptr->data);
287 >  DLINK_FOREACH(node, local_client_list.head)
288 >    send_queued_write(node->data);
289  
290    /* NOTE: This can still put clients on aborted_list; unfortunately,
291     * exit_aborted_clients takes precedence over send_queued_all,
# Line 421 | Line 306 | void
306   sendto_one(struct Client *to, const char *pattern, ...)
307   {
308    va_list args;
309 <  char buffer[IRCD_BUFSIZE];
425 <  int len;
309 >  struct dbuf_block *buffer = NULL;
310  
311 <  if (to->from != NULL)
312 <    to = to->from;
313 <  if (IsDead(to))
314 <    return; /* This socket has already been marked as dead */
311 >  if (IsDead(to->from))
312 >    return;  /* This socket has already been marked as dead */
313 >
314 >  buffer = dbuf_alloc();
315 >
316 >  va_start(args, pattern);
317 >  send_format(buffer, pattern, args);
318 >  va_end(args);
319 >
320 >  send_message(to->from, buffer);
321 >
322 >  dbuf_ref_free(buffer);
323 > }
324 >
325 > void
326 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
327 > {
328 >  struct dbuf_block *buffer = NULL;
329 >  const char *dest = NULL, *numstr = NULL;
330 >  va_list args;
331 >
332 >  if (IsDead(to->from))
333 >    return;
334 >
335 >  dest = ID_or_name(to, to);
336 >
337 >  if (EmptyString(dest))
338 >    dest = "*";
339 >
340 >  buffer = dbuf_alloc();
341 >
342 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
343 >
344 >  va_start(args, numeric);
345 >
346 >  if (numeric & SND_EXPLICIT)
347 >    numstr = va_arg(args, const char *);
348 >  else
349 >    numstr = numeric_form(numeric);
350 >
351 >  send_format(buffer, numstr, args);
352 >  va_end(args);
353 >
354 >  send_message(to->from, buffer);
355 >
356 >  dbuf_ref_free(buffer);
357 > }
358 >
359 > void
360 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
361 > {
362 >  struct dbuf_block *buffer = NULL;
363 >  const char *dest = NULL;
364 >  va_list args;
365 >
366 >  if (IsDead(to->from))
367 >    return;
368 >
369 >  dest = ID_or_name(to, to);
370 >
371 >  if (EmptyString(dest))
372 >    dest = "*";
373 >
374 >  buffer = dbuf_alloc();
375 >
376 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
377  
378    va_start(args, pattern);
379 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
379 >  send_format(buffer, pattern, args);
380    va_end(args);
381  
382 <  send_message(to, buffer, len);
382 >  send_message(to->from, buffer);
383 >
384 >  dbuf_ref_free(buffer);
385   }
386  
387   /* sendto_channel_butone()
# Line 449 | Line 397 | sendto_one(struct Client *to, const char
397   */
398   void
399   sendto_channel_butone(struct Client *one, struct Client *from,
400 <                      struct Channel *chptr, const char *command,
400 >                      struct Channel *chptr, unsigned int type,
401                        const char *pattern, ...)
402   {
403 <  va_list alocal, aremote, auid;
404 <  char local_buf[IRCD_BUFSIZE];
405 <  char remote_buf[IRCD_BUFSIZE];
406 <  char uid_buf[IRCD_BUFSIZE];
407 <  int local_len, remote_len, uid_len;
408 <  dlink_node *ptr = NULL, *ptr_next = NULL;
409 <
410 <  if (IsServer(from))
463 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
464 <                           from->name, command, chptr->chname);
403 >  va_list alocal, aremote;
404 >  struct dbuf_block *local_buf, *remote_buf;
405 >  dlink_node *node = NULL, *node_next = NULL;
406 >
407 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
408 >
409 >  if (IsClient(from))
410 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
411    else
412 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
413 <                           from->name, from->username, from->host,
414 <                           command, chptr->chname);
469 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
470 <                          from->name, command, chptr->chname);
471 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
472 <                       ID(from), command, chptr->chname);
412 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
413 >
414 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
415  
416    va_start(alocal, pattern);
417    va_start(aremote, pattern);
418 <  va_start(auid, pattern);
419 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
420 <                           pattern, alocal);
479 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
480 <                            pattern, aremote);
481 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
482 <                         auid);
483 <  va_end(auid);
418 >  send_format(local_buf, pattern, alocal);
419 >  send_format(remote_buf, pattern, aremote);
420 >
421    va_end(aremote);
422    va_end(alocal);
423  
424    ++current_serial;
425  
426 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
426 >  DLINK_FOREACH_SAFE(node, node_next, chptr->members.head)
427    {
428 <    struct Client *target_p = ((struct Membership *)ptr->data)->client_p;
428 >    struct Membership *member = node->data;
429 >    struct Client *target_p = member->client_p;
430  
431      assert(IsClient(target_p));
432  
433 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
433 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
434 >        (one && target_p->from == one->from))
435 >      continue;
436 >
437 >    if (type && (member->flags & type) == 0)
438        continue;
439  
440      if (MyConnect(target_p))
441 <    {
442 <      if (target_p->localClient->serial != current_serial)
443 <      {
444 <        send_message(target_p, local_buf, local_len);
445 <        target_p->localClient->serial = current_serial;
504 <      }
505 <    }
506 <    else
507 <    {
508 <      /* Now check whether a message has been sent to this
509 <       * remote link already
510 <       */
511 <      if (target_p->from->localClient->serial != current_serial)
512 <      {
513 <        if (IsCapable(target_p->from, CAP_TS6))
514 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
515 <        else
516 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
517 <        target_p->from->localClient->serial = current_serial;
518 <      }
519 <    }
441 >      send_message(target_p, local_buf);
442 >    else if (target_p->from->connection->serial != current_serial)
443 >      send_message_remote(target_p->from, from, remote_buf);
444 >
445 >    target_p->from->connection->serial = current_serial;
446    }
447 +
448 +  dbuf_ref_free(local_buf);
449 +  dbuf_ref_free(remote_buf);
450   }
451  
452   /* sendto_server()
453 < *
453 > *
454   * inputs       - pointer to client to NOT send to
455   *              - pointer to channel
456   *              - caps or'd together which must ALL be present
# Line 532 | Line 461 | sendto_channel_butone(struct Client *one
461   * side effects - Send a message to all connected servers, except the
462   *                client 'one' (if non-NULL), as long as the servers
463   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
464 < *            
464 > *
465   * This function was written in an attempt to merge together the other
466   * billion sendto_*serv*() functions, which sprung up with capabs,
467   * lazylinks, uids, etc.
468   * -davidt
469   */
470 < void
471 < sendto_server(struct Client *one, const struct Channel *chptr,
470 > void
471 > sendto_server(struct Client *one,
472                const unsigned int caps,
473                const unsigned int nocaps,
474                const char *format, ...)
475   {
476    va_list args;
477 <  dlink_node *ptr = NULL;
478 <  char buffer[IRCD_BUFSIZE];
550 <  int len = 0;
551 <
552 <  if (chptr && chptr->chname[0] != '#')
553 <    return;
477 >  dlink_node *node = NULL;
478 >  struct dbuf_block *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)
484 >  DLINK_FOREACH(node, local_server_list.head)
485    {
486 <    struct Client *client_p = ptr->data;
486 >    struct Client *client_p = node->data;
487  
488      /* If dead already skip */
489      if (IsDead(client_p))
490        continue;
491 +
492      /* check against 'one' */
493 <    if (one != NULL && (client_p == one->from))
493 >    if (one && (client_p == one->from))
494        continue;
495 +
496      /* check we have required capabs */
497 <    if ((client_p->localClient->caps & caps) != caps)
497 >    if ((client_p->connection->caps & caps) != caps)
498        continue;
499 +
500      /* check we don't have any forbidden capabs */
501 <    if ((client_p->localClient->caps & nocaps) != 0)
501 >    if ((client_p->connection->caps & nocaps))
502        continue;
503  
504 <    send_message(client_p, buffer, len);
504 >    send_message(client_p, buffer);
505    }
506 +
507 +  dbuf_ref_free(buffer);
508   }
509  
510   /* sendto_common_channels_local()
# Line 583 | Line 513 | sendto_server(struct Client *one, const
513   *              - pattern to send
514   * output       - NONE
515   * side effects - Sends a message to all people on local server who are
516 < *                in same channel with user.
516 > *                in same channel with user.
517   *                used by m_nick.c and exit_one_client.
518   */
519   void
520 < sendto_common_channels_local(struct Client *user, int touser,
520 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
521                               const char *pattern, ...)
522   {
523    va_list args;
524    dlink_node *uptr;
525    dlink_node *cptr;
526    struct Channel *chptr;
527 <  struct Membership *ms;
527 >  struct Membership *member;
528    struct Client *target_p;
529 <  char buffer[IRCD_BUFSIZE];
600 <  int len;
529 >  struct dbuf_block *buffer = dbuf_alloc();
530  
531    va_start(args, pattern);
532 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
532 >  send_format(buffer, pattern, args);
533    va_end(args);
534  
535    ++current_serial;
536  
537    DLINK_FOREACH(cptr, user->channel.head)
538    {
539 <    chptr = ((struct Membership *) cptr->data)->chptr;
611 <    assert(chptr != NULL);
539 >    chptr = ((struct Membership *)cptr->data)->chptr;
540  
541 <    DLINK_FOREACH(uptr, chptr->members.head)
541 >    DLINK_FOREACH(uptr, chptr->locmembers.head)
542      {
543 <      ms = uptr->data;
544 <      target_p = ms->client_p;
617 <      assert(target_p != NULL);
543 >      member = uptr->data;
544 >      target_p = member->client_p;
545  
546 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
547 <          target_p->localClient->serial == current_serial)
546 >      if (target_p == user || IsDefunct(target_p) ||
547 >          target_p->connection->serial == current_serial)
548          continue;
549  
550 <      target_p->localClient->serial = current_serial;
551 <      send_message(target_p, buffer, len);
550 >      if (HasCap(target_p, cap) != cap)
551 >        continue;
552 >
553 >      target_p->connection->serial = current_serial;
554 >      send_message(target_p, buffer);
555      }
556    }
557  
558    if (touser && MyConnect(user) && !IsDead(user) &&
559 <      user->localClient->serial != current_serial)
560 <    send_message(user, buffer, len);
559 >      user->connection->serial != current_serial)
560 >    if (HasCap(user, cap) == cap)
561 >      send_message(user, buffer);
562 >
563 >  dbuf_ref_free(buffer);
564   }
565  
566   /* sendto_channel_local()
567   *
568   * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
636 *              - whether to ignore +D clients (YES/NO)
569   *              - pointer to channel to send to
570   *              - var args pattern
571   * output       - NONE
# Line 641 | 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, struct Channel *chptr,
577                       const char *pattern, ...)
578   {
579    va_list args;
580 <  char buffer[IRCD_BUFSIZE];
581 <  int len;
650 <  dlink_node *ptr;
651 <  struct Membership *ms;
652 <  struct Client *target_p;
580 >  dlink_node *node = NULL;
581 >  struct dbuf_block *buffer = dbuf_alloc();
582  
583    va_start(args, pattern);
584 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
584 >  send_format(buffer, pattern, args);
585    va_end(args);
586  
587 <  DLINK_FOREACH(ptr, chptr->members.head)
587 >  DLINK_FOREACH(node, chptr->locmembers.head)
588    {
589 <    ms = ptr->data;
590 <    target_p = ms->client_p;
589 >    struct Membership *member = node->data;
590 >    struct Client *target_p = member->client_p;
591  
592 <    if (type != 0 && (ms->flags & type) == 0)
592 >    if (type && (member->flags & type) == 0)
593        continue;
594  
595 <    if (!MyConnect(target_p) || IsDefunct(target_p) ||
667 <        (nodeaf && IsDeaf(target_p)))
595 >    if (IsDefunct(target_p))
596        continue;
597  
598 <    send_message(target_p, buffer, len);
598 >    send_message(target_p, buffer);
599    }
600 +
601 +  dbuf_ref_free(buffer);
602   }
603  
604   /* sendto_channel_local_butone()
# Line 683 | Line 613 | sendto_channel_local(int type, int nodea
613   *
614   * WARNING - +D clients are omitted
615   */
686 void      
687 sendto_channel_local_butone(struct Client *one, int type,
688                            struct Channel *chptr, const char *pattern, ...)
689 {
690  va_list args;
691  char buffer[IRCD_BUFSIZE];
692  int len;
693  struct Client *target_p;
694  struct Membership *ms;
695  dlink_node *ptr;
696
697  va_start(args, pattern);
698  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
699  va_end(args);
700
701  DLINK_FOREACH(ptr, chptr->members.head)      
702  {  
703    ms = ptr->data;
704    target_p = ms->client_p;
705
706    if (type != 0 && (ms->flags & type) == 0)
707      continue;
708
709    if (!MyConnect(target_p) || target_p == one ||
710        IsDefunct(target_p) || IsDeaf(target_p))
711      continue;
712    send_message(target_p, buffer, len);
713  }
714 }
715
716
717 /* sendto_channel_remote()
718 *
719 * inputs       - Client not to send towards
720 *              - Client from whom message is from
721 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
722 *              - pointer to channel to send to
723 *              - var args pattern
724 * output       - NONE
725 * side effects - Send a message to all members of a channel that are
726 *                remote to this server.
727 */
616   void
617 < sendto_channel_remote(struct Client *one, struct Client *from, int type,
618 <                      const unsigned int caps, const unsigned int nocaps,
731 <                      struct Channel *chptr, const char *pattern, ...)
617 > sendto_channel_local_butone(struct Client *one, unsigned int poscap, unsigned int negcap,
618 >                            struct Channel *chptr, const char *pattern, ...)
619   {
620    va_list args;
621 <  char buffer[IRCD_BUFSIZE];
622 <  int len;
736 <  dlink_node *ptr;
737 <  struct Client *target_p;
738 <  struct Membership *ms;
621 >  dlink_node *node = NULL;
622 >  struct dbuf_block *buffer = dbuf_alloc();
623  
624    va_start(args, pattern);
625 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
625 >  send_format(buffer, pattern, args);
626    va_end(args);
627  
628 <  ++current_serial;
745 <
746 <  DLINK_FOREACH(ptr, chptr->members.head)
628 >  DLINK_FOREACH(node, chptr->locmembers.head)
629    {
630 <    ms = ptr->data;
631 <    target_p = ms->client_p;
630 >    struct Membership *member = node->data;
631 >    struct Client *target_p = member->client_p;
632  
633 <    if (type != 0 && (ms->flags & type) == 0)
633 >    if (one && target_p == one->from)
634        continue;
635  
636 <    if (MyConnect(target_p))
636 >    if (IsDefunct(target_p))
637        continue;
756    target_p = target_p->from;
638  
639 <    if (target_p == one->from ||
759 <        ((target_p->from->localClient->caps & caps) != caps) ||
760 <        ((target_p->from->localClient->caps & nocaps) != 0))
639 >    if (poscap && HasCap(target_p, poscap) != poscap)
640        continue;
641 <    if (target_p->from->localClient->serial != current_serial)
642 <    {
643 <      send_message(target_p, buffer, len);
644 <      target_p->from->localClient->serial = current_serial;
645 <    }
646 <  }
641 >
642 >    if (negcap && HasCap(target_p, negcap))
643 >      continue;
644 >
645 >    send_message(target_p, buffer);
646 >  }
647 >
648 >  dbuf_ref_free(buffer);
649   }
650  
651   /*
# Line 785 | Line 666 | sendto_channel_remote(struct Client *one
666   * side effects - NONE
667   */
668   static int
669 < match_it(const struct Client *one, const char *mask, int what)
669 > match_it(const struct Client *one, const char *mask, unsigned int what)
670   {
671    if (what == MATCH_HOST)
672 <    return match(mask, one->host);
672 >    return !match(mask, one->host);
673  
674 <  return match(mask, one->servptr->name);
674 >  return !match(mask, one->servptr->name);
675   }
676  
677   /* sendto_match_butone()
# Line 801 | Line 682 | match_it(const struct Client *one, const
682   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
683   */
684   void
685 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
685 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
686                      int what, const char *pattern, ...)
687   {
688    va_list alocal, aremote;
689 <  struct Client *client_p;
690 <  dlink_node *ptr, *ptr_next;
691 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
692 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
693 <                             from->username, from->host);
694 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
689 >  dlink_node *node = NULL, *node_next = NULL;
690 >  struct dbuf_block *local_buf, *remote_buf;
691 >
692 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
693 >
694 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
695 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
696  
697    va_start(alocal, pattern);
698    va_start(aremote, pattern);
699 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
700 <                           pattern, alocal);
819 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
820 <                            pattern, aremote);
699 >  send_format(local_buf, pattern, alocal);
700 >  send_format(remote_buf, pattern, aremote);
701    va_end(aremote);
702    va_end(alocal);
703  
704    /* scan the local clients */
705 <  DLINK_FOREACH(ptr, local_client_list.head)
705 >  DLINK_FOREACH(node, local_client_list.head)
706    {
707 <    client_p = ptr->data;
707 >    struct Client *client_p = node->data;
708  
709 <    if (client_p != one && !IsDefunct(client_p) &&
709 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
710          match_it(client_p, mask, what))
711 <      send_message(client_p, local_buf, local_len);
711 >      send_message(client_p, local_buf);
712    }
713  
714    /* Now scan servers */
715 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
715 >  DLINK_FOREACH_SAFE(node, node_next, local_server_list.head)
716    {
717 <    client_p = ptr->data;
717 >    struct Client *client_p = node->data;
718  
719      /*
720       * The old code looped through every client on the
# Line 860 | Line 740 | sendto_match_butone(struct Client *one,
740       * server deal with it.
741       * -wnder
742       */
743 <    if (client_p != one && !IsDefunct(client_p))
744 <      send_message_remote(client_p, from, remote_buf, remote_len);
743 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
744 >      send_message_remote(client_p, from, remote_buf);
745    }
746 +
747 +  dbuf_ref_free(local_buf);
748 +  dbuf_ref_free(remote_buf);
749   }
750  
751   /* sendto_match_servs()
# Line 875 | Line 758 | sendto_match_butone(struct Client *one,
758   * side effects - data sent to servers matching with capab
759   */
760   void
761 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
761 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
762                     const char *pattern, ...)
763   {
764    va_list args;
765 <  struct Client *target_p;
766 <  dlink_node *ptr;
884 <  char buffer[IRCD_BUFSIZE];
885 <  int found = 0;
765 >  dlink_node *node = NULL, *node_next = NULL;
766 >  struct dbuf_block *buffer = dbuf_alloc();
767  
768 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
769    va_start(args, pattern);
770 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
770 >  send_format(buffer, pattern, args);
771    va_end(args);
772  
773    ++current_serial;
774  
775 <  DLINK_FOREACH(ptr, global_serv_list.head)
775 >  DLINK_FOREACH_SAFE(node, node_next, global_server_list.head)
776    {
777 <    target_p = ptr->data;
777 >    struct Client *target_p = node->data;
778  
779      /* Do not attempt to send to ourselves, or the source */
780      if (IsMe(target_p) || target_p->from == source_p->from)
781        continue;
782  
783 <    if (target_p->from->localClient->serial == current_serial)
783 >    if (target_p->from->connection->serial == current_serial)
784        continue;
785  
786      if (match(mask, target_p->name))
787 <    {
906 <      /*
907 <       * if we set the serial here, then we'll never do a
908 <       * match() again, if !IsCapable()
909 <       */
910 <      target_p->from->localClient->serial = current_serial;
911 <      found++;
787 >      continue;
788  
789 <      if (!IsCapable(target_p->from, cap))
790 <        continue;
789 >    /*
790 >     * If we set the serial here, then we'll never do a
791 >     * match() again, if !IsCapable()
792 >     */
793 >    target_p->from->connection->serial = current_serial;
794  
795 <      sendto_anywhere(target_p, source_p, "%s", buffer);
796 <    }
795 >    if (!IsCapable(target_p->from, cap))
796 >      continue;
797 >
798 >    send_message_remote(target_p->from, source_p, buffer);
799    }
800 +
801 +  dbuf_ref_free(buffer);
802   }
803  
804   /* sendto_anywhere()
# Line 929 | Line 812 | sendto_match_servs(struct Client *source
812   */
813   void
814   sendto_anywhere(struct Client *to, struct Client *from,
815 +                const char *command,
816                  const char *pattern, ...)
817   {
818    va_list args;
819 <  char buffer[IRCD_BUFSIZE];
936 <  int len;
937 <  struct Client *send_to = (to->from != NULL ? to->from : to);
819 >  struct dbuf_block *buffer = NULL;
820  
821 <  if (IsDead(send_to))
821 >  if (IsDead(to->from))
822      return;
823  
824 <  if (MyClient(to))
825 <  {
826 <    if (IsServer(from))
827 <    {
828 <      if (IsCapable(to, CAP_TS6) && HasID(from))
829 <        len = ircsprintf(buffer, ":%s ", from->id);
830 <      else
831 <        len = ircsprintf(buffer, ":%s ", from->name);
950 <    }
951 <    else
952 <      len = ircsprintf(buffer, ":%s!%s@%s ",
953 <                       from->name, from->username, from->host);
954 <  }
955 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
824 >  buffer = dbuf_alloc();
825 >
826 >  if (MyClient(to) && IsClient(from))
827 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
828 >                 from->host, command, to->name);
829 >  else
830 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
831 >                 command, ID_or_name(to, to));
832  
833    va_start(args, pattern);
834 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
834 >  send_format(buffer, pattern, args);
835    va_end(args);
836  
837 <  if(MyClient(to))
838 <    send_message(send_to, buffer, len);
837 >  if (MyConnect(to))
838 >    send_message(to, buffer);
839    else
840 <    send_message_remote(send_to, from, buffer, len);
840 >    send_message_remote(to->from, from, buffer);
841 >
842 >  dbuf_ref_free(buffer);
843   }
844  
845   /* sendto_realops_flags()
# Line 973 | Line 851 | sendto_anywhere(struct Client *to, struc
851   * side effects - Send to *local* ops only but NOT +s nonopers.
852   */
853   void
854 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
854 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
855   {
856 <  dlink_node *ptr = NULL;
857 <  char nbuf[IRCD_BUFSIZE];
856 >  const char *ntype = NULL;
857 >  dlink_node *node = NULL;
858 >  char nbuf[IRCD_BUFSIZE] = "";
859    va_list args;
860  
861    va_start(args, pattern);
862 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
862 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
863    va_end(args);
864  
865 <  DLINK_FOREACH(ptr, oper_list.head)
865 >  switch (type)
866    {
867 <    struct Client *client_p = ptr->data;
868 <    assert(client_p->umodes & UMODE_OPER);
869 <
870 <    /* If we're sending it to opers and theyre an admin, skip.
871 <     * If we're sending it to admins, and theyre not, skip.
872 <     */
873 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
874 <        ((level == L_OPER) && IsAdmin(client_p)))
875 <      continue;
876 <
877 <    if (client_p->umodes & flags)
999 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1000 <                 me.name, client_p->name, nbuf);
867 >    case SEND_NOTICE:
868 >      ntype = "Notice";
869 >      break;
870 >    case SEND_GLOBAL:
871 >      ntype = "Global";
872 >      break;
873 >    case SEND_LOCOPS:
874 >      ntype = "LocOps";
875 >      break;
876 >    default:
877 >      assert(0);
878    }
1002 }
1003
1004 /* sendto_wallops_flags()
1005 *
1006 * inputs       - flag types of messages to show to real opers
1007 *              - client sending request
1008 *              - var args input message
1009 * output       - NONE
1010 * side effects - Send a wallops to local opers
1011 */
1012 void
1013 sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1014                     const char *pattern, ...)
1015 {
1016  dlink_node *ptr = NULL;
1017  va_list args;
1018  char buffer[IRCD_BUFSIZE];
1019  int len;
879  
880 <  if (IsClient(source_p))
1022 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1023 <                     source_p->name, source_p->username, source_p->host);
1024 <  else
1025 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
1026 <
1027 <  va_start(args, pattern);
1028 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1029 <  va_end(args);
1030 <
1031 <  DLINK_FOREACH(ptr, oper_list.head)
880 >  DLINK_FOREACH(node, oper_list.head)
881    {
882 <    struct Client *client_p = ptr->data;
883 <    assert(client_p->umodes & UMODE_OPER);
882 >    struct Client *client_p = node->data;
883 >    assert(HasUMode(client_p, UMODE_OPER));
884  
885 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
886 <      send_message(client_p, buffer, len);
887 <  }
888 < }
889 <
890 < /* ts_warn()
891 < *
1043 < * inputs       - var args message
1044 < * output       - NONE
1045 < * side effects - Call sendto_realops_flags, with some flood checking
1046 < *                (at most 5 warnings every 5 seconds)
1047 < */
1048 < void
1049 < ts_warn(const char *pattern, ...)
1050 < {
1051 <  va_list args;
1052 <  char buffer[IRCD_BUFSIZE];
1053 <  static time_t last = 0;
1054 <  static int warnings = 0;
1055 <
1056 <  /*
1057 <   ** if we're running with TS_WARNINGS enabled and someone does
1058 <   ** something silly like (remotely) connecting a nonTS server,
1059 <   ** we'll get a ton of warnings, so we make sure we don't send
1060 <   ** more than 5 every 5 seconds.  -orabidoo
1061 <   */
885 >    /*
886 >     * If we're sending it to opers and they're an admin, skip.
887 >     * If we're sending it to admins, and they're not, skip.
888 >     */
889 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
890 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
891 >      continue;
892  
893 <  if (CurrentTime - last < 5)
894 <  {
895 <    if (++warnings > 5)
1066 <      return;
893 >    if (HasUMode(client_p, flags))
894 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
895 >                 me.name, client_p->name, ntype, nbuf);
896    }
1068  else
1069  {
1070    last = CurrentTime;
1071    warnings = 0;
1072  }
1073
1074  va_start(args, pattern);
1075  vsnprintf(buffer, sizeof(buffer), pattern, args);
1076  va_end(args);
1077
1078  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1079  ilog(L_CRIT, "%s", buffer);
897   }
898  
899 < /* kill_client()
899 > /* ts_warn()
900   *
901 < * inputs       - client to send kill towards
902 < *              - pointer to client to kill
903 < *              - reason for kill
904 < * output       - NONE
1088 < * side effects - NONE
901 > * inputs       - var args message
902 > * output       - NONE
903 > * side effects - Call sendto_realops_flags, with some flood checking
904 > *                (at most 5 warnings every 5 seconds)
905   */
906   void
907 < kill_client(struct Client *client_p, struct Client *diedie,
1092 <            const char *pattern, ...)
907 > sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
908   {
909    va_list args;
910 <  char buffer[IRCD_BUFSIZE];
1096 <  int len;
910 >  char buffer[IRCD_BUFSIZE] = "";
911  
912 <  if (client_p->from != NULL)
1099 <    client_p = client_p->from;
1100 <  if (IsDead(client_p))
912 >  if ((CurrentTime - *rate) < 20)
913      return;
914  
915 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1104 <                   ID_or_name(diedie, client_p));
915 >  *rate = CurrentTime;
916  
917    va_start(args, pattern);
918 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
918 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
919    va_end(args);
920  
921 <  send_message(client_p, buffer, len);
921 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
922 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
923   }
924  
925 < /* kill_client_ll_serv_butone()
925 > /* sendto_wallops_flags()
926   *
927 < * inputs       - pointer to client to not send to
928 < *              - pointer to client to kill
929 < * output       - NONE
930 < * side effects - Send a KILL for the given client
931 < *                message to all connected servers
1120 < *                except the client 'one'. Also deal with
1121 < *                client being unknown to leaf, as in lazylink...
927 > * inputs       - flag types of messages to show to real opers
928 > *              - client sending request
929 > *              - var args input message
930 > * output       - NONE
931 > * side effects - Send a wallops to local opers
932   */
933   void
934 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
935 <                           const char *pattern, ...)
934 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
935 >                     const char *pattern, ...)
936   {
937 +  dlink_node *node = NULL;
938    va_list args;
939 <  int have_uid = 0;
1129 <  dlink_node *ptr = NULL;
1130 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1131 <  int len_uid = 0, len_nick = 0;
939 >  struct dbuf_block *buffer = dbuf_alloc();
940  
941 <  if (HasID(source_p) && (me.id[0] != '\0'))
942 <  {
943 <    have_uid = 1;
944 <    va_start(args, pattern);
1137 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1138 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1139 <                           args);
1140 <    va_end(args);
1141 <  }
941 >  if (IsClient(source_p))
942 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
943 >  else
944 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
945  
946    va_start(args, pattern);
947 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1145 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1146 <                          args);
947 >  send_format(buffer, pattern, args);
948    va_end(args);
949  
950 <  DLINK_FOREACH(ptr, serv_list.head)
950 >  DLINK_FOREACH(node, oper_list.head)
951    {
952 <    struct Client *client_p = ptr->data;
953 <
1153 <    if (one != NULL && (client_p == one->from))
1154 <      continue;
1155 <    if (IsDefunct(client_p))
1156 <      continue;
952 >    struct Client *client_p = node->data;
953 >    assert(client_p->umodes & UMODE_OPER);
954  
955 <    if (have_uid && IsCapable(client_p, CAP_TS6))
956 <      send_message(client_p, buf_uid, len_uid);
1160 <    else
1161 <      send_message(client_p, buf_nick, len_nick);
955 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
956 >      send_message(client_p, buffer);
957    }
958 < }
958 >
959 >  dbuf_ref_free(buffer);
960 > }

Diff Legend

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