ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 3347
Committed: Sun Apr 20 14:03:06 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 25864 byte(s)
Log Message:
- Moved files:
  s_user.c -> user.c
  s_misc.c -> misc.c
  s_serv.c -> server.c

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

Properties

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