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

Comparing ircd-hybrid/trunk/src/send.c (file contents):
Revision 3136 by michael, Tue Mar 11 18:24:03 2014 UTC vs.
Revision 8036 by michael, Fri Mar 17 17:49:22 2017 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2017 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 15 | 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  
# Line 32 | Line 32
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
35 #include "numeric.h"
36 #include "fdlist.h"
35   #include "s_bsd.h"
36 < #include "s_serv.h"
37 < #include "conf.h"
36 > #include "server.h"
37 > #include "conf_class.h"
38   #include "log.h"
41 #include "memory.h"
42 #include "packet.h"
39  
40  
41 < static unsigned int current_serial = 0;
41 > static uintmax_t current_serial;
42  
43  
44   /* send_format()
# Line 71 | Line 67 | send_format(struct dbuf_block *buffer, c
67     */
68    dbuf_put_args(buffer, pattern, args);
69  
70 <  if (buffer->size > sizeof(buffer->data) - 2)
71 <    buffer->size = sizeof(buffer->data) - 2;
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';
# Line 88 | Line 84 | send_message(struct Client *to, struct d
84   {
85    assert(!IsMe(to));
86    assert(to != &me);
87 +  assert(MyConnect(to));
88  
89 <  if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs))
89 >  if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs))
90    {
91      if (IsServer(to))
92 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
93 <                           "Max SendQ limit exceeded for %s: %lu > %u",
94 <                           get_client_name(to, HIDE_IP),
95 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size),
96 <                           get_sendq(&to->localClient->confs));
92 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
93 >                           "Max SendQ limit exceeded for %s: %zu > %u",
94 >                           client_get_name(to, HIDE_IP),
95 >                           (dbuf_length(&to->connection->buf_sendq) + buf->size),
96 >                           get_sendq(&to->connection->confs));
97 >
98      if (IsClient(to))
99 <      SetSendQExceeded(to);
99 >      AddFlag(to, FLAGS_SENDQEX);
100 >
101      dead_link_on_write(to, 0);
102      return;
103    }
104  
105 <  dbuf_add(&to->localClient->buf_sendq, 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    send_queued_write(to);
116   }
# Line 127 | Line 126 | send_message(struct Client *to, struct d
126   *
127   */
128   static void
129 < send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
129 > send_message_remote(struct Client *to, const struct Client *from, struct dbuf_block *buf)
130   {
131 <  to = to->from;
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135  
136 <  if (!MyConnect(to))
136 >  if (to == from->from)
137    {
138 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
139 <                         "Server send message to %s [%s] dropped from %s(Not local server)",
140 <                         to->name, to->from->name, from->name);
139 <    return;
140 <  }
141 <
142 <  /* Optimize by checking if (from && to) before everything */
143 <  /* we set to->from up there.. */
144 <
145 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
146 <  {
147 <    if (IsServer(from))
148 <    {
149 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
150 <                           "Send message to %s [%s] dropped from %s(Fake Dir)",
151 <                           to->name, to->from->name, from->name);
152 <      return;
153 <    }
154 <
155 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
156 <                         "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
157 <                         to->name, to->username, to->host,
158 <                         from->name, from->username, from->host,
159 <                         to->from->name);
160 <
161 <    sendto_server(NULL, NOCAPS, NOCAPS,
162 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
163 <                  me.id, to->name, me.name, to->name,
164 <                  to->username, to->host, to->from->name);
165 <
166 <    AddFlag(to, FLAGS_KILLED);
167 <
168 <    if (IsClient(from))
169 <      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
170 <                         to->username, to->host, to->from);
171 <
172 <    exit_client(to, &me, "Ghosted client");
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  
# Line 181 | 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 <  assert(fd == &client_p->localClient->fd);
154 >  struct Client *const client_p = data;
155 >  assert(fd == &client_p->connection->fd);
156 >
157 >  DelFlag(client_p, FLAGS_BLOCKED);
158    send_queued_write(client_p);
159   }
160  
# Line 197 | Line 168 | void
168   send_queued_write(struct Client *to)
169   {
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))
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 <  if (dbuf_length(&to->localClient->buf_sendq))
181 >  if (dbuf_length(&to->connection->buf_sendq))
182    {
183      do
184      {
185 <      struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data;
185 >      const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
186  
187 < #ifdef HAVE_LIBCRYPTO
216 <      if (to->localClient->fd.ssl)
187 >      if (tls_isusing(&to->connection->fd.ssl))
188        {
189 <        retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos);
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)
222 <        {
223 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
224 <          {
225 <            case SSL_ERROR_WANT_READ:
226 <              return;  /* retry later, don't register for write events */
227 <            case SSL_ERROR_WANT_WRITE:
228 <              errno = EWOULDBLOCK;
229 <            case SSL_ERROR_SYSCALL:
230 <              break;
231 <            case SSL_ERROR_SSL:
232 <              if (errno == EAGAIN)
233 <                break;
234 <            default:
235 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
236 <          }
237 <        }
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 + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 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)
200          break;
201  
202 <      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 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
257 <                     (PF *)sendq_unblocked, to, 0);
214 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
215      }
216      else if (retlen <= 0)
217      {
# Line 273 | Line 230 | send_queued_write(struct Client *to)
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(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(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(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 306 | Line 263 | void
263   sendto_one(struct Client *to, const char *pattern, ...)
264   {
265    va_list args;
309  struct dbuf_block *buffer;
310
311  to = to->from;
266  
267 <  if (IsDead(to))
267 >  if (IsDead(to->from))
268      return;  /* This socket has already been marked as dead */
269  
316  buffer = dbuf_alloc();
317
270    va_start(args, pattern);
271 +
272 +  struct dbuf_block *buffer = dbuf_alloc();
273    send_format(buffer, pattern, args);
274 +
275    va_end(args);
276  
277 <  send_message(to, buffer);
277 >  send_message(to->from, buffer);
278  
279    dbuf_ref_free(buffer);
280   }
281  
282   void
283 < sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
283 > sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
284   {
330  struct dbuf_block *buffer;
285    va_list args;
286 <  const char *dest;
333 <
334 <  to = to->from;
286 >  const char *numstr = NULL;
287  
288 <  if (IsDead(to))
288 >  if (IsDead(to->from))
289      return;
290  
291 <  dest = ID_or_name(to, to);
291 >  const char *dest = ID_or_name(to, to);
292    if (EmptyString(dest))
293      dest = "*";
294  
295 <  buffer = dbuf_alloc();
296 <
345 <  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
295 >  struct dbuf_block *buffer = dbuf_alloc();
296 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
297  
298    va_start(args, numeric);
299 <  send_format(buffer, numeric_form(numeric), args);
299 >
300 >  if (numeric & SND_EXPLICIT)
301 >    numstr = va_arg(args, const char *);
302 >  else
303 >    numstr = numeric_form(numeric);
304 >
305 >  send_format(buffer, numstr, args);
306    va_end(args);
307  
308 <  send_message(to, buffer);
308 >  send_message(to->from, buffer);
309  
310    dbuf_ref_free(buffer);
311   }
312  
313   void
314 < sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
314 > sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
315   {
359  struct dbuf_block *buffer;
316    va_list args;
361  const char *dest;
362
363  to = to->from;
317  
318 <  if (IsDead(to))
318 >  if (IsDead(to->from))
319      return;
320  
321 <  dest = ID_or_name(to, to);
321 >  const char *dest = ID_or_name(to, to);
322    if (EmptyString(dest))
323      dest = "*";
324  
325 <  buffer = dbuf_alloc();
373 <
325 >  struct dbuf_block *buffer = dbuf_alloc();
326    dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
327  
328    va_start(args, pattern);
329    send_format(buffer, pattern, args);
330    va_end(args);
331  
332 <  send_message(to, buffer);
332 >  send_message(to->from, buffer);
333  
334    dbuf_ref_free(buffer);
335   }
# Line 394 | Line 346 | sendto_one_notice(struct Client *to, str
346   * WARNING - +D clients are ignored
347   */
348   void
349 < sendto_channel_butone(struct Client *one, struct Client *from,
349 > sendto_channel_butone(struct Client *one, const struct Client *from,
350                        struct Channel *chptr, unsigned int type,
351                        const char *pattern, ...)
352   {
353    va_list alocal, aremote;
354    struct dbuf_block *local_buf, *remote_buf;
355 <  dlink_node *ptr = NULL, *ptr_next = NULL;
355 >  dlink_node *node = NULL;
356  
357    local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
358  
359 <  if (IsServer(from))
408 <    dbuf_put_fmt(local_buf, ":%s ", from->name);
409 <  else
359 >  if (IsClient(from))
360      dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
361 +  else
362 +    dbuf_put_fmt(local_buf, ":%s ", from->name);
363  
364 <  dbuf_put_fmt(remote_buf, ":%s ", ID(from));
364 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
365  
366    va_start(alocal, pattern);
367    va_start(aremote, pattern);
# Line 421 | Line 373 | sendto_channel_butone(struct Client *one
373  
374    ++current_serial;
375  
376 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
376 >  DLINK_FOREACH(node, chptr->members.head)
377    {
378 <    struct Membership *ms = ptr->data;
379 <    struct Client *target_p = ms->client_p;
378 >    struct Membership *member = node->data;
379 >    struct Client *target_p = member->client_p;
380  
381      assert(IsClient(target_p));
382  
383 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
383 >    if (IsDefunct(target_p->from))
384 >      continue;
385 >
386 >    if (one && (target_p->from == one->from))
387 >      continue;
388 >
389 >    if (type && (member->flags & type) == 0)
390        continue;
391  
392 <    if (type != 0 && (ms->flags & type) == 0)
392 >    if (HasUMode(target_p, UMODE_DEAF))
393        continue;
394  
395      if (MyConnect(target_p))
396        send_message(target_p, local_buf);
397 <    else if (target_p->from->localClient->serial != current_serial)
397 >    else if (target_p->from->connection->serial != current_serial)
398        send_message_remote(target_p->from, from, remote_buf);
399 <    target_p->from->localClient->serial = current_serial;
399 >
400 >    target_p->from->connection->serial = current_serial;
401    }
402  
403    dbuf_ref_free(local_buf);
# Line 464 | Line 423 | sendto_channel_butone(struct Client *one
423   * -davidt
424   */
425   void
426 < sendto_server(struct Client *one,
426 > sendto_server(const struct Client *one,
427                const unsigned int caps,
428                const unsigned int nocaps,
429                const char *format, ...)
430   {
431    va_list args;
432 <  dlink_node *ptr = NULL;
474 <  struct dbuf_block *buffer;
475 <
476 <  buffer = dbuf_alloc();
432 >  dlink_node *node;
433  
434    va_start(args, format);
435 +
436 +  struct dbuf_block *buffer = dbuf_alloc();
437    send_format(buffer, format, args);
438 +
439    va_end(args);
440  
441 <  DLINK_FOREACH(ptr, serv_list.head)
441 >  DLINK_FOREACH(node, local_server_list.head)
442    {
443 <    struct Client *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      send_message(client_p, buffer);
# Line 512 | Line 474 | sendto_server(struct Client *one,
474   *                used by m_nick.c and exit_one_client.
475   */
476   void
477 < sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
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 <  struct dbuf_block *buffer;
525 <
526 <  buffer = dbuf_alloc();
486 >  struct dbuf_block *buffer = dbuf_alloc();
487  
488    va_start(args, pattern);
489    send_format(buffer, pattern, args);
# Line 534 | Line 494 | sendto_common_channels_local(struct Clie
494    DLINK_FOREACH(cptr, user->channel.head)
495    {
496      chptr = ((struct Membership *)cptr->data)->chptr;
537    assert(chptr != NULL);
497  
498 <    DLINK_FOREACH(uptr, chptr->members.head)
498 >    DLINK_FOREACH(uptr, chptr->locmembers.head)
499      {
500 <      ms = uptr->data;
501 <      target_p = ms->client_p;
543 <      assert(target_p != NULL);
500 >      member = uptr->data;
501 >      target_p = member->client_p;
502  
503 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
504 <          target_p->localClient->serial == current_serial)
503 >      if (target_p == user || IsDefunct(target_p) ||
504 >          target_p->connection->serial == current_serial)
505          continue;
506  
507 <      if (HasCap(target_p, cap) != cap)
507 >      if (poscap && HasCap(target_p, poscap) != poscap)
508          continue;
509  
510 <      target_p->localClient->serial = current_serial;
510 >      if (negcap && HasCap(target_p, negcap))
511 >        continue;
512 >
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->localClient->serial != current_serial)
520 <    if (HasCap(user, cap) == cap)
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
572 < * side effects - Send a message to all members of a channel that are
573 < *                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(unsigned 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 <  dlink_node *ptr = NULL;
540 <  struct dbuf_block *buffer;
582 <
583 <  buffer = dbuf_alloc();
539 >  dlink_node *node = NULL;
540 >  struct dbuf_block *buffer = dbuf_alloc();
541  
542    va_start(args, pattern);
543    send_format(buffer, pattern, args);
544    va_end(args);
545  
546 <  DLINK_FOREACH(ptr, chptr->members.head)
546 >  DLINK_FOREACH(node, chptr->locmembers.head)
547    {
548 <    struct Membership *ms = ptr->data;
549 <    struct Client *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 (!MyConnect(target_p) || IsDefunct(target_p) ||
598 <        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
554 >    if (one && target_p == one->from)
555        continue;
556  
557 <    send_message(target_p, buffer);
602 <  }
603 <
604 <  dbuf_ref_free(buffer);
605 < }
606 <
607 < /* sendto_channel_local_butone()
608 < *
609 < * inputs       - pointer to client to NOT send message to
610 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
611 < *              - pointer to channel to send to
612 < *              - var args pattern
613 < * output       - NONE
614 < * side effects - Send a message to all members of a channel that are
615 < *                locally connected to this server except one.
616 < *
617 < * WARNING - +D clients are omitted
618 < */
619 < void
620 < sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
621 <                            struct Channel *chptr, const char *pattern, ...)
622 < {
623 <  va_list args;
624 <  dlink_node *ptr = NULL;
625 <  struct dbuf_block *buffer;
626 <
627 <  buffer = dbuf_alloc();
628 <
629 <  va_start(args, pattern);
630 <  send_format(buffer, pattern, args);
631 <  va_end(args);
632 <
633 <  DLINK_FOREACH(ptr, chptr->members.head)
634 <  {
635 <    struct Membership *ms = ptr->data;
636 <    struct Client *target_p = ms->client_p;
637 <
638 <    if (type != 0 && (ms->flags & type) == 0)
557 >    if (status && (member->flags & status) == 0)
558        continue;
559  
560 <    if (!MyConnect(target_p) || target_p == one ||
642 <        IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
560 >    if (poscap && HasCap(target_p, poscap) != poscap)
561        continue;
562  
563 <    if (HasCap(target_p, cap) != cap)
563 >    if (negcap && HasCap(target_p, negcap))
564        continue;
565  
566      send_message(target_p, buffer);
# Line 685 | 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 alocal, aremote;
610 <  dlink_node *ptr = NULL, *ptr_next = NULL;
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 ", ID(from));
616 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
617  
618    va_start(alocal, pattern);
619    va_start(aremote, pattern);
# Line 705 | Line 623 | sendto_match_butone(struct Client *one,
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 <    struct Client *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);
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 <    struct Client *client_p = ptr->data;
638 >    struct Client *client_p = node->data;
639  
640      /*
641       * The old code looped through every client on the
# Line 743 | Line 661 | sendto_match_butone(struct Client *one,
661       * server deal with it.
662       * -wnder
663       */
664 <    if (client_p != one && !IsDefunct(client_p))
664 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
665        send_message_remote(client_p, from, remote_buf);
666    }
667  
# Line 761 | 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, unsigned 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 <  dlink_node *ptr = NULL;
687 <  struct dbuf_block *buff_suid;
770 <
771 <  buff_suid = dbuf_alloc();
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 <  dbuf_put_fmt(buff_suid, ":%s ", ID(source_p));
775 <  dbuf_put_args(buff_suid, pattern, args);
691 >  send_format(buffer, pattern, args);
692    va_end(args);
693  
694    ++current_serial;
695  
696 <  DLINK_FOREACH(ptr, global_serv_list.head)
696 >  DLINK_FOREACH(node, global_server_list.head)
697    {
698 <    struct Client *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->localClient->serial == current_serial)
704 >    if (target_p->from->connection->serial == current_serial)
705        continue;
706  
707 <    if (!match(mask, target_p->name))
708 <    {
793 <      /*
794 <       * if we set the serial here, then we'll never do a
795 <       * match() again, if !IsCapable()
796 <       */
797 <      target_p->from->localClient->serial = current_serial;
707 >    if (match(mask, target_p->name))
708 >      continue;
709  
710 <      if (!IsCapable(target_p->from, cap))
711 <        continue;
710 >    if (cap && IsCapable(target_p->from, cap) != cap)
711 >      continue;
712  
713 <      send_message_remote(target_p->from, source_p, buff_suid);
714 <    }
713 >    target_p->from->connection->serial = current_serial;
714 >    send_message_remote(target_p->from, source_p, buffer);
715    }
716  
717 <  dbuf_ref_free(buff_suid);
717 >  dbuf_ref_free(buffer);
718   }
719  
720   /* sendto_anywhere()
# Line 816 | Line 727 | sendto_match_servs(struct Client *source
727   *                but useful when one does not know where target "lives"
728   */
729   void
730 < sendto_anywhere(struct Client *to, struct Client *from,
730 > sendto_anywhere(struct Client *to, const struct Client *from,
731                  const char *command,
732                  const char *pattern, ...)
733   {
734    va_list args;
824  struct dbuf_block *buffer;
735  
736    if (IsDead(to->from))
737      return;
738  
739 <  buffer = dbuf_alloc();
740 <
741 <  if (MyClient(to))
742 <  {
833 <    if (IsServer(from))
834 <      dbuf_put_fmt(buffer, ":%s %s %s ", from->name, command, to->name);
835 <    else
836 <      dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name);
837 <  }
739 >  struct dbuf_block *buffer = dbuf_alloc();
740 >  if (MyClient(to) && IsClient(from))
741 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
742 >                 from->host, command, to->name);
743    else
744 <    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to));
744 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
745 >                 command, ID_or_name(to, to));
746  
747    va_start(args, pattern);
748    send_format(buffer, pattern, args);
749    va_end(args);
750  
751 <  if (MyClient(to))
751 >  if (MyConnect(to))
752      send_message(to, buffer);
753    else
754 <    send_message_remote(to, from, buffer);
754 >    send_message_remote(to->from, from, buffer);
755  
756    dbuf_ref_free(buffer);
757   }
# Line 861 | Line 767 | sendto_anywhere(struct Client *to, struc
767   void
768   sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
769   {
770 <  const char *ntype = NULL;
771 <  dlink_node *ptr = NULL;
866 <  char nbuf[IRCD_BUFSIZE];
770 >  const char *ntype = "???";
771 >  dlink_node *node;
772    va_list args;
773  
869  va_start(args, pattern);
870  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
871  va_end(args);
872
774    switch (type)
775    {
776      case SEND_NOTICE:
# Line 885 | Line 786 | sendto_realops_flags(unsigned int flags,
786        assert(0);
787    }
788  
789 <  DLINK_FOREACH(ptr, oper_list.head)
789 >  struct dbuf_block *buffer = dbuf_alloc();
790 >  dbuf_put_fmt(buffer, ":%s NOTICE * :*** %s -- ", me.name, ntype);
791 >
792 >  va_start(args, pattern);
793 >  send_format(buffer, pattern, args);
794 >  va_end(args);
795 >
796 >  DLINK_FOREACH(node, oper_list.head)
797    {
798 <    struct Client *client_p = ptr->data;
798 >    struct Client *client_p = node->data;
799      assert(HasUMode(client_p, UMODE_OPER));
800  
801      /*
# Line 898 | Line 806 | sendto_realops_flags(unsigned int flags,
806          ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
807        continue;
808  
809 <    if (HasUMode(client_p, flags))
902 <      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
903 <                 me.name, client_p->name, ntype, nbuf);
904 <  }
905 < }
906 <
907 < /* sendto_wallops_flags()
908 < *
909 < * inputs       - flag types of messages to show to real opers
910 < *              - client sending request
911 < *              - var args input message
912 < * output       - NONE
913 < * side effects - Send a wallops to local opers
914 < */
915 < void
916 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
917 <                     const char *pattern, ...)
918 < {
919 <  dlink_node *ptr = NULL;
920 <  va_list args;
921 <  struct dbuf_block *buffer;
922 <
923 <  buffer = dbuf_alloc();
924 <
925 <  if (IsClient(source_p))
926 <    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
927 <  else
928 <    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
929 <
930 <  va_start(args, pattern);
931 <  send_format(buffer, pattern, args);
932 <  va_end(args);
933 <
934 <  DLINK_FOREACH(ptr, oper_list.head)
935 <  {
936 <    struct Client *client_p = ptr->data;
937 <    assert(client_p->umodes & UMODE_OPER);
938 <
939 <    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
809 >    if (HasUMode(client_p, flags) && !IsDead(client_p))
810        send_message(client_p, buffer);
811    }
812  
# Line 945 | Line 815 | sendto_wallops_flags(unsigned int flags,
815  
816   /* ts_warn()
817   *
818 < * inputs       - var args message
819 < * output       - NONE
820 < * side effects - Call sendto_realops_flags, with some flood checking
821 < *                (at most 5 warnings every 5 seconds)
818 > * inputs       - var args message
819 > * output       - NONE
820 > * side effects - Call sendto_realops_flags, with some flood checking
821 > *                (at most 5 warnings every 5 seconds)
822   */
823   void
824 < sendto_realops_flags_ratelimited(const char *pattern, ...)
824 > sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
825   {
826    va_list args;
827 <  char buffer[IRCD_BUFSIZE];
958 <  static time_t last = 0;
959 <  static int warnings = 0;
827 >  char buffer[IRCD_BUFSIZE] = "";
828  
829 <  /*
830 <   ** if we're running with TS_WARNINGS enabled and someone does
963 <   ** something silly like (remotely) connecting a nonTS server,
964 <   ** we'll get a ton of warnings, so we make sure we don't send
965 <   ** more than 5 every 5 seconds.  -orabidoo
966 <   */
829 >  if ((CurrentTime - *rate) < 20)
830 >    return;
831  
832 <  if (CurrentTime - last < 5)
969 <  {
970 <    if (++warnings > 5)
971 <      return;
972 <  }
973 <  else
974 <  {
975 <    last = CurrentTime;
976 <    warnings = 0;
977 <  }
832 >  *rate = CurrentTime;
833  
834    va_start(args, pattern);
835    vsnprintf(buffer, sizeof(buffer), pattern, args);
836    va_end(args);
837  
838 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
838 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
839    ilog(LOG_TYPE_IRCD, "%s", buffer);
840   }
841  
842 < /* kill_client()
842 > /* sendto_wallops_flags()
843   *
844 < * inputs       - client to send kill towards
845 < *              - pointer to client to kill
846 < *              - reason for kill
847 < * output       - NONE
848 < * side effects - NONE
844 > * inputs       - flag types of messages to show to real opers
845 > *              - client sending request
846 > *              - var args input message
847 > * output       - NONE
848 > * side effects - Send a wallops to local opers
849   */
850   void
851 < kill_client(struct Client *client_p, struct Client *diedie,
852 <            const char *pattern, ...)
851 > sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
852 >                     const char *pattern, ...)
853   {
854 +  dlink_node *node = NULL;
855    va_list args;
856 <  struct dbuf_block *buffer;
1001 <
1002 <  client_p = client_p->from;
1003 <
1004 <  if (IsDead(client_p))
1005 <    return;
1006 <
1007 <  buffer = dbuf_alloc();
856 >  struct dbuf_block *buffer = dbuf_alloc();
857  
858 <  dbuf_put_fmt(buffer, ":%s KILL %s :",
859 <               ID_or_name(&me, client_p),
860 <               ID_or_name(diedie, client_p));
858 >  if (IsClient(source_p))
859 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
860 >  else
861 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
862  
863    va_start(args, pattern);
864    send_format(buffer, pattern, args);
865    va_end(args);
866  
867 <  send_message(client_p, buffer);
1018 <
1019 <  dbuf_ref_free(buffer);
1020 < }
1021 <
1022 < /* kill_client_serv_butone()
1023 < *
1024 < * inputs       - pointer to client to not send to
1025 < *              - pointer to client to kill
1026 < * output       - NONE
1027 < * side effects - Send a KILL for the given client
1028 < *                message to all connected servers
1029 < *                except the client 'one'. Also deal with
1030 < *                client being unknown to leaf, as in lazylink...
1031 < */
1032 < void
1033 < kill_client_serv_butone(struct Client *one, struct Client *source_p,
1034 <                        const char *pattern, ...)
1035 < {
1036 <  va_list args;
1037 <  dlink_node *ptr = NULL;
1038 <  struct dbuf_block *uid_buffer = dbuf_alloc();
1039 <
1040 <  va_start(args, pattern);
1041 <  dbuf_put_fmt(uid_buffer, ":%s KILL %s :", ID(&me), ID(source_p));
1042 <  send_format(uid_buffer, pattern, args);
1043 <  va_end(args);
1044 <
1045 <  DLINK_FOREACH(ptr, serv_list.head)
867 >  DLINK_FOREACH(node, oper_list.head)
868    {
869 <    struct Client *client_p = ptr->data;
870 <
1049 <    if (one != NULL && (client_p == one->from))
1050 <      continue;
1051 <    if (IsDefunct(client_p))
1052 <      continue;
869 >    struct Client *client_p = node->data;
870 >    assert(client_p->umodes & UMODE_OPER);
871  
872 <    send_message(client_p, uid_buffer);
872 >    if (HasUMode(client_p, flags) && !IsDead(client_p))
873 >      send_message(client_p, buffer);
874    }
875  
876 <  dbuf_ref_free(uid_buffer);
876 >  dbuf_ref_free(buffer);
877   }

Comparing ircd-hybrid/trunk/src/send.c (property svn:keywords):
Revision 3136 by michael, Tue Mar 11 18:24:03 2014 UTC vs.
Revision 8036 by michael, Fri Mar 17 17:49:22 2017 UTC

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

Diff Legend

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