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/src/send.c (file contents), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 7330 by michael, Fri Feb 19 17:50:13 2016 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-2016 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: send.c,v 7.307 2005/10/02 12:45:07 adx Exp $
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"
36 > #include "server.h"
37 > #include "conf_class.h"
38 > #include "log.h"
39  
48 #define LOG_BUFSIZE 2048
40  
41 < struct Callback *iosend_cb = NULL;
51 < struct Callback *iosendctrl_cb = NULL;
41 > static uintmax_t current_serial;
42  
53 static void send_message(struct Client *, char *, int);
54 static void send_message_remote(struct Client *, struct Client *, char *, int);
55
56 static unsigned long current_serial = 0L;
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);
69 <  if (len > bufsize - 2)
70 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
71 <
72 <  lsendbuf[len++] = '\r';
73 <  lsendbuf[len++] = '\n';
74 <  return (len);
68 >  dbuf_put_args(buffer, pattern, args);
69 >
70 >  if (buffer->size > IRCD_BUFSIZE - 2)
71 >    buffer->size = IRCD_BUFSIZE - 2;
72 >
73 >  buffer->data[buffer->size++] = '\r';
74 >  buffer->data[buffer->size++] = '\n';
75   }
76  
77   /*
# Line 96 | Line 80 | send_format(char *lsendbuf, int bufsize,
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 <  {
104 <    sendto_realops_flags(UMODE_ALL, L_ALL,
105 <                         "Trying to send message to myself!");
106 <    return;
107 <  }
108 < #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",
92 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
93 >                           "Max SendQ limit exceeded for %s: %zu > %u",
94                             get_client_name(to, HIDE_IP),
95 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
96 <                           get_sendq(to));
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 <  dbuf_put(&to->localClient->buf_sendq, buf, len);
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) >
135 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
136 <    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
144 < *              - 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,
152 <                    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);
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135 >
136 >  if (to == from->from)
137 >  {
138 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
139 >                         "Send message to %s dropped from %s (Fake Dir)",
140 >                         to->name, from->name);
141      return;
142    }
143  
144 <  if (ServerInfo.hub && IsCapable(to, CAP_LL))
163 <  {
164 <    if (((from->lazyLinkClientExists &
165 <          to->localClient->serverMask) == 0))
166 <      client_burst_if_needed(to, from);
167 <  }
168 <
169 <  /* Optimize by checking if (from && to) before everything */
170 <  /* we set to->from up there.. */
171 <
172 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
173 <  {
174 <    if (IsServer(from))
175 <    {
176 <      sendto_realops_flags(UMODE_ALL, L_ALL,
177 <                           "Send message to %s [%s] dropped from %s(Fake Dir)",
178 <                           to->name, to->from->name, from->name);
179 <      return;
180 <    }
181 <
182 <    sendto_realops_flags(UMODE_ALL, L_ALL,
183 <                         "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
184 <                         to->name, to->username, to->host,
185 <                         from->name, from->username, from->host,
186 <                         to->from->name);
187 <
188 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
189 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
190 <                  me.id, to->name, me.name, to->name,
191 <                  to->username, to->host, to->from->name);
192 <    sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS,
193 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
194 <                  me.name, to->name, me.name, to->name,
195 <                  to->username, to->host, to->from->name);
196 <
197 <    SetKilled(to);
198 <
199 <    if (IsClient(from))
200 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
201 <                 me.name, from->name, to->name, to->username,
202 <                 to->host, to->from);
203 <
204 <    exit_client(to, &me, "Ghosted client");
205 <
206 <    return;
207 <  }
208 <
209 <  send_message(to, buf, len);
144 >  send_message(to, buf);
145   }
146  
147   /*
# Line 214 | Line 149 | send_message_remote(struct Client *to, s
149   **      Called when a socket is ready for writing.
150   */
151   void
152 < sendq_unblocked(fde_t *fd, struct Client *client_p)
152 > sendq_unblocked(fde_t *fd, void *data)
153   {
154 <  ClearSendqBlocked(client_p);
155 <  /* let send_queued_write be executed by send_queued_all */
221 <
222 < #ifdef HAVE_LIBCRYPTO
223 <  if (fd->flags.pending_read)
224 <  {
225 <    fd->flags.pending_read = 0;
226 <    read_packet(fd, client_p);
227 <  }
228 < #endif
229 < }
154 >  struct Client *const client_p = data;
155 >  assert(fd == &client_p->connection->fd);
156  
157 < /*
158 < ** slinkq_unblocked
233 < **      Called when a server control socket is ready for writing.
234 < */
235 < static void
236 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
237 < {
238 <  ClearSlinkqBlocked(client_p);
239 <  send_queued_slink_write(client_p);
157 >  DelFlag(client_p, FLAGS_BLOCKED);
158 >  send_queued_write(client_p);
159   }
160  
161   /*
# Line 248 | Line 167 | slinkq_unblocked(fde_t *fd, struct Clien
167   void
168   send_queued_write(struct Client *to)
169   {
170 <  int retlen;
171 <  struct dbuf_block *first;
170 >  int retlen = 0;
171 >  int want_read = 0;
172  
173    /*
174     ** Once socket is marked dead, we cannot start writing to it,
175     ** even if the error is removed...
176     */
177 <  if (IsDead(to) || IsSendqBlocked(to))
177 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
178      return;  /* no use calling send() now */
179  
180    /* Next, lets try to write some data */
181 <
263 <  if (dbuf_length(&to->localClient->buf_sendq))
181 >  if (dbuf_length(&to->connection->buf_sendq))
182    {
183 <    do {
184 <      first = to->localClient->buf_sendq.blocks.head->data;
183 >    do
184 >    {
185 >      const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
186  
187 < #ifdef HAVE_LIBCRYPTO
269 <      if (to->localClient->fd.ssl)
187 >      if (tls_isusing(&to->connection->fd.ssl))
188        {
189 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
189 >        retlen = tls_write(&to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos,
190 >                                                    first->size - to->connection->buf_sendq.pos, &want_read);
191  
192 <        /* translate openssl error codes, sigh */
193 <        if (retlen < 0)
275 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
276 <          {
277 <            case SSL_ERROR_WANT_READ:
278 <              return;  /* retry later, don't register for write events */
279 <
280 <            case SSL_ERROR_WANT_WRITE:
281 <              errno = EWOULDBLOCK;
282 <            case SSL_ERROR_SYSCALL:
283 <              break;
284 <
285 <            default:
286 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
287 <          }
192 >        if (want_read)
193 >          return;  /* Retry later, don't register for write events */
194        }
195        else
196 < #endif
197 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
196 >        retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos,
197 >                                             first->size - to->connection->buf_sendq.pos, 0);
198  
199        if (retlen <= 0)
294      {
295 #ifdef _WIN32
296        errno = WSAGetLastError();
297 #endif
200          break;
299      }
201  
202 <      execute_callback(iosend_cb, to, retlen, first->data);
302 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
202 >      dbuf_delete(&to->connection->buf_sendq, retlen);
203  
204        /* We have some data written .. update counters */
205 <      to->localClient->send.bytes += retlen;
206 <      me.localClient->send.bytes += retlen;
207 <    } while (dbuf_length(&to->localClient->buf_sendq));
205 >      to->connection->send.bytes += retlen;
206 >      me.connection->send.bytes += retlen;
207 >    } while (dbuf_length(&to->connection->buf_sendq));
208  
209 <    if ((retlen < 0) && (ignoreErrno(errno)))
209 >    if (retlen < 0 && ignoreErrno(errno))
210      {
211 +      AddFlag(to, FLAGS_BLOCKED);
212 +
213        /* we have a non-fatal error, reschedule a write */
214 <      SetSendqBlocked(to);
313 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
314 <                     (PF *)sendq_unblocked, (void *)to, 0);
214 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
215      }
216      else if (retlen <= 0)
217      {
# Line 321 | Line 221 | send_queued_write(struct Client *to)
221    }
222   }
223  
324 /*
325 ** send_queued_slink_write
326 **      This is called when there is a chance the some output would
327 **      be possible. This attempts to empty the send queue as far as
328 **      possible, and then if any data is left, a write is rescheduled.
329 */
330 void
331 send_queued_slink_write(struct Client *to)
332 {
333  int retlen;
334
335  /*
336   ** Once socket is marked dead, we cannot start writing to it,
337   ** even if the error is removed...
338   */
339  if (IsDead(to) || IsSlinkqBlocked(to))
340    return;  /* no use calling send() now */
341
342  /* Next, lets try to write some data */
343  if (to->localClient->slinkq != NULL)
344  {
345    retlen = send(to->localClient->ctrlfd.fd,
346                   to->localClient->slinkq + to->localClient->slinkq_ofs,
347                   to->localClient->slinkq_len, 0);
348    if (retlen < 0)
349    {
350      /* If we have a fatal error */
351      if (!ignoreErrno(errno))
352      {
353        dead_link_on_write(to, errno);
354        return;
355      }
356    }
357    else if (retlen == 0)
358    {
359      /* 0 bytes is an EOF .. */
360      dead_link_on_write(to, 0);
361      return;
362    }
363    else
364    {
365      execute_callback(iosendctrl_cb, to, retlen,
366        to->localClient->slinkq + to->localClient->slinkq_ofs);
367      to->localClient->slinkq_len -= retlen;
368
369      assert(to->localClient->slinkq_len >= 0);
370      if (to->localClient->slinkq_len)
371        to->localClient->slinkq_ofs += retlen;
372      else
373      {
374        to->localClient->slinkq_ofs = 0;
375        MyFree(to->localClient->slinkq);
376        to->localClient->slinkq = NULL;
377      }
378    }
379
380    /* Finally, if we have any more data, reschedule a write */
381    if (to->localClient->slinkq_len)
382    {
383      SetSlinkqBlocked(to);
384      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
385                     (PF *)slinkq_unblocked, (void *)to, 0);
386    }
387  }
388 }
389
224   /* send_queued_all()
225   *
226   * input        - NONE
# Line 396 | Line 230 | send_queued_slink_write(struct Client *t
230   void
231   send_queued_all(void)
232   {
233 <  dlink_node *ptr;
233 >  dlink_node *node = NULL;
234  
235    /* Servers are processed first, mainly because this can generate
236     * a notice to opers, which is to be delivered by this function.
237     */
238 <  DLINK_FOREACH(ptr, serv_list.head)
239 <    send_queued_write((struct Client *) ptr->data);
238 >  DLINK_FOREACH(node, local_server_list.head)
239 >    send_queued_write(node->data);
240  
241 <  DLINK_FOREACH(ptr, unknown_list.head)
242 <    send_queued_write((struct Client *) ptr->data);
241 >  DLINK_FOREACH(node, unknown_list.head)
242 >    send_queued_write(node->data);
243  
244 <  DLINK_FOREACH(ptr, local_client_list.head)
245 <    send_queued_write((struct Client *) ptr->data);
244 >  DLINK_FOREACH(node, local_client_list.head)
245 >    send_queued_write(node->data);
246  
247    /* NOTE: This can still put clients on aborted_list; unfortunately,
248     * exit_aborted_clients takes precedence over send_queued_all,
# Line 429 | Line 263 | void
263   sendto_one(struct Client *to, const char *pattern, ...)
264   {
265    va_list args;
266 <  char buffer[IRCD_BUFSIZE];
267 <  int len;
266 >  struct dbuf_block *buffer = NULL;
267 >
268 >  if (IsDead(to->from))
269 >    return;  /* This socket has already been marked as dead */
270  
271 <  if (to->from != NULL)
436 <    to = to->from;
437 <  if (IsDead(to))
438 <    return; /* This socket has already been marked as dead */
271 >  buffer = dbuf_alloc();
272  
273    va_start(args, pattern);
274 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
274 >  send_format(buffer, pattern, args);
275    va_end(args);
276  
277 <  send_message(to, buffer, len);
277 >  send_message(to->from, buffer);
278 >
279 >  dbuf_ref_free(buffer);
280 > }
281 >
282 > void
283 > sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
284 > {
285 >  struct dbuf_block *buffer = NULL;
286 >  const char *dest = NULL, *numstr = NULL;
287 >  va_list args;
288 >
289 >  if (IsDead(to->from))
290 >    return;
291 >
292 >  dest = ID_or_name(to, to);
293 >
294 >  if (EmptyString(dest))
295 >    dest = "*";
296 >
297 >  buffer = dbuf_alloc();
298 >
299 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
300 >
301 >  va_start(args, numeric);
302 >
303 >  if (numeric & SND_EXPLICIT)
304 >    numstr = va_arg(args, const char *);
305 >  else
306 >    numstr = numeric_form(numeric);
307 >
308 >  send_format(buffer, numstr, args);
309 >  va_end(args);
310 >
311 >  send_message(to->from, buffer);
312 >
313 >  dbuf_ref_free(buffer);
314 > }
315 >
316 > void
317 > sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
318 > {
319 >  struct dbuf_block *buffer = NULL;
320 >  const char *dest = NULL;
321 >  va_list args;
322 >
323 >  if (IsDead(to->from))
324 >    return;
325 >
326 >  dest = ID_or_name(to, to);
327 >
328 >  if (EmptyString(dest))
329 >    dest = "*";
330 >
331 >  buffer = dbuf_alloc();
332 >
333 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
334 >
335 >  va_start(args, pattern);
336 >  send_format(buffer, pattern, args);
337 >  va_end(args);
338 >
339 >  send_message(to->from, buffer);
340 >
341 >  dbuf_ref_free(buffer);
342   }
343  
344   /* sendto_channel_butone()
# Line 456 | Line 353 | sendto_one(struct Client *to, const char
353   * WARNING - +D clients are ignored
354   */
355   void
356 < sendto_channel_butone(struct Client *one, struct Client *from,
357 <                      struct Channel *chptr, const char *command,
356 > sendto_channel_butone(struct Client *one, const struct Client *from,
357 >                      struct Channel *chptr, unsigned int type,
358                        const char *pattern, ...)
359   {
360 <  va_list args;
361 <  char local_buf[IRCD_BUFSIZE];
362 <  char remote_buf[IRCD_BUFSIZE];
363 <  char uid_buf[IRCD_BUFSIZE];
364 <  int local_len, remote_len, uid_len;
468 <  dlink_node *ptr;
469 <  dlink_node *ptr_next;
470 <  struct Client *target_p;
360 >  va_list alocal, aremote;
361 >  struct dbuf_block *local_buf, *remote_buf;
362 >  dlink_node *node = NULL;
363 >
364 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
365  
366 <  if (IsServer(from))
367 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
474 <                           from->name, command, chptr->chname);
366 >  if (IsClient(from))
367 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
368    else
369 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
477 <                           from->name, from->username, from->host,
478 <                           command, chptr->chname);
479 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
480 <                          from->name, command, chptr->chname);
481 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
482 <                       ID(from), command, chptr->chname);
369 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
370  
371 <  va_start(args, pattern);
372 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
373 <                           pattern, args);
374 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
375 <                            pattern, args);
376 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
377 <                         args);
378 <  va_end(args);
371 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
372 >
373 >  va_start(alocal, pattern);
374 >  va_start(aremote, pattern);
375 >  send_format(local_buf, pattern, alocal);
376 >  send_format(remote_buf, pattern, aremote);
377 >
378 >  va_end(aremote);
379 >  va_end(alocal);
380  
381    ++current_serial;
382  
383 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
383 >  DLINK_FOREACH(node, chptr->members.head)
384    {
385 <    target_p = ((struct Membership *)ptr->data)->client_p;
386 <    assert(target_p != NULL);
385 >    struct Membership *member = node->data;
386 >    struct Client *target_p = member->client_p;
387 >
388 >    assert(IsClient(target_p));
389  
390 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
390 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
391 >        (one && target_p->from == one->from))
392        continue;
393  
394 <    if (MyClient(target_p))
395 <    {
396 <      if (target_p->serial != current_serial)
397 <      {
398 <        send_message(target_p, local_buf, local_len);
399 <        target_p->serial = current_serial;
400 <      }
401 <    }
402 <    else
512 <    {
513 <      /* Now check whether a message has been sent to this
514 <       * remote link already
515 <       */
516 <      if (target_p->from->serial != current_serial)
517 <      {
518 <        if (IsCapable(target_p->from, CAP_TS6))
519 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
520 <        else
521 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
522 <        target_p->from->serial = current_serial;
523 <      }
524 <    }
394 >    if (type && (member->flags & type) == 0)
395 >      continue;
396 >
397 >    if (MyConnect(target_p))
398 >      send_message(target_p, local_buf);
399 >    else if (target_p->from->connection->serial != current_serial)
400 >      send_message_remote(target_p->from, from, remote_buf);
401 >
402 >    target_p->from->connection->serial = current_serial;
403    }
404 +
405 +  dbuf_ref_free(local_buf);
406 +  dbuf_ref_free(remote_buf);
407   }
408  
409   /* sendto_server()
410 < *
410 > *
411   * inputs       - pointer to client to NOT send to
412 < *              - pointer to source client required by LL (if any)
532 < *              - pointer to channel required by LL (if any)
412 > *              - pointer to channel
413   *              - caps or'd together which must ALL be present
414   *              - caps or'd together which must ALL NOT be present
535 *              - LL flags: LL_ICLIENT | LL_ICHAN
415   *              - printf style format string
416   *              - args to format string
417   * output       - NONE
418   * side effects - Send a message to all connected servers, except the
419   *                client 'one' (if non-NULL), as long as the servers
420   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
421 < *                If the server is a lazylink client, then it must know
543 < *                about source_p if non-NULL (unless LL_ICLIENT is specified,
544 < *                when source_p will be introduced where required) and
545 < *                chptr if non-NULL (unless LL_ICHANNEL is specified, when
546 < *                chptr will be introduced where required).
547 < *                Note: nothing will be introduced to a LazyLeaf unless
548 < *                the message is actually sent.
549 < *            
421 > *
422   * This function was written in an attempt to merge together the other
423   * billion sendto_*serv*() functions, which sprung up with capabs,
424   * lazylinks, uids, etc.
425   * -davidt
426   */
427 < void
428 < sendto_server(struct Client *one, struct Client *source_p,
429 <              struct Channel *chptr, unsigned long caps,
430 <              unsigned long nocaps, unsigned long llflags,
427 > void
428 > sendto_server(const struct Client *one,
429 >              const unsigned int caps,
430 >              const unsigned int nocaps,
431                const char *format, ...)
432   {
433    va_list args;
434 <  struct Client *client_p;
435 <  dlink_node *ptr;
564 <  char buffer[IRCD_BUFSIZE];
565 <  int len;
566 <
567 <  if (chptr != NULL)
568 <  {
569 <    if (chptr->chname[0] != '#')
570 <      return;
571 <  }
434 >  dlink_node *node = NULL;
435 >  struct dbuf_block *buffer = dbuf_alloc();
436  
437    va_start(args, format);
438 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
438 >  send_format(buffer, format, args);
439    va_end(args);
440  
441 <  DLINK_FOREACH(ptr, serv_list.head)
441 >  DLINK_FOREACH(node, local_server_list.head)
442    {
443 <    client_p = ptr->data;
443 >    struct Client *client_p = node->data;
444  
445      /* If dead already skip */
446      if (IsDead(client_p))
447        continue;
448 +
449      /* check against 'one' */
450 <    if (one != NULL && (client_p == one->from))
450 >    if (one && (client_p == one->from))
451        continue;
452 +
453      /* check we have required capabs */
454 <    if ((client_p->localClient->caps & caps) != caps)
454 >    if ((client_p->connection->caps & caps) != caps)
455        continue;
456 +
457      /* check we don't have any forbidden capabs */
458 <    if ((client_p->localClient->caps & nocaps) != 0)
458 >    if ((client_p->connection->caps & nocaps))
459        continue;
460  
461 <    if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
595 <    {
596 <      /* check LL channel */
597 <      if (chptr != NULL &&
598 <          ((chptr->lazyLinkChannelExists &
599 <            client_p->localClient->serverMask) == 0))
600 <      {
601 <        /* Only introduce the channel if we really will send this message */
602 <        if (!(llflags & LL_ICLIENT) && source_p &&
603 <            ((source_p->lazyLinkClientExists &
604 <              client_p->localClient->serverMask) == 0))
605 <          continue; /* we can't introduce the unknown source_p, skip */
606 <
607 <        if (llflags & LL_ICHAN)
608 <          burst_channel(client_p, chptr);
609 <        else
610 <          continue; /* we can't introduce the unknown chptr, skip */
611 <      }
612 <      /* check LL client */
613 <      if (source_p &&
614 <          ((source_p->lazyLinkClientExists &
615 <            client_p->localClient->serverMask) == 0))
616 <      {
617 <        if (llflags & LL_ICLIENT)
618 <          client_burst_if_needed(client_p,source_p);
619 <        else
620 <          continue; /* we can't introduce the unknown source_p, skip */
621 <      }
622 <    }
623 <    send_message(client_p, buffer, len);
461 >    send_message(client_p, buffer);
462    }
463 +
464 +  dbuf_ref_free(buffer);
465   }
466  
467   /* sendto_common_channels_local()
# Line 630 | Line 470 | sendto_server(struct Client *one, struct
470   *              - pattern to send
471   * output       - NONE
472   * side effects - Sends a message to all people on local server who are
473 < *                in same channel with user.
473 > *                in same channel with user.
474   *                used by m_nick.c and exit_one_client.
475   */
476   void
477 < sendto_common_channels_local(struct Client *user, int touser,
478 <                             const char *pattern, ...)
477 > sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap,
478 >                             unsigned int negcap, const char *pattern, ...)
479   {
480    va_list args;
481    dlink_node *uptr;
482    dlink_node *cptr;
483    struct Channel *chptr;
484 <  struct Membership *ms;
484 >  struct Membership *member;
485    struct Client *target_p;
486 <  char buffer[IRCD_BUFSIZE];
647 <  int len;
486 >  struct dbuf_block *buffer = dbuf_alloc();
487  
488    va_start(args, pattern);
489 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
489 >  send_format(buffer, pattern, args);
490    va_end(args);
491  
492    ++current_serial;
493  
494    DLINK_FOREACH(cptr, user->channel.head)
495    {
496 <    chptr = ((struct Membership *) cptr->data)->chptr;
658 <    assert(chptr != NULL);
496 >    chptr = ((struct Membership *)cptr->data)->chptr;
497  
498      DLINK_FOREACH(uptr, chptr->locmembers.head)
499      {
500 <      ms = uptr->data;
501 <      target_p = ms->client_p;
664 <      assert(target_p != NULL);
500 >      member = uptr->data;
501 >      target_p = member->client_p;
502  
503        if (target_p == user || IsDefunct(target_p) ||
504 <          target_p->serial == current_serial)
504 >          target_p->connection->serial == current_serial)
505 >        continue;
506 >
507 >      if (poscap && HasCap(target_p, poscap) != poscap)
508 >        continue;
509 >
510 >      if (negcap && HasCap(target_p, negcap))
511          continue;
512  
513 <      target_p->serial = current_serial;
514 <      send_message(target_p, buffer, len);
513 >      target_p->connection->serial = current_serial;
514 >      send_message(target_p, buffer);
515      }
516    }
517  
518    if (touser && MyConnect(user) && !IsDead(user) &&
519 <      user->serial != current_serial)
520 <    send_message(user, buffer, len);
519 >      user->connection->serial != current_serial)
520 >    if (HasCap(user, poscap) == poscap)
521 >      send_message(user, buffer);
522 >
523 >  dbuf_ref_free(buffer);
524   }
525  
526 < /* sendto_channel_local()
527 < *
528 < * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
529 < *              - whether to ignore +D clients (YES/NO)
530 < *              - pointer to channel to send to
531 < *              - var args pattern
532 < * output       - NONE
687 < * side effects - Send a message to all members of a channel that are
688 < *                locally connected to this server.
526 > /*! \brief Send a message to members of a channel that are locally connected to this server.
527 > * \param one      Client to skip; can be NULL
528 > * \param chptr    Destination channel
529 > * \param status   Channel member status flags clients must have
530 > * \param poscap   Positive client capabilities flags (CAP)
531 > * \param negcap   Negative client capabilities flags (CAP)
532 > * \param pattern  Format string for command arguments
533   */
534   void
535 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
536 <                     const char *pattern, ...)
535 > sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status,
536 >                     unsigned int poscap, unsigned int negcap, const char *pattern, ...)
537   {
538    va_list args;
539 <  char buffer[IRCD_BUFSIZE];
540 <  int len;
697 <  dlink_node *ptr;
698 <  struct Membership *ms;
699 <  struct Client *target_p;
539 >  dlink_node *node = NULL;
540 >  struct dbuf_block *buffer = dbuf_alloc();
541  
542    va_start(args, pattern);
543 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
543 >  send_format(buffer, pattern, args);
544    va_end(args);
545  
546 <  DLINK_FOREACH(ptr, chptr->locmembers.head)
546 >  DLINK_FOREACH(node, chptr->locmembers.head)
547    {
548 <    ms = ptr->data;
549 <    target_p = ms->client_p;
548 >    struct Membership *member = node->data;
549 >    struct Client *target_p = member->client_p;
550  
551 <    if (type != 0 && (ms->flags & type) == 0)
551 >    if (IsDefunct(target_p))
552        continue;
553  
554 <    if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
554 >    if (one && target_p == one->from)
555        continue;
556  
557 <    send_message(target_p, buffer, len);
717 <  }
718 < }
719 <
720 < /* sendto_channel_local_butone()
721 < *
722 < * inputs       - pointer to client to NOT send message to
723 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
724 < *              - pointer to channel to send to
725 < *              - var args pattern
726 < * output       - NONE
727 < * side effects - Send a message to all members of a channel that are
728 < *                locally connected to this server except one.
729 < *
730 < * WARNING - +D clients are omitted
731 < */
732 < void      
733 < sendto_channel_local_butone(struct Client *one, int type,
734 <                            struct Channel *chptr, const char *pattern, ...)
735 < {
736 <  va_list args;
737 <  char buffer[IRCD_BUFSIZE];
738 <  int len;
739 <  struct Client *target_p;
740 <  struct Membership *ms;
741 <  dlink_node *ptr;
742 <
743 <  va_start(args, pattern);
744 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
745 <  va_end(args);
746 <
747 <  DLINK_FOREACH(ptr, chptr->locmembers.head)      
748 <  {  
749 <    ms = ptr->data;
750 <    target_p = ms->client_p;
751 <
752 <    if (type != 0 && (ms->flags & type) == 0)
557 >    if (status && (member->flags & status) == 0)
558        continue;
559  
560 <    if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p))
756 <      continue;
757 <    send_message(target_p, buffer, len);
758 <  }
759 < }
760 <
761 <
762 < /* sendto_channel_remote()
763 < *
764 < * inputs       - Client not to send towards
765 < *              - Client from whom message is from
766 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
767 < *              - pointer to channel to send to
768 < *              - var args pattern
769 < * output       - NONE
770 < * side effects - Send a message to all members of a channel that are
771 < *                remote to this server.
772 < */
773 < void
774 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
775 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
776 < {
777 <  va_list args;
778 <  char buffer[IRCD_BUFSIZE];
779 <  int len;
780 <  dlink_node *ptr;
781 <  struct Client *target_p;
782 <  struct Membership *ms;
783 <
784 <  va_start(args, pattern);
785 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
786 <  va_end(args);
787 <
788 <  DLINK_FOREACH(ptr, chptr->members.head)
789 <  {
790 <    ms = ptr->data;
791 <    target_p = ms->client_p;
792 <
793 <    if (type != 0 && (ms->flags & type) == 0)
560 >    if (poscap && HasCap(target_p, poscap) != poscap)
561        continue;
562  
563 <    if (MyConnect(target_p))
563 >    if (negcap && HasCap(target_p, negcap))
564        continue;
798    target_p = target_p->from;
565  
566 <    if (target_p == one->from ||
567 <        ((target_p->from->localClient->caps & caps) != caps) ||
802 <        ((target_p->from->localClient->caps & nocaps) != 0))
803 <      continue;
566 >    send_message(target_p, buffer);
567 >  }
568  
569 <    send_message(target_p, buffer, len);
806 <  }
569 >  dbuf_ref_free(buffer);
570   }
571  
572   /*
# Line 824 | Line 587 | sendto_channel_remote(struct Client *one
587   * side effects - NONE
588   */
589   static int
590 < match_it(const struct Client *one, const char *mask, int what)
590 > match_it(const struct Client *one, const char *mask, unsigned int what)
591   {
592    if (what == MATCH_HOST)
593 <    return(match(mask, one->host));
593 >    return !match(mask, one->host);
594  
595 <  return(match(mask, one->servptr->name));
595 >  return !match(mask, one->servptr->name);
596   }
597  
598   /* sendto_match_butone()
# Line 840 | Line 603 | match_it(const struct Client *one, const
603   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
604   */
605   void
606 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
607 <                    int what, const char *pattern, ...)
606 > sendto_match_butone(const struct Client *one, const struct Client *from,
607 >                    const char *mask, int what, const char *pattern, ...)
608   {
609 <  va_list args;
610 <  struct Client *client_p;
611 <  dlink_node *ptr, *ptr_next;
612 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
613 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
614 <                             from->username, from->host);
615 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
616 <
617 <  va_start(args, pattern);
618 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
619 <                           pattern, args);
620 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
621 <                            pattern, args);
622 <  va_end(args);
609 >  va_list alocal, aremote;
610 >  dlink_node *node = NULL;
611 >  struct dbuf_block *local_buf, *remote_buf;
612 >
613 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
614 >
615 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
616 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
617 >
618 >  va_start(alocal, pattern);
619 >  va_start(aremote, pattern);
620 >  send_format(local_buf, pattern, alocal);
621 >  send_format(remote_buf, pattern, aremote);
622 >  va_end(aremote);
623 >  va_end(alocal);
624  
625    /* scan the local clients */
626 <  DLINK_FOREACH(ptr, local_client_list.head)
626 >  DLINK_FOREACH(node, local_client_list.head)
627    {
628 <    client_p = ptr->data;
628 >    struct Client *client_p = node->data;
629  
630 <    if (client_p != one && !IsDefunct(client_p) &&
630 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
631          match_it(client_p, mask, what))
632 <      send_message(client_p, local_buf, local_len);
632 >      send_message(client_p, local_buf);
633    }
634  
635    /* Now scan servers */
636 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
636 >  DLINK_FOREACH(node, local_server_list.head)
637    {
638 <    client_p = ptr->data;
638 >    struct Client *client_p = node->data;
639  
640      /*
641       * The old code looped through every client on the
# Line 897 | Line 661 | sendto_match_butone(struct Client *one,
661       * server deal with it.
662       * -wnder
663       */
664 <    if (client_p != one && !IsDefunct(client_p))
665 <      send_message_remote(client_p, from, remote_buf, remote_len);
664 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
665 >      send_message_remote(client_p, from, remote_buf);
666    }
667 +
668 +  dbuf_ref_free(local_buf);
669 +  dbuf_ref_free(remote_buf);
670   }
671  
672   /* sendto_match_servs()
# Line 912 | Line 679 | sendto_match_butone(struct Client *one,
679   * side effects - data sent to servers matching with capab
680   */
681   void
682 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
682 > sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
683                     const char *pattern, ...)
684   {
685    va_list args;
686 <  struct Client *target_p;
687 <  dlink_node *ptr;
921 <  char buffer[IRCD_BUFSIZE];
922 <  int found = 0;
686 >  dlink_node *node = NULL;
687 >  struct dbuf_block *buffer = dbuf_alloc();
688  
689 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
690    va_start(args, pattern);
691 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
691 >  send_format(buffer, pattern, args);
692    va_end(args);
693  
694 <  current_serial++;
694 >  ++current_serial;
695  
696 <  DLINK_FOREACH(ptr, global_serv_list.head)
696 >  DLINK_FOREACH(node, global_server_list.head)
697    {
698 <    target_p = ptr->data;
698 >    struct Client *target_p = node->data;
699  
700      /* Do not attempt to send to ourselves, or the source */
701      if (IsMe(target_p) || target_p->from == source_p->from)
702        continue;
703  
704 <    if (target_p->from->serial == current_serial)
704 >    if (target_p->from->connection->serial == current_serial)
705        continue;
706  
707      if (match(mask, target_p->name))
708 <    {
943 <      /*
944 <       * if we set the serial here, then we'll never do a
945 <       * match() again, if !IsCapable()
946 <       */
947 <      target_p->from->serial = current_serial;
948 <      found++;
708 >      continue;
709  
710 <      if (!IsCapable(target_p->from, cap))
711 <        continue;
710 >    /*
711 >     * If we set the serial here, then we'll never do a
712 >     * match() again, if !IsCapable()
713 >     */
714 >    target_p->from->connection->serial = current_serial;
715  
716 <      sendto_anywhere(target_p, source_p, "%s", buffer);
717 <    }
716 >    if (cap && IsCapable(target_p->from, cap) != cap)
717 >      continue;
718 >
719 >    send_message_remote(target_p->from, source_p, buffer);
720    }
721 +
722 +  dbuf_ref_free(buffer);
723   }
724  
725   /* sendto_anywhere()
# Line 965 | Line 732 | sendto_match_servs(struct Client *source
732   *                but useful when one does not know where target "lives"
733   */
734   void
735 < sendto_anywhere(struct Client *to, struct Client *from,
735 > sendto_anywhere(struct Client *to, const struct Client *from,
736 >                const char *command,
737                  const char *pattern, ...)
738   {
739    va_list args;
740 <  char buffer[IRCD_BUFSIZE];
973 <  int len;
974 <  struct Client *send_to = (to->from != NULL ? to->from : to);
740 >  struct dbuf_block *buffer = NULL;
741  
742 <  if (IsDead(send_to))
742 >  if (IsDead(to->from))
743      return;
744  
745 <  if (MyClient(to))
746 <  {
747 <    if (IsServer(from))
748 <    {
749 <      if (IsCapable(to, CAP_TS6) && HasID(from))
750 <        len = ircsprintf(buffer, ":%s ", from->id);
751 <      else
752 <        len = ircsprintf(buffer, ":%s ", from->name);
987 <    }
988 <    else
989 <      len = ircsprintf(buffer, ":%s!%s@%s ",
990 <                       from->name, from->username, from->host);
991 <  }
992 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
745 >  buffer = dbuf_alloc();
746 >
747 >  if (MyClient(to) && IsClient(from))
748 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
749 >                 from->host, command, to->name);
750 >  else
751 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
752 >                 command, ID_or_name(to, to));
753  
754    va_start(args, pattern);
755 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
755 >  send_format(buffer, pattern, args);
756    va_end(args);
757  
758 <  if(MyClient(to))
759 <    send_message(send_to, buffer, len);
758 >  if (MyConnect(to))
759 >    send_message(to, buffer);
760    else
761 <    send_message_remote(send_to, from, buffer, len);
761 >    send_message_remote(to->from, from, buffer);
762 >
763 >  dbuf_ref_free(buffer);
764   }
765  
766   /* sendto_realops_flags()
# Line 1010 | Line 772 | sendto_anywhere(struct Client *to, struc
772   * side effects - Send to *local* ops only but NOT +s nonopers.
773   */
774   void
775 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
775 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
776   {
777 <  struct Client *client_p;
778 <  char nbuf[IRCD_BUFSIZE];
779 <  dlink_node *ptr;
777 >  const char *ntype = NULL;
778 >  dlink_node *node = NULL;
779 >  char nbuf[IRCD_BUFSIZE] = "";
780    va_list args;
781  
782    va_start(args, pattern);
783 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
783 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
784    va_end(args);
785  
786 <  DLINK_FOREACH(ptr, oper_list.head)
786 >  switch (type)
787    {
788 <    client_p = ptr->data;
789 <    assert(client_p->umodes & UMODE_OPER);
790 <
791 <    /* If we're sending it to opers and theyre an admin, skip.
792 <     * If we're sending it to admins, and theyre not, skip.
793 <     */
794 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
795 <        ((level == L_OPER) && IsAdmin(client_p)))
796 <      continue;
797 <
798 <    if (client_p->umodes & flags)
1037 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1038 <                 me.name, client_p->name, nbuf);
788 >    case SEND_NOTICE:
789 >      ntype = "Notice";
790 >      break;
791 >    case SEND_GLOBAL:
792 >      ntype = "Global";
793 >      break;
794 >    case SEND_LOCOPS:
795 >      ntype = "LocOps";
796 >      break;
797 >    default:
798 >      assert(0);
799    }
1040 }
800  
801 < /* sendto_wallops_flags()
1043 < *
1044 < * inputs       - flag types of messages to show to real opers
1045 < *              - client sending request
1046 < *              - var args input message
1047 < * output       - NONE
1048 < * side effects - Send a wallops to local opers
1049 < */
1050 < void
1051 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1052 <                     const char *pattern, ...)
1053 < {
1054 <  struct Client *client_p;
1055 <  dlink_node *ptr;
1056 <  va_list args;
1057 <  char buffer[IRCD_BUFSIZE];
1058 <  int len;
1059 <
1060 <  if (IsClient(source_p))
1061 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1062 <                     source_p->name, source_p->username, source_p->host);
1063 <  else
1064 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
1065 <
1066 <  va_start(args, pattern);
1067 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1068 <  va_end(args);
1069 <
1070 <  DLINK_FOREACH(ptr, oper_list.head)
801 >  DLINK_FOREACH(node, oper_list.head)
802    {
803 <    client_p = ptr->data;
804 <    assert(client_p->umodes & UMODE_OPER);
1074 <
1075 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
1076 <      send_message(client_p, buffer, len);
1077 <  }
1078 < }
1079 <
1080 < /* ts_warn()
1081 < *
1082 < * inputs       - var args message
1083 < * output       - NONE
1084 < * side effects - Call sendto_realops_flags, with some flood checking
1085 < *                (at most 5 warnings every 5 seconds)
1086 < */
1087 < void
1088 < ts_warn(const char *pattern, ...)
1089 < {
1090 <  va_list args;
1091 <  char buffer[LOG_BUFSIZE];
1092 <  static time_t last = 0;
1093 <  static int warnings = 0;
803 >    struct Client *client_p = node->data;
804 >    assert(HasUMode(client_p, UMODE_OPER));
805  
806 <  /*
807 <   ** if we're running with TS_WARNINGS enabled and someone does
808 <   ** something silly like (remotely) connecting a nonTS server,
809 <   ** we'll get a ton of warnings, so we make sure we don't send
810 <   ** more than 5 every 5 seconds.  -orabidoo
811 <   */
806 >    /*
807 >     * If we're sending it to opers and they're an admin, skip.
808 >     * If we're sending it to admins, and they're not, skip.
809 >     */
810 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
811 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
812 >      continue;
813  
814 <  if (CurrentTime - last < 5)
815 <  {
816 <    if (++warnings > 5)
1105 <      return;
1106 <  }
1107 <  else
1108 <  {
1109 <    last = CurrentTime;
1110 <    warnings = 0;
814 >    if (HasUMode(client_p, flags))
815 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
816 >                 me.name, client_p->name, ntype, nbuf);
817    }
1112
1113  va_start(args, pattern);
1114  vsprintf_irc(buffer, pattern, args);
1115  va_end(args);
1116
1117  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1118  ilog(L_CRIT, "%s", buffer);
818   }
819  
820 < /* kill_client()
820 > /* ts_warn()
821   *
822 < * inputs       - client to send kill towards
823 < *              - pointer to client to kill
824 < *              - reason for kill
825 < * output       - NONE
1127 < * side effects - NONE
822 > * inputs       - var args message
823 > * output       - NONE
824 > * side effects - Call sendto_realops_flags, with some flood checking
825 > *                (at most 5 warnings every 5 seconds)
826   */
827   void
828 < kill_client(struct Client *client_p, struct Client *diedie,
1131 <            const char *pattern, ...)
828 > sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
829   {
830    va_list args;
831 <  char buffer[IRCD_BUFSIZE];
1135 <  int len;
831 >  char buffer[IRCD_BUFSIZE] = "";
832  
833 <  if (client_p->from != NULL)
1138 <    client_p = client_p->from;
1139 <  if (IsDead(client_p))
833 >  if ((CurrentTime - *rate) < 20)
834      return;
835  
836 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1143 <                   ID_or_name(diedie, client_p));
836 >  *rate = CurrentTime;
837  
838    va_start(args, pattern);
839 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
839 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
840    va_end(args);
841  
842 <  send_message(client_p, buffer, len);
842 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
843 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
844   }
845  
846 < /* kill_client_ll_serv_butone()
846 > /* sendto_wallops_flags()
847   *
848 < * inputs       - pointer to client to not send to
849 < *              - pointer to client to kill
850 < * output       - NONE
851 < * side effects - Send a KILL for the given client
852 < *                message to all connected servers
1159 < *                except the client 'one'. Also deal with
1160 < *                client being unknown to leaf, as in lazylink...
848 > * inputs       - flag types of messages to show to real opers
849 > *              - client sending request
850 > *              - var args input message
851 > * output       - NONE
852 > * side effects - Send a wallops to local opers
853   */
854   void
855 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
856 <                           const char *pattern, ...)
855 > sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
856 >                     const char *pattern, ...)
857   {
858 +  dlink_node *node = NULL;
859    va_list args;
860 <  int have_uid = 0;
861 <  struct Client *client_p;
862 <  dlink_node *ptr;
863 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
864 <  int len_uid = 0, len_nick;
860 >  struct dbuf_block *buffer = dbuf_alloc();
861 >
862 >  if (IsClient(source_p))
863 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
864 >  else
865 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
866  
867    va_start(args, pattern);
868 <  if (HasID(source_p) && (me.id[0] != '\0'))
1175 <  {
1176 <    have_uid = 1;
1177 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1178 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1179 <                           args);
1180 <  }
1181 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1182 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1183 <                          args);
868 >  send_format(buffer, pattern, args);
869    va_end(args);
870  
871 <  DLINK_FOREACH(ptr, serv_list.head)
871 >  DLINK_FOREACH(node, oper_list.head)
872    {
873 <    client_p = ptr->data;
874 <
1190 <    if (one != NULL && (client_p == one->from))
1191 <      continue;
1192 <    if (IsDefunct(client_p))
1193 <      continue;
873 >    struct Client *client_p = node->data;
874 >    assert(client_p->umodes & UMODE_OPER);
875  
876 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
877 <    if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) ||
1197 <        !ServerInfo.hub ||
1198 <        (source_p->lazyLinkClientExists & client_p->localClient->serverMask))
1199 <    {
1200 <      if (have_uid && IsCapable(client_p, CAP_TS6))
1201 <        send_message(client_p, buf_uid, len_uid);
1202 <      else
1203 <        send_message(client_p, buf_nick, len_nick);
1204 <    }
876 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
877 >      send_message(client_p, buffer);
878    }
879 < }
879 >
880 >  dbuf_ref_free(buffer);
881 > }

Comparing:
ircd-hybrid/src/send.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/src/send.c (property svn:keywords), Revision 7330 by michael, Fri Feb 19 17:50:13 2016 UTC

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

Diff Legend

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