ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 4890
Committed: Wed Nov 19 17:10:46 2014 UTC (11 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 25501 byte(s)
Log Message:
- Style corrections

File Contents

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

Properties

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