ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 7322
Committed: Sun Feb 14 15:41:25 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 23384 byte(s)
Log Message:
- Constification

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 7006 * Copyright (c) 1997-2016 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file send.c
23     * \brief Functions for sending messages.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "send.h"
30     #include "channel.h"
31     #include "client.h"
32     #include "dbuf.h"
33     #include "irc_string.h"
34     #include "ircd.h"
35     #include "s_bsd.h"
36 michael 3347 #include "server.h"
37 michael 5035 #include "conf_class.h"
38 michael 1309 #include "log.h"
39 adx 30
40    
41 michael 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 adx 30 get_client_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 adx 30 {
138 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
139 michael 4923 "Send message to %s dropped from %s (Fake Dir)",
140     to->name, from->name);
141 adx 30 return;
142 michael 2638 }
143 adx 30
144 michael 3107 send_message(to, buf);
145 adx 30 }
146    
147     /*
148     ** sendq_unblocked
149     ** Called when a socket is ready for writing.
150     */
151     void
152 michael 4461 sendq_unblocked(fde_t *fd, void *data)
153 adx 30 {
154 michael 4995 struct Client *const client_p = data;
155 michael 4588 assert(fd == &client_p->connection->fd);
156 michael 3312
157     DelFlag(client_p, FLAGS_BLOCKED);
158 michael 2881 send_queued_write(client_p);
159 adx 30 }
160    
161     /*
162     ** send_queued_write
163     ** This is called when there is a chance that some output would
164     ** be possible. This attempts to empty the send queue as far as
165     ** possible, and then if any data is left, a write is rescheduled.
166     */
167     void
168     send_queued_write(struct Client *to)
169     {
170 michael 3311 int retlen = 0;
171 michael 7105 int want_read = 0;
172 adx 30
173     /*
174 michael 3311 ** Once socket is marked dead, we cannot start writing to it,
175     ** even if the error is removed...
176 adx 30 */
177 michael 3312 if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
178 michael 3311 return; /* no use calling send() now */
179 adx 30
180 michael 3311 /* Next, lets try to write some data */
181 michael 4588 if (dbuf_length(&to->connection->buf_sendq))
182 adx 30 {
183 michael 3311 do
184     {
185 michael 6357 const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
186 adx 30
187 michael 7105 if (tls_isusing(&to->connection->fd.ssl))
188 michael 3311 {
189 michael 7322 retlen = tls_write(&to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos,
190     first->size - to->connection->buf_sendq.pos, &want_read);
191 michael 3241
192 michael 7105 if (want_read)
193     return; /* Retry later, don't register for write events */
194 michael 3311 }
195     else
196 michael 7322 retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos,
197     first->size - to->connection->buf_sendq.pos, 0);
198 michael 3241
199 michael 3311 if (retlen <= 0)
200     break;
201 michael 3241
202 michael 4588 dbuf_delete(&to->connection->buf_sendq, retlen);
203 adx 30
204 michael 3311 /* We have some data written .. update counters */
205 michael 4588 to->connection->send.bytes += retlen;
206     me.connection->send.bytes += retlen;
207     } while (dbuf_length(&to->connection->buf_sendq));
208 adx 30
209 michael 3335 if (retlen < 0 && ignoreErrno(errno))
210 michael 3311 {
211 michael 3312 AddFlag(to, FLAGS_BLOCKED);
212 michael 3335
213 michael 3311 /* we have a non-fatal error, reschedule a write */
214 michael 7322 comm_setselect(&to->connection->fd, COMM_SELECT_WRITE, sendq_unblocked, to, 0);
215 michael 3311 }
216     else if (retlen <= 0)
217     {
218     dead_link_on_write(to, errno);
219     return;
220     }
221 adx 30 }
222     }
223    
224     /* send_queued_all()
225     *
226     * input - NONE
227     * output - NONE
228     * side effects - try to flush sendq of each client
229     */
230     void
231     send_queued_all(void)
232     {
233 michael 4815 dlink_node *node = NULL;
234 adx 30
235     /* Servers are processed first, mainly because this can generate
236     * a notice to opers, which is to be delivered by this function.
237     */
238 michael 4815 DLINK_FOREACH(node, local_server_list.head)
239     send_queued_write(node->data);
240 adx 30
241 michael 4815 DLINK_FOREACH(node, unknown_list.head)
242     send_queued_write(node->data);
243 adx 30
244 michael 4815 DLINK_FOREACH(node, local_client_list.head)
245     send_queued_write(node->data);
246 adx 30
247     /* NOTE: This can still put clients on aborted_list; unfortunately,
248     * exit_aborted_clients takes precedence over send_queued_all,
249     * because exiting clients can generate server/oper traffic.
250     * The easiest approach is dealing with aborted clients in the next I/O lap.
251     * -adx
252     */
253     }
254    
255     /* sendto_one()
256     *
257     * inputs - pointer to destination client
258     * - var args message
259     * output - NONE
260     * side effects - send message to single client
261     */
262     void
263     sendto_one(struct Client *to, const char *pattern, ...)
264     {
265     va_list args;
266 michael 3189 struct dbuf_block *buffer = NULL;
267 adx 30
268 michael 3189 if (IsDead(to->from))
269 michael 3107 return; /* This socket has already been marked as dead */
270 adx 30
271 michael 3107 buffer = dbuf_alloc();
272    
273 adx 30 va_start(args, pattern);
274 michael 3107 send_format(buffer, pattern, args);
275 adx 30 va_end(args);
276    
277 michael 3189 send_message(to->from, buffer);
278 michael 3107
279     dbuf_ref_free(buffer);
280 adx 30 }
281    
282 michael 3109 void
283 michael 7322 sendto_one_numeric(struct Client *to, const struct Client *from, enum irc_numerics numeric, ...)
284 michael 3109 {
285 michael 3189 struct dbuf_block *buffer = NULL;
286 michael 3573 const char *dest = NULL, *numstr = NULL;
287 michael 3109 va_list args;
288    
289 michael 3189 if (IsDead(to->from))
290 michael 3109 return;
291    
292     dest = ID_or_name(to, to);
293 michael 3335
294 michael 3109 if (EmptyString(dest))
295     dest = "*";
296    
297     buffer = dbuf_alloc();
298    
299 michael 3573 dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
300 michael 3109
301     va_start(args, numeric);
302 michael 3573
303     if (numeric & SND_EXPLICIT)
304     numstr = va_arg(args, const char *);
305     else
306     numstr = numeric_form(numeric);
307 michael 4791
308 michael 3573 send_format(buffer, numstr, args);
309 michael 3109 va_end(args);
310    
311 michael 3189 send_message(to->from, buffer);
312 michael 3109
313     dbuf_ref_free(buffer);
314     }
315    
316 michael 3110 void
317 michael 7322 sendto_one_notice(struct Client *to, const struct Client *from, const char *pattern, ...)
318 michael 3110 {
319 michael 3189 struct dbuf_block *buffer = NULL;
320     const char *dest = NULL;
321 michael 3110 va_list args;
322    
323 michael 3189 if (IsDead(to->from))
324 michael 3110 return;
325    
326     dest = ID_or_name(to, to);
327 michael 3335
328 michael 3110 if (EmptyString(dest))
329     dest = "*";
330    
331     buffer = dbuf_alloc();
332    
333 michael 3113 dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
334 michael 3110
335     va_start(args, pattern);
336     send_format(buffer, pattern, args);
337     va_end(args);
338    
339 michael 3189 send_message(to->from, buffer);
340 michael 3110
341     dbuf_ref_free(buffer);
342     }
343    
344 adx 30 /* sendto_channel_butone()
345     *
346     * inputs - pointer to client(server) to NOT send message to
347     * - pointer to client that is sending this message
348     * - pointer to channel being sent to
349     * - vargs message
350     * output - NONE
351     * side effects - message as given is sent to given channel members.
352     *
353     * WARNING - +D clients are ignored
354     */
355     void
356 michael 7322 sendto_channel_butone(struct Client *one, const struct Client *from,
357 michael 1479 struct Channel *chptr, unsigned int type,
358 adx 30 const char *pattern, ...)
359     {
360 michael 3136 va_list alocal, aremote;
361     struct dbuf_block *local_buf, *remote_buf;
362 michael 4925 dlink_node *node = NULL;
363 adx 30
364 michael 3136 local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
365 michael 3107
366 michael 3805 if (IsClient(from))
367     dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
368     else
369 michael 3113 dbuf_put_fmt(local_buf, ":%s ", from->name);
370 adx 30
371 michael 3186 dbuf_put_fmt(remote_buf, ":%s ", from->id);
372 michael 3107
373 adx 285 va_start(alocal, pattern);
374     va_start(aremote, pattern);
375 michael 3107 send_format(local_buf, pattern, alocal);
376     send_format(remote_buf, pattern, aremote);
377 michael 3136
378 adx 285 va_end(aremote);
379     va_end(alocal);
380 adx 30
381     ++current_serial;
382    
383 michael 4925 DLINK_FOREACH(node, chptr->members.head)
384 adx 30 {
385 michael 4815 struct Membership *member = node->data;
386     struct Client *target_p = member->client_p;
387 adx 30
388 michael 1078 assert(IsClient(target_p));
389    
390 michael 3164 if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
391     (one && target_p->from == one->from))
392 adx 30 continue;
393    
394 michael 4815 if (type && (member->flags & type) == 0)
395 michael 1479 continue;
396    
397 michael 1078 if (MyConnect(target_p))
398 michael 3103 send_message(target_p, local_buf);
399 michael 4588 else if (target_p->from->connection->serial != current_serial)
400 michael 3103 send_message_remote(target_p->from, from, remote_buf);
401 michael 4890
402 michael 4588 target_p->from->connection->serial = current_serial;
403 adx 30 }
404 michael 3107
405     dbuf_ref_free(local_buf);
406     dbuf_ref_free(remote_buf);
407 adx 30 }
408    
409     /* sendto_server()
410 michael 2916 *
411 adx 30 * inputs - pointer to client to NOT send to
412 db 939 * - pointer to channel
413 adx 30 * - caps or'd together which must ALL be present
414     * - caps or'd together which must ALL NOT be present
415     * - printf style format string
416     * - args to format string
417     * output - NONE
418     * side effects - Send a message to all connected servers, except the
419     * client 'one' (if non-NULL), as long as the servers
420     * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
421 michael 2916 *
422 adx 30 * This function was written in an attempt to merge together the other
423     * billion sendto_*serv*() functions, which sprung up with capabs,
424     * lazylinks, uids, etc.
425     * -davidt
426     */
427 michael 2638 void
428 michael 7322 sendto_server(const struct Client *one,
429 michael 1015 const unsigned int caps,
430     const unsigned int nocaps,
431 adx 30 const char *format, ...)
432     {
433     va_list args;
434 michael 4815 dlink_node *node = NULL;
435     struct dbuf_block *buffer = dbuf_alloc();
436 adx 30
437     va_start(args, format);
438 michael 3107 send_format(buffer, format, args);
439 adx 30 va_end(args);
440    
441 michael 4815 DLINK_FOREACH(node, local_server_list.head)
442 adx 30 {
443 michael 4815 struct Client *client_p = node->data;
444 adx 30
445     /* If dead already skip */
446     if (IsDead(client_p))
447     continue;
448 michael 4890
449 adx 30 /* check against 'one' */
450 michael 3243 if (one && (client_p == one->from))
451 adx 30 continue;
452 michael 4890
453 adx 30 /* check we have required capabs */
454 michael 4588 if ((client_p->connection->caps & caps) != caps)
455 adx 30 continue;
456 michael 4890
457 adx 30 /* check we don't have any forbidden capabs */
458 michael 4588 if ((client_p->connection->caps & nocaps))
459 adx 30 continue;
460    
461 michael 3107 send_message(client_p, buffer);
462 adx 30 }
463 michael 3107
464     dbuf_ref_free(buffer);
465 adx 30 }
466    
467     /* sendto_common_channels_local()
468     *
469     * inputs - pointer to client
470     * - pattern to send
471     * output - NONE
472     * side effects - Sends a message to all people on local server who are
473 michael 2916 * in same channel with user.
474 adx 30 * used by m_nick.c and exit_one_client.
475     */
476     void
477 michael 6774 sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap,
478     unsigned int negcap, const char *pattern, ...)
479 adx 30 {
480     va_list args;
481     dlink_node *uptr;
482     dlink_node *cptr;
483     struct Channel *chptr;
484 michael 4815 struct Membership *member;
485 adx 30 struct Client *target_p;
486 michael 4815 struct dbuf_block *buffer = dbuf_alloc();
487 adx 30
488     va_start(args, pattern);
489 michael 3107 send_format(buffer, pattern, args);
490 adx 30 va_end(args);
491    
492     ++current_serial;
493    
494     DLINK_FOREACH(cptr, user->channel.head)
495     {
496 michael 2638 chptr = ((struct Membership *)cptr->data)->chptr;
497 adx 30
498 michael 4170 DLINK_FOREACH(uptr, chptr->locmembers.head)
499 adx 30 {
500 michael 4815 member = uptr->data;
501     target_p = member->client_p;
502 adx 30
503 michael 4170 if (target_p == user || IsDefunct(target_p) ||
504 michael 4588 target_p->connection->serial == current_serial)
505 adx 30 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     if (touser && 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 4815 dlink_node *node = NULL;
540     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 4815 DLINK_FOREACH(node, chptr->locmembers.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 4795 if (IsDefunct(target_p))
552 adx 30 continue;
553    
554 michael 4170 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     static int
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 1652 return !match(mask, one->host);
594 adx 30
595 michael 1652 return !match(mask, one->servptr->name);
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 4925 dlink_node *node = NULL;
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 3174 if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
631 adx 30 match_it(client_p, mask, what))
632 michael 3107 send_message(client_p, local_buf);
633 adx 30 }
634    
635     /* Now scan servers */
636 michael 4925 DLINK_FOREACH(node, local_server_list.head)
637 adx 30 {
638 michael 4815 struct Client *client_p = node->data;
639 adx 30
640     /*
641     * The old code looped through every client on the
642     * network for each server to check if the
643     * server (client_p) has at least 1 client matching
644     * the mask, using something like:
645     *
646     * for (target_p = GlobalClientList; target_p; target_p = target_p->next)
647     * if (IsRegisteredUser(target_p) &&
648     * match_it(target_p, mask, what) &&
649     * (target_p->from == client_p))
650     * vsendto_prefix_one(client_p, from, pattern, args);
651     *
652     * That way, we wouldn't send the message to
653     * a server who didn't have a matching client.
654     * However, on a network such as EFNet, that
655     * code would have looped through about 50
656     * servers, and in each loop, loop through
657     * about 50k clients as well, calling match()
658     * in each nested loop. That is a very bad
659     * thing cpu wise - just send the message
660     * to every connected server and let that
661     * server deal with it.
662     * -wnder
663     */
664 michael 3170 if ((!one || client_p != one->from) && !IsDefunct(client_p))
665 michael 3107 send_message_remote(client_p, from, remote_buf);
666 adx 30 }
667 michael 3107
668     dbuf_ref_free(local_buf);
669     dbuf_ref_free(remote_buf);
670 adx 30 }
671    
672     /* sendto_match_servs()
673     *
674     * inputs - source client
675     * - mask to send to
676     * - capab needed
677     * - data
678     * outputs - none
679     * side effects - data sent to servers matching with capab
680     */
681     void
682 michael 7322 sendto_match_servs(const struct Client *source_p, const char *mask, unsigned int cap,
683 adx 30 const char *pattern, ...)
684     {
685     va_list args;
686 michael 4925 dlink_node *node = NULL;
687 michael 4796 struct dbuf_block *buffer = dbuf_alloc();
688 adx 30
689 michael 3947 dbuf_put_fmt(buffer, ":%s ", source_p->id);
690 adx 30 va_start(args, pattern);
691 michael 3947 send_format(buffer, pattern, args);
692 adx 30 va_end(args);
693    
694 michael 948 ++current_serial;
695 adx 30
696 michael 4925 DLINK_FOREACH(node, global_server_list.head)
697 adx 30 {
698 michael 4815 struct Client *target_p = node->data;
699 adx 30
700     /* Do not attempt to send to ourselves, or the source */
701     if (IsMe(target_p) || target_p->from == source_p->from)
702     continue;
703    
704 michael 4588 if (target_p->from->connection->serial == current_serial)
705 adx 30 continue;
706    
707 michael 4796 if (match(mask, target_p->name))
708     continue;
709 adx 30
710 michael 4796 /*
711     * If we set the serial here, then we'll never do a
712     * match() again, if !IsCapable()
713     */
714     target_p->from->connection->serial = current_serial;
715 adx 30
716 michael 7222 if (cap && IsCapable(target_p->from, cap) != cap)
717 michael 4796 continue;
718    
719     send_message_remote(target_p->from, source_p, buffer);
720 adx 30 }
721 michael 3107
722 michael 3947 dbuf_ref_free(buffer);
723 adx 30 }
724    
725     /* sendto_anywhere()
726     *
727     * inputs - pointer to dest client
728     * - pointer to from client
729     * - varags
730     * output - NONE
731     * side effects - less efficient than sendto_remote and sendto_one
732     * but useful when one does not know where target "lives"
733     */
734     void
735 michael 7322 sendto_anywhere(struct Client *to, const struct Client *from,
736 michael 2793 const char *command,
737 adx 30 const char *pattern, ...)
738     {
739     va_list args;
740 michael 3189 struct dbuf_block *buffer = NULL;
741 adx 30
742 michael 2793 if (IsDead(to->from))
743 adx 30 return;
744    
745 michael 3107 buffer = dbuf_alloc();
746    
747 michael 3189 if (MyClient(to) && IsClient(from))
748     dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
749     from->host, command, to->name);
750 michael 2634 else
751 michael 3189 dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
752     command, ID_or_name(to, to));
753 adx 30
754     va_start(args, pattern);
755 michael 3107 send_format(buffer, pattern, args);
756 adx 30 va_end(args);
757    
758 michael 4804 if (MyConnect(to))
759 michael 3107 send_message(to, buffer);
760 adx 30 else
761 michael 4803 send_message_remote(to->from, from, buffer);
762 michael 3107
763     dbuf_ref_free(buffer);
764 adx 30 }
765    
766     /* sendto_realops_flags()
767     *
768     * inputs - flag types of messages to show to real opers
769     * - flag indicating opers/admins
770     * - var args input message
771     * output - NONE
772     * side effects - Send to *local* ops only but NOT +s nonopers.
773     */
774     void
775 michael 1618 sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
776 adx 30 {
777 michael 1618 const char *ntype = NULL;
778 michael 4815 dlink_node *node = NULL;
779 michael 3215 char nbuf[IRCD_BUFSIZE] = "";
780 adx 30 va_list args;
781    
782     va_start(args, pattern);
783 michael 1618 vsnprintf(nbuf, sizeof(nbuf), pattern, args);
784 adx 30 va_end(args);
785    
786 michael 1618 switch (type)
787 adx 30 {
788 michael 1618 case SEND_NOTICE:
789     ntype = "Notice";
790     break;
791     case SEND_GLOBAL:
792     ntype = "Global";
793     break;
794     case SEND_LOCOPS:
795     ntype = "LocOps";
796     break;
797     default:
798     assert(0);
799 adx 30 }
800    
801 michael 4815 DLINK_FOREACH(node, oper_list.head)
802 michael 1206 {
803 michael 4815 struct Client *client_p = node->data;
804 michael 1618 assert(HasUMode(client_p, UMODE_OPER));
805 michael 1206
806 michael 1618 /*
807     * If we're sending it to opers and they're an admin, skip.
808     * If we're sending it to admins, and they're not, skip.
809 michael 1206 */
810 michael 1219 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
811 michael 2638 ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
812 michael 1206 continue;
813    
814 michael 1219 if (HasUMode(client_p, flags))
815 michael 1618 sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
816     me.name, client_p->name, ntype, nbuf);
817 michael 1206 }
818     }
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 4431 sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
829 michael 3215 {
830     va_list args;
831     char buffer[IRCD_BUFSIZE] = "";
832    
833 michael 4431 if ((CurrentTime - *rate) < 20)
834     return;
835 michael 4890
836 michael 4431 *rate = CurrentTime;
837 michael 3215
838     va_start(args, pattern);
839     vsnprintf(buffer, sizeof(buffer), pattern, args);
840     va_end(args);
841    
842 michael 6318 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 7322 sendto_wallops_flags(unsigned int flags, const struct Client *source_p,
856 adx 30 const char *pattern, ...)
857     {
858 michael 4815 dlink_node *node = NULL;
859 adx 30 va_list args;
860 michael 4815 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 4815 DLINK_FOREACH(node, oper_list.head)
872 adx 30 {
873 michael 4815 struct Client *client_p = node->data;
874 adx 30 assert(client_p->umodes & UMODE_OPER);
875    
876 michael 1219 if (HasUMode(client_p, flags) && !IsDefunct(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 Revision