ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
Revision: 1734
Committed: Fri Jan 11 12:59:24 2013 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 30465 byte(s)
Log Message:
- Add support for "away-notify" client capability

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 michael 1632 if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(&to->localClient->confs))
110 adx 30 {
111     if (IsServer(to))
112 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
113 adx 30 "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 michael 1632 get_sendq(&to->localClient->confs));
117 adx 30 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 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
156 adx 30 "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 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
169 adx 30 "Send message to %s [%s] dropped from %s(Fake Dir)",
170     to->name, to->from->name, from->name);
171     return;
172     }
173    
174 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
175 adx 30 "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 michael 1479 struct Channel *chptr, unsigned int type,
372 adx 30 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 michael 1479 local_len = ircsprintf(local_buf, ":%s ",
383     from->name);
384 adx 30 else
385 michael 1479 local_len = ircsprintf(local_buf, ":%s!%s@%s ",
386     from->name, from->username, from->host);
387     remote_len = ircsprintf(remote_buf, ":%s ",
388     from->name);
389     uid_len = ircsprintf(uid_buf, ":%s ",
390     ID(from));
391 adx 30
392 adx 285 va_start(alocal, pattern);
393     va_start(aremote, pattern);
394     va_start(auid, pattern);
395 adx 30 local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
396 adx 285 pattern, alocal);
397 adx 30 remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
398 adx 285 pattern, aremote);
399 adx 30 uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
400 adx 285 auid);
401     va_end(auid);
402     va_end(aremote);
403     va_end(alocal);
404 adx 30
405     ++current_serial;
406    
407     DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
408     {
409 michael 1479 struct Membership *ms = ptr->data;
410     struct Client *target_p = ms->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 1479 if (type != 0 && (ms->flags & type) == 0)
418     continue;
419    
420 michael 1078 if (MyConnect(target_p))
421 adx 30 {
422 michael 1078 if (target_p->localClient->serial != current_serial)
423 adx 30 {
424     send_message(target_p, local_buf, local_len);
425 michael 1078 target_p->localClient->serial = current_serial;
426 adx 30 }
427     }
428     else
429     {
430     /* Now check whether a message has been sent to this
431     * remote link already
432     */
433 michael 1078 if (target_p->from->localClient->serial != current_serial)
434 adx 30 {
435     if (IsCapable(target_p->from, CAP_TS6))
436     send_message_remote(target_p->from, from, uid_buf, uid_len);
437     else
438     send_message_remote(target_p->from, from, remote_buf, remote_len);
439 michael 1078 target_p->from->localClient->serial = current_serial;
440 adx 30 }
441     }
442     }
443     }
444    
445     /* sendto_server()
446     *
447     * inputs - pointer to client to NOT send to
448 db 939 * - pointer to channel
449 adx 30 * - caps or'd together which must ALL be present
450     * - caps or'd together which must ALL NOT be present
451     * - printf style format string
452     * - args to format string
453     * output - NONE
454     * side effects - Send a message to all connected servers, except the
455     * client 'one' (if non-NULL), as long as the servers
456     * support ALL capabs in 'caps', and NO capabs in 'nocaps'.
457     *
458     * This function was written in an attempt to merge together the other
459     * billion sendto_*serv*() functions, which sprung up with capabs,
460     * lazylinks, uids, etc.
461     * -davidt
462     */
463     void
464 michael 1474 sendto_server(struct Client *one,
465 michael 1015 const unsigned int caps,
466     const unsigned int nocaps,
467 adx 30 const char *format, ...)
468     {
469     va_list args;
470 michael 885 dlink_node *ptr = NULL;
471 adx 30 char buffer[IRCD_BUFSIZE];
472 michael 885 int len = 0;
473 adx 30
474     va_start(args, format);
475     len = send_format(buffer, IRCD_BUFSIZE, format, args);
476     va_end(args);
477    
478     DLINK_FOREACH(ptr, serv_list.head)
479     {
480 michael 885 struct Client *client_p = ptr->data;
481 adx 30
482     /* If dead already skip */
483     if (IsDead(client_p))
484     continue;
485     /* check against 'one' */
486     if (one != NULL && (client_p == one->from))
487     continue;
488     /* check we have required capabs */
489     if ((client_p->localClient->caps & caps) != caps)
490     continue;
491     /* check we don't have any forbidden capabs */
492     if ((client_p->localClient->caps & nocaps) != 0)
493     continue;
494    
495     send_message(client_p, buffer, len);
496     }
497     }
498    
499     /* sendto_common_channels_local()
500     *
501     * inputs - pointer to client
502     * - pattern to send
503     * output - NONE
504     * side effects - Sends a message to all people on local server who are
505     * in same channel with user.
506     * used by m_nick.c and exit_one_client.
507     */
508     void
509 michael 1734 sendto_common_channels_local(struct Client *user, int touser, unsigned int cap,
510 adx 30 const char *pattern, ...)
511     {
512     va_list args;
513     dlink_node *uptr;
514     dlink_node *cptr;
515     struct Channel *chptr;
516     struct Membership *ms;
517     struct Client *target_p;
518     char buffer[IRCD_BUFSIZE];
519     int len;
520    
521     va_start(args, pattern);
522     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
523     va_end(args);
524    
525     ++current_serial;
526    
527     DLINK_FOREACH(cptr, user->channel.head)
528     {
529     chptr = ((struct Membership *) cptr->data)->chptr;
530     assert(chptr != NULL);
531    
532 michael 572 DLINK_FOREACH(uptr, chptr->members.head)
533 adx 30 {
534     ms = uptr->data;
535     target_p = ms->client_p;
536     assert(target_p != NULL);
537    
538 michael 572 if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
539 michael 1078 target_p->localClient->serial == current_serial)
540 adx 30 continue;
541    
542 michael 1734 if (HasCap(target_p, cap) != cap)
543     continue;
544    
545 michael 1078 target_p->localClient->serial = current_serial;
546 adx 30 send_message(target_p, buffer, len);
547     }
548     }
549    
550     if (touser && MyConnect(user) && !IsDead(user) &&
551 michael 1078 user->localClient->serial != current_serial)
552 michael 1734 if (HasCap(target_p, cap) == cap)
553     send_message(user, buffer, len);
554 adx 30 }
555    
556     /* sendto_channel_local()
557     *
558     * inputs - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
559     * - whether to ignore +D clients (YES/NO)
560     * - pointer to channel to send to
561     * - var args pattern
562     * output - NONE
563     * side effects - Send a message to all members of a channel that are
564     * locally connected to this server.
565     */
566     void
567     sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
568     const char *pattern, ...)
569     {
570     va_list args;
571     char buffer[IRCD_BUFSIZE];
572     int len;
573     dlink_node *ptr;
574     struct Membership *ms;
575     struct Client *target_p;
576    
577     va_start(args, pattern);
578     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
579     va_end(args);
580    
581 michael 572 DLINK_FOREACH(ptr, chptr->members.head)
582 adx 30 {
583     ms = ptr->data;
584     target_p = ms->client_p;
585    
586     if (type != 0 && (ms->flags & type) == 0)
587     continue;
588    
589 michael 572 if (!MyConnect(target_p) || IsDefunct(target_p) ||
590 michael 1219 (nodeaf && HasUMode(target_p, UMODE_DEAF)))
591 adx 30 continue;
592    
593     send_message(target_p, buffer, len);
594     }
595     }
596    
597     /* sendto_channel_local_butone()
598     *
599     * inputs - pointer to client to NOT send message to
600     * - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
601     * - pointer to channel to send to
602     * - var args pattern
603     * output - NONE
604     * side effects - Send a message to all members of a channel that are
605     * locally connected to this server except one.
606     *
607     * WARNING - +D clients are omitted
608     */
609     void
610 michael 1734 sendto_channel_local_butone(struct Client *one, int type, unsigned int cap,
611 adx 30 struct Channel *chptr, const char *pattern, ...)
612     {
613     va_list args;
614     char buffer[IRCD_BUFSIZE];
615     int len;
616     struct Client *target_p;
617     struct Membership *ms;
618     dlink_node *ptr;
619    
620     va_start(args, pattern);
621     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
622     va_end(args);
623    
624 michael 572 DLINK_FOREACH(ptr, chptr->members.head)
625 adx 30 {
626     ms = ptr->data;
627     target_p = ms->client_p;
628    
629     if (type != 0 && (ms->flags & type) == 0)
630     continue;
631    
632 michael 572 if (!MyConnect(target_p) || target_p == one ||
633 michael 1219 IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF))
634 adx 30 continue;
635 michael 1734
636     if (HasCap(target_p, cap) != cap)
637     continue;
638 adx 30 send_message(target_p, buffer, len);
639     }
640     }
641    
642    
643     /* sendto_channel_remote()
644     *
645     * inputs - Client not to send towards
646     * - Client from whom message is from
647     * - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
648     * - pointer to channel to send to
649     * - var args pattern
650     * output - NONE
651     * side effects - Send a message to all members of a channel that are
652     * remote to this server.
653     */
654     void
655 michael 1015 sendto_channel_remote(struct Client *one, struct Client *from, int type,
656     const unsigned int caps, const unsigned int nocaps,
657     struct Channel *chptr, const char *pattern, ...)
658 adx 30 {
659     va_list args;
660     char buffer[IRCD_BUFSIZE];
661     int len;
662     dlink_node *ptr;
663     struct Client *target_p;
664     struct Membership *ms;
665    
666     va_start(args, pattern);
667     len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
668     va_end(args);
669    
670 db 189 ++current_serial;
671    
672 adx 30 DLINK_FOREACH(ptr, chptr->members.head)
673     {
674     ms = ptr->data;
675     target_p = ms->client_p;
676    
677     if (type != 0 && (ms->flags & type) == 0)
678     continue;
679    
680     if (MyConnect(target_p))
681     continue;
682     target_p = target_p->from;
683    
684     if (target_p == one->from ||
685     ((target_p->from->localClient->caps & caps) != caps) ||
686     ((target_p->from->localClient->caps & nocaps) != 0))
687     continue;
688 michael 1078 if (target_p->from->localClient->serial != current_serial)
689 db 189 {
690     send_message(target_p, buffer, len);
691 michael 1078 target_p->from->localClient->serial = current_serial;
692 db 189 }
693 adx 30 }
694     }
695    
696     /*
697     ** match_it() and sendto_match_butone() ARE only used
698     ** to send a msg to all ppl on servers/hosts that match a specified mask
699     ** (used for enhanced PRIVMSGs) for opers
700     **
701     ** addition -- Armin, 8jun90 (gruner@informatik.tu-muenchen.de)
702     **
703     */
704    
705     /* match_it()
706     *
707     * inputs - client pointer to match on
708     * - actual mask to match
709     * - what to match on, HOST or SERVER
710     * output - 1 or 0 if match or not
711     * side effects - NONE
712     */
713     static int
714     match_it(const struct Client *one, const char *mask, int what)
715     {
716     if (what == MATCH_HOST)
717 michael 1652 return !match(mask, one->host);
718 adx 30
719 michael 1652 return !match(mask, one->servptr->name);
720 adx 30 }
721    
722     /* sendto_match_butone()
723     *
724     * Send to all clients which match the mask in a way defined on 'what';
725     * either by user hostname or user servername.
726     *
727     * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
728     */
729     void
730     sendto_match_butone(struct Client *one, struct Client *from, char *mask,
731     int what, const char *pattern, ...)
732     {
733 adx 285 va_list alocal, aremote;
734 adx 30 struct Client *client_p;
735     dlink_node *ptr, *ptr_next;
736     char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
737     int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
738     from->username, from->host);
739     int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
740    
741 adx 285 va_start(alocal, pattern);
742     va_start(aremote, pattern);
743 adx 30 local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
744 adx 285 pattern, alocal);
745 adx 30 remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
746 adx 285 pattern, aremote);
747     va_end(aremote);
748     va_end(alocal);
749 adx 30
750     /* scan the local clients */
751     DLINK_FOREACH(ptr, local_client_list.head)
752     {
753     client_p = ptr->data;
754    
755     if (client_p != one && !IsDefunct(client_p) &&
756     match_it(client_p, mask, what))
757     send_message(client_p, local_buf, local_len);
758     }
759    
760     /* Now scan servers */
761     DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
762     {
763     client_p = ptr->data;
764    
765     /*
766     * The old code looped through every client on the
767     * network for each server to check if the
768     * server (client_p) has at least 1 client matching
769     * the mask, using something like:
770     *
771     * for (target_p = GlobalClientList; target_p; target_p = target_p->next)
772     * if (IsRegisteredUser(target_p) &&
773     * match_it(target_p, mask, what) &&
774     * (target_p->from == client_p))
775     * vsendto_prefix_one(client_p, from, pattern, args);
776     *
777     * That way, we wouldn't send the message to
778     * a server who didn't have a matching client.
779     * However, on a network such as EFNet, that
780     * code would have looped through about 50
781     * servers, and in each loop, loop through
782     * about 50k clients as well, calling match()
783     * in each nested loop. That is a very bad
784     * thing cpu wise - just send the message
785     * to every connected server and let that
786     * server deal with it.
787     * -wnder
788     */
789     if (client_p != one && !IsDefunct(client_p))
790     send_message_remote(client_p, from, remote_buf, remote_len);
791     }
792     }
793    
794     /* sendto_match_servs()
795     *
796     * inputs - source client
797     * - mask to send to
798     * - capab needed
799     * - data
800     * outputs - none
801     * side effects - data sent to servers matching with capab
802     */
803     void
804     sendto_match_servs(struct Client *source_p, const char *mask, int cap,
805     const char *pattern, ...)
806     {
807     va_list args;
808     struct Client *target_p;
809     dlink_node *ptr;
810     char buffer[IRCD_BUFSIZE];
811     int found = 0;
812    
813     va_start(args, pattern);
814     vsnprintf(buffer, sizeof(buffer), pattern, args);
815     va_end(args);
816    
817 michael 948 ++current_serial;
818 adx 30
819     DLINK_FOREACH(ptr, global_serv_list.head)
820     {
821     target_p = ptr->data;
822    
823     /* Do not attempt to send to ourselves, or the source */
824     if (IsMe(target_p) || target_p->from == source_p->from)
825     continue;
826    
827 michael 1078 if (target_p->from->localClient->serial == current_serial)
828 adx 30 continue;
829    
830 michael 1652 if (!match(mask, target_p->name))
831 adx 30 {
832     /*
833     * if we set the serial here, then we'll never do a
834     * match() again, if !IsCapable()
835     */
836 michael 1078 target_p->from->localClient->serial = current_serial;
837 adx 30 found++;
838    
839     if (!IsCapable(target_p->from, cap))
840     continue;
841    
842     sendto_anywhere(target_p, source_p, "%s", buffer);
843     }
844     }
845     }
846    
847     /* sendto_anywhere()
848     *
849     * inputs - pointer to dest client
850     * - pointer to from client
851     * - varags
852     * output - NONE
853     * side effects - less efficient than sendto_remote and sendto_one
854     * but useful when one does not know where target "lives"
855     */
856     void
857     sendto_anywhere(struct Client *to, struct Client *from,
858     const char *pattern, ...)
859     {
860     va_list args;
861     char buffer[IRCD_BUFSIZE];
862     int len;
863     struct Client *send_to = (to->from != NULL ? to->from : to);
864    
865     if (IsDead(send_to))
866     return;
867    
868     if (MyClient(to))
869     {
870     if (IsServer(from))
871     {
872     if (IsCapable(to, CAP_TS6) && HasID(from))
873     len = ircsprintf(buffer, ":%s ", from->id);
874     else
875     len = ircsprintf(buffer, ":%s ", from->name);
876     }
877     else
878     len = ircsprintf(buffer, ":%s!%s@%s ",
879     from->name, from->username, from->host);
880     }
881     else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
882    
883     va_start(args, pattern);
884     len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
885     va_end(args);
886    
887     if(MyClient(to))
888     send_message(send_to, buffer, len);
889     else
890     send_message_remote(send_to, from, buffer, len);
891     }
892    
893     /* sendto_realops_flags()
894     *
895     * inputs - flag types of messages to show to real opers
896     * - flag indicating opers/admins
897     * - var args input message
898     * output - NONE
899     * side effects - Send to *local* ops only but NOT +s nonopers.
900     */
901     void
902 michael 1618 sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
903 adx 30 {
904 michael 1618 const char *ntype = NULL;
905 michael 1078 dlink_node *ptr = NULL;
906 adx 30 char nbuf[IRCD_BUFSIZE];
907     va_list args;
908    
909     va_start(args, pattern);
910 michael 1618 vsnprintf(nbuf, sizeof(nbuf), pattern, args);
911 adx 30 va_end(args);
912    
913 michael 1618 switch (type)
914 adx 30 {
915 michael 1618 case SEND_NOTICE:
916     ntype = "Notice";
917     break;
918     case SEND_GLOBAL:
919     ntype = "Global";
920     break;
921     case SEND_LOCOPS:
922     ntype = "LocOps";
923     break;
924     default:
925     assert(0);
926 adx 30 }
927    
928 michael 1206 DLINK_FOREACH(ptr, oper_list.head)
929     {
930     struct Client *client_p = ptr->data;
931 michael 1618 assert(HasUMode(client_p, UMODE_OPER));
932 michael 1206
933 michael 1618 /*
934     * If we're sending it to opers and they're an admin, skip.
935     * If we're sending it to admins, and they're not, skip.
936 michael 1206 */
937 michael 1219 if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
938 michael 1618 ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
939 michael 1206 continue;
940    
941 michael 1219 if (HasUMode(client_p, flags))
942 michael 1618 sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
943     me.name, client_p->name, ntype, nbuf);
944 michael 1206 }
945     }
946    
947 adx 30 /* sendto_wallops_flags()
948     *
949     * inputs - flag types of messages to show to real opers
950     * - client sending request
951     * - var args input message
952     * output - NONE
953     * side effects - Send a wallops to local opers
954     */
955     void
956     sendto_wallops_flags(unsigned int flags, struct Client *source_p,
957     const char *pattern, ...)
958     {
959 michael 1078 dlink_node *ptr = NULL;
960 adx 30 va_list args;
961     char buffer[IRCD_BUFSIZE];
962     int len;
963    
964     if (IsClient(source_p))
965     len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
966     source_p->name, source_p->username, source_p->host);
967     else
968     len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
969    
970     va_start(args, pattern);
971     len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
972     va_end(args);
973    
974     DLINK_FOREACH(ptr, oper_list.head)
975     {
976 michael 1078 struct Client *client_p = ptr->data;
977 adx 30 assert(client_p->umodes & UMODE_OPER);
978    
979 michael 1219 if (HasUMode(client_p, flags) && !IsDefunct(client_p))
980 adx 30 send_message(client_p, buffer, len);
981     }
982     }
983    
984     /* ts_warn()
985     *
986     * inputs - var args message
987     * output - NONE
988     * side effects - Call sendto_realops_flags, with some flood checking
989     * (at most 5 warnings every 5 seconds)
990     */
991     void
992     ts_warn(const char *pattern, ...)
993     {
994     va_list args;
995 michael 1078 char buffer[IRCD_BUFSIZE];
996 adx 30 static time_t last = 0;
997     static int warnings = 0;
998    
999     /*
1000     ** if we're running with TS_WARNINGS enabled and someone does
1001     ** something silly like (remotely) connecting a nonTS server,
1002     ** we'll get a ton of warnings, so we make sure we don't send
1003     ** more than 5 every 5 seconds. -orabidoo
1004     */
1005    
1006     if (CurrentTime - last < 5)
1007     {
1008     if (++warnings > 5)
1009     return;
1010     }
1011     else
1012     {
1013     last = CurrentTime;
1014     warnings = 0;
1015     }
1016    
1017     va_start(args, pattern);
1018 michael 1086 vsnprintf(buffer, sizeof(buffer), pattern, args);
1019 adx 30 va_end(args);
1020    
1021 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer);
1022 michael 1247 ilog(LOG_TYPE_IRCD, "%s", buffer);
1023 adx 30 }
1024    
1025     /* kill_client()
1026     *
1027     * inputs - client to send kill towards
1028     * - pointer to client to kill
1029     * - reason for kill
1030     * output - NONE
1031     * side effects - NONE
1032     */
1033     void
1034     kill_client(struct Client *client_p, struct Client *diedie,
1035     const char *pattern, ...)
1036     {
1037     va_list args;
1038     char buffer[IRCD_BUFSIZE];
1039     int len;
1040    
1041     if (client_p->from != NULL)
1042     client_p = client_p->from;
1043     if (IsDead(client_p))
1044     return;
1045    
1046     len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1047     ID_or_name(diedie, client_p));
1048    
1049     va_start(args, pattern);
1050     len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1051     va_end(args);
1052    
1053     send_message(client_p, buffer, len);
1054     }
1055    
1056     /* kill_client_ll_serv_butone()
1057     *
1058     * inputs - pointer to client to not send to
1059     * - pointer to client to kill
1060     * output - NONE
1061     * side effects - Send a KILL for the given client
1062     * message to all connected servers
1063     * except the client 'one'. Also deal with
1064     * client being unknown to leaf, as in lazylink...
1065     */
1066     void
1067     kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
1068     const char *pattern, ...)
1069     {
1070     va_list args;
1071     int have_uid = 0;
1072 michael 885 dlink_node *ptr = NULL;
1073 adx 30 char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1074 michael 885 int len_uid = 0, len_nick = 0;
1075 adx 30
1076 michael 1115 if (HasID(source_p))
1077 adx 30 {
1078     have_uid = 1;
1079 adx 285 va_start(args, pattern);
1080 adx 30 len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1081     len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1082     args);
1083 adx 285 va_end(args);
1084 adx 30 }
1085 adx 285
1086     va_start(args, pattern);
1087 adx 30 len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1088     len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1089     args);
1090     va_end(args);
1091    
1092     DLINK_FOREACH(ptr, serv_list.head)
1093     {
1094 michael 885 struct Client *client_p = ptr->data;
1095 adx 30
1096     if (one != NULL && (client_p == one->from))
1097     continue;
1098     if (IsDefunct(client_p))
1099     continue;
1100    
1101 michael 885 if (have_uid && IsCapable(client_p, CAP_TS6))
1102     send_message(client_p, buf_uid, len_uid);
1103     else
1104     send_message(client_p, buf_nick, len_nick);
1105 adx 30 }
1106     }

Properties

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