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 1302 by michael, Wed Mar 21 17:48:54 2012 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 5035 by michael, Sat Dec 13 15:55:02 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 30 | Line 32
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
33 #include "numeric.h"
34 #include "fdlist.h"
35   #include "s_bsd.h"
36 < #include "s_serv.h"
37 < #include "sprintf_irc.h"
38 < #include "s_conf.h"
39 < #include "s_log.h"
40 < #include "memory.h"
41 < #include "hook.h"
42 < #include "packet.h"
36 > #include "server.h"
37 > #include "conf_class.h"
38 > #include "log.h"
39  
40  
41 < struct Callback *iosend_cb = NULL;
46 < static unsigned int current_serial = 0;
41 > static uint64_t current_serial;
42  
43  
44   /* send_format()
45   *
46 < * inputs       - buffer to format into
47 < *              - size of the buffer
46 > * inputs
47 > *              - buffer
48   *              - format pattern to use
49   *              - var args
50   * output       - number of bytes formatted output
51   * side effects - modifies sendbuf
52   */
53 < static inline int
54 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
53 > static void
54 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
55   {
61  int len;
62
56    /*
57     * from rfc1459
58     *
59     * IRC messages are always lines of characters terminated with a CR-LF
60     * (Carriage Return - Line Feed) pair, and these messages shall not
61 <   * exceed 512 characters in length,  counting all characters
61 >   * exceed 512 characters in length,  counting all characters
62     * including the trailing CR-LF.
63     * Thus, there are 510 characters maximum allowed
64     * for the command and its parameters.  There is no provision for
65     * continuation message lines.  See section 7 for more details about
66     * current implementations.
67     */
68 <  len = vsnprintf(lsendbuf, bufsize - 1, pattern, args);
76 <  if (len > bufsize - 2)
77 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
78 <
79 <  lsendbuf[len++] = '\r';
80 <  lsendbuf[len++] = '\n';
81 <  return len;
82 < }
68 >  dbuf_put_args(buffer, pattern, args);
69  
70 < /*
71 < * iosend_default - append a packet to the client's sendq.
86 < */
87 < void *
88 < iosend_default(va_list args)
89 < {
90 <  struct Client *to = va_arg(args, struct Client *);
91 <  int length = va_arg(args, int);
92 <  char *buf = va_arg(args, char *);
70 >  if (buffer->size > IRCD_BUFSIZE - 2)
71 >    buffer->size = IRCD_BUFSIZE - 2;
72  
73 <  dbuf_put(&to->localClient->buf_sendq, buf, length);
74 <  return NULL;
73 >  buffer->data[buffer->size++] = '\r';
74 >  buffer->data[buffer->size++] = '\n';
75   }
76  
77   /*
# Line 101 | Line 80 | iosend_default(va_list args)
80   **      sendq.
81   */
82   static void
83 < send_message(struct Client *to, char *buf, int len)
83 > send_message(struct Client *to, struct dbuf_block *buf)
84   {
85    assert(!IsMe(to));
86    assert(to != &me);
87 +  assert(MyConnect(to));
88  
89 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
89 >  if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs))
90    {
91      if (IsServer(to))
92 <      sendto_realops_flags(UMODE_ALL, L_ALL,
93 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
92 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
93 >                           "Max SendQ limit exceeded for %s: %lu > %u",
94                             get_client_name(to, HIDE_IP),
95 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
96 <                           get_sendq(to));
95 >                           (unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size),
96 >                           get_sendq(&to->connection->confs));
97 >
98      if (IsClient(to))
99        SetSendQExceeded(to);
100 +
101      dead_link_on_write(to, 0);
102      return;
103    }
104  
105 <  execute_callback(iosend_cb, to, len, buf);
105 >  dbuf_add(&to->connection->buf_sendq, buf);
106  
107    /*
108 <   ** Update statistics. The following is slightly incorrect
109 <   ** because it counts messages even if queued, but bytes
110 <   ** only really sent. Queued bytes get updated in SendQueued.
108 >   * Update statistics. The following is slightly incorrect because
109 >   * it counts messages even if queued, but bytes only really sent.
110 >   * Queued bytes get updated in send_queued_write().
111     */
112 <  ++to->localClient->send.messages;
113 <  ++me.localClient->send.messages;
112 >  ++to->connection->send.messages;
113 >  ++me.connection->send.messages;
114  
115 <  if (dbuf_length(&to->localClient->buf_sendq) >
134 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
135 <    send_queued_write(to);
115 >  send_queued_write(to);
116   }
117  
118   /* send_message_remote()
119   *
120   * inputs       - pointer to client from message is being sent
121   *              - pointer to client to send to
122 < *              - pointer to preformatted buffer
143 < *              - length of input buffer
122 > *              - pointer to buffer
123   * output       - none
124   * side effects - Despite the function name, this only sends to directly
125   *                connected clients.
126 < *
126 > *
127   */
128   static void
129 < send_message_remote(struct Client *to, struct Client *from,
151 <                    char *buf, int len)
129 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
130   {
131 <  if (!MyConnect(to))
132 <  {
133 <    sendto_realops_flags(UMODE_ALL, L_ALL,
134 <                         "server send message to %s [%s] dropped from %s(Not local server)",
157 <                         to->name, to->from->name, from->name);
158 <    return;
159 <  }
160 <
161 <  /* Optimize by checking if (from && to) before everything */
162 <  /* we set to->from up there.. */
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135  
136 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
136 >  if (to == from->from)
137    {
138 <    if (IsServer(from))
139 <    {
140 <      sendto_realops_flags(UMODE_ALL, L_ALL,
169 <                           "Send message to %s [%s] dropped from %s(Fake Dir)",
170 <                           to->name, to->from->name, from->name);
171 <      return;
172 <    }
173 <
174 <    sendto_realops_flags(UMODE_ALL, L_ALL,
175 <                         "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
176 <                         to->name, to->username, to->host,
177 <                         from->name, from->username, from->host,
178 <                         to->from->name);
179 <
180 <    sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
181 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
182 <                  me.id, to->name, me.name, to->name,
183 <                  to->username, to->host, to->from->name);
184 <    sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
185 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
186 <                  me.name, to->name, me.name, to->name,
187 <                  to->username, to->host, to->from->name);
188 <
189 <    AddFlag(to, FLAGS_KILLED);
190 <
191 <    if (IsClient(from))
192 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
193 <                 me.name, from->name, to->name, to->username,
194 <                 to->host, to->from);
195 <
196 <    exit_client(to, &me, "Ghosted client");
197 <
138 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
139 >                         "Send message to %s dropped from %s (Fake Dir)",
140 >                         to->name, from->name);
141      return;
142 <  }
142 >  }
143  
144 <  send_message(to, buf, len);
144 >  send_message(to, buf);
145   }
146  
147   /*
# Line 206 | Line 149 | send_message_remote(struct Client *to, s
149   **      Called when a socket is ready for writing.
150   */
151   void
152 < sendq_unblocked(fde_t *fd, struct Client *client_p)
152 > sendq_unblocked(fde_t *fd, void *data)
153   {
154 <  ClearSendqBlocked(client_p);
155 <  /* let send_queued_write be executed by send_queued_all */
154 >  struct Client *const client_p = data;
155 >  assert(fd == &client_p->connection->fd);
156  
157 < #ifdef HAVE_LIBCRYPTO
158 <  if (fd->flags.pending_read)
216 <  {
217 <    fd->flags.pending_read = 0;
218 <    read_packet(fd, client_p);
219 <  }
220 < #endif
157 >  DelFlag(client_p, FLAGS_BLOCKED);
158 >  send_queued_write(client_p);
159   }
160  
161   /*
# Line 229 | Line 167 | sendq_unblocked(fde_t *fd, struct Client
167   void
168   send_queued_write(struct Client *to)
169   {
170 <  int retlen;
233 <  struct dbuf_block *first;
170 >  int retlen = 0;
171  
172    /*
173     ** Once socket is marked dead, we cannot start writing to it,
174     ** even if the error is removed...
175     */
176 <  if (IsDead(to) || IsSendqBlocked(to))
176 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
177      return;  /* no use calling send() now */
178  
179    /* Next, lets try to write some data */
180 <
244 <  if (dbuf_length(&to->localClient->buf_sendq))
180 >  if (dbuf_length(&to->connection->buf_sendq))
181    {
182 <    do {
183 <      first = to->localClient->buf_sendq.blocks.head->data;
182 >    do
183 >    {
184 >      struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
185  
186   #ifdef HAVE_LIBCRYPTO
187 <      if (to->localClient->fd.ssl)
187 >      if (to->connection->fd.ssl)
188        {
189 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
189 >        retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos);
190  
191          /* translate openssl error codes, sigh */
192 <        if (retlen < 0)
193 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
194 <          {
192 >        if (retlen < 0)
193 >        {
194 >          switch (SSL_get_error(to->connection->fd.ssl, retlen))
195 >          {
196              case SSL_ERROR_WANT_READ:
197 <              return;  /* retry later, don't register for write events */
198 <
199 <            case SSL_ERROR_WANT_WRITE:
262 <              errno = EWOULDBLOCK;
197 >              return;  /* retry later, don't register for write events */
198 >            case SSL_ERROR_WANT_WRITE:
199 >              errno = EWOULDBLOCK;
200              case SSL_ERROR_SYSCALL:
201 <              break;
201 >              break;
202              case SSL_ERROR_SSL:
203                if (errno == EAGAIN)
204                  break;
205              default:
206 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
207 <          }
206 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
207 >          }
208 >        }
209        }
210        else
211   #endif
212 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
212 >        retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
213  
214        if (retlen <= 0)
215          break;
216  
217 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
217 >      dbuf_delete(&to->connection->buf_sendq, retlen);
218  
219        /* We have some data written .. update counters */
220 <      to->localClient->send.bytes += retlen;
221 <      me.localClient->send.bytes += retlen;
222 <    } while (dbuf_length(&to->localClient->buf_sendq));
220 >      to->connection->send.bytes += retlen;
221 >      me.connection->send.bytes += retlen;
222 >    } while (dbuf_length(&to->connection->buf_sendq));
223  
224 <    if ((retlen < 0) && (ignoreErrno(errno)))
224 >    if (retlen < 0 && ignoreErrno(errno))
225      {
226 +      AddFlag(to, FLAGS_BLOCKED);
227 +
228        /* we have a non-fatal error, reschedule a write */
229 <      SetSendqBlocked(to);
230 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
291 <                     (PF *)sendq_unblocked, (void *)to, 0);
229 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
230 >                     sendq_unblocked, to, 0);
231      }
232      else if (retlen <= 0)
233      {
# Line 307 | Line 246 | send_queued_write(struct Client *to)
246   void
247   send_queued_all(void)
248   {
249 <  dlink_node *ptr;
249 >  dlink_node *node = NULL;
250  
251    /* Servers are processed first, mainly because this can generate
252     * a notice to opers, which is to be delivered by this function.
253     */
254 <  DLINK_FOREACH(ptr, serv_list.head)
255 <    send_queued_write((struct Client *) ptr->data);
254 >  DLINK_FOREACH(node, local_server_list.head)
255 >    send_queued_write(node->data);
256  
257 <  DLINK_FOREACH(ptr, unknown_list.head)
258 <    send_queued_write((struct Client *) ptr->data);
257 >  DLINK_FOREACH(node, unknown_list.head)
258 >    send_queued_write(node->data);
259  
260 <  DLINK_FOREACH(ptr, local_client_list.head)
261 <    send_queued_write((struct Client *) ptr->data);
260 >  DLINK_FOREACH(node, local_client_list.head)
261 >    send_queued_write(node->data);
262  
263    /* NOTE: This can still put clients on aborted_list; unfortunately,
264     * exit_aborted_clients takes precedence over send_queued_all,
# Line 340 | Line 279 | void
279   sendto_one(struct Client *to, const char *pattern, ...)
280   {
281    va_list args;
282 <  char buffer[IRCD_BUFSIZE];
283 <  int len;
282 >  struct dbuf_block *buffer = NULL;
283 >
284 >  if (IsDead(to->from))
285 >    return;  /* This socket has already been marked as dead */
286 >
287 >  buffer = dbuf_alloc();
288 >
289 >  va_start(args, pattern);
290 >  send_format(buffer, pattern, args);
291 >  va_end(args);
292 >
293 >  send_message(to->from, buffer);
294 >
295 >  dbuf_ref_free(buffer);
296 > }
297 >
298 > void
299 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
300 > {
301 >  struct dbuf_block *buffer = NULL;
302 >  const char *dest = NULL, *numstr = NULL;
303 >  va_list args;
304 >
305 >  if (IsDead(to->from))
306 >    return;
307 >
308 >  dest = ID_or_name(to, to);
309 >
310 >  if (EmptyString(dest))
311 >    dest = "*";
312 >
313 >  buffer = dbuf_alloc();
314 >
315 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
316 >
317 >  va_start(args, numeric);
318 >
319 >  if (numeric & SND_EXPLICIT)
320 >    numstr = va_arg(args, const char *);
321 >  else
322 >    numstr = numeric_form(numeric);
323 >
324 >  send_format(buffer, numstr, args);
325 >  va_end(args);
326 >
327 >  send_message(to->from, buffer);
328 >
329 >  dbuf_ref_free(buffer);
330 > }
331 >
332 > void
333 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
334 > {
335 >  struct dbuf_block *buffer = NULL;
336 >  const char *dest = NULL;
337 >  va_list args;
338 >
339 >  if (IsDead(to->from))
340 >    return;
341 >
342 >  dest = ID_or_name(to, to);
343 >
344 >  if (EmptyString(dest))
345 >    dest = "*";
346 >
347 >  buffer = dbuf_alloc();
348  
349 <  if (to->from != NULL)
347 <    to = to->from;
348 <  if (IsDead(to))
349 <    return; /* This socket has already been marked as dead */
349 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
350  
351    va_start(args, pattern);
352 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
352 >  send_format(buffer, pattern, args);
353    va_end(args);
354  
355 <  send_message(to, buffer, len);
355 >  send_message(to->from, buffer);
356 >
357 >  dbuf_ref_free(buffer);
358   }
359  
360   /* sendto_channel_butone()
# Line 368 | Line 370 | sendto_one(struct Client *to, const char
370   */
371   void
372   sendto_channel_butone(struct Client *one, struct Client *from,
373 <                      struct Channel *chptr, const char *command,
373 >                      struct Channel *chptr, unsigned int type,
374                        const char *pattern, ...)
375   {
376 <  va_list alocal, aremote, auid;
377 <  char local_buf[IRCD_BUFSIZE];
378 <  char remote_buf[IRCD_BUFSIZE];
379 <  char uid_buf[IRCD_BUFSIZE];
380 <  int local_len, remote_len, uid_len;
381 <  dlink_node *ptr = NULL, *ptr_next = NULL;
382 <
383 <  if (IsServer(from))
382 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
383 <                           from->name, command, chptr->chname);
376 >  va_list alocal, aremote;
377 >  struct dbuf_block *local_buf, *remote_buf;
378 >  dlink_node *node = NULL;
379 >
380 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
381 >
382 >  if (IsClient(from))
383 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
384    else
385 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
386 <                           from->name, from->username, from->host,
387 <                           command, chptr->chname);
388 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
389 <                          from->name, command, chptr->chname);
390 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
391 <                       ID(from), command, chptr->chname);
385 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
386 >
387 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
388  
389    va_start(alocal, pattern);
390    va_start(aremote, pattern);
391 <  va_start(auid, pattern);
392 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
393 <                           pattern, alocal);
398 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
399 <                            pattern, aremote);
400 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
401 <                         auid);
402 <  va_end(auid);
391 >  send_format(local_buf, pattern, alocal);
392 >  send_format(remote_buf, pattern, aremote);
393 >
394    va_end(aremote);
395    va_end(alocal);
396  
397    ++current_serial;
398  
399 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
399 >  DLINK_FOREACH(node, chptr->members.head)
400    {
401 <    struct Client *target_p = ((struct Membership *)ptr->data)->client_p;
401 >    struct Membership *member = node->data;
402 >    struct Client *target_p = member->client_p;
403  
404      assert(IsClient(target_p));
405  
406 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
406 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
407 >        (one && target_p->from == one->from))
408 >      continue;
409 >
410 >    if (type && (member->flags & type) == 0)
411        continue;
412  
413      if (MyConnect(target_p))
414 <    {
415 <      if (target_p->localClient->serial != current_serial)
416 <      {
417 <        send_message(target_p, local_buf, local_len);
418 <        target_p->localClient->serial = current_serial;
423 <      }
424 <    }
425 <    else
426 <    {
427 <      /* Now check whether a message has been sent to this
428 <       * remote link already
429 <       */
430 <      if (target_p->from->localClient->serial != current_serial)
431 <      {
432 <        if (IsCapable(target_p->from, CAP_TS6))
433 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
434 <        else
435 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
436 <        target_p->from->localClient->serial = current_serial;
437 <      }
438 <    }
414 >      send_message(target_p, local_buf);
415 >    else if (target_p->from->connection->serial != current_serial)
416 >      send_message_remote(target_p->from, from, remote_buf);
417 >
418 >    target_p->from->connection->serial = current_serial;
419    }
420 +
421 +  dbuf_ref_free(local_buf);
422 +  dbuf_ref_free(remote_buf);
423   }
424  
425   /* sendto_server()
426 < *
426 > *
427   * inputs       - pointer to client to NOT send to
428   *              - pointer to channel
429   *              - caps or'd together which must ALL be present
# Line 451 | Line 434 | sendto_channel_butone(struct Client *one
434   * side effects - Send a message to all connected servers, except the
435   *                client 'one' (if non-NULL), as long as the servers
436   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
437 < *            
437 > *
438   * This function was written in an attempt to merge together the other
439   * billion sendto_*serv*() functions, which sprung up with capabs,
440   * lazylinks, uids, etc.
441   * -davidt
442   */
443 < void
444 < sendto_server(struct Client *one, const struct Channel *chptr,
443 > void
444 > sendto_server(struct Client *one,
445                const unsigned int caps,
446                const unsigned int nocaps,
447                const char *format, ...)
448   {
449    va_list args;
450 <  dlink_node *ptr = NULL;
451 <  char buffer[IRCD_BUFSIZE];
469 <  int len = 0;
470 <
471 <  if (chptr && chptr->chname[0] != '#')
472 <    return;
450 >  dlink_node *node = NULL;
451 >  struct dbuf_block *buffer = dbuf_alloc();
452  
453    va_start(args, format);
454 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
454 >  send_format(buffer, format, args);
455    va_end(args);
456  
457 <  DLINK_FOREACH(ptr, serv_list.head)
457 >  DLINK_FOREACH(node, local_server_list.head)
458    {
459 <    struct Client *client_p = ptr->data;
459 >    struct Client *client_p = node->data;
460  
461      /* If dead already skip */
462      if (IsDead(client_p))
463        continue;
464 +
465      /* check against 'one' */
466 <    if (one != NULL && (client_p == one->from))
466 >    if (one && (client_p == one->from))
467        continue;
468 +
469      /* check we have required capabs */
470 <    if ((client_p->localClient->caps & caps) != caps)
470 >    if ((client_p->connection->caps & caps) != caps)
471        continue;
472 +
473      /* check we don't have any forbidden capabs */
474 <    if ((client_p->localClient->caps & nocaps) != 0)
474 >    if ((client_p->connection->caps & nocaps))
475        continue;
476  
477 <    send_message(client_p, buffer, len);
477 >    send_message(client_p, buffer);
478    }
479 +
480 +  dbuf_ref_free(buffer);
481   }
482  
483   /* sendto_common_channels_local()
# Line 502 | Line 486 | sendto_server(struct Client *one, const
486   *              - pattern to send
487   * output       - NONE
488   * side effects - Sends a message to all people on local server who are
489 < *                in same channel with user.
489 > *                in same channel with user.
490   *                used by m_nick.c and exit_one_client.
491   */
492   void
493 < sendto_common_channels_local(struct Client *user, int touser,
493 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
494                               const char *pattern, ...)
495   {
496    va_list args;
497    dlink_node *uptr;
498    dlink_node *cptr;
499    struct Channel *chptr;
500 <  struct Membership *ms;
500 >  struct Membership *member;
501    struct Client *target_p;
502 <  char buffer[IRCD_BUFSIZE];
519 <  int len;
502 >  struct dbuf_block *buffer = dbuf_alloc();
503  
504    va_start(args, pattern);
505 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
505 >  send_format(buffer, pattern, args);
506    va_end(args);
507  
508    ++current_serial;
509  
510    DLINK_FOREACH(cptr, user->channel.head)
511    {
512 <    chptr = ((struct Membership *) cptr->data)->chptr;
530 <    assert(chptr != NULL);
512 >    chptr = ((struct Membership *)cptr->data)->chptr;
513  
514 <    DLINK_FOREACH(uptr, chptr->members.head)
514 >    DLINK_FOREACH(uptr, chptr->locmembers.head)
515      {
516 <      ms = uptr->data;
517 <      target_p = ms->client_p;
518 <      assert(target_p != NULL);
516 >      member = uptr->data;
517 >      target_p = member->client_p;
518 >
519 >      if (target_p == user || IsDefunct(target_p) ||
520 >          target_p->connection->serial == current_serial)
521 >        continue;
522  
523 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
539 <          target_p->localClient->serial == current_serial)
523 >      if (HasCap(target_p, cap) != cap)
524          continue;
525  
526 <      target_p->localClient->serial = current_serial;
527 <      send_message(target_p, buffer, len);
526 >      target_p->connection->serial = current_serial;
527 >      send_message(target_p, buffer);
528      }
529    }
530  
531    if (touser && MyConnect(user) && !IsDead(user) &&
532 <      user->localClient->serial != current_serial)
533 <    send_message(user, buffer, len);
532 >      user->connection->serial != current_serial)
533 >    if (HasCap(user, cap) == cap)
534 >      send_message(user, buffer);
535 >
536 >  dbuf_ref_free(buffer);
537   }
538  
539   /* sendto_channel_local()
540   *
541   * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
555 *              - whether to ignore +D clients (YES/NO)
542   *              - pointer to channel to send to
543   *              - var args pattern
544   * output       - NONE
# Line 560 | Line 546 | sendto_common_channels_local(struct Clie
546   *                locally connected to this server.
547   */
548   void
549 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
549 > sendto_channel_local(unsigned int type, struct Channel *chptr,
550                       const char *pattern, ...)
551   {
552    va_list args;
553 <  char buffer[IRCD_BUFSIZE];
554 <  int len;
569 <  dlink_node *ptr;
570 <  struct Membership *ms;
571 <  struct Client *target_p;
553 >  dlink_node *node = NULL;
554 >  struct dbuf_block *buffer = dbuf_alloc();
555  
556    va_start(args, pattern);
557 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
557 >  send_format(buffer, pattern, args);
558    va_end(args);
559  
560 <  DLINK_FOREACH(ptr, chptr->members.head)
560 >  DLINK_FOREACH(node, chptr->locmembers.head)
561    {
562 <    ms = ptr->data;
563 <    target_p = ms->client_p;
562 >    struct Membership *member = node->data;
563 >    struct Client *target_p = member->client_p;
564  
565 <    if (type != 0 && (ms->flags & type) == 0)
565 >    if (type && (member->flags & type) == 0)
566        continue;
567  
568 <    if (!MyConnect(target_p) || IsDefunct(target_p) ||
586 <        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
568 >    if (IsDefunct(target_p))
569        continue;
570  
571 <    send_message(target_p, buffer, len);
571 >    send_message(target_p, buffer);
572    }
573 +
574 +  dbuf_ref_free(buffer);
575   }
576  
577   /* sendto_channel_local_butone()
# Line 602 | Line 586 | sendto_channel_local(int type, int nodea
586   *
587   * WARNING - +D clients are omitted
588   */
605 void      
606 sendto_channel_local_butone(struct Client *one, int type,
607                            struct Channel *chptr, const char *pattern, ...)
608 {
609  va_list args;
610  char buffer[IRCD_BUFSIZE];
611  int len;
612  struct Client *target_p;
613  struct Membership *ms;
614  dlink_node *ptr;
615
616  va_start(args, pattern);
617  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
618  va_end(args);
619
620  DLINK_FOREACH(ptr, chptr->members.head)      
621  {  
622    ms = ptr->data;
623    target_p = ms->client_p;
624
625    if (type != 0 && (ms->flags & type) == 0)
626      continue;
627
628    if (!MyConnect(target_p) || target_p == one ||
629        IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
630      continue;
631    send_message(target_p, buffer, len);
632  }
633 }
634
635
636 /* sendto_channel_remote()
637 *
638 * inputs       - Client not to send towards
639 *              - Client from whom message is from
640 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
641 *              - pointer to channel to send to
642 *              - var args pattern
643 * output       - NONE
644 * side effects - Send a message to all members of a channel that are
645 *                remote to this server.
646 */
589   void
590 < sendto_channel_remote(struct Client *one, struct Client *from, int type,
591 <                      const unsigned int caps, const unsigned int nocaps,
650 <                      struct Channel *chptr, const char *pattern, ...)
590 > sendto_channel_local_butone(struct Client *one, unsigned int poscap, unsigned int negcap,
591 >                            struct Channel *chptr, const char *pattern, ...)
592   {
593    va_list args;
594 <  char buffer[IRCD_BUFSIZE];
595 <  int len;
655 <  dlink_node *ptr;
656 <  struct Client *target_p;
657 <  struct Membership *ms;
594 >  dlink_node *node = NULL;
595 >  struct dbuf_block *buffer = dbuf_alloc();
596  
597    va_start(args, pattern);
598 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
598 >  send_format(buffer, pattern, args);
599    va_end(args);
600  
601 <  ++current_serial;
664 <
665 <  DLINK_FOREACH(ptr, chptr->members.head)
601 >  DLINK_FOREACH(node, chptr->locmembers.head)
602    {
603 <    ms = ptr->data;
604 <    target_p = ms->client_p;
603 >    struct Membership *member = node->data;
604 >    struct Client *target_p = member->client_p;
605  
606 <    if (type != 0 && (ms->flags & type) == 0)
606 >    if (one && target_p == one->from)
607        continue;
608  
609 <    if (MyConnect(target_p))
609 >    if (IsDefunct(target_p))
610        continue;
675    target_p = target_p->from;
611  
612 <    if (target_p == one->from ||
678 <        ((target_p->from->localClient->caps & caps) != caps) ||
679 <        ((target_p->from->localClient->caps & nocaps) != 0))
612 >    if (poscap && HasCap(target_p, poscap) != poscap)
613        continue;
614 <    if (target_p->from->localClient->serial != current_serial)
615 <    {
616 <      send_message(target_p, buffer, len);
617 <      target_p->from->localClient->serial = current_serial;
618 <    }
619 <  }
614 >
615 >    if (negcap && HasCap(target_p, negcap))
616 >      continue;
617 >
618 >    send_message(target_p, buffer);
619 >  }
620 >
621 >  dbuf_ref_free(buffer);
622   }
623  
624   /*
# Line 704 | Line 639 | sendto_channel_remote(struct Client *one
639   * side effects - NONE
640   */
641   static int
642 < match_it(const struct Client *one, const char *mask, int what)
642 > match_it(const struct Client *one, const char *mask, unsigned int what)
643   {
644    if (what == MATCH_HOST)
645 <    return match(mask, one->host);
645 >    return !match(mask, one->host);
646  
647 <  return match(mask, one->servptr->name);
647 >  return !match(mask, one->servptr->name);
648   }
649  
650   /* sendto_match_butone()
# Line 720 | Line 655 | match_it(const struct Client *one, const
655   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
656   */
657   void
658 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
658 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
659                      int what, const char *pattern, ...)
660   {
661    va_list alocal, aremote;
662 <  struct Client *client_p;
663 <  dlink_node *ptr, *ptr_next;
664 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
665 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
666 <                             from->username, from->host);
667 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
662 >  dlink_node *node = NULL;
663 >  struct dbuf_block *local_buf, *remote_buf;
664 >
665 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
666 >
667 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
668 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
669  
670    va_start(alocal, pattern);
671    va_start(aremote, pattern);
672 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
673 <                           pattern, alocal);
738 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
739 <                            pattern, aremote);
672 >  send_format(local_buf, pattern, alocal);
673 >  send_format(remote_buf, pattern, aremote);
674    va_end(aremote);
675    va_end(alocal);
676  
677    /* scan the local clients */
678 <  DLINK_FOREACH(ptr, local_client_list.head)
678 >  DLINK_FOREACH(node, local_client_list.head)
679    {
680 <    client_p = ptr->data;
680 >    struct Client *client_p = node->data;
681  
682 <    if (client_p != one && !IsDefunct(client_p) &&
682 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
683          match_it(client_p, mask, what))
684 <      send_message(client_p, local_buf, local_len);
684 >      send_message(client_p, local_buf);
685    }
686  
687    /* Now scan servers */
688 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
688 >  DLINK_FOREACH(node, local_server_list.head)
689    {
690 <    client_p = ptr->data;
690 >    struct Client *client_p = node->data;
691  
692      /*
693       * The old code looped through every client on the
# Line 779 | Line 713 | sendto_match_butone(struct Client *one,
713       * server deal with it.
714       * -wnder
715       */
716 <    if (client_p != one && !IsDefunct(client_p))
717 <      send_message_remote(client_p, from, remote_buf, remote_len);
716 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
717 >      send_message_remote(client_p, from, remote_buf);
718    }
719 +
720 +  dbuf_ref_free(local_buf);
721 +  dbuf_ref_free(remote_buf);
722   }
723  
724   /* sendto_match_servs()
# Line 794 | Line 731 | sendto_match_butone(struct Client *one,
731   * side effects - data sent to servers matching with capab
732   */
733   void
734 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
734 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
735                     const char *pattern, ...)
736   {
737    va_list args;
738 <  struct Client *target_p;
739 <  dlink_node *ptr;
803 <  char buffer[IRCD_BUFSIZE];
804 <  int found = 0;
738 >  dlink_node *node = NULL;
739 >  struct dbuf_block *buffer = dbuf_alloc();
740  
741 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
742    va_start(args, pattern);
743 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
743 >  send_format(buffer, pattern, args);
744    va_end(args);
745  
746    ++current_serial;
747  
748 <  DLINK_FOREACH(ptr, global_serv_list.head)
748 >  DLINK_FOREACH(node, global_server_list.head)
749    {
750 <    target_p = ptr->data;
750 >    struct Client *target_p = node->data;
751  
752      /* Do not attempt to send to ourselves, or the source */
753      if (IsMe(target_p) || target_p->from == source_p->from)
754        continue;
755  
756 <    if (target_p->from->localClient->serial == current_serial)
756 >    if (target_p->from->connection->serial == current_serial)
757        continue;
758  
759      if (match(mask, target_p->name))
760 <    {
825 <      /*
826 <       * if we set the serial here, then we'll never do a
827 <       * match() again, if !IsCapable()
828 <       */
829 <      target_p->from->localClient->serial = current_serial;
830 <      found++;
760 >      continue;
761  
762 <      if (!IsCapable(target_p->from, cap))
763 <        continue;
762 >    /*
763 >     * If we set the serial here, then we'll never do a
764 >     * match() again, if !IsCapable()
765 >     */
766 >    target_p->from->connection->serial = current_serial;
767  
768 <      sendto_anywhere(target_p, source_p, "%s", buffer);
769 <    }
768 >    if (!IsCapable(target_p->from, cap))
769 >      continue;
770 >
771 >    send_message_remote(target_p->from, source_p, buffer);
772    }
773 +
774 +  dbuf_ref_free(buffer);
775   }
776  
777   /* sendto_anywhere()
# Line 848 | Line 785 | sendto_match_servs(struct Client *source
785   */
786   void
787   sendto_anywhere(struct Client *to, struct Client *from,
788 +                const char *command,
789                  const char *pattern, ...)
790   {
791    va_list args;
792 <  char buffer[IRCD_BUFSIZE];
855 <  int len;
856 <  struct Client *send_to = (to->from != NULL ? to->from : to);
792 >  struct dbuf_block *buffer = NULL;
793  
794 <  if (IsDead(send_to))
794 >  if (IsDead(to->from))
795      return;
796  
797 <  if (MyClient(to))
798 <  {
799 <    if (IsServer(from))
800 <    {
801 <      if (IsCapable(to, CAP_TS6) && HasID(from))
802 <        len = ircsprintf(buffer, ":%s ", from->id);
803 <      else
804 <        len = ircsprintf(buffer, ":%s ", from->name);
869 <    }
870 <    else
871 <      len = ircsprintf(buffer, ":%s!%s@%s ",
872 <                       from->name, from->username, from->host);
873 <  }
874 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
797 >  buffer = dbuf_alloc();
798 >
799 >  if (MyClient(to) && IsClient(from))
800 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
801 >                 from->host, command, to->name);
802 >  else
803 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
804 >                 command, ID_or_name(to, to));
805  
806    va_start(args, pattern);
807 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
807 >  send_format(buffer, pattern, args);
808    va_end(args);
809  
810 <  if(MyClient(to))
811 <    send_message(send_to, buffer, len);
810 >  if (MyConnect(to))
811 >    send_message(to, buffer);
812    else
813 <    send_message_remote(send_to, from, buffer, len);
813 >    send_message_remote(to->from, from, buffer);
814 >
815 >  dbuf_ref_free(buffer);
816   }
817  
818   /* sendto_realops_flags()
# Line 892 | Line 824 | sendto_anywhere(struct Client *to, struc
824   * side effects - Send to *local* ops only but NOT +s nonopers.
825   */
826   void
827 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
827 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
828   {
829 <  dlink_node *ptr = NULL;
830 <  char nbuf[IRCD_BUFSIZE];
829 >  const char *ntype = NULL;
830 >  dlink_node *node = NULL;
831 >  char nbuf[IRCD_BUFSIZE] = "";
832    va_list args;
833  
834    va_start(args, pattern);
835 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
835 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
836    va_end(args);
837  
838 <  DLINK_FOREACH(ptr, oper_list.head)
838 >  switch (type)
839    {
840 <    struct Client *client_p = ptr->data;
840 >    case SEND_NOTICE:
841 >      ntype = "Notice";
842 >      break;
843 >    case SEND_GLOBAL:
844 >      ntype = "Global";
845 >      break;
846 >    case SEND_LOCOPS:
847 >      ntype = "LocOps";
848 >      break;
849 >    default:
850 >      assert(0);
851 >  }
852 >
853 >  DLINK_FOREACH(node, oper_list.head)
854 >  {
855 >    struct Client *client_p = node->data;
856      assert(HasUMode(client_p, UMODE_OPER));
857  
858 <    /* If we're sending it to opers and theyre an admin, skip.
859 <     * If we're sending it to admins, and theyre not, skip.
858 >    /*
859 >     * If we're sending it to opers and they're an admin, skip.
860 >     * If we're sending it to admins, and they're not, skip.
861       */
862      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
863 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
863 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
864        continue;
865  
866      if (HasUMode(client_p, flags))
867 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
868 <                 me.name, client_p->name, nbuf);
867 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
868 >                 me.name, client_p->name, ntype, nbuf);
869    }
870   }
871  
872 + /* ts_warn()
873 + *
874 + * inputs       - var args message
875 + * output       - NONE
876 + * side effects - Call sendto_realops_flags, with some flood checking
877 + *                (at most 5 warnings every 5 seconds)
878 + */
879   void
880 < sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...)
880 > sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
881   {
926  dlink_node *ptr = NULL;
927  char nbuf[IRCD_BUFSIZE];
882    va_list args;
883 +  char buffer[IRCD_BUFSIZE] = "";
884  
885 <  va_start(args, pattern);
886 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
932 <  va_end(args);
885 >  if ((CurrentTime - *rate) < 20)
886 >    return;
887  
888 <  DLINK_FOREACH(ptr, oper_list.head)
935 <  {
936 <    struct Client *client_p = ptr->data;
937 <    assert(client_p->umodes & UMODE_OPER);
888 >  *rate = CurrentTime;
889  
890 <    /* If we're sending it to opers and theyre an admin, skip.
891 <     * If we're sending it to admins, and theyre not, skip.
892 <     */
942 <    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
943 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
944 <      continue;
890 >  va_start(args, pattern);
891 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
892 >  va_end(args);
893  
894 <    if (HasUMode(client_p, flags))
895 <      sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s",
948 <                 me.name, client_p->name, nbuf);
949 <  }
894 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
895 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
896   }
897  
898   /* sendto_wallops_flags()
# Line 961 | Line 907 | void
907   sendto_wallops_flags(unsigned int flags, struct Client *source_p,
908                       const char *pattern, ...)
909   {
910 <  dlink_node *ptr = NULL;
910 >  dlink_node *node = NULL;
911    va_list args;
912 <  char buffer[IRCD_BUFSIZE];
967 <  int len;
912 >  struct dbuf_block *buffer = dbuf_alloc();
913  
914    if (IsClient(source_p))
915 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
971 <                     source_p->name, source_p->username, source_p->host);
915 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
916    else
917 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
917 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
918  
919    va_start(args, pattern);
920 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
920 >  send_format(buffer, pattern, args);
921    va_end(args);
922  
923 <  DLINK_FOREACH(ptr, oper_list.head)
923 >  DLINK_FOREACH(node, oper_list.head)
924    {
925 <    struct Client *client_p = ptr->data;
925 >    struct Client *client_p = node->data;
926      assert(client_p->umodes & UMODE_OPER);
927  
928      if (HasUMode(client_p, flags) && !IsDefunct(client_p))
929 <      send_message(client_p, buffer, len);
986 <  }
987 < }
988 <
989 < /* ts_warn()
990 < *
991 < * inputs       - var args message
992 < * output       - NONE
993 < * side effects - Call sendto_realops_flags, with some flood checking
994 < *                (at most 5 warnings every 5 seconds)
995 < */
996 < void
997 < ts_warn(const char *pattern, ...)
998 < {
999 <  va_list args;
1000 <  char buffer[IRCD_BUFSIZE];
1001 <  static time_t last = 0;
1002 <  static int warnings = 0;
1003 <
1004 <  /*
1005 <   ** if we're running with TS_WARNINGS enabled and someone does
1006 <   ** something silly like (remotely) connecting a nonTS server,
1007 <   ** we'll get a ton of warnings, so we make sure we don't send
1008 <   ** more than 5 every 5 seconds.  -orabidoo
1009 <   */
1010 <
1011 <  if (CurrentTime - last < 5)
1012 <  {
1013 <    if (++warnings > 5)
1014 <      return;
929 >      send_message(client_p, buffer);
930    }
1016  else
1017  {
1018    last = CurrentTime;
1019    warnings = 0;
1020  }
1021
1022  va_start(args, pattern);
1023  vsnprintf(buffer, sizeof(buffer), pattern, args);
1024  va_end(args);
931  
932 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1027 <  ilog(LOG_TYPE_IRCD, "%s", buffer);
932 >  dbuf_ref_free(buffer);
933   }
1029
1030 /* kill_client()
1031 *
1032 * inputs       - client to send kill towards
1033 *              - pointer to client to kill
1034 *              - reason for kill
1035 * output       - NONE
1036 * side effects - NONE
1037 */
1038 void
1039 kill_client(struct Client *client_p, struct Client *diedie,
1040            const char *pattern, ...)
1041 {
1042  va_list args;
1043  char buffer[IRCD_BUFSIZE];
1044  int len;
1045
1046  if (client_p->from != NULL)
1047    client_p = client_p->from;
1048  if (IsDead(client_p))
1049    return;
1050
1051  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1052                   ID_or_name(diedie, client_p));
1053
1054  va_start(args, pattern);
1055  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1056  va_end(args);
1057
1058  send_message(client_p, buffer, len);
1059 }
1060
1061 /* kill_client_ll_serv_butone()
1062 *
1063 * inputs       - pointer to client to not send to
1064 *              - pointer to client to kill
1065 * output       - NONE
1066 * side effects - Send a KILL for the given client
1067 *                message to all connected servers
1068 *                except the client 'one'. Also deal with
1069 *                client being unknown to leaf, as in lazylink...
1070 */
1071 void
1072 kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1073                           const char *pattern, ...)
1074 {
1075  va_list args;
1076  int have_uid = 0;
1077  dlink_node *ptr = NULL;
1078  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1079  int len_uid = 0, len_nick = 0;
1080
1081  if (HasID(source_p))
1082  {
1083    have_uid = 1;
1084    va_start(args, pattern);
1085    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1086    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1087                           args);
1088    va_end(args);
1089  }
1090
1091  va_start(args, pattern);
1092  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1093  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1094                          args);
1095  va_end(args);
1096
1097  DLINK_FOREACH(ptr, serv_list.head)
1098  {
1099    struct Client *client_p = ptr->data;
1100
1101    if (one != NULL && (client_p == one->from))
1102      continue;
1103    if (IsDefunct(client_p))
1104      continue;
1105
1106    if (have_uid && IsCapable(client_p, CAP_TS6))
1107      send_message(client_p, buf_uid, len_uid);
1108    else
1109      send_message(client_p, buf_nick, len_nick);
1110  }
1111 }

Diff Legend

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