| 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" |
| 53 |
|
static void send_message(struct Client *, char *, int); |
| 54 |
|
static void send_message_remote(struct Client *, struct Client *, char *, int); |
| 55 |
|
|
| 56 |
< |
static unsigned long current_serial = 0L; |
| 56 |
> |
static unsigned int current_serial = 0; |
| 57 |
|
|
| 58 |
|
/* send_format() |
| 59 |
|
* |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
/* |
| 94 |
+ |
* iosend_default - append a packet to the client's sendq. |
| 95 |
+ |
*/ |
| 96 |
+ |
void * |
| 97 |
+ |
iosend_default(va_list args) |
| 98 |
+ |
{ |
| 99 |
+ |
struct Client *to = va_arg(args, struct Client *); |
| 100 |
+ |
int length = va_arg(args, int); |
| 101 |
+ |
char *buf = va_arg(args, char *); |
| 102 |
+ |
|
| 103 |
+ |
dbuf_put(&to->localClient->buf_sendq, buf, length); |
| 104 |
+ |
return NULL; |
| 105 |
+ |
} |
| 106 |
+ |
|
| 107 |
+ |
/* |
| 108 |
|
** send_message |
| 109 |
|
** Internal utility which appends given buffer to the sockets |
| 110 |
|
** sendq. |
| 112 |
|
static void |
| 113 |
|
send_message(struct Client *to, char *buf, int len) |
| 114 |
|
{ |
| 115 |
< |
#ifdef INVARIANTS |
| 116 |
< |
if (IsMe(to)) |
| 103 |
< |
{ |
| 104 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 105 |
< |
"Trying to send message to myself!"); |
| 106 |
< |
return; |
| 107 |
< |
} |
| 108 |
< |
#endif |
| 115 |
> |
assert(!IsMe(to)); |
| 116 |
> |
assert(to != &me); |
| 117 |
|
|
| 118 |
|
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
| 119 |
|
{ |
| 129 |
|
return; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, len); |
| 132 |
> |
execute_callback(iosend_cb, to, len, buf); |
| 133 |
|
|
| 134 |
|
/* |
| 135 |
|
** Update statistics. The following is slightly incorrect |
| 167 |
|
return; |
| 168 |
|
} |
| 169 |
|
|
| 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 |
– |
|
| 170 |
|
/* Optimize by checking if (from && to) before everything */ |
| 171 |
|
/* we set to->from up there.. */ |
| 172 |
|
|
| 186 |
|
from->name, from->username, from->host, |
| 187 |
|
to->from->name); |
| 188 |
|
|
| 189 |
< |
sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
| 189 |
> |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
| 190 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 191 |
|
me.id, to->name, me.name, to->name, |
| 192 |
|
to->username, to->host, to->from->name); |
| 193 |
< |
sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
| 193 |
> |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
| 194 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 195 |
|
me.name, to->name, me.name, to->name, |
| 196 |
|
to->username, to->host, to->from->name); |
| 282 |
|
errno = EWOULDBLOCK; |
| 283 |
|
case SSL_ERROR_SYSCALL: |
| 284 |
|
break; |
| 285 |
< |
|
| 285 |
> |
case SSL_ERROR_SSL: |
| 286 |
> |
if (errno == EAGAIN) |
| 287 |
> |
break; |
| 288 |
|
default: |
| 289 |
|
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
| 290 |
|
} |
| 294 |
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
| 295 |
|
|
| 296 |
|
if (retlen <= 0) |
| 294 |
– |
{ |
| 295 |
– |
#ifdef _WIN32 |
| 296 |
– |
errno = WSAGetLastError(); |
| 297 |
– |
#endif |
| 297 |
|
break; |
| 299 |
– |
} |
| 298 |
|
|
| 301 |
– |
execute_callback(iosend_cb, to, retlen, first->data); |
| 299 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
| 300 |
|
|
| 301 |
|
/* We have some data written .. update counters */ |
| 457 |
|
struct Channel *chptr, const char *command, |
| 458 |
|
const char *pattern, ...) |
| 459 |
|
{ |
| 460 |
< |
va_list args; |
| 460 |
> |
va_list alocal, aremote, auid; |
| 461 |
|
char local_buf[IRCD_BUFSIZE]; |
| 462 |
|
char remote_buf[IRCD_BUFSIZE]; |
| 463 |
|
char uid_buf[IRCD_BUFSIZE]; |
| 478 |
|
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
| 479 |
|
ID(from), command, chptr->chname); |
| 480 |
|
|
| 481 |
< |
va_start(args, pattern); |
| 481 |
> |
va_start(alocal, pattern); |
| 482 |
> |
va_start(aremote, pattern); |
| 483 |
> |
va_start(auid, pattern); |
| 484 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
| 485 |
< |
pattern, args); |
| 485 |
> |
pattern, alocal); |
| 486 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
| 487 |
< |
pattern, args); |
| 487 |
> |
pattern, aremote); |
| 488 |
|
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
| 489 |
< |
args); |
| 490 |
< |
va_end(args); |
| 489 |
> |
auid); |
| 490 |
> |
va_end(auid); |
| 491 |
> |
va_end(aremote); |
| 492 |
> |
va_end(alocal); |
| 493 |
|
|
| 494 |
|
++current_serial; |
| 495 |
|
|
| 529 |
|
/* sendto_server() |
| 530 |
|
* |
| 531 |
|
* inputs - pointer to client to NOT send to |
| 532 |
< |
* - pointer to source client required by LL (if any) |
| 532 |
< |
* - pointer to channel required by LL (if any) |
| 532 |
> |
* - pointer to channel |
| 533 |
|
* - caps or'd together which must ALL be present |
| 534 |
|
* - caps or'd together which must ALL NOT be present |
| 535 |
– |
* - LL flags: LL_ICLIENT | LL_ICHAN |
| 535 |
|
* - printf style format string |
| 536 |
|
* - args to format string |
| 537 |
|
* output - NONE |
| 538 |
|
* side effects - Send a message to all connected servers, except the |
| 539 |
|
* client 'one' (if non-NULL), as long as the servers |
| 540 |
|
* 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. |
| 541 |
|
* |
| 542 |
|
* This function was written in an attempt to merge together the other |
| 543 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
| 545 |
|
* -davidt |
| 546 |
|
*/ |
| 547 |
|
void |
| 548 |
< |
sendto_server(struct Client *one, struct Client *source_p, |
| 548 |
> |
sendto_server(struct Client *one, |
| 549 |
|
struct Channel *chptr, unsigned long caps, |
| 550 |
< |
unsigned long nocaps, unsigned long llflags, |
| 550 |
> |
unsigned long nocaps, |
| 551 |
|
const char *format, ...) |
| 552 |
|
{ |
| 553 |
|
va_list args; |
| 554 |
< |
struct Client *client_p; |
| 563 |
< |
dlink_node *ptr; |
| 554 |
> |
dlink_node *ptr = NULL; |
| 555 |
|
char buffer[IRCD_BUFSIZE]; |
| 556 |
< |
int len; |
| 556 |
> |
int len = 0; |
| 557 |
|
|
| 558 |
< |
if (chptr != NULL) |
| 559 |
< |
{ |
| 569 |
< |
if (chptr->chname[0] != '#') |
| 570 |
< |
return; |
| 571 |
< |
} |
| 558 |
> |
if (chptr && chptr->chname[0] != '#') |
| 559 |
> |
return; |
| 560 |
|
|
| 561 |
|
va_start(args, format); |
| 562 |
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
| 564 |
|
|
| 565 |
|
DLINK_FOREACH(ptr, serv_list.head) |
| 566 |
|
{ |
| 567 |
< |
client_p = ptr->data; |
| 567 |
> |
struct Client *client_p = ptr->data; |
| 568 |
|
|
| 569 |
|
/* If dead already skip */ |
| 570 |
|
if (IsDead(client_p)) |
| 579 |
|
if ((client_p->localClient->caps & nocaps) != 0) |
| 580 |
|
continue; |
| 581 |
|
|
| 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 |
– |
} |
| 582 |
|
send_message(client_p, buffer, len); |
| 583 |
|
} |
| 584 |
|
} |
| 616 |
|
chptr = ((struct Membership *) cptr->data)->chptr; |
| 617 |
|
assert(chptr != NULL); |
| 618 |
|
|
| 619 |
< |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
| 619 |
> |
DLINK_FOREACH(uptr, chptr->members.head) |
| 620 |
|
{ |
| 621 |
|
ms = uptr->data; |
| 622 |
|
target_p = ms->client_p; |
| 623 |
|
assert(target_p != NULL); |
| 624 |
|
|
| 625 |
< |
if (target_p == user || IsDefunct(target_p) || |
| 625 |
> |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
| 626 |
|
target_p->serial == current_serial) |
| 627 |
|
continue; |
| 628 |
|
|
| 661 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 662 |
|
va_end(args); |
| 663 |
|
|
| 664 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 664 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
| 665 |
|
{ |
| 666 |
|
ms = ptr->data; |
| 667 |
|
target_p = ms->client_p; |
| 669 |
|
if (type != 0 && (ms->flags & type) == 0) |
| 670 |
|
continue; |
| 671 |
|
|
| 672 |
< |
if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p))) |
| 672 |
> |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
| 673 |
> |
(nodeaf && IsDeaf(target_p))) |
| 674 |
|
continue; |
| 675 |
|
|
| 676 |
|
send_message(target_p, buffer, len); |
| 704 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 705 |
|
va_end(args); |
| 706 |
|
|
| 707 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 707 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
| 708 |
|
{ |
| 709 |
|
ms = ptr->data; |
| 710 |
|
target_p = ms->client_p; |
| 712 |
|
if (type != 0 && (ms->flags & type) == 0) |
| 713 |
|
continue; |
| 714 |
|
|
| 715 |
< |
if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p)) |
| 715 |
> |
if (!MyConnect(target_p) || target_p == one || |
| 716 |
> |
IsDefunct(target_p) || IsDeaf(target_p)) |
| 717 |
|
continue; |
| 718 |
|
send_message(target_p, buffer, len); |
| 719 |
|
} |
| 746 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 747 |
|
va_end(args); |
| 748 |
|
|
| 749 |
+ |
++current_serial; |
| 750 |
+ |
|
| 751 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
| 752 |
|
{ |
| 753 |
|
ms = ptr->data; |
| 764 |
|
((target_p->from->localClient->caps & caps) != caps) || |
| 765 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
| 766 |
|
continue; |
| 767 |
< |
|
| 768 |
< |
send_message(target_p, buffer, len); |
| 767 |
> |
if (target_p->from->serial != current_serial) |
| 768 |
> |
{ |
| 769 |
> |
send_message(target_p, buffer, len); |
| 770 |
> |
target_p->from->serial = current_serial; |
| 771 |
> |
} |
| 772 |
|
} |
| 773 |
|
} |
| 774 |
|
|
| 809 |
|
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
| 810 |
|
int what, const char *pattern, ...) |
| 811 |
|
{ |
| 812 |
< |
va_list args; |
| 812 |
> |
va_list alocal, aremote; |
| 813 |
|
struct Client *client_p; |
| 814 |
|
dlink_node *ptr, *ptr_next; |
| 815 |
|
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
| 817 |
|
from->username, from->host); |
| 818 |
|
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
| 819 |
|
|
| 820 |
< |
va_start(args, pattern); |
| 820 |
> |
va_start(alocal, pattern); |
| 821 |
> |
va_start(aremote, pattern); |
| 822 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
| 823 |
< |
pattern, args); |
| 823 |
> |
pattern, alocal); |
| 824 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
| 825 |
< |
pattern, args); |
| 826 |
< |
va_end(args); |
| 825 |
> |
pattern, aremote); |
| 826 |
> |
va_end(aremote); |
| 827 |
> |
va_end(alocal); |
| 828 |
|
|
| 829 |
|
/* scan the local clients */ |
| 830 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 893 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 894 |
|
va_end(args); |
| 895 |
|
|
| 896 |
< |
current_serial++; |
| 896 |
> |
++current_serial; |
| 897 |
|
|
| 898 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
| 899 |
|
{ |
| 1133 |
|
{ |
| 1134 |
|
va_list args; |
| 1135 |
|
int have_uid = 0; |
| 1136 |
< |
struct Client *client_p; |
| 1169 |
< |
dlink_node *ptr; |
| 1136 |
> |
dlink_node *ptr = NULL; |
| 1137 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
| 1138 |
< |
int len_uid = 0, len_nick; |
| 1138 |
> |
int len_uid = 0, len_nick = 0; |
| 1139 |
|
|
| 1173 |
– |
va_start(args, pattern); |
| 1140 |
|
if (HasID(source_p) && (me.id[0] != '\0')) |
| 1141 |
|
{ |
| 1142 |
|
have_uid = 1; |
| 1143 |
+ |
va_start(args, pattern); |
| 1144 |
|
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
| 1145 |
|
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
| 1146 |
|
args); |
| 1147 |
+ |
va_end(args); |
| 1148 |
|
} |
| 1149 |
+ |
|
| 1150 |
+ |
va_start(args, pattern); |
| 1151 |
|
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
| 1152 |
|
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
| 1153 |
|
args); |
| 1155 |
|
|
| 1156 |
|
DLINK_FOREACH(ptr, serv_list.head) |
| 1157 |
|
{ |
| 1158 |
< |
client_p = ptr->data; |
| 1158 |
> |
struct Client *client_p = ptr->data; |
| 1159 |
|
|
| 1160 |
|
if (one != NULL && (client_p == one->from)) |
| 1161 |
|
continue; |
| 1162 |
|
if (IsDefunct(client_p)) |
| 1163 |
|
continue; |
| 1164 |
|
|
| 1165 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
| 1166 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
| 1167 |
< |
!ServerInfo.hub || |
| 1168 |
< |
(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 |
< |
} |
| 1165 |
> |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
| 1166 |
> |
send_message(client_p, buf_uid, len_uid); |
| 1167 |
> |
else |
| 1168 |
> |
send_message(client_p, buf_nick, len_nick); |
| 1169 |
|
} |
| 1170 |
|
} |