ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/send.c
Revision: 8556
Committed: Sat Sep 22 21:45:27 2018 UTC (5 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 23349 byte(s)
Log Message:
- Minor style corrections

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

Properties

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