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/trunk/src/send.c (file contents):
Revision 1652 by michael, Tue Nov 13 20:28:53 2012 UTC vs.
Revision 9101 by michael, Wed Jan 1 09:58:45 2020 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-2020 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 "conf.h"
36 > #include "server_capab.h"
37 > #include "conf_class.h"
38   #include "log.h"
40 #include "memory.h"
41 #include "hook.h"
42 #include "packet.h"
39  
40  
41 < struct Callback *iosend_cb = NULL;
46 < static unsigned int current_serial = 0;
41 > static uintmax_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->localClient->confs))
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, SEND_NOTICE,
93 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
94 <                           get_client_name(to, HIDE_IP),
95 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
96 <                           get_sendq(&to->localClient->confs));
92 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
93 >                           "Max SendQ limit exceeded for %s: %zu > %u",
94 >                           client_get_name(to, HIDE_IP),
95 >                           (dbuf_length(&to->connection->buf_sendq) + buf->size),
96 >                           get_sendq(&to->connection->confs));
97 >
98      if (IsClient(to))
99 <      SetSendQExceeded(to);
99 >      AddFlag(to, FLAGS_SENDQEX);
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, const struct Client *from, struct dbuf_block *buf)
130   {
131 <  if (!MyConnect(to))
132 <  {
133 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
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.. */
163 <
164 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
165 <  {
166 <    if (IsServer(from))
167 <    {
168 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
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, SEND_NOTICE,
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, 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, 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 <
198 <    return;
199 <  }
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135  
136 <  send_message(to, buf, len);
136 >  if (to == from->from)
137 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Send message to %s dropped from %s (Fake Dir)",
138 >                         to->name, from->name);
139 >  else
140 >    send_message(to, buf);
141   }
142  
143   /*
# Line 206 | Line 145 | send_message_remote(struct Client *to, s
145   **      Called when a socket is ready for writing.
146   */
147   void
148 < sendq_unblocked(fde_t *fd, struct Client *client_p)
148 > sendq_unblocked(fde_t *F, void *data)
149   {
150 <  ClearSendqBlocked(client_p);
212 <  /* let send_queued_write be executed by send_queued_all */
150 >  struct Client *const client_p = data;
151  
152 < #ifdef HAVE_LIBCRYPTO
153 <  if (fd->flags.pending_read)
154 <  {
155 <    fd->flags.pending_read = 0;
156 <    read_packet(fd, client_p);
157 <  }
158 < #endif
152 >  assert(client_p);
153 >  assert(client_p->connection);
154 >  assert(client_p->connection->fd);
155 >  assert(client_p->connection->fd == F);
156 >
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 >  ssize_t retlen;
171  
172    /*
173 <   ** Once socket is marked dead, we cannot start writing to it,
174 <   ** even if the error is removed...
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 >  while (dbuf_length(&to->connection->buf_sendq))
181    {
182 <    do {
183 <      first = to->localClient->buf_sendq.blocks.head->data;
248 <
249 < #ifdef HAVE_LIBCRYPTO
250 <      if (to->localClient->fd.ssl)
251 <      {
252 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
253 <
254 <        /* translate openssl error codes, sigh */
255 <        if (retlen < 0)
256 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
257 <          {
258 <            case SSL_ERROR_WANT_READ:
259 <              return;  /* retry later, don't register for write events */
260 <
261 <            case SSL_ERROR_WANT_WRITE:
262 <              errno = EWOULDBLOCK;
263 <            case SSL_ERROR_SYSCALL:
264 <              break;
265 <            case SSL_ERROR_SSL:
266 <              if (errno == EAGAIN)
267 <                break;
268 <            default:
269 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
270 <          }
271 <      }
272 <      else
273 < #endif
274 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
182 >    bool want_read = false;
183 >    const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
184  
185 <      if (retlen <= 0)
277 <        break;
278 <
279 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
280 <
281 <      /* We have some data written .. update counters */
282 <      to->localClient->send.bytes += retlen;
283 <      me.localClient->send.bytes += retlen;
284 <    } while (dbuf_length(&to->localClient->buf_sendq));
285 <
286 <    if ((retlen < 0) && (ignoreErrno(errno)))
185 >    if (tls_isusing(&to->connection->fd->ssl))
186      {
187 <      /* we have a non-fatal error, reschedule a write */
188 <      SetSendqBlocked(to);
189 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
190 <                     (PF *)sendq_unblocked, (void *)to, 0);
187 >      retlen = tls_write(&to->connection->fd->ssl, first->data + to->connection->buf_sendq.pos,
188 >                                                   first->size - to->connection->buf_sendq.pos, &want_read);
189 >
190 >      if (want_read == true)
191 >        return;  /* Retry later, don't register for write events */
192      }
193 <    else if (retlen <= 0)
193 >    else
194 >      retlen = send(to->connection->fd->fd, first->data + to->connection->buf_sendq.pos,
195 >                                            first->size - to->connection->buf_sendq.pos, 0);
196 >
197 >    if (retlen <= 0)
198      {
199 <      dead_link_on_write(to, errno);
199 >      if (retlen < 0 && comm_ignore_errno(errno) == true)
200 >      {
201 >        AddFlag(to, FLAGS_BLOCKED);
202 >        /* We have a non-fatal error, reschedule a write */
203 >        comm_setselect(to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
204 >      }
205 >      else
206 >        dead_link_on_write(to, errno);
207        return;
208      }
209 +
210 +    dbuf_delete(&to->connection->buf_sendq, retlen);
211 +
212 +    /* We have some data written .. update counters */
213 +    to->connection->send.bytes += retlen;
214 +    me.connection->send.bytes += retlen;
215    }
216   }
217  
218 < /* send_queued_all()
218 > /* sendto_one()
219   *
220 < * input        - NONE
221 < * output       - NONE
222 < * side effects - try to flush sendq of each client
220 > * inputs       - pointer to destination client
221 > *              - var args message
222 > * output       - NONE
223 > * side effects - send message to single client
224   */
225   void
226 < send_queued_all(void)
226 > sendto_one(struct Client *to, const char *pattern, ...)
227   {
228 <  dlink_node *ptr;
228 >  va_list args;
229  
230 <  /* Servers are processed first, mainly because this can generate
231 <   * a notice to opers, which is to be delivered by this function.
314 <   */
315 <  DLINK_FOREACH(ptr, serv_list.head)
316 <    send_queued_write((struct Client *) ptr->data);
230 >  if (IsDead(to->from))
231 >    return;  /* This socket has already been marked as dead */
232  
233 <  DLINK_FOREACH(ptr, unknown_list.head)
319 <    send_queued_write((struct Client *) ptr->data);
233 >  va_start(args, pattern);
234  
235 <  DLINK_FOREACH(ptr, local_client_list.head)
236 <    send_queued_write((struct Client *) ptr->data);
235 >  struct dbuf_block *buffer = dbuf_alloc();
236 >  send_format(buffer, pattern, args);
237  
238 <  /* NOTE: This can still put clients on aborted_list; unfortunately,
239 <   * exit_aborted_clients takes precedence over send_queued_all,
240 <   * because exiting clients can generate server/oper traffic.
241 <   * The easiest approach is dealing with aborted clients in the next I/O lap.
242 <   * -adx
329 <   */
238 >  va_end(args);
239 >
240 >  send_message(to->from, buffer);
241 >
242 >  dbuf_ref_free(buffer);
243   }
244  
332 /* sendto_one()
333 *
334 * inputs       - pointer to destination client
335 *              - var args message
336 * output       - NONE
337 * side effects - send message to single client
338 */
245   void
246 < sendto_one(struct Client *to, const char *pattern, ...)
246 > sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
247 > {
248 >  va_list args;
249 >
250 >  if (IsDead(to->from))
251 >    return;  /* This socket has already been marked as dead */
252 >
253 >  const char *dest = ID_or_name(to, to);
254 >  if (EmptyString(dest))
255 >    dest = "*";
256 >
257 >  struct dbuf_block *buffer = dbuf_alloc();
258 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
259 >
260 >  va_start(args, numeric);
261 >
262 >  const char *numstr;
263 >  if (numeric & SND_EXPLICIT)
264 >    numstr = va_arg(args, const char *);
265 >  else
266 >    numstr = numeric_form(numeric);
267 >
268 >  send_format(buffer, numstr, args);
269 >  va_end(args);
270 >
271 >  send_message(to->from, buffer);
272 >
273 >  dbuf_ref_free(buffer);
274 > }
275 >
276 > void
277 > sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
278   {
279    va_list args;
343  char buffer[IRCD_BUFSIZE];
344  int len;
280  
281 <  if (to->from != NULL)
282 <    to = to->from;
283 <  if (IsDead(to))
284 <    return; /* This socket has already been marked as dead */
281 >  if (IsDead(to->from))
282 >    return;  /* This socket has already been marked as dead */
283 >
284 >  const char *dest = ID_or_name(to, to);
285 >  if (EmptyString(dest))
286 >    dest = "*";
287 >
288 >  struct dbuf_block *buffer = dbuf_alloc();
289 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
290  
291    va_start(args, pattern);
292 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
292 >  send_format(buffer, pattern, args);
293    va_end(args);
294  
295 <  send_message(to, buffer, len);
295 >  send_message(to->from, buffer);
296 >
297 >  dbuf_ref_free(buffer);
298   }
299  
300   /* sendto_channel_butone()
# Line 367 | Line 309 | sendto_one(struct Client *to, const char
309   * WARNING - +D clients are ignored
310   */
311   void
312 < sendto_channel_butone(struct Client *one, struct Client *from,
313 <                      struct Channel *chptr, unsigned int type,
312 > sendto_channel_butone(struct Client *one, const struct Client *from,
313 >                      struct Channel *channel, unsigned int type,
314                        const char *pattern, ...)
315   {
316 <  va_list alocal, aremote, auid;
317 <  char local_buf[IRCD_BUFSIZE];
318 <  char remote_buf[IRCD_BUFSIZE];
319 <  char uid_buf[IRCD_BUFSIZE];
320 <  int local_len, remote_len, uid_len;
321 <  dlink_node *ptr = NULL, *ptr_next = NULL;
322 <
323 <  if (IsServer(from))
382 <    local_len = ircsprintf(local_buf, ":%s ",
383 <                           from->name);
316 >  va_list alocal, aremote;
317 >  struct dbuf_block *local_buf, *remote_buf;
318 >  dlink_node *node;
319 >
320 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
321 >
322 >  if (IsClient(from))
323 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
324    else
325 <    local_len = ircsprintf(local_buf, ":%s!%s@%s ",
326 <                           from->name, from->username, from->host);
327 <  remote_len = ircsprintf(remote_buf, ":%s ",
388 <                          from->name);
389 <  uid_len = ircsprintf(uid_buf, ":%s ",
390 <                       ID(from));
325 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
326 >
327 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
328  
329    va_start(alocal, pattern);
330    va_start(aremote, pattern);
331 <  va_start(auid, pattern);
332 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
333 <                           pattern, alocal);
397 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
398 <                            pattern, aremote);
399 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
400 <                         auid);
401 <  va_end(auid);
331 >  send_format(local_buf, pattern, alocal);
332 >  send_format(remote_buf, pattern, aremote);
333 >
334    va_end(aremote);
335    va_end(alocal);
336  
337    ++current_serial;
338  
339 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
339 >  DLINK_FOREACH(node, channel->members.head)
340    {
341 <    struct Membership *ms = ptr->data;
342 <    struct Client *target_p = ms->client_p;
341 >    struct ChannelMember *member = node->data;
342 >    struct Client *target_p = member->client;
343  
344      assert(IsClient(target_p));
345  
346 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
346 >    if (IsDead(target_p->from))
347 >      continue;
348 >
349 >    if (one && (target_p->from == one->from))
350        continue;
351  
352 <    if (type != 0 && (ms->flags & type) == 0)
352 >    if (type && (member->flags & type) == 0)
353 >      continue;
354 >
355 >    if (HasUMode(target_p, UMODE_DEAF))
356        continue;
357  
358      if (MyConnect(target_p))
359 <    {
360 <      if (target_p->localClient->serial != current_serial)
361 <      {
362 <        send_message(target_p, local_buf, local_len);
363 <        target_p->localClient->serial = current_serial;
426 <      }
427 <    }
428 <    else
429 <    {
430 <      /* Now check whether a message has been sent to this
431 <       * remote link already
432 <       */
433 <      if (target_p->from->localClient->serial != current_serial)
434 <      {
435 <        if (IsCapable(target_p->from, CAP_TS6))
436 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
437 <        else
438 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
439 <        target_p->from->localClient->serial = current_serial;
440 <      }
441 <    }
359 >      send_message(target_p, local_buf);
360 >    else if (target_p->from->connection->serial != current_serial)
361 >      send_message_remote(target_p->from, from, remote_buf);
362 >
363 >    target_p->from->connection->serial = current_serial;
364    }
365 +
366 +  dbuf_ref_free(local_buf);
367 +  dbuf_ref_free(remote_buf);
368   }
369  
370   /* sendto_server()
371 < *
371 > *
372   * inputs       - pointer to client to NOT send to
373   *              - pointer to channel
374   *              - caps or'd together which must ALL be present
# Line 454 | Line 379 | sendto_channel_butone(struct Client *one
379   * side effects - Send a message to all connected servers, except the
380   *                client 'one' (if non-NULL), as long as the servers
381   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
382 < *            
382 > *
383   * This function was written in an attempt to merge together the other
384   * billion sendto_*serv*() functions, which sprung up with capabs,
385   * lazylinks, uids, etc.
386   * -davidt
387   */
388 < void
389 < sendto_server(struct Client *one,
388 > void
389 > sendto_server(const struct Client *one,
390                const unsigned int caps,
391                const unsigned int nocaps,
392                const char *format, ...)
393   {
394    va_list args;
395 <  dlink_node *ptr = NULL;
471 <  char buffer[IRCD_BUFSIZE];
472 <  int len = 0;
395 >  dlink_node *node;
396  
397    va_start(args, format);
398 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
398 >
399 >  struct dbuf_block *buffer = dbuf_alloc();
400 >  send_format(buffer, format, args);
401 >
402    va_end(args);
403  
404 <  DLINK_FOREACH(ptr, serv_list.head)
404 >  DLINK_FOREACH(node, local_server_list.head)
405    {
406 <    struct Client *client_p = ptr->data;
406 >    struct Client *client_p = node->data;
407  
408      /* If dead already skip */
409      if (IsDead(client_p))
410        continue;
411 +
412      /* check against 'one' */
413 <    if (one != NULL && (client_p == one->from))
413 >    if (one && (client_p == one->from))
414        continue;
415 +
416      /* check we have required capabs */
417 <    if ((client_p->localClient->caps & caps) != caps)
417 >    if ((client_p->connection->caps & caps) != caps)
418        continue;
419 +
420      /* check we don't have any forbidden capabs */
421 <    if ((client_p->localClient->caps & nocaps) != 0)
421 >    if ((client_p->connection->caps & nocaps))
422        continue;
423  
424 <    send_message(client_p, buffer, len);
424 >    send_message(client_p, buffer);
425    }
426 +
427 +  dbuf_ref_free(buffer);
428   }
429  
430   /* sendto_common_channels_local()
# Line 502 | Line 433 | sendto_server(struct Client *one,
433   *              - pattern to send
434   * output       - NONE
435   * side effects - Sends a message to all people on local server who are
436 < *                in same channel with user.
436 > *                in same channel with user.
437   *                used by m_nick.c and exit_one_client.
438   */
439   void
440 < sendto_common_channels_local(struct Client *user, int touser,
441 <                             const char *pattern, ...)
440 > sendto_common_channels_local(struct Client *user, bool touser, unsigned int poscap,
441 >                             unsigned int negcap, const char *pattern, ...)
442   {
443    va_list args;
444    dlink_node *uptr;
445    dlink_node *cptr;
446 <  struct Channel *chptr;
447 <  struct Membership *ms;
446 >  struct Channel *channel;
447 >  struct ChannelMember *member;
448    struct Client *target_p;
449 <  char buffer[IRCD_BUFSIZE];
519 <  int len;
449 >  struct dbuf_block *buffer = dbuf_alloc();
450  
451    va_start(args, pattern);
452 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
452 >  send_format(buffer, pattern, args);
453    va_end(args);
454  
455    ++current_serial;
456  
457    DLINK_FOREACH(cptr, user->channel.head)
458    {
459 <    chptr = ((struct Membership *) cptr->data)->chptr;
530 <    assert(chptr != NULL);
459 >    channel = ((struct ChannelMember *)cptr->data)->channel;
460  
461 <    DLINK_FOREACH(uptr, chptr->members.head)
461 >    DLINK_FOREACH(uptr, channel->members_local.head)
462      {
463 <      ms = uptr->data;
464 <      target_p = ms->client_p;
536 <      assert(target_p != NULL);
463 >      member = uptr->data;
464 >      target_p = member->client;
465  
466 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
539 <          target_p->localClient->serial == current_serial)
466 >      if (IsDead(target_p))
467          continue;
468  
469 <      target_p->localClient->serial = current_serial;
470 <      send_message(target_p, buffer, len);
469 >      if (target_p == user)
470 >        continue;
471 >
472 >      if (target_p->connection->serial == current_serial)
473 >        continue;
474 >
475 >      if (poscap && HasCap(target_p, poscap) != poscap)
476 >        continue;
477 >
478 >      if (negcap && HasCap(target_p, negcap))
479 >        continue;
480 >
481 >      target_p->connection->serial = current_serial;
482 >      send_message(target_p, buffer);
483      }
484    }
485  
486 <  if (touser && MyConnect(user) && !IsDead(user) &&
487 <      user->localClient->serial != current_serial)
488 <    send_message(user, buffer, len);
486 >  if (touser == true && MyConnect(user) && !IsDead(user))
487 >    if (HasCap(user, poscap) == poscap)
488 >      send_message(user, buffer);
489 >
490 >  dbuf_ref_free(buffer);
491   }
492  
493 < /* sendto_channel_local()
494 < *
495 < * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
496 < *              - whether to ignore +D clients (YES/NO)
497 < *              - pointer to channel to send to
498 < *              - var args pattern
499 < * output       - NONE
559 < * side effects - Send a message to all members of a channel that are
560 < *                locally connected to this server.
493 > /*! \brief Send a message to members of a channel that are locally connected to this server.
494 > * \param one      Client to skip; can be NULL
495 > * \param channel    Destination channel
496 > * \param status   Channel member status flags clients must have
497 > * \param poscap   Positive client capabilities flags (CAP)
498 > * \param negcap   Negative client capabilities flags (CAP)
499 > * \param pattern  Format string for command arguments
500   */
501   void
502 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
503 <                     const char *pattern, ...)
502 > sendto_channel_local(const struct Client *one, struct Channel *channel, unsigned int status,
503 >                     unsigned int poscap, unsigned int negcap, const char *pattern, ...)
504   {
505    va_list args;
506 <  char buffer[IRCD_BUFSIZE];
507 <  int len;
569 <  dlink_node *ptr;
570 <  struct Membership *ms;
571 <  struct Client *target_p;
506 >  dlink_node *node;
507 >  struct dbuf_block *buffer = dbuf_alloc();
508  
509    va_start(args, pattern);
510 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
510 >  send_format(buffer, pattern, args);
511    va_end(args);
512  
513 <  DLINK_FOREACH(ptr, chptr->members.head)
513 >  DLINK_FOREACH(node, channel->members_local.head)
514    {
515 <    ms = ptr->data;
516 <    target_p = ms->client_p;
515 >    struct ChannelMember *member = node->data;
516 >    struct Client *target_p = member->client;
517  
518 <    if (type != 0 && (ms->flags & type) == 0)
518 >    if (IsDead(target_p))
519        continue;
520  
521 <    if (!MyConnect(target_p) || IsDefunct(target_p) ||
586 <        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
521 >    if (one && (target_p == one->from))
522        continue;
523  
524 <    send_message(target_p, buffer, len);
590 <  }
591 < }
592 <
593 < /* sendto_channel_local_butone()
594 < *
595 < * inputs       - pointer to client to NOT send message to
596 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
597 < *              - pointer to channel to send to
598 < *              - var args pattern
599 < * output       - NONE
600 < * side effects - Send a message to all members of a channel that are
601 < *                locally connected to this server except one.
602 < *
603 < * WARNING - +D clients are omitted
604 < */
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)
524 >    if (status && (member->flags & status) == 0)
525        continue;
526  
527 <    if (!MyConnect(target_p) || target_p == one ||
629 <        IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
527 >    if (poscap && HasCap(target_p, poscap) != poscap)
528        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 */
647 void
648 sendto_channel_remote(struct Client *one, struct Client *from, int type,
649                      const unsigned int caps, const unsigned int nocaps,
650                      struct Channel *chptr, const char *pattern, ...)
651 {
652  va_list args;
653  char buffer[IRCD_BUFSIZE];
654  int len;
655  dlink_node *ptr;
656  struct Client *target_p;
657  struct Membership *ms;
658
659  va_start(args, pattern);
660  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
661  va_end(args);
662
663  ++current_serial;
664
665  DLINK_FOREACH(ptr, chptr->members.head)
666  {
667    ms = ptr->data;
668    target_p = ms->client_p;
529  
530 <    if (type != 0 && (ms->flags & type) == 0)
530 >    if (negcap && HasCap(target_p, negcap))
531        continue;
532  
533 <    if (MyConnect(target_p))
534 <      continue;
675 <    target_p = target_p->from;
533 >    send_message(target_p, buffer);
534 >  }
535  
536 <    if (target_p == one->from ||
678 <        ((target_p->from->localClient->caps & caps) != caps) ||
679 <        ((target_p->from->localClient->caps & nocaps) != 0))
680 <      continue;
681 <    if (target_p->from->localClient->serial != current_serial)
682 <    {
683 <      send_message(target_p, buffer, len);
684 <      target_p->from->localClient->serial = current_serial;
685 <    }
686 <  }
536 >  dbuf_ref_free(buffer);
537   }
538  
539   /*
# Line 703 | Line 553 | sendto_channel_remote(struct Client *one
553   * output       - 1 or 0 if match or not
554   * side effects - NONE
555   */
556 < static int
557 < match_it(const struct Client *one, const char *mask, int what)
556 > static bool
557 > match_it(const struct Client *one, const char *mask, unsigned int what)
558   {
559    if (what == MATCH_HOST)
560 <    return !match(mask, one->host);
560 >    return match(mask, one->host) == 0;
561  
562 <  return !match(mask, one->servptr->name);
562 >  return match(mask, one->servptr->name) == 0;
563   }
564  
565   /* sendto_match_butone()
# Line 720 | Line 570 | match_it(const struct Client *one, const
570   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
571   */
572   void
573 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
574 <                    int what, const char *pattern, ...)
573 > sendto_match_butone(const struct Client *one, const struct Client *from,
574 >                    const char *mask, int what, const char *pattern, ...)
575   {
576    va_list alocal, aremote;
577 <  struct Client *client_p;
578 <  dlink_node *ptr, *ptr_next;
579 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
580 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
581 <                             from->username, from->host);
582 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
577 >  dlink_node *node;
578 >  struct dbuf_block *local_buf, *remote_buf;
579 >
580 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
581 >
582 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
583 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
584  
585    va_start(alocal, pattern);
586    va_start(aremote, pattern);
587 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
588 <                           pattern, alocal);
738 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
739 <                            pattern, aremote);
587 >  send_format(local_buf, pattern, alocal);
588 >  send_format(remote_buf, pattern, aremote);
589    va_end(aremote);
590    va_end(alocal);
591  
592    /* scan the local clients */
593 <  DLINK_FOREACH(ptr, local_client_list.head)
593 >  DLINK_FOREACH(node, local_client_list.head)
594    {
595 <    client_p = ptr->data;
595 >    struct Client *client_p = node->data;
596  
597 <    if (client_p != one && !IsDefunct(client_p) &&
598 <        match_it(client_p, mask, what))
599 <      send_message(client_p, local_buf, local_len);
597 >    if (IsDead(client_p))
598 >      continue;
599 >
600 >    if (one && (client_p == one->from))
601 >      continue;
602 >
603 >    if (match_it(client_p, mask, what) == false)
604 >      continue;
605 >
606 >    send_message(client_p, local_buf);
607    }
608  
609    /* Now scan servers */
610 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
610 >  DLINK_FOREACH(node, local_server_list.head)
611    {
612 <    client_p = ptr->data;
612 >    struct Client *client_p = node->data;
613  
614      /*
615       * The old code looped through every client on the
# Line 779 | Line 635 | sendto_match_butone(struct Client *one,
635       * server deal with it.
636       * -wnder
637       */
638 <    if (client_p != one && !IsDefunct(client_p))
639 <      send_message_remote(client_p, from, remote_buf, remote_len);
638 >    if (IsDead(client_p))
639 >      continue;
640 >
641 >    if (one && (client_p == one->from))
642 >      continue;
643 >
644 >    send_message_remote(client_p, from, remote_buf);
645    }
646 +
647 +  dbuf_ref_free(local_buf);
648 +  dbuf_ref_free(remote_buf);
649   }
650  
651   /* sendto_match_servs()
# Line 794 | Line 658 | sendto_match_butone(struct Client *one,
658   * side effects - data sent to servers matching with capab
659   */
660   void
661 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
661 > sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
662                     const char *pattern, ...)
663   {
664    va_list args;
665 <  struct Client *target_p;
666 <  dlink_node *ptr;
803 <  char buffer[IRCD_BUFSIZE];
804 <  int found = 0;
665 >  dlink_node *node;
666 >  struct dbuf_block *buffer = dbuf_alloc();
667  
668 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
669    va_start(args, pattern);
670 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
670 >  send_format(buffer, pattern, args);
671    va_end(args);
672  
673    ++current_serial;
674  
675 <  DLINK_FOREACH(ptr, global_serv_list.head)
675 >  DLINK_FOREACH(node, global_server_list.head)
676    {
677 <    target_p = ptr->data;
677 >    struct Client *target_p = node->data;
678  
679 <    /* Do not attempt to send to ourselves, or the source */
817 <    if (IsMe(target_p) || target_p->from == source_p->from)
679 >    if (IsDead(target_p->from))
680        continue;
681  
682 <    if (target_p->from->localClient->serial == current_serial)
682 >    /* Do not attempt to send to ourselves ... */
683 >    if (IsMe(target_p))
684        continue;
685  
686 <    if (!match(mask, target_p->name))
687 <    {
688 <      /*
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++;
686 >    /* ... or the source */
687 >    if (target_p->from == source_p->from)
688 >      continue;
689  
690 <      if (!IsCapable(target_p->from, cap))
691 <        continue;
690 >    if (target_p->from->connection->serial == current_serial)
691 >      continue;
692  
693 <      sendto_anywhere(target_p, source_p, "%s", buffer);
694 <    }
693 >    if (match(mask, target_p->name))
694 >      continue;
695 >
696 >    if (cap && IsCapable(target_p->from, cap) != cap)
697 >      continue;
698 >
699 >    target_p->from->connection->serial = current_serial;
700 >    send_message_remote(target_p->from, source_p, buffer);
701    }
702 +
703 +  dbuf_ref_free(buffer);
704   }
705  
706   /* sendto_anywhere()
# Line 847 | Line 713 | sendto_match_servs(struct Client *source
713   *                but useful when one does not know where target "lives"
714   */
715   void
716 < sendto_anywhere(struct Client *to, struct Client *from,
716 > sendto_anywhere(struct Client *to, const struct Client *from,
717 >                const char *command,
718                  const char *pattern, ...)
719   {
720    va_list args;
854  char buffer[IRCD_BUFSIZE];
855  int len;
856  struct Client *send_to = (to->from != NULL ? to->from : to);
721  
722 <  if (IsDead(send_to))
722 >  if (IsDead(to->from))
723      return;
724  
725 <  if (MyClient(to))
726 <  {
727 <    if (IsServer(from))
728 <    {
729 <      if (IsCapable(to, CAP_TS6) && HasID(from))
730 <        len = ircsprintf(buffer, ":%s ", from->id);
731 <      else
868 <        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));
725 >  struct dbuf_block *buffer = dbuf_alloc();
726 >  if (MyClient(to) && IsClient(from))
727 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
728 >                 from->host, command, to->name);
729 >  else
730 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
731 >                 command, ID_or_name(to, to));
732  
733    va_start(args, pattern);
734 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
734 >  send_format(buffer, pattern, args);
735    va_end(args);
736  
737 <  if(MyClient(to))
738 <    send_message(send_to, buffer, len);
737 >  if (MyConnect(to))
738 >    send_message(to, buffer);
739    else
740 <    send_message_remote(send_to, from, buffer, len);
740 >    send_message_remote(to->from, from, buffer);
741 >
742 >  dbuf_ref_free(buffer);
743   }
744  
745   /* sendto_realops_flags()
# Line 894 | Line 753 | sendto_anywhere(struct Client *to, struc
753   void
754   sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
755   {
756 <  const char *ntype = NULL;
757 <  dlink_node *ptr = NULL;
899 <  char nbuf[IRCD_BUFSIZE];
756 >  const char *ntype = "???";
757 >  dlink_node *node;
758    va_list args;
759  
902  va_start(args, pattern);
903  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
904  va_end(args);
905
760    switch (type)
761    {
762      case SEND_NOTICE:
# Line 918 | Line 772 | sendto_realops_flags(unsigned int flags,
772        assert(0);
773    }
774  
775 <  DLINK_FOREACH(ptr, oper_list.head)
775 >  struct dbuf_block *buffer = dbuf_alloc();
776 >  dbuf_put_fmt(buffer, ":%s NOTICE * :*** %s -- ", me.name, ntype);
777 >
778 >  va_start(args, pattern);
779 >  send_format(buffer, pattern, args);
780 >  va_end(args);
781 >
782 >  DLINK_FOREACH(node, oper_list.head)
783    {
784 <    struct Client *client_p = ptr->data;
784 >    struct Client *client_p = node->data;
785      assert(HasUMode(client_p, UMODE_OPER));
786  
787 +    if (IsDead(client_p))
788 +      continue;
789 +
790      /*
791       * If we're sending it to opers and they're an admin, skip.
792       * If we're sending it to admins, and they're not, skip.
793       */
794      if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
795 <        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
795 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
796        continue;
797  
798 <    if (HasUMode(client_p, flags))
799 <      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
936 <                 me.name, client_p->name, ntype, nbuf);
937 <  }
938 < }
939 <
940 < /* sendto_wallops_flags()
941 < *
942 < * inputs       - flag types of messages to show to real opers
943 < *              - client sending request
944 < *              - var args input message
945 < * output       - NONE
946 < * side effects - Send a wallops to local opers
947 < */
948 < void
949 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
950 <                     const char *pattern, ...)
951 < {
952 <  dlink_node *ptr = NULL;
953 <  va_list args;
954 <  char buffer[IRCD_BUFSIZE];
955 <  int len;
956 <
957 <  if (IsClient(source_p))
958 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
959 <                     source_p->name, source_p->username, source_p->host);
960 <  else
961 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
962 <
963 <  va_start(args, pattern);
964 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
965 <  va_end(args);
966 <
967 <  DLINK_FOREACH(ptr, oper_list.head)
968 <  {
969 <    struct Client *client_p = ptr->data;
970 <    assert(client_p->umodes & UMODE_OPER);
798 >    if (!HasUMode(client_p, flags))
799 >      continue;
800  
801 <    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
973 <      send_message(client_p, buffer, len);
801 >    send_message(client_p, buffer);
802    }
803 +
804 +  dbuf_ref_free(buffer);
805   }
806  
807   /* ts_warn()
808   *
809 < * inputs       - var args message
810 < * output       - NONE
811 < * side effects - Call sendto_realops_flags, with some flood checking
812 < *                (at most 5 warnings every 5 seconds)
809 > * inputs       - var args message
810 > * output       - NONE
811 > * side effects - Call sendto_realops_flags, with some flood checking
812 > *                (at most 5 warnings every 5 seconds)
813   */
814   void
815 < ts_warn(const char *pattern, ...)
815 > sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
816   {
817    va_list args;
818 <  char buffer[IRCD_BUFSIZE];
989 <  static time_t last = 0;
990 <  static int warnings = 0;
818 >  char buffer[IRCD_BUFSIZE] = "";
819  
820 <  /*
821 <   ** if we're running with TS_WARNINGS enabled and someone does
994 <   ** something silly like (remotely) connecting a nonTS server,
995 <   ** we'll get a ton of warnings, so we make sure we don't send
996 <   ** more than 5 every 5 seconds.  -orabidoo
997 <   */
820 >  if ((event_base->time.sec_monotonic - *rate) < 20)
821 >    return;
822  
823 <  if (CurrentTime - last < 5)
1000 <  {
1001 <    if (++warnings > 5)
1002 <      return;
1003 <  }
1004 <  else
1005 <  {
1006 <    last = CurrentTime;
1007 <    warnings = 0;
1008 <  }
823 >  *rate = event_base->time.sec_monotonic;
824  
825    va_start(args, pattern);
826    vsnprintf(buffer, sizeof(buffer), pattern, args);
827    va_end(args);
828  
829 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
829 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
830    ilog(LOG_TYPE_IRCD, "%s", buffer);
831   }
832  
833 < /* kill_client()
1019 < *
1020 < * inputs       - client to send kill towards
1021 < *              - pointer to client to kill
1022 < *              - reason for kill
1023 < * output       - NONE
1024 < * side effects - NONE
1025 < */
1026 < void
1027 < kill_client(struct Client *client_p, struct Client *diedie,
1028 <            const char *pattern, ...)
1029 < {
1030 <  va_list args;
1031 <  char buffer[IRCD_BUFSIZE];
1032 <  int len;
1033 <
1034 <  if (client_p->from != NULL)
1035 <    client_p = client_p->from;
1036 <  if (IsDead(client_p))
1037 <    return;
1038 <
1039 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1040 <                   ID_or_name(diedie, client_p));
1041 <
1042 <  va_start(args, pattern);
1043 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1044 <  va_end(args);
1045 <
1046 <  send_message(client_p, buffer, len);
1047 < }
1048 <
1049 < /* kill_client_ll_serv_butone()
833 > /* sendto_wallops_flags()
834   *
835 < * inputs       - pointer to client to not send to
836 < *              - pointer to client to kill
837 < * output       - NONE
838 < * side effects - Send a KILL for the given client
839 < *                message to all connected servers
1056 < *                except the client 'one'. Also deal with
1057 < *                client being unknown to leaf, as in lazylink...
835 > * inputs       - flag types of messages to show to real opers
836 > *              - client sending request
837 > *              - var args input message
838 > * output       - NONE
839 > * side effects - Send a wallops to local opers
840   */
841   void
842 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
843 <                           const char *pattern, ...)
842 > sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
843 >                     const char *pattern, ...)
844   {
845 +  dlink_node *node;
846    va_list args;
847 <  int have_uid = 0;
1065 <  dlink_node *ptr = NULL;
1066 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1067 <  int len_uid = 0, len_nick = 0;
847 >  struct dbuf_block *buffer = dbuf_alloc();
848  
849 <  if (HasID(source_p))
850 <  {
851 <    have_uid = 1;
852 <    va_start(args, pattern);
1073 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1074 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1075 <                           args);
1076 <    va_end(args);
1077 <  }
849 >  if (IsClient(source_p))
850 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
851 >  else
852 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
853  
854    va_start(args, pattern);
855 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1081 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1082 <                          args);
855 >  send_format(buffer, pattern, args);
856    va_end(args);
857  
858 <  DLINK_FOREACH(ptr, serv_list.head)
858 >  DLINK_FOREACH(node, oper_list.head)
859    {
860 <    struct Client *client_p = ptr->data;
860 >    struct Client *client_p = node->data;
861 >    assert(client_p->umodes & UMODE_OPER);
862  
863 <    if (one != NULL && (client_p == one->from))
863 >    if (IsDead(client_p))
864        continue;
865 <    if (IsDefunct(client_p))
865 >
866 >    if (!HasUMode(client_p, flags))
867        continue;
868  
869 <    if (have_uid && IsCapable(client_p, CAP_TS6))
1095 <      send_message(client_p, buf_uid, len_uid);
1096 <    else
1097 <      send_message(client_p, buf_nick, len_nick);
869 >    send_message(client_p, buffer);
870    }
871 < }
871 >
872 >  dbuf_ref_free(buffer);
873 > }

Comparing ircd-hybrid/trunk/src/send.c (property svn:keywords):
Revision 1652 by michael, Tue Nov 13 20:28:53 2012 UTC vs.
Revision 9101 by michael, Wed Jan 1 09:58:45 2020 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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