ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 1474
Committed: Sun Jul 22 14:44:07 2012 UTC (14 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/send.c
File size: 30764 byte(s)
Log Message:
- removed &localchannels

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * send.c: Functions for sending messages.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "send.h"
28     #include "channel.h"
29     #include "client.h"
30     #include "dbuf.h"
31     #include "irc_string.h"
32     #include "ircd.h"
33     #include "numeric.h"
34     #include "fdlist.h"
35     #include "s_bsd.h"
36     #include "s_serv.h"
37     #include "sprintf_irc.h"
38 michael 1309 #include "conf.h"
39     #include "log.h"
40 adx 30 #include "memory.h"
41     #include "hook.h"
42     #include "packet.h"
43    
44    
45     struct Callback *iosend_cb = NULL;
46 michael 1078 static unsigned int current_serial = 0;
47 adx 30
48    
49     /* send_format()
50     *
51     * inputs - buffer to format into
52     * - size of the buffer
53     * - format pattern to use
54     * - var args
55     * output - number of bytes formatted output
56     * side effects - modifies sendbuf
57     */
58     static inline int
59     send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
60     {
61     int len;
62    
63     /*
64     * from rfc1459
65     *
66     * IRC messages are always lines of characters terminated with a CR-LF
67     * (Carriage Return - Line Feed) pair, and these messages shall not
68     * exceed 512 characters in length, counting all characters
69     * including the trailing CR-LF.
70     * Thus, there are 510 characters maximum allowed
71     * for the command and its parameters. There is no provision for
72     * continuation message lines. See section 7 for more details about
73     * current implementations.
74     */
75     len = vsnprintf(lsendbuf, bufsize - 1, pattern, args);
76     if (len > bufsize - 2)
77     len = bufsize - 2; /* required by some versions of vsnprintf */
78    
79     lsendbuf[len++] = '\r';
80     lsendbuf[len++] = '\n';
81 michael 1078 return len;
82 adx 30 }
83    
84     /*
85 adx 163 * iosend_default - append a packet to the client's sendq.
86     */
87     void *
88     iosend_default(va_list args)
89     {
90     struct Client *to = va_arg(args, struct Client *);
91     int length = va_arg(args, int);
92     char *buf = va_arg(args, char *);
93    
94     dbuf_put(&to->localClient->buf_sendq, buf, length);
95     return NULL;
96     }
97    
98     /*
99 adx 30 ** send_message
100     ** Internal utility which appends given buffer to the sockets
101     ** sendq.
102     */
103     static void
104     send_message(struct Client *to, char *buf, int len)
105     {
106 michael 439 assert(!IsMe(to));
107 michael 438 assert(to != &me);
108 adx 30
109     if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
110     {
111     if (IsServer(to))
112     sendto_realops_flags(UMODE_ALL, L_ALL,
113     "Max SendQ limit exceeded for %s: %lu > %lu",
114     get_client_name(to, HIDE_IP),
115     (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
116     get_sendq(to));
117     if (IsClient(to))
118     SetSendQExceeded(to);
119     dead_link_on_write(to, 0);
120     return;
121     }
122    
123 adx 163 execute_callback(iosend_cb, to, len, buf);
124 adx 30
125     /*
126     ** Update statistics. The following is slightly incorrect
127     ** because it counts messages even if queued, but bytes
128     ** only really sent. Queued bytes get updated in SendQueued.
129     */
130     ++to->localClient->send.messages;
131     ++me.localClient->send.messages;
132    
133     if (dbuf_length(&to->localClient->buf_sendq) >
134     (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
135     send_queued_write(to);
136     }
137    
138     /* send_message_remote()
139     *
140     * inputs - pointer to client from message is being sent
141     * - pointer to client to send to
142     * - pointer to preformatted buffer
143     * - length of input buffer
144     * output - none
145     * side effects - Despite the function name, this only sends to directly
146     * connected clients.
147     *
148     */
149     static void
150     send_message_remote(struct Client *to, struct Client *from,
151     char *buf, int len)
152     {
153     if (!MyConnect(to))
154     {
155     sendto_realops_flags(UMODE_ALL, L_ALL,
156     "server send message to %s [%s] dropped from %s(Not local server)",
157     to->name, to->from->name, from->name);
158     return;
159     }
160    
161     /* Optimize by checking if (from && to) before everything */
162     /* we set to->from up there.. */
163    
164     if (!MyClient(from) && IsClient(to) && (to == from->from))
165     {
166     if (IsServer(from))
167     {
168     sendto_realops_flags(UMODE_ALL, L_ALL,
169     "Send message to %s [%s] dropped from %s(Fake Dir)",
170     to->name, to->from->name, from->name);
171     return;
172     }
173    
174     sendto_realops_flags(UMODE_ALL, L_ALL,
175     "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
176     to->name, to->username, to->host,
177     from->name, from->username, from->host,
178     to->from->name);
179    
180 michael 1474 sendto_server(NULL, CAP_TS6, NOCAPS,
181 adx 30 ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
182     me.id, to->name, me.name, to->name,
183     to->username, to->host, to->from->name);
184 michael 1474 sendto_server(NULL, NOCAPS, CAP_TS6,
185 adx 30 ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
186     me.name, to->name, me.name, to->name,
187     to->username, to->host, to->from->name);
188    
189 michael 1219 AddFlag(to, FLAGS_KILLED);
190 adx 30
191     if (IsClient(from))
192     sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
193     me.name, from->name, to->name, to->username,
194     to->host, to->from);
195    
196     exit_client(to, &me, "Ghosted client");
197    
198     return;
199     }
200    
201     send_message(to, buf, len);
202     }
203    
204     /*
205     ** sendq_unblocked
206     ** Called when a socket is ready for writing.
207     */
208     void
209     sendq_unblocked(fde_t *fd, struct Client *client_p)
210     {
211     ClearSendqBlocked(client_p);
212     /* let send_queued_write be executed by send_queued_all */
213    
214     #ifdef HAVE_LIBCRYPTO
215     if (fd->flags.pending_read)
216     {
217     fd->flags.pending_read = 0;
218     read_packet(fd, client_p);
219     }
220     #endif
221     }
222    
223     /*
224     ** send_queued_write
225     ** This is called when there is a chance that some output would
226     ** be possible. This attempts to empty the send queue as far as
227     ** possible, and then if any data is left, a write is rescheduled.
228     */
229     void
230     send_queued_write(struct Client *to)
231     {
232     int retlen;
233     struct dbuf_block *first;
234    
235     /*
236     ** Once socket is marked dead, we cannot start writing to it,
237     ** even if the error is removed...
238     */
239     if (IsDead(to) || IsSendqBlocked(to))
240     return; /* no use calling send() now */
241    
242     /* Next, lets try to write some data */
243    
244     if (dbuf_length(&to->localClient->buf_sendq))
245     {
246     do {
247     first = to->localClient->buf_sendq.blocks.head->data;
248    
249     #ifdef HAVE_LIBCRYPTO
250     if (to->localClient->fd.ssl)
251     {
252     retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
253    
254     /* translate openssl error codes, sigh */
255     if (retlen < 0)
256     switch (SSL_get_error(to->localClient->fd.ssl, retlen))
257     {
258     case SSL_ERROR_WANT_READ:
259     return; /* retry later, don't register for write events */
260    
261     case SSL_ERROR_WANT_WRITE:
262     errno = EWOULDBLOCK;
263     case SSL_ERROR_SYSCALL:
264     break;
265 michael 430 case SSL_ERROR_SSL:
266     if (errno == EAGAIN)
267     break;
268 adx 30 default:
269     retlen = errno = 0; /* either an SSL-specific error or EOF */
270     }
271     }
272     else
273     #endif
274     retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
275    
276     if (retlen <= 0)
277     break;
278    
279     dbuf_delete(&to->localClient->buf_sendq, retlen);
280    
281     /* We have some data written .. update counters */
282     to->localClient->send.bytes += retlen;
283     me.localClient->send.bytes += retlen;
284     } while (dbuf_length(&to->localClient->buf_sendq));
285    
286     if ((retlen < 0) && (ignoreErrno(errno)))
287     {
288     /* we have a non-fatal error, reschedule a write */
289     SetSendqBlocked(to);
290     comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
291     (PF *)sendq_unblocked, (void *)to, 0);
292     }
293     else if (retlen <= 0)
294     {
295     dead_link_on_write(to, errno);
296     return;
297     }
298     }
299     }
300    
301     /* send_queued_all()
302     *
303     * input - NONE
304     * output - NONE
305     * side effects - try to flush sendq of each client
306     */
307     void
308     send_queued_all(void)
309     {
310     dlink_node *ptr;
311    
312     /* Servers are processed first, mainly because this can generate
313     * a notice to opers, which is to be delivered by this function.
314     */
315     DLINK_FOREACH(ptr, serv_list.head)
316     send_queued_write((struct Client *) ptr->data);
317    
318     DLINK_FOREACH(ptr, unknown_list.head)
319     send_queued_write((struct Client *) ptr->data);
320    
321     DLINK_FOREACH(ptr, local_client_list.head)
322     send_queued_write((struct Client *) ptr->data);
323    
324     /* NOTE: This can still put clients on aborted_list; unfortunately,
325     * exit_aborted_clients takes precedence over send_queued_all,
326     * because exiting clients can generate server/oper traffic.
327     * The easiest approach is dealing with aborted clients in the next I/O lap.
328     * -adx
329     */
330     }
331    
332     /* sendto_one()
333     *
334     * inputs - pointer to destination client
335     * - var args message
336     * output - NONE
337     * side effects - send message to single client
338     */
339     void
340     sendto_one(struct Client *to, const char *pattern, ...)
341     {
342     va_list args;
343     char buffer[IRCD_BUFSIZE];
344     int len;
345    
346     if (to->from != NULL)
347     to = to->from;
348     if (IsDead(to))
349     return; /* This socket has already been marked as dead */
350    
351     va_start(args, pattern);
352     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
353     va_end(args);
354    
355     send_message(to, buffer, len);
356     }
357    
358     /* sendto_channel_butone()
359     *
360     * inputs - pointer to client(server) to NOT send message to
361     * - pointer to client that is sending this message
362     * - pointer to channel being sent to
363     * - vargs message
364     * output - NONE
365     * side effects - message as given is sent to given channel members.
366     *
367     * WARNING - +D clients are ignored
368     */
369     void
370     sendto_channel_butone(struct Client *one, struct Client *from,
371     struct Channel *chptr, const char *command,
372     const char *pattern, ...)
373     {
374 adx 285 va_list alocal, aremote, auid;
375 adx 30 char local_buf[IRCD_BUFSIZE];
376     char remote_buf[IRCD_BUFSIZE];
377     char uid_buf[IRCD_BUFSIZE];
378     int local_len, remote_len, uid_len;
379 michael 1078 dlink_node *ptr = NULL, *ptr_next = NULL;
380 adx 30
381     if (IsServer(from))
382     local_len = ircsprintf(local_buf, ":%s %s %s ",
383     from->name, command, chptr->chname);
384     else
385     local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
386     from->name, from->username, from->host,
387     command, chptr->chname);
388     remote_len = ircsprintf(remote_buf, ":%s %s %s ",
389     from->name, command, chptr->chname);
390     uid_len = ircsprintf(uid_buf, ":%s %s %s ",
391     ID(from), command, chptr->chname);
392    
393 adx 285 va_start(alocal, pattern);
394     va_start(aremote, pattern);
395     va_start(auid, pattern);
396 adx 30 local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
397 adx 285 pattern, alocal);
398 adx 30 remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
399 adx 285 pattern, aremote);
400 adx 30 uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
401 adx 285 auid);
402     va_end(auid);
403     va_end(aremote);
404     va_end(alocal);
405 adx 30
406     ++current_serial;
407    
408     DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
409     {
410 michael 1078 struct Client *target_p = ((struct Membership *)ptr->data)->client_p;
411 adx 30
412 michael 1078 assert(IsClient(target_p));
413    
414 michael 1219 if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one)
415 adx 30 continue;
416    
417 michael 1078 if (MyConnect(target_p))
418 adx 30 {
419 michael 1078 if (target_p->localClient->serial != current_serial)
420 adx 30 {
421     send_message(target_p, local_buf, local_len);
422 michael 1078 target_p->localClient->serial = current_serial;
423 adx 30 }
424     }
425     else
426     {
427     /* Now check whether a message has been sent to this
428     * remote link already
429     */
430 michael 1078 if (target_p->from->localClient->serial != current_serial)
431 adx 30 {
432     if (IsCapable(target_p->from, CAP_TS6))
433     send_message_remote(target_p->from, from, uid_buf, uid_len);
434     else
435     send_message_remote(target_p->from, from, remote_buf, remote_len);
436 michael 1078 target_p->from->localClient->serial = current_serial;
437 adx 30 }
438     }
439     }
440     }
441    
442     /* sendto_server()
443     *
444     * inputs - pointer to client to NOT send to
445 db 939 * - pointer to channel
446 adx 30 * - caps or'd together which must ALL be present
447     * - caps or'd together which must ALL NOT be present
448     * - printf style format string
449     * - args to format string
450     * output - NONE
451     * side effects - Send a message to all connected servers, except the
452     * client 'one' (if non-NULL), as long as the servers
453     * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
454     *
455     * This function was written in an attempt to merge together the other
456     * billion sendto_*serv*() functions, which sprung up with capabs,
457     * lazylinks, uids, etc.
458     * -davidt
459     */
460     void
461 michael 1474 sendto_server(struct Client *one,
462 michael 1015 const unsigned int caps,
463     const unsigned int nocaps,
464 adx 30 const char *format, ...)
465     {
466     va_list args;
467 michael 885 dlink_node *ptr = NULL;
468 adx 30 char buffer[IRCD_BUFSIZE];
469 michael 885 int len = 0;
470 adx 30
471     va_start(args, format);
472     len = send_format(buffer, IRCD_BUFSIZE, format, args);
473     va_end(args);
474    
475     DLINK_FOREACH(ptr, serv_list.head)
476     {
477 michael 885 struct Client *client_p = ptr->data;
478 adx 30
479     /* If dead already skip */
480     if (IsDead(client_p))
481     continue;
482     /* check against 'one' */
483     if (one != NULL && (client_p == one->from))
484     continue;
485     /* check we have required capabs */
486     if ((client_p->localClient->caps & caps) != caps)
487     continue;
488     /* check we don't have any forbidden capabs */
489     if ((client_p->localClient->caps & nocaps) != 0)
490     continue;
491    
492     send_message(client_p, buffer, len);
493     }
494     }
495    
496     /* sendto_common_channels_local()
497     *
498     * inputs - pointer to client
499     * - pattern to send
500     * output - NONE
501     * side effects - Sends a message to all people on local server who are
502     * in same channel with user.
503     * used by m_nick.c and exit_one_client.
504     */
505     void
506     sendto_common_channels_local(struct Client *user, int touser,
507     const char *pattern, ...)
508     {
509     va_list args;
510     dlink_node *uptr;
511     dlink_node *cptr;
512     struct Channel *chptr;
513     struct Membership *ms;
514     struct Client *target_p;
515     char buffer[IRCD_BUFSIZE];
516     int len;
517    
518     va_start(args, pattern);
519     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
520     va_end(args);
521    
522     ++current_serial;
523    
524     DLINK_FOREACH(cptr, user->channel.head)
525     {
526     chptr = ((struct Membership *) cptr->data)->chptr;
527     assert(chptr != NULL);
528    
529 michael 572 DLINK_FOREACH(uptr, chptr->members.head)
530 adx 30 {
531     ms = uptr->data;
532     target_p = ms->client_p;
533     assert(target_p != NULL);
534    
535 michael 572 if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
536 michael 1078 target_p->localClient->serial == current_serial)
537 adx 30 continue;
538    
539 michael 1078 target_p->localClient->serial = current_serial;
540 adx 30 send_message(target_p, buffer, len);
541     }
542     }
543    
544     if (touser && MyConnect(user) && !IsDead(user) &&
545 michael 1078 user->localClient->serial != current_serial)
546 adx 30 send_message(user, buffer, len);
547     }
548    
549     /* sendto_channel_local()
550     *
551     * inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
552     * - whether to ignore +D clients (YES/NO)
553     * - pointer to channel to send to
554     * - var args pattern
555     * output - NONE
556     * side effects - Send a message to all members of a channel that are
557     * locally connected to this server.
558     */
559     void
560     sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
561     const char *pattern, ...)
562     {
563     va_list args;
564     char buffer[IRCD_BUFSIZE];
565     int len;
566     dlink_node *ptr;
567     struct Membership *ms;
568     struct Client *target_p;
569    
570     va_start(args, pattern);
571     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
572     va_end(args);
573    
574 michael 572 DLINK_FOREACH(ptr, chptr->members.head)
575 adx 30 {
576     ms = ptr->data;
577     target_p = ms->client_p;
578    
579     if (type != 0 && (ms->flags & type) == 0)
580     continue;
581    
582 michael 572 if (!MyConnect(target_p) || IsDefunct(target_p) ||
583 michael 1219 (nodeaf && HasUMode(target_p, UMODE_DEAF)))
584 adx 30 continue;
585    
586     send_message(target_p, buffer, len);
587     }
588     }
589    
590     /* sendto_channel_local_butone()
591     *
592     * inputs - pointer to client to NOT send message to
593     * - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
594     * - pointer to channel to send to
595     * - var args pattern
596     * output - NONE
597     * side effects - Send a message to all members of a channel that are
598     * locally connected to this server except one.
599     *
600     * WARNING - +D clients are omitted
601     */
602     void
603     sendto_channel_local_butone(struct Client *one, int type,
604     struct Channel *chptr, const char *pattern, ...)
605     {
606     va_list args;
607     char buffer[IRCD_BUFSIZE];
608     int len;
609     struct Client *target_p;
610     struct Membership *ms;
611     dlink_node *ptr;
612    
613     va_start(args, pattern);
614     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
615     va_end(args);
616    
617 michael 572 DLINK_FOREACH(ptr, chptr->members.head)
618 adx 30 {
619     ms = ptr->data;
620     target_p = ms->client_p;
621    
622     if (type != 0 && (ms->flags & type) == 0)
623     continue;
624    
625 michael 572 if (!MyConnect(target_p) || target_p == one ||
626 michael 1219 IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
627 adx 30 continue;
628     send_message(target_p, buffer, len);
629     }
630     }
631    
632    
633     /* sendto_channel_remote()
634     *
635     * inputs - Client not to send towards
636     * - Client from whom message is from
637     * - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
638     * - pointer to channel to send to
639     * - var args pattern
640     * output - NONE
641     * side effects - Send a message to all members of a channel that are
642     * remote to this server.
643     */
644     void
645 michael 1015 sendto_channel_remote(struct Client *one, struct Client *from, int type,
646     const unsigned int caps, const unsigned int nocaps,
647     struct Channel *chptr, const char *pattern, ...)
648 adx 30 {
649     va_list args;
650     char buffer[IRCD_BUFSIZE];
651     int len;
652     dlink_node *ptr;
653     struct Client *target_p;
654     struct Membership *ms;
655    
656     va_start(args, pattern);
657     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
658     va_end(args);
659    
660 db 189 ++current_serial;
661    
662 adx 30 DLINK_FOREACH(ptr, chptr->members.head)
663     {
664     ms = ptr->data;
665     target_p = ms->client_p;
666    
667     if (type != 0 && (ms->flags & type) == 0)
668     continue;
669    
670     if (MyConnect(target_p))
671     continue;
672     target_p = target_p->from;
673    
674     if (target_p == one->from ||
675     ((target_p->from->localClient->caps & caps) != caps) ||
676     ((target_p->from->localClient->caps & nocaps) != 0))
677     continue;
678 michael 1078 if (target_p->from->localClient->serial != current_serial)
679 db 189 {
680     send_message(target_p, buffer, len);
681 michael 1078 target_p->from->localClient->serial = current_serial;
682 db 189 }
683 adx 30 }
684     }
685    
686     /*
687     ** match_it() and sendto_match_butone() ARE only used
688     ** to send a msg to all ppl on servers/hosts that match a specified mask
689     ** (used for enhanced PRIVMSGs) for opers
690     **
691     ** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
692     **
693     */
694    
695     /* match_it()
696     *
697     * inputs - client pointer to match on
698     * - actual mask to match
699     * - what to match on, HOST or SERVER
700     * output - 1 or 0 if match or not
701     * side effects - NONE
702     */
703     static int
704     match_it(const struct Client *one, const char *mask, int what)
705     {
706     if (what == MATCH_HOST)
707 michael 1078 return match(mask, one->host);
708 adx 30
709 michael 1078 return match(mask, one->servptr->name);
710 adx 30 }
711    
712     /* sendto_match_butone()
713     *
714     * Send to all clients which match the mask in a way defined on 'what';
715     * either by user hostname or user servername.
716     *
717     * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
718     */
719     void
720     sendto_match_butone(struct Client *one, struct Client *from, char *mask,
721     int what, const char *pattern, ...)
722     {
723 adx 285 va_list alocal, aremote;
724 adx 30 struct Client *client_p;
725     dlink_node *ptr, *ptr_next;
726     char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
727     int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
728     from->username, from->host);
729     int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
730    
731 adx 285 va_start(alocal, pattern);
732     va_start(aremote, pattern);
733 adx 30 local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
734 adx 285 pattern, alocal);
735 adx 30 remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
736 adx 285 pattern, aremote);
737     va_end(aremote);
738     va_end(alocal);
739 adx 30
740     /* scan the local clients */
741     DLINK_FOREACH(ptr, local_client_list.head)
742     {
743     client_p = ptr->data;
744    
745     if (client_p != one && !IsDefunct(client_p) &&
746     match_it(client_p, mask, what))
747     send_message(client_p, local_buf, local_len);
748     }
749    
750     /* Now scan servers */
751     DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
752     {
753     client_p = ptr->data;
754    
755     /*
756     * The old code looped through every client on the
757     * network for each server to check if the
758     * server (client_p) has at least 1 client matching
759     * the mask, using something like:
760     *
761     * for (target_p = GlobalClientList; target_p; target_p = target_p->next)
762     * if (IsRegisteredUser(target_p) &&
763     * match_it(target_p, mask, what) &&
764     * (target_p->from == client_p))
765     * vsendto_prefix_one(client_p, from, pattern, args);
766     *
767     * That way, we wouldn't send the message to
768     * a server who didn't have a matching client.
769     * However, on a network such as EFNet, that
770     * code would have looped through about 50
771     * servers, and in each loop, loop through
772     * about 50k clients as well, calling match()
773     * in each nested loop. That is a very bad
774     * thing cpu wise - just send the message
775     * to every connected server and let that
776     * server deal with it.
777     * -wnder
778     */
779     if (client_p != one && !IsDefunct(client_p))
780     send_message_remote(client_p, from, remote_buf, remote_len);
781     }
782     }
783    
784     /* sendto_match_servs()
785     *
786     * inputs - source client
787     * - mask to send to
788     * - capab needed
789     * - data
790     * outputs - none
791     * side effects - data sent to servers matching with capab
792     */
793     void
794     sendto_match_servs(struct Client *source_p, const char *mask, int cap,
795     const char *pattern, ...)
796     {
797     va_list args;
798     struct Client *target_p;
799     dlink_node *ptr;
800     char buffer[IRCD_BUFSIZE];
801     int found = 0;
802    
803     va_start(args, pattern);
804     vsnprintf(buffer, sizeof(buffer), pattern, args);
805     va_end(args);
806    
807 michael 948 ++current_serial;
808 adx 30
809     DLINK_FOREACH(ptr, global_serv_list.head)
810     {
811     target_p = ptr->data;
812    
813     /* Do not attempt to send to ourselves, or the source */
814     if (IsMe(target_p) || target_p->from == source_p->from)
815     continue;
816    
817 michael 1078 if (target_p->from->localClient->serial == current_serial)
818 adx 30 continue;
819    
820     if (match(mask, target_p->name))
821     {
822     /*
823     * if we set the serial here, then we'll never do a
824     * match() again, if !IsCapable()
825     */
826 michael 1078 target_p->from->localClient->serial = current_serial;
827 adx 30 found++;
828    
829     if (!IsCapable(target_p->from, cap))
830     continue;
831    
832     sendto_anywhere(target_p, source_p, "%s", buffer);
833     }
834     }
835     }
836    
837     /* sendto_anywhere()
838     *
839     * inputs - pointer to dest client
840     * - pointer to from client
841     * - varags
842     * output - NONE
843     * side effects - less efficient than sendto_remote and sendto_one
844     * but useful when one does not know where target "lives"
845     */
846     void
847     sendto_anywhere(struct Client *to, struct Client *from,
848     const char *pattern, ...)
849     {
850     va_list args;
851     char buffer[IRCD_BUFSIZE];
852     int len;
853     struct Client *send_to = (to->from != NULL ? to->from : to);
854    
855     if (IsDead(send_to))
856     return;
857    
858     if (MyClient(to))
859     {
860     if (IsServer(from))
861     {
862     if (IsCapable(to, CAP_TS6) && HasID(from))
863     len = ircsprintf(buffer, ":%s ", from->id);
864     else
865     len = ircsprintf(buffer, ":%s ", from->name);
866     }
867     else
868     len = ircsprintf(buffer, ":%s!%s@%s ",
869     from->name, from->username, from->host);
870     }
871     else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
872    
873     va_start(args, pattern);
874     len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
875     va_end(args);
876    
877     if(MyClient(to))
878     send_message(send_to, buffer, len);
879     else
880     send_message_remote(send_to, from, buffer, len);
881     }
882    
883     /* sendto_realops_flags()
884     *
885     * inputs - flag types of messages to show to real opers
886     * - flag indicating opers/admins
887     * - var args input message
888     * output - NONE
889     * side effects - Send to *local* ops only but NOT +s nonopers.
890     */
891     void
892     sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
893     {
894 michael 1078 dlink_node *ptr = NULL;
895 adx 30 char nbuf[IRCD_BUFSIZE];
896     va_list args;
897    
898     va_start(args, pattern);
899     vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
900     va_end(args);
901    
902     DLINK_FOREACH(ptr, oper_list.head)
903     {
904 michael 1078 struct Client *client_p = ptr->data;
905 michael 1219 assert(HasUMode(client_p, UMODE_OPER));
906 adx 30
907     /* If we're sending it to opers and theyre an admin, skip.
908     * If we're sending it to admins, and theyre not, skip.
909     */
910 michael 1219 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
911     ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
912 adx 30 continue;
913    
914 michael 1219 if (HasUMode(client_p, flags))
915 adx 30 sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
916     me.name, client_p->name, nbuf);
917     }
918     }
919    
920 michael 1206 void
921     sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...)
922     {
923     dlink_node *ptr = NULL;
924     char nbuf[IRCD_BUFSIZE];
925     va_list args;
926    
927     va_start(args, pattern);
928     vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
929     va_end(args);
930    
931     DLINK_FOREACH(ptr, oper_list.head)
932     {
933     struct Client *client_p = ptr->data;
934     assert(client_p->umodes & UMODE_OPER);
935    
936     /* If we're sending it to opers and theyre an admin, skip.
937     * If we're sending it to admins, and theyre not, skip.
938     */
939 michael 1219 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
940     ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
941 michael 1206 continue;
942    
943 michael 1219 if (HasUMode(client_p, flags))
944 michael 1206 sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s",
945     me.name, client_p->name, nbuf);
946     }
947     }
948    
949 adx 30 /* sendto_wallops_flags()
950     *
951     * inputs - flag types of messages to show to real opers
952     * - client sending request
953     * - var args input message
954     * output - NONE
955     * side effects - Send a wallops to local opers
956     */
957     void
958     sendto_wallops_flags(unsigned int flags, struct Client *source_p,
959     const char *pattern, ...)
960     {
961 michael 1078 dlink_node *ptr = NULL;
962 adx 30 va_list args;
963     char buffer[IRCD_BUFSIZE];
964     int len;
965    
966     if (IsClient(source_p))
967     len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
968     source_p->name, source_p->username, source_p->host);
969     else
970     len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
971    
972     va_start(args, pattern);
973     len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
974     va_end(args);
975    
976     DLINK_FOREACH(ptr, oper_list.head)
977     {
978 michael 1078 struct Client *client_p = ptr->data;
979 adx 30 assert(client_p->umodes & UMODE_OPER);
980    
981 michael 1219 if (HasUMode(client_p, flags) && !IsDefunct(client_p))
982 adx 30 send_message(client_p, buffer, len);
983     }
984     }
985    
986     /* ts_warn()
987     *
988     * inputs - var args message
989     * output - NONE
990     * side effects - Call sendto_realops_flags, with some flood checking
991     * (at most 5 warnings every 5 seconds)
992     */
993     void
994     ts_warn(const char *pattern, ...)
995     {
996     va_list args;
997 michael 1078 char buffer[IRCD_BUFSIZE];
998 adx 30 static time_t last = 0;
999     static int warnings = 0;
1000    
1001     /*
1002     ** if we're running with TS_WARNINGS enabled and someone does
1003     ** something silly like (remotely) connecting a nonTS server,
1004     ** we'll get a ton of warnings, so we make sure we don't send
1005     ** more than 5 every 5 seconds. -orabidoo
1006     */
1007    
1008     if (CurrentTime - last < 5)
1009     {
1010     if (++warnings > 5)
1011     return;
1012     }
1013     else
1014     {
1015     last = CurrentTime;
1016     warnings = 0;
1017     }
1018    
1019     va_start(args, pattern);
1020 michael 1086 vsnprintf(buffer, sizeof(buffer), pattern, args);
1021 adx 30 va_end(args);
1022    
1023     sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1024 michael 1247 ilog(LOG_TYPE_IRCD, "%s", buffer);
1025 adx 30 }
1026    
1027     /* kill_client()
1028     *
1029     * inputs - client to send kill towards
1030     * - pointer to client to kill
1031     * - reason for kill
1032     * output - NONE
1033     * side effects - NONE
1034     */
1035     void
1036     kill_client(struct Client *client_p, struct Client *diedie,
1037     const char *pattern, ...)
1038     {
1039     va_list args;
1040     char buffer[IRCD_BUFSIZE];
1041     int len;
1042    
1043     if (client_p->from != NULL)
1044     client_p = client_p->from;
1045     if (IsDead(client_p))
1046     return;
1047    
1048     len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1049     ID_or_name(diedie, client_p));
1050    
1051     va_start(args, pattern);
1052     len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1053     va_end(args);
1054    
1055     send_message(client_p, buffer, len);
1056     }
1057    
1058     /* kill_client_ll_serv_butone()
1059     *
1060     * inputs - pointer to client to not send to
1061     * - pointer to client to kill
1062     * output - NONE
1063     * side effects - Send a KILL for the given client
1064     * message to all connected servers
1065     * except the client 'one'. Also deal with
1066     * client being unknown to leaf, as in lazylink...
1067     */
1068     void
1069     kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1070     const char *pattern, ...)
1071     {
1072     va_list args;
1073     int have_uid = 0;
1074 michael 885 dlink_node *ptr = NULL;
1075 adx 30 char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1076 michael 885 int len_uid = 0, len_nick = 0;
1077 adx 30
1078 michael 1115 if (HasID(source_p))
1079 adx 30 {
1080     have_uid = 1;
1081 adx 285 va_start(args, pattern);
1082 adx 30 len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1083     len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1084     args);
1085 adx 285 va_end(args);
1086 adx 30 }
1087 adx 285
1088     va_start(args, pattern);
1089 adx 30 len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1090     len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1091     args);
1092     va_end(args);
1093    
1094     DLINK_FOREACH(ptr, serv_list.head)
1095     {
1096 michael 885 struct Client *client_p = ptr->data;
1097 adx 30
1098     if (one != NULL && (client_p == one->from))
1099     continue;
1100     if (IsDefunct(client_p))
1101     continue;
1102    
1103 michael 885 if (have_uid && IsCapable(client_p, CAP_TS6))
1104     send_message(client_p, buf_uid, len_uid);
1105     else
1106     send_message(client_p, buf_nick, len_nick);
1107 adx 30 }
1108     }

Properties

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