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 33 by knight, Sun Oct 2 20:50:00 2005 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 3103 by michael, Thu Mar 6 00:05:12 2014 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-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file send.c
23 > * \brief Functions for sending messages.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "send.h"
30   #include "channel.h"
31   #include "client.h"
30 #include "common.h"
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
34 #include "handlers.h"
35   #include "numeric.h"
36   #include "fdlist.h"
37   #include "s_bsd.h"
38   #include "s_serv.h"
39 < #include "sprintf_irc.h"
40 < #include "s_conf.h"
41 < #include "list.h"
42 < #include "s_log.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "memory.h"
44 #include "hook.h"
45 #include "irc_getnameinfo.h"
42   #include "packet.h"
43  
48 #define LOG_BUFSIZE 2048
49
50 struct Callback *iosend_cb = NULL;
51 struct Callback *iosendctrl_cb = NULL;
44  
45 < static void send_message(struct Client *, char *, int);
54 < static void send_message_remote(struct Client *, struct Client *, char *, int);
45 > static unsigned int current_serial = 0;
46  
56 static unsigned long current_serial = 0L;
47  
48   /* send_format()
49   *
# Line 74 | Line 64 | send_format(char *lsendbuf, int bufsize,
64     *
65     * IRC messages are always lines of characters terminated with a CR-LF
66     * (Carriage Return - Line Feed) pair, and these messages shall not
67 <   * exceed 512 characters in length,  counting all characters
67 >   * exceed 512 characters in length,  counting all characters
68     * including the trailing CR-LF.
69     * Thus, there are 510 characters maximum allowed
70     * for the command and its parameters.  There is no provision for
# Line 87 | Line 77 | send_format(char *lsendbuf, int bufsize,
77  
78    lsendbuf[len++] = '\r';
79    lsendbuf[len++] = '\n';
80 <  return (len);
80 >  return len;
81   }
82  
83   /*
# Line 98 | Line 88 | send_format(char *lsendbuf, int bufsize,
88   static void
89   send_message(struct Client *to, char *buf, int len)
90   {
91 < #ifdef INVARIANTS
92 <  if (IsMe(to))
103 <  {
104 <    sendto_realops_flags(UMODE_ALL, L_ALL,
105 <                         "Trying to send message to myself!");
106 <    return;
107 <  }
108 < #endif
91 >  assert(!IsMe(to));
92 >  assert(to != &me);
93  
94 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
94 >  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs))
95    {
96      if (IsServer(to))
97 <      sendto_realops_flags(UMODE_ALL, L_ALL,
98 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
97 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
98 >                           "Max SendQ limit exceeded for %s: %lu > %u",
99                             get_client_name(to, HIDE_IP),
100                             (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
101 <                           get_sendq(to));
101 >                           get_sendq(&to->localClient->confs));
102      if (IsClient(to))
103        SetSendQExceeded(to);
104      dead_link_on_write(to, 0);
# Line 131 | Line 115 | send_message(struct Client *to, char *bu
115    ++to->localClient->send.messages;
116    ++me.localClient->send.messages;
117  
118 <  if (dbuf_length(&to->localClient->buf_sendq) >
135 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
136 <    send_queued_write(to);
118 >  send_queued_write(to);
119   }
120  
121   /* send_message_remote()
# Line 145 | Line 127 | send_message(struct Client *to, char *bu
127   * output       - none
128   * side effects - Despite the function name, this only sends to directly
129   *                connected clients.
130 < *
130 > *
131   */
132   static void
133   send_message_remote(struct Client *to, struct Client *from,
134                      char *buf, int len)
135   {
136 +  if (to->from)
137 +    to = to->from;
138 +
139    if (!MyConnect(to))
140    {
141 <    sendto_realops_flags(UMODE_ALL, L_ALL,
142 <                         "server send message to %s [%s] dropped from %s(Not local server)",
143 <                         to->name, to->from->name, from->name);
141 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
142 >                         "Server send message to %s [%s] dropped from %s(Not local server)",
143 >                         to->name, to->from->name, from->name);
144      return;
145    }
146  
162  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
147    /* Optimize by checking if (from && to) before everything */
148    /* we set to->from up there.. */
149  
# Line 173 | Line 151 | send_message_remote(struct Client *to, s
151    {
152      if (IsServer(from))
153      {
154 <      sendto_realops_flags(UMODE_ALL, L_ALL,
154 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
155                             "Send message to %s [%s] dropped from %s(Fake Dir)",
156                             to->name, to->from->name, from->name);
157        return;
158      }
159  
160 <    sendto_realops_flags(UMODE_ALL, L_ALL,
160 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
161                           "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
162                           to->name, to->username, to->host,
163                           from->name, from->username, from->host,
164                           to->from->name);
165  
166 <    sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS,
166 >    sendto_server(NULL, CAP_TS6, NOCAPS,
167                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
168                    me.id, to->name, me.name, to->name,
169                    to->username, to->host, to->from->name);
170 <    sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS,
170 >    sendto_server(NULL, NOCAPS, CAP_TS6,
171                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
172                    me.name, to->name, me.name, to->name,
173                    to->username, to->host, to->from->name);
174  
175 <    SetKilled(to);
175 >    AddFlag(to, FLAGS_KILLED);
176  
177      if (IsClient(from))
178        sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
# Line 202 | Line 180 | send_message_remote(struct Client *to, s
180                   to->host, to->from);
181  
182      exit_client(to, &me, "Ghosted client");
205
183      return;
184 <  }
184 >  }
185  
186    send_message(to, buf, len);
187   }
# Line 216 | Line 193 | send_message_remote(struct Client *to, s
193   void
194   sendq_unblocked(fde_t *fd, struct Client *client_p)
195   {
196 <  ClearSendqBlocked(client_p);
197 <  /* 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 < }
230 <
231 < /*
232 < ** 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);
196 >  assert(fd == &client_p->localClient->fd);
197 >  send_queued_write(client_p);
198   }
199  
200   /*
# Line 248 | Line 206 | slinkq_unblocked(fde_t *fd, struct Clien
206   void
207   send_queued_write(struct Client *to)
208   {
209 <  int retlen;
210 <  struct dbuf_block *first;
209 >  int retlen = 0;
210 >  struct dbuf_block *first = NULL;
211  
212    /*
213     ** Once socket is marked dead, we cannot start writing to it,
214     ** even if the error is removed...
215     */
216 <  if (IsDead(to) || IsSendqBlocked(to))
216 >  if (IsDead(to))
217      return;  /* no use calling send() now */
218  
219    /* Next, lets try to write some data */
262
220    if (dbuf_length(&to->localClient->buf_sendq))
221    {
222 <    do {
222 >    do
223 >    {
224        first = to->localClient->buf_sendq.blocks.head->data;
225  
226   #ifdef HAVE_LIBCRYPTO
# Line 271 | Line 229 | send_queued_write(struct Client *to)
229          retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
230  
231          /* translate openssl error codes, sigh */
232 <        if (retlen < 0)
233 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
234 <          {
232 >        if (retlen < 0)
233 >        {
234 >          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
235 >          {
236              case SSL_ERROR_WANT_READ:
237 <              return;  /* retry later, don't register for write events */
238 <
239 <            case SSL_ERROR_WANT_WRITE:
281 <              errno = EWOULDBLOCK;
237 >              return;  /* retry later, don't register for write events */
238 >            case SSL_ERROR_WANT_WRITE:
239 >              errno = EWOULDBLOCK;
240              case SSL_ERROR_SYSCALL:
241 <              break;
242 <
241 >              break;
242 >            case SSL_ERROR_SSL:
243 >              if (errno == EAGAIN)
244 >                break;
245              default:
246 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
247 <          }
246 >              retlen = errno = 0;  /* either an SSL-specific error or EOF */
247 >          }
248 >        }
249        }
250        else
251   #endif
252          retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
253  
254        if (retlen <= 0)
294      {
295 #ifdef _WIN32
296        errno = WSAGetLastError();
297 #endif
255          break;
299      }
256  
301      execute_callback(iosend_cb, to, retlen, first->data);
257        dbuf_delete(&to->localClient->buf_sendq, retlen);
258  
259        /* We have some data written .. update counters */
# Line 309 | Line 264 | send_queued_write(struct Client *to)
264      if ((retlen < 0) && (ignoreErrno(errno)))
265      {
266        /* we have a non-fatal error, reschedule a write */
312      SetSendqBlocked(to);
267        comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
268 <                     (PF *)sendq_unblocked, (void *)to, 0);
268 >                     (PF *)sendq_unblocked, to, 0);
269      }
270      else if (retlen <= 0)
271      {
# Line 321 | Line 275 | send_queued_write(struct Client *to)
275    }
276   }
277  
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
278   /* send_queued_all()
279   *
280   * input        - NONE
# Line 402 | Line 290 | send_queued_all(void)
290     * a notice to opers, which is to be delivered by this function.
291     */
292    DLINK_FOREACH(ptr, serv_list.head)
293 <    send_queued_write((struct Client *) ptr->data);
293 >    send_queued_write(ptr->data);
294  
295    DLINK_FOREACH(ptr, unknown_list.head)
296 <    send_queued_write((struct Client *) ptr->data);
296 >    send_queued_write(ptr->data);
297  
298    DLINK_FOREACH(ptr, local_client_list.head)
299 <    send_queued_write((struct Client *) ptr->data);
299 >    send_queued_write(ptr->data);
300  
301    /* NOTE: This can still put clients on aborted_list; unfortunately,
302     * exit_aborted_clients takes precedence over send_queued_all,
# Line 438 | Line 326 | sendto_one(struct Client *to, const char
326      return; /* This socket has already been marked as dead */
327  
328    va_start(args, pattern);
329 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
329 >  len = send_format(buffer, sizeof(buffer), pattern, args);
330    va_end(args);
331  
332    send_message(to, buffer, len);
# Line 457 | Line 345 | sendto_one(struct Client *to, const char
345   */
346   void
347   sendto_channel_butone(struct Client *one, struct Client *from,
348 <                      struct Channel *chptr, const char *command,
348 >                      struct Channel *chptr, unsigned int type,
349                        const char *pattern, ...)
350   {
351 <  va_list args;
351 >  va_list alocal, aremote, auid;
352    char local_buf[IRCD_BUFSIZE];
353    char remote_buf[IRCD_BUFSIZE];
354    char uid_buf[IRCD_BUFSIZE];
355    int local_len, remote_len, uid_len;
356 <  dlink_node *ptr;
469 <  dlink_node *ptr_next;
470 <  struct Client *target_p;
356 >  dlink_node *ptr = NULL, *ptr_next = NULL;
357  
358    if (IsServer(from))
359 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
360 <                           from->name, command, chptr->chname);
359 >    local_len = snprintf(local_buf, sizeof(local_buf), ":%s ",
360 >                        from->name);
361    else
362 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
363 <                           from->name, from->username, from->host,
364 <                           command, chptr->chname);
365 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
366 <                          from->name, command, chptr->chname);
367 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
368 <                       ID(from), command, chptr->chname);
369 <
370 <  va_start(args, pattern);
362 >    local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
363 >                         from->name, from->username, from->host);
364 >  remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
365 >                        from->name);
366 >  uid_len = snprintf(uid_buf, sizeof(uid_buf), ":%s ", ID(from));
367 >
368 >  va_start(alocal, pattern);
369 >  va_start(aremote, pattern);
370 >  va_start(auid, pattern);
371    local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
372 <                           pattern, args);
372 >                           pattern, alocal);
373    remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
374 <                            pattern, args);
374 >                            pattern, aremote);
375    uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
376 <                         args);
377 <  va_end(args);
376 >                         auid);
377 >  va_end(auid);
378 >  va_end(aremote);
379 >  va_end(alocal);
380  
381    ++current_serial;
382  
383    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
384    {
385 <    target_p = ((struct Membership *)ptr->data)->client_p;
386 <    assert(target_p != NULL);
385 >    struct Membership *ms = ptr->data;
386 >    struct Client *target_p = ms->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) || target_p->from == one)
391        continue;
392  
393 <    if (MyClient(target_p))
394 <    {
395 <      if (target_p->serial != current_serial)
396 <      {
397 <        send_message(target_p, local_buf, local_len);
398 <        target_p->serial = current_serial;
399 <      }
400 <    }
511 <    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 <    }
393 >    if (type != 0 && (ms->flags & type) == 0)
394 >      continue;
395 >
396 >    if (MyConnect(target_p))
397 >      send_message(target_p, local_buf);
398 >    else if (target_p->from->localClient->serial != current_serial)
399 >      send_message_remote(target_p->from, from, remote_buf);
400 >    target_p->from->localClient->serial = current_serial;
401    }
402   }
403  
404   /* sendto_server()
405 < *
405 > *
406   * inputs       - pointer to client to NOT send to
407 < *              - pointer to source client required by LL (if any)
532 < *              - pointer to channel required by LL (if any)
407 > *              - pointer to channel
408   *              - caps or'd together which must ALL be present
409   *              - caps or'd together which must ALL NOT be present
535 *              - LL flags: LL_ICLIENT | LL_ICHAN
410   *              - printf style format string
411   *              - args to format string
412   * output       - NONE
413   * side effects - Send a message to all connected servers, except the
414   *                client 'one' (if non-NULL), as long as the servers
415   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
416 < *                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 < *            
416 > *
417   * This function was written in an attempt to merge together the other
418   * billion sendto_*serv*() functions, which sprung up with capabs,
419   * lazylinks, uids, etc.
420   * -davidt
421   */
422 < void
423 < sendto_server(struct Client *one, struct Client *source_p,
424 <              struct Channel *chptr, unsigned long caps,
425 <              unsigned long nocaps, unsigned long llflags,
422 > void
423 > sendto_server(struct Client *one,
424 >              const unsigned int caps,
425 >              const unsigned int nocaps,
426                const char *format, ...)
427   {
428    va_list args;
429 <  struct Client *client_p;
563 <  dlink_node *ptr;
429 >  dlink_node *ptr = NULL;
430    char buffer[IRCD_BUFSIZE];
431 <  int len;
566 <
567 <  if (chptr != NULL)
568 <  {
569 <    if (chptr->chname[0] != '#')
570 <      return;
571 <  }
431 >  int len = 0;
432  
433    va_start(args, format);
434 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
434 >  len = send_format(buffer, sizeof(buffer), format, args);
435    va_end(args);
436  
437    DLINK_FOREACH(ptr, serv_list.head)
438    {
439 <    client_p = ptr->data;
439 >    struct Client *client_p = ptr->data;
440  
441      /* If dead already skip */
442      if (IsDead(client_p))
# Line 591 | Line 451 | sendto_server(struct Client *one, struct
451      if ((client_p->localClient->caps & nocaps) != 0)
452        continue;
453  
594    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    }
454      send_message(client_p, buffer, len);
455    }
456   }
# Line 630 | Line 461 | sendto_server(struct Client *one, struct
461   *              - pattern to send
462   * output       - NONE
463   * side effects - Sends a message to all people on local server who are
464 < *                in same channel with user.
464 > *                in same channel with user.
465   *                used by m_nick.c and exit_one_client.
466   */
467   void
468 < sendto_common_channels_local(struct Client *user, int touser,
468 > sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
469                               const char *pattern, ...)
470   {
471    va_list args;
# Line 647 | Line 478 | sendto_common_channels_local(struct Clie
478    int len;
479  
480    va_start(args, pattern);
481 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
481 >  len = send_format(buffer, sizeof(buffer), pattern, args);
482    va_end(args);
483  
484    ++current_serial;
485  
486    DLINK_FOREACH(cptr, user->channel.head)
487    {
488 <    chptr = ((struct Membership *) cptr->data)->chptr;
488 >    chptr = ((struct Membership *)cptr->data)->chptr;
489      assert(chptr != NULL);
490  
491 <    DLINK_FOREACH(uptr, chptr->locmembers.head)
491 >    DLINK_FOREACH(uptr, chptr->members.head)
492      {
493        ms = uptr->data;
494        target_p = ms->client_p;
495        assert(target_p != NULL);
496  
497 <      if (target_p == user || IsDefunct(target_p) ||
498 <          target_p->serial == current_serial)
497 >      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
498 >          target_p->localClient->serial == current_serial)
499 >        continue;
500 >
501 >      if (HasCap(target_p, cap) != cap)
502          continue;
503  
504 <      target_p->serial = current_serial;
504 >      target_p->localClient->serial = current_serial;
505        send_message(target_p, buffer, len);
506      }
507    }
508  
509    if (touser && MyConnect(user) && !IsDead(user) &&
510 <      user->serial != current_serial)
511 <    send_message(user, buffer, len);
510 >      user->localClient->serial != current_serial)
511 >    if (HasCap(user, cap) == cap)
512 >      send_message(user, buffer, len);
513   }
514  
515   /* sendto_channel_local()
# Line 688 | Line 523 | sendto_common_channels_local(struct Clie
523   *                locally connected to this server.
524   */
525   void
526 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
526 > sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr,
527                       const char *pattern, ...)
528   {
529    va_list args;
530    char buffer[IRCD_BUFSIZE];
531 <  int len;
532 <  dlink_node *ptr;
698 <  struct Membership *ms;
699 <  struct Client *target_p;
531 >  int len = 0;
532 >  dlink_node *ptr = NULL;
533  
534    va_start(args, pattern);
535 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
535 >  len = send_format(buffer, sizeof(buffer), pattern, args);
536    va_end(args);
537  
538 <  DLINK_FOREACH(ptr, chptr->locmembers.head)
538 >  DLINK_FOREACH(ptr, chptr->members.head)
539    {
540 <    ms = ptr->data;
541 <    target_p = ms->client_p;
540 >    struct Membership *ms = ptr->data;
541 >    struct Client *target_p = ms->client_p;
542  
543      if (type != 0 && (ms->flags & type) == 0)
544        continue;
545  
546 <    if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p)))
546 >    if (!MyConnect(target_p) || IsDefunct(target_p) ||
547 >        (nodeaf && HasUMode(target_p, UMODE_DEAF)))
548        continue;
549  
550      send_message(target_p, buffer, len);
# Line 729 | Line 563 | sendto_channel_local(int type, int nodea
563   *
564   * WARNING - +D clients are omitted
565   */
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)
753      continue;
754
755    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 */
566   void
567 < sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
568 <                      int nocaps, struct Channel *chptr, const char *pattern, ...)
567 > sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap,
568 >                            struct Channel *chptr, const char *pattern, ...)
569   {
570    va_list args;
571    char buffer[IRCD_BUFSIZE];
572 <  int len;
573 <  dlink_node *ptr;
781 <  struct Client *target_p;
782 <  struct Membership *ms;
572 >  int len = 0;
573 >  dlink_node *ptr = NULL;
574  
575    va_start(args, pattern);
576 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
576 >  len = send_format(buffer, sizeof(buffer), pattern, args);
577    va_end(args);
578  
579    DLINK_FOREACH(ptr, chptr->members.head)
580    {
581 <    ms = ptr->data;
582 <    target_p = ms->client_p;
581 >    struct Membership *ms = ptr->data;
582 >    struct Client *target_p = ms->client_p;
583  
584      if (type != 0 && (ms->flags & type) == 0)
585        continue;
586  
587 <    if (MyConnect(target_p))
587 >    if (!MyConnect(target_p) || target_p == one ||
588 >        IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
589        continue;
798    target_p = target_p->from;
590  
591 <    if (target_p == one->from ||
801 <        ((target_p->from->localClient->caps & caps) != caps) ||
802 <        ((target_p->from->localClient->caps & nocaps) != 0))
591 >    if (HasCap(target_p, cap) != cap)
592        continue;
593  
594      send_message(target_p, buffer, len);
595 <  }
595 >  }
596   }
597  
598   /*
# Line 824 | Line 613 | sendto_channel_remote(struct Client *one
613   * side effects - NONE
614   */
615   static int
616 < match_it(const struct Client *one, const char *mask, int what)
616 > match_it(const struct Client *one, const char *mask, unsigned int what)
617   {
618    if (what == MATCH_HOST)
619 <    return(match(mask, one->host));
619 >    return !match(mask, one->host);
620  
621 <  return(match(mask, one->servptr->name));
621 >  return !match(mask, one->servptr->name);
622   }
623  
624   /* sendto_match_butone()
# Line 843 | Line 632 | void
632   sendto_match_butone(struct Client *one, struct Client *from, char *mask,
633                      int what, const char *pattern, ...)
634   {
635 <  va_list args;
635 >  va_list alocal, aremote;
636    struct Client *client_p;
637    dlink_node *ptr, *ptr_next;
638    char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
639 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
640 <                             from->username, from->host);
641 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
639 >  int local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
640 >                           from->name, from->username, from->host);
641 >  int remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
642 >                            from->name);
643  
644 <  va_start(args, pattern);
644 >  va_start(alocal, pattern);
645 >  va_start(aremote, pattern);
646    local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
647 <                           pattern, args);
647 >                           pattern, alocal);
648    remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
649 <                            pattern, args);
650 <  va_end(args);
649 >                            pattern, aremote);
650 >  va_end(aremote);
651 >  va_end(alocal);
652  
653    /* scan the local clients */
654    DLINK_FOREACH(ptr, local_client_list.head)
# Line 912 | Line 704 | sendto_match_butone(struct Client *one,
704   * side effects - data sent to servers matching with capab
705   */
706   void
707 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
707 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
708                     const char *pattern, ...)
709   {
710    va_list args;
711 <  struct Client *target_p;
712 <  dlink_node *ptr;
713 <  char buffer[IRCD_BUFSIZE];
714 <  int found = 0;
711 >  dlink_node *ptr = NULL;
712 >  char buff_suid[IRCD_BUFSIZE];
713 >  char buff_name[IRCD_BUFSIZE];
714 >  int len_suid = 0;
715 >  int len_name = 0;
716  
717    va_start(args, pattern);
718 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
718 >  len_suid  = snprintf(buff_suid, sizeof(buff_suid), ":%s ", ID(source_p));
719 >  len_suid += send_format(&buff_suid[len_suid], sizeof(buff_suid) - len_suid,
720 >                          pattern, args);
721 >  va_end(args);
722 >
723 >  va_start(args, pattern);
724 >  len_name = snprintf(buff_name, sizeof(buff_name), ":%s ", source_p->name);
725 >  len_name += send_format(&buff_name[len_name], sizeof(buff_name) - len_name,
726 >                          pattern, args);
727    va_end(args);
728  
729 <  current_serial++;
729 >  ++current_serial;
730  
731    DLINK_FOREACH(ptr, global_serv_list.head)
732    {
733 <    target_p = ptr->data;
733 >    struct Client *target_p = ptr->data;
734  
735      /* Do not attempt to send to ourselves, or the source */
736      if (IsMe(target_p) || target_p->from == source_p->from)
737        continue;
738  
739 <    if (target_p->from->serial == current_serial)
739 >    if (target_p->from->localClient->serial == current_serial)
740        continue;
741  
742 <    if (match(mask, target_p->name))
742 >    if (!match(mask, target_p->name))
743      {
744        /*
745         * if we set the serial here, then we'll never do a
746         * match() again, if !IsCapable()
747         */
748 <      target_p->from->serial = current_serial;
948 <      found++;
748 >      target_p->from->localClient->serial = current_serial;
749  
750        if (!IsCapable(target_p->from, cap))
751          continue;
752  
753 <      sendto_anywhere(target_p, source_p, "%s", buffer);
753 >      if (HasID(target_p->from))
754 >        send_message_remote(target_p->from, source_p, buff_suid, len_suid);
755 >      else
756 >        send_message_remote(target_p->from, source_p, buff_name, len_name);
757      }
758    }
759   }
# Line 966 | Line 769 | sendto_match_servs(struct Client *source
769   */
770   void
771   sendto_anywhere(struct Client *to, struct Client *from,
772 +                const char *command,
773                  const char *pattern, ...)
774   {
775    va_list args;
776    char buffer[IRCD_BUFSIZE];
777 <  int len;
974 <  struct Client *send_to = (to->from != NULL ? to->from : to);
777 >  int len = 0;
778  
779 <  if (IsDead(send_to))
779 >  if (IsDead(to->from))
780      return;
781  
782    if (MyClient(to))
783    {
784      if (IsServer(from))
785 <    {
786 <      if (IsCapable(to, CAP_TS6) && HasID(from))
984 <        len = ircsprintf(buffer, ":%s ", from->id);
985 <      else
986 <        len = ircsprintf(buffer, ":%s ", from->name);
987 <    }
785 >      len = snprintf(buffer, sizeof(buffer), ":%s %s %s ",
786 >                     from->name, command, to->name);
787      else
788 <      len = ircsprintf(buffer, ":%s!%s@%s ",
789 <                       from->name, from->username, from->host);
788 >      len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s %s %s ",
789 >                     from->name, from->username, from->host, command, to->name);
790    }
791 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
791 >  else
792 >    len = snprintf(buffer, sizeof(buffer), ":%s %s %s ",
793 >                   ID_or_name(from, to), command,
794 >                   ID_or_name(to, to));
795  
796    va_start(args, pattern);
797 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
797 >  len += send_format(&buffer[len], sizeof(buffer) - len, pattern, args);
798    va_end(args);
799  
800 <  if(MyClient(to))
801 <    send_message(send_to, buffer, len);
800 >  if (MyClient(to))
801 >    send_message(to, buffer, len);
802    else
803 <    send_message_remote(send_to, from, buffer, len);
803 >    send_message_remote(to, from, buffer, len);
804   }
805  
806   /* sendto_realops_flags()
# Line 1010 | Line 812 | sendto_anywhere(struct Client *to, struc
812   * side effects - Send to *local* ops only but NOT +s nonopers.
813   */
814   void
815 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
815 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
816   {
817 <  struct Client *client_p;
817 >  const char *ntype = NULL;
818 >  dlink_node *ptr = NULL;
819    char nbuf[IRCD_BUFSIZE];
1017  dlink_node *ptr;
820    va_list args;
821  
822    va_start(args, pattern);
823 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
823 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
824    va_end(args);
825  
826 +  switch (type)
827 +  {
828 +    case SEND_NOTICE:
829 +      ntype = "Notice";
830 +      break;
831 +    case SEND_GLOBAL:
832 +      ntype = "Global";
833 +      break;
834 +    case SEND_LOCOPS:
835 +      ntype = "LocOps";
836 +      break;
837 +    default:
838 +      assert(0);
839 +  }
840 +
841    DLINK_FOREACH(ptr, oper_list.head)
842    {
843 <    client_p = ptr->data;
844 <    assert(client_p->umodes & UMODE_OPER);
843 >    struct Client *client_p = ptr->data;
844 >    assert(HasUMode(client_p, UMODE_OPER));
845  
846 <    /* If we're sending it to opers and theyre an admin, skip.
847 <     * If we're sending it to admins, and theyre not, skip.
846 >    /*
847 >     * If we're sending it to opers and they're an admin, skip.
848 >     * If we're sending it to admins, and they're not, skip.
849       */
850 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
851 <        ((level == L_OPER) && IsAdmin(client_p)))
850 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
851 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
852        continue;
853  
854 <    if (client_p->umodes & flags)
855 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
856 <                 me.name, client_p->name, nbuf);
854 >    if (HasUMode(client_p, flags))
855 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
856 >                 me.name, client_p->name, ntype, nbuf);
857    }
858   }
859  
# Line 1051 | Line 869 | void
869   sendto_wallops_flags(unsigned int flags, struct Client *source_p,
870                       const char *pattern, ...)
871   {
872 <  struct Client *client_p;
1055 <  dlink_node *ptr;
872 >  dlink_node *ptr = NULL;
873    va_list args;
874    char buffer[IRCD_BUFSIZE];
875    int len;
876  
877    if (IsClient(source_p))
878 <    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
879 <                     source_p->name, source_p->username, source_p->host);
878 >    len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s WALLOPS :",
879 >                   source_p->name, source_p->username,
880 >                   source_p->host);
881    else
882 <    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
882 >    len = snprintf(buffer, sizeof(buffer), ":%s WALLOPS :",
883 >                   source_p->name);
884  
885    va_start(args, pattern);
886    len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
# Line 1069 | Line 888 | sendto_wallops_flags(unsigned int flags,
888  
889    DLINK_FOREACH(ptr, oper_list.head)
890    {
891 <    client_p = ptr->data;
891 >    struct Client *client_p = ptr->data;
892      assert(client_p->umodes & UMODE_OPER);
893  
894 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
894 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
895        send_message(client_p, buffer, len);
896    }
897   }
# Line 1085 | Line 904 | sendto_wallops_flags(unsigned int flags,
904   *                (at most 5 warnings every 5 seconds)
905   */
906   void
907 < ts_warn(const char *pattern, ...)
907 > sendto_realops_flags_ratelimited(const char *pattern, ...)
908   {
909    va_list args;
910 <  char buffer[LOG_BUFSIZE];
910 >  char buffer[IRCD_BUFSIZE];
911    static time_t last = 0;
912    static int warnings = 0;
913  
# Line 1111 | Line 930 | ts_warn(const char *pattern, ...)
930    }
931  
932    va_start(args, pattern);
933 <  vsprintf_irc(buffer, pattern, args);
933 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
934    va_end(args);
935  
936 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
937 <  ilog(L_CRIT, "%s", buffer);
936 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
937 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
938   }
939  
940   /* kill_client()
# Line 1139 | Line 958 | kill_client(struct Client *client_p, str
958    if (IsDead(client_p))
959      return;
960  
961 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
962 <                   ID_or_name(diedie, client_p));
961 >  len = snprintf(buffer, sizeof(buffer), ":%s KILL %s :",
962 >                 ID_or_name(&me, client_p),
963 >                 ID_or_name(diedie, client_p));
964  
965    va_start(args, pattern);
966    len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
# Line 1160 | Line 980 | kill_client(struct Client *client_p, str
980   *                client being unknown to leaf, as in lazylink...
981   */
982   void
983 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
984 <                           const char *pattern, ...)
983 > kill_client_serv_butone(struct Client *one, struct Client *source_p,
984 >                        const char *pattern, ...)
985   {
986    va_list args;
987    int have_uid = 0;
988 <  struct Client *client_p;
1169 <  dlink_node *ptr;
988 >  dlink_node *ptr = NULL;
989    char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
990 <  int len_uid = 0, len_nick;
990 >  int len_uid = 0, len_nick = 0;
991  
992 <  va_start(args, pattern);
1174 <  if (HasID(source_p) && (me.id[0] != '\0'))
992 >  if (HasID(source_p))
993    {
994      have_uid = 1;
995 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
996 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
997 <                           args);
995 >    va_start(args, pattern);
996 >    len_uid = snprintf(buf_uid, sizeof(buf_uid), ":%s KILL %s :",
997 >                       me.id, ID(source_p));
998 >    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, args);
999 >    va_end(args);
1000    }
1001 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1002 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1003 <                          args);
1001 >
1002 >  va_start(args, pattern);
1003 >  len_nick = snprintf(buf_nick, sizeof(buf_nick), ":%s KILL %s :",
1004 >                      me.name, source_p->name);
1005 >  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, args);
1006    va_end(args);
1007  
1008    DLINK_FOREACH(ptr, serv_list.head)
1009    {
1010 <    client_p = ptr->data;
1010 >    struct Client *client_p = ptr->data;
1011  
1012      if (one != NULL && (client_p == one->from))
1013        continue;
1014      if (IsDefunct(client_p))
1015        continue;
1016  
1017 <    /* XXX perhaps IsCapable should test for localClient itself ? -db */
1018 <    if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) ||
1019 <        !ServerInfo.hub ||
1020 <        (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 <    }
1017 >    if (have_uid && IsCapable(client_p, CAP_TS6))
1018 >      send_message(client_p, buf_uid, len_uid);
1019 >    else
1020 >      send_message(client_p, buf_nick, len_nick);
1021    }
1022 < }
1022 > }

Diff Legend

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