ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 9101
Committed: Wed Jan 1 09:58:45 2020 UTC (6 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 22758 byte(s)
Log Message:
- Bump copyright years everywhere

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

Properties

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