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 3103 by michael, Thu Mar 6 00:05:12 2014 UTC vs.
Revision 3311 by michael, Tue Apr 15 12:10:36 2014 UTC

# Line 47 | Line 47 | static unsigned int current_serial = 0;
47  
48   /* send_format()
49   *
50 < * inputs       - buffer to format into
51 < *              - size of the buffer
50 > * inputs
51 > *              - buffer
52   *              - format pattern to use
53   *              - var args
54   * output       - number of bytes formatted output
55   * side effects - modifies sendbuf
56   */
57 < static inline int
58 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
57 > static void
58 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
59   {
60 –  int len;
61 –
60    /*
61     * from rfc1459
62     *
# Line 71 | Line 69 | send_format(char *lsendbuf, int bufsize,
69     * continuation message lines.  See section 7 for more details about
70     * current implementations.
71     */
72 <  len = vsnprintf(lsendbuf, bufsize - 1, pattern, args);
73 <  if (len > bufsize - 2)
74 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
75 <
76 <  lsendbuf[len++] = '\r';
77 <  lsendbuf[len++] = '\n';
78 <  return len;
72 >  dbuf_put_args(buffer, pattern, args);
73 >
74 >  if (buffer->size > sizeof(buffer->data) - 2)
75 >    buffer->size = sizeof(buffer->data) - 2;
76 >
77 >  buffer->data[buffer->size++] = '\r';
78 >  buffer->data[buffer->size++] = '\n';
79   }
80  
81   /*
# Line 86 | Line 84 | send_format(char *lsendbuf, int bufsize,
84   **      sendq.
85   */
86   static void
87 < send_message(struct Client *to, char *buf, int len)
87 > send_message(struct Client *to, struct dbuf_block *buf)
88   {
89    assert(!IsMe(to));
90    assert(to != &me);
91  
92 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs))
92 >  if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs))
93    {
94      if (IsServer(to))
95        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
96                             "Max SendQ limit exceeded for %s: %lu > %u",
97                             get_client_name(to, HIDE_IP),
98 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
98 >                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size),
99                             get_sendq(&to->localClient->confs));
100      if (IsClient(to))
101        SetSendQExceeded(to);
102 +
103      dead_link_on_write(to, 0);
104      return;
105    }
106  
107 <  dbuf_put(&to->localClient->buf_sendq, buf, len);
107 >  dbuf_add(&to->localClient->buf_sendq, buf);
108  
109    /*
110 <   ** Update statistics. The following is slightly incorrect
111 <   ** because it counts messages even if queued, but bytes
112 <   ** only really sent. Queued bytes get updated in SendQueued.
110 >   * Update statistics. The following is slightly incorrect because
111 >   * it counts messages even if queued, but bytes only really sent.
112 >   * Queued bytes get updated in send_queued_write().
113     */
114    ++to->localClient->send.messages;
115    ++me.localClient->send.messages;
# Line 122 | Line 121 | send_message(struct Client *to, char *bu
121   *
122   * inputs       - pointer to client from message is being sent
123   *              - pointer to client to send to
124 < *              - pointer to preformatted buffer
126 < *              - length of input buffer
124 > *              - pointer to buffer
125   * output       - none
126   * side effects - Despite the function name, this only sends to directly
127   *                connected clients.
128   *
129   */
130   static void
131 < send_message_remote(struct Client *to, struct Client *from,
134 <                    char *buf, int len)
131 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
132   {
133 <  if (to->from)
137 <    to = to->from;
133 >  to = to->from;
134  
135    if (!MyConnect(to))
136    {
# Line 163 | Line 159 | send_message_remote(struct Client *to, s
159                           from->name, from->username, from->host,
160                           to->from->name);
161  
162 <    sendto_server(NULL, CAP_TS6, NOCAPS,
162 >    sendto_server(NULL, NOCAPS, NOCAPS,
163                    ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
164 <                  me.id, to->name, me.name, to->name,
169 <                  to->username, to->host, to->from->name);
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,
164 >                  me.id, to->id, me.name, to->name,
165                    to->username, to->host, to->from->name);
166  
167      AddFlag(to, FLAGS_KILLED);
168  
169      if (IsClient(from))
170 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
171 <                 me.name, from->name, to->name, to->username,
180 <                 to->host, to->from);
170 >      sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name,
171 >                         to->username, to->host, to->from);
172  
173 <    exit_client(to, &me, "Ghosted client");
173 >    exit_client(to, "Ghosted client");
174      return;
175    }
176  
177 <  send_message(to, buf, len);
177 >  send_message(to, buf);
178   }
179  
180   /*
# Line 207 | Line 198 | void
198   send_queued_write(struct Client *to)
199   {
200    int retlen = 0;
210 –  struct dbuf_block *first = NULL;
201  
202    /*
203     ** Once socket is marked dead, we cannot start writing to it,
# Line 221 | Line 211 | send_queued_write(struct Client *to)
211    {
212      do
213      {
214 <      first = to->localClient->buf_sendq.blocks.head->data;
214 >      struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data;
215  
216   #ifdef HAVE_LIBCRYPTO
217        if (to->localClient->fd.ssl)
218        {
219 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
219 >        retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos);
220  
221          /* translate openssl error codes, sigh */
222          if (retlen < 0)
# Line 249 | Line 239 | send_queued_write(struct Client *to)
239        }
240        else
241   #endif
242 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
242 >        retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0);
243  
244        if (retlen <= 0)
245          break;
# Line 317 | Line 307 | void
307   sendto_one(struct Client *to, const char *pattern, ...)
308   {
309    va_list args;
310 <  char buffer[IRCD_BUFSIZE];
321 <  int len;
310 >  struct dbuf_block *buffer = NULL;
311  
312 <  if (to->from != NULL)
313 <    to = to->from;
314 <  if (IsDead(to))
315 <    return; /* This socket has already been marked as dead */
312 >  if (IsDead(to->from))
313 >    return;  /* This socket has already been marked as dead */
314 >
315 >  buffer = dbuf_alloc();
316 >
317 >  va_start(args, pattern);
318 >  send_format(buffer, pattern, args);
319 >  va_end(args);
320 >
321 >  send_message(to->from, buffer);
322 >
323 >  dbuf_ref_free(buffer);
324 > }
325 >
326 > void
327 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
328 > {
329 >  struct dbuf_block *buffer = NULL;
330 >  const char *dest = NULL;
331 >  va_list args;
332 >
333 >  if (IsDead(to->from))
334 >    return;
335 >
336 >  dest = ID_or_name(to, to);
337 >  if (EmptyString(dest))
338 >    dest = "*";
339 >
340 >  buffer = dbuf_alloc();
341 >
342 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest);
343 >
344 >  va_start(args, numeric);
345 >  send_format(buffer, numeric_form(numeric), args);
346 >  va_end(args);
347 >
348 >  send_message(to->from, buffer);
349 >
350 >  dbuf_ref_free(buffer);
351 > }
352 >
353 > void
354 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
355 > {
356 >  struct dbuf_block *buffer = NULL;
357 >  const char *dest = NULL;
358 >  va_list args;
359 >
360 >  if (IsDead(to->from))
361 >    return;
362 >
363 >  dest = ID_or_name(to, to);
364 >  if (EmptyString(dest))
365 >    dest = "*";
366 >
367 >  buffer = dbuf_alloc();
368 >
369 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
370  
371    va_start(args, pattern);
372 <  len = send_format(buffer, sizeof(buffer), pattern, args);
372 >  send_format(buffer, pattern, args);
373    va_end(args);
374  
375 <  send_message(to, buffer, len);
375 >  send_message(to->from, buffer);
376 >
377 >  dbuf_ref_free(buffer);
378   }
379  
380   /* sendto_channel_butone()
# Line 348 | Line 393 | sendto_channel_butone(struct Client *one
393                        struct Channel *chptr, unsigned int type,
394                        const char *pattern, ...)
395   {
396 <  va_list alocal, aremote, auid;
397 <  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;
396 >  va_list alocal, aremote;
397 >  struct dbuf_block *local_buf, *remote_buf;
398    dlink_node *ptr = NULL, *ptr_next = NULL;
399  
400 +  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
401 +
402    if (IsServer(from))
403 <    local_len = snprintf(local_buf, sizeof(local_buf), ":%s ",
360 <                        from->name);
403 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
404    else
405 <    local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
406 <                         from->name, from->username, from->host);
407 <  remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
365 <                        from->name);
366 <  uid_len = snprintf(uid_buf, sizeof(uid_buf), ":%s ", ID(from));
405 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
406 >
407 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
408  
409    va_start(alocal, pattern);
410    va_start(aremote, pattern);
411 <  va_start(auid, pattern);
412 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
413 <                           pattern, alocal);
373 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
374 <                            pattern, aremote);
375 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
376 <                         auid);
377 <  va_end(auid);
411 >  send_format(local_buf, pattern, alocal);
412 >  send_format(remote_buf, pattern, aremote);
413 >
414    va_end(aremote);
415    va_end(alocal);
416  
# Line 387 | Line 423 | sendto_channel_butone(struct Client *one
423  
424      assert(IsClient(target_p));
425  
426 <    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
426 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
427 >        (one && target_p->from == one->from))
428        continue;
429  
430 <    if (type != 0 && (ms->flags & type) == 0)
430 >    if (type && (ms->flags & type) == 0)
431        continue;
432  
433      if (MyConnect(target_p))
# Line 399 | Line 436 | sendto_channel_butone(struct Client *one
436        send_message_remote(target_p->from, from, remote_buf);
437      target_p->from->localClient->serial = current_serial;
438    }
439 +
440 +  dbuf_ref_free(local_buf);
441 +  dbuf_ref_free(remote_buf);
442   }
443  
444   /* sendto_server()
# Line 427 | Line 467 | sendto_server(struct Client *one,
467   {
468    va_list args;
469    dlink_node *ptr = NULL;
470 <  char buffer[IRCD_BUFSIZE];
471 <  int len = 0;
470 >  struct dbuf_block *buffer;
471 >
472 >  buffer = dbuf_alloc();
473  
474    va_start(args, format);
475 <  len = send_format(buffer, sizeof(buffer), format, args);
475 >  send_format(buffer, format, args);
476    va_end(args);
477  
478    DLINK_FOREACH(ptr, serv_list.head)
# Line 442 | Line 483 | sendto_server(struct Client *one,
483      if (IsDead(client_p))
484        continue;
485      /* check against 'one' */
486 <    if (one != NULL && (client_p == one->from))
486 >    if (one && (client_p == one->from))
487        continue;
488      /* check we have required capabs */
489      if ((client_p->localClient->caps & caps) != caps)
490        continue;
491      /* check we don't have any forbidden capabs */
492 <    if ((client_p->localClient->caps & nocaps) != 0)
492 >    if ((client_p->localClient->caps & nocaps))
493        continue;
494  
495 <    send_message(client_p, buffer, len);
495 >    send_message(client_p, buffer);
496    }
497 +
498 +  dbuf_ref_free(buffer);
499   }
500  
501   /* sendto_common_channels_local()
# Line 474 | Line 517 | sendto_common_channels_local(struct Clie
517    struct Channel *chptr;
518    struct Membership *ms;
519    struct Client *target_p;
520 <  char buffer[IRCD_BUFSIZE];
521 <  int len;
520 >  struct dbuf_block *buffer;
521 >
522 >  buffer = dbuf_alloc();
523  
524    va_start(args, pattern);
525 <  len = send_format(buffer, sizeof(buffer), pattern, args);
525 >  send_format(buffer, pattern, args);
526    va_end(args);
527  
528    ++current_serial;
# Line 486 | Line 530 | sendto_common_channels_local(struct Clie
530    DLINK_FOREACH(cptr, user->channel.head)
531    {
532      chptr = ((struct Membership *)cptr->data)->chptr;
489 –    assert(chptr != NULL);
533  
534      DLINK_FOREACH(uptr, chptr->members.head)
535      {
536        ms = uptr->data;
537        target_p = ms->client_p;
495 –      assert(target_p != NULL);
538  
539        if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
540            target_p->localClient->serial == current_serial)
# Line 502 | Line 544 | sendto_common_channels_local(struct Clie
544          continue;
545  
546        target_p->localClient->serial = current_serial;
547 <      send_message(target_p, buffer, len);
547 >      send_message(target_p, buffer);
548      }
549    }
550  
551    if (touser && MyConnect(user) && !IsDead(user) &&
552        user->localClient->serial != current_serial)
553      if (HasCap(user, cap) == cap)
554 <      send_message(user, buffer, len);
554 >      send_message(user, buffer);
555 >
556 >  dbuf_ref_free(buffer);
557   }
558  
559   /* sendto_channel_local()
# Line 527 | Line 571 | sendto_channel_local(unsigned int type,
571                       const char *pattern, ...)
572   {
573    va_list args;
530 –  char buffer[IRCD_BUFSIZE];
531 –  int len = 0;
574    dlink_node *ptr = NULL;
575 +  struct dbuf_block *buffer;
576 +
577 +  buffer = dbuf_alloc();
578  
579    va_start(args, pattern);
580 <  len = send_format(buffer, sizeof(buffer), pattern, args);
580 >  send_format(buffer, pattern, args);
581    va_end(args);
582  
583    DLINK_FOREACH(ptr, chptr->members.head)
# Line 540 | Line 585 | sendto_channel_local(unsigned int type,
585      struct Membership *ms = ptr->data;
586      struct Client *target_p = ms->client_p;
587  
588 <    if (type != 0 && (ms->flags & type) == 0)
588 >    if (type && (ms->flags & type) == 0)
589        continue;
590  
591      if (!MyConnect(target_p) || IsDefunct(target_p) ||
592          (nodeaf && HasUMode(target_p, UMODE_DEAF)))
593        continue;
594  
595 <    send_message(target_p, buffer, len);
595 >    send_message(target_p, buffer);
596    }
597 +
598 +  dbuf_ref_free(buffer);
599   }
600  
601   /* sendto_channel_local_butone()
# Line 568 | Line 615 | sendto_channel_local_butone(struct Clien
615                              struct Channel *chptr, const char *pattern, ...)
616   {
617    va_list args;
571 –  char buffer[IRCD_BUFSIZE];
572 –  int len = 0;
618    dlink_node *ptr = NULL;
619 +  struct dbuf_block *buffer;
620 +
621 +  buffer = dbuf_alloc();
622  
623    va_start(args, pattern);
624 <  len = send_format(buffer, sizeof(buffer), pattern, args);
624 >  send_format(buffer, pattern, args);
625    va_end(args);
626  
627    DLINK_FOREACH(ptr, chptr->members.head)
# Line 581 | Line 629 | sendto_channel_local_butone(struct Clien
629      struct Membership *ms = ptr->data;
630      struct Client *target_p = ms->client_p;
631  
632 <    if (type != 0 && (ms->flags & type) == 0)
632 >    if (type && (ms->flags & type) == 0)
633        continue;
634  
635 <    if (!MyConnect(target_p) || target_p == one ||
636 <        IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
635 >    if (!MyConnect(target_p) || (one && target_p == one->from))
636 >      continue;
637 >
638 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
639        continue;
640  
641      if (HasCap(target_p, cap) != cap)
642        continue;
643  
644 <    send_message(target_p, buffer, len);
644 >    send_message(target_p, buffer);
645    }
646 +
647 +  dbuf_ref_free(buffer);
648   }
649  
650   /*
# Line 629 | Line 681 | match_it(const struct Client *one, const
681   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
682   */
683   void
684 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
684 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
685                      int what, const char *pattern, ...)
686   {
687    va_list alocal, aremote;
688 <  struct Client *client_p;
689 <  dlink_node *ptr, *ptr_next;
690 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
691 <  int local_len = snprintf(local_buf, sizeof(local_buf), ":%s!%s@%s ",
692 <                           from->name, from->username, from->host);
693 <  int remote_len = snprintf(remote_buf, sizeof(remote_buf), ":%s ",
694 <                            from->name);
688 >  dlink_node *ptr = NULL, *ptr_next = NULL;
689 >  struct dbuf_block *local_buf, *remote_buf;
690 >
691 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
692 >
693 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
694 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
695  
696    va_start(alocal, pattern);
697    va_start(aremote, pattern);
698 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
699 <                           pattern, alocal);
648 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
649 <                            pattern, aremote);
698 >  send_format(local_buf, pattern, alocal);
699 >  send_format(remote_buf, pattern, aremote);
700    va_end(aremote);
701    va_end(alocal);
702  
703    /* scan the local clients */
704    DLINK_FOREACH(ptr, local_client_list.head)
705    {
706 <    client_p = ptr->data;
706 >    struct Client *client_p = ptr->data;
707  
708 <    if (client_p != one && !IsDefunct(client_p) &&
708 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
709          match_it(client_p, mask, what))
710 <      send_message(client_p, local_buf, local_len);
710 >      send_message(client_p, local_buf);
711    }
712  
713    /* Now scan servers */
714    DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
715    {
716 <    client_p = ptr->data;
716 >    struct Client *client_p = ptr->data;
717  
718      /*
719       * The old code looped through every client on the
# Line 689 | Line 739 | sendto_match_butone(struct Client *one,
739       * server deal with it.
740       * -wnder
741       */
742 <    if (client_p != one && !IsDefunct(client_p))
743 <      send_message_remote(client_p, from, remote_buf, remote_len);
742 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
743 >      send_message_remote(client_p, from, remote_buf);
744    }
745 +
746 +  dbuf_ref_free(local_buf);
747 +  dbuf_ref_free(remote_buf);
748   }
749  
750   /* sendto_match_servs()
# Line 709 | Line 762 | sendto_match_servs(struct Client *source
762   {
763    va_list args;
764    dlink_node *ptr = NULL;
765 <  char buff_suid[IRCD_BUFSIZE];
713 <  char buff_name[IRCD_BUFSIZE];
714 <  int len_suid = 0;
715 <  int len_name = 0;
765 >  struct dbuf_block *buff_suid;
766  
767 <  va_start(args, pattern);
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);
767 >  buff_suid = dbuf_alloc();
768  
769    va_start(args, pattern);
770 <  len_name = snprintf(buff_name, sizeof(buff_name), ":%s ", source_p->name);
771 <  len_name += send_format(&buff_name[len_name], sizeof(buff_name) - len_name,
726 <                          pattern, args);
770 >  dbuf_put_fmt(buff_suid, ":%s ", source_p->id);
771 >  dbuf_put_args(buff_suid, pattern, args);
772    va_end(args);
773  
774    ++current_serial;
# Line 750 | Line 795 | sendto_match_servs(struct Client *source
795        if (!IsCapable(target_p->from, cap))
796          continue;
797  
798 <      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);
798 >      send_message_remote(target_p->from, source_p, buff_suid);
799      }
800    }
801 +
802 +  dbuf_ref_free(buff_suid);
803   }
804  
805   /* sendto_anywhere()
# Line 773 | Line 817 | sendto_anywhere(struct Client *to, struc
817                  const char *pattern, ...)
818   {
819    va_list args;
820 <  char buffer[IRCD_BUFSIZE];
777 <  int len = 0;
820 >  struct dbuf_block *buffer = NULL;
821  
822    if (IsDead(to->from))
823      return;
824  
825 <  if (MyClient(to))
826 <  {
827 <    if (IsServer(from))
828 <      len = snprintf(buffer, sizeof(buffer), ":%s %s %s ",
829 <                     from->name, command, to->name);
787 <    else
788 <      len = snprintf(buffer, sizeof(buffer), ":%s!%s@%s %s %s ",
789 <                     from->name, from->username, from->host, command, to->name);
790 <  }
825 >  buffer = dbuf_alloc();
826 >
827 >  if (MyClient(to) && IsClient(from))
828 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
829 >                 from->host, command, to->name);
830    else
831 <    len = snprintf(buffer, sizeof(buffer), ":%s %s %s ",
832 <                   ID_or_name(from, to), command,
794 <                   ID_or_name(to, to));
831 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
832 >                 command, ID_or_name(to, to));
833  
834    va_start(args, pattern);
835 <  len += send_format(&buffer[len], sizeof(buffer) - len, pattern, args);
835 >  send_format(buffer, pattern, args);
836    va_end(args);
837  
838    if (MyClient(to))
839 <    send_message(to, buffer, len);
839 >    send_message(to, buffer);
840    else
841 <    send_message_remote(to, from, buffer, len);
841 >    send_message_remote(to, from, buffer);
842 >
843 >  dbuf_ref_free(buffer);
844   }
845  
846   /* sendto_realops_flags()
# Line 816 | Line 856 | sendto_realops_flags(unsigned int flags,
856   {
857    const char *ntype = NULL;
858    dlink_node *ptr = NULL;
859 <  char nbuf[IRCD_BUFSIZE];
859 >  char nbuf[IRCD_BUFSIZE] = "";
860    va_list args;
861  
862    va_start(args, pattern);
# Line 857 | Line 897 | sendto_realops_flags(unsigned int flags,
897    }
898   }
899  
860 – /* sendto_wallops_flags()
861 – *
862 – * inputs       - flag types of messages to show to real opers
863 – *              - client sending request
864 – *              - var args input message
865 – * output       - NONE
866 – * side effects - Send a wallops to local opers
867 – */
868 – void
869 – sendto_wallops_flags(unsigned int flags, struct Client *source_p,
870 –                     const char *pattern, ...)
871 – {
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 = snprintf(buffer, sizeof(buffer), ":%s!%s@%s WALLOPS :",
879 –                   source_p->name, source_p->username,
880 –                   source_p->host);
881 –  else
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);
887 –  va_end(args);
888 –
889 –  DLINK_FOREACH(ptr, oper_list.head)
890 –  {
891 –    struct Client *client_p = ptr->data;
892 –    assert(client_p->umodes & UMODE_OPER);
893 –
894 –    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
895 –      send_message(client_p, buffer, len);
896 –  }
897 – }
898 –
900   /* ts_warn()
901   *
902 < * inputs       - var args message
903 < * output       - NONE
904 < * side effects - Call sendto_realops_flags, with some flood checking
905 < *                (at most 5 warnings every 5 seconds)
902 > * inputs       - var args message
903 > * output       - NONE
904 > * side effects - Call sendto_realops_flags, with some flood checking
905 > *                (at most 5 warnings every 5 seconds)
906   */
907   void
908   sendto_realops_flags_ratelimited(const char *pattern, ...)
909   {
910    va_list args;
911 <  char buffer[IRCD_BUFSIZE];
911 >  char buffer[IRCD_BUFSIZE] = "";
912    static time_t last = 0;
913    static int warnings = 0;
914  
# Line 937 | Line 938 | sendto_realops_flags_ratelimited(const c
938    ilog(LOG_TYPE_IRCD, "%s", buffer);
939   }
940  
941 < /* kill_client()
941 > /* sendto_wallops_flags()
942   *
943 < * inputs       - client to send kill towards
944 < *              - pointer to client to kill
945 < *              - reason for kill
946 < * output       - NONE
947 < * side effects - NONE
943 > * inputs       - flag types of messages to show to real opers
944 > *              - client sending request
945 > *              - var args input message
946 > * output       - NONE
947 > * side effects - Send a wallops to local opers
948   */
949   void
950 < kill_client(struct Client *client_p, struct Client *diedie,
951 <            const char *pattern, ...)
950 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
951 >                     const char *pattern, ...)
952   {
953 +  dlink_node *ptr = NULL;
954    va_list args;
955 <  char buffer[IRCD_BUFSIZE];
954 <  int len;
955 <
956 <  if (client_p->from != NULL)
957 <    client_p = client_p->from;
958 <  if (IsDead(client_p))
959 <    return;
955 >  struct dbuf_block *buffer;
956  
957 <  len = snprintf(buffer, sizeof(buffer), ":%s KILL %s :",
962 <                 ID_or_name(&me, client_p),
963 <                 ID_or_name(diedie, client_p));
957 >  buffer = dbuf_alloc();
958  
959 <  va_start(args, pattern);
960 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
961 <  va_end(args);
962 <
969 <  send_message(client_p, buffer, len);
970 < }
971 <
972 < /* kill_client_ll_serv_butone()
973 < *
974 < * inputs       - pointer to client to not send to
975 < *              - pointer to client to kill
976 < * output       - NONE
977 < * side effects - Send a KILL for the given client
978 < *                message to all connected servers
979 < *                except the client 'one'. Also deal with
980 < *                client being unknown to leaf, as in lazylink...
981 < */
982 < void
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 <  dlink_node *ptr = NULL;
989 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
990 <  int len_uid = 0, len_nick = 0;
991 <
992 <  if (HasID(source_p))
993 <  {
994 <    have_uid = 1;
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 <  }
959 >  if (IsClient(source_p))
960 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
961 >  else
962 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
963  
964    va_start(args, pattern);
965 <  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);
965 >  send_format(buffer, pattern, args);
966    va_end(args);
967  
968 <  DLINK_FOREACH(ptr, serv_list.head)
968 >  DLINK_FOREACH(ptr, oper_list.head)
969    {
970      struct Client *client_p = ptr->data;
971 +    assert(client_p->umodes & UMODE_OPER);
972  
973 <    if (one != NULL && (client_p == one->from))
974 <      continue;
1014 <    if (IsDefunct(client_p))
1015 <      continue;
1016 <
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);
973 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
974 >      send_message(client_p, buffer);
975    }
976 +
977 +  dbuf_ref_free(buffer);
978   }

Diff Legend

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