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 939 by db, Sat May 2 01:41:47 2009 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 3241 by michael, Sun Mar 30 16:45:31 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  send.c: Functions for sending messages.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file send.c
23 > * \brief Functions for sending messages.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "send.h"
30   #include "channel.h"
31   #include "client.h"
30 #include "common.h"
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
34 #include "handlers.h"
35   #include "numeric.h"
36   #include "fdlist.h"
37   #include "s_bsd.h"
38   #include "s_serv.h"
39 < #include "sprintf_irc.h"
40 < #include "s_conf.h"
41 < #include "list.h"
42 < #include "s_log.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "memory.h"
44 #include "hook.h"
45 #include "irc_getnameinfo.h"
42   #include "packet.h"
43  
44 < #define LOG_BUFSIZE 2048
45 <
46 < struct Callback *iosend_cb = NULL;
51 < struct Callback *iosendctrl_cb = NULL;
44 > #ifndef IOV_MAX
45 > #define IOV_MAX 64
46 > #endif
47  
48 < static void send_message(struct Client *, char *, int);
54 < static void send_message_remote(struct Client *, struct Client *, char *, int);
48 > static unsigned int current_serial = 0;
49  
56 static unsigned long current_serial = 0L;
50  
51   /* send_format()
52   *
53 < * inputs       - buffer to format into
54 < *              - size of the buffer
53 > * inputs
54 > *              - buffer
55   *              - format pattern to use
56   *              - var args
57   * output       - number of bytes formatted output
58   * side effects - modifies sendbuf
59   */
60 < static inline int
61 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
60 > static void
61 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
62   {
70  int len;
71
63    /*
64     * from rfc1459
65     *
66     * IRC messages are always lines of characters terminated with a CR-LF
67     * (Carriage Return - Line Feed) pair, and these messages shall not
68 <   * exceed 512 characters in length,  counting all characters
68 >   * exceed 512 characters in length,  counting all characters
69     * including the trailing CR-LF.
70     * Thus, there are 510 characters maximum allowed
71     * for the command and its parameters.  There is no provision for
72     * continuation message lines.  See section 7 for more details about
73     * current implementations.
74     */
75 <  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 < }
75 >  dbuf_put_args(buffer, pattern, args);
76  
77 < /*
78 < * 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 *);
77 >  if (buffer->size > sizeof(buffer->data) - 2)
78 >    buffer->size = sizeof(buffer->data) - 2;
79  
80 <  dbuf_put(&to->localClient->buf_sendq, buf, length);
81 <  return NULL;
80 >  buffer->data[buffer->size++] = '\r';
81 >  buffer->data[buffer->size++] = '\n';
82   }
83  
84   /*
# Line 110 | Line 87 | iosend_default(va_list args)
87   **      sendq.
88   */
89   static void
90 < send_message(struct Client *to, char *buf, int len)
90 > send_message(struct Client *to, struct dbuf_block *buf)
91   {
92    assert(!IsMe(to));
93    assert(to != &me);
94  
95 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
95 >  if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs))
96    {
97      if (IsServer(to))
98 <      sendto_realops_flags(UMODE_ALL, L_ALL,
99 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
98 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
99 >                           "Max SendQ limit exceeded for %s: %lu > %u",
100                             get_client_name(to, HIDE_IP),
101 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
102 <                           get_sendq(to));
101 >                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size),
102 >                           get_sendq(&to->localClient->confs));
103      if (IsClient(to))
104        SetSendQExceeded(to);
105 +
106      dead_link_on_write(to, 0);
107      return;
108    }
109  
110 <  execute_callback(iosend_cb, to, len, buf);
110 >  dbuf_add(&to->localClient->buf_sendq, buf);
111  
112    /*
113 <   ** Update statistics. The following is slightly incorrect
114 <   ** because it counts messages even if queued, but bytes
115 <   ** only really sent. Queued bytes get updated in SendQueued.
113 >   * Update statistics. The following is slightly incorrect because
114 >   * it counts messages even if queued, but bytes only really sent.
115 >   * Queued bytes get updated in send_queued_write().
116     */
117    ++to->localClient->send.messages;
118    ++me.localClient->send.messages;
119  
120 <  if (dbuf_length(&to->localClient->buf_sendq) >
143 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
144 <    send_queued_write(to);
120 >  send_queued_write(to);
121   }
122  
123   /* send_message_remote()
124   *
125   * inputs       - pointer to client from message is being sent
126   *              - pointer to client to send to
127 < *              - pointer to preformatted buffer
152 < *              - length of input buffer
127 > *              - pointer to buffer
128   * output       - none
129   * side effects - Despite the function name, this only sends to directly
130   *                connected clients.
131 < *
131 > *
132   */
133   static void
134 < send_message_remote(struct Client *to, struct Client *from,
160 <                    char *buf, int len)
134 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
135   {
136 +  to = to->from;
137 +
138    if (!MyConnect(to))
139    {
140 <    sendto_realops_flags(UMODE_ALL, L_ALL,
141 <                         "server send message to %s [%s] dropped from %s(Not local server)",
142 <                         to->name, to->from->name, from->name);
140 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
141 >                         "Server send message to %s [%s] dropped from %s(Not local server)",
142 >                         to->name, to->from->name, from->name);
143      return;
144    }
145  
# Line 174 | Line 150 | send_message_remote(struct Client *to, s
150    {
151      if (IsServer(from))
152      {
153 <      sendto_realops_flags(UMODE_ALL, L_ALL,
153 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
154                             "Send message to %s [%s] dropped from %s(Fake Dir)",
155                             to->name, to->from->name, from->name);
156        return;
157      }
158  
159 <    sendto_realops_flags(UMODE_ALL, L_ALL,
159 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
160                           "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
161                           to->name, to->username, to->host,
162                           from->name, from->username, from->host,
163                           to->from->name);
164  
165 <    sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
190 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
191 <                  me.id, to->name, me.name, to->name,
192 <                  to->username, to->host, to->from->name);
193 <    sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
165 >    sendto_server(NULL, NOCAPS, NOCAPS,
166                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
167 <                  me.name, to->name, me.name, to->name,
167 >                  me.id, to->id, me.name, to->name,
168                    to->username, to->host, to->from->name);
169  
170 <    SetKilled(to);
170 >    AddFlag(to, FLAGS_KILLED);
171  
172      if (IsClient(from))
173 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
174 <                 me.name, from->name, to->name, to->username,
203 <                 to->host, to->from);
204 <
205 <    exit_client(to, &me, "Ghosted client");
173 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
174 >                         to->username, to->host, to->from);
175  
176 +    exit_client(to, "Ghosted client");
177      return;
178 <  }
178 >  }
179  
180 <  send_message(to, buf, len);
180 >  send_message(to, buf);
181   }
182  
183   /*
# Line 217 | Line 187 | send_message_remote(struct Client *to, s
187   void
188   sendq_unblocked(fde_t *fd, struct Client *client_p)
189   {
190 <  ClearSendqBlocked(client_p);
191 <  /* let send_queued_write be executed by send_queued_all */
190 >  assert(fd == &client_p->localClient->fd);
191 >  send_queued_write(client_p);
192 > }
193  
194   #ifdef HAVE_LIBCRYPTO
195 <  if (fd->flags.pending_read)
195 > static int
196 > send_SSL_writev(SSL *ssl, const struct iovec *vec, int iovcnt)
197 > {
198 >  int total_written = 0;
199 >
200 >  for (int i = 0; i < iovcnt; ++i)
201    {
202 <    fd->flags.pending_read = 0;
203 <    read_packet(fd, client_p);
202 >    const struct iovec *iov = &vec[i];
203 >    int ret = 0;
204 >
205 >    /* Translate openssl error codes, sigh */
206 >    if ((ret = SSL_write(ssl, iov->iov_base, iov->iov_len)) <= 0)
207 >    {
208 >      switch (SSL_get_error(ssl, i))
209 >      {
210 >        case SSL_ERROR_WANT_READ:
211 >          return -1;
212 >        case SSL_ERROR_WANT_WRITE:
213 >          errno = EWOULDBLOCK;
214 >        case SSL_ERROR_SYSCALL:
215 >          break;
216 >        case SSL_ERROR_SSL:
217 >          if (errno == EAGAIN)
218 >            break;
219 >        default:
220 >          errno = 0;  /* Either an SSL-specific error or EOF */
221 >      }
222 >
223 >      return 0;
224 >    }
225 >
226 >    total_written += ret;
227    }
229 #endif
230 }
228  
229 < /*
233 < ** slinkq_unblocked
234 < **      Called when a server control socket is ready for writing.
235 < */
236 < static void
237 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
238 < {
239 <  ClearSlinkqBlocked(client_p);
240 <  send_queued_slink_write(client_p);
229 >  return total_written;
230   }
231 + #endif
232  
233   /*
234   ** send_queued_write
# Line 249 | Line 239 | slinkq_unblocked(fde_t *fd, struct Clien
239   void
240   send_queued_write(struct Client *to)
241   {
242 <  int retlen;
243 <  struct dbuf_block *first;
242 >  int retlen = 0, i = 0;
243 >  dlink_node *ptr = NULL;
244 >  struct iovec vec[IOV_MAX];
245  
246    /*
247 <   ** Once socket is marked dead, we cannot start writing to it,
248 <   ** even if the error is removed...
247 >   * Once socket is marked dead, we cannot start writing to it,
248 >   * even if the error is removed...
249     */
250 <  if (IsDead(to) || IsSendqBlocked(to))
251 <    return;  /* no use calling send() now */
261 <
262 <  /* Next, lets try to write some data */
263 <
264 <  if (dbuf_length(&to->localClient->buf_sendq))
265 <  {
266 <    do {
267 <      first = to->localClient->buf_sendq.blocks.head->data;
268 <
269 < #ifdef HAVE_LIBCRYPTO
270 <      if (to->localClient->fd.ssl)
271 <      {
272 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
250 >  if (IsDead(to))
251 >    return;  /* No use calling send() now */
252  
253 <        /* translate openssl error codes, sigh */
254 <        if (retlen < 0)
276 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
277 <          {
278 <            case SSL_ERROR_WANT_READ:
279 <              return;  /* retry later, don't register for write events */
280 <
281 <            case SSL_ERROR_WANT_WRITE:
282 <              errno = EWOULDBLOCK;
283 <            case SSL_ERROR_SYSCALL:
284 <              break;
285 <            case SSL_ERROR_SSL:
286 <              if (errno == EAGAIN)
287 <                break;
288 <            default:
289 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
290 <          }
291 <      }
292 <      else
293 < #endif
294 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
253 >  if (HasFlag(to, FLAGS_CORK))
254 >    return;
255  
256 <      if (retlen <= 0)
257 <      {
258 < #ifdef _WIN32
299 <        errno = WSAGetLastError();
300 < #endif
301 <        break;
302 <      }
256 >  /* Nothing to do? */
257 >  if (!dbuf_length(&to->localClient->buf_sendq))
258 >    return;
259  
260 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
260 >  /* Build iovec */
261 >  DLINK_FOREACH(ptr, to->localClient->buf_sendq.blocks.head)
262 >  {
263 >    struct dbuf_block *block = ptr->data;
264 >    struct iovec *iov;
265 >    int offset;
266 >
267 >    if (i >= sizeof(vec) / sizeof(struct iovec))
268 >      break;
269 >        
270 >    iov = &vec[i];
271 >    offset = !i ? to->localClient->buf_sendq.pos : 0;
272  
273 <      /* We have some data written .. update counters */
274 <      to->localClient->send.bytes += retlen;
308 <      me.localClient->send.bytes += retlen;
309 <    } while (dbuf_length(&to->localClient->buf_sendq));
273 >    iov->iov_base = block->data + offset;
274 >    iov->iov_len = block->size - offset;
275  
276 <    if ((retlen < 0) && (ignoreErrno(errno)))
312 <    {
313 <      /* we have a non-fatal error, reschedule a write */
314 <      SetSendqBlocked(to);
315 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
316 <                     (PF *)sendq_unblocked, (void *)to, 0);
317 <    }
318 <    else if (retlen <= 0)
319 <    {
320 <      dead_link_on_write(to, errno);
321 <      return;
322 <    }
276 >    ++i;
277    }
324 }
325
326 /*
327 ** send_queued_slink_write
328 **      This is called when there is a chance the some output would
329 **      be possible. This attempts to empty the send queue as far as
330 **      possible, and then if any data is left, a write is rescheduled.
331 */
332 void
333 send_queued_slink_write(struct Client *to)
334 {
335  int retlen;
336
337  /*
338   ** Once socket is marked dead, we cannot start writing to it,
339   ** even if the error is removed...
340   */
341  if (IsDead(to) || IsSlinkqBlocked(to))
342    return;  /* no use calling send() now */
278  
279    /* Next, lets try to write some data */
280 <  if (to->localClient->slinkq != NULL)
280 > #ifdef HAVE_LIBCRYPTO
281 >  if (to->localClient->fd.ssl)
282    {
283 <    retlen = send(to->localClient->ctrlfd.fd,
348 <                   to->localClient->slinkq + to->localClient->slinkq_ofs,
349 <                   to->localClient->slinkq_len, 0);
350 <    if (retlen < 0)
351 <    {
352 <      /* If we have a fatal error */
353 <      if (!ignoreErrno(errno))
354 <      {
355 <        dead_link_on_write(to, errno);
356 <        return;
357 <      }
358 <    }
359 <    else if (retlen == 0)
360 <    {
361 <      /* 0 bytes is an EOF .. */
362 <      dead_link_on_write(to, 0);
283 >    if ((retlen = send_SSL_writev(to->localClient->fd.ssl, vec, i)) == -1)
284        return;
285 <    }
286 <    else
287 <    {
288 <      execute_callback(iosendctrl_cb, to, retlen,
368 <        to->localClient->slinkq + to->localClient->slinkq_ofs);
369 <      to->localClient->slinkq_len -= retlen;
370 <
371 <      assert(to->localClient->slinkq_len >= 0);
372 <      if (to->localClient->slinkq_len)
373 <        to->localClient->slinkq_ofs += retlen;
374 <      else
375 <      {
376 <        to->localClient->slinkq_ofs = 0;
377 <        MyFree(to->localClient->slinkq);
378 <        to->localClient->slinkq = NULL;
379 <      }
380 <    }
285 >  }
286 >  else
287 > #endif
288 >    retlen = writev(to->localClient->fd.fd, vec, i);
289  
290 <    /* Finally, if we have any more data, reschedule a write */
291 <    if (to->localClient->slinkq_len)
292 <    {
293 <      SetSlinkqBlocked(to);
294 <      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
295 <                     (PF *)slinkq_unblocked, (void *)to, 0);
296 <    }
290 >  if (retlen > 0)
291 >  {
292 >    dbuf_delete(&to->localClient->buf_sendq, retlen);
293 >
294 >    /* We have some data written .. update counters */
295 >    to->localClient->send.bytes += retlen;
296 >    me.localClient->send.bytes += retlen;
297 >
298 >    if (dbuf_length(&to->localClient->buf_sendq))
299 >      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
300 >                     (PF *)sendq_unblocked, to, 0);
301    }
302 +  else if (retlen < 0 && ignoreErrno(errno))
303 +    /* we have a non-fatal error, reschedule a write */
304 +    comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
305 +                   (PF *)sendq_unblocked, to, 0);
306 +  else if (retlen <= 0)
307 +    dead_link_on_write(to, errno);
308   }
309  
310   /* send_queued_all()
# Line 404 | Line 322 | send_queued_all(void)
322     * a notice to opers, which is to be delivered by this function.
323     */
324    DLINK_FOREACH(ptr, serv_list.head)
325 <    send_queued_write((struct Client *) ptr->data);
325 >    send_queued_write(ptr->data);
326  
327    DLINK_FOREACH(ptr, unknown_list.head)
328 <    send_queued_write((struct Client *) ptr->data);
328 >    send_queued_write(ptr->data);
329  
330    DLINK_FOREACH(ptr, local_client_list.head)
331 <    send_queued_write((struct Client *) ptr->data);
331 >    send_queued_write(ptr->data);
332  
333    /* NOTE: This can still put clients on aborted_list; unfortunately,
334     * exit_aborted_clients takes precedence over send_queued_all,
# Line 431 | Line 349 | void
349   sendto_one(struct Client *to, const char *pattern, ...)
350   {
351    va_list args;
352 <  char buffer[IRCD_BUFSIZE];
435 <  int len;
352 >  struct dbuf_block *buffer = NULL;
353  
354 <  if (to->from != NULL)
355 <    to = to->from;
356 <  if (IsDead(to))
357 <    return; /* This socket has already been marked as dead */
354 >  if (IsDead(to->from))
355 >    return;  /* This socket has already been marked as dead */
356 >
357 >  buffer = dbuf_alloc();
358 >
359 >  va_start(args, pattern);
360 >  send_format(buffer, pattern, args);
361 >  va_end(args);
362 >
363 >  send_message(to->from, buffer);
364 >
365 >  dbuf_ref_free(buffer);
366 > }
367 >
368 > void
369 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
370 > {
371 >  struct dbuf_block *buffer = NULL;
372 >  const char *dest = NULL;
373 >  va_list args;
374 >
375 >  if (IsDead(to->from))
376 >    return;
377 >
378 >  dest = ID_or_name(to, to);
379 >  if (EmptyString(dest))
380 >    dest = "*";
381 >
382 >  buffer = dbuf_alloc();
383 >
384 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
385 >
386 >  va_start(args, numeric);
387 >  send_format(buffer, numeric_form(numeric), args);
388 >  va_end(args);
389 >
390 >  send_message(to->from, buffer);
391 >
392 >  dbuf_ref_free(buffer);
393 > }
394 >
395 > void
396 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
397 > {
398 >  struct dbuf_block *buffer = NULL;
399 >  const char *dest = NULL;
400 >  va_list args;
401 >
402 >  if (IsDead(to->from))
403 >    return;
404 >
405 >  dest = ID_or_name(to, to);
406 >  if (EmptyString(dest))
407 >    dest = "*";
408 >
409 >  buffer = dbuf_alloc();
410 >
411 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
412  
413    va_start(args, pattern);
414 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
414 >  send_format(buffer, pattern, args);
415    va_end(args);
416  
417 <  send_message(to, buffer, len);
417 >  send_message(to->from, buffer);
418 >
419 >  dbuf_ref_free(buffer);
420   }
421  
422   /* sendto_channel_butone()
# Line 459 | Line 432 | sendto_one(struct Client *to, const char
432   */
433   void
434   sendto_channel_butone(struct Client *one, struct Client *from,
435 <                      struct Channel *chptr, const char *command,
435 >                      struct Channel *chptr, unsigned int type,
436                        const char *pattern, ...)
437   {
438 <  va_list alocal, aremote, auid;
439 <  char local_buf[IRCD_BUFSIZE];
440 <  char remote_buf[IRCD_BUFSIZE];
441 <  char uid_buf[IRCD_BUFSIZE];
442 <  int local_len, remote_len, uid_len;
470 <  dlink_node *ptr;
471 <  dlink_node *ptr_next;
472 <  struct Client *target_p;
438 >  va_list alocal, aremote;
439 >  struct dbuf_block *local_buf, *remote_buf;
440 >  dlink_node *ptr = NULL, *ptr_next = NULL;
441 >
442 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
443  
444    if (IsServer(from))
445 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
476 <                           from->name, command, chptr->chname);
445 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
446    else
447 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
448 <                           from->name, from->username, from->host,
449 <                           command, chptr->chname);
481 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
482 <                          from->name, command, chptr->chname);
483 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
484 <                       ID(from), command, chptr->chname);
447 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
448 >
449 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
450  
451    va_start(alocal, pattern);
452    va_start(aremote, pattern);
453 <  va_start(auid, pattern);
454 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
455 <                           pattern, alocal);
491 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
492 <                            pattern, aremote);
493 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
494 <                         auid);
495 <  va_end(auid);
453 >  send_format(local_buf, pattern, alocal);
454 >  send_format(remote_buf, pattern, aremote);
455 >
456    va_end(aremote);
457    va_end(alocal);
458  
# Line 500 | Line 460 | sendto_channel_butone(struct Client *one
460  
461    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
462    {
463 <    target_p = ((struct Membership *)ptr->data)->client_p;
464 <    assert(target_p != NULL);
463 >    struct Membership *ms = ptr->data;
464 >    struct Client *target_p = ms->client_p;
465 >
466 >    assert(IsClient(target_p));
467  
468 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
468 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
469 >        (one && target_p->from == one->from))
470        continue;
471  
472 <    if (MyClient(target_p))
473 <    {
474 <      if (target_p->serial != current_serial)
475 <      {
476 <        send_message(target_p, local_buf, local_len);
477 <        target_p->serial = current_serial;
478 <      }
479 <    }
517 <    else
518 <    {
519 <      /* Now check whether a message has been sent to this
520 <       * remote link already
521 <       */
522 <      if (target_p->from->serial != current_serial)
523 <      {
524 <        if (IsCapable(target_p->from, CAP_TS6))
525 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
526 <        else
527 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
528 <        target_p->from->serial = current_serial;
529 <      }
530 <    }
472 >    if (type != 0 && (ms->flags & type) == 0)
473 >      continue;
474 >
475 >    if (MyConnect(target_p))
476 >      send_message(target_p, local_buf);
477 >    else if (target_p->from->localClient->serial != current_serial)
478 >      send_message_remote(target_p->from, from, remote_buf);
479 >    target_p->from->localClient->serial = current_serial;
480    }
481 +
482 +  dbuf_ref_free(local_buf);
483 +  dbuf_ref_free(remote_buf);
484   }
485  
486   /* sendto_server()
487 < *
487 > *
488   * inputs       - pointer to client to NOT send to
489   *              - pointer to channel
490   *              - caps or'd together which must ALL be present
# Line 543 | Line 495 | sendto_channel_butone(struct Client *one
495   * side effects - Send a message to all connected servers, except the
496   *                client 'one' (if non-NULL), as long as the servers
497   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
498 < *            
498 > *
499   * This function was written in an attempt to merge together the other
500   * billion sendto_*serv*() functions, which sprung up with capabs,
501   * lazylinks, uids, etc.
502   * -davidt
503   */
504 < void
504 > void
505   sendto_server(struct Client *one,
506 <              struct Channel *chptr, unsigned long caps,
507 <              unsigned long nocaps,
506 >              const unsigned int caps,
507 >              const unsigned int nocaps,
508                const char *format, ...)
509   {
510    va_list args;
511    dlink_node *ptr = NULL;
512 <  char buffer[IRCD_BUFSIZE];
561 <  int len = 0;
512 >  struct dbuf_block *buffer;
513  
514 <  if (chptr && chptr->chname[0] != '#')
564 <    return;
514 >  buffer = dbuf_alloc();
515  
516    va_start(args, format);
517 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
517 >  send_format(buffer, format, args);
518    va_end(args);
519  
520    DLINK_FOREACH(ptr, serv_list.head)
# Line 584 | Line 534 | sendto_server(struct Client *one,
534      if ((client_p->localClient->caps & nocaps) != 0)
535        continue;
536  
537 <    send_message(client_p, buffer, len);
537 >    send_message(client_p, buffer);
538    }
539 +
540 +  dbuf_ref_free(buffer);
541   }
542  
543   /* sendto_common_channels_local()
# Line 594 | Line 546 | sendto_server(struct Client *one,
546   *              - pattern to send
547   * output       - NONE
548   * side effects - Sends a message to all people on local server who are
549 < *                in same channel with user.
549 > *                in same channel with user.
550   *                used by m_nick.c and exit_one_client.
551   */
552   void
553 < sendto_common_channels_local(struct Client *user, int touser,
553 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
554                               const char *pattern, ...)
555   {
556    va_list args;
# Line 607 | Line 559 | sendto_common_channels_local(struct Clie
559    struct Channel *chptr;
560    struct Membership *ms;
561    struct Client *target_p;
562 <  char buffer[IRCD_BUFSIZE];
563 <  int len;
562 >  struct dbuf_block *buffer;
563 >
564 >  buffer = dbuf_alloc();
565  
566    va_start(args, pattern);
567 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
567 >  send_format(buffer, pattern, args);
568    va_end(args);
569  
570    ++current_serial;
571  
572    DLINK_FOREACH(cptr, user->channel.head)
573    {
574 <    chptr = ((struct Membership *) cptr->data)->chptr;
574 >    chptr = ((struct Membership *)cptr->data)->chptr;
575      assert(chptr != NULL);
576  
577      DLINK_FOREACH(uptr, chptr->members.head)
# Line 628 | Line 581 | sendto_common_channels_local(struct Clie
581        assert(target_p != NULL);
582  
583        if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
584 <          target_p->serial == current_serial)
584 >          target_p->localClient->serial == current_serial)
585          continue;
586  
587 <      target_p->serial = current_serial;
588 <      send_message(target_p, buffer, len);
587 >      if (HasCap(target_p, cap) != cap)
588 >        continue;
589 >
590 >      target_p->localClient->serial = current_serial;
591 >      send_message(target_p, buffer);
592      }
593    }
594  
595    if (touser && MyConnect(user) && !IsDead(user) &&
596 <      user->serial != current_serial)
597 <    send_message(user, buffer, len);
596 >      user->localClient->serial != current_serial)
597 >    if (HasCap(user, cap) == cap)
598 >      send_message(user, buffer);
599 >
600 >  dbuf_ref_free(buffer);
601   }
602  
603   /* sendto_channel_local()
# Line 652 | Line 611 | sendto_common_channels_local(struct Clie
611   *                locally connected to this server.
612   */
613   void
614 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
614 > sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
615                       const char *pattern, ...)
616   {
617    va_list args;
618 <  char buffer[IRCD_BUFSIZE];
619 <  int len;
620 <  dlink_node *ptr;
621 <  struct Membership *ms;
663 <  struct Client *target_p;
618 >  dlink_node *ptr = NULL;
619 >  struct dbuf_block *buffer;
620 >
621 >  buffer = dbuf_alloc();
622  
623    va_start(args, pattern);
624 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
624 >  send_format(buffer, pattern, args);
625    va_end(args);
626  
627    DLINK_FOREACH(ptr, chptr->members.head)
628    {
629 <    ms = ptr->data;
630 <    target_p = ms->client_p;
629 >    struct Membership *ms = ptr->data;
630 >    struct Client *target_p = ms->client_p;
631  
632      if (type != 0 && (ms->flags & type) == 0)
633        continue;
634  
635      if (!MyConnect(target_p) || IsDefunct(target_p) ||
636 <        (nodeaf && IsDeaf(target_p)))
636 >        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
637        continue;
638  
639 <    send_message(target_p, buffer, len);
639 >    send_message(target_p, buffer);
640    }
641 +
642 +  dbuf_ref_free(buffer);
643   }
644  
645   /* sendto_channel_local_butone()
# Line 694 | Line 654 | sendto_channel_local(int type, int nodea
654   *
655   * WARNING - +D clients are omitted
656   */
697 void      
698 sendto_channel_local_butone(struct Client *one, int type,
699                            struct Channel *chptr, const char *pattern, ...)
700 {
701  va_list args;
702  char buffer[IRCD_BUFSIZE];
703  int len;
704  struct Client *target_p;
705  struct Membership *ms;
706  dlink_node *ptr;
707
708  va_start(args, pattern);
709  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
710  va_end(args);
711
712  DLINK_FOREACH(ptr, chptr->members.head)      
713  {  
714    ms = ptr->data;
715    target_p = ms->client_p;
716
717    if (type != 0 && (ms->flags & type) == 0)
718      continue;
719
720    if (!MyConnect(target_p) || target_p == one ||
721        IsDefunct(target_p) || IsDeaf(target_p))
722      continue;
723    send_message(target_p, buffer, len);
724  }
725 }
726
727
728 /* sendto_channel_remote()
729 *
730 * inputs       - Client not to send towards
731 *              - Client from whom message is from
732 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
733 *              - pointer to channel to send to
734 *              - var args pattern
735 * output       - NONE
736 * side effects - Send a message to all members of a channel that are
737 *                remote to this server.
738 */
657   void
658 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
659 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
658 > sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
659 >                            struct Channel *chptr, const char *pattern, ...)
660   {
661    va_list args;
662 <  char buffer[IRCD_BUFSIZE];
663 <  int len;
664 <  dlink_node *ptr;
665 <  struct Client *target_p;
748 <  struct Membership *ms;
662 >  dlink_node *ptr = NULL;
663 >  struct dbuf_block *buffer;
664 >
665 >  buffer = dbuf_alloc();
666  
667    va_start(args, pattern);
668 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
668 >  send_format(buffer, pattern, args);
669    va_end(args);
670  
754  ++current_serial;
755
671    DLINK_FOREACH(ptr, chptr->members.head)
672    {
673 <    ms = ptr->data;
674 <    target_p = ms->client_p;
673 >    struct Membership *ms = ptr->data;
674 >    struct Client *target_p = ms->client_p;
675  
676      if (type != 0 && (ms->flags & type) == 0)
677        continue;
678  
679 <    if (MyConnect(target_p))
679 >    if (!MyConnect(target_p) || (one && target_p == one->from))
680        continue;
766    target_p = target_p->from;
681  
682 <    if (target_p == one->from ||
769 <        ((target_p->from->localClient->caps & caps) != caps) ||
770 <        ((target_p->from->localClient->caps & nocaps) != 0))
682 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
683        continue;
684 <    if (target_p->from->serial != current_serial)
685 <    {
686 <      send_message(target_p, buffer, len);
687 <      target_p->from->serial = current_serial;
688 <    }
689 <  }
684 >
685 >    if (HasCap(target_p, cap) != cap)
686 >      continue;
687 >
688 >    send_message(target_p, buffer);
689 >  }
690 >
691 >  dbuf_ref_free(buffer);
692   }
693  
694   /*
# Line 795 | Line 709 | sendto_channel_remote(struct Client *one
709   * side effects - NONE
710   */
711   static int
712 < match_it(const struct Client *one, const char *mask, int what)
712 > match_it(const struct Client *one, const char *mask, unsigned int what)
713   {
714    if (what == MATCH_HOST)
715 <    return(match(mask, one->host));
715 >    return !match(mask, one->host);
716  
717 <  return(match(mask, one->servptr->name));
717 >  return !match(mask, one->servptr->name);
718   }
719  
720   /* sendto_match_butone()
# Line 811 | Line 725 | match_it(const struct Client *one, const
725   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
726   */
727   void
728 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
728 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
729                      int what, const char *pattern, ...)
730   {
731    va_list alocal, aremote;
732 <  struct Client *client_p;
733 <  dlink_node *ptr, *ptr_next;
734 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
735 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
736 <                             from->username, from->host);
737 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
732 >  dlink_node *ptr = NULL, *ptr_next = NULL;
733 >  struct dbuf_block *local_buf, *remote_buf;
734 >
735 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
736 >
737 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
738 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
739  
740    va_start(alocal, pattern);
741    va_start(aremote, pattern);
742 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
743 <                           pattern, alocal);
829 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
830 <                            pattern, aremote);
742 >  send_format(local_buf, pattern, alocal);
743 >  send_format(remote_buf, pattern, aremote);
744    va_end(aremote);
745    va_end(alocal);
746  
747    /* scan the local clients */
748    DLINK_FOREACH(ptr, local_client_list.head)
749    {
750 <    client_p = ptr->data;
750 >    struct Client *client_p = ptr->data;
751  
752 <    if (client_p != one && !IsDefunct(client_p) &&
752 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
753          match_it(client_p, mask, what))
754 <      send_message(client_p, local_buf, local_len);
754 >      send_message(client_p, local_buf);
755    }
756  
757    /* Now scan servers */
758    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
759    {
760 <    client_p = ptr->data;
760 >    struct Client *client_p = ptr->data;
761  
762      /*
763       * The old code looped through every client on the
# Line 870 | Line 783 | sendto_match_butone(struct Client *one,
783       * server deal with it.
784       * -wnder
785       */
786 <    if (client_p != one && !IsDefunct(client_p))
787 <      send_message_remote(client_p, from, remote_buf, remote_len);
786 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
787 >      send_message_remote(client_p, from, remote_buf);
788    }
789 +
790 +  dbuf_ref_free(local_buf);
791 +  dbuf_ref_free(remote_buf);
792   }
793  
794   /* sendto_match_servs()
# Line 885 | Line 801 | sendto_match_butone(struct Client *one,
801   * side effects - data sent to servers matching with capab
802   */
803   void
804 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
804 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
805                     const char *pattern, ...)
806   {
807    va_list args;
808 <  struct Client *target_p;
809 <  dlink_node *ptr;
810 <  char buffer[IRCD_BUFSIZE];
811 <  int found = 0;
808 >  dlink_node *ptr = NULL;
809 >  struct dbuf_block *buff_suid;
810 >
811 >  buff_suid = dbuf_alloc();
812  
813    va_start(args, pattern);
814 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
814 >  dbuf_put_fmt(buff_suid, ":%s ", source_p->id);
815 >  dbuf_put_args(buff_suid, pattern, args);
816    va_end(args);
817  
818 <  current_serial++;
818 >  ++current_serial;
819  
820    DLINK_FOREACH(ptr, global_serv_list.head)
821    {
822 <    target_p = ptr->data;
822 >    struct Client *target_p = ptr->data;
823  
824      /* Do not attempt to send to ourselves, or the source */
825      if (IsMe(target_p) || target_p->from == source_p->from)
826        continue;
827  
828 <    if (target_p->from->serial == current_serial)
828 >    if (target_p->from->localClient->serial == current_serial)
829        continue;
830  
831 <    if (match(mask, target_p->name))
831 >    if (!match(mask, target_p->name))
832      {
833        /*
834         * if we set the serial here, then we'll never do a
835         * match() again, if !IsCapable()
836         */
837 <      target_p->from->serial = current_serial;
921 <      found++;
837 >      target_p->from->localClient->serial = current_serial;
838  
839        if (!IsCapable(target_p->from, cap))
840          continue;
841  
842 <      sendto_anywhere(target_p, source_p, "%s", buffer);
842 >      send_message_remote(target_p->from, source_p, buff_suid);
843      }
844    }
845 +
846 +  dbuf_ref_free(buff_suid);
847   }
848  
849   /* sendto_anywhere()
# Line 939 | Line 857 | sendto_match_servs(struct Client *source
857   */
858   void
859   sendto_anywhere(struct Client *to, struct Client *from,
860 +                const char *command,
861                  const char *pattern, ...)
862   {
863    va_list args;
864 <  char buffer[IRCD_BUFSIZE];
946 <  int len;
947 <  struct Client *send_to = (to->from != NULL ? to->from : to);
864 >  struct dbuf_block *buffer = NULL;
865  
866 <  if (IsDead(send_to))
866 >  if (IsDead(to->from))
867      return;
868  
869 <  if (MyClient(to))
870 <  {
871 <    if (IsServer(from))
872 <    {
873 <      if (IsCapable(to, CAP_TS6) && HasID(from))
874 <        len = ircsprintf(buffer, ":%s ", from->id);
875 <      else
876 <        len = ircsprintf(buffer, ":%s ", from->name);
960 <    }
961 <    else
962 <      len = ircsprintf(buffer, ":%s!%s@%s ",
963 <                       from->name, from->username, from->host);
964 <  }
965 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
869 >  buffer = dbuf_alloc();
870 >
871 >  if (MyClient(to) && IsClient(from))
872 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
873 >                 from->host, command, to->name);
874 >  else
875 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
876 >                 command, ID_or_name(to, to));
877  
878    va_start(args, pattern);
879 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
879 >  send_format(buffer, pattern, args);
880    va_end(args);
881  
882 <  if(MyClient(to))
883 <    send_message(send_to, buffer, len);
882 >  if (MyClient(to))
883 >    send_message(to, buffer);
884    else
885 <    send_message_remote(send_to, from, buffer, len);
885 >    send_message_remote(to, from, buffer);
886 >
887 >  dbuf_ref_free(buffer);
888   }
889  
890   /* sendto_realops_flags()
# Line 983 | Line 896 | sendto_anywhere(struct Client *to, struc
896   * side effects - Send to *local* ops only but NOT +s nonopers.
897   */
898   void
899 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
899 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
900   {
901 <  struct Client *client_p;
902 <  char nbuf[IRCD_BUFSIZE];
903 <  dlink_node *ptr;
901 >  const char *ntype = NULL;
902 >  dlink_node *ptr = NULL;
903 >  char nbuf[IRCD_BUFSIZE] = "";
904    va_list args;
905  
906    va_start(args, pattern);
907 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
907 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
908    va_end(args);
909  
910 <  DLINK_FOREACH(ptr, oper_list.head)
910 >  switch (type)
911    {
912 <    client_p = ptr->data;
913 <    assert(client_p->umodes & UMODE_OPER);
914 <
915 <    /* If we're sending it to opers and theyre an admin, skip.
916 <     * If we're sending it to admins, and theyre not, skip.
917 <     */
918 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
919 <        ((level == L_OPER) && IsAdmin(client_p)))
920 <      continue;
921 <
922 <    if (client_p->umodes & flags)
1010 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1011 <                 me.name, client_p->name, nbuf);
912 >    case SEND_NOTICE:
913 >      ntype = "Notice";
914 >      break;
915 >    case SEND_GLOBAL:
916 >      ntype = "Global";
917 >      break;
918 >    case SEND_LOCOPS:
919 >      ntype = "LocOps";
920 >      break;
921 >    default:
922 >      assert(0);
923    }
1013 }
1014
1015 /* sendto_wallops_flags()
1016 *
1017 * inputs       - flag types of messages to show to real opers
1018 *              - client sending request
1019 *              - var args input message
1020 * output       - NONE
1021 * side effects - Send a wallops to local opers
1022 */
1023 void
1024 sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1025                     const char *pattern, ...)
1026 {
1027  struct Client *client_p;
1028  dlink_node *ptr;
1029  va_list args;
1030  char buffer[IRCD_BUFSIZE];
1031  int len;
1032
1033  if (IsClient(source_p))
1034    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1035                     source_p->name, source_p->username, source_p->host);
1036  else
1037    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
1038
1039  va_start(args, pattern);
1040  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1041  va_end(args);
924  
925    DLINK_FOREACH(ptr, oper_list.head)
926    {
927 <    client_p = ptr->data;
928 <    assert(client_p->umodes & UMODE_OPER);
927 >    struct Client *client_p = ptr->data;
928 >    assert(HasUMode(client_p, UMODE_OPER));
929  
930 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
931 <      send_message(client_p, buffer, len);
930 >    /*
931 >     * If we're sending it to opers and they're an admin, skip.
932 >     * If we're sending it to admins, and they're not, skip.
933 >     */
934 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
935 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
936 >      continue;
937 >
938 >    if (HasUMode(client_p, flags))
939 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
940 >                 me.name, client_p->name, ntype, nbuf);
941    }
942   }
943  
944   /* ts_warn()
945   *
946 < * inputs       - var args message
947 < * output       - NONE
948 < * side effects - Call sendto_realops_flags, with some flood checking
949 < *                (at most 5 warnings every 5 seconds)
946 > * inputs       - var args message
947 > * output       - NONE
948 > * side effects - Call sendto_realops_flags, with some flood checking
949 > *                (at most 5 warnings every 5 seconds)
950   */
951   void
952 < ts_warn(const char *pattern, ...)
952 > sendto_realops_flags_ratelimited(const char *pattern, ...)
953   {
954    va_list args;
955 <  char buffer[LOG_BUFSIZE];
955 >  char buffer[IRCD_BUFSIZE] = "";
956    static time_t last = 0;
957    static int warnings = 0;
958  
# Line 1084 | Line 975 | ts_warn(const char *pattern, ...)
975    }
976  
977    va_start(args, pattern);
978 <  vsprintf_irc(buffer, pattern, args);
978 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
979    va_end(args);
980  
981 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
982 <  ilog(L_CRIT, "%s", buffer);
981 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
982 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
983   }
984  
985 < /* kill_client()
985 > /* sendto_wallops_flags()
986   *
987 < * inputs       - client to send kill towards
988 < *              - pointer to client to kill
989 < *              - reason for kill
990 < * output       - NONE
991 < * side effects - NONE
987 > * inputs       - flag types of messages to show to real opers
988 > *              - client sending request
989 > *              - var args input message
990 > * output       - NONE
991 > * side effects - Send a wallops to local opers
992   */
993   void
994 < kill_client(struct Client *client_p, struct Client *diedie,
995 <            const char *pattern, ...)
994 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
995 >                     const char *pattern, ...)
996   {
997 +  dlink_node *ptr = NULL;
998    va_list args;
999 <  char buffer[IRCD_BUFSIZE];
1108 <  int len;
999 >  struct dbuf_block *buffer;
1000  
1001 <  if (client_p->from != NULL)
1111 <    client_p = client_p->from;
1112 <  if (IsDead(client_p))
1113 <    return;
1001 >  buffer = dbuf_alloc();
1002  
1003 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1004 <                   ID_or_name(diedie, client_p));
1005 <
1006 <  va_start(args, pattern);
1119 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1120 <  va_end(args);
1121 <
1122 <  send_message(client_p, buffer, len);
1123 < }
1124 <
1125 < /* kill_client_ll_serv_butone()
1126 < *
1127 < * inputs       - pointer to client to not send to
1128 < *              - pointer to client to kill
1129 < * output       - NONE
1130 < * side effects - Send a KILL for the given client
1131 < *                message to all connected servers
1132 < *                except the client 'one'. Also deal with
1133 < *                client being unknown to leaf, as in lazylink...
1134 < */
1135 < void
1136 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1137 <                           const char *pattern, ...)
1138 < {
1139 <  va_list args;
1140 <  int have_uid = 0;
1141 <  dlink_node *ptr = NULL;
1142 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1143 <  int len_uid = 0, len_nick = 0;
1144 <
1145 <  if (HasID(source_p) && (me.id[0] != '\0'))
1146 <  {
1147 <    have_uid = 1;
1148 <    va_start(args, pattern);
1149 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1150 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1151 <                           args);
1152 <    va_end(args);
1153 <  }
1003 >  if (IsClient(source_p))
1004 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
1005 >  else
1006 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
1007  
1008    va_start(args, pattern);
1009 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1157 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1158 <                          args);
1009 >  send_format(buffer, pattern, args);
1010    va_end(args);
1011  
1012 <  DLINK_FOREACH(ptr, serv_list.head)
1012 >  DLINK_FOREACH(ptr, oper_list.head)
1013    {
1014      struct Client *client_p = ptr->data;
1015 +    assert(client_p->umodes & UMODE_OPER);
1016  
1017 <    if (one != NULL && (client_p == one->from))
1018 <      continue;
1167 <    if (IsDefunct(client_p))
1168 <      continue;
1169 <
1170 <    if (have_uid && IsCapable(client_p, CAP_TS6))
1171 <      send_message(client_p, buf_uid, len_uid);
1172 <    else
1173 <      send_message(client_p, buf_nick, len_nick);
1017 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
1018 >      send_message(client_p, buffer);
1019    }
1020 < }
1020 >
1021 >  dbuf_ref_free(buffer);
1022 > }

Diff Legend

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