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 3176 by michael, Tue Mar 18 20:00:16 2014 UTC vs.
Revision 9002 by michael, Sat May 25 23:13:57 2019 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-2019 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_capab.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;
132 <
133 <  if (!MyConnect(to))
134 <  {
136 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
137 <                         "Server send message to %s [%s] dropped from %s(Not local server)",
138 <                         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->id, 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, "Ghosted client");
173 <    return;
174 <  }
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135  
136 <  send_message(to, buf);
136 >  if (to == from->from)
137 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Send message to %s dropped from %s (Fake Dir)",
138 >                         to->name, from->name);
139 >  else
140 >    send_message(to, buf);
141   }
142  
143   /*
# Line 181 | Line 145 | send_message_remote(struct Client *to, s
145   **      Called when a socket is ready for writing.
146   */
147   void
148 < sendq_unblocked(fde_t *fd, struct Client *client_p)
148 > sendq_unblocked(fde_t *F, void *data)
149   {
150 <  assert(fd == &client_p->localClient->fd);
150 >  struct Client *const client_p = data;
151 >
152 >  assert(client_p);
153 >  assert(client_p->connection);
154 >  assert(client_p->connection->fd);
155 >  assert(client_p->connection->fd == F);
156 >
157 >  DelFlag(client_p, FLAGS_BLOCKED);
158    send_queued_write(client_p);
159   }
160  
# Line 196 | Line 167 | sendq_unblocked(fde_t *fd, struct Client
167   void
168   send_queued_write(struct Client *to)
169   {
170 <  int retlen = 0;
170 >  ssize_t retlen = 0;
171  
172    /*
173     ** Once socket is marked dead, we cannot start writing to it,
174     ** even if the error is removed...
175     */
176 <  if (IsDead(to))
176 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
177      return;  /* no use calling send() now */
178  
179    /* Next, lets try to write some data */
180 <  if (dbuf_length(&to->localClient->buf_sendq))
180 >  while (dbuf_length(&to->connection->buf_sendq))
181    {
182 <    do
182 >    bool want_read = false;
183 >    const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
184 >
185 >    if (tls_isusing(&to->connection->fd->ssl))
186      {
187 <      struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data;
187 >      retlen = tls_write(&to->connection->fd->ssl, first->data + to->connection->buf_sendq.pos,
188 >                                                   first->size - to->connection->buf_sendq.pos, &want_read);
189  
190 < #ifdef HAVE_LIBCRYPTO
191 <      if (to->localClient->fd.ssl)
192 <      {
193 <        retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos);
190 >      if (want_read == true)
191 >        return;  /* Retry later, don't register for write events */
192 >    }
193 >    else
194 >      retlen = send(to->connection->fd->fd, first->data + to->connection->buf_sendq.pos,
195 >                                            first->size - to->connection->buf_sendq.pos, 0);
196  
197 <        /* translate openssl error codes, sigh */
198 <        if (retlen < 0)
199 <        {
200 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
201 <          {
202 <            case SSL_ERROR_WANT_READ:
203 <              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 <        }
197 >    if (retlen <= 0)
198 >    {
199 >      if (retlen < 0 && comm_ignore_errno(errno) == true)
200 >      {
201 >        AddFlag(to, FLAGS_BLOCKED);
202 >        /* We have a non-fatal error, reschedule a write */
203 >        comm_setselect(to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
204        }
205        else
206 < #endif
241 <        retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0);
242 <
243 <      if (retlen <= 0)
244 <        break;
245 <
246 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
247 <
248 <      /* We have some data written .. update counters */
249 <      to->localClient->send.bytes += retlen;
250 <      me.localClient->send.bytes += retlen;
251 <    } while (dbuf_length(&to->localClient->buf_sendq));
252 <
253 <    if ((retlen < 0) && (ignoreErrno(errno)))
254 <    {
255 <      /* we have a non-fatal error, reschedule a write */
256 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
257 <                     (PF *)sendq_unblocked, to, 0);
258 <    }
259 <    else if (retlen <= 0)
260 <    {
261 <      dead_link_on_write(to, errno);
206 >        dead_link_on_write(to, errno);
207        return;
208      }
264 –  }
265 – }
266 –
267 – /* send_queued_all()
268 – *
269 – * input        - NONE
270 – * output       - NONE
271 – * side effects - try to flush sendq of each client
272 – */
273 – void
274 – send_queued_all(void)
275 – {
276 –  dlink_node *ptr;
277 –
278 –  /* Servers are processed first, mainly because this can generate
279 –   * a notice to opers, which is to be delivered by this function.
280 –   */
281 –  DLINK_FOREACH(ptr, serv_list.head)
282 –    send_queued_write(ptr->data);
283 –
284 –  DLINK_FOREACH(ptr, unknown_list.head)
285 –    send_queued_write(ptr->data);
209  
210 <  DLINK_FOREACH(ptr, local_client_list.head)
288 <    send_queued_write(ptr->data);
210 >    dbuf_delete(&to->connection->buf_sendq, retlen);
211  
212 <  /* NOTE: This can still put clients on aborted_list; unfortunately,
213 <   * exit_aborted_clients takes precedence over send_queued_all,
214 <   * because exiting clients can generate server/oper traffic.
215 <   * The easiest approach is dealing with aborted clients in the next I/O lap.
294 <   * -adx
295 <   */
212 >    /* We have some data written .. update counters */
213 >    to->connection->send.bytes += retlen;
214 >    me.connection->send.bytes += retlen;
215 >  }
216   }
217  
218   /* sendto_one()
# Line 306 | Line 226 | void
226   sendto_one(struct Client *to, const char *pattern, ...)
227   {
228    va_list args;
309 –  struct dbuf_block *buffer;
310 –
311 –  to = to->from;
229  
230 <  if (IsDead(to))
230 >  if (IsDead(to->from))
231      return;  /* This socket has already been marked as dead */
232  
316 –  buffer = dbuf_alloc();
317 –
233    va_start(args, pattern);
234 +
235 +  struct dbuf_block *buffer = dbuf_alloc();
236    send_format(buffer, pattern, args);
237 +
238    va_end(args);
239  
240 <  send_message(to, buffer);
240 >  send_message(to->from, buffer);
241  
242    dbuf_ref_free(buffer);
243   }
244  
245   void
246 < sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
246 > sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
247   {
330 –  struct dbuf_block *buffer;
248    va_list args;
249 <  const char *dest;
333 <
334 <  to = to->from;
249 >  const char *numstr = NULL;
250  
251 <  if (IsDead(to))
252 <    return;
251 >  if (IsDead(to->from))
252 >    return;  /* This socket has already been marked as dead */
253  
254 <  dest = ID_or_name(to, to);
254 >  const char *dest = ID_or_name(to, to);
255    if (EmptyString(dest))
256      dest = "*";
257  
258 <  buffer = dbuf_alloc();
259 <
345 <  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
258 >  struct dbuf_block *buffer = dbuf_alloc();
259 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
260  
261    va_start(args, numeric);
262 <  send_format(buffer, numeric_form(numeric), args);
262 >
263 >  if (numeric & SND_EXPLICIT)
264 >    numstr = va_arg(args, const char *);
265 >  else
266 >    numstr = numeric_form(numeric);
267 >
268 >  send_format(buffer, numstr, args);
269    va_end(args);
270  
271 <  send_message(to, buffer);
271 >  send_message(to->from, buffer);
272  
273    dbuf_ref_free(buffer);
274   }
275  
276   void
277 < sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
277 > sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
278   {
359 –  struct dbuf_block *buffer;
279    va_list args;
361 –  const char *dest;
362 –
363 –  to = to->from;
280  
281 <  if (IsDead(to))
282 <    return;
281 >  if (IsDead(to->from))
282 >    return;  /* This socket has already been marked as dead */
283  
284 <  dest = ID_or_name(to, to);
284 >  const char *dest = ID_or_name(to, to);
285    if (EmptyString(dest))
286      dest = "*";
287  
288 <  buffer = dbuf_alloc();
373 <
288 >  struct dbuf_block *buffer = dbuf_alloc();
289    dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
290  
291    va_start(args, pattern);
292    send_format(buffer, pattern, args);
293    va_end(args);
294  
295 <  send_message(to, buffer);
295 >  send_message(to->from, buffer);
296  
297    dbuf_ref_free(buffer);
298   }
# Line 394 | Line 309 | sendto_one_notice(struct Client *to, str
309   * WARNING - +D clients are ignored
310   */
311   void
312 < sendto_channel_butone(struct Client *one, struct Client *from,
312 > sendto_channel_butone(struct Client *one, const struct Client *from,
313                        struct Channel *chptr, unsigned int type,
314                        const char *pattern, ...)
315   {
316    va_list alocal, aremote;
317    struct dbuf_block *local_buf, *remote_buf;
318 <  dlink_node *ptr = NULL, *ptr_next = NULL;
318 >  dlink_node *node;
319  
320    local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
321  
322 <  if (IsServer(from))
408 <    dbuf_put_fmt(local_buf, ":%s ", from->name);
409 <  else
322 >  if (IsClient(from))
323      dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
324 +  else
325 +    dbuf_put_fmt(local_buf, ":%s ", from->name);
326  
327 <  dbuf_put_fmt(remote_buf, ":%s ", ID(from));
327 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
328  
329    va_start(alocal, pattern);
330    va_start(aremote, pattern);
# Line 421 | Line 336 | sendto_channel_butone(struct Client *one
336  
337    ++current_serial;
338  
339 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
339 >  DLINK_FOREACH(node, chptr->members.head)
340    {
341 <    struct Membership *ms = ptr->data;
342 <    struct Client *target_p = ms->client_p;
341 >    struct Membership *member = node->data;
342 >    struct Client *target_p = member->client_p;
343  
344      assert(IsClient(target_p));
345  
346 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
347 <        (one && target_p->from == one->from))
346 >    if (IsDead(target_p->from))
347 >      continue;
348 >
349 >    if (one && (target_p->from == one->from))
350        continue;
351  
352 <    if (type != 0 && (ms->flags & type) == 0)
352 >    if (type && (member->flags & type) == 0)
353 >      continue;
354 >
355 >    if (HasUMode(target_p, UMODE_DEAF))
356        continue;
357  
358      if (MyConnect(target_p))
359        send_message(target_p, local_buf);
360 <    else if (target_p->from->localClient->serial != current_serial)
360 >    else if (target_p->from->connection->serial != current_serial)
361        send_message_remote(target_p->from, from, remote_buf);
362 <    target_p->from->localClient->serial = current_serial;
362 >
363 >    target_p->from->connection->serial = current_serial;
364    }
365  
366    dbuf_ref_free(local_buf);
# Line 465 | Line 386 | sendto_channel_butone(struct Client *one
386   * -davidt
387   */
388   void
389 < sendto_server(struct Client *one,
389 > sendto_server(const struct Client *one,
390                const unsigned int caps,
391                const unsigned int nocaps,
392                const char *format, ...)
393   {
394    va_list args;
395 <  dlink_node *ptr = NULL;
475 <  struct dbuf_block *buffer;
476 <
477 <  buffer = dbuf_alloc();
395 >  dlink_node *node;
396  
397    va_start(args, format);
398 +
399 +  struct dbuf_block *buffer = dbuf_alloc();
400    send_format(buffer, format, args);
401 +
402    va_end(args);
403  
404 <  DLINK_FOREACH(ptr, serv_list.head)
404 >  DLINK_FOREACH(node, local_server_list.head)
405    {
406 <    struct Client *client_p = ptr->data;
406 >    struct Client *client_p = node->data;
407  
408      /* If dead already skip */
409      if (IsDead(client_p))
410        continue;
411 +
412      /* check against 'one' */
413 <    if (one != NULL && (client_p == one->from))
413 >    if (one && (client_p == one->from))
414        continue;
415 +
416      /* check we have required capabs */
417 <    if ((client_p->localClient->caps & caps) != caps)
417 >    if ((client_p->connection->caps & caps) != caps)
418        continue;
419 +
420      /* check we don't have any forbidden capabs */
421 <    if ((client_p->localClient->caps & nocaps) != 0)
421 >    if ((client_p->connection->caps & nocaps))
422        continue;
423  
424      send_message(client_p, buffer);
# Line 513 | Line 437 | sendto_server(struct Client *one,
437   *                used by m_nick.c and exit_one_client.
438   */
439   void
440 < sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
441 <                             const char *pattern, ...)
440 > sendto_common_channels_local(struct Client *user, bool touser, unsigned int poscap,
441 >                             unsigned int negcap, const char *pattern, ...)
442   {
443    va_list args;
444    dlink_node *uptr;
445    dlink_node *cptr;
446    struct Channel *chptr;
447 <  struct Membership *ms;
447 >  struct Membership *member;
448    struct Client *target_p;
449 <  struct dbuf_block *buffer;
526 <
527 <  buffer = dbuf_alloc();
449 >  struct dbuf_block *buffer = dbuf_alloc();
450  
451    va_start(args, pattern);
452    send_format(buffer, pattern, args);
# Line 535 | Line 457 | sendto_common_channels_local(struct Clie
457    DLINK_FOREACH(cptr, user->channel.head)
458    {
459      chptr = ((struct Membership *)cptr->data)->chptr;
538 –    assert(chptr != NULL);
460  
461 <    DLINK_FOREACH(uptr, chptr->members.head)
461 >    DLINK_FOREACH(uptr, chptr->members_local.head)
462      {
463 <      ms = uptr->data;
464 <      target_p = ms->client_p;
544 <      assert(target_p != NULL);
463 >      member = uptr->data;
464 >      target_p = member->client_p;
465  
466 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
547 <          target_p->localClient->serial == current_serial)
466 >      if (IsDead(target_p))
467          continue;
468  
469 <      if (HasCap(target_p, cap) != cap)
469 >      if (target_p == user)
470          continue;
471  
472 <      target_p->localClient->serial = current_serial;
472 >      if (target_p->connection->serial == current_serial)
473 >        continue;
474 >
475 >      if (poscap && HasCap(target_p, poscap) != poscap)
476 >        continue;
477 >
478 >      if (negcap && HasCap(target_p, negcap))
479 >        continue;
480 >
481 >      target_p->connection->serial = current_serial;
482        send_message(target_p, buffer);
483      }
484    }
485  
486 <  if (touser && MyConnect(user) && !IsDead(user) &&
487 <      user->localClient->serial != current_serial)
560 <    if (HasCap(user, cap) == cap)
486 >  if (touser == true && MyConnect(user) && !IsDead(user))
487 >    if (HasCap(user, poscap) == poscap)
488        send_message(user, buffer);
489  
490    dbuf_ref_free(buffer);
491   }
492  
493 < /* sendto_channel_local()
494 < *
495 < * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
496 < *              - whether to ignore +D clients (YES/NO)
497 < *              - pointer to channel to send to
498 < *              - var args pattern
499 < * output       - NONE
573 < * side effects - Send a message to all members of a channel that are
574 < *                locally connected to this server.
493 > /*! \brief Send a message to members of a channel that are locally connected to this server.
494 > * \param one      Client to skip; can be NULL
495 > * \param chptr    Destination channel
496 > * \param status   Channel member status flags clients must have
497 > * \param poscap   Positive client capabilities flags (CAP)
498 > * \param negcap   Negative client capabilities flags (CAP)
499 > * \param pattern  Format string for command arguments
500   */
501   void
502 < sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
503 <                     const char *pattern, ...)
502 > sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status,
503 >                     unsigned int poscap, unsigned int negcap, const char *pattern, ...)
504   {
505    va_list args;
506 <  dlink_node *ptr = NULL;
507 <  struct dbuf_block *buffer;
583 <
584 <  buffer = dbuf_alloc();
506 >  dlink_node *node;
507 >  struct dbuf_block *buffer = dbuf_alloc();
508  
509    va_start(args, pattern);
510    send_format(buffer, pattern, args);
511    va_end(args);
512  
513 <  DLINK_FOREACH(ptr, chptr->members.head)
513 >  DLINK_FOREACH(node, chptr->members_local.head)
514    {
515 <    struct Membership *ms = ptr->data;
516 <    struct Client *target_p = ms->client_p;
515 >    struct Membership *member = node->data;
516 >    struct Client *target_p = member->client_p;
517  
518 <    if (type != 0 && (ms->flags & type) == 0)
518 >    if (IsDead(target_p))
519        continue;
520  
521 <    if (!MyConnect(target_p) || IsDefunct(target_p) ||
599 <        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
600 <      continue;
601 <
602 <    send_message(target_p, buffer);
603 <  }
604 <
605 <  dbuf_ref_free(buffer);
606 < }
607 <
608 < /* sendto_channel_local_butone()
609 < *
610 < * inputs       - pointer to client to NOT send message to
611 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
612 < *              - pointer to channel to send to
613 < *              - var args pattern
614 < * output       - NONE
615 < * side effects - Send a message to all members of a channel that are
616 < *                locally connected to this server except one.
617 < *
618 < * WARNING - +D clients are omitted
619 < */
620 < void
621 < sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
622 <                            struct Channel *chptr, const char *pattern, ...)
623 < {
624 <  va_list args;
625 <  dlink_node *ptr = NULL;
626 <  struct dbuf_block *buffer;
627 <
628 <  buffer = dbuf_alloc();
629 <
630 <  va_start(args, pattern);
631 <  send_format(buffer, pattern, args);
632 <  va_end(args);
633 <
634 <  DLINK_FOREACH(ptr, chptr->members.head)
635 <  {
636 <    struct Membership *ms = ptr->data;
637 <    struct Client *target_p = ms->client_p;
638 <
639 <    if (type != 0 && (ms->flags & type) == 0)
521 >    if (one && (target_p == one->from))
522        continue;
523  
524 <    if (!MyConnect(target_p) || (one && target_p == one->from))
524 >    if (status && (member->flags & status) == 0)
525        continue;
526  
527 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
527 >    if (poscap && HasCap(target_p, poscap) != poscap)
528        continue;
529  
530 <    if (HasCap(target_p, cap) != cap)
530 >    if (negcap && HasCap(target_p, negcap))
531        continue;
532  
533      send_message(target_p, buffer);
# Line 671 | Line 553 | sendto_channel_local_butone(struct Clien
553   * output       - 1 or 0 if match or not
554   * side effects - NONE
555   */
556 < static int
556 > static bool
557   match_it(const struct Client *one, const char *mask, unsigned int what)
558   {
559    if (what == MATCH_HOST)
560 <    return !match(mask, one->host);
560 >    return match(mask, one->host) == 0;
561  
562 <  return !match(mask, one->servptr->name);
562 >  return match(mask, one->servptr->name) == 0;
563   }
564  
565   /* sendto_match_butone()
# Line 688 | Line 570 | match_it(const struct Client *one, const
570   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
571   */
572   void
573 < sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
574 <                    int what, const char *pattern, ...)
573 > sendto_match_butone(const struct Client *one, const struct Client *from,
574 >                    const char *mask, int what, const char *pattern, ...)
575   {
576    va_list alocal, aremote;
577 <  dlink_node *ptr = NULL, *ptr_next = NULL;
577 >  dlink_node *node;
578    struct dbuf_block *local_buf, *remote_buf;
579  
580    local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
581  
582    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
583 <  dbuf_put_fmt(remote_buf, ":%s ", ID(from));
583 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
584  
585    va_start(alocal, pattern);
586    va_start(aremote, pattern);
# Line 708 | Line 590 | sendto_match_butone(struct Client *one,
590    va_end(alocal);
591  
592    /* scan the local clients */
593 <  DLINK_FOREACH(ptr, local_client_list.head)
593 >  DLINK_FOREACH(node, local_client_list.head)
594    {
595 <    struct Client *client_p = ptr->data;
595 >    struct Client *client_p = node->data;
596 >
597 >    if (IsDead(client_p))
598 >      continue;
599 >
600 >    if (one && (client_p == one->from))
601 >      continue;
602 >
603 >    if (match_it(client_p, mask, what) == false)
604 >      continue;
605  
606 <    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
716 <        match_it(client_p, mask, what))
717 <      send_message(client_p, local_buf);
606 >    send_message(client_p, local_buf);
607    }
608  
609    /* Now scan servers */
610 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
610 >  DLINK_FOREACH(node, local_server_list.head)
611    {
612 <    struct Client *client_p = ptr->data;
612 >    struct Client *client_p = node->data;
613  
614      /*
615       * The old code looped through every client on the
# Line 746 | Line 635 | sendto_match_butone(struct Client *one,
635       * server deal with it.
636       * -wnder
637       */
638 <    if ((!one || client_p != one->from) && !IsDefunct(client_p))
639 <      send_message_remote(client_p, from, remote_buf);
638 >    if (IsDead(client_p))
639 >      continue;
640 >
641 >    if (one && (client_p == one->from))
642 >      continue;
643 >
644 >    send_message_remote(client_p, from, remote_buf);
645    }
646  
647    dbuf_ref_free(local_buf);
# Line 764 | Line 658 | sendto_match_butone(struct Client *one,
658   * side effects - data sent to servers matching with capab
659   */
660   void
661 < sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
661 > sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
662                     const char *pattern, ...)
663   {
664    va_list args;
665 <  dlink_node *ptr = NULL;
666 <  struct dbuf_block *buff_suid;
773 <
774 <  buff_suid = dbuf_alloc();
665 >  dlink_node *node;
666 >  struct dbuf_block *buffer = dbuf_alloc();
667  
668 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
669    va_start(args, pattern);
670 <  dbuf_put_fmt(buff_suid, ":%s ", ID(source_p));
778 <  dbuf_put_args(buff_suid, pattern, args);
670 >  send_format(buffer, pattern, args);
671    va_end(args);
672  
673    ++current_serial;
674  
675 <  DLINK_FOREACH(ptr, global_serv_list.head)
675 >  DLINK_FOREACH(node, global_server_list.head)
676    {
677 <    struct Client *target_p = ptr->data;
677 >    struct Client *target_p = node->data;
678  
679 <    /* Do not attempt to send to ourselves, or the source */
788 <    if (IsMe(target_p) || target_p->from == source_p->from)
679 >    if (IsDead(target_p->from))
680        continue;
681  
682 <    if (target_p->from->localClient->serial == current_serial)
682 >    /* Do not attempt to send to ourselves ... */
683 >    if (IsMe(target_p))
684        continue;
685  
686 <    if (!match(mask, target_p->name))
687 <    {
688 <      /*
797 <       * if we set the serial here, then we'll never do a
798 <       * match() again, if !IsCapable()
799 <       */
800 <      target_p->from->localClient->serial = current_serial;
686 >    /* ... or the source */
687 >    if (target_p->from == source_p->from)
688 >      continue;
689  
690 <      if (!IsCapable(target_p->from, cap))
691 <        continue;
690 >    if (target_p->from->connection->serial == current_serial)
691 >      continue;
692  
693 <      send_message_remote(target_p->from, source_p, buff_suid);
694 <    }
693 >    if (match(mask, target_p->name))
694 >      continue;
695 >
696 >    if (cap && IsCapable(target_p->from, cap) != cap)
697 >      continue;
698 >
699 >    target_p->from->connection->serial = current_serial;
700 >    send_message_remote(target_p->from, source_p, buffer);
701    }
702  
703 <  dbuf_ref_free(buff_suid);
703 >  dbuf_ref_free(buffer);
704   }
705  
706   /* sendto_anywhere()
# Line 819 | Line 713 | sendto_match_servs(struct Client *source
713   *                but useful when one does not know where target "lives"
714   */
715   void
716 < sendto_anywhere(struct Client *to, struct Client *from,
716 > sendto_anywhere(struct Client *to, const struct Client *from,
717                  const char *command,
718                  const char *pattern, ...)
719   {
720    va_list args;
827 –  struct dbuf_block *buffer;
721  
722    if (IsDead(to->from))
723      return;
724  
725 <  buffer = dbuf_alloc();
726 <
727 <  if (MyClient(to))
728 <  {
836 <    if (IsServer(from))
837 <      dbuf_put_fmt(buffer, ":%s %s %s ", from->name, command, to->name);
838 <    else
839 <      dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name);
840 <  }
725 >  struct dbuf_block *buffer = dbuf_alloc();
726 >  if (MyClient(to) && IsClient(from))
727 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
728 >                 from->host, command, to->name);
729    else
730 <    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to));
730 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
731 >                 command, ID_or_name(to, to));
732  
733    va_start(args, pattern);
734    send_format(buffer, pattern, args);
735    va_end(args);
736  
737 <  if (MyClient(to))
737 >  if (MyConnect(to))
738      send_message(to, buffer);
739    else
740 <    send_message_remote(to, from, buffer);
740 >    send_message_remote(to->from, from, buffer);
741  
742    dbuf_ref_free(buffer);
743   }
# Line 864 | Line 753 | sendto_anywhere(struct Client *to, struc
753   void
754   sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
755   {
756 <  const char *ntype = NULL;
757 <  dlink_node *ptr = NULL;
869 <  char nbuf[IRCD_BUFSIZE];
756 >  const char *ntype = "???";
757 >  dlink_node *node;
758    va_list args;
759  
872 –  va_start(args, pattern);
873 –  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
874 –  va_end(args);
875 –
760    switch (type)
761    {
762      case SEND_NOTICE:
# Line 888 | Line 772 | sendto_realops_flags(unsigned int flags,
772        assert(0);
773    }
774  
775 <  DLINK_FOREACH(ptr, oper_list.head)
775 >  struct dbuf_block *buffer = dbuf_alloc();
776 >  dbuf_put_fmt(buffer, ":%s NOTICE * :*** %s -- ", me.name, ntype);
777 >
778 >  va_start(args, pattern);
779 >  send_format(buffer, pattern, args);
780 >  va_end(args);
781 >
782 >  DLINK_FOREACH(node, oper_list.head)
783    {
784 <    struct Client *client_p = ptr->data;
784 >    struct Client *client_p = node->data;
785      assert(HasUMode(client_p, UMODE_OPER));
786  
787 +    if (IsDead(client_p))
788 +      continue;
789 +
790      /*
791       * If we're sending it to opers and they're an admin, skip.
792       * If we're sending it to admins, and they're not, skip.
# Line 901 | Line 795 | sendto_realops_flags(unsigned int flags,
795          ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
796        continue;
797  
798 <    if (HasUMode(client_p, flags))
799 <      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
906 <                 me.name, client_p->name, ntype, nbuf);
907 <  }
908 < }
909 <
910 < /* sendto_wallops_flags()
911 < *
912 < * inputs       - flag types of messages to show to real opers
913 < *              - client sending request
914 < *              - var args input message
915 < * output       - NONE
916 < * side effects - Send a wallops to local opers
917 < */
918 < void
919 < sendto_wallops_flags(unsigned int flags, struct Client *source_p,
920 <                     const char *pattern, ...)
921 < {
922 <  dlink_node *ptr = NULL;
923 <  va_list args;
924 <  struct dbuf_block *buffer;
925 <
926 <  buffer = dbuf_alloc();
927 <
928 <  if (IsClient(source_p))
929 <    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
930 <  else
931 <    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
932 <
933 <  va_start(args, pattern);
934 <  send_format(buffer, pattern, args);
935 <  va_end(args);
936 <
937 <  DLINK_FOREACH(ptr, oper_list.head)
938 <  {
939 <    struct Client *client_p = ptr->data;
940 <    assert(client_p->umodes & UMODE_OPER);
798 >    if (!HasUMode(client_p, flags))
799 >      continue;
800  
801 <    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
943 <      send_message(client_p, buffer);
801 >    send_message(client_p, buffer);
802    }
803  
804    dbuf_ref_free(buffer);
# Line 948 | Line 806 | sendto_wallops_flags(unsigned int flags,
806  
807   /* ts_warn()
808   *
809 < * inputs       - var args message
810 < * output       - NONE
811 < * side effects - Call sendto_realops_flags, with some flood checking
812 < *                (at most 5 warnings every 5 seconds)
809 > * inputs       - var args message
810 > * output       - NONE
811 > * side effects - Call sendto_realops_flags, with some flood checking
812 > *                (at most 5 warnings every 5 seconds)
813   */
814   void
815 < sendto_realops_flags_ratelimited(const char *pattern, ...)
815 > sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
816   {
817    va_list args;
818 <  char buffer[IRCD_BUFSIZE];
961 <  static time_t last = 0;
962 <  static int warnings = 0;
818 >  char buffer[IRCD_BUFSIZE] = "";
819  
820 <  /*
821 <   ** if we're running with TS_WARNINGS enabled and someone does
966 <   ** something silly like (remotely) connecting a nonTS server,
967 <   ** we'll get a ton of warnings, so we make sure we don't send
968 <   ** more than 5 every 5 seconds.  -orabidoo
969 <   */
820 >  if ((event_base->time.sec_monotonic - *rate) < 20)
821 >    return;
822  
823 <  if (CurrentTime - last < 5)
972 <  {
973 <    if (++warnings > 5)
974 <      return;
975 <  }
976 <  else
977 <  {
978 <    last = CurrentTime;
979 <    warnings = 0;
980 <  }
823 >  *rate = event_base->time.sec_monotonic;
824  
825    va_start(args, pattern);
826    vsnprintf(buffer, sizeof(buffer), pattern, args);
827    va_end(args);
828  
829 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
829 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
830    ilog(LOG_TYPE_IRCD, "%s", buffer);
831   }
832  
833 < /* kill_client_serv_butone()
833 > /* sendto_wallops_flags()
834   *
835 < * inputs       - pointer to client to not send to
836 < *              - pointer to client to kill
837 < * output       - NONE
838 < * side effects - Send a KILL for the given client
839 < *                message to all connected servers
997 < *                except the client 'one'. Also deal with
998 < *                client being unknown to leaf, as in lazylink...
835 > * inputs       - flag types of messages to show to real opers
836 > *              - client sending request
837 > *              - var args input message
838 > * output       - NONE
839 > * side effects - Send a wallops to local opers
840   */
841   void
842 < kill_client_serv_butone(struct Client *one, struct Client *source_p,
843 <                        const char *pattern, ...)
842 > sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
843 >                     const char *pattern, ...)
844   {
845 +  dlink_node *node;
846    va_list args;
847 <  dlink_node *ptr = NULL;
848 <  struct dbuf_block *uid_buffer = dbuf_alloc();
847 >  struct dbuf_block *buffer = dbuf_alloc();
848 >
849 >  if (IsClient(source_p))
850 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
851 >  else
852 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
853  
854    va_start(args, pattern);
855 <  dbuf_put_fmt(uid_buffer, ":%s KILL %s :", ID(&me), ID(source_p));
1010 <  send_format(uid_buffer, pattern, args);
855 >  send_format(buffer, pattern, args);
856    va_end(args);
857  
858 <  DLINK_FOREACH(ptr, serv_list.head)
858 >  DLINK_FOREACH(node, oper_list.head)
859    {
860 <    struct Client *client_p = ptr->data;
860 >    struct Client *client_p = node->data;
861 >    assert(client_p->umodes & UMODE_OPER);
862  
863 <    if (one != NULL && (client_p == one->from))
863 >    if (IsDead(client_p))
864        continue;
865 <    if (IsDefunct(client_p))
865 >
866 >    if (!HasUMode(client_p, flags))
867        continue;
868  
869 <    send_message(client_p, uid_buffer);
869 >    send_message(client_p, buffer);
870    }
871  
872 <  dbuf_ref_free(uid_buffer);
872 >  dbuf_ref_free(buffer);
873   }

Comparing ircd-hybrid/trunk/src/send.c (property svn:keywords):
Revision 3176 by michael, Tue Mar 18 20:00:16 2014 UTC vs.
Revision 9002 by michael, Sat May 25 23:13:57 2019 UTC

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

Diff Legend

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