ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/send.c (file contents), Revision 430 by michael, Sat Feb 11 12:52:34 2006 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), 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"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "send.h"
30   #include "channel.h"
31   #include "client.h"
30 #include "common.h"
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
34 #include "handlers.h"
35 #include "numeric.h"
36 #include "fdlist.h"
35   #include "s_bsd.h"
36 < #include "s_serv.h"
37 < #include "sprintf_irc.h"
38 < #include "s_conf.h"
41 < #include "list.h"
42 < #include "s_log.h"
43 < #include "memory.h"
44 < #include "hook.h"
45 < #include "irc_getnameinfo.h"
46 < #include "packet.h"
47 <
48 < #define LOG_BUFSIZE 2048
36 > #include "server_capab.h"
37 > #include "conf_class.h"
38 > #include "log.h"
39  
50 struct Callback *iosend_cb = NULL;
51 struct Callback *iosendctrl_cb = NULL;
40  
41 < static void send_message(struct Client *, char *, int);
54 < static void send_message_remote(struct Client *, struct Client *, char *, int);
41 > static uintmax_t current_serial;
42  
56 static unsigned long current_serial = 0L;
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   {
70  int len;
71
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);
85 <  if (len > bufsize - 2)
86 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
87 <
88 <  lsendbuf[len++] = '\r';
89 <  lsendbuf[len++] = '\n';
90 <  return (len);
91 < }
68 >  dbuf_put_args(buffer, pattern, args);
69  
70 < /*
71 < * iosend_default - append a packet to the client's sendq.
95 < */
96 < void *
97 < iosend_default(va_list args)
98 < {
99 <  struct Client *to = va_arg(args, struct Client *);
100 <  int length = va_arg(args, int);
101 <  char *buf = va_arg(args, char *);
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 110 | 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 < #ifdef INVARIANTS
86 <  if (IsMe(to))
87 <  {
118 <    sendto_realops_flags(UMODE_ALL, L_ALL,
119 <                         "Trying to send message to myself!");
120 <    return;
121 <  }
122 < #endif
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",
94 <                           get_client_name(to, HIDE_IP),
95 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
96 <                           get_sendq(to));
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) >
149 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
150 <    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
158 < *              - 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,
166 <                    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,
134 <                         "server send message to %s [%s] dropped from %s(Not local server)",
135 <                         to->name, to->from->name, from->name);
136 <    return;
137 <  }
138 <
139 <  if (ServerInfo.hub && IsCapable(to, CAP_LL))
140 <  {
178 <    if (((from->lazyLinkClientExists &
179 <          to->localClient->serverMask) == 0))
180 <      client_burst_if_needed(to, from);
181 <  }
182 <
183 <  /* Optimize by checking if (from && to) before everything */
184 <  /* we set to->from up there.. */
185 <
186 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
187 <  {
188 <    if (IsServer(from))
189 <    {
190 <      sendto_realops_flags(UMODE_ALL, L_ALL,
191 <                           "Send message to %s [%s] dropped from %s(Fake Dir)",
192 <                           to->name, to->from->name, from->name);
193 <      return;
194 <    }
195 <
196 <    sendto_realops_flags(UMODE_ALL, L_ALL,
197 <                         "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
198 <                         to->name, to->username, to->host,
199 <                         from->name, from->username, from->host,
200 <                         to->from->name);
201 <
202 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
203 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
204 <                  me.id, to->name, me.name, to->name,
205 <                  to->username, to->host, to->from->name);
206 <    sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS,
207 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
208 <                  me.name, to->name, me.name, to->name,
209 <                  to->username, to->host, to->from->name);
210 <
211 <    SetKilled(to);
212 <
213 <    if (IsClient(from))
214 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
215 <                 me.name, from->name, to->name, to->username,
216 <                 to->host, to->from);
217 <
218 <    exit_client(to, &me, "Ghosted client");
219 <
220 <    return;
221 <  }
222 <
223 <  send_message(to, buf, len);
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135 >
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 228 | 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);
234 <  /* 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;
240 <    read_packet(fd, client_p);
241 <  }
242 < #endif
243 < }
152 >  assert(client_p);
153 >  assert(client_p->connection);
154 >  assert(client_p->connection->fd);
155 >  assert(client_p->connection->fd == F);
156  
157 < /*
158 < ** slinkq_unblocked
247 < **      Called when a server control socket is ready for writing.
248 < */
249 < static void
250 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
251 < {
252 <  ClearSlinkqBlocked(client_p);
253 <  send_queued_slink_write(client_p);
157 >  DelFlag(client_p, FLAGS_BLOCKED);
158 >  send_queued_write(client_p);
159   }
160  
161   /*
# Line 262 | Line 167 | slinkq_unblocked(fde_t *fd, struct Clien
167   void
168   send_queued_write(struct Client *to)
169   {
170 <  int retlen;
266 <  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 <
277 <  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;
182 >    bool want_read = false;
183 >    const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
184  
185 < #ifdef HAVE_LIBCRYPTO
186 <      if (to->localClient->fd.ssl)
187 <      {
188 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
185 >    if (tls_isusing(&to->connection->fd->ssl))
186 >    {
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 <        /* translate openssl error codes, sigh */
191 <        if (retlen < 0)
192 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
193 <          {
194 <            case SSL_ERROR_WANT_READ:
195 <              return;  /* retry later, don't register for write events */
293 <
294 <            case SSL_ERROR_WANT_WRITE:
295 <              errno = EWOULDBLOCK;
296 <            case SSL_ERROR_SYSCALL:
297 <              break;
298 <            case SSL_ERROR_SSL:
299 <              if (errno == EAGAIN)
300 <                break;
301 <            default:
302 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
303 <          }
304 <      }
305 <      else
306 < #endif
307 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
190 >      if (want_read == true)
191 >        return;  /* Retry later, don't register for write events */
192 >    }
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)
197 >    if (retlen <= 0)
198 >    {
199 >      if (retlen < 0 && comm_ignore_errno(errno) == true)
200        {
201 < #ifdef _WIN32
202 <        errno = WSAGetLastError();
203 < #endif
314 <        break;
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 <
206 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
318 <
319 <      /* We have some data written .. update counters */
320 <      to->localClient->send.bytes += retlen;
321 <      me.localClient->send.bytes += retlen;
322 <    } while (dbuf_length(&to->localClient->buf_sendq));
323 <
324 <    if ((retlen < 0) && (ignoreErrno(errno)))
325 <    {
326 <      /* we have a non-fatal error, reschedule a write */
327 <      SetSendqBlocked(to);
328 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
329 <                     (PF *)sendq_unblocked, (void *)to, 0);
330 <    }
331 <    else if (retlen <= 0)
332 <    {
333 <      dead_link_on_write(to, errno);
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 < /*
219 < ** send_queued_slink_write
220 < **      This is called when there is a chance the some output would
221 < **      be possible. This attempts to empty the send queue as far as
222 < **      possible, and then if any data is left, a write is rescheduled.
218 > /* sendto_one()
219 > *
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_slink_write(struct Client *to)
226 > sendto_one(struct Client *to, const char *pattern, ...)
227   {
228 <  int retlen;
228 >  va_list args;
229  
230 <  /*
231 <   ** Once socket is marked dead, we cannot start writing to it,
352 <   ** even if the error is removed...
353 <   */
354 <  if (IsDead(to) || IsSlinkqBlocked(to))
355 <    return;  /* no use calling send() now */
230 >  if (IsDead(to->from))
231 >    return;  /* This socket has already been marked as dead */
232  
233 <  /* Next, lets try to write some data */
358 <  if (to->localClient->slinkq != NULL)
359 <  {
360 <    retlen = send(to->localClient->ctrlfd.fd,
361 <                   to->localClient->slinkq + to->localClient->slinkq_ofs,
362 <                   to->localClient->slinkq_len, 0);
363 <    if (retlen < 0)
364 <    {
365 <      /* If we have a fatal error */
366 <      if (!ignoreErrno(errno))
367 <      {
368 <        dead_link_on_write(to, errno);
369 <        return;
370 <      }
371 <    }
372 <    else if (retlen == 0)
373 <    {
374 <      /* 0 bytes is an EOF .. */
375 <      dead_link_on_write(to, 0);
376 <      return;
377 <    }
378 <    else
379 <    {
380 <      execute_callback(iosendctrl_cb, to, retlen,
381 <        to->localClient->slinkq + to->localClient->slinkq_ofs);
382 <      to->localClient->slinkq_len -= retlen;
383 <
384 <      assert(to->localClient->slinkq_len >= 0);
385 <      if (to->localClient->slinkq_len)
386 <        to->localClient->slinkq_ofs += retlen;
387 <      else
388 <      {
389 <        to->localClient->slinkq_ofs = 0;
390 <        MyFree(to->localClient->slinkq);
391 <        to->localClient->slinkq = NULL;
392 <      }
393 <    }
233 >  va_start(args, pattern);
234  
235 <    /* Finally, if we have any more data, reschedule a write */
236 <    if (to->localClient->slinkq_len)
237 <    {
238 <      SetSlinkqBlocked(to);
239 <      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
240 <                     (PF *)slinkq_unblocked, (void *)to, 0);
241 <    }
242 <  }
235 >  struct dbuf_block *buffer = dbuf_alloc();
236 >  send_format(buffer, pattern, args);
237 >
238 >  va_end(args);
239 >
240 >  send_message(to->from, buffer);
241 >
242 >  dbuf_ref_free(buffer);
243   }
244  
405 /* send_queued_all()
406 *
407 * input        - NONE
408 * output       - NONE
409 * side effects - try to flush sendq of each client
410 */
245   void
246 < send_queued_all(void)
246 > sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
247   {
248 <  dlink_node *ptr;
248 >  va_list args;
249  
250 <  /* Servers are processed first, mainly because this can generate
251 <   * a notice to opers, which is to be delivered by this function.
418 <   */
419 <  DLINK_FOREACH(ptr, serv_list.head)
420 <    send_queued_write((struct Client *) ptr->data);
250 >  if (IsDead(to->from))
251 >    return;  /* This socket has already been marked as dead */
252  
253 <  DLINK_FOREACH(ptr, unknown_list.head)
254 <    send_queued_write((struct Client *) ptr->data);
253 >  const char *dest = ID_or_name(to, to);
254 >  if (EmptyString(dest))
255 >    dest = "*";
256  
257 <  DLINK_FOREACH(ptr, local_client_list.head)
258 <    send_queued_write((struct Client *) ptr->data);
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 <  /* NOTE: This can still put clients on aborted_list; unfortunately,
261 <   * exit_aborted_clients takes precedence over send_queued_all,
262 <   * because exiting clients can generate server/oper traffic.
263 <   * The easiest approach is dealing with aborted clients in the next I/O lap.
264 <   * -adx
265 <   */
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  
436 /* sendto_one()
437 *
438 * inputs       - pointer to destination client
439 *              - var args message
440 * output       - NONE
441 * side effects - send message to single client
442 */
276   void
277 < sendto_one(struct Client *to, const char *pattern, ...)
277 > sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
278   {
279    va_list args;
447  char buffer[IRCD_BUFSIZE];
448  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 471 | 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, const char *command,
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;
483 <  dlink_node *ptr;
484 <  dlink_node *ptr_next;
485 <  struct Client *target_p;
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 (IsServer(from))
323 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
489 <                           from->name, command, chptr->chname);
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 %s %s ",
326 <                           from->name, from->username, from->host,
327 <                           command, chptr->chname);
494 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
495 <                          from->name, command, chptr->chname);
496 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
497 <                       ID(from), command, chptr->chname);
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);
504 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
505 <                            pattern, aremote);
506 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
507 <                         auid);
508 <  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 <    target_p = ((struct Membership *)ptr->data)->client_p;
342 <    assert(target_p != NULL);
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) || IsDeaf(target_p) || target_p->from == one)
346 >    if (IsDead(target_p->from))
347        continue;
348  
349 <    if (MyClient(target_p))
350 <    {
351 <      if (target_p->serial != current_serial)
352 <      {
353 <        send_message(target_p, local_buf, local_len);
354 <        target_p->serial = current_serial;
355 <      }
356 <    }
357 <    else
358 <    {
359 <      /* Now check whether a message has been sent to this
360 <       * remote link already
361 <       */
362 <      if (target_p->from->serial != current_serial)
363 <      {
537 <        if (IsCapable(target_p->from, CAP_TS6))
538 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
539 <        else
540 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
541 <        target_p->from->serial = current_serial;
542 <      }
543 <    }
349 >    if (one && (target_p->from == one->from))
350 >      continue;
351 >
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 >      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 source client required by LL (if any)
551 < *              - pointer to channel required by LL (if any)
373 > *              - pointer to channel
374   *              - caps or'd together which must ALL be present
375   *              - caps or'd together which must ALL NOT be present
554 *              - LL flags: LL_ICLIENT | LL_ICHAN
376   *              - printf style format string
377   *              - args to format string
378   * output       - NONE
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 < *                If the server is a lazylink client, then it must know
562 < *                about source_p if non-NULL (unless LL_ICLIENT is specified,
563 < *                when source_p will be introduced where required) and
564 < *                chptr if non-NULL (unless LL_ICHANNEL is specified, when
565 < *                chptr will be introduced where required).
566 < *                Note: nothing will be introduced to a LazyLeaf unless
567 < *                the message is actually sent.
568 < *            
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, struct Client *source_p,
390 <              struct Channel *chptr, unsigned long caps,
391 <              unsigned long nocaps, unsigned long llflags,
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 <  struct Client *client_p;
582 <  dlink_node *ptr;
583 <  char buffer[IRCD_BUFSIZE];
584 <  int len;
585 <
586 <  if (chptr != NULL)
587 <  {
588 <    if (chptr->chname[0] != '#')
589 <      return;
590 <  }
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 <    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 <    if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
614 <    {
615 <      /* check LL channel */
616 <      if (chptr != NULL &&
617 <          ((chptr->lazyLinkChannelExists &
618 <            client_p->localClient->serverMask) == 0))
619 <      {
620 <        /* Only introduce the channel if we really will send this message */
621 <        if (!(llflags & LL_ICLIENT) && source_p &&
622 <            ((source_p->lazyLinkClientExists &
623 <              client_p->localClient->serverMask) == 0))
624 <          continue; /* we can't introduce the unknown source_p, skip */
625 <
626 <        if (llflags & LL_ICHAN)
627 <          burst_channel(client_p, chptr);
628 <        else
629 <          continue; /* we can't introduce the unknown chptr, skip */
630 <      }
631 <      /* check LL client */
632 <      if (source_p &&
633 <          ((source_p->lazyLinkClientExists &
634 <            client_p->localClient->serverMask) == 0))
635 <      {
636 <        if (llflags & LL_ICLIENT)
637 <          client_burst_if_needed(client_p,source_p);
638 <        else
639 <          continue; /* we can't introduce the unknown source_p, skip */
640 <      }
641 <    }
642 <    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 649 | Line 433 | sendto_server(struct Client *one, struct
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];
666 <  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;
677 <    assert(chptr != NULL);
459 >    channel = ((struct ChannelMember *)cptr->data)->channel;
460  
461 <    DLINK_FOREACH(uptr, chptr->locmembers.head)
461 >    DLINK_FOREACH(uptr, channel->members_local.head)
462      {
463 <      ms = uptr->data;
464 <      target_p = ms->client_p;
683 <      assert(target_p != NULL);
463 >      member = uptr->data;
464 >      target_p = member->client;
465  
466 <      if (target_p == user || IsDefunct(target_p) ||
686 <          target_p->serial == current_serial)
466 >      if (IsDead(target_p))
467          continue;
468  
469 <      target_p->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->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
706 < * side effects - Send a message to all members of a channel that are
707 < *                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;
716 <  dlink_node *ptr;
717 <  struct Membership *ms;
718 <  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->locmembers.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 (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
521 >    if (one && (target_p == one->from))
522        continue;
523  
524 <    send_message(target_p, buffer, len);
736 <  }
737 < }
738 <
739 < /* sendto_channel_local_butone()
740 < *
741 < * inputs       - pointer to client to NOT send message to
742 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
743 < *              - pointer to channel to send to
744 < *              - var args pattern
745 < * output       - NONE
746 < * side effects - Send a message to all members of a channel that are
747 < *                locally connected to this server except one.
748 < *
749 < * WARNING - +D clients are omitted
750 < */
751 < void      
752 < sendto_channel_local_butone(struct Client *one, int type,
753 <                            struct Channel *chptr, const char *pattern, ...)
754 < {
755 <  va_list args;
756 <  char buffer[IRCD_BUFSIZE];
757 <  int len;
758 <  struct Client *target_p;
759 <  struct Membership *ms;
760 <  dlink_node *ptr;
761 <
762 <  va_start(args, pattern);
763 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
764 <  va_end(args);
765 <
766 <  DLINK_FOREACH(ptr, chptr->locmembers.head)      
767 <  {  
768 <    ms = ptr->data;
769 <    target_p = ms->client_p;
770 <
771 <    if (type != 0 && (ms->flags & type) == 0)
524 >    if (status && (member->flags & status) == 0)
525        continue;
526  
527 <    if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p))
527 >    if (poscap && HasCap(target_p, poscap) != poscap)
528        continue;
776    send_message(target_p, buffer, len);
777  }
778 }
779
780
781 /* sendto_channel_remote()
782 *
783 * inputs       - Client not to send towards
784 *              - Client from whom message is from
785 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
786 *              - pointer to channel to send to
787 *              - var args pattern
788 * output       - NONE
789 * side effects - Send a message to all members of a channel that are
790 *                remote to this server.
791 */
792 void
793 sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
794                      int nocaps, struct Channel *chptr, const char *pattern, ...)
795 {
796  va_list args;
797  char buffer[IRCD_BUFSIZE];
798  int len;
799  dlink_node *ptr;
800  struct Client *target_p;
801  struct Membership *ms;
802
803  va_start(args, pattern);
804  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
805  va_end(args);
529  
530 <  ++current_serial;
808 <
809 <  DLINK_FOREACH(ptr, chptr->members.head)
810 <  {
811 <    ms = ptr->data;
812 <    target_p = ms->client_p;
813 <
814 <    if (type != 0 && (ms->flags & type) == 0)
530 >    if (negcap && HasCap(target_p, negcap))
531        continue;
532  
533 <    if (MyConnect(target_p))
534 <      continue;
819 <    target_p = target_p->from;
533 >    send_message(target_p, buffer);
534 >  }
535  
536 <    if (target_p == one->from ||
822 <        ((target_p->from->localClient->caps & caps) != caps) ||
823 <        ((target_p->from->localClient->caps & nocaps) != 0))
824 <      continue;
825 <    if (target_p->from->serial != current_serial)
826 <    {
827 <      send_message(target_p, buffer, len);
828 <      target_p->from->serial = current_serial;
829 <    }
830 <  }
536 >  dbuf_ref_free(buffer);
537   }
538  
539   /*
# Line 847 | 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 864 | 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);
882 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
883 <                            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 (IsDead(client_p))
598 >      continue;
599  
600 <    if (client_p != one && !IsDefunct(client_p) &&
601 <        match_it(client_p, mask, what))
602 <      send_message(client_p, local_buf, local_len);
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 923 | 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 938 | 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;
947 <  char buffer[IRCD_BUFSIZE];
948 <  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++;
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 >    if (IsDead(target_p->from))
680 >      continue;
681  
682 <    /* Do not attempt to send to ourselves, or the source */
683 <    if (IsMe(target_p) || target_p->from == source_p->from)
682 >    /* Do not attempt to send to ourselves ... */
683 >    if (IsMe(target_p))
684        continue;
685  
686 <    if (target_p->from->serial == current_serial)
686 >    /* ... or the source */
687 >    if (target_p->from == source_p->from)
688 >      continue;
689 >
690 >    if (target_p->from->connection->serial == current_serial)
691        continue;
692  
693      if (match(mask, target_p->name))
694 <    {
969 <      /*
970 <       * if we set the serial here, then we'll never do a
971 <       * match() again, if !IsCapable()
972 <       */
973 <      target_p->from->serial = current_serial;
974 <      found++;
694 >      continue;
695  
696 <      if (!IsCapable(target_p->from, cap))
697 <        continue;
696 >    if (cap && IsCapable(target_p->from, cap) != cap)
697 >      continue;
698  
699 <      sendto_anywhere(target_p, source_p, "%s", buffer);
700 <    }
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 991 | 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;
998  char buffer[IRCD_BUFSIZE];
999  int len;
1000  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
1012 <        len = ircsprintf(buffer, ":%s ", from->name);
1013 <    }
1014 <    else
1015 <      len = ircsprintf(buffer, ":%s!%s@%s ",
1016 <                       from->name, from->username, from->host);
1017 <  }
1018 <  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 1036 | Line 751 | sendto_anywhere(struct Client *to, struc
751   * side effects - Send to *local* ops only but NOT +s nonopers.
752   */
753   void
754 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
754 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
755   {
756 <  struct Client *client_p;
757 <  char nbuf[IRCD_BUFSIZE];
1043 <  dlink_node *ptr;
756 >  const char *ntype = "???";
757 >  dlink_node *node;
758    va_list args;
759  
760 <  va_start(args, pattern);
1047 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
1048 <  va_end(args);
1049 <
1050 <  DLINK_FOREACH(ptr, oper_list.head)
760 >  switch (type)
761    {
762 <    client_p = ptr->data;
763 <    assert(client_p->umodes & UMODE_OPER);
764 <
765 <    /* If we're sending it to opers and theyre an admin, skip.
766 <     * If we're sending it to admins, and theyre not, skip.
767 <     */
768 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
769 <        ((level == L_OPER) && IsAdmin(client_p)))
770 <      continue;
771 <
772 <    if (client_p->umodes & flags)
1063 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1064 <                 me.name, client_p->name, nbuf);
762 >    case SEND_NOTICE:
763 >      ntype = "Notice";
764 >      break;
765 >    case SEND_GLOBAL:
766 >      ntype = "Global";
767 >      break;
768 >    case SEND_LOCOPS:
769 >      ntype = "LocOps";
770 >      break;
771 >    default:
772 >      assert(0);
773    }
1066 }
774  
775 < /* sendto_wallops_flags()
776 < *
1070 < * inputs       - flag types of messages to show to real opers
1071 < *              - client sending request
1072 < *              - var args input message
1073 < * output       - NONE
1074 < * side effects - Send a wallops to local opers
1075 < */
1076 < void
1077 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1078 <                     const char *pattern, ...)
1079 < {
1080 <  struct Client *client_p;
1081 <  dlink_node *ptr;
1082 <  va_list args;
1083 <  char buffer[IRCD_BUFSIZE];
1084 <  int len;
1085 <
1086 <  if (IsClient(source_p))
1087 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1088 <                     source_p->name, source_p->username, source_p->host);
1089 <  else
1090 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
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 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
779 >  send_format(buffer, pattern, args);
780    va_end(args);
781  
782 <  DLINK_FOREACH(ptr, oper_list.head)
782 >  DLINK_FOREACH(node, oper_list.head)
783    {
784 <    client_p = ptr->data;
785 <    assert(client_p->umodes & UMODE_OPER);
784 >    struct Client *client_p = node->data;
785 >    assert(HasUMode(client_p, UMODE_OPER));
786  
787 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
788 <      send_message(client_p, buffer, len);
1103 <  }
1104 < }
787 >    if (IsDead(client_p))
788 >      continue;
789  
790 < /* ts_warn()
791 < *
792 < * inputs       - var args message
793 < * output       - NONE
794 < * side effects - Call sendto_realops_flags, with some flood checking
795 < *                (at most 5 warnings every 5 seconds)
796 < */
1113 < void
1114 < ts_warn(const char *pattern, ...)
1115 < {
1116 <  va_list args;
1117 <  char buffer[LOG_BUFSIZE];
1118 <  static time_t last = 0;
1119 <  static int warnings = 0;
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)))
796 >      continue;
797  
798 <  /*
799 <   ** if we're running with TS_WARNINGS enabled and someone does
1123 <   ** something silly like (remotely) connecting a nonTS server,
1124 <   ** we'll get a ton of warnings, so we make sure we don't send
1125 <   ** more than 5 every 5 seconds.  -orabidoo
1126 <   */
798 >    if (!HasUMode(client_p, flags))
799 >      continue;
800  
801 <  if (CurrentTime - last < 5)
1129 <  {
1130 <    if (++warnings > 5)
1131 <      return;
1132 <  }
1133 <  else
1134 <  {
1135 <    last = CurrentTime;
1136 <    warnings = 0;
801 >    send_message(client_p, buffer);
802    }
803  
804 <  va_start(args, pattern);
1140 <  vsprintf_irc(buffer, pattern, args);
1141 <  va_end(args);
1142 <
1143 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1144 <  ilog(L_CRIT, "%s", buffer);
804 >  dbuf_ref_free(buffer);
805   }
806  
807 < /* kill_client()
807 > /* ts_warn()
808   *
809 < * inputs       - client to send kill towards
810 < *              - pointer to client to kill
811 < *              - reason for kill
812 < * output       - NONE
1153 < * side effects - NONE
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 < kill_client(struct Client *client_p, struct Client *diedie,
1157 <            const char *pattern, ...)
815 > sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
816   {
817    va_list args;
818 <  char buffer[IRCD_BUFSIZE];
1161 <  int len;
818 >  char buffer[IRCD_BUFSIZE] = "";
819  
820 <  if (client_p->from != NULL)
1164 <    client_p = client_p->from;
1165 <  if (IsDead(client_p))
820 >  if ((event_base->time.sec_monotonic - *rate) < 20)
821      return;
822  
823 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1169 <                   ID_or_name(diedie, client_p));
823 >  *rate = event_base->time.sec_monotonic;
824  
825    va_start(args, pattern);
826 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
826 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
827    va_end(args);
828  
829 <  send_message(client_p, buffer, len);
829 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
830 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
831   }
832  
833 < /* 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
1185 < *                except the client 'one'. Also deal with
1186 < *                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;
1194 <  struct Client *client_p;
1195 <  dlink_node *ptr;
1196 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1197 <  int len_uid = 0, len_nick;
847 >  struct dbuf_block *buffer = dbuf_alloc();
848  
849 <  if (HasID(source_p) && (me.id[0] != '\0'))
850 <  {
851 <    have_uid = 1;
852 <    va_start(args, pattern);
1203 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1204 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1205 <                           args);
1206 <    va_end(args);
1207 <  }
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);
1211 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1212 <                          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 <    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 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
1225 <    if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) ||
1226 <        !ServerInfo.hub ||
1227 <        (source_p->lazyLinkClientExists & client_p->localClient->serverMask))
1228 <    {
1229 <      if (have_uid && IsCapable(client_p, CAP_TS6))
1230 <        send_message(client_p, buf_uid, len_uid);
1231 <      else
1232 <        send_message(client_p, buf_nick, len_nick);
1233 <    }
869 >    send_message(client_p, buffer);
870    }
871 < }
871 >
872 >  dbuf_ref_free(buffer);
873 > }

Comparing:
ircd-hybrid-7.2/src/send.c (property svn:keywords), Revision 430 by michael, Sat Feb 11 12:52:34 2006 UTC vs.
ircd-hybrid/trunk/src/send.c (property svn:keywords), 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)