| 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 |
|
* |
| 111 |
|
static void |
| 112 |
|
send_message(struct Client *to, char *buf, int len) |
| 113 |
|
{ |
| 114 |
< |
#ifdef INVARIANTS |
| 115 |
< |
if (IsMe(to)) |
| 117 |
< |
{ |
| 118 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 119 |
< |
"Trying to send message to myself!"); |
| 120 |
< |
return; |
| 121 |
< |
} |
| 122 |
< |
#endif |
| 114 |
> |
assert(!IsMe(to)); |
| 115 |
> |
assert(to != &me); |
| 116 |
|
|
| 117 |
|
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
| 118 |
|
{ |
| 166 |
|
return; |
| 167 |
|
} |
| 168 |
|
|
| 176 |
– |
if (ServerInfo.hub && IsCapable(to, CAP_LL)) |
| 177 |
– |
{ |
| 178 |
– |
if (((from->lazyLinkClientExists & |
| 179 |
– |
to->localClient->serverMask) == 0)) |
| 180 |
– |
client_burst_if_needed(to, from); |
| 181 |
– |
} |
| 182 |
– |
|
| 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) |
| 308 |
– |
{ |
| 309 |
– |
#ifdef _WIN32 |
| 310 |
– |
errno = WSAGetLastError(); |
| 311 |
– |
#endif |
| 296 |
|
break; |
| 313 |
– |
} |
| 297 |
|
|
| 298 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
| 299 |
|
|
| 528 |
|
/* sendto_server() |
| 529 |
|
* |
| 530 |
|
* inputs - pointer to client to NOT send to |
| 531 |
< |
* - pointer to source client required by LL (if any) |
| 549 |
< |
* - 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 |
| 552 |
– |
* - 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'. |
| 559 |
– |
* If the server is a lazylink client, then it must know |
| 560 |
– |
* about source_p if non-NULL (unless LL_ICLIENT is specified, |
| 561 |
– |
* when source_p will be introduced where required) and |
| 562 |
– |
* chptr if non-NULL (unless LL_ICHANNEL is specified, when |
| 563 |
– |
* chptr will be introduced where required). |
| 564 |
– |
* Note: nothing will be introduced to a LazyLeaf unless |
| 565 |
– |
* 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, |
| 548 |
< |
struct Channel *chptr, unsigned long caps, |
| 549 |
< |
unsigned long nocaps, unsigned long llflags, |
| 547 |
> |
sendto_server(struct Client *one, const struct Channel *chptr, |
| 548 |
> |
const unsigned int caps, |
| 549 |
> |
const unsigned int nocaps, |
| 550 |
|
const char *format, ...) |
| 551 |
|
{ |
| 552 |
|
va_list args; |
| 553 |
< |
struct Client *client_p; |
| 580 |
< |
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 |
< |
{ |
| 586 |
< |
if (chptr->chname[0] != '#') |
| 587 |
< |
return; |
| 588 |
< |
} |
| 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 |
|
|
| 611 |
– |
if (ServerInfo.hub && IsCapable(client_p, CAP_LL)) |
| 612 |
– |
{ |
| 613 |
– |
/* check LL channel */ |
| 614 |
– |
if (chptr != NULL && |
| 615 |
– |
((chptr->lazyLinkChannelExists & |
| 616 |
– |
client_p->localClient->serverMask) == 0)) |
| 617 |
– |
{ |
| 618 |
– |
/* Only introduce the channel if we really will send this message */ |
| 619 |
– |
if (!(llflags & LL_ICLIENT) && source_p && |
| 620 |
– |
((source_p->lazyLinkClientExists & |
| 621 |
– |
client_p->localClient->serverMask) == 0)) |
| 622 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
| 623 |
– |
|
| 624 |
– |
if (llflags & LL_ICHAN) |
| 625 |
– |
burst_channel(client_p, chptr); |
| 626 |
– |
else |
| 627 |
– |
continue; /* we can't introduce the unknown chptr, skip */ |
| 628 |
– |
} |
| 629 |
– |
/* check LL client */ |
| 630 |
– |
if (source_p && |
| 631 |
– |
((source_p->lazyLinkClientExists & |
| 632 |
– |
client_p->localClient->serverMask) == 0)) |
| 633 |
– |
{ |
| 634 |
– |
if (llflags & LL_ICLIENT) |
| 635 |
– |
client_burst_if_needed(client_p,source_p); |
| 636 |
– |
else |
| 637 |
– |
continue; /* we can't introduce the unknown source_p, skip */ |
| 638 |
– |
} |
| 639 |
– |
} |
| 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 |
|
} |
| 731 |
|
* remote to this server. |
| 732 |
|
*/ |
| 733 |
|
void |
| 734 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
| 735 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
| 734 |
> |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
| 735 |
> |
const unsigned int caps, const unsigned int nocaps, |
| 736 |
> |
struct Channel *chptr, const char *pattern, ...) |
| 737 |
|
{ |
| 738 |
|
va_list args; |
| 739 |
|
char buffer[IRCD_BUFSIZE]; |
| 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; |
| 1193 |
< |
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 |
|
|
| 1140 |
|
if (HasID(source_p) && (me.id[0] != '\0')) |
| 1141 |
|
{ |
| 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)) |
| 1226 |
< |
{ |
| 1227 |
< |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
| 1228 |
< |
send_message(client_p, buf_uid, len_uid); |
| 1229 |
< |
else |
| 1230 |
< |
send_message(client_p, buf_nick, len_nick); |
| 1231 |
< |
} |
| 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 |
|
} |