ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 6357
Committed: Mon Aug 17 16:38:13 2015 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 24495 byte(s)
Log Message:
- Make server_die() use enum; minor cleanups here and there

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1997-2015 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file send.c
23     * \brief Functions for sending messages.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #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 michael 3347 #include "server.h"
37 michael 5035 #include "conf_class.h"
38 michael 1309 #include "log.h"
39 adx 30
40    
41 michael 4780 static uint64_t current_serial;
42 adx 30
43    
44     /* send_format()
45     *
46 michael 3120 * inputs
47     * - buffer
48 adx 30 * - format pattern to use
49     * - var args
50     * output - number of bytes formatted output
51     * side effects - modifies sendbuf
52     */
53 michael 3107 static void
54     send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
55 adx 30 {
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 michael 2638 * exceed 512 characters in length, counting all characters
62 adx 30 * 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 michael 3107 dbuf_put_args(buffer, pattern, args);
69 adx 30
70 michael 4622 if (buffer->size > IRCD_BUFSIZE - 2)
71     buffer->size = IRCD_BUFSIZE - 2;
72 michael 3107
73     buffer->data[buffer->size++] = '\r';
74     buffer->data[buffer->size++] = '\n';
75 adx 30 }
76    
77     /*
78     ** send_message
79     ** Internal utility which appends given buffer to the sockets
80     ** sendq.
81     */
82     static void
83 michael 3107 send_message(struct Client *to, struct dbuf_block *buf)
84 adx 30 {
85 michael 439 assert(!IsMe(to));
86 michael 438 assert(to != &me);
87 michael 4803 assert(MyConnect(to));
88 adx 30
89 michael 4588 if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs))
90 adx 30 {
91     if (IsServer(to))
92 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
93 michael 1761 "Max SendQ limit exceeded for %s: %lu > %u",
94 adx 30 get_client_name(to, HIDE_IP),
95 michael 4588 (unsigned long)(dbuf_length(&to->connection->buf_sendq) + buf->size),
96     get_sendq(&to->connection->confs));
97 michael 4890
98 adx 30 if (IsClient(to))
99 michael 6313 AddFlag(to, FLAGS_SENDQEX);
100 michael 3215
101 adx 30 dead_link_on_write(to, 0);
102     return;
103     }
104 michael 2638
105 michael 4588 dbuf_add(&to->connection->buf_sendq, buf);
106 adx 30
107     /*
108 michael 3215 * 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 adx 30 */
112 michael 4588 ++to->connection->send.messages;
113     ++me.connection->send.messages;
114 adx 30
115 michael 2881 send_queued_write(to);
116 adx 30 }
117    
118     /* send_message_remote()
119     *
120     * inputs - pointer to client from message is being sent
121     * - pointer to client to send to
122 michael 3120 * - pointer to buffer
123 adx 30 * output - none
124     * side effects - Despite the function name, this only sends to directly
125     * connected clients.
126 michael 2916 *
127 adx 30 */
128     static void
129 michael 3107 send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
130 adx 30 {
131 michael 4803 assert(MyConnect(to));
132 michael 4931 assert(IsServer(to));
133 michael 4923 assert(!IsMe(to));
134     assert(to->from == to);
135 michael 2793
136 michael 4931 if (to == from->from)
137 adx 30 {
138 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
139 michael 4923 "Send message to %s dropped from %s (Fake Dir)",
140     to->name, from->name);
141 adx 30 return;
142 michael 2638 }
143 adx 30
144 michael 3107 send_message(to, buf);
145 adx 30 }
146    
147     /*
148     ** sendq_unblocked
149     ** Called when a socket is ready for writing.
150     */
151     void
152 michael 4461 sendq_unblocked(fde_t *fd, void *data)
153 adx 30 {
154 michael 4995 struct Client *const client_p = data;
155 michael 4588 assert(fd == &client_p->connection->fd);
156 michael 3312
157     DelFlag(client_p, FLAGS_BLOCKED);
158 michael 2881 send_queued_write(client_p);
159 adx 30 }
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 michael 3311 int retlen = 0;
171 adx 30
172     /*
173 michael 3311 ** Once socket is marked dead, we cannot start writing to it,
174     ** even if the error is removed...
175 adx 30 */
176 michael 3312 if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
177 michael 3311 return; /* no use calling send() now */
178 adx 30
179 michael 3311 /* Next, lets try to write some data */
180 michael 4588 if (dbuf_length(&to->connection->buf_sendq))
181 adx 30 {
182 michael 3311 do
183     {
184 michael 6357 const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
185 adx 30
186 michael 3311 #ifdef HAVE_LIBCRYPTO
187 michael 4588 if (to->connection->fd.ssl)
188 michael 3311 {
189 michael 4588 retlen = SSL_write(to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos);
190 michael 3241
191 michael 3311 /* translate openssl error codes, sigh */
192     if (retlen < 0)
193     {
194 michael 4588 switch (SSL_get_error(to->connection->fd.ssl, retlen))
195 michael 3311 {
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 michael 4588 retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
213 michael 3241
214 michael 3311 if (retlen <= 0)
215     break;
216 michael 3241
217 michael 4588 dbuf_delete(&to->connection->buf_sendq, retlen);
218 adx 30
219 michael 3311 /* We have some data written .. update counters */
220 michael 4588 to->connection->send.bytes += retlen;
221     me.connection->send.bytes += retlen;
222     } while (dbuf_length(&to->connection->buf_sendq));
223 adx 30
224 michael 3335 if (retlen < 0 && ignoreErrno(errno))
225 michael 3311 {
226 michael 3312 AddFlag(to, FLAGS_BLOCKED);
227 michael 3335
228 michael 3311 /* we have a non-fatal error, reschedule a write */
229 michael 4588 comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
230 michael 4461 sendq_unblocked, to, 0);
231 michael 3311 }
232     else if (retlen <= 0)
233     {
234     dead_link_on_write(to, errno);
235     return;
236     }
237 adx 30 }
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 michael 4815 dlink_node *node = NULL;
250 adx 30
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 michael 4815 DLINK_FOREACH(node, local_server_list.head)
255     send_queued_write(node->data);
256 adx 30
257 michael 4815 DLINK_FOREACH(node, unknown_list.head)
258     send_queued_write(node->data);
259 adx 30
260 michael 4815 DLINK_FOREACH(node, local_client_list.head)
261     send_queued_write(node->data);
262 adx 30
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 michael 3189 struct dbuf_block *buffer = NULL;
283 adx 30
284 michael 3189 if (IsDead(to->from))
285 michael 3107 return; /* This socket has already been marked as dead */
286 adx 30
287 michael 3107 buffer = dbuf_alloc();
288    
289 adx 30 va_start(args, pattern);
290 michael 3107 send_format(buffer, pattern, args);
291 adx 30 va_end(args);
292    
293 michael 3189 send_message(to->from, buffer);
294 michael 3107
295     dbuf_ref_free(buffer);
296 adx 30 }
297    
298 michael 3109 void
299     sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
300     {
301 michael 3189 struct dbuf_block *buffer = NULL;
302 michael 3573 const char *dest = NULL, *numstr = NULL;
303 michael 3109 va_list args;
304    
305 michael 3189 if (IsDead(to->from))
306 michael 3109 return;
307    
308     dest = ID_or_name(to, to);
309 michael 3335
310 michael 3109 if (EmptyString(dest))
311     dest = "*";
312    
313     buffer = dbuf_alloc();
314    
315 michael 3573 dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
316 michael 3109
317     va_start(args, numeric);
318 michael 3573
319     if (numeric & SND_EXPLICIT)
320     numstr = va_arg(args, const char *);
321     else
322     numstr = numeric_form(numeric);
323 michael 4791
324 michael 3573 send_format(buffer, numstr, args);
325 michael 3109 va_end(args);
326    
327 michael 3189 send_message(to->from, buffer);
328 michael 3109
329     dbuf_ref_free(buffer);
330     }
331    
332 michael 3110 void
333     sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
334     {
335 michael 3189 struct dbuf_block *buffer = NULL;
336     const char *dest = NULL;
337 michael 3110 va_list args;
338    
339 michael 3189 if (IsDead(to->from))
340 michael 3110 return;
341    
342     dest = ID_or_name(to, to);
343 michael 3335
344 michael 3110 if (EmptyString(dest))
345     dest = "*";
346    
347     buffer = dbuf_alloc();
348    
349 michael 3113 dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
350 michael 3110
351     va_start(args, pattern);
352     send_format(buffer, pattern, args);
353     va_end(args);
354    
355 michael 3189 send_message(to->from, buffer);
356 michael 3110
357     dbuf_ref_free(buffer);
358     }
359    
360 adx 30 /* 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 michael 1479 struct Channel *chptr, unsigned int type,
374 adx 30 const char *pattern, ...)
375     {
376 michael 3136 va_list alocal, aremote;
377     struct dbuf_block *local_buf, *remote_buf;
378 michael 4925 dlink_node *node = NULL;
379 adx 30
380 michael 3136 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
381 michael 3107
382 michael 3805 if (IsClient(from))
383     dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
384     else
385 michael 3113 dbuf_put_fmt(local_buf, ":%s ", from->name);
386 adx 30
387 michael 3186 dbuf_put_fmt(remote_buf, ":%s ", from->id);
388 michael 3107
389 adx 285 va_start(alocal, pattern);
390     va_start(aremote, pattern);
391 michael 3107 send_format(local_buf, pattern, alocal);
392     send_format(remote_buf, pattern, aremote);
393 michael 3136
394 adx 285 va_end(aremote);
395     va_end(alocal);
396 adx 30
397     ++current_serial;
398    
399 michael 4925 DLINK_FOREACH(node, chptr->members.head)
400 adx 30 {
401 michael 4815 struct Membership *member = node->data;
402     struct Client *target_p = member->client_p;
403 adx 30
404 michael 1078 assert(IsClient(target_p));
405    
406 michael 3164 if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
407     (one && target_p->from == one->from))
408 adx 30 continue;
409    
410 michael 4815 if (type && (member->flags & type) == 0)
411 michael 1479 continue;
412    
413 michael 1078 if (MyConnect(target_p))
414 michael 3103 send_message(target_p, local_buf);
415 michael 4588 else if (target_p->from->connection->serial != current_serial)
416 michael 3103 send_message_remote(target_p->from, from, remote_buf);
417 michael 4890
418 michael 4588 target_p->from->connection->serial = current_serial;
419 adx 30 }
420 michael 3107
421     dbuf_ref_free(local_buf);
422     dbuf_ref_free(remote_buf);
423 adx 30 }
424    
425     /* sendto_server()
426 michael 2916 *
427 adx 30 * inputs - pointer to client to NOT send to
428 db 939 * - pointer to channel
429 adx 30 * - 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 michael 2916 *
438 adx 30 * 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 michael 2638 void
444 michael 1474 sendto_server(struct Client *one,
445 michael 1015 const unsigned int caps,
446     const unsigned int nocaps,
447 adx 30 const char *format, ...)
448     {
449     va_list args;
450 michael 4815 dlink_node *node = NULL;
451     struct dbuf_block *buffer = dbuf_alloc();
452 adx 30
453     va_start(args, format);
454 michael 3107 send_format(buffer, format, args);
455 adx 30 va_end(args);
456    
457 michael 4815 DLINK_FOREACH(node, local_server_list.head)
458 adx 30 {
459 michael 4815 struct Client *client_p = node->data;
460 adx 30
461     /* If dead already skip */
462     if (IsDead(client_p))
463     continue;
464 michael 4890
465 adx 30 /* check against 'one' */
466 michael 3243 if (one && (client_p == one->from))
467 adx 30 continue;
468 michael 4890
469 adx 30 /* check we have required capabs */
470 michael 4588 if ((client_p->connection->caps & caps) != caps)
471 adx 30 continue;
472 michael 4890
473 adx 30 /* check we don't have any forbidden capabs */
474 michael 4588 if ((client_p->connection->caps & nocaps))
475 adx 30 continue;
476    
477 michael 3107 send_message(client_p, buffer);
478 adx 30 }
479 michael 3107
480     dbuf_ref_free(buffer);
481 adx 30 }
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 michael 2916 * in same channel with user.
490 adx 30 * used by m_nick.c and exit_one_client.
491     */
492     void
493 michael 1734 sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
494 adx 30 const char *pattern, ...)
495     {
496     va_list args;
497     dlink_node *uptr;
498     dlink_node *cptr;
499     struct Channel *chptr;
500 michael 4815 struct Membership *member;
501 adx 30 struct Client *target_p;
502 michael 4815 struct dbuf_block *buffer = dbuf_alloc();
503 adx 30
504     va_start(args, pattern);
505 michael 3107 send_format(buffer, pattern, args);
506 adx 30 va_end(args);
507    
508     ++current_serial;
509    
510     DLINK_FOREACH(cptr, user->channel.head)
511     {
512 michael 2638 chptr = ((struct Membership *)cptr->data)->chptr;
513 adx 30
514 michael 4170 DLINK_FOREACH(uptr, chptr->locmembers.head)
515 adx 30 {
516 michael 4815 member = uptr->data;
517     target_p = member->client_p;
518 adx 30
519 michael 4170 if (target_p == user || IsDefunct(target_p) ||
520 michael 4588 target_p->connection->serial == current_serial)
521 adx 30 continue;
522    
523 michael 1734 if (HasCap(target_p, cap) != cap)
524     continue;
525    
526 michael 4588 target_p->connection->serial = current_serial;
527 michael 3107 send_message(target_p, buffer);
528 adx 30 }
529     }
530    
531     if (touser && MyConnect(user) && !IsDead(user) &&
532 michael 4588 user->connection->serial != current_serial)
533 michael 1844 if (HasCap(user, cap) == cap)
534 michael 3107 send_message(user, buffer);
535    
536     dbuf_ref_free(buffer);
537 adx 30 }
538    
539     /* sendto_channel_local()
540     *
541     * inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
542     * - pointer to channel to send to
543     * - var args pattern
544     * output - NONE
545     * side effects - Send a message to all members of a channel that are
546     * locally connected to this server.
547     */
548     void
549 michael 4795 sendto_channel_local(unsigned int type, struct Channel *chptr,
550 adx 30 const char *pattern, ...)
551     {
552     va_list args;
553 michael 4815 dlink_node *node = NULL;
554     struct dbuf_block *buffer = dbuf_alloc();
555 adx 30
556     va_start(args, pattern);
557 michael 3107 send_format(buffer, pattern, args);
558 adx 30 va_end(args);
559    
560 michael 4815 DLINK_FOREACH(node, chptr->locmembers.head)
561 adx 30 {
562 michael 4815 struct Membership *member = node->data;
563     struct Client *target_p = member->client_p;
564 adx 30
565 michael 4815 if (type && (member->flags & type) == 0)
566 adx 30 continue;
567    
568 michael 4795 if (IsDefunct(target_p))
569 adx 30 continue;
570    
571 michael 3107 send_message(target_p, buffer);
572 adx 30 }
573 michael 3107
574     dbuf_ref_free(buffer);
575 adx 30 }
576    
577     /* sendto_channel_local_butone()
578     *
579     * inputs - pointer to client to NOT send message to
580     * - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
581     * - pointer to channel to send to
582     * - var args pattern
583     * output - NONE
584     * side effects - Send a message to all members of a channel that are
585     * locally connected to this server except one.
586     *
587     * WARNING - +D clients are omitted
588     */
589 michael 2638 void
590 michael 4792 sendto_channel_local_butone(struct Client *one, unsigned int poscap, unsigned int negcap,
591 michael 2638 struct Channel *chptr, const char *pattern, ...)
592 adx 30 {
593     va_list args;
594 michael 4815 dlink_node *node = NULL;
595 michael 4792 struct dbuf_block *buffer = dbuf_alloc();
596 adx 30
597 michael 2638 va_start(args, pattern);
598 michael 3107 send_format(buffer, pattern, args);
599 adx 30 va_end(args);
600    
601 michael 4815 DLINK_FOREACH(node, chptr->locmembers.head)
602 michael 2638 {
603 michael 4815 struct Membership *member = node->data;
604     struct Client *target_p = member->client_p;
605 adx 30
606 michael 4170 if (one && target_p == one->from)
607 adx 30 continue;
608 michael 1734
609 michael 4795 if (IsDefunct(target_p))
610 michael 3170 continue;
611    
612 michael 4792 if (poscap && HasCap(target_p, poscap) != poscap)
613 michael 2638 continue;
614    
615 michael 4792 if (negcap && HasCap(target_p, negcap))
616     continue;
617    
618 michael 3107 send_message(target_p, buffer);
619 adx 30 }
620 michael 3107
621     dbuf_ref_free(buffer);
622 adx 30 }
623    
624     /*
625     ** match_it() and sendto_match_butone() ARE only used
626     ** to send a msg to all ppl on servers/hosts that match a specified mask
627     ** (used for enhanced PRIVMSGs) for opers
628     **
629     ** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
630     **
631     */
632    
633     /* match_it()
634     *
635     * inputs - client pointer to match on
636     * - actual mask to match
637     * - what to match on, HOST or SERVER
638     * output - 1 or 0 if match or not
639     * side effects - NONE
640     */
641     static int
642 michael 2867 match_it(const struct Client *one, const char *mask, unsigned int what)
643 adx 30 {
644     if (what == MATCH_HOST)
645 michael 1652 return !match(mask, one->host);
646 adx 30
647 michael 1652 return !match(mask, one->servptr->name);
648 adx 30 }
649    
650     /* sendto_match_butone()
651     *
652     * Send to all clients which match the mask in a way defined on 'what';
653     * either by user hostname or user servername.
654     *
655     * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
656     */
657     void
658 michael 3170 sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
659 adx 30 int what, const char *pattern, ...)
660     {
661 adx 285 va_list alocal, aremote;
662 michael 4925 dlink_node *node = NULL;
663 michael 3107 struct dbuf_block *local_buf, *remote_buf;
664 adx 30
665 michael 3107 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
666    
667 michael 3113 dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
668 michael 3186 dbuf_put_fmt(remote_buf, ":%s ", from->id);
669 michael 3107
670 adx 285 va_start(alocal, pattern);
671     va_start(aremote, pattern);
672 michael 3107 send_format(local_buf, pattern, alocal);
673     send_format(remote_buf, pattern, aremote);
674 adx 285 va_end(aremote);
675     va_end(alocal);
676 adx 30
677     /* scan the local clients */
678 michael 4815 DLINK_FOREACH(node, local_client_list.head)
679 adx 30 {
680 michael 4815 struct Client *client_p = node->data;
681 adx 30
682 michael 3174 if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
683 adx 30 match_it(client_p, mask, what))
684 michael 3107 send_message(client_p, local_buf);
685 adx 30 }
686    
687     /* Now scan servers */
688 michael 4925 DLINK_FOREACH(node, local_server_list.head)
689 adx 30 {
690 michael 4815 struct Client *client_p = node->data;
691 adx 30
692     /*
693     * The old code looped through every client on the
694     * network for each server to check if the
695     * server (client_p) has at least 1 client matching
696     * the mask, using something like:
697     *
698     * for (target_p = GlobalClientList; target_p; target_p = target_p->next)
699     * if (IsRegisteredUser(target_p) &&
700     * match_it(target_p, mask, what) &&
701     * (target_p->from == client_p))
702     * vsendto_prefix_one(client_p, from, pattern, args);
703     *
704     * That way, we wouldn't send the message to
705     * a server who didn't have a matching client.
706     * However, on a network such as EFNet, that
707     * code would have looped through about 50
708     * servers, and in each loop, loop through
709     * about 50k clients as well, calling match()
710     * in each nested loop. That is a very bad
711     * thing cpu wise - just send the message
712     * to every connected server and let that
713     * server deal with it.
714     * -wnder
715     */
716 michael 3170 if ((!one || client_p != one->from) && !IsDefunct(client_p))
717 michael 3107 send_message_remote(client_p, from, remote_buf);
718 adx 30 }
719 michael 3107
720     dbuf_ref_free(local_buf);
721     dbuf_ref_free(remote_buf);
722 adx 30 }
723    
724     /* sendto_match_servs()
725     *
726     * inputs - source client
727     * - mask to send to
728     * - capab needed
729     * - data
730     * outputs - none
731     * side effects - data sent to servers matching with capab
732     */
733     void
734 michael 2543 sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
735 adx 30 const char *pattern, ...)
736     {
737     va_list args;
738 michael 4925 dlink_node *node = NULL;
739 michael 4796 struct dbuf_block *buffer = dbuf_alloc();
740 adx 30
741 michael 3947 dbuf_put_fmt(buffer, ":%s ", source_p->id);
742 adx 30 va_start(args, pattern);
743 michael 3947 send_format(buffer, pattern, args);
744 adx 30 va_end(args);
745    
746 michael 948 ++current_serial;
747 adx 30
748 michael 4925 DLINK_FOREACH(node, global_server_list.head)
749 adx 30 {
750 michael 4815 struct Client *target_p = node->data;
751 adx 30
752     /* Do not attempt to send to ourselves, or the source */
753     if (IsMe(target_p) || target_p->from == source_p->from)
754     continue;
755    
756 michael 4588 if (target_p->from->connection->serial == current_serial)
757 adx 30 continue;
758    
759 michael 4796 if (match(mask, target_p->name))
760     continue;
761 adx 30
762 michael 4796 /*
763     * If we set the serial here, then we'll never do a
764     * match() again, if !IsCapable()
765     */
766     target_p->from->connection->serial = current_serial;
767 adx 30
768 michael 4796 if (!IsCapable(target_p->from, cap))
769     continue;
770    
771     send_message_remote(target_p->from, source_p, buffer);
772 adx 30 }
773 michael 3107
774 michael 3947 dbuf_ref_free(buffer);
775 adx 30 }
776    
777     /* sendto_anywhere()
778     *
779     * inputs - pointer to dest client
780     * - pointer to from client
781     * - varags
782     * output - NONE
783     * side effects - less efficient than sendto_remote and sendto_one
784     * but useful when one does not know where target "lives"
785     */
786     void
787     sendto_anywhere(struct Client *to, struct Client *from,
788 michael 2793 const char *command,
789 adx 30 const char *pattern, ...)
790     {
791     va_list args;
792 michael 3189 struct dbuf_block *buffer = NULL;
793 adx 30
794 michael 2793 if (IsDead(to->from))
795 adx 30 return;
796    
797 michael 3107 buffer = dbuf_alloc();
798    
799 michael 3189 if (MyClient(to) && IsClient(from))
800     dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
801     from->host, command, to->name);
802 michael 2634 else
803 michael 3189 dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
804     command, ID_or_name(to, to));
805 adx 30
806     va_start(args, pattern);
807 michael 3107 send_format(buffer, pattern, args);
808 adx 30 va_end(args);
809    
810 michael 4804 if (MyConnect(to))
811 michael 3107 send_message(to, buffer);
812 adx 30 else
813 michael 4803 send_message_remote(to->from, from, buffer);
814 michael 3107
815     dbuf_ref_free(buffer);
816 adx 30 }
817    
818     /* sendto_realops_flags()
819     *
820     * inputs - flag types of messages to show to real opers
821     * - flag indicating opers/admins
822     * - var args input message
823     * output - NONE
824     * side effects - Send to *local* ops only but NOT +s nonopers.
825     */
826     void
827 michael 1618 sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
828 adx 30 {
829 michael 1618 const char *ntype = NULL;
830 michael 4815 dlink_node *node = NULL;
831 michael 3215 char nbuf[IRCD_BUFSIZE] = "";
832 adx 30 va_list args;
833    
834     va_start(args, pattern);
835 michael 1618 vsnprintf(nbuf, sizeof(nbuf), pattern, args);
836 adx 30 va_end(args);
837    
838 michael 1618 switch (type)
839 adx 30 {
840 michael 1618 case SEND_NOTICE:
841     ntype = "Notice";
842     break;
843     case SEND_GLOBAL:
844     ntype = "Global";
845     break;
846     case SEND_LOCOPS:
847     ntype = "LocOps";
848     break;
849     default:
850     assert(0);
851 adx 30 }
852    
853 michael 4815 DLINK_FOREACH(node, oper_list.head)
854 michael 1206 {
855 michael 4815 struct Client *client_p = node->data;
856 michael 1618 assert(HasUMode(client_p, UMODE_OPER));
857 michael 1206
858 michael 1618 /*
859     * If we're sending it to opers and they're an admin, skip.
860     * If we're sending it to admins, and they're not, skip.
861 michael 1206 */
862 michael 1219 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
863 michael 2638 ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
864 michael 1206 continue;
865    
866 michael 1219 if (HasUMode(client_p, flags))
867 michael 1618 sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
868     me.name, client_p->name, ntype, nbuf);
869 michael 1206 }
870     }
871    
872 michael 3215 /* ts_warn()
873     *
874     * inputs - var args message
875     * output - NONE
876     * side effects - Call sendto_realops_flags, with some flood checking
877     * (at most 5 warnings every 5 seconds)
878     */
879     void
880 michael 4431 sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
881 michael 3215 {
882     va_list args;
883     char buffer[IRCD_BUFSIZE] = "";
884    
885 michael 4431 if ((CurrentTime - *rate) < 20)
886     return;
887 michael 4890
888 michael 4431 *rate = CurrentTime;
889 michael 3215
890     va_start(args, pattern);
891     vsnprintf(buffer, sizeof(buffer), pattern, args);
892     va_end(args);
893    
894 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
895 michael 3215 ilog(LOG_TYPE_IRCD, "%s", buffer);
896     }
897    
898 adx 30 /* sendto_wallops_flags()
899     *
900     * inputs - flag types of messages to show to real opers
901     * - client sending request
902     * - var args input message
903     * output - NONE
904     * side effects - Send a wallops to local opers
905     */
906     void
907     sendto_wallops_flags(unsigned int flags, struct Client *source_p,
908     const char *pattern, ...)
909     {
910 michael 4815 dlink_node *node = NULL;
911 adx 30 va_list args;
912 michael 4815 struct dbuf_block *buffer = dbuf_alloc();
913 adx 30
914     if (IsClient(source_p))
915 michael 3113 dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
916 adx 30 else
917 michael 3113 dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
918 adx 30
919     va_start(args, pattern);
920 michael 3107 send_format(buffer, pattern, args);
921 adx 30 va_end(args);
922    
923 michael 4815 DLINK_FOREACH(node, oper_list.head)
924 adx 30 {
925 michael 4815 struct Client *client_p = node->data;
926 adx 30 assert(client_p->umodes & UMODE_OPER);
927    
928 michael 1219 if (HasUMode(client_p, flags) && !IsDefunct(client_p))
929 michael 3107 send_message(client_p, buffer);
930 adx 30 }
931 michael 3107
932     dbuf_ref_free(buffer);
933 adx 30 }

Properties

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