ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 9790
Committed: Sun Dec 6 18:38:44 2020 UTC (5 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 22496 byte(s)
Log Message:
- Rename Connection::caps to Connection::capab

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 9433 send_message(struct Client *to, struct dbuf_block *buffer)
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 9433 if (dbuf_length(&to->connection->buf_sendq) + buffer->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 9433 (dbuf_length(&to->connection->buf_sendq) + buffer->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 9433 dbuf_add(&to->connection->buf_sendq, buffer);
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 9433 send_message_remote(struct Client *to, const struct Client *from, struct dbuf_block *buffer)
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 michael 9433 send_message(to, buffer);
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 9250 struct Client *const client = data;
151 michael 3312
152 michael 9250 assert(client);
153     assert(client->connection);
154     assert(client->connection->fd);
155     assert(client->connection->fd == F);
156 michael 8339
157 michael 9250 DelFlag(client, FLAGS_BLOCKED);
158     send_queued_write(client);
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 michael 9157 if (tls_isusing(&to->connection->fd->tls))
186 michael 3311 {
187 michael 9157 retlen = tls_write(&to->connection->fd->tls, first->data + to->connection->buf_sendq.pos,
188 michael 8955 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 9433 va_list args_l, args_r;
317 michael 8349 dlink_node *node;
318 michael 9433 struct dbuf_block *buffer_l = dbuf_alloc();
319     struct dbuf_block *buffer_r = dbuf_alloc();
320 adx 30
321 michael 3805 if (IsClient(from))
322 michael 9433 dbuf_put_fmt(buffer_l, ":%s!%s@%s ", from->name, from->username, from->host);
323 michael 3805 else
324 michael 9433 dbuf_put_fmt(buffer_l, ":%s ", from->name);
325 adx 30
326 michael 9433 dbuf_put_fmt(buffer_r, ":%s ", from->id);
327 michael 3107
328 michael 9433 va_start(args_l, pattern);
329     va_start(args_r, pattern);
330     send_format(buffer_l, pattern, args_l);
331     send_format(buffer_r, pattern, args_r);
332     va_end(args_l);
333     va_end(args_r);
334 michael 3136
335 adx 30 ++current_serial;
336    
337 michael 9081 DLINK_FOREACH(node, channel->members.head)
338 adx 30 {
339 michael 9081 struct ChannelMember *member = node->data;
340 michael 9250 struct Client *target = member->client;
341 adx 30
342 michael 9250 assert(IsClient(target));
343 michael 1078
344 michael 9250 if (IsDead(target->from))
345 adx 30 continue;
346    
347 michael 9250 if (one && (target->from == one->from))
348 michael 7945 continue;
349    
350 michael 4815 if (type && (member->flags & type) == 0)
351 michael 1479 continue;
352    
353 michael 9250 if (HasUMode(target, UMODE_DEAF))
354 michael 7945 continue;
355    
356 michael 9250 if (MyConnect(target))
357 michael 9433 send_message(target, buffer_l);
358 michael 9250 else if (target->from->connection->serial != current_serial)
359 michael 9433 send_message_remote(target->from, from, buffer_r);
360 michael 4890
361 michael 9250 target->from->connection->serial = current_serial;
362 adx 30 }
363 michael 3107
364 michael 9433 dbuf_ref_free(buffer_l);
365     dbuf_ref_free(buffer_r);
366 adx 30 }
367    
368     /* sendto_server()
369 michael 2916 *
370 adx 30 * inputs - pointer to client to NOT send to
371 db 939 * - pointer to channel
372 michael 9790 * - capabs or'd together which must ALL be present
373     * - capabs or'd together which must ALL NOT be present
374 adx 30 * - printf style format string
375     * - args to format string
376     * output - NONE
377     * side effects - Send a message to all connected servers, except the
378     * client 'one' (if non-NULL), as long as the servers
379 michael 9790 * support ALL capabs in 'capab', and NO capabs in 'nocapab'.
380 michael 2916 *
381 adx 30 * This function was written in an attempt to merge together the other
382     * billion sendto_*serv*() functions, which sprung up with capabs,
383     * lazylinks, uids, etc.
384     * -davidt
385     */
386 michael 2638 void
387 michael 7322 sendto_server(const struct Client *one,
388 michael 9790 const unsigned int capab,
389     const unsigned int nocapab,
390 adx 30 const char *format, ...)
391     {
392     va_list args;
393 michael 7947 dlink_node *node;
394 michael 9433 struct dbuf_block *buffer = dbuf_alloc();
395 adx 30
396     va_start(args, format);
397 michael 3107 send_format(buffer, format, args);
398 adx 30 va_end(args);
399    
400 michael 4815 DLINK_FOREACH(node, local_server_list.head)
401 adx 30 {
402 michael 9250 struct Client *client = node->data;
403 adx 30
404     /* If dead already skip */
405 michael 9250 if (IsDead(client))
406 adx 30 continue;
407 michael 4890
408 adx 30 /* check against 'one' */
409 michael 9250 if (one && (client == one->from))
410 adx 30 continue;
411 michael 4890
412 adx 30 /* check we have required capabs */
413 michael 9790 if (IsCapable(client, capab) != capab)
414 adx 30 continue;
415 michael 4890
416 adx 30 /* check we don't have any forbidden capabs */
417 michael 9790 if (IsCapable(client, nocapab))
418 adx 30 continue;
419    
420 michael 9250 send_message(client, buffer);
421 adx 30 }
422 michael 3107
423     dbuf_ref_free(buffer);
424 adx 30 }
425    
426     /* sendto_common_channels_local()
427     *
428     * inputs - pointer to client
429     * - pattern to send
430     * output - NONE
431     * side effects - Sends a message to all people on local server who are
432 michael 2916 * in same channel with user.
433 adx 30 * used by m_nick.c and exit_one_client.
434     */
435     void
436 michael 8688 sendto_common_channels_local(struct Client *user, bool touser, unsigned int poscap,
437 michael 6774 unsigned int negcap, const char *pattern, ...)
438 adx 30 {
439     va_list args;
440 michael 9431 dlink_node *node, *node2;
441 michael 4815 struct dbuf_block *buffer = dbuf_alloc();
442 adx 30
443     va_start(args, pattern);
444 michael 3107 send_format(buffer, pattern, args);
445 adx 30 va_end(args);
446    
447     ++current_serial;
448    
449 michael 9431 DLINK_FOREACH(node, user->channel.head)
450 adx 30 {
451 michael 9431 struct ChannelMember *member = node->data;
452     struct Channel *channel = member->channel;
453 adx 30
454 michael 9431 DLINK_FOREACH(node2, channel->members_local.head)
455 adx 30 {
456 michael 9431 struct ChannelMember *member2 = node2->data;
457     struct Client *target = member2->client;
458 adx 30
459 michael 9250 if (IsDead(target))
460 adx 30 continue;
461    
462 michael 9250 if (target == user)
463 michael 8945 continue;
464    
465 michael 9250 if (target->connection->serial == current_serial)
466 michael 8945 continue;
467    
468 michael 9250 if (poscap && HasCap(target, poscap) != poscap)
469 michael 1734 continue;
470    
471 michael 9250 if (negcap && HasCap(target, negcap))
472 michael 6774 continue;
473    
474 michael 9250 target->connection->serial = current_serial;
475     send_message(target, buffer);
476 adx 30 }
477     }
478    
479 michael 8998 if (touser == true && MyConnect(user) && !IsDead(user))
480 michael 6774 if (HasCap(user, poscap) == poscap)
481 michael 3107 send_message(user, buffer);
482    
483     dbuf_ref_free(buffer);
484 adx 30 }
485    
486 michael 6759 /*! \brief Send a message to members of a channel that are locally connected to this server.
487     * \param one Client to skip; can be NULL
488 michael 9081 * \param channel Destination channel
489 michael 6759 * \param status Channel member status flags clients must have
490     * \param poscap Positive client capabilities flags (CAP)
491     * \param negcap Negative client capabilities flags (CAP)
492     * \param pattern Format string for command arguments
493 adx 30 */
494     void
495 michael 9081 sendto_channel_local(const struct Client *one, struct Channel *channel, unsigned int status,
496 michael 6759 unsigned int poscap, unsigned int negcap, const char *pattern, ...)
497 adx 30 {
498     va_list args;
499 michael 8349 dlink_node *node;
500 michael 4815 struct dbuf_block *buffer = dbuf_alloc();
501 adx 30
502     va_start(args, pattern);
503 michael 3107 send_format(buffer, pattern, args);
504 adx 30 va_end(args);
505    
506 michael 9081 DLINK_FOREACH(node, channel->members_local.head)
507 adx 30 {
508 michael 9081 struct ChannelMember *member = node->data;
509 michael 9250 struct Client *target = member->client;
510 adx 30
511 michael 9250 if (IsDead(target))
512 adx 30 continue;
513    
514 michael 9250 if (one && (target == one->from))
515 adx 30 continue;
516 michael 1734
517 michael 6759 if (status && (member->flags & status) == 0)
518 michael 3170 continue;
519    
520 michael 9250 if (poscap && HasCap(target, poscap) != poscap)
521 michael 2638 continue;
522    
523 michael 9250 if (negcap && HasCap(target, negcap))
524 michael 4792 continue;
525    
526 michael 9250 send_message(target, buffer);
527 adx 30 }
528 michael 3107
529     dbuf_ref_free(buffer);
530 adx 30 }
531    
532     /*
533     ** match_it() and sendto_match_butone() ARE only used
534     ** to send a msg to all ppl on servers/hosts that match a specified mask
535     ** (used for enhanced PRIVMSGs) for opers
536     **
537     ** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
538     **
539     */
540    
541     /* match_it()
542     *
543     * inputs - client pointer to match on
544     * - actual mask to match
545     * - what to match on, HOST or SERVER
546     * output - 1 or 0 if match or not
547     * side effects - NONE
548     */
549 michael 8945 static bool
550 michael 2867 match_it(const struct Client *one, const char *mask, unsigned int what)
551 adx 30 {
552     if (what == MATCH_HOST)
553 michael 8557 return match(mask, one->host) == 0;
554 adx 30
555 michael 8557 return match(mask, one->servptr->name) == 0;
556 adx 30 }
557    
558     /* sendto_match_butone()
559     *
560     * Send to all clients which match the mask in a way defined on 'what';
561     * either by user hostname or user servername.
562     *
563     * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
564     */
565     void
566 michael 7322 sendto_match_butone(const struct Client *one, const struct Client *from,
567     const char *mask, int what, const char *pattern, ...)
568 adx 30 {
569 michael 9433 va_list args_l, args_r;
570 michael 8349 dlink_node *node;
571 michael 9433 struct dbuf_block *buffer_l = dbuf_alloc();
572     struct dbuf_block *buffer_r = dbuf_alloc();
573 adx 30
574 michael 9433 dbuf_put_fmt(buffer_l, ":%s!%s@%s ", from->name, from->username, from->host);
575     dbuf_put_fmt(buffer_r, ":%s ", from->id);
576 michael 3107
577 michael 9433 va_start(args_l, pattern);
578     va_start(args_r, pattern);
579     send_format(buffer_l, pattern, args_l);
580     send_format(buffer_r, pattern, args_r);
581     va_end(args_l);
582     va_end(args_r);
583 michael 3107
584 michael 9433 /* Scan the local clients */
585 michael 4815 DLINK_FOREACH(node, local_client_list.head)
586 adx 30 {
587 michael 9250 struct Client *client = node->data;
588 adx 30
589 michael 9250 if (IsDead(client))
590 michael 8945 continue;
591    
592 michael 9250 if (one && (client == one->from))
593 michael 8945 continue;
594    
595 michael 9250 if (match_it(client, mask, what) == false)
596 michael 8945 continue;
597    
598 michael 9433 send_message(client, buffer_l);
599 adx 30 }
600    
601     /* Now scan servers */
602 michael 4925 DLINK_FOREACH(node, local_server_list.head)
603 adx 30 {
604 michael 9250 struct Client *client = node->data;
605 adx 30
606     /*
607 michael 9433 * The old code looped through every client on the network for each
608     * server to check if the server (client) has at least 1 client
609     * matching the mask, using something like:
610 adx 30 *
611 michael 9250 * for (target = GlobalClientList; target; target = target->next)
612     * if (IsRegisteredUser(target) &&
613     * match_it(target, mask, what) &&
614     * (target->from == client))
615     * vsendto_prefix_one(client, from, pattern, args);
616 adx 30 *
617 michael 9433 * That way, we wouldn't send the message to a server who didn't have
618     * a matching client. However, on a network such as EFNet, that code
619     * would have looped through about 50 servers, and in each loop, loop
620     * through about 50k clients as well, calling match() in each nested
621     * loop. That is a very bad thing cpu wise - just send the message to
622     * every connected server and let that server deal with it.
623 adx 30 * -wnder
624     */
625 michael 9250 if (IsDead(client))
626 michael 8945 continue;
627    
628 michael 9250 if (one && (client == one->from))
629 michael 8945 continue;
630    
631 michael 9433 send_message_remote(client, from, buffer_r);
632 adx 30 }
633 michael 3107
634 michael 9433 dbuf_ref_free(buffer_l);
635     dbuf_ref_free(buffer_r);
636 adx 30 }
637    
638     /* sendto_match_servs()
639     *
640     * inputs - source client
641     * - mask to send to
642     * - capab needed
643     * - data
644     * outputs - none
645     * side effects - data sent to servers matching with capab
646     */
647     void
648 michael 7322 sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
649 adx 30 const char *pattern, ...)
650     {
651     va_list args;
652 michael 8349 dlink_node *node;
653 michael 4796 struct dbuf_block *buffer = dbuf_alloc();
654 adx 30
655 michael 3947 dbuf_put_fmt(buffer, ":%s ", source_p->id);
656 michael 9433
657 adx 30 va_start(args, pattern);
658 michael 3947 send_format(buffer, pattern, args);
659 adx 30 va_end(args);
660    
661 michael 948 ++current_serial;
662 adx 30
663 michael 4925 DLINK_FOREACH(node, global_server_list.head)
664 adx 30 {
665 michael 9250 struct Client *target = node->data;
666 adx 30
667 michael 9250 if (IsDead(target->from))
668 michael 8817 continue;
669    
670 michael 8994 /* Do not attempt to send to ourselves ... */
671 michael 9250 if (IsMe(target))
672 adx 30 continue;
673    
674 michael 8994 /* ... or the source */
675 michael 9250 if (target->from == source_p->from)
676 michael 8994 continue;
677    
678 michael 9250 if (target->from->connection->serial == current_serial)
679 adx 30 continue;
680    
681 michael 9433 if (cap && IsCapable(target->from, cap) != cap)
682 michael 4796 continue;
683 adx 30
684 michael 9433 if (match(mask, target->name))
685 michael 4796 continue;
686    
687 michael 9250 target->from->connection->serial = current_serial;
688     send_message_remote(target->from, source_p, buffer);
689 adx 30 }
690 michael 3107
691 michael 3947 dbuf_ref_free(buffer);
692 adx 30 }
693    
694     /* sendto_anywhere()
695     *
696     * inputs - pointer to dest client
697     * - pointer to from client
698     * - varags
699     * output - NONE
700     * side effects - less efficient than sendto_remote and sendto_one
701     * but useful when one does not know where target "lives"
702     */
703     void
704 michael 7322 sendto_anywhere(struct Client *to, const struct Client *from,
705 michael 2793 const char *command,
706 adx 30 const char *pattern, ...)
707     {
708     va_list args;
709    
710 michael 2793 if (IsDead(to->from))
711 adx 30 return;
712    
713 michael 8036 struct dbuf_block *buffer = dbuf_alloc();
714 michael 3189 if (MyClient(to) && IsClient(from))
715     dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
716     from->host, command, to->name);
717 michael 2634 else
718 michael 3189 dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
719     command, ID_or_name(to, to));
720 adx 30
721     va_start(args, pattern);
722 michael 3107 send_format(buffer, pattern, args);
723 adx 30 va_end(args);
724    
725 michael 4804 if (MyConnect(to))
726 michael 3107 send_message(to, buffer);
727 adx 30 else
728 michael 4803 send_message_remote(to->from, from, buffer);
729 michael 3107
730     dbuf_ref_free(buffer);
731 adx 30 }
732    
733     /* sendto_realops_flags()
734     *
735     * inputs - flag types of messages to show to real opers
736     * - flag indicating opers/admins
737     * - var args input message
738     * output - NONE
739     * side effects - Send to *local* ops only but NOT +s nonopers.
740     */
741     void
742 michael 1618 sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
743 adx 30 {
744 michael 9433 va_list args;
745     dlink_node *node;
746 michael 8030 const char *ntype = "???";
747 adx 30
748 michael 1618 switch (type)
749 adx 30 {
750 michael 1618 case SEND_NOTICE:
751     ntype = "Notice";
752     break;
753     case SEND_GLOBAL:
754     ntype = "Global";
755     break;
756     case SEND_LOCOPS:
757     ntype = "LocOps";
758     break;
759     default:
760     assert(0);
761 adx 30 }
762    
763 michael 8034 struct dbuf_block *buffer = dbuf_alloc();
764     dbuf_put_fmt(buffer, ":%s NOTICE * :*** %s -- ", me.name, ntype);
765    
766     va_start(args, pattern);
767     send_format(buffer, pattern, args);
768     va_end(args);
769    
770 michael 4815 DLINK_FOREACH(node, oper_list.head)
771 michael 1206 {
772 michael 9250 struct Client *client = node->data;
773     assert(HasUMode(client, UMODE_OPER));
774 michael 1206
775 michael 9250 if (IsDead(client))
776 michael 8994 continue;
777    
778 michael 1618 /*
779     * If we're sending it to opers and they're an admin, skip.
780     * If we're sending it to admins, and they're not, skip.
781 michael 1206 */
782 michael 9250 if (((level == L_ADMIN) && !HasUMode(client, UMODE_ADMIN)) ||
783     ((level == L_OPER) && HasUMode(client, UMODE_ADMIN)))
784 michael 1206 continue;
785    
786 michael 9250 if (!HasUMode(client, flags))
787 michael 8994 continue;
788    
789 michael 9250 send_message(client, buffer);
790 michael 1206 }
791 michael 8034
792     dbuf_ref_free(buffer);
793 michael 1206 }
794    
795 michael 3215 /* ts_warn()
796     *
797     * inputs - var args message
798     * output - NONE
799     * side effects - Call sendto_realops_flags, with some flood checking
800     * (at most 5 warnings every 5 seconds)
801     */
802     void
803 michael 7330 sendto_realops_flags_ratelimited(uintmax_t *rate, const char *pattern, ...)
804 michael 3215 {
805     va_list args;
806 michael 9433 char buffer[IRCD_BUFSIZE];
807 michael 3215
808 michael 8903 if ((event_base->time.sec_monotonic - *rate) < 20)
809 michael 4431 return;
810 michael 4890
811 michael 8903 *rate = event_base->time.sec_monotonic;
812 michael 3215
813     va_start(args, pattern);
814     vsnprintf(buffer, sizeof(buffer), pattern, args);
815     va_end(args);
816    
817 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
818 michael 3215 ilog(LOG_TYPE_IRCD, "%s", buffer);
819     }
820    
821 adx 30 /* sendto_wallops_flags()
822     *
823     * inputs - flag types of messages to show to real opers
824     * - client sending request
825     * - var args input message
826     * output - NONE
827     * side effects - Send a wallops to local opers
828     */
829     void
830 michael 7322 sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
831 adx 30 const char *pattern, ...)
832     {
833 michael 9433 va_list args;
834 michael 8349 dlink_node *node;
835 michael 4815 struct dbuf_block *buffer = dbuf_alloc();
836 adx 30
837     if (IsClient(source_p))
838 michael 3113 dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
839 adx 30 else
840 michael 3113 dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
841 adx 30
842     va_start(args, pattern);
843 michael 3107 send_format(buffer, pattern, args);
844 adx 30 va_end(args);
845    
846 michael 4815 DLINK_FOREACH(node, oper_list.head)
847 adx 30 {
848 michael 9250 struct Client *client = node->data;
849     assert(client->umodes & UMODE_OPER);
850 adx 30
851 michael 9250 if (IsDead(client))
852 michael 8994 continue;
853    
854 michael 9250 if (!HasUMode(client, flags))
855 michael 8994 continue;
856    
857 michael 9250 send_message(client, buffer);
858 adx 30 }
859 michael 3107
860     dbuf_ref_free(buffer);
861 adx 30 }

Properties

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