ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 7945
Committed: Wed Feb 22 19:46:22 2017 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 23277 byte(s)
Error occurred while calculating annotation data.
Log Message:
- send.c:sendto_channel_butone(): split long if statement

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2017 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file send.c
23 * \brief Functions for sending messages.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "send.h"
30 #include "channel.h"
31 #include "client.h"
32 #include "dbuf.h"
33 #include "irc_string.h"
34 #include "ircd.h"
35 #include "s_bsd.h"
36 #include "server.h"
37 #include "conf_class.h"
38 #include "log.h"
39
40
41 static uintmax_t current_serial;
42
43
44 /* send_format()
45 *
46 * inputs
47 * - buffer
48 * - format pattern to use
49 * - var args
50 * output - number of bytes formatted output
51 * side effects - modifies sendbuf
52 */
53 static void
54 send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
55 {
56 /*
57 * from rfc1459
58 *
59 * IRC messages are always lines of characters terminated with a CR-LF
60 * (Carriage Return - Line Feed) pair, and these messages shall not
61 * exceed 512 characters in length, counting all characters
62 * including the trailing CR-LF.
63 * Thus, there are 510 characters maximum allowed
64 * for the command and its parameters. There is no provision for
65 * continuation message lines. See section 7 for more details about
66 * current implementations.
67 */
68 dbuf_put_args(buffer, pattern, args);
69
70 if (buffer->size > IRCD_BUFSIZE - 2)
71 buffer->size = IRCD_BUFSIZE - 2;
72
73 buffer->data[buffer->size++] = '\r';
74 buffer->data[buffer->size++] = '\n';
75 }
76
77 /*
78 ** send_message
79 ** Internal utility which appends given buffer to the sockets
80 ** sendq.
81 */
82 static void
83 send_message(struct Client *to, struct dbuf_block *buf)
84 {
85 assert(!IsMe(to));
86 assert(to != &me);
87 assert(MyConnect(to));
88
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_SERVNOTICE, L_ALL, SEND_NOTICE,
93 "Max SendQ limit exceeded for %s: %zu > %u",
94 get_client_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 AddFlag(to, FLAGS_SENDQEX);
100
101 dead_link_on_write(to, 0);
102 return;
103 }
104
105 dbuf_add(&to->connection->buf_sendq, buf);
106
107 /*
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->connection->send.messages;
113 ++me.connection->send.messages;
114
115 send_queued_write(to);
116 }
117
118 /* send_message_remote()
119 *
120 * inputs - pointer to client from message is being sent
121 * - pointer to client to send to
122 * - pointer to buffer
123 * output - none
124 * side effects - Despite the function name, this only sends to directly
125 * connected clients.
126 *
127 */
128 static void
129 send_message_remote(struct Client *to, const struct Client *from, struct dbuf_block *buf)
130 {
131 assert(MyConnect(to));
132 assert(IsServer(to));
133 assert(!IsMe(to));
134 assert(to->from == to);
135
136 if (to == from->from)
137 {
138 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
139 "Send message to %s dropped from %s (Fake Dir)",
140 to->name, from->name);
141 return;
142 }
143
144 send_message(to, buf);
145 }
146
147 /*
148 ** sendq_unblocked
149 ** Called when a socket is ready for writing.
150 */
151 void
152 sendq_unblocked(fde_t *fd, void *data)
153 {
154 struct Client *const client_p = data;
155 assert(fd == &client_p->connection->fd);
156
157 DelFlag(client_p, FLAGS_BLOCKED);
158 send_queued_write(client_p);
159 }
160
161 /*
162 ** send_queued_write
163 ** This is called when there is a chance that some output would
164 ** be possible. This attempts to empty the send queue as far as
165 ** possible, and then if any data is left, a write is rescheduled.
166 */
167 void
168 send_queued_write(struct Client *to)
169 {
170 int retlen = 0;
171 int want_read = 0;
172
173 /*
174 ** Once socket is marked dead, we cannot start writing to it,
175 ** even if the error is removed...
176 */
177 if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
178 return; /* no use calling send() now */
179
180 /* Next, lets try to write some data */
181 if (dbuf_length(&to->connection->buf_sendq))
182 {
183 do
184 {
185 const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
186
187 if (tls_isusing(&to->connection->fd.ssl))
188 {
189 retlen = tls_write(&to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos,
190 first->size - to->connection->buf_sendq.pos, &want_read);
191
192 if (want_read)
193 return; /* Retry later, don't register for write events */
194 }
195 else
196 retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos,
197 first->size - to->connection->buf_sendq.pos, 0);
198
199 if (retlen <= 0)
200 break;
201
202 dbuf_delete(&to->connection->buf_sendq, retlen);
203
204 /* We have some data written .. update counters */
205 to->connection->send.bytes += retlen;
206 me.connection->send.bytes += retlen;
207 } while (dbuf_length(&to->connection->buf_sendq));
208
209 if (retlen < 0 && ignoreErrno(errno))
210 {
211 AddFlag(to, FLAGS_BLOCKED);
212
213 /* we have a non-fatal error, reschedule a write */
214 comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
215 }
216 else if (retlen <= 0)
217 {
218 dead_link_on_write(to, errno);
219 return;
220 }
221 }
222 }
223
224 /* send_queued_all()
225 *
226 * input - NONE
227 * output - NONE
228 * side effects - try to flush sendq of each client
229 */
230 void
231 send_queued_all(void)
232 {
233 dlink_node *node = NULL;
234
235 /* Servers are processed first, mainly because this can generate
236 * a notice to opers, which is to be delivered by this function.
237 */
238 DLINK_FOREACH(node, local_server_list.head)
239 send_queued_write(node->data);
240
241 DLINK_FOREACH(node, unknown_list.head)
242 send_queued_write(node->data);
243
244 DLINK_FOREACH(node, local_client_list.head)
245 send_queued_write(node->data);
246
247 /* NOTE: This can still put clients on aborted_list; unfortunately,
248 * exit_aborted_clients takes precedence over send_queued_all,
249 * because exiting clients can generate server/oper traffic.
250 * The easiest approach is dealing with aborted clients in the next I/O lap.
251 * -adx
252 */
253 }
254
255 /* sendto_one()
256 *
257 * inputs - pointer to destination client
258 * - var args message
259 * output - NONE
260 * side effects - send message to single client
261 */
262 void
263 sendto_one(struct Client *to, const char *pattern, ...)
264 {
265 va_list args;
266 struct dbuf_block *buffer = NULL;
267
268 if (IsDead(to->from))
269 return; /* This socket has already been marked as dead */
270
271 buffer = dbuf_alloc();
272
273 va_start(args, pattern);
274 send_format(buffer, pattern, args);
275 va_end(args);
276
277 send_message(to->from, buffer);
278
279 dbuf_ref_free(buffer);
280 }
281
282 void
283 sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
284 {
285 struct dbuf_block *buffer = NULL;
286 const char *dest = NULL, *numstr = NULL;
287 va_list args;
288
289 if (IsDead(to->from))
290 return;
291
292 dest = ID_or_name(to, to);
293
294 if (EmptyString(dest))
295 dest = "*";
296
297 buffer = dbuf_alloc();
298
299 dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
300
301 va_start(args, numeric);
302
303 if (numeric & SND_EXPLICIT)
304 numstr = va_arg(args, const char *);
305 else
306 numstr = numeric_form(numeric);
307
308 send_format(buffer, numstr, args);
309 va_end(args);
310
311 send_message(to->from, buffer);
312
313 dbuf_ref_free(buffer);
314 }
315
316 void
317 sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
318 {
319 struct dbuf_block *buffer = NULL;
320 const char *dest = NULL;
321 va_list args;
322
323 if (IsDead(to->from))
324 return;
325
326 dest = ID_or_name(to, to);
327
328 if (EmptyString(dest))
329 dest = "*";
330
331 buffer = dbuf_alloc();
332
333 dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
334
335 va_start(args, pattern);
336 send_format(buffer, pattern, args);
337 va_end(args);
338
339 send_message(to->from, buffer);
340
341 dbuf_ref_free(buffer);
342 }
343
344 /* sendto_channel_butone()
345 *
346 * inputs - pointer to client(server) to NOT send message to
347 * - pointer to client that is sending this message
348 * - pointer to channel being sent to
349 * - vargs message
350 * output - NONE
351 * side effects - message as given is sent to given channel members.
352 *
353 * WARNING - +D clients are ignored
354 */
355 void
356 sendto_channel_butone(struct Client *one, const struct Client *from,
357 struct Channel *chptr, unsigned int type,
358 const char *pattern, ...)
359 {
360 va_list alocal, aremote;
361 struct dbuf_block *local_buf, *remote_buf;
362 dlink_node *node = NULL;
363
364 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
365
366 if (IsClient(from))
367 dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
368 else
369 dbuf_put_fmt(local_buf, ":%s ", from->name);
370
371 dbuf_put_fmt(remote_buf, ":%s ", from->id);
372
373 va_start(alocal, pattern);
374 va_start(aremote, pattern);
375 send_format(local_buf, pattern, alocal);
376 send_format(remote_buf, pattern, aremote);
377
378 va_end(aremote);
379 va_end(alocal);
380
381 ++current_serial;
382
383 DLINK_FOREACH(node, chptr->members.head)
384 {
385 struct Membership *member = node->data;
386 struct Client *target_p = member->client_p;
387
388 assert(IsClient(target_p));
389
390 if (IsDefunct(target_p->from))
391 continue;
392
393 if (one && (target_p->from == one->from))
394 continue;
395
396 if (type && (member->flags & type) == 0)
397 continue;
398
399 if (HasUMode(target_p, UMODE_DEAF))
400 continue;
401
402 if (MyConnect(target_p))
403 send_message(target_p, local_buf);
404 else if (target_p->from->connection->serial != current_serial)
405 send_message_remote(target_p->from, from, remote_buf);
406
407 target_p->from->connection->serial = current_serial;
408 }
409
410 dbuf_ref_free(local_buf);
411 dbuf_ref_free(remote_buf);
412 }
413
414 /* sendto_server()
415 *
416 * inputs - pointer to client to NOT send to
417 * - pointer to channel
418 * - caps or'd together which must ALL be present
419 * - caps or'd together which must ALL NOT be present
420 * - printf style format string
421 * - args to format string
422 * output - NONE
423 * side effects - Send a message to all connected servers, except the
424 * client 'one' (if non-NULL), as long as the servers
425 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
426 *
427 * This function was written in an attempt to merge together the other
428 * billion sendto_*serv*() functions, which sprung up with capabs,
429 * lazylinks, uids, etc.
430 * -davidt
431 */
432 void
433 sendto_server(const struct Client *one,
434 const unsigned int caps,
435 const unsigned int nocaps,
436 const char *format, ...)
437 {
438 va_list args;
439 dlink_node *node = NULL;
440 struct dbuf_block *buffer = dbuf_alloc();
441
442 va_start(args, format);
443 send_format(buffer, format, args);
444 va_end(args);
445
446 DLINK_FOREACH(node, local_server_list.head)
447 {
448 struct Client *client_p = node->data;
449
450 /* If dead already skip */
451 if (IsDead(client_p))
452 continue;
453
454 /* check against 'one' */
455 if (one && (client_p == one->from))
456 continue;
457
458 /* check we have required capabs */
459 if ((client_p->connection->caps & caps) != caps)
460 continue;
461
462 /* check we don't have any forbidden capabs */
463 if ((client_p->connection->caps & nocaps))
464 continue;
465
466 send_message(client_p, buffer);
467 }
468
469 dbuf_ref_free(buffer);
470 }
471
472 /* sendto_common_channels_local()
473 *
474 * inputs - pointer to client
475 * - pattern to send
476 * output - NONE
477 * side effects - Sends a message to all people on local server who are
478 * in same channel with user.
479 * used by m_nick.c and exit_one_client.
480 */
481 void
482 sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap,
483 unsigned int negcap, const char *pattern, ...)
484 {
485 va_list args;
486 dlink_node *uptr;
487 dlink_node *cptr;
488 struct Channel *chptr;
489 struct Membership *member;
490 struct Client *target_p;
491 struct dbuf_block *buffer = dbuf_alloc();
492
493 va_start(args, pattern);
494 send_format(buffer, pattern, args);
495 va_end(args);
496
497 ++current_serial;
498
499 DLINK_FOREACH(cptr, user->channel.head)
500 {
501 chptr = ((struct Membership *)cptr->data)->chptr;
502
503 DLINK_FOREACH(uptr, chptr->locmembers.head)
504 {
505 member = uptr->data;
506 target_p = member->client_p;
507
508 if (target_p == user || IsDefunct(target_p) ||
509 target_p->connection->serial == current_serial)
510 continue;
511
512 if (poscap && HasCap(target_p, poscap) != poscap)
513 continue;
514
515 if (negcap && HasCap(target_p, negcap))
516 continue;
517
518 target_p->connection->serial = current_serial;
519 send_message(target_p, buffer);
520 }
521 }
522
523 if (touser && MyConnect(user) && !IsDead(user) &&
524 user->connection->serial != current_serial)
525 if (HasCap(user, poscap) == poscap)
526 send_message(user, buffer);
527
528 dbuf_ref_free(buffer);
529 }
530
531 /*! \brief Send a message to members of a channel that are locally connected to this server.
532 * \param one Client to skip; can be NULL
533 * \param chptr Destination channel
534 * \param status Channel member status flags clients must have
535 * \param poscap Positive client capabilities flags (CAP)
536 * \param negcap Negative client capabilities flags (CAP)
537 * \param pattern Format string for command arguments
538 */
539 void
540 sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status,
541 unsigned int poscap, unsigned int negcap, const char *pattern, ...)
542 {
543 va_list args;
544 dlink_node *node = NULL;
545 struct dbuf_block *buffer = dbuf_alloc();
546
547 va_start(args, pattern);
548 send_format(buffer, pattern, args);
549 va_end(args);
550
551 DLINK_FOREACH(node, chptr->locmembers.head)
552 {
553 struct Membership *member = node->data;
554 struct Client *target_p = member->client_p;
555
556 if (IsDefunct(target_p))
557 continue;
558
559 if (one && target_p == one->from)
560 continue;
561
562 if (status && (member->flags & status) == 0)
563 continue;
564
565 if (poscap && HasCap(target_p, poscap) != poscap)
566 continue;
567
568 if (negcap && HasCap(target_p, negcap))
569 continue;
570
571 send_message(target_p, buffer);
572 }
573
574 dbuf_ref_free(buffer);
575 }
576
577 /*
578 ** match_it() and sendto_match_butone() ARE only used
579 ** to send a msg to all ppl on servers/hosts that match a specified mask
580 ** (used for enhanced PRIVMSGs) for opers
581 **
582 ** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
583 **
584 */
585
586 /* match_it()
587 *
588 * inputs - client pointer to match on
589 * - actual mask to match
590 * - what to match on, HOST or SERVER
591 * output - 1 or 0 if match or not
592 * side effects - NONE
593 */
594 static int
595 match_it(const struct Client *one, const char *mask, unsigned int what)
596 {
597 if (what == MATCH_HOST)
598 return !match(mask, one->host);
599
600 return !match(mask, one->servptr->name);
601 }
602
603 /* sendto_match_butone()
604 *
605 * Send to all clients which match the mask in a way defined on 'what';
606 * either by user hostname or user servername.
607 *
608 * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
609 */
610 void
611 sendto_match_butone(const struct Client *one, const struct Client *from,
612 const char *mask, int what, const char *pattern, ...)
613 {
614 va_list alocal, aremote;
615 dlink_node *node = NULL;
616 struct dbuf_block *local_buf, *remote_buf;
617
618 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
619
620 dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
621 dbuf_put_fmt(remote_buf, ":%s ", from->id);
622
623 va_start(alocal, pattern);
624 va_start(aremote, pattern);
625 send_format(local_buf, pattern, alocal);
626 send_format(remote_buf, pattern, aremote);
627 va_end(aremote);
628 va_end(alocal);
629
630 /* scan the local clients */
631 DLINK_FOREACH(node, local_client_list.head)
632 {
633 struct Client *client_p = node->data;
634
635 if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
636 match_it(client_p, mask, what))
637 send_message(client_p, local_buf);
638 }
639
640 /* Now scan servers */
641 DLINK_FOREACH(node, local_server_list.head)
642 {
643 struct Client *client_p = node->data;
644
645 /*
646 * The old code looped through every client on the
647 * network for each server to check if the
648 * server (client_p) has at least 1 client matching
649 * the mask, using something like:
650 *
651 * for (target_p = GlobalClientList; target_p; target_p = target_p->next)
652 * if (IsRegisteredUser(target_p) &&
653 * match_it(target_p, mask, what) &&
654 * (target_p->from == client_p))
655 * vsendto_prefix_one(client_p, from, pattern, args);
656 *
657 * That way, we wouldn't send the message to
658 * a server who didn't have a matching client.
659 * However, on a network such as EFNet, that
660 * code would have looped through about 50
661 * servers, and in each loop, loop through
662 * about 50k clients as well, calling match()
663 * in each nested loop. That is a very bad
664 * thing cpu wise - just send the message
665 * to every connected server and let that
666 * server deal with it.
667 * -wnder
668 */
669 if ((!one || client_p != one->from) && !IsDefunct(client_p))
670 send_message_remote(client_p, from, remote_buf);
671 }
672
673 dbuf_ref_free(local_buf);
674 dbuf_ref_free(remote_buf);
675 }
676
677 /* sendto_match_servs()
678 *
679 * inputs - source client
680 * - mask to send to
681 * - capab needed
682 * - data
683 * outputs - none
684 * side effects - data sent to servers matching with capab
685 */
686 void
687 sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
688 const char *pattern, ...)
689 {
690 va_list args;
691 dlink_node *node = NULL;
692 struct dbuf_block *buffer = dbuf_alloc();
693
694 dbuf_put_fmt(buffer, ":%s ", source_p->id);
695 va_start(args, pattern);
696 send_format(buffer, pattern, args);
697 va_end(args);
698
699 ++current_serial;
700
701 DLINK_FOREACH(node, global_server_list.head)
702 {
703 struct Client *target_p = node->data;
704
705 /* Do not attempt to send to ourselves, or the source */
706 if (IsMe(target_p) || target_p->from == source_p->from)
707 continue;
708
709 if (target_p->from->connection->serial == current_serial)
710 continue;
711
712 if (match(mask, target_p->name))
713 continue;
714
715 if (cap && IsCapable(target_p->from, cap) != cap)
716 continue;
717
718 target_p->from->connection->serial = current_serial;
719 send_message_remote(target_p->from, source_p, buffer);
720 }
721
722 dbuf_ref_free(buffer);
723 }
724
725 /* sendto_anywhere()
726 *
727 * inputs - pointer to dest client
728 * - pointer to from client
729 * - varags
730 * output - NONE
731 * side effects - less efficient than sendto_remote and sendto_one
732 * but useful when one does not know where target "lives"
733 */
734 void
735 sendto_anywhere(struct Client *to, const struct Client *from,
736 const char *command,
737 const char *pattern, ...)
738 {
739 va_list args;
740 struct dbuf_block *buffer = NULL;
741
742 if (IsDead(to->from))
743 return;
744
745 buffer = dbuf_alloc();
746
747 if (MyClient(to) && IsClient(from))
748 dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
749 from->host, command, to->name);
750 else
751 dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
752 command, ID_or_name(to, to));
753
754 va_start(args, pattern);
755 send_format(buffer, pattern, args);
756 va_end(args);
757
758 if (MyConnect(to))
759 send_message(to, buffer);
760 else
761 send_message_remote(to->from, from, buffer);
762
763 dbuf_ref_free(buffer);
764 }
765
766 /* sendto_realops_flags()
767 *
768 * inputs - flag types of messages to show to real opers
769 * - flag indicating opers/admins
770 * - var args input message
771 * output - NONE
772 * side effects - Send to *local* ops only but NOT +s nonopers.
773 */
774 void
775 sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
776 {
777 const char *ntype = NULL;
778 dlink_node *node = NULL;
779 char nbuf[IRCD_BUFSIZE] = "";
780 va_list args;
781
782 va_start(args, pattern);
783 vsnprintf(nbuf, sizeof(nbuf), pattern, args);
784 va_end(args);
785
786 switch (type)
787 {
788 case SEND_NOTICE:
789 ntype = "Notice";
790 break;
791 case SEND_GLOBAL:
792 ntype = "Global";
793 break;
794 case SEND_LOCOPS:
795 ntype = "LocOps";
796 break;
797 default:
798 assert(0);
799 }
800
801 DLINK_FOREACH(node, oper_list.head)
802 {
803 struct Client *client_p = node->data;
804 assert(HasUMode(client_p, UMODE_OPER));
805
806 /*
807 * If we're sending it to opers and they're an admin, skip.
808 * If we're sending it to admins, and they're not, skip.
809 */
810 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
811 ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
812 continue;
813
814 if (HasUMode(client_p, flags))
815 sendto_one_notice(client_p, &me, ":*** %s -- %s", ntype, nbuf);
816 }
817 }
818
819 /* ts_warn()
820 *
821 * inputs - var args message
822 * output - NONE
823 * side effects - Call sendto_realops_flags, with some flood checking
824 * (at most 5 warnings every 5 seconds)
825 */
826 void
827 sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
828 {
829 va_list args;
830 char buffer[IRCD_BUFSIZE] = "";
831
832 if ((CurrentTime - *rate) < 20)
833 return;
834
835 *rate = CurrentTime;
836
837 va_start(args, pattern);
838 vsnprintf(buffer, sizeof(buffer), pattern, args);
839 va_end(args);
840
841 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
842 ilog(LOG_TYPE_IRCD, "%s", buffer);
843 }
844
845 /* sendto_wallops_flags()
846 *
847 * inputs - flag types of messages to show to real opers
848 * - client sending request
849 * - var args input message
850 * output - NONE
851 * side effects - Send a wallops to local opers
852 */
853 void
854 sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
855 const char *pattern, ...)
856 {
857 dlink_node *node = NULL;
858 va_list args;
859 struct dbuf_block *buffer = dbuf_alloc();
860
861 if (IsClient(source_p))
862 dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
863 else
864 dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
865
866 va_start(args, pattern);
867 send_format(buffer, pattern, args);
868 va_end(args);
869
870 DLINK_FOREACH(node, oper_list.head)
871 {
872 struct Client *client_p = node->data;
873 assert(client_p->umodes & UMODE_OPER);
874
875 if (HasUMode(client_p, flags) && !IsDefunct(client_p))
876 send_message(client_p, buffer);
877 }
878
879 dbuf_ref_free(buffer);
880 }

Properties

Name Value
svn:eol-style native
svn:keywords Id