ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 6782
Committed: Sun Nov 15 18:49:32 2015 UTC (9 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 23737 byte(s)
Log Message:
- Use the %ju conversion specifier for time_t and get rid of these non-portable (unsigned long) casts; replace some uint64_t with uintmax_t

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 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, 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
172 /*
173 ** Once socket is marked dead, we cannot start writing to it,
174 ** even if the error is removed...
175 */
176 if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
177 return; /* no use calling send() now */
178
179 /* Next, lets try to write some data */
180 if (dbuf_length(&to->connection->buf_sendq))
181 {
182 do
183 {
184 const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
185
186 #ifdef HAVE_LIBCRYPTO
187 if (to->connection->fd.ssl)
188 {
189 retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos);
190
191 /* translate openssl error codes, sigh */
192 if (retlen < 0)
193 {
194 switch (SSL_get_error(to->connection->fd.ssl, retlen))
195 {
196 case SSL_ERROR_WANT_READ:
197 return; /* retry later, don't register for write events */
198 case SSL_ERROR_WANT_WRITE:
199 errno = EWOULDBLOCK;
200 case SSL_ERROR_SYSCALL:
201 break;
202 case SSL_ERROR_SSL:
203 if (errno == EAGAIN)
204 break;
205 default:
206 retlen = errno = 0; /* either an SSL-specific error or EOF */
207 }
208 }
209 }
210 else
211 #endif
212 retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
213
214 if (retlen <= 0)
215 break;
216
217 dbuf_delete(&to->connection->buf_sendq, retlen);
218
219 /* We have some data written .. update counters */
220 to->connection->send.bytes += retlen;
221 me.connection->send.bytes += retlen;
222 } while (dbuf_length(&to->connection->buf_sendq));
223
224 if (retlen < 0 && ignoreErrno(errno))
225 {
226 AddFlag(to, FLAGS_BLOCKED);
227
228 /* we have a non-fatal error, reschedule a write */
229 comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
230 sendq_unblocked, to, 0);
231 }
232 else if (retlen <= 0)
233 {
234 dead_link_on_write(to, errno);
235 return;
236 }
237 }
238 }
239
240 /* send_queued_all()
241 *
242 * input - NONE
243 * output - NONE
244 * side effects - try to flush sendq of each client
245 */
246 void
247 send_queued_all(void)
248 {
249 dlink_node *node = NULL;
250
251 /* Servers are processed first, mainly because this can generate
252 * a notice to opers, which is to be delivered by this function.
253 */
254 DLINK_FOREACH(node, local_server_list.head)
255 send_queued_write(node->data);
256
257 DLINK_FOREACH(node, unknown_list.head)
258 send_queued_write(node->data);
259
260 DLINK_FOREACH(node, local_client_list.head)
261 send_queued_write(node->data);
262
263 /* NOTE: This can still put clients on aborted_list; unfortunately,
264 * exit_aborted_clients takes precedence over send_queued_all,
265 * because exiting clients can generate server/oper traffic.
266 * The easiest approach is dealing with aborted clients in the next I/O lap.
267 * -adx
268 */
269 }
270
271 /* sendto_one()
272 *
273 * inputs - pointer to destination client
274 * - var args message
275 * output - NONE
276 * side effects - send message to single client
277 */
278 void
279 sendto_one(struct Client *to, const char *pattern, ...)
280 {
281 va_list args;
282 struct dbuf_block *buffer = NULL;
283
284 if (IsDead(to->from))
285 return; /* This socket has already been marked as dead */
286
287 buffer = dbuf_alloc();
288
289 va_start(args, pattern);
290 send_format(buffer, pattern, args);
291 va_end(args);
292
293 send_message(to->from, buffer);
294
295 dbuf_ref_free(buffer);
296 }
297
298 void
299 sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
300 {
301 struct dbuf_block *buffer = NULL;
302 const char *dest = NULL, *numstr = NULL;
303 va_list args;
304
305 if (IsDead(to->from))
306 return;
307
308 dest = ID_or_name(to, to);
309
310 if (EmptyString(dest))
311 dest = "*";
312
313 buffer = dbuf_alloc();
314
315 dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
316
317 va_start(args, numeric);
318
319 if (numeric & SND_EXPLICIT)
320 numstr = va_arg(args, const char *);
321 else
322 numstr = numeric_form(numeric);
323
324 send_format(buffer, numstr, args);
325 va_end(args);
326
327 send_message(to->from, buffer);
328
329 dbuf_ref_free(buffer);
330 }
331
332 void
333 sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
334 {
335 struct dbuf_block *buffer = NULL;
336 const char *dest = NULL;
337 va_list args;
338
339 if (IsDead(to->from))
340 return;
341
342 dest = ID_or_name(to, to);
343
344 if (EmptyString(dest))
345 dest = "*";
346
347 buffer = dbuf_alloc();
348
349 dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
350
351 va_start(args, pattern);
352 send_format(buffer, pattern, args);
353 va_end(args);
354
355 send_message(to->from, buffer);
356
357 dbuf_ref_free(buffer);
358 }
359
360 /* sendto_channel_butone()
361 *
362 * inputs - pointer to client(server) to NOT send message to
363 * - pointer to client that is sending this message
364 * - pointer to channel being sent to
365 * - vargs message
366 * output - NONE
367 * side effects - message as given is sent to given channel members.
368 *
369 * WARNING - +D clients are ignored
370 */
371 void
372 sendto_channel_butone(struct Client *one, struct Client *from,
373 struct Channel *chptr, unsigned int type,
374 const char *pattern, ...)
375 {
376 va_list alocal, aremote;
377 struct dbuf_block *local_buf, *remote_buf;
378 dlink_node *node = NULL;
379
380 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
381
382 if (IsClient(from))
383 dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
384 else
385 dbuf_put_fmt(local_buf, ":%s ", from->name);
386
387 dbuf_put_fmt(remote_buf, ":%s ", from->id);
388
389 va_start(alocal, pattern);
390 va_start(aremote, pattern);
391 send_format(local_buf, pattern, alocal);
392 send_format(remote_buf, pattern, aremote);
393
394 va_end(aremote);
395 va_end(alocal);
396
397 ++current_serial;
398
399 DLINK_FOREACH(node, chptr->members.head)
400 {
401 struct Membership *member = node->data;
402 struct Client *target_p = member->client_p;
403
404 assert(IsClient(target_p));
405
406 if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
407 (one && target_p->from == one->from))
408 continue;
409
410 if (type && (member->flags & type) == 0)
411 continue;
412
413 if (MyConnect(target_p))
414 send_message(target_p, local_buf);
415 else if (target_p->from->connection->serial != current_serial)
416 send_message_remote(target_p->from, from, remote_buf);
417
418 target_p->from->connection->serial = current_serial;
419 }
420
421 dbuf_ref_free(local_buf);
422 dbuf_ref_free(remote_buf);
423 }
424
425 /* sendto_server()
426 *
427 * inputs - pointer to client to NOT send to
428 * - pointer to channel
429 * - caps or'd together which must ALL be present
430 * - caps or'd together which must ALL NOT be present
431 * - printf style format string
432 * - args to format string
433 * output - NONE
434 * side effects - Send a message to all connected servers, except the
435 * client 'one' (if non-NULL), as long as the servers
436 * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
437 *
438 * This function was written in an attempt to merge together the other
439 * billion sendto_*serv*() functions, which sprung up with capabs,
440 * lazylinks, uids, etc.
441 * -davidt
442 */
443 void
444 sendto_server(struct Client *one,
445 const unsigned int caps,
446 const unsigned int nocaps,
447 const char *format, ...)
448 {
449 va_list args;
450 dlink_node *node = NULL;
451 struct dbuf_block *buffer = dbuf_alloc();
452
453 va_start(args, format);
454 send_format(buffer, format, args);
455 va_end(args);
456
457 DLINK_FOREACH(node, local_server_list.head)
458 {
459 struct Client *client_p = node->data;
460
461 /* If dead already skip */
462 if (IsDead(client_p))
463 continue;
464
465 /* check against 'one' */
466 if (one && (client_p == one->from))
467 continue;
468
469 /* check we have required capabs */
470 if ((client_p->connection->caps & caps) != caps)
471 continue;
472
473 /* check we don't have any forbidden capabs */
474 if ((client_p->connection->caps & nocaps))
475 continue;
476
477 send_message(client_p, buffer);
478 }
479
480 dbuf_ref_free(buffer);
481 }
482
483 /* sendto_common_channels_local()
484 *
485 * inputs - pointer to client
486 * - pattern to send
487 * output - NONE
488 * side effects - Sends a message to all people on local server who are
489 * in same channel with user.
490 * used by m_nick.c and exit_one_client.
491 */
492 void
493 sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap,
494 unsigned int negcap, const char *pattern, ...)
495 {
496 va_list args;
497 dlink_node *uptr;
498 dlink_node *cptr;
499 struct Channel *chptr;
500 struct Membership *member;
501 struct Client *target_p;
502 struct dbuf_block *buffer = dbuf_alloc();
503
504 va_start(args, pattern);
505 send_format(buffer, pattern, args);
506 va_end(args);
507
508 ++current_serial;
509
510 DLINK_FOREACH(cptr, user->channel.head)
511 {
512 chptr = ((struct Membership *)cptr->data)->chptr;
513
514 DLINK_FOREACH(uptr, chptr->locmembers.head)
515 {
516 member = uptr->data;
517 target_p = member->client_p;
518
519 if (target_p == user || IsDefunct(target_p) ||
520 target_p->connection->serial == current_serial)
521 continue;
522
523 if (poscap && HasCap(target_p, poscap) != poscap)
524 continue;
525
526 if (negcap && HasCap(target_p, negcap))
527 continue;
528
529 target_p->connection->serial = current_serial;
530 send_message(target_p, buffer);
531 }
532 }
533
534 if (touser && MyConnect(user) && !IsDead(user) &&
535 user->connection->serial != current_serial)
536 if (HasCap(user, poscap) == poscap)
537 send_message(user, buffer);
538
539 dbuf_ref_free(buffer);
540 }
541
542 /*! \brief Send a message to members of a channel that are locally connected to this server.
543 * \param one Client to skip; can be NULL
544 * \param chptr Destination channel
545 * \param status Channel member status flags clients must have
546 * \param poscap Positive client capabilities flags (CAP)
547 * \param negcap Negative client capabilities flags (CAP)
548 * \param pattern Format string for command arguments
549 */
550 void
551 sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status,
552 unsigned int poscap, unsigned int negcap, const char *pattern, ...)
553 {
554 va_list args;
555 dlink_node *node = NULL;
556 struct dbuf_block *buffer = dbuf_alloc();
557
558 va_start(args, pattern);
559 send_format(buffer, pattern, args);
560 va_end(args);
561
562 DLINK_FOREACH(node, chptr->locmembers.head)
563 {
564 struct Membership *member = node->data;
565 struct Client *target_p = member->client_p;
566
567 if (IsDefunct(target_p))
568 continue;
569
570 if (one && target_p == one->from)
571 continue;
572
573 if (status && (member->flags & status) == 0)
574 continue;
575
576 if (poscap && HasCap(target_p, poscap) != poscap)
577 continue;
578
579 if (negcap && HasCap(target_p, negcap))
580 continue;
581
582 send_message(target_p, buffer);
583 }
584
585 dbuf_ref_free(buffer);
586 }
587
588 /*
589 ** match_it() and sendto_match_butone() ARE only used
590 ** to send a msg to all ppl on servers/hosts that match a specified mask
591 ** (used for enhanced PRIVMSGs) for opers
592 **
593 ** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
594 **
595 */
596
597 /* match_it()
598 *
599 * inputs - client pointer to match on
600 * - actual mask to match
601 * - what to match on, HOST or SERVER
602 * output - 1 or 0 if match or not
603 * side effects - NONE
604 */
605 static int
606 match_it(const struct Client *one, const char *mask, unsigned int what)
607 {
608 if (what == MATCH_HOST)
609 return !match(mask, one->host);
610
611 return !match(mask, one->servptr->name);
612 }
613
614 /* sendto_match_butone()
615 *
616 * Send to all clients which match the mask in a way defined on 'what';
617 * either by user hostname or user servername.
618 *
619 * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
620 */
621 void
622 sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
623 int what, const char *pattern, ...)
624 {
625 va_list alocal, aremote;
626 dlink_node *node = NULL;
627 struct dbuf_block *local_buf, *remote_buf;
628
629 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
630
631 dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
632 dbuf_put_fmt(remote_buf, ":%s ", from->id);
633
634 va_start(alocal, pattern);
635 va_start(aremote, pattern);
636 send_format(local_buf, pattern, alocal);
637 send_format(remote_buf, pattern, aremote);
638 va_end(aremote);
639 va_end(alocal);
640
641 /* scan the local clients */
642 DLINK_FOREACH(node, local_client_list.head)
643 {
644 struct Client *client_p = node->data;
645
646 if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
647 match_it(client_p, mask, what))
648 send_message(client_p, local_buf);
649 }
650
651 /* Now scan servers */
652 DLINK_FOREACH(node, local_server_list.head)
653 {
654 struct Client *client_p = node->data;
655
656 /*
657 * The old code looped through every client on the
658 * network for each server to check if the
659 * server (client_p) has at least 1 client matching
660 * the mask, using something like:
661 *
662 * for (target_p = GlobalClientList; target_p; target_p = target_p->next)
663 * if (IsRegisteredUser(target_p) &&
664 * match_it(target_p, mask, what) &&
665 * (target_p->from == client_p))
666 * vsendto_prefix_one(client_p, from, pattern, args);
667 *
668 * That way, we wouldn't send the message to
669 * a server who didn't have a matching client.
670 * However, on a network such as EFNet, that
671 * code would have looped through about 50
672 * servers, and in each loop, loop through
673 * about 50k clients as well, calling match()
674 * in each nested loop. That is a very bad
675 * thing cpu wise - just send the message
676 * to every connected server and let that
677 * server deal with it.
678 * -wnder
679 */
680 if ((!one || client_p != one->from) && !IsDefunct(client_p))
681 send_message_remote(client_p, from, remote_buf);
682 }
683
684 dbuf_ref_free(local_buf);
685 dbuf_ref_free(remote_buf);
686 }
687
688 /* sendto_match_servs()
689 *
690 * inputs - source client
691 * - mask to send to
692 * - capab needed
693 * - data
694 * outputs - none
695 * side effects - data sent to servers matching with capab
696 */
697 void
698 sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
699 const char *pattern, ...)
700 {
701 va_list args;
702 dlink_node *node = NULL;
703 struct dbuf_block *buffer = dbuf_alloc();
704
705 dbuf_put_fmt(buffer, ":%s ", source_p->id);
706 va_start(args, pattern);
707 send_format(buffer, pattern, args);
708 va_end(args);
709
710 ++current_serial;
711
712 DLINK_FOREACH(node, global_server_list.head)
713 {
714 struct Client *target_p = node->data;
715
716 /* Do not attempt to send to ourselves, or the source */
717 if (IsMe(target_p) || target_p->from == source_p->from)
718 continue;
719
720 if (target_p->from->connection->serial == current_serial)
721 continue;
722
723 if (match(mask, target_p->name))
724 continue;
725
726 /*
727 * If we set the serial here, then we'll never do a
728 * match() again, if !IsCapable()
729 */
730 target_p->from->connection->serial = current_serial;
731
732 if (!IsCapable(target_p->from, cap))
733 continue;
734
735 send_message_remote(target_p->from, source_p, buffer);
736 }
737
738 dbuf_ref_free(buffer);
739 }
740
741 /* sendto_anywhere()
742 *
743 * inputs - pointer to dest client
744 * - pointer to from client
745 * - varags
746 * output - NONE
747 * side effects - less efficient than sendto_remote and sendto_one
748 * but useful when one does not know where target "lives"
749 */
750 void
751 sendto_anywhere(struct Client *to, struct Client *from,
752 const char *command,
753 const char *pattern, ...)
754 {
755 va_list args;
756 struct dbuf_block *buffer = NULL;
757
758 if (IsDead(to->from))
759 return;
760
761 buffer = dbuf_alloc();
762
763 if (MyClient(to) && IsClient(from))
764 dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
765 from->host, command, to->name);
766 else
767 dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
768 command, ID_or_name(to, to));
769
770 va_start(args, pattern);
771 send_format(buffer, pattern, args);
772 va_end(args);
773
774 if (MyConnect(to))
775 send_message(to, buffer);
776 else
777 send_message_remote(to->from, from, buffer);
778
779 dbuf_ref_free(buffer);
780 }
781
782 /* sendto_realops_flags()
783 *
784 * inputs - flag types of messages to show to real opers
785 * - flag indicating opers/admins
786 * - var args input message
787 * output - NONE
788 * side effects - Send to *local* ops only but NOT +s nonopers.
789 */
790 void
791 sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
792 {
793 const char *ntype = NULL;
794 dlink_node *node = NULL;
795 char nbuf[IRCD_BUFSIZE] = "";
796 va_list args;
797
798 va_start(args, pattern);
799 vsnprintf(nbuf, sizeof(nbuf), pattern, args);
800 va_end(args);
801
802 switch (type)
803 {
804 case SEND_NOTICE:
805 ntype = "Notice";
806 break;
807 case SEND_GLOBAL:
808 ntype = "Global";
809 break;
810 case SEND_LOCOPS:
811 ntype = "LocOps";
812 break;
813 default:
814 assert(0);
815 }
816
817 DLINK_FOREACH(node, oper_list.head)
818 {
819 struct Client *client_p = node->data;
820 assert(HasUMode(client_p, UMODE_OPER));
821
822 /*
823 * If we're sending it to opers and they're an admin, skip.
824 * If we're sending it to admins, and they're not, skip.
825 */
826 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
827 ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
828 continue;
829
830 if (HasUMode(client_p, flags))
831 sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
832 me.name, client_p->name, ntype, nbuf);
833 }
834 }
835
836 /* ts_warn()
837 *
838 * inputs - var args message
839 * output - NONE
840 * side effects - Call sendto_realops_flags, with some flood checking
841 * (at most 5 warnings every 5 seconds)
842 */
843 void
844 sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
845 {
846 va_list args;
847 char buffer[IRCD_BUFSIZE] = "";
848
849 if ((CurrentTime - *rate) < 20)
850 return;
851
852 *rate = CurrentTime;
853
854 va_start(args, pattern);
855 vsnprintf(buffer, sizeof(buffer), pattern, args);
856 va_end(args);
857
858 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
859 ilog(LOG_TYPE_IRCD, "%s", buffer);
860 }
861
862 /* sendto_wallops_flags()
863 *
864 * inputs - flag types of messages to show to real opers
865 * - client sending request
866 * - var args input message
867 * output - NONE
868 * side effects - Send a wallops to local opers
869 */
870 void
871 sendto_wallops_flags(unsigned int flags, struct Client *source_p,
872 const char *pattern, ...)
873 {
874 dlink_node *node = NULL;
875 va_list args;
876 struct dbuf_block *buffer = dbuf_alloc();
877
878 if (IsClient(source_p))
879 dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
880 else
881 dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
882
883 va_start(args, pattern);
884 send_format(buffer, pattern, args);
885 va_end(args);
886
887 DLINK_FOREACH(node, oper_list.head)
888 {
889 struct Client *client_p = node->data;
890 assert(client_p->umodes & UMODE_OPER);
891
892 if (HasUMode(client_p, flags) && !IsDefunct(client_p))
893 send_message(client_p, buffer);
894 }
895
896 dbuf_ref_free(buffer);
897 }

Properties

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