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 34 by lusky, Sun Oct 2 21:05:51 2005 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 4461 by michael, Wed Aug 13 17:05:26 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"
38 > #include "server.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "memory.h"
44 #include "hook.h"
45 #include "irc_getnameinfo.h"
42   #include "packet.h"
43  
48 #define LOG_BUFSIZE 2048
44  
45 < struct Callback *iosend_cb = NULL;
51 < struct Callback *iosendctrl_cb = NULL;
45 > static unsigned int current_serial = 0;
46  
53 static void send_message(struct Client *, char *, int);
54 static void send_message_remote(struct Client *, struct Client *, char *, int);
55
56 static unsigned long current_serial = 0L;
47  
48   /* send_format()
49   *
50 < * inputs       - buffer to format into
51 < *              - size of the buffer
50 > * inputs
51 > *              - buffer
52   *              - format pattern to use
53   *              - var args
54   * output       - number of bytes formatted output
55   * side effects - modifies sendbuf
56   */
57 < static inline int
58 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
57 > static void
58 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
59   {
70  int len;
71
60    /*
61     * from rfc1459
62     *
63     * IRC messages are always lines of characters terminated with a CR-LF
64     * (Carriage Return - Line Feed) pair, and these messages shall not
65 <   * exceed 512 characters in length,  counting all characters
65 >   * exceed 512 characters in length,  counting all characters
66     * including the trailing CR-LF.
67     * Thus, there are 510 characters maximum allowed
68     * for the command and its parameters.  There is no provision for
69     * continuation message lines.  See section 7 for more details about
70     * current implementations.
71     */
72 <  len = vsnprintf(lsendbuf, bufsize - 1, pattern, args);
73 <  if (len > bufsize - 2)
74 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
75 <
76 <  lsendbuf[len++] = '\r';
77 <  lsendbuf[len++] = '\n';
78 <  return (len);
72 >  dbuf_put_args(buffer, pattern, args);
73 >
74 >  if (buffer->size > sizeof(buffer->data) - 2)
75 >    buffer->size = sizeof(buffer->data) - 2;
76 >
77 >  buffer->data[buffer->size++] = '\r';
78 >  buffer->data[buffer->size++] = '\n';
79   }
80  
81   /*
# Line 96 | Line 84 | send_format(char *lsendbuf, int bufsize,
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 < #ifdef INVARIANTS
90 <  if (IsMe(to))
103 <  {
104 <    sendto_realops_flags(UMODE_ALL, L_ALL,
105 <                         "Trying to send message to myself!");
106 <    return;
107 <  }
108 < #endif
89 >  assert(!IsMe(to));
90 >  assert(to != &me);
91  
92 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
92 >  if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs))
93    {
94      if (IsServer(to))
95 <      sendto_realops_flags(UMODE_ALL, L_ALL,
96 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
95 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
96 >                           "Max SendQ limit exceeded for %s: %lu > %u",
97                             get_client_name(to, HIDE_IP),
98 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
99 <                           get_sendq(to));
98 >                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size),
99 >                           get_sendq(&to->localClient->confs));
100      if (IsClient(to))
101        SetSendQExceeded(to);
102 +
103      dead_link_on_write(to, 0);
104      return;
105    }
106  
107 <  dbuf_put(&to->localClient->buf_sendq, buf, len);
107 >  dbuf_add(&to->localClient->buf_sendq, buf);
108  
109    /*
110 <   ** Update statistics. The following is slightly incorrect
111 <   ** because it counts messages even if queued, but bytes
112 <   ** only really sent. Queued bytes get updated in SendQueued.
110 >   * Update statistics. The following is slightly incorrect because
111 >   * it counts messages even if queued, but bytes only really sent.
112 >   * Queued bytes get updated in send_queued_write().
113     */
114    ++to->localClient->send.messages;
115    ++me.localClient->send.messages;
116  
117 <  if (dbuf_length(&to->localClient->buf_sendq) >
135 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
136 <    send_queued_write(to);
117 >  send_queued_write(to);
118   }
119  
120   /* send_message_remote()
121   *
122   * inputs       - pointer to client from message is being sent
123   *              - pointer to client to send to
124 < *              - pointer to preformatted buffer
144 < *              - length of input buffer
124 > *              - pointer to buffer
125   * output       - none
126   * side effects - Despite the function name, this only sends to directly
127   *                connected clients.
128 < *
128 > *
129   */
130   static void
131 < send_message_remote(struct Client *to, struct Client *from,
152 <                    char *buf, int len)
131 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
132   {
133 +  to = to->from;
134 +
135    if (!MyConnect(to))
136    {
137 <    sendto_realops_flags(UMODE_ALL, L_ALL,
138 <                         "server send message to %s [%s] dropped from %s(Not local server)",
139 <                         to->name, to->from->name, from->name);
137 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
138 >                         "Server send message to %s [%s] dropped from %s(Not local server)",
139 >                         to->name, to->from->name, from->name);
140      return;
141    }
142  
162  if (ServerInfo.hub && IsCapable(to, CAP_LL))
163  {
164    if (((from->lazyLinkClientExists &
165          to->localClient->serverMask) == 0))
166      client_burst_if_needed(to, from);
167  }
168
143    /* Optimize by checking if (from && to) before everything */
144    /* we set to->from up there.. */
145  
# Line 173 | Line 147 | send_message_remote(struct Client *to, s
147    {
148      if (IsServer(from))
149      {
150 <      sendto_realops_flags(UMODE_ALL, L_ALL,
150 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
151                             "Send message to %s [%s] dropped from %s(Fake Dir)",
152                             to->name, to->from->name, from->name);
153        return;
154      }
155  
156 <    sendto_realops_flags(UMODE_ALL, L_ALL,
156 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
157                           "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
158                           to->name, to->username, to->host,
159                           from->name, from->username, from->host,
160                           to->from->name);
161  
162 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
189 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
190 <                  me.id, to->name, me.name, to->name,
191 <                  to->username, to->host, to->from->name);
192 <    sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS,
162 >    sendto_server(NULL, NOCAPS, NOCAPS,
163                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
164 <                  me.name, to->name, me.name, to->name,
164 >                  me.id, to->id, me.name, to->name,
165                    to->username, to->host, to->from->name);
166  
167 <    SetKilled(to);
167 >    AddFlag(to, FLAGS_KILLED);
168  
169      if (IsClient(from))
170 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
171 <                 me.name, from->name, to->name, to->username,
202 <                 to->host, to->from);
203 <
204 <    exit_client(to, &me, "Ghosted client");
170 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
171 >                         to->username, to->host, to->from);
172  
173 +    exit_client(to, "Ghosted client");
174      return;
175 <  }
175 >  }
176  
177 <  send_message(to, buf, len);
177 >  send_message(to, buf);
178   }
179  
180   /*
# Line 214 | Line 182 | send_message_remote(struct Client *to, s
182   **      Called when a socket is ready for writing.
183   */
184   void
185 < sendq_unblocked(fde_t *fd, struct Client *client_p)
185 > sendq_unblocked(fde_t *fd, void *data)
186   {
187 <  ClearSendqBlocked(client_p);
188 <  /* let send_queued_write be executed by send_queued_all */
221 <
222 < #ifdef HAVE_LIBCRYPTO
223 <  if (fd->flags.pending_read)
224 <  {
225 <    fd->flags.pending_read = 0;
226 <    read_packet(fd, client_p);
227 <  }
228 < #endif
229 < }
187 >  struct Client *client_p = data;
188 >  assert(fd == &client_p->localClient->fd);
189  
190 < /*
191 < ** slinkq_unblocked
233 < **      Called when a server control socket is ready for writing.
234 < */
235 < static void
236 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
237 < {
238 <  ClearSlinkqBlocked(client_p);
239 <  send_queued_slink_write(client_p);
190 >  DelFlag(client_p, FLAGS_BLOCKED);
191 >  send_queued_write(client_p);
192   }
193  
194   /*
# Line 248 | Line 200 | slinkq_unblocked(fde_t *fd, struct Clien
200   void
201   send_queued_write(struct Client *to)
202   {
203 <  int retlen;
252 <  struct dbuf_block *first;
203 >  int retlen = 0;
204  
205    /*
206     ** Once socket is marked dead, we cannot start writing to it,
207     ** even if the error is removed...
208     */
209 <  if (IsDead(to) || IsSendqBlocked(to))
209 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
210      return;  /* no use calling send() now */
211  
212    /* Next, lets try to write some data */
262
213    if (dbuf_length(&to->localClient->buf_sendq))
214    {
215 <    do {
216 <      first = to->localClient->buf_sendq.blocks.head->data;
215 >    do
216 >    {
217 >      struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data;
218  
219   #ifdef HAVE_LIBCRYPTO
220        if (to->localClient->fd.ssl)
221        {
222 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
222 >        retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos);
223  
224          /* translate openssl error codes, sigh */
225 <        if (retlen < 0)
226 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
227 <          {
225 >        if (retlen < 0)
226 >        {
227 >          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
228 >          {
229              case SSL_ERROR_WANT_READ:
230 <              return;  /* retry later, don't register for write events */
231 <
232 <            case SSL_ERROR_WANT_WRITE:
281 <              errno = EWOULDBLOCK;
230 >              return;  /* retry later, don't register for write events */
231 >            case SSL_ERROR_WANT_WRITE:
232 >              errno = EWOULDBLOCK;
233              case SSL_ERROR_SYSCALL:
234 <              break;
235 <
234 >              break;
235 >            case SSL_ERROR_SSL:
236 >              if (errno == EAGAIN)
237 >                break;
238              default:
239 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
240 <          }
239 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
240 >          }
241 >        }
242        }
243        else
244   #endif
245 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
245 >        retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0);
246  
247        if (retlen <= 0)
294      {
295 #ifdef _WIN32
296        errno = WSAGetLastError();
297 #endif
248          break;
299      }
249  
301      execute_callback(iosend_cb, to, retlen, first->data);
250        dbuf_delete(&to->localClient->buf_sendq, retlen);
251  
252        /* We have some data written .. update counters */
# Line 306 | Line 254 | send_queued_write(struct Client *to)
254        me.localClient->send.bytes += retlen;
255      } while (dbuf_length(&to->localClient->buf_sendq));
256  
257 <    if ((retlen < 0) && (ignoreErrno(errno)))
257 >    if (retlen < 0 && ignoreErrno(errno))
258      {
259 +      AddFlag(to, FLAGS_BLOCKED);
260 +
261        /* we have a non-fatal error, reschedule a write */
312      SetSendqBlocked(to);
262        comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
263 <                     (PF *)sendq_unblocked, (void *)to, 0);
263 >                     sendq_unblocked, to, 0);
264      }
265      else if (retlen <= 0)
266      {
# Line 321 | Line 270 | send_queued_write(struct Client *to)
270    }
271   }
272  
324 /*
325 ** send_queued_slink_write
326 **      This is called when there is a chance the some output would
327 **      be possible. This attempts to empty the send queue as far as
328 **      possible, and then if any data is left, a write is rescheduled.
329 */
330 void
331 send_queued_slink_write(struct Client *to)
332 {
333  int retlen;
334
335  /*
336   ** Once socket is marked dead, we cannot start writing to it,
337   ** even if the error is removed...
338   */
339  if (IsDead(to) || IsSlinkqBlocked(to))
340    return;  /* no use calling send() now */
341
342  /* Next, lets try to write some data */
343  if (to->localClient->slinkq != NULL)
344  {
345    retlen = send(to->localClient->ctrlfd.fd,
346                   to->localClient->slinkq + to->localClient->slinkq_ofs,
347                   to->localClient->slinkq_len, 0);
348    if (retlen < 0)
349    {
350      /* If we have a fatal error */
351      if (!ignoreErrno(errno))
352      {
353        dead_link_on_write(to, errno);
354        return;
355      }
356    }
357    else if (retlen == 0)
358    {
359      /* 0 bytes is an EOF .. */
360      dead_link_on_write(to, 0);
361      return;
362    }
363    else
364    {
365      execute_callback(iosendctrl_cb, to, retlen,
366        to->localClient->slinkq + to->localClient->slinkq_ofs);
367      to->localClient->slinkq_len -= retlen;
368
369      assert(to->localClient->slinkq_len >= 0);
370      if (to->localClient->slinkq_len)
371        to->localClient->slinkq_ofs += retlen;
372      else
373      {
374        to->localClient->slinkq_ofs = 0;
375        MyFree(to->localClient->slinkq);
376        to->localClient->slinkq = NULL;
377      }
378    }
379
380    /* Finally, if we have any more data, reschedule a write */
381    if (to->localClient->slinkq_len)
382    {
383      SetSlinkqBlocked(to);
384      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
385                     (PF *)slinkq_unblocked, (void *)to, 0);
386    }
387  }
388 }
389
273   /* send_queued_all()
274   *
275   * input        - NONE
# Line 401 | Line 284 | send_queued_all(void)
284    /* Servers are processed first, mainly because this can generate
285     * a notice to opers, which is to be delivered by this function.
286     */
287 <  DLINK_FOREACH(ptr, serv_list.head)
288 <    send_queued_write((struct Client *) ptr->data);
287 >  DLINK_FOREACH(ptr, local_server_list.head)
288 >    send_queued_write(ptr->data);
289  
290    DLINK_FOREACH(ptr, unknown_list.head)
291 <    send_queued_write((struct Client *) ptr->data);
291 >    send_queued_write(ptr->data);
292  
293    DLINK_FOREACH(ptr, local_client_list.head)
294 <    send_queued_write((struct Client *) ptr->data);
294 >    send_queued_write(ptr->data);
295  
296    /* NOTE: This can still put clients on aborted_list; unfortunately,
297     * exit_aborted_clients takes precedence over send_queued_all,
# Line 429 | Line 312 | void
312   sendto_one(struct Client *to, const char *pattern, ...)
313   {
314    va_list args;
315 <  char buffer[IRCD_BUFSIZE];
316 <  int len;
315 >  struct dbuf_block *buffer = NULL;
316 >
317 >  if (IsDead(to->from))
318 >    return;  /* This socket has already been marked as dead */
319  
320 <  if (to->from != NULL)
436 <    to = to->from;
437 <  if (IsDead(to))
438 <    return; /* This socket has already been marked as dead */
320 >  buffer = dbuf_alloc();
321  
322    va_start(args, pattern);
323 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
323 >  send_format(buffer, pattern, args);
324    va_end(args);
325  
326 <  send_message(to, buffer, len);
326 >  send_message(to->from, buffer);
327 >
328 >  dbuf_ref_free(buffer);
329 > }
330 >
331 > void
332 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
333 > {
334 >  struct dbuf_block *buffer = NULL;
335 >  const char *dest = NULL, *numstr = NULL;
336 >  va_list args;
337 >
338 >  if (IsDead(to->from))
339 >    return;
340 >
341 >  dest = ID_or_name(to, to);
342 >
343 >  if (EmptyString(dest))
344 >    dest = "*";
345 >
346 >  buffer = dbuf_alloc();
347 >
348 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
349 >
350 >  va_start(args, numeric);
351 >
352 >  if (numeric & SND_EXPLICIT)
353 >    numstr = va_arg(args, const char *);
354 >  else
355 >    numstr = numeric_form(numeric);
356 >  send_format(buffer, numstr, args);
357 >  va_end(args);
358 >
359 >  send_message(to->from, buffer);
360 >
361 >  dbuf_ref_free(buffer);
362 > }
363 >
364 > void
365 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
366 > {
367 >  struct dbuf_block *buffer = NULL;
368 >  const char *dest = NULL;
369 >  va_list args;
370 >
371 >  if (IsDead(to->from))
372 >    return;
373 >
374 >  dest = ID_or_name(to, to);
375 >
376 >  if (EmptyString(dest))
377 >    dest = "*";
378 >
379 >  buffer = dbuf_alloc();
380 >
381 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
382 >
383 >  va_start(args, pattern);
384 >  send_format(buffer, pattern, args);
385 >  va_end(args);
386 >
387 >  send_message(to->from, buffer);
388 >
389 >  dbuf_ref_free(buffer);
390   }
391  
392   /* sendto_channel_butone()
# Line 457 | Line 402 | sendto_one(struct Client *to, const char
402   */
403   void
404   sendto_channel_butone(struct Client *one, struct Client *from,
405 <                      struct Channel *chptr, const char *command,
405 >                      struct Channel *chptr, unsigned int type,
406                        const char *pattern, ...)
407   {
408 <  va_list args;
409 <  char local_buf[IRCD_BUFSIZE];
410 <  char remote_buf[IRCD_BUFSIZE];
466 <  char uid_buf[IRCD_BUFSIZE];
467 <  int local_len, remote_len, uid_len;
468 <  dlink_node *ptr;
469 <  dlink_node *ptr_next;
470 <  struct Client *target_p;
408 >  va_list alocal, aremote;
409 >  struct dbuf_block *local_buf, *remote_buf;
410 >  dlink_node *ptr = NULL, *ptr_next = NULL;
411  
412 <  if (IsServer(from))
413 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
414 <                           from->name, command, chptr->chname);
412 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
413 >
414 >  if (IsClient(from))
415 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
416    else
417 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
477 <                           from->name, from->username, from->host,
478 <                           command, chptr->chname);
479 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
480 <                          from->name, command, chptr->chname);
481 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
482 <                       ID(from), command, chptr->chname);
417 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
418  
419 <  va_start(args, pattern);
420 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
421 <                           pattern, args);
422 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
423 <                            pattern, args);
424 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
425 <                         args);
426 <  va_end(args);
419 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
420 >
421 >  va_start(alocal, pattern);
422 >  va_start(aremote, pattern);
423 >  send_format(local_buf, pattern, alocal);
424 >  send_format(remote_buf, pattern, aremote);
425 >
426 >  va_end(aremote);
427 >  va_end(alocal);
428  
429    ++current_serial;
430  
431    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
432    {
433 <    target_p = ((struct Membership *)ptr->data)->client_p;
434 <    assert(target_p != NULL);
433 >    struct Membership *ms = ptr->data;
434 >    struct Client *target_p = ms->client_p;
435 >
436 >    assert(IsClient(target_p));
437  
438 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
438 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
439 >        (one && target_p->from == one->from))
440        continue;
441  
442 <    if (MyClient(target_p))
443 <    {
444 <      if (target_p->serial != current_serial)
445 <      {
446 <        send_message(target_p, local_buf, local_len);
447 <        target_p->serial = current_serial;
448 <      }
449 <    }
511 <    else
512 <    {
513 <      /* Now check whether a message has been sent to this
514 <       * remote link already
515 <       */
516 <      if (target_p->from->serial != current_serial)
517 <      {
518 <        if (IsCapable(target_p->from, CAP_TS6))
519 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
520 <        else
521 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
522 <        target_p->from->serial = current_serial;
523 <      }
524 <    }
442 >    if (type && (ms->flags & type) == 0)
443 >      continue;
444 >
445 >    if (MyConnect(target_p))
446 >      send_message(target_p, local_buf);
447 >    else if (target_p->from->localClient->serial != current_serial)
448 >      send_message_remote(target_p->from, from, remote_buf);
449 >    target_p->from->localClient->serial = current_serial;
450    }
451 +
452 +  dbuf_ref_free(local_buf);
453 +  dbuf_ref_free(remote_buf);
454   }
455  
456   /* sendto_server()
457 < *
457 > *
458   * inputs       - pointer to client to NOT send to
459 < *              - pointer to source client required by LL (if any)
532 < *              - pointer to channel required by LL (if any)
459 > *              - pointer to channel
460   *              - caps or'd together which must ALL be present
461   *              - caps or'd together which must ALL NOT be present
535 *              - LL flags: LL_ICLIENT | LL_ICHAN
462   *              - printf style format string
463   *              - args to format string
464   * output       - NONE
465   * side effects - Send a message to all connected servers, except the
466   *                client 'one' (if non-NULL), as long as the servers
467   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
468 < *                If the server is a lazylink client, then it must know
543 < *                about source_p if non-NULL (unless LL_ICLIENT is specified,
544 < *                when source_p will be introduced where required) and
545 < *                chptr if non-NULL (unless LL_ICHANNEL is specified, when
546 < *                chptr will be introduced where required).
547 < *                Note: nothing will be introduced to a LazyLeaf unless
548 < *                the message is actually sent.
549 < *            
468 > *
469   * This function was written in an attempt to merge together the other
470   * billion sendto_*serv*() functions, which sprung up with capabs,
471   * lazylinks, uids, etc.
472   * -davidt
473   */
474 < void
475 < sendto_server(struct Client *one, struct Client *source_p,
476 <              struct Channel *chptr, unsigned long caps,
477 <              unsigned long nocaps, unsigned long llflags,
474 > void
475 > sendto_server(struct Client *one,
476 >              const unsigned int caps,
477 >              const unsigned int nocaps,
478                const char *format, ...)
479   {
480    va_list args;
481 <  struct Client *client_p;
482 <  dlink_node *ptr;
564 <  char buffer[IRCD_BUFSIZE];
565 <  int len;
481 >  dlink_node *ptr = NULL;
482 >  struct dbuf_block *buffer;
483  
484 <  if (chptr != NULL)
568 <  {
569 <    if (chptr->chname[0] != '#')
570 <      return;
571 <  }
484 >  buffer = dbuf_alloc();
485  
486    va_start(args, format);
487 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
487 >  send_format(buffer, format, args);
488    va_end(args);
489  
490 <  DLINK_FOREACH(ptr, serv_list.head)
490 >  DLINK_FOREACH(ptr, local_server_list.head)
491    {
492 <    client_p = ptr->data;
492 >    struct Client *client_p = ptr->data;
493  
494      /* If dead already skip */
495      if (IsDead(client_p))
496        continue;
497      /* check against 'one' */
498 <    if (one != NULL && (client_p == one->from))
498 >    if (one && (client_p == one->from))
499        continue;
500      /* check we have required capabs */
501      if ((client_p->localClient->caps & caps) != caps)
502        continue;
503      /* check we don't have any forbidden capabs */
504 <    if ((client_p->localClient->caps & nocaps) != 0)
504 >    if ((client_p->localClient->caps & nocaps))
505        continue;
506  
507 <    if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
595 <    {
596 <      /* check LL channel */
597 <      if (chptr != NULL &&
598 <          ((chptr->lazyLinkChannelExists &
599 <            client_p->localClient->serverMask) == 0))
600 <      {
601 <        /* Only introduce the channel if we really will send this message */
602 <        if (!(llflags & LL_ICLIENT) && source_p &&
603 <            ((source_p->lazyLinkClientExists &
604 <              client_p->localClient->serverMask) == 0))
605 <          continue; /* we can't introduce the unknown source_p, skip */
606 <
607 <        if (llflags & LL_ICHAN)
608 <          burst_channel(client_p, chptr);
609 <        else
610 <          continue; /* we can't introduce the unknown chptr, skip */
611 <      }
612 <      /* check LL client */
613 <      if (source_p &&
614 <          ((source_p->lazyLinkClientExists &
615 <            client_p->localClient->serverMask) == 0))
616 <      {
617 <        if (llflags & LL_ICLIENT)
618 <          client_burst_if_needed(client_p,source_p);
619 <        else
620 <          continue; /* we can't introduce the unknown source_p, skip */
621 <      }
622 <    }
623 <    send_message(client_p, buffer, len);
507 >    send_message(client_p, buffer);
508    }
509 +
510 +  dbuf_ref_free(buffer);
511   }
512  
513   /* sendto_common_channels_local()
# Line 630 | Line 516 | sendto_server(struct Client *one, struct
516   *              - pattern to send
517   * output       - NONE
518   * side effects - Sends a message to all people on local server who are
519 < *                in same channel with user.
519 > *                in same channel with user.
520   *                used by m_nick.c and exit_one_client.
521   */
522   void
523 < sendto_common_channels_local(struct Client *user, int touser,
523 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
524                               const char *pattern, ...)
525   {
526    va_list args;
# Line 643 | Line 529 | sendto_common_channels_local(struct Clie
529    struct Channel *chptr;
530    struct Membership *ms;
531    struct Client *target_p;
532 <  char buffer[IRCD_BUFSIZE];
533 <  int len;
532 >  struct dbuf_block *buffer;
533 >
534 >  buffer = dbuf_alloc();
535  
536    va_start(args, pattern);
537 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
537 >  send_format(buffer, pattern, args);
538    va_end(args);
539  
540    ++current_serial;
541  
542    DLINK_FOREACH(cptr, user->channel.head)
543    {
544 <    chptr = ((struct Membership *) cptr->data)->chptr;
658 <    assert(chptr != NULL);
544 >    chptr = ((struct Membership *)cptr->data)->chptr;
545  
546      DLINK_FOREACH(uptr, chptr->locmembers.head)
547      {
548        ms = uptr->data;
549        target_p = ms->client_p;
664      assert(target_p != NULL);
550  
551        if (target_p == user || IsDefunct(target_p) ||
552 <          target_p->serial == current_serial)
552 >          target_p->localClient->serial == current_serial)
553 >        continue;
554 >
555 >      if (HasCap(target_p, cap) != cap)
556          continue;
557  
558 <      target_p->serial = current_serial;
559 <      send_message(target_p, buffer, len);
558 >      target_p->localClient->serial = current_serial;
559 >      send_message(target_p, buffer);
560      }
561    }
562  
563    if (touser && MyConnect(user) && !IsDead(user) &&
564 <      user->serial != current_serial)
565 <    send_message(user, buffer, len);
564 >      user->localClient->serial != current_serial)
565 >    if (HasCap(user, cap) == cap)
566 >      send_message(user, buffer);
567 >
568 >  dbuf_ref_free(buffer);
569   }
570  
571   /* sendto_channel_local()
# Line 688 | Line 579 | sendto_common_channels_local(struct Clie
579   *                locally connected to this server.
580   */
581   void
582 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
582 > sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
583                       const char *pattern, ...)
584   {
585    va_list args;
586 <  char buffer[IRCD_BUFSIZE];
587 <  int len;
588 <  dlink_node *ptr;
589 <  struct Membership *ms;
699 <  struct Client *target_p;
586 >  dlink_node *ptr = NULL;
587 >  struct dbuf_block *buffer;
588 >
589 >  buffer = dbuf_alloc();
590  
591    va_start(args, pattern);
592 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
592 >  send_format(buffer, pattern, args);
593    va_end(args);
594  
595    DLINK_FOREACH(ptr, chptr->locmembers.head)
596    {
597 <    ms = ptr->data;
598 <    target_p = ms->client_p;
597 >    struct Membership *ms = ptr->data;
598 >    struct Client *target_p = ms->client_p;
599  
600 <    if (type != 0 && (ms->flags & type) == 0)
600 >    if (type && (ms->flags & type) == 0)
601        continue;
602  
603 <    if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
603 >    if (IsDefunct(target_p) ||
604 >        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
605        continue;
606  
607 <    send_message(target_p, buffer, len);
607 >    send_message(target_p, buffer);
608    }
609 +
610 +  dbuf_ref_free(buffer);
611   }
612  
613   /* sendto_channel_local_butone()
# Line 729 | Line 622 | sendto_channel_local(int type, int nodea
622   *
623   * WARNING - +D clients are omitted
624   */
732 void      
733 sendto_channel_local_butone(struct Client *one, int type,
734                            struct Channel *chptr, const char *pattern, ...)
735 {
736  va_list args;
737  char buffer[IRCD_BUFSIZE];
738  int len;
739  struct Client *target_p;
740  struct Membership *ms;
741  dlink_node *ptr;
742
743  va_start(args, pattern);
744  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
745  va_end(args);
746
747  DLINK_FOREACH(ptr, chptr->locmembers.head)      
748  {  
749    ms = ptr->data;
750    target_p = ms->client_p;
751
752    if (type != 0 && (ms->flags & type) == 0)
753      continue;
754
755    if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p))
756      continue;
757    send_message(target_p, buffer, len);
758  }
759 }
760
761
762 /* sendto_channel_remote()
763 *
764 * inputs       - Client not to send towards
765 *              - Client from whom message is from
766 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
767 *              - pointer to channel to send to
768 *              - var args pattern
769 * output       - NONE
770 * side effects - Send a message to all members of a channel that are
771 *                remote to this server.
772 */
625   void
626 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
627 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
626 > sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
627 >                            struct Channel *chptr, const char *pattern, ...)
628   {
629    va_list args;
630 <  char buffer[IRCD_BUFSIZE];
631 <  int len;
632 <  dlink_node *ptr;
633 <  struct Client *target_p;
782 <  struct Membership *ms;
630 >  dlink_node *ptr = NULL;
631 >  struct dbuf_block *buffer;
632 >
633 >  buffer = dbuf_alloc();
634  
635    va_start(args, pattern);
636 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
636 >  send_format(buffer, pattern, args);
637    va_end(args);
638  
639 <  DLINK_FOREACH(ptr, chptr->members.head)
639 >  DLINK_FOREACH(ptr, chptr->locmembers.head)
640    {
641 <    ms = ptr->data;
642 <    target_p = ms->client_p;
641 >    struct Membership *ms = ptr->data;
642 >    struct Client *target_p = ms->client_p;
643  
644 <    if (type != 0 && (ms->flags & type) == 0)
644 >    if (type && (ms->flags & type) == 0)
645        continue;
646  
647 <    if (MyConnect(target_p))
647 >    if (one && target_p == one->from)
648        continue;
798    target_p = target_p->from;
649  
650 <    if (target_p == one->from ||
801 <        ((target_p->from->localClient->caps & caps) != caps) ||
802 <        ((target_p->from->localClient->caps & nocaps) != 0))
650 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
651        continue;
652  
653 <    send_message(target_p, buffer, len);
654 <  }
653 >    if (HasCap(target_p, cap) != cap)
654 >      continue;
655 >
656 >    send_message(target_p, buffer);
657 >  }
658 >
659 >  dbuf_ref_free(buffer);
660   }
661  
662   /*
# Line 824 | Line 677 | sendto_channel_remote(struct Client *one
677   * side effects - NONE
678   */
679   static int
680 < match_it(const struct Client *one, const char *mask, int what)
680 > match_it(const struct Client *one, const char *mask, unsigned int what)
681   {
682    if (what == MATCH_HOST)
683 <    return(match(mask, one->host));
683 >    return !match(mask, one->host);
684  
685 <  return(match(mask, one->servptr->name));
685 >  return !match(mask, one->servptr->name);
686   }
687  
688   /* sendto_match_butone()
# Line 840 | Line 693 | match_it(const struct Client *one, const
693   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
694   */
695   void
696 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
696 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
697                      int what, const char *pattern, ...)
698   {
699 <  va_list args;
700 <  struct Client *client_p;
701 <  dlink_node *ptr, *ptr_next;
702 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
703 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
704 <                             from->username, from->host);
705 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
706 <
707 <  va_start(args, pattern);
708 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
709 <                           pattern, args);
710 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
711 <                            pattern, args);
712 <  va_end(args);
699 >  va_list alocal, aremote;
700 >  dlink_node *ptr = NULL, *ptr_next = NULL;
701 >  struct dbuf_block *local_buf, *remote_buf;
702 >
703 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
704 >
705 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
706 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
707 >
708 >  va_start(alocal, pattern);
709 >  va_start(aremote, pattern);
710 >  send_format(local_buf, pattern, alocal);
711 >  send_format(remote_buf, pattern, aremote);
712 >  va_end(aremote);
713 >  va_end(alocal);
714  
715    /* scan the local clients */
716    DLINK_FOREACH(ptr, local_client_list.head)
717    {
718 <    client_p = ptr->data;
718 >    struct Client *client_p = ptr->data;
719  
720 <    if (client_p != one && !IsDefunct(client_p) &&
720 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
721          match_it(client_p, mask, what))
722 <      send_message(client_p, local_buf, local_len);
722 >      send_message(client_p, local_buf);
723    }
724  
725    /* Now scan servers */
726 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
726 >  DLINK_FOREACH_SAFE(ptr, ptr_next, local_server_list.head)
727    {
728 <    client_p = ptr->data;
728 >    struct Client *client_p = ptr->data;
729  
730      /*
731       * The old code looped through every client on the
# Line 897 | Line 751 | sendto_match_butone(struct Client *one,
751       * server deal with it.
752       * -wnder
753       */
754 <    if (client_p != one && !IsDefunct(client_p))
755 <      send_message_remote(client_p, from, remote_buf, remote_len);
754 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
755 >      send_message_remote(client_p, from, remote_buf);
756    }
757 +
758 +  dbuf_ref_free(local_buf);
759 +  dbuf_ref_free(remote_buf);
760   }
761  
762   /* sendto_match_servs()
# Line 912 | Line 769 | sendto_match_butone(struct Client *one,
769   * side effects - data sent to servers matching with capab
770   */
771   void
772 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
772 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
773                     const char *pattern, ...)
774   {
775    va_list args;
776 <  struct Client *target_p;
777 <  dlink_node *ptr;
778 <  char buffer[IRCD_BUFSIZE];
779 <  int found = 0;
776 >  dlink_node *ptr = NULL, *ptr_next = NULL;
777 >  struct dbuf_block *buffer;
778 >
779 >  buffer = dbuf_alloc();
780  
781 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
782    va_start(args, pattern);
783 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
783 >  send_format(buffer, pattern, args);
784    va_end(args);
785  
786 <  current_serial++;
786 >  ++current_serial;
787  
788 <  DLINK_FOREACH(ptr, global_serv_list.head)
788 >  DLINK_FOREACH_SAFE(ptr, ptr_next, global_server_list.head)
789    {
790 <    target_p = ptr->data;
790 >    struct Client *target_p = ptr->data;
791  
792      /* Do not attempt to send to ourselves, or the source */
793      if (IsMe(target_p) || target_p->from == source_p->from)
794        continue;
795  
796 <    if (target_p->from->serial == current_serial)
796 >    if (target_p->from->localClient->serial == current_serial)
797        continue;
798  
799 <    if (match(mask, target_p->name))
799 >    if (!match(mask, target_p->name))
800      {
801        /*
802         * if we set the serial here, then we'll never do a
803         * match() again, if !IsCapable()
804         */
805 <      target_p->from->serial = current_serial;
948 <      found++;
805 >      target_p->from->localClient->serial = current_serial;
806  
807        if (!IsCapable(target_p->from, cap))
808          continue;
809  
810 <      sendto_anywhere(target_p, source_p, "%s", buffer);
810 >      send_message_remote(target_p->from, source_p, buffer);
811      }
812    }
813 +
814 +  dbuf_ref_free(buffer);
815   }
816  
817   /* sendto_anywhere()
# Line 966 | Line 825 | sendto_match_servs(struct Client *source
825   */
826   void
827   sendto_anywhere(struct Client *to, struct Client *from,
828 +                const char *command,
829                  const char *pattern, ...)
830   {
831    va_list args;
832 <  char buffer[IRCD_BUFSIZE];
973 <  int len;
974 <  struct Client *send_to = (to->from != NULL ? to->from : to);
832 >  struct dbuf_block *buffer = NULL;
833  
834 <  if (IsDead(send_to))
834 >  if (IsDead(to->from))
835      return;
836  
837 <  if (MyClient(to))
838 <  {
839 <    if (IsServer(from))
840 <    {
841 <      if (IsCapable(to, CAP_TS6) && HasID(from))
842 <        len = ircsprintf(buffer, ":%s ", from->id);
843 <      else
844 <        len = ircsprintf(buffer, ":%s ", from->name);
987 <    }
988 <    else
989 <      len = ircsprintf(buffer, ":%s!%s@%s ",
990 <                       from->name, from->username, from->host);
991 <  }
992 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
837 >  buffer = dbuf_alloc();
838 >
839 >  if (MyClient(to) && IsClient(from))
840 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
841 >                 from->host, command, to->name);
842 >  else
843 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
844 >                 command, ID_or_name(to, to));
845  
846    va_start(args, pattern);
847 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
847 >  send_format(buffer, pattern, args);
848    va_end(args);
849  
850 <  if(MyClient(to))
851 <    send_message(send_to, buffer, len);
850 >  if (MyClient(to))
851 >    send_message(to, buffer);
852    else
853 <    send_message_remote(send_to, from, buffer, len);
853 >    send_message_remote(to, from, buffer);
854 >
855 >  dbuf_ref_free(buffer);
856   }
857  
858   /* sendto_realops_flags()
# Line 1010 | Line 864 | sendto_anywhere(struct Client *to, struc
864   * side effects - Send to *local* ops only but NOT +s nonopers.
865   */
866   void
867 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
867 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
868   {
869 <  struct Client *client_p;
870 <  char nbuf[IRCD_BUFSIZE];
871 <  dlink_node *ptr;
869 >  const char *ntype = NULL;
870 >  dlink_node *ptr = NULL;
871 >  char nbuf[IRCD_BUFSIZE] = "";
872    va_list args;
873  
874    va_start(args, pattern);
875 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
875 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
876    va_end(args);
877  
878 +  switch (type)
879 +  {
880 +    case SEND_NOTICE:
881 +      ntype = "Notice";
882 +      break;
883 +    case SEND_GLOBAL:
884 +      ntype = "Global";
885 +      break;
886 +    case SEND_LOCOPS:
887 +      ntype = "LocOps";
888 +      break;
889 +    default:
890 +      assert(0);
891 +  }
892 +
893    DLINK_FOREACH(ptr, oper_list.head)
894    {
895 <    client_p = ptr->data;
896 <    assert(client_p->umodes & UMODE_OPER);
895 >    struct Client *client_p = ptr->data;
896 >    assert(HasUMode(client_p, UMODE_OPER));
897  
898 <    /* If we're sending it to opers and theyre an admin, skip.
899 <     * If we're sending it to admins, and theyre not, skip.
898 >    /*
899 >     * If we're sending it to opers and they're an admin, skip.
900 >     * If we're sending it to admins, and they're not, skip.
901       */
902 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
903 <        ((level == L_OPER) && IsAdmin(client_p)))
902 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
903 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
904        continue;
905  
906 <    if (client_p->umodes & flags)
907 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
908 <                 me.name, client_p->name, nbuf);
906 >    if (HasUMode(client_p, flags))
907 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
908 >                 me.name, client_p->name, ntype, nbuf);
909    }
910   }
911  
912 < /* sendto_wallops_flags()
912 > /* ts_warn()
913   *
914 < * inputs       - flag types of messages to show to real opers
1045 < *              - client sending request
1046 < *              - var args input message
914 > * inputs       - var args message
915   * output       - NONE
916 < * side effects - Send a wallops to local opers
916 > * side effects - Call sendto_realops_flags, with some flood checking
917 > *                (at most 5 warnings every 5 seconds)
918   */
919   void
920 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1052 <                     const char *pattern, ...)
920 > sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
921   {
1054  struct Client *client_p;
1055  dlink_node *ptr;
922    va_list args;
923 <  char buffer[IRCD_BUFSIZE];
1058 <  int len;
923 >  char buffer[IRCD_BUFSIZE] = "";
924  
925 <  if (IsClient(source_p))
926 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
927 <                     source_p->name, source_p->username, source_p->host);
1063 <  else
1064 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
925 >  if ((CurrentTime - *rate) < 20)
926 >    return;
927 >  *rate = CurrentTime;
928  
929    va_start(args, pattern);
930 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
930 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
931    va_end(args);
932  
933 <  DLINK_FOREACH(ptr, oper_list.head)
934 <  {
1072 <    client_p = ptr->data;
1073 <    assert(client_p->umodes & UMODE_OPER);
1074 <
1075 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
1076 <      send_message(client_p, buffer, len);
1077 <  }
933 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
934 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
935   }
936  
937 < /* ts_warn()
937 > /* sendto_wallops_flags()
938   *
939 < * inputs       - var args message
940 < * output       - NONE
941 < * side effects - Call sendto_realops_flags, with some flood checking
942 < *                (at most 5 warnings every 5 seconds)
939 > * inputs       - flag types of messages to show to real opers
940 > *              - client sending request
941 > *              - var args input message
942 > * output       - NONE
943 > * side effects - Send a wallops to local opers
944   */
945   void
946 < ts_warn(const char *pattern, ...)
946 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
947 >                     const char *pattern, ...)
948   {
949 +  dlink_node *ptr = NULL;
950    va_list args;
951 <  char buffer[LOG_BUFSIZE];
1092 <  static time_t last = 0;
1093 <  static int warnings = 0;
951 >  struct dbuf_block *buffer;
952  
953 <  /*
1096 <   ** if we're running with TS_WARNINGS enabled and someone does
1097 <   ** something silly like (remotely) connecting a nonTS server,
1098 <   ** we'll get a ton of warnings, so we make sure we don't send
1099 <   ** more than 5 every 5 seconds.  -orabidoo
1100 <   */
953 >  buffer = dbuf_alloc();
954  
955 <  if (CurrentTime - last < 5)
956 <  {
1104 <    if (++warnings > 5)
1105 <      return;
1106 <  }
955 >  if (IsClient(source_p))
956 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
957    else
958 <  {
1109 <    last = CurrentTime;
1110 <    warnings = 0;
1111 <  }
958 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
959  
960    va_start(args, pattern);
961 <  vsprintf_irc(buffer, pattern, args);
961 >  send_format(buffer, pattern, args);
962    va_end(args);
963  
964 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1118 <  ilog(L_CRIT, "%s", buffer);
1119 < }
1120 <
1121 < /* kill_client()
1122 < *
1123 < * inputs       - client to send kill towards
1124 < *              - pointer to client to kill
1125 < *              - reason for kill
1126 < * output       - NONE
1127 < * side effects - NONE
1128 < */
1129 < void
1130 < kill_client(struct Client *client_p, struct Client *diedie,
1131 <            const char *pattern, ...)
1132 < {
1133 <  va_list args;
1134 <  char buffer[IRCD_BUFSIZE];
1135 <  int len;
1136 <
1137 <  if (client_p->from != NULL)
1138 <    client_p = client_p->from;
1139 <  if (IsDead(client_p))
1140 <    return;
1141 <
1142 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1143 <                   ID_or_name(diedie, client_p));
1144 <
1145 <  va_start(args, pattern);
1146 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1147 <  va_end(args);
1148 <
1149 <  send_message(client_p, buffer, len);
1150 < }
1151 <
1152 < /* kill_client_ll_serv_butone()
1153 < *
1154 < * inputs       - pointer to client to not send to
1155 < *              - pointer to client to kill
1156 < * output       - NONE
1157 < * side effects - Send a KILL for the given client
1158 < *                message to all connected servers
1159 < *                except the client 'one'. Also deal with
1160 < *                client being unknown to leaf, as in lazylink...
1161 < */
1162 < void
1163 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1164 <                           const char *pattern, ...)
1165 < {
1166 <  va_list args;
1167 <  int have_uid = 0;
1168 <  struct Client *client_p;
1169 <  dlink_node *ptr;
1170 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1171 <  int len_uid = 0, len_nick;
1172 <
1173 <  va_start(args, pattern);
1174 <  if (HasID(source_p) && (me.id[0] != '\0'))
1175 <  {
1176 <    have_uid = 1;
1177 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1178 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1179 <                           args);
1180 <  }
1181 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1182 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1183 <                          args);
1184 <  va_end(args);
1185 <
1186 <  DLINK_FOREACH(ptr, serv_list.head)
964 >  DLINK_FOREACH(ptr, oper_list.head)
965    {
966 <    client_p = ptr->data;
967 <
1190 <    if (one != NULL && (client_p == one->from))
1191 <      continue;
1192 <    if (IsDefunct(client_p))
1193 <      continue;
966 >    struct Client *client_p = ptr->data;
967 >    assert(client_p->umodes & UMODE_OPER);
968  
969 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
970 <    if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) ||
1197 <        !ServerInfo.hub ||
1198 <        (source_p->lazyLinkClientExists & client_p->localClient->serverMask))
1199 <    {
1200 <      if (have_uid && IsCapable(client_p, CAP_TS6))
1201 <        send_message(client_p, buf_uid, len_uid);
1202 <      else
1203 <        send_message(client_p, buf_nick, len_nick);
1204 <    }
969 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
970 >      send_message(client_p, buffer);
971    }
972 < }
972 >
973 >  dbuf_ref_free(buffer);
974 > }

Diff Legend

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