ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 7113
Committed: Sat Jan 23 20:31:25 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 23235 byte(s)
Log Message:
- Remove some HAVE_TLS

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

Properties

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