ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 8994
Committed: Sat May 25 20:38:06 2019 UTC (7 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 23657 byte(s)
Log Message:
- send.c: stylistic changes

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

Properties

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