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-8/src/send.c (file contents), Revision 1247 by michael, Sat Oct 1 07:54:24 2011 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 4792 by michael, Tue Oct 28 12:44:43 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  send.c: Functions for sending messages.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file send.c
23 > * \brief Functions for sending messages.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 33 | Line 35
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"
39 < #include "s_log.h"
38 > #include "server.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "memory.h"
41 – #include "hook.h"
42   #include "packet.h"
43  
44  
45 < struct Callback *iosend_cb = NULL;
46 < struct Callback *iosendctrl_cb = NULL;
47 < static unsigned int current_serial = 0;
45 > static uint64_t current_serial;
46  
47  
48   /* send_format()
49   *
50 < * inputs       - buffer to format into
51 < *              - size of the buffer
50 > * inputs
51 > *              - buffer
52   *              - format pattern to use
53   *              - var args
54   * output       - number of bytes formatted output
55   * side effects - modifies sendbuf
56   */
57 < static inline int
58 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
57 > static void
58 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
59   {
62 –  int len;
63 –
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);
77 <  if (len > bufsize - 2)
78 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
79 <
80 <  lsendbuf[len++] = '\r';
81 <  lsendbuf[len++] = '\n';
82 <  return len;
83 < }
72 >  dbuf_put_args(buffer, pattern, args);
73  
74 < /*
75 < * iosend_default - append a packet to the client's sendq.
87 < */
88 < void *
89 < iosend_default(va_list args)
90 < {
91 <  struct Client *to = va_arg(args, struct Client *);
92 <  int length = va_arg(args, int);
93 <  char *buf = va_arg(args, char *);
74 >  if (buffer->size > IRCD_BUFSIZE - 2)
75 >    buffer->size = IRCD_BUFSIZE - 2;
76  
77 <  dbuf_put(&to->localClient->buf_sendq, buf, length);
78 <  return NULL;
77 >  buffer->data[buffer->size++] = '\r';
78 >  buffer->data[buffer->size++] = '\n';
79   }
80  
81   /*
# Line 102 | Line 84 | iosend_default(va_list args)
84   **      sendq.
85   */
86   static void
87 < send_message(struct Client *to, char *buf, int len)
87 > send_message(struct Client *to, struct dbuf_block *buf)
88   {
89    assert(!IsMe(to));
90    assert(to != &me);
91  
92 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
92 >  if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->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->connection->buf_sendq) + buf->size),
99 >                           get_sendq(&to->connection->confs));
100      if (IsClient(to))
101        SetSendQExceeded(to);
102 +
103      dead_link_on_write(to, 0);
104      return;
105    }
106  
107 <  execute_callback(iosend_cb, to, len, buf);
107 >  dbuf_add(&to->connection->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;
114 >  ++to->connection->send.messages;
115 >  ++me.connection->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  
# Line 166 | 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, NULL, CAP_TS6, NOCAPS,
182 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
183 <                  me.id, to->name, me.name, to->name,
184 <                  to->username, to->host, to->from->name);
185 <    sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
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      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,
195 <                 to->host, to->from);
196 <
197 <    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 207 | 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 */
187 >  struct Client *client_p = data;
188 >  assert(fd == &client_p->connection->fd);
189  
190 < #ifdef HAVE_LIBCRYPTO
191 <  if (fd->flags.pending_read)
217 <  {
218 <    fd->flags.pending_read = 0;
219 <    read_packet(fd, client_p);
220 <  }
221 < #endif
222 < }
223 <
224 < /*
225 < ** slinkq_unblocked
226 < **      Called when a server control socket is ready for writing.
227 < */
228 < static void
229 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
230 < {
231 <  ClearSlinkqBlocked(client_p);
232 <  send_queued_slink_write(client_p);
190 >  DelFlag(client_p, FLAGS_BLOCKED);
191 >  send_queued_write(client_p);
192   }
193  
194   /*
# Line 241 | Line 200 | slinkq_unblocked(fde_t *fd, struct Clien
200   void
201   send_queued_write(struct Client *to)
202   {
203 <  int retlen;
245 <  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 */
213 <
256 <  if (dbuf_length(&to->localClient->buf_sendq))
213 >  if (dbuf_length(&to->connection->buf_sendq))
214    {
215 <    do {
216 <      first = to->localClient->buf_sendq.blocks.head->data;
215 >    do
216 >    {
217 >      struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
218  
219   #ifdef HAVE_LIBCRYPTO
220 <      if (to->localClient->fd.ssl)
220 >      if (to->connection->fd.ssl)
221        {
222 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
222 >        retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->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->connection->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:
274 <              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;
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->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
246  
247        if (retlen <= 0)
248          break;
249  
250 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
250 >      dbuf_delete(&to->connection->buf_sendq, retlen);
251  
252        /* We have some data written .. update counters */
253 <      to->localClient->send.bytes += retlen;
254 <      me.localClient->send.bytes += retlen;
255 <    } while (dbuf_length(&to->localClient->buf_sendq));
253 >      to->connection->send.bytes += retlen;
254 >      me.connection->send.bytes += retlen;
255 >    } while (dbuf_length(&to->connection->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 */
262 <      SetSendqBlocked(to);
263 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
303 <                     (PF *)sendq_unblocked, (void *)to, 0);
262 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
263 >                     sendq_unblocked, to, 0);
264      }
265      else if (retlen <= 0)
266      {
# Line 310 | Line 270 | send_queued_write(struct Client *to)
270    }
271   }
272  
313 – /*
314 – ** send_queued_slink_write
315 – **      This is called when there is a chance the some output would
316 – **      be possible. This attempts to empty the send queue as far as
317 – **      possible, and then if any data is left, a write is rescheduled.
318 – */
319 – void
320 – send_queued_slink_write(struct Client *to)
321 – {
322 –  int retlen;
323 –
324 –  /*
325 –   ** Once socket is marked dead, we cannot start writing to it,
326 –   ** even if the error is removed...
327 –   */
328 –  if (IsDead(to) || IsSlinkqBlocked(to))
329 –    return;  /* no use calling send() now */
330 –
331 –  /* Next, lets try to write some data */
332 –  if (to->localClient->slinkq != NULL)
333 –  {
334 –    retlen = send(to->localClient->ctrlfd.fd,
335 –                   to->localClient->slinkq + to->localClient->slinkq_ofs,
336 –                   to->localClient->slinkq_len, 0);
337 –    if (retlen < 0)
338 –    {
339 –      /* If we have a fatal error */
340 –      if (!ignoreErrno(errno))
341 –      {
342 –        dead_link_on_write(to, errno);
343 –        return;
344 –      }
345 –    }
346 –    else if (retlen == 0)
347 –    {
348 –      /* 0 bytes is an EOF .. */
349 –      dead_link_on_write(to, 0);
350 –      return;
351 –    }
352 –    else
353 –    {
354 –      execute_callback(iosendctrl_cb, to, retlen,
355 –        to->localClient->slinkq + to->localClient->slinkq_ofs);
356 –      to->localClient->slinkq_len -= retlen;
357 –
358 –      assert(to->localClient->slinkq_len >= 0);
359 –      if (to->localClient->slinkq_len)
360 –        to->localClient->slinkq_ofs += retlen;
361 –      else
362 –      {
363 –        to->localClient->slinkq_ofs = 0;
364 –        MyFree(to->localClient->slinkq);
365 –        to->localClient->slinkq = NULL;
366 –      }
367 –    }
368 –
369 –    /* Finally, if we have any more data, reschedule a write */
370 –    if (to->localClient->slinkq_len)
371 –    {
372 –      SetSlinkqBlocked(to);
373 –      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
374 –                     (PF *)slinkq_unblocked, (void *)to, 0);
375 –    }
376 –  }
377 – }
378 –
273   /* send_queued_all()
274   *
275   * input        - NONE
# Line 390 | 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 418 | 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)
425 <    to = to->from;
426 <  if (IsDead(to))
427 <    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 >
357 >  send_format(buffer, numstr, args);
358 >  va_end(args);
359 >
360 >  send_message(to->from, buffer);
361 >
362 >  dbuf_ref_free(buffer);
363 > }
364 >
365 > void
366 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
367 > {
368 >  struct dbuf_block *buffer = NULL;
369 >  const char *dest = NULL;
370 >  va_list args;
371 >
372 >  if (IsDead(to->from))
373 >    return;
374 >
375 >  dest = ID_or_name(to, to);
376 >
377 >  if (EmptyString(dest))
378 >    dest = "*";
379 >
380 >  buffer = dbuf_alloc();
381 >
382 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
383 >
384 >  va_start(args, pattern);
385 >  send_format(buffer, pattern, args);
386 >  va_end(args);
387 >
388 >  send_message(to->from, buffer);
389 >
390 >  dbuf_ref_free(buffer);
391   }
392  
393   /* sendto_channel_butone()
# Line 446 | Line 403 | sendto_one(struct Client *to, const char
403   */
404   void
405   sendto_channel_butone(struct Client *one, struct Client *from,
406 <                      struct Channel *chptr, const char *command,
406 >                      struct Channel *chptr, unsigned int type,
407                        const char *pattern, ...)
408   {
409 <  va_list alocal, aremote, auid;
410 <  char local_buf[IRCD_BUFSIZE];
454 <  char remote_buf[IRCD_BUFSIZE];
455 <  char uid_buf[IRCD_BUFSIZE];
456 <  int local_len, remote_len, uid_len;
409 >  va_list alocal, aremote;
410 >  struct dbuf_block *local_buf, *remote_buf;
411    dlink_node *ptr = NULL, *ptr_next = NULL;
412  
413 <  if (IsServer(from))
414 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
415 <                           from->name, command, chptr->chname);
413 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
414 >
415 >  if (IsClient(from))
416 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
417    else
418 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
419 <                           from->name, from->username, from->host,
420 <                           command, chptr->chname);
466 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
467 <                          from->name, command, chptr->chname);
468 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
469 <                       ID(from), command, chptr->chname);
418 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
419 >
420 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
421  
422    va_start(alocal, pattern);
423    va_start(aremote, pattern);
424 <  va_start(auid, pattern);
425 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
426 <                           pattern, alocal);
476 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
477 <                            pattern, aremote);
478 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
479 <                         auid);
480 <  va_end(auid);
424 >  send_format(local_buf, pattern, alocal);
425 >  send_format(remote_buf, pattern, aremote);
426 >
427    va_end(aremote);
428    va_end(alocal);
429  
# Line 485 | Line 431 | sendto_channel_butone(struct Client *one
431  
432    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
433    {
434 <    struct Client *target_p = ((struct Membership *)ptr->data)->client_p;
434 >    struct Membership *ms = ptr->data;
435 >    struct Client *target_p = ms->client_p;
436  
437      assert(IsClient(target_p));
438  
439 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
439 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
440 >        (one && target_p->from == one->from))
441 >      continue;
442 >
443 >    if (type && (ms->flags & type) == 0)
444        continue;
445  
446      if (MyConnect(target_p))
447 <    {
448 <      if (target_p->localClient->serial != current_serial)
449 <      {
450 <        send_message(target_p, local_buf, local_len);
500 <        target_p->localClient->serial = current_serial;
501 <      }
502 <    }
503 <    else
504 <    {
505 <      /* Now check whether a message has been sent to this
506 <       * remote link already
507 <       */
508 <      if (target_p->from->localClient->serial != current_serial)
509 <      {
510 <        if (IsCapable(target_p->from, CAP_TS6))
511 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
512 <        else
513 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
514 <        target_p->from->localClient->serial = current_serial;
515 <      }
516 <    }
447 >      send_message(target_p, local_buf);
448 >    else if (target_p->from->connection->serial != current_serial)
449 >      send_message_remote(target_p->from, from, remote_buf);
450 >    target_p->from->connection->serial = current_serial;
451    }
452 +
453 +  dbuf_ref_free(local_buf);
454 +  dbuf_ref_free(remote_buf);
455   }
456  
457   /* sendto_server()
458 < *
458 > *
459   * inputs       - pointer to client to NOT send to
460   *              - pointer to channel
461   *              - caps or'd together which must ALL be present
# Line 529 | Line 466 | sendto_channel_butone(struct Client *one
466   * side effects - Send a message to all connected servers, except the
467   *                client 'one' (if non-NULL), as long as the servers
468   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
469 < *            
469 > *
470   * This function was written in an attempt to merge together the other
471   * billion sendto_*serv*() functions, which sprung up with capabs,
472   * lazylinks, uids, etc.
473   * -davidt
474   */
475 < void
476 < sendto_server(struct Client *one, const struct Channel *chptr,
475 > void
476 > sendto_server(struct Client *one,
477                const unsigned int caps,
478                const unsigned int nocaps,
479                const char *format, ...)
480   {
481    va_list args;
482    dlink_node *ptr = NULL;
483 <  char buffer[IRCD_BUFSIZE];
547 <  int len = 0;
483 >  struct dbuf_block *buffer;
484  
485 <  if (chptr && chptr->chname[0] != '#')
550 <    return;
485 >  buffer = dbuf_alloc();
486  
487    va_start(args, format);
488 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
488 >  send_format(buffer, format, args);
489    va_end(args);
490  
491 <  DLINK_FOREACH(ptr, serv_list.head)
491 >  DLINK_FOREACH(ptr, local_server_list.head)
492    {
493      struct Client *client_p = ptr->data;
494  
# Line 561 | Line 496 | sendto_server(struct Client *one, const
496      if (IsDead(client_p))
497        continue;
498      /* check against 'one' */
499 <    if (one != NULL && (client_p == one->from))
499 >    if (one && (client_p == one->from))
500        continue;
501      /* check we have required capabs */
502 <    if ((client_p->localClient->caps & caps) != caps)
502 >    if ((client_p->connection->caps & caps) != caps)
503        continue;
504      /* check we don't have any forbidden capabs */
505 <    if ((client_p->localClient->caps & nocaps) != 0)
505 >    if ((client_p->connection->caps & nocaps))
506        continue;
507  
508 <    send_message(client_p, buffer, len);
508 >    send_message(client_p, buffer);
509    }
510 +
511 +  dbuf_ref_free(buffer);
512   }
513  
514   /* sendto_common_channels_local()
# Line 580 | Line 517 | sendto_server(struct Client *one, const
517   *              - pattern to send
518   * output       - NONE
519   * side effects - Sends a message to all people on local server who are
520 < *                in same channel with user.
520 > *                in same channel with user.
521   *                used by m_nick.c and exit_one_client.
522   */
523   void
524 < sendto_common_channels_local(struct Client *user, int touser,
524 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
525                               const char *pattern, ...)
526   {
527    va_list args;
# Line 593 | Line 530 | sendto_common_channels_local(struct Clie
530    struct Channel *chptr;
531    struct Membership *ms;
532    struct Client *target_p;
533 <  char buffer[IRCD_BUFSIZE];
534 <  int len;
533 >  struct dbuf_block *buffer;
534 >
535 >  buffer = dbuf_alloc();
536  
537    va_start(args, pattern);
538 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
538 >  send_format(buffer, pattern, args);
539    va_end(args);
540  
541    ++current_serial;
542  
543    DLINK_FOREACH(cptr, user->channel.head)
544    {
545 <    chptr = ((struct Membership *) cptr->data)->chptr;
608 <    assert(chptr != NULL);
545 >    chptr = ((struct Membership *)cptr->data)->chptr;
546  
547 <    DLINK_FOREACH(uptr, chptr->members.head)
547 >    DLINK_FOREACH(uptr, chptr->locmembers.head)
548      {
549        ms = uptr->data;
550        target_p = ms->client_p;
614 –      assert(target_p != NULL);
551  
552 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
553 <          target_p->localClient->serial == current_serial)
552 >      if (target_p == user || IsDefunct(target_p) ||
553 >          target_p->connection->serial == current_serial)
554 >        continue;
555 >
556 >      if (HasCap(target_p, cap) != cap)
557          continue;
558  
559 <      target_p->localClient->serial = current_serial;
560 <      send_message(target_p, buffer, len);
559 >      target_p->connection->serial = current_serial;
560 >      send_message(target_p, buffer);
561      }
562    }
563  
564    if (touser && MyConnect(user) && !IsDead(user) &&
565 <      user->localClient->serial != current_serial)
566 <    send_message(user, buffer, len);
565 >      user->connection->serial != current_serial)
566 >    if (HasCap(user, cap) == cap)
567 >      send_message(user, buffer);
568 >
569 >  dbuf_ref_free(buffer);
570   }
571  
572   /* sendto_channel_local()
# Line 638 | Line 580 | sendto_common_channels_local(struct Clie
580   *                locally connected to this server.
581   */
582   void
583 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
583 > sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
584                       const char *pattern, ...)
585   {
586    va_list args;
587 <  char buffer[IRCD_BUFSIZE];
588 <  int len;
589 <  dlink_node *ptr;
590 <  struct Membership *ms;
649 <  struct Client *target_p;
587 >  dlink_node *ptr = NULL;
588 >  struct dbuf_block *buffer;
589 >
590 >  buffer = dbuf_alloc();
591  
592    va_start(args, pattern);
593 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
593 >  send_format(buffer, pattern, args);
594    va_end(args);
595  
596 <  DLINK_FOREACH(ptr, chptr->members.head)
596 >  DLINK_FOREACH(ptr, chptr->locmembers.head)
597    {
598 <    ms = ptr->data;
599 <    target_p = ms->client_p;
598 >    struct Membership *ms = ptr->data;
599 >    struct Client *target_p = ms->client_p;
600  
601 <    if (type != 0 && (ms->flags & type) == 0)
601 >    if (type && (ms->flags & type) == 0)
602        continue;
603  
604 <    if (!MyConnect(target_p) || IsDefunct(target_p) ||
604 >    if (IsDefunct(target_p) ||
605          (nodeaf && HasUMode(target_p, UMODE_DEAF)))
606        continue;
607  
608 <    send_message(target_p, buffer, len);
608 >    send_message(target_p, buffer);
609    }
610 +
611 +  dbuf_ref_free(buffer);
612   }
613  
614   /* sendto_channel_local_butone()
# Line 680 | Line 623 | sendto_channel_local(int type, int nodea
623   *
624   * WARNING - +D clients are omitted
625   */
683 – void      
684 – sendto_channel_local_butone(struct Client *one, int type,
685 –                            struct Channel *chptr, const char *pattern, ...)
686 – {
687 –  va_list args;
688 –  char buffer[IRCD_BUFSIZE];
689 –  int len;
690 –  struct Client *target_p;
691 –  struct Membership *ms;
692 –  dlink_node *ptr;
693 –
694 –  va_start(args, pattern);
695 –  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
696 –  va_end(args);
697 –
698 –  DLINK_FOREACH(ptr, chptr->members.head)      
699 –  {  
700 –    ms = ptr->data;
701 –    target_p = ms->client_p;
702 –
703 –    if (type != 0 && (ms->flags & type) == 0)
704 –      continue;
705 –
706 –    if (!MyConnect(target_p) || target_p == one ||
707 –        IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
708 –      continue;
709 –    send_message(target_p, buffer, len);
710 –  }
711 – }
712 –
713 –
714 – /* sendto_channel_remote()
715 – *
716 – * inputs       - Client not to send towards
717 – *              - Client from whom message is from
718 – *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
719 – *              - pointer to channel to send to
720 – *              - var args pattern
721 – * output       - NONE
722 – * side effects - Send a message to all members of a channel that are
723 – *                remote to this server.
724 – */
626   void
627 < sendto_channel_remote(struct Client *one, struct Client *from, int type,
628 <                      const unsigned int caps, const unsigned int nocaps,
728 <                      struct Channel *chptr, const char *pattern, ...)
627 > sendto_channel_local_butone(struct Client *one, unsigned int poscap, unsigned int negcap,
628 >                            struct Channel *chptr, const char *pattern, ...)
629   {
630    va_list args;
631 <  char buffer[IRCD_BUFSIZE];
632 <  int len;
733 <  dlink_node *ptr;
734 <  struct Client *target_p;
735 <  struct Membership *ms;
631 >  dlink_node *ptr = NULL;
632 >  struct dbuf_block *buffer = dbuf_alloc();
633  
634    va_start(args, pattern);
635 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
635 >  send_format(buffer, pattern, args);
636    va_end(args);
637  
638 <  ++current_serial;
742 <
743 <  DLINK_FOREACH(ptr, chptr->members.head)
638 >  DLINK_FOREACH(ptr, chptr->locmembers.head)
639    {
640 <    ms = ptr->data;
641 <    target_p = ms->client_p;
640 >    struct Membership *ms = ptr->data;
641 >    struct Client *target_p = ms->client_p;
642  
643 <    if (type != 0 && (ms->flags & type) == 0)
643 >    if (one && target_p == one->from)
644        continue;
645  
646 <    if (MyConnect(target_p))
646 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
647        continue;
753 –    target_p = target_p->from;
648  
649 <    if (target_p == one->from ||
756 <        ((target_p->from->localClient->caps & caps) != caps) ||
757 <        ((target_p->from->localClient->caps & nocaps) != 0))
649 >    if (poscap && HasCap(target_p, poscap) != poscap)
650        continue;
651 <    if (target_p->from->localClient->serial != current_serial)
652 <    {
653 <      send_message(target_p, buffer, len);
654 <      target_p->from->localClient->serial = current_serial;
655 <    }
656 <  }
651 >
652 >    if (negcap && HasCap(target_p, negcap))
653 >      continue;
654 >
655 >    send_message(target_p, buffer);
656 >  }
657 >
658 >  dbuf_ref_free(buffer);
659   }
660  
661   /*
# Line 782 | Line 676 | sendto_channel_remote(struct Client *one
676   * side effects - NONE
677   */
678   static int
679 < match_it(const struct Client *one, const char *mask, int what)
679 > match_it(const struct Client *one, const char *mask, unsigned int what)
680   {
681    if (what == MATCH_HOST)
682 <    return match(mask, one->host);
682 >    return !match(mask, one->host);
683  
684 <  return match(mask, one->servptr->name);
684 >  return !match(mask, one->servptr->name);
685   }
686  
687   /* sendto_match_butone()
# Line 798 | Line 692 | match_it(const struct Client *one, const
692   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
693   */
694   void
695 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
695 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
696                      int what, const char *pattern, ...)
697   {
698    va_list alocal, aremote;
699 <  struct Client *client_p;
700 <  dlink_node *ptr, *ptr_next;
701 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
702 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
703 <                             from->username, from->host);
704 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
699 >  dlink_node *ptr = NULL, *ptr_next = NULL;
700 >  struct dbuf_block *local_buf, *remote_buf;
701 >
702 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
703 >
704 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
705 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
706  
707    va_start(alocal, pattern);
708    va_start(aremote, pattern);
709 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
710 <                           pattern, alocal);
816 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
817 <                            pattern, aremote);
709 >  send_format(local_buf, pattern, alocal);
710 >  send_format(remote_buf, pattern, aremote);
711    va_end(aremote);
712    va_end(alocal);
713  
714    /* scan the local clients */
715    DLINK_FOREACH(ptr, local_client_list.head)
716    {
717 <    client_p = ptr->data;
717 >    struct Client *client_p = ptr->data;
718  
719 <    if (client_p != one && !IsDefunct(client_p) &&
719 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
720          match_it(client_p, mask, what))
721 <      send_message(client_p, local_buf, local_len);
721 >      send_message(client_p, local_buf);
722    }
723  
724    /* Now scan servers */
725 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
725 >  DLINK_FOREACH_SAFE(ptr, ptr_next, local_server_list.head)
726    {
727 <    client_p = ptr->data;
727 >    struct Client *client_p = ptr->data;
728  
729      /*
730       * The old code looped through every client on the
# Line 857 | Line 750 | sendto_match_butone(struct Client *one,
750       * server deal with it.
751       * -wnder
752       */
753 <    if (client_p != one && !IsDefunct(client_p))
754 <      send_message_remote(client_p, from, remote_buf, remote_len);
753 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
754 >      send_message_remote(client_p, from, remote_buf);
755    }
756 +
757 +  dbuf_ref_free(local_buf);
758 +  dbuf_ref_free(remote_buf);
759   }
760  
761   /* sendto_match_servs()
# Line 872 | Line 768 | sendto_match_butone(struct Client *one,
768   * side effects - data sent to servers matching with capab
769   */
770   void
771 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
771 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
772                     const char *pattern, ...)
773   {
774    va_list args;
775 <  struct Client *target_p;
776 <  dlink_node *ptr;
777 <  char buffer[IRCD_BUFSIZE];
778 <  int found = 0;
775 >  dlink_node *ptr = NULL, *ptr_next = NULL;
776 >  struct dbuf_block *buffer;
777 >
778 >  buffer = dbuf_alloc();
779  
780 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
781    va_start(args, pattern);
782 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
782 >  send_format(buffer, pattern, args);
783    va_end(args);
784  
785    ++current_serial;
786  
787 <  DLINK_FOREACH(ptr, global_serv_list.head)
787 >  DLINK_FOREACH_SAFE(ptr, ptr_next, global_server_list.head)
788    {
789 <    target_p = ptr->data;
789 >    struct Client *target_p = ptr->data;
790  
791      /* Do not attempt to send to ourselves, or the source */
792      if (IsMe(target_p) || target_p->from == source_p->from)
793        continue;
794  
795 <    if (target_p->from->localClient->serial == current_serial)
795 >    if (target_p->from->connection->serial == current_serial)
796        continue;
797  
798 <    if (match(mask, target_p->name))
798 >    if (!match(mask, target_p->name))
799      {
800        /*
801         * if we set the serial here, then we'll never do a
802         * match() again, if !IsCapable()
803         */
804 <      target_p->from->localClient->serial = current_serial;
908 <      found++;
804 >      target_p->from->connection->serial = current_serial;
805  
806        if (!IsCapable(target_p->from, cap))
807          continue;
808  
809 <      sendto_anywhere(target_p, source_p, "%s", buffer);
809 >      send_message_remote(target_p->from, source_p, buffer);
810      }
811    }
812 +
813 +  dbuf_ref_free(buffer);
814   }
815  
816   /* sendto_anywhere()
# Line 926 | Line 824 | sendto_match_servs(struct Client *source
824   */
825   void
826   sendto_anywhere(struct Client *to, struct Client *from,
827 +                const char *command,
828                  const char *pattern, ...)
829   {
830    va_list args;
831 <  char buffer[IRCD_BUFSIZE];
933 <  int len;
934 <  struct Client *send_to = (to->from != NULL ? to->from : to);
831 >  struct dbuf_block *buffer = NULL;
832  
833 <  if (IsDead(send_to))
833 >  if (IsDead(to->from))
834      return;
835  
836 <  if (MyClient(to))
837 <  {
838 <    if (IsServer(from))
839 <    {
840 <      if (IsCapable(to, CAP_TS6) && HasID(from))
841 <        len = ircsprintf(buffer, ":%s ", from->id);
842 <      else
843 <        len = ircsprintf(buffer, ":%s ", from->name);
947 <    }
948 <    else
949 <      len = ircsprintf(buffer, ":%s!%s@%s ",
950 <                       from->name, from->username, from->host);
951 <  }
952 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
836 >  buffer = dbuf_alloc();
837 >
838 >  if (MyClient(to) && IsClient(from))
839 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
840 >                 from->host, command, to->name);
841 >  else
842 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
843 >                 command, ID_or_name(to, to));
844  
845    va_start(args, pattern);
846 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
846 >  send_format(buffer, pattern, args);
847    va_end(args);
848  
849 <  if(MyClient(to))
850 <    send_message(send_to, buffer, len);
849 >  if (MyClient(to))
850 >    send_message(to, buffer);
851    else
852 <    send_message_remote(send_to, from, buffer, len);
852 >    send_message_remote(to, from, buffer);
853 >
854 >  dbuf_ref_free(buffer);
855   }
856  
857   /* sendto_realops_flags()
# Line 970 | Line 863 | sendto_anywhere(struct Client *to, struc
863   * side effects - Send to *local* ops only but NOT +s nonopers.
864   */
865   void
866 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
866 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
867   {
868 +  const char *ntype = NULL;
869    dlink_node *ptr = NULL;
870 <  char nbuf[IRCD_BUFSIZE];
870 >  char nbuf[IRCD_BUFSIZE] = "";
871    va_list args;
872  
873    va_start(args, pattern);
874 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
874 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
875    va_end(args);
876  
877 +  switch (type)
878 +  {
879 +    case SEND_NOTICE:
880 +      ntype = "Notice";
881 +      break;
882 +    case SEND_GLOBAL:
883 +      ntype = "Global";
884 +      break;
885 +    case SEND_LOCOPS:
886 +      ntype = "LocOps";
887 +      break;
888 +    default:
889 +      assert(0);
890 +  }
891 +
892    DLINK_FOREACH(ptr, oper_list.head)
893    {
894      struct Client *client_p = ptr->data;
895      assert(HasUMode(client_p, UMODE_OPER));
896  
897 <    /* If we're sending it to opers and theyre an admin, skip.
898 <     * If we're sending it to admins, and theyre not, skip.
897 >    /*
898 >     * If we're sending it to opers and they're an admin, skip.
899 >     * If we're sending it to admins, and they're not, skip.
900       */
901      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
902 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
902 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
903        continue;
904  
905      if (HasUMode(client_p, flags))
906 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
907 <                 me.name, client_p->name, nbuf);
906 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
907 >                 me.name, client_p->name, ntype, nbuf);
908    }
909   }
910  
911 + /* ts_warn()
912 + *
913 + * inputs       - var args message
914 + * output       - NONE
915 + * side effects - Call sendto_realops_flags, with some flood checking
916 + *                (at most 5 warnings every 5 seconds)
917 + */
918   void
919 < sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...)
919 > sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
920   {
1004 –  dlink_node *ptr = NULL;
1005 –  char nbuf[IRCD_BUFSIZE];
921    va_list args;
922 +  char buffer[IRCD_BUFSIZE] = "";
923 +
924 +  if ((CurrentTime - *rate) < 20)
925 +    return;
926 +  *rate = CurrentTime;
927  
928    va_start(args, pattern);
929 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
929 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
930    va_end(args);
931  
932 <  DLINK_FOREACH(ptr, oper_list.head)
933 <  {
1014 <    struct Client *client_p = ptr->data;
1015 <    assert(client_p->umodes & UMODE_OPER);
1016 <
1017 <    /* If we're sending it to opers and theyre an admin, skip.
1018 <     * If we're sending it to admins, and theyre not, skip.
1019 <     */
1020 <    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
1021 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
1022 <      continue;
1023 <
1024 <    if (HasUMode(client_p, flags))
1025 <      sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s",
1026 <                 me.name, client_p->name, nbuf);
1027 <  }
932 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
933 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
934   }
935  
936   /* sendto_wallops_flags()
# Line 1041 | Line 947 | sendto_wallops_flags(unsigned int flags,
947   {
948    dlink_node *ptr = NULL;
949    va_list args;
950 <  char buffer[IRCD_BUFSIZE];
951 <  int len;
950 >  struct dbuf_block *buffer;
951 >
952 >  buffer = dbuf_alloc();
953  
954    if (IsClient(source_p))
955 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1049 <                     source_p->name, source_p->username, source_p->host);
955 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
956    else
957 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
957 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
958  
959    va_start(args, pattern);
960 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
960 >  send_format(buffer, pattern, args);
961    va_end(args);
962  
963    DLINK_FOREACH(ptr, oper_list.head)
# Line 1060 | Line 966 | sendto_wallops_flags(unsigned int flags,
966      assert(client_p->umodes & UMODE_OPER);
967  
968      if (HasUMode(client_p, flags) && !IsDefunct(client_p))
969 <      send_message(client_p, buffer, len);
969 >      send_message(client_p, buffer);
970    }
1065 – }
1066 –
1067 – /* ts_warn()
1068 – *
1069 – * inputs       - var args message
1070 – * output       - NONE
1071 – * side effects - Call sendto_realops_flags, with some flood checking
1072 – *                (at most 5 warnings every 5 seconds)
1073 – */
1074 – void
1075 – ts_warn(const char *pattern, ...)
1076 – {
1077 –  va_list args;
1078 –  char buffer[IRCD_BUFSIZE];
1079 –  static time_t last = 0;
1080 –  static int warnings = 0;
971  
972 <  /*
1083 <   ** if we're running with TS_WARNINGS enabled and someone does
1084 <   ** something silly like (remotely) connecting a nonTS server,
1085 <   ** we'll get a ton of warnings, so we make sure we don't send
1086 <   ** more than 5 every 5 seconds.  -orabidoo
1087 <   */
1088 <
1089 <  if (CurrentTime - last < 5)
1090 <  {
1091 <    if (++warnings > 5)
1092 <      return;
1093 <  }
1094 <  else
1095 <  {
1096 <    last = CurrentTime;
1097 <    warnings = 0;
1098 <  }
1099 <
1100 <  va_start(args, pattern);
1101 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
1102 <  va_end(args);
1103 <
1104 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1105 <  ilog(LOG_TYPE_IRCD, "%s", buffer);
972 >  dbuf_ref_free(buffer);
973   }
1107 –
1108 – /* kill_client()
1109 – *
1110 – * inputs       - client to send kill towards
1111 – *              - pointer to client to kill
1112 – *              - reason for kill
1113 – * output       - NONE
1114 – * side effects - NONE
1115 – */
1116 – void
1117 – kill_client(struct Client *client_p, struct Client *diedie,
1118 –            const char *pattern, ...)
1119 – {
1120 –  va_list args;
1121 –  char buffer[IRCD_BUFSIZE];
1122 –  int len;
1123 –
1124 –  if (client_p->from != NULL)
1125 –    client_p = client_p->from;
1126 –  if (IsDead(client_p))
1127 –    return;
1128 –
1129 –  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1130 –                   ID_or_name(diedie, client_p));
1131 –
1132 –  va_start(args, pattern);
1133 –  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1134 –  va_end(args);
1135 –
1136 –  send_message(client_p, buffer, len);
1137 – }
1138 –
1139 – /* kill_client_ll_serv_butone()
1140 – *
1141 – * inputs       - pointer to client to not send to
1142 – *              - pointer to client to kill
1143 – * output       - NONE
1144 – * side effects - Send a KILL for the given client
1145 – *                message to all connected servers
1146 – *                except the client 'one'. Also deal with
1147 – *                client being unknown to leaf, as in lazylink...
1148 – */
1149 – void
1150 – kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1151 –                           const char *pattern, ...)
1152 – {
1153 –  va_list args;
1154 –  int have_uid = 0;
1155 –  dlink_node *ptr = NULL;
1156 –  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1157 –  int len_uid = 0, len_nick = 0;
1158 –
1159 –  if (HasID(source_p))
1160 –  {
1161 –    have_uid = 1;
1162 –    va_start(args, pattern);
1163 –    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1164 –    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1165 –                           args);
1166 –    va_end(args);
1167 –  }
1168 –
1169 –  va_start(args, pattern);
1170 –  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1171 –  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1172 –                          args);
1173 –  va_end(args);
1174 –
1175 –  DLINK_FOREACH(ptr, serv_list.head)
1176 –  {
1177 –    struct Client *client_p = ptr->data;
1178 –
1179 –    if (one != NULL && (client_p == one->from))
1180 –      continue;
1181 –    if (IsDefunct(client_p))
1182 –      continue;
1183 –
1184 –    if (have_uid && IsCapable(client_p, CAP_TS6))
1185 –      send_message(client_p, buf_uid, len_uid);
1186 –    else
1187 –      send_message(client_p, buf_nick, len_nick);
1188 –  }
1189 – }

Diff Legend

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