19 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
* USA |
21 |
|
* |
22 |
< |
* $Id: send.c,v 7.307 2005/10/02 12:45:07 adx Exp $ |
22 |
> |
* $Id$ |
23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
< |
#include "tools.h" |
26 |
> |
#include "list.h" |
27 |
|
#include "send.h" |
28 |
|
#include "channel.h" |
29 |
|
#include "client.h" |
38 |
|
#include "s_serv.h" |
39 |
|
#include "sprintf_irc.h" |
40 |
|
#include "s_conf.h" |
41 |
– |
#include "list.h" |
41 |
|
#include "s_log.h" |
42 |
|
#include "memory.h" |
43 |
|
#include "hook.h" |
52 |
|
static void send_message(struct Client *, char *, int); |
53 |
|
static void send_message_remote(struct Client *, struct Client *, char *, int); |
54 |
|
|
55 |
< |
static unsigned long current_serial = 0L; |
55 |
> |
static unsigned int current_serial = 0; |
56 |
|
|
57 |
|
/* send_format() |
58 |
|
* |
90 |
|
} |
91 |
|
|
92 |
|
/* |
93 |
+ |
* iosend_default - append a packet to the client's sendq. |
94 |
+ |
*/ |
95 |
+ |
void * |
96 |
+ |
iosend_default(va_list args) |
97 |
+ |
{ |
98 |
+ |
struct Client *to = va_arg(args, struct Client *); |
99 |
+ |
int length = va_arg(args, int); |
100 |
+ |
char *buf = va_arg(args, char *); |
101 |
+ |
|
102 |
+ |
dbuf_put(&to->localClient->buf_sendq, buf, length); |
103 |
+ |
return NULL; |
104 |
+ |
} |
105 |
+ |
|
106 |
+ |
/* |
107 |
|
** send_message |
108 |
|
** Internal utility which appends given buffer to the sockets |
109 |
|
** sendq. |
111 |
|
static void |
112 |
|
send_message(struct Client *to, char *buf, int len) |
113 |
|
{ |
114 |
< |
#ifdef INVARIANTS |
115 |
< |
if (IsMe(to)) |
103 |
< |
{ |
104 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
105 |
< |
"Trying to send message to myself!"); |
106 |
< |
return; |
107 |
< |
} |
108 |
< |
#endif |
114 |
> |
assert(!IsMe(to)); |
115 |
> |
assert(to != &me); |
116 |
|
|
117 |
|
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
118 |
|
{ |
128 |
|
return; |
129 |
|
} |
130 |
|
|
131 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, len); |
131 |
> |
execute_callback(iosend_cb, to, len, buf); |
132 |
|
|
133 |
|
/* |
134 |
|
** Update statistics. The following is slightly incorrect |
166 |
|
return; |
167 |
|
} |
168 |
|
|
162 |
– |
if (ServerInfo.hub && IsCapable(to, CAP_LL)) |
163 |
– |
{ |
164 |
– |
if (((from->lazyLinkClientExists & |
165 |
– |
to->localClient->serverMask) == 0)) |
166 |
– |
client_burst_if_needed(to, from); |
167 |
– |
} |
168 |
– |
|
169 |
|
/* Optimize by checking if (from && to) before everything */ |
170 |
|
/* we set to->from up there.. */ |
171 |
|
|
185 |
|
from->name, from->username, from->host, |
186 |
|
to->from->name); |
187 |
|
|
188 |
< |
sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
188 |
> |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
189 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
190 |
|
me.id, to->name, me.name, to->name, |
191 |
|
to->username, to->host, to->from->name); |
192 |
< |
sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
192 |
> |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
193 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
194 |
|
me.name, to->name, me.name, to->name, |
195 |
|
to->username, to->host, to->from->name); |
281 |
|
errno = EWOULDBLOCK; |
282 |
|
case SSL_ERROR_SYSCALL: |
283 |
|
break; |
284 |
< |
|
284 |
> |
case SSL_ERROR_SSL: |
285 |
> |
if (errno == EAGAIN) |
286 |
> |
break; |
287 |
|
default: |
288 |
|
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
289 |
|
} |
293 |
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
294 |
|
|
295 |
|
if (retlen <= 0) |
294 |
– |
{ |
295 |
– |
#ifdef _WIN32 |
296 |
– |
errno = WSAGetLastError(); |
297 |
– |
#endif |
296 |
|
break; |
299 |
– |
} |
297 |
|
|
301 |
– |
execute_callback(iosend_cb, to, retlen, first->data); |
298 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
299 |
|
|
300 |
|
/* We have some data written .. update counters */ |
456 |
|
struct Channel *chptr, const char *command, |
457 |
|
const char *pattern, ...) |
458 |
|
{ |
459 |
< |
va_list args; |
459 |
> |
va_list alocal, aremote, auid; |
460 |
|
char local_buf[IRCD_BUFSIZE]; |
461 |
|
char remote_buf[IRCD_BUFSIZE]; |
462 |
|
char uid_buf[IRCD_BUFSIZE]; |
477 |
|
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
478 |
|
ID(from), command, chptr->chname); |
479 |
|
|
480 |
< |
va_start(args, pattern); |
480 |
> |
va_start(alocal, pattern); |
481 |
> |
va_start(aremote, pattern); |
482 |
> |
va_start(auid, pattern); |
483 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
484 |
< |
pattern, args); |
484 |
> |
pattern, alocal); |
485 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
486 |
< |
pattern, args); |
486 |
> |
pattern, aremote); |
487 |
|
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
488 |
< |
args); |
489 |
< |
va_end(args); |
488 |
> |
auid); |
489 |
> |
va_end(auid); |
490 |
> |
va_end(aremote); |
491 |
> |
va_end(alocal); |
492 |
|
|
493 |
|
++current_serial; |
494 |
|
|
528 |
|
/* sendto_server() |
529 |
|
* |
530 |
|
* inputs - pointer to client to NOT send to |
531 |
< |
* - pointer to source client required by LL (if any) |
532 |
< |
* - pointer to channel required by LL (if any) |
531 |
> |
* - pointer to channel |
532 |
|
* - caps or'd together which must ALL be present |
533 |
|
* - caps or'd together which must ALL NOT be present |
535 |
– |
* - LL flags: LL_ICLIENT | LL_ICHAN |
534 |
|
* - printf style format string |
535 |
|
* - args to format string |
536 |
|
* output - NONE |
537 |
|
* side effects - Send a message to all connected servers, except the |
538 |
|
* client 'one' (if non-NULL), as long as the servers |
539 |
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
542 |
– |
* If the server is a lazylink client, then it must know |
543 |
– |
* about source_p if non-NULL (unless LL_ICLIENT is specified, |
544 |
– |
* when source_p will be introduced where required) and |
545 |
– |
* chptr if non-NULL (unless LL_ICHANNEL is specified, when |
546 |
– |
* chptr will be introduced where required). |
547 |
– |
* Note: nothing will be introduced to a LazyLeaf unless |
548 |
– |
* the message is actually sent. |
540 |
|
* |
541 |
|
* This function was written in an attempt to merge together the other |
542 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
544 |
|
* -davidt |
545 |
|
*/ |
546 |
|
void |
547 |
< |
sendto_server(struct Client *one, struct Client *source_p, |
547 |
> |
sendto_server(struct Client *one, |
548 |
|
struct Channel *chptr, unsigned long caps, |
549 |
< |
unsigned long nocaps, unsigned long llflags, |
549 |
> |
unsigned long nocaps, |
550 |
|
const char *format, ...) |
551 |
|
{ |
552 |
|
va_list args; |
553 |
< |
struct Client *client_p; |
563 |
< |
dlink_node *ptr; |
553 |
> |
dlink_node *ptr = NULL; |
554 |
|
char buffer[IRCD_BUFSIZE]; |
555 |
< |
int len; |
555 |
> |
int len = 0; |
556 |
|
|
557 |
< |
if (chptr != NULL) |
558 |
< |
{ |
569 |
< |
if (chptr->chname[0] != '#') |
570 |
< |
return; |
571 |
< |
} |
557 |
> |
if (chptr && chptr->chname[0] != '#') |
558 |
> |
return; |
559 |
|
|
560 |
|
va_start(args, format); |
561 |
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
563 |
|
|
564 |
|
DLINK_FOREACH(ptr, serv_list.head) |
565 |
|
{ |
566 |
< |
client_p = ptr->data; |
566 |
> |
struct Client *client_p = ptr->data; |
567 |
|
|
568 |
|
/* If dead already skip */ |
569 |
|
if (IsDead(client_p)) |
578 |
|
if ((client_p->localClient->caps & nocaps) != 0) |
579 |
|
continue; |
580 |
|
|
594 |
– |
if (ServerInfo.hub && IsCapable(client_p, CAP_LL)) |
595 |
– |
{ |
596 |
– |
/* check LL channel */ |
597 |
– |
if (chptr != NULL && |
598 |
– |
((chptr->lazyLinkChannelExists & |
599 |
– |
client_p->localClient->serverMask) == 0)) |
600 |
– |
{ |
601 |
– |
/* Only introduce the channel if we really will send this message */ |
602 |
– |
if (!(llflags & LL_ICLIENT) && source_p && |
603 |
– |
((source_p->lazyLinkClientExists & |
604 |
– |
client_p->localClient->serverMask) == 0)) |
605 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
606 |
– |
|
607 |
– |
if (llflags & LL_ICHAN) |
608 |
– |
burst_channel(client_p, chptr); |
609 |
– |
else |
610 |
– |
continue; /* we can't introduce the unknown chptr, skip */ |
611 |
– |
} |
612 |
– |
/* check LL client */ |
613 |
– |
if (source_p && |
614 |
– |
((source_p->lazyLinkClientExists & |
615 |
– |
client_p->localClient->serverMask) == 0)) |
616 |
– |
{ |
617 |
– |
if (llflags & LL_ICLIENT) |
618 |
– |
client_burst_if_needed(client_p,source_p); |
619 |
– |
else |
620 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
621 |
– |
} |
622 |
– |
} |
581 |
|
send_message(client_p, buffer, len); |
582 |
|
} |
583 |
|
} |
615 |
|
chptr = ((struct Membership *) cptr->data)->chptr; |
616 |
|
assert(chptr != NULL); |
617 |
|
|
618 |
< |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
618 |
> |
DLINK_FOREACH(uptr, chptr->members.head) |
619 |
|
{ |
620 |
|
ms = uptr->data; |
621 |
|
target_p = ms->client_p; |
622 |
|
assert(target_p != NULL); |
623 |
|
|
624 |
< |
if (target_p == user || IsDefunct(target_p) || |
624 |
> |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
625 |
|
target_p->serial == current_serial) |
626 |
|
continue; |
627 |
|
|
660 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
661 |
|
va_end(args); |
662 |
|
|
663 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
663 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
664 |
|
{ |
665 |
|
ms = ptr->data; |
666 |
|
target_p = ms->client_p; |
668 |
|
if (type != 0 && (ms->flags & type) == 0) |
669 |
|
continue; |
670 |
|
|
671 |
< |
if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p))) |
671 |
> |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
672 |
> |
(nodeaf && IsDeaf(target_p))) |
673 |
|
continue; |
674 |
|
|
675 |
|
send_message(target_p, buffer, len); |
703 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
704 |
|
va_end(args); |
705 |
|
|
706 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
706 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
707 |
|
{ |
708 |
|
ms = ptr->data; |
709 |
|
target_p = ms->client_p; |
711 |
|
if (type != 0 && (ms->flags & type) == 0) |
712 |
|
continue; |
713 |
|
|
714 |
< |
if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p)) |
714 |
> |
if (!MyConnect(target_p) || target_p == one || |
715 |
> |
IsDefunct(target_p) || IsDeaf(target_p)) |
716 |
|
continue; |
717 |
|
send_message(target_p, buffer, len); |
718 |
|
} |
745 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
746 |
|
va_end(args); |
747 |
|
|
748 |
+ |
++current_serial; |
749 |
+ |
|
750 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
751 |
|
{ |
752 |
|
ms = ptr->data; |
763 |
|
((target_p->from->localClient->caps & caps) != caps) || |
764 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
765 |
|
continue; |
766 |
< |
|
767 |
< |
send_message(target_p, buffer, len); |
766 |
> |
if (target_p->from->serial != current_serial) |
767 |
> |
{ |
768 |
> |
send_message(target_p, buffer, len); |
769 |
> |
target_p->from->serial = current_serial; |
770 |
> |
} |
771 |
|
} |
772 |
|
} |
773 |
|
|
808 |
|
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
809 |
|
int what, const char *pattern, ...) |
810 |
|
{ |
811 |
< |
va_list args; |
811 |
> |
va_list alocal, aremote; |
812 |
|
struct Client *client_p; |
813 |
|
dlink_node *ptr, *ptr_next; |
814 |
|
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
816 |
|
from->username, from->host); |
817 |
|
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
818 |
|
|
819 |
< |
va_start(args, pattern); |
819 |
> |
va_start(alocal, pattern); |
820 |
> |
va_start(aremote, pattern); |
821 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
822 |
< |
pattern, args); |
822 |
> |
pattern, alocal); |
823 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
824 |
< |
pattern, args); |
825 |
< |
va_end(args); |
824 |
> |
pattern, aremote); |
825 |
> |
va_end(aremote); |
826 |
> |
va_end(alocal); |
827 |
|
|
828 |
|
/* scan the local clients */ |
829 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
892 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
893 |
|
va_end(args); |
894 |
|
|
895 |
< |
current_serial++; |
895 |
> |
++current_serial; |
896 |
|
|
897 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
898 |
|
{ |
1132 |
|
{ |
1133 |
|
va_list args; |
1134 |
|
int have_uid = 0; |
1135 |
< |
struct Client *client_p; |
1169 |
< |
dlink_node *ptr; |
1135 |
> |
dlink_node *ptr = NULL; |
1136 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1137 |
< |
int len_uid = 0, len_nick; |
1137 |
> |
int len_uid = 0, len_nick = 0; |
1138 |
|
|
1173 |
– |
va_start(args, pattern); |
1139 |
|
if (HasID(source_p) && (me.id[0] != '\0')) |
1140 |
|
{ |
1141 |
|
have_uid = 1; |
1142 |
+ |
va_start(args, pattern); |
1143 |
|
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1144 |
|
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
1145 |
|
args); |
1146 |
+ |
va_end(args); |
1147 |
|
} |
1148 |
+ |
|
1149 |
+ |
va_start(args, pattern); |
1150 |
|
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1151 |
|
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
1152 |
|
args); |
1154 |
|
|
1155 |
|
DLINK_FOREACH(ptr, serv_list.head) |
1156 |
|
{ |
1157 |
< |
client_p = ptr->data; |
1157 |
> |
struct Client *client_p = ptr->data; |
1158 |
|
|
1159 |
|
if (one != NULL && (client_p == one->from)) |
1160 |
|
continue; |
1161 |
|
if (IsDefunct(client_p)) |
1162 |
|
continue; |
1163 |
|
|
1164 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
1165 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
1166 |
< |
!ServerInfo.hub || |
1167 |
< |
(source_p->lazyLinkClientExists & client_p->localClient->serverMask)) |
1199 |
< |
{ |
1200 |
< |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1201 |
< |
send_message(client_p, buf_uid, len_uid); |
1202 |
< |
else |
1203 |
< |
send_message(client_p, buf_nick, len_nick); |
1204 |
< |
} |
1164 |
> |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1165 |
> |
send_message(client_p, buf_uid, len_uid); |
1166 |
> |
else |
1167 |
> |
send_message(client_p, buf_nick, len_nick); |
1168 |
|
} |
1169 |
|
} |