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" |
30 |
– |
#include "common.h" |
30 |
|
#include "dbuf.h" |
31 |
|
#include "irc_string.h" |
32 |
|
#include "ircd.h" |
34 |
– |
#include "handlers.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 |
< |
#include "s_conf.h" |
39 |
< |
#include "list.h" |
42 |
< |
#include "s_log.h" |
38 |
> |
#include "conf.h" |
39 |
> |
#include "log.h" |
40 |
|
#include "memory.h" |
41 |
|
#include "hook.h" |
45 |
– |
#include "irc_getnameinfo.h" |
42 |
|
#include "packet.h" |
43 |
|
|
48 |
– |
#define LOG_BUFSIZE 2048 |
44 |
|
|
45 |
|
struct Callback *iosend_cb = NULL; |
46 |
< |
struct Callback *iosendctrl_cb = NULL; |
52 |
< |
|
53 |
< |
static void send_message(struct Client *, char *, int); |
54 |
< |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
46 |
> |
static unsigned int current_serial = 0; |
47 |
|
|
56 |
– |
static unsigned long current_serial = 0L; |
48 |
|
|
49 |
|
/* send_format() |
50 |
|
* |
78 |
|
|
79 |
|
lsendbuf[len++] = '\r'; |
80 |
|
lsendbuf[len++] = '\n'; |
81 |
< |
return (len); |
81 |
> |
return len; |
82 |
> |
} |
83 |
> |
|
84 |
> |
/* |
85 |
> |
* 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 |
|
/* |
103 |
|
static void |
104 |
|
send_message(struct Client *to, char *buf, int len) |
105 |
|
{ |
106 |
< |
#ifdef INVARIANTS |
107 |
< |
if (IsMe(to)) |
103 |
< |
{ |
104 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
105 |
< |
"Trying to send message to myself!"); |
106 |
< |
return; |
107 |
< |
} |
108 |
< |
#endif |
106 |
> |
assert(!IsMe(to)); |
107 |
> |
assert(to != &me); |
108 |
|
|
109 |
|
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
110 |
|
{ |
120 |
|
return; |
121 |
|
} |
122 |
|
|
123 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, len); |
123 |
> |
execute_callback(iosend_cb, to, len, buf); |
124 |
|
|
125 |
|
/* |
126 |
|
** Update statistics. The following is slightly incorrect |
158 |
|
return; |
159 |
|
} |
160 |
|
|
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 |
– |
|
161 |
|
/* Optimize by checking if (from && to) before everything */ |
162 |
|
/* we set to->from up there.. */ |
163 |
|
|
177 |
|
from->name, from->username, from->host, |
178 |
|
to->from->name); |
179 |
|
|
180 |
< |
sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
180 |
> |
sendto_server(NULL, CAP_TS6, NOCAPS, |
181 |
|
":%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 |
< |
sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
184 |
> |
sendto_server(NULL, NOCAPS, CAP_TS6, |
185 |
|
":%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 |
< |
SetKilled(to); |
189 |
> |
AddFlag(to, FLAGS_KILLED); |
190 |
|
|
191 |
|
if (IsClient(from)) |
192 |
|
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
221 |
|
} |
222 |
|
|
223 |
|
/* |
232 |
– |
** slinkq_unblocked |
233 |
– |
** Called when a server control socket is ready for writing. |
234 |
– |
*/ |
235 |
– |
static void |
236 |
– |
slinkq_unblocked(fde_t *fd, struct Client *client_p) |
237 |
– |
{ |
238 |
– |
ClearSlinkqBlocked(client_p); |
239 |
– |
send_queued_slink_write(client_p); |
240 |
– |
} |
241 |
– |
|
242 |
– |
/* |
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 |
262 |
|
errno = EWOULDBLOCK; |
263 |
|
case SSL_ERROR_SYSCALL: |
264 |
|
break; |
265 |
< |
|
265 |
> |
case SSL_ERROR_SSL: |
266 |
> |
if (errno == EAGAIN) |
267 |
> |
break; |
268 |
|
default: |
269 |
|
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
270 |
|
} |
274 |
|
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
275 |
|
|
276 |
|
if (retlen <= 0) |
294 |
– |
{ |
295 |
– |
#ifdef _WIN32 |
296 |
– |
errno = WSAGetLastError(); |
297 |
– |
#endif |
277 |
|
break; |
299 |
– |
} |
278 |
|
|
301 |
– |
execute_callback(iosend_cb, to, retlen, first->data); |
279 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
280 |
|
|
281 |
|
/* We have some data written .. update counters */ |
298 |
|
} |
299 |
|
} |
300 |
|
|
324 |
– |
/* |
325 |
– |
** send_queued_slink_write |
326 |
– |
** This is called when there is a chance the some output would |
327 |
– |
** be possible. This attempts to empty the send queue as far as |
328 |
– |
** possible, and then if any data is left, a write is rescheduled. |
329 |
– |
*/ |
330 |
– |
void |
331 |
– |
send_queued_slink_write(struct Client *to) |
332 |
– |
{ |
333 |
– |
int retlen; |
334 |
– |
|
335 |
– |
/* |
336 |
– |
** Once socket is marked dead, we cannot start writing to it, |
337 |
– |
** even if the error is removed... |
338 |
– |
*/ |
339 |
– |
if (IsDead(to) || IsSlinkqBlocked(to)) |
340 |
– |
return; /* no use calling send() now */ |
341 |
– |
|
342 |
– |
/* Next, lets try to write some data */ |
343 |
– |
if (to->localClient->slinkq != NULL) |
344 |
– |
{ |
345 |
– |
retlen = send(to->localClient->ctrlfd.fd, |
346 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs, |
347 |
– |
to->localClient->slinkq_len, 0); |
348 |
– |
if (retlen < 0) |
349 |
– |
{ |
350 |
– |
/* If we have a fatal error */ |
351 |
– |
if (!ignoreErrno(errno)) |
352 |
– |
{ |
353 |
– |
dead_link_on_write(to, errno); |
354 |
– |
return; |
355 |
– |
} |
356 |
– |
} |
357 |
– |
else if (retlen == 0) |
358 |
– |
{ |
359 |
– |
/* 0 bytes is an EOF .. */ |
360 |
– |
dead_link_on_write(to, 0); |
361 |
– |
return; |
362 |
– |
} |
363 |
– |
else |
364 |
– |
{ |
365 |
– |
execute_callback(iosendctrl_cb, to, retlen, |
366 |
– |
to->localClient->slinkq + to->localClient->slinkq_ofs); |
367 |
– |
to->localClient->slinkq_len -= retlen; |
368 |
– |
|
369 |
– |
assert(to->localClient->slinkq_len >= 0); |
370 |
– |
if (to->localClient->slinkq_len) |
371 |
– |
to->localClient->slinkq_ofs += retlen; |
372 |
– |
else |
373 |
– |
{ |
374 |
– |
to->localClient->slinkq_ofs = 0; |
375 |
– |
MyFree(to->localClient->slinkq); |
376 |
– |
to->localClient->slinkq = NULL; |
377 |
– |
} |
378 |
– |
} |
379 |
– |
|
380 |
– |
/* Finally, if we have any more data, reschedule a write */ |
381 |
– |
if (to->localClient->slinkq_len) |
382 |
– |
{ |
383 |
– |
SetSlinkqBlocked(to); |
384 |
– |
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
385 |
– |
(PF *)slinkq_unblocked, (void *)to, 0); |
386 |
– |
} |
387 |
– |
} |
388 |
– |
} |
389 |
– |
|
301 |
|
/* send_queued_all() |
302 |
|
* |
303 |
|
* input - NONE |
368 |
|
*/ |
369 |
|
void |
370 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
371 |
< |
struct Channel *chptr, const char *command, |
371 |
> |
struct Channel *chptr, unsigned int type, |
372 |
|
const char *pattern, ...) |
373 |
|
{ |
374 |
< |
va_list args; |
374 |
> |
va_list alocal, aremote, auid; |
375 |
|
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 |
< |
dlink_node *ptr; |
469 |
< |
dlink_node *ptr_next; |
470 |
< |
struct Client *target_p; |
379 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
380 |
|
|
381 |
|
if (IsServer(from)) |
382 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
383 |
< |
from->name, command, chptr->chname); |
382 |
> |
local_len = ircsprintf(local_buf, ":%s ", |
383 |
> |
from->name); |
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 |
< |
va_start(args, pattern); |
385 |
> |
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 |
> |
|
392 |
> |
va_start(alocal, pattern); |
393 |
> |
va_start(aremote, pattern); |
394 |
> |
va_start(auid, pattern); |
395 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
396 |
< |
pattern, args); |
396 |
> |
pattern, alocal); |
397 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
398 |
< |
pattern, args); |
398 |
> |
pattern, aremote); |
399 |
|
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
400 |
< |
args); |
401 |
< |
va_end(args); |
400 |
> |
auid); |
401 |
> |
va_end(auid); |
402 |
> |
va_end(aremote); |
403 |
> |
va_end(alocal); |
404 |
|
|
405 |
|
++current_serial; |
406 |
|
|
407 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
408 |
|
{ |
409 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
410 |
< |
assert(target_p != NULL); |
409 |
> |
struct Membership *ms = ptr->data; |
410 |
> |
struct Client *target_p = ms->client_p; |
411 |
|
|
412 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
412 |
> |
assert(IsClient(target_p)); |
413 |
> |
|
414 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one) |
415 |
> |
continue; |
416 |
> |
|
417 |
> |
if (type != 0 && (ms->flags & type) == 0) |
418 |
|
continue; |
419 |
|
|
420 |
< |
if (MyClient(target_p)) |
420 |
> |
if (MyConnect(target_p)) |
421 |
|
{ |
422 |
< |
if (target_p->serial != current_serial) |
422 |
> |
if (target_p->localClient->serial != current_serial) |
423 |
|
{ |
424 |
|
send_message(target_p, local_buf, local_len); |
425 |
< |
target_p->serial = current_serial; |
425 |
> |
target_p->localClient->serial = current_serial; |
426 |
|
} |
427 |
|
} |
428 |
|
else |
430 |
|
/* Now check whether a message has been sent to this |
431 |
|
* remote link already |
432 |
|
*/ |
433 |
< |
if (target_p->from->serial != current_serial) |
433 |
> |
if (target_p->from->localClient->serial != current_serial) |
434 |
|
{ |
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 |
< |
target_p->from->serial = current_serial; |
439 |
> |
target_p->from->localClient->serial = current_serial; |
440 |
|
} |
441 |
|
} |
442 |
|
} |
445 |
|
/* sendto_server() |
446 |
|
* |
447 |
|
* inputs - pointer to client to NOT send to |
448 |
< |
* - pointer to source client required by LL (if any) |
532 |
< |
* - pointer to channel required by LL (if any) |
448 |
> |
* - pointer to channel |
449 |
|
* - caps or'd together which must ALL be present |
450 |
|
* - caps or'd together which must ALL NOT be present |
535 |
– |
* - LL flags: LL_ICLIENT | LL_ICHAN |
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'. |
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. |
457 |
|
* |
458 |
|
* This function was written in an attempt to merge together the other |
459 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
461 |
|
* -davidt |
462 |
|
*/ |
463 |
|
void |
464 |
< |
sendto_server(struct Client *one, struct Client *source_p, |
465 |
< |
struct Channel *chptr, unsigned long caps, |
466 |
< |
unsigned long nocaps, unsigned long llflags, |
464 |
> |
sendto_server(struct Client *one, |
465 |
> |
const unsigned int caps, |
466 |
> |
const unsigned int nocaps, |
467 |
|
const char *format, ...) |
468 |
|
{ |
469 |
|
va_list args; |
470 |
< |
struct Client *client_p; |
563 |
< |
dlink_node *ptr; |
470 |
> |
dlink_node *ptr = NULL; |
471 |
|
char buffer[IRCD_BUFSIZE]; |
472 |
< |
int len; |
566 |
< |
|
567 |
< |
if (chptr != NULL) |
568 |
< |
{ |
569 |
< |
if (chptr->chname[0] != '#') |
570 |
< |
return; |
571 |
< |
} |
472 |
> |
int len = 0; |
473 |
|
|
474 |
|
va_start(args, format); |
475 |
|
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
477 |
|
|
478 |
|
DLINK_FOREACH(ptr, serv_list.head) |
479 |
|
{ |
480 |
< |
client_p = ptr->data; |
480 |
> |
struct Client *client_p = ptr->data; |
481 |
|
|
482 |
|
/* If dead already skip */ |
483 |
|
if (IsDead(client_p)) |
492 |
|
if ((client_p->localClient->caps & nocaps) != 0) |
493 |
|
continue; |
494 |
|
|
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 |
– |
} |
495 |
|
send_message(client_p, buffer, len); |
496 |
|
} |
497 |
|
} |
529 |
|
chptr = ((struct Membership *) cptr->data)->chptr; |
530 |
|
assert(chptr != NULL); |
531 |
|
|
532 |
< |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
532 |
> |
DLINK_FOREACH(uptr, chptr->members.head) |
533 |
|
{ |
534 |
|
ms = uptr->data; |
535 |
|
target_p = ms->client_p; |
536 |
|
assert(target_p != NULL); |
537 |
|
|
538 |
< |
if (target_p == user || IsDefunct(target_p) || |
539 |
< |
target_p->serial == current_serial) |
538 |
> |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
539 |
> |
target_p->localClient->serial == current_serial) |
540 |
|
continue; |
541 |
|
|
542 |
< |
target_p->serial = current_serial; |
542 |
> |
target_p->localClient->serial = current_serial; |
543 |
|
send_message(target_p, buffer, len); |
544 |
|
} |
545 |
|
} |
546 |
|
|
547 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
548 |
< |
user->serial != current_serial) |
548 |
> |
user->localClient->serial != current_serial) |
549 |
|
send_message(user, buffer, len); |
550 |
|
} |
551 |
|
|
574 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
575 |
|
va_end(args); |
576 |
|
|
577 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
577 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
578 |
|
{ |
579 |
|
ms = ptr->data; |
580 |
|
target_p = ms->client_p; |
582 |
|
if (type != 0 && (ms->flags & type) == 0) |
583 |
|
continue; |
584 |
|
|
585 |
< |
if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p))) |
585 |
> |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
586 |
> |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
587 |
|
continue; |
588 |
|
|
589 |
|
send_message(target_p, buffer, len); |
617 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
618 |
|
va_end(args); |
619 |
|
|
620 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
620 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
621 |
|
{ |
622 |
|
ms = ptr->data; |
623 |
|
target_p = ms->client_p; |
625 |
|
if (type != 0 && (ms->flags & type) == 0) |
626 |
|
continue; |
627 |
|
|
628 |
< |
if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p)) |
628 |
> |
if (!MyConnect(target_p) || target_p == one || |
629 |
> |
IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
630 |
|
continue; |
631 |
|
send_message(target_p, buffer, len); |
632 |
|
} |
645 |
|
* remote to this server. |
646 |
|
*/ |
647 |
|
void |
648 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
649 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
648 |
> |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
649 |
> |
const unsigned int caps, const unsigned int nocaps, |
650 |
> |
struct Channel *chptr, const char *pattern, ...) |
651 |
|
{ |
652 |
|
va_list args; |
653 |
|
char buffer[IRCD_BUFSIZE]; |
660 |
|
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
661 |
|
va_end(args); |
662 |
|
|
663 |
+ |
++current_serial; |
664 |
+ |
|
665 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
666 |
|
{ |
667 |
|
ms = ptr->data; |
678 |
|
((target_p->from->localClient->caps & caps) != caps) || |
679 |
|
((target_p->from->localClient->caps & nocaps) != 0)) |
680 |
|
continue; |
681 |
< |
|
682 |
< |
send_message(target_p, buffer, len); |
681 |
> |
if (target_p->from->localClient->serial != current_serial) |
682 |
> |
{ |
683 |
> |
send_message(target_p, buffer, len); |
684 |
> |
target_p->from->localClient->serial = current_serial; |
685 |
> |
} |
686 |
|
} |
687 |
|
} |
688 |
|
|
707 |
|
match_it(const struct Client *one, const char *mask, int what) |
708 |
|
{ |
709 |
|
if (what == MATCH_HOST) |
710 |
< |
return(match(mask, one->host)); |
710 |
> |
return match(mask, one->host); |
711 |
|
|
712 |
< |
return(match(mask, one->servptr->name)); |
712 |
> |
return match(mask, one->servptr->name); |
713 |
|
} |
714 |
|
|
715 |
|
/* sendto_match_butone() |
723 |
|
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
724 |
|
int what, const char *pattern, ...) |
725 |
|
{ |
726 |
< |
va_list args; |
726 |
> |
va_list alocal, aremote; |
727 |
|
struct Client *client_p; |
728 |
|
dlink_node *ptr, *ptr_next; |
729 |
|
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
731 |
|
from->username, from->host); |
732 |
|
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
733 |
|
|
734 |
< |
va_start(args, pattern); |
734 |
> |
va_start(alocal, pattern); |
735 |
> |
va_start(aremote, pattern); |
736 |
|
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
737 |
< |
pattern, args); |
737 |
> |
pattern, alocal); |
738 |
|
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
739 |
< |
pattern, args); |
740 |
< |
va_end(args); |
739 |
> |
pattern, aremote); |
740 |
> |
va_end(aremote); |
741 |
> |
va_end(alocal); |
742 |
|
|
743 |
|
/* scan the local clients */ |
744 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
807 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
808 |
|
va_end(args); |
809 |
|
|
810 |
< |
current_serial++; |
810 |
> |
++current_serial; |
811 |
|
|
812 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
813 |
|
{ |
817 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
818 |
|
continue; |
819 |
|
|
820 |
< |
if (target_p->from->serial == current_serial) |
820 |
> |
if (target_p->from->localClient->serial == current_serial) |
821 |
|
continue; |
822 |
|
|
823 |
|
if (match(mask, target_p->name)) |
826 |
|
* if we set the serial here, then we'll never do a |
827 |
|
* match() again, if !IsCapable() |
828 |
|
*/ |
829 |
< |
target_p->from->serial = current_serial; |
829 |
> |
target_p->from->localClient->serial = current_serial; |
830 |
|
found++; |
831 |
|
|
832 |
|
if (!IsCapable(target_p->from, cap)) |
894 |
|
void |
895 |
|
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
896 |
|
{ |
897 |
< |
struct Client *client_p; |
897 |
> |
dlink_node *ptr = NULL; |
898 |
|
char nbuf[IRCD_BUFSIZE]; |
1017 |
– |
dlink_node *ptr; |
899 |
|
va_list args; |
900 |
|
|
901 |
|
va_start(args, pattern); |
904 |
|
|
905 |
|
DLINK_FOREACH(ptr, oper_list.head) |
906 |
|
{ |
907 |
< |
client_p = ptr->data; |
908 |
< |
assert(client_p->umodes & UMODE_OPER); |
907 |
> |
struct Client *client_p = ptr->data; |
908 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
909 |
|
|
910 |
|
/* If we're sending it to opers and theyre an admin, skip. |
911 |
|
* If we're sending it to admins, and theyre not, skip. |
912 |
|
*/ |
913 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
914 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
913 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
914 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
915 |
|
continue; |
916 |
|
|
917 |
< |
if (client_p->umodes & flags) |
917 |
> |
if (HasUMode(client_p, flags)) |
918 |
|
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
919 |
|
me.name, client_p->name, nbuf); |
920 |
|
} |
921 |
|
} |
922 |
|
|
923 |
+ |
void |
924 |
+ |
sendto_globops_flags(unsigned int flags, int level, const char *pattern, ...) |
925 |
+ |
{ |
926 |
+ |
dlink_node *ptr = NULL; |
927 |
+ |
char nbuf[IRCD_BUFSIZE]; |
928 |
+ |
va_list args; |
929 |
+ |
|
930 |
+ |
va_start(args, pattern); |
931 |
+ |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
932 |
+ |
va_end(args); |
933 |
+ |
|
934 |
+ |
DLINK_FOREACH(ptr, oper_list.head) |
935 |
+ |
{ |
936 |
+ |
struct Client *client_p = ptr->data; |
937 |
+ |
assert(client_p->umodes & UMODE_OPER); |
938 |
+ |
|
939 |
+ |
/* If we're sending it to opers and theyre an admin, skip. |
940 |
+ |
* If we're sending it to admins, and theyre not, skip. |
941 |
+ |
*/ |
942 |
+ |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
943 |
+ |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
944 |
+ |
continue; |
945 |
+ |
|
946 |
+ |
if (HasUMode(client_p, flags)) |
947 |
+ |
sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s", |
948 |
+ |
me.name, client_p->name, nbuf); |
949 |
+ |
} |
950 |
+ |
} |
951 |
+ |
|
952 |
|
/* sendto_wallops_flags() |
953 |
|
* |
954 |
|
* inputs - flag types of messages to show to real opers |
961 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
962 |
|
const char *pattern, ...) |
963 |
|
{ |
964 |
< |
struct Client *client_p; |
1055 |
< |
dlink_node *ptr; |
964 |
> |
dlink_node *ptr = NULL; |
965 |
|
va_list args; |
966 |
|
char buffer[IRCD_BUFSIZE]; |
967 |
|
int len; |
978 |
|
|
979 |
|
DLINK_FOREACH(ptr, oper_list.head) |
980 |
|
{ |
981 |
< |
client_p = ptr->data; |
981 |
> |
struct Client *client_p = ptr->data; |
982 |
|
assert(client_p->umodes & UMODE_OPER); |
983 |
|
|
984 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
984 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
985 |
|
send_message(client_p, buffer, len); |
986 |
|
} |
987 |
|
} |
997 |
|
ts_warn(const char *pattern, ...) |
998 |
|
{ |
999 |
|
va_list args; |
1000 |
< |
char buffer[LOG_BUFSIZE]; |
1000 |
> |
char buffer[IRCD_BUFSIZE]; |
1001 |
|
static time_t last = 0; |
1002 |
|
static int warnings = 0; |
1003 |
|
|
1020 |
|
} |
1021 |
|
|
1022 |
|
va_start(args, pattern); |
1023 |
< |
vsprintf_irc(buffer, pattern, args); |
1023 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
1024 |
|
va_end(args); |
1025 |
|
|
1026 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
1027 |
< |
ilog(L_CRIT, "%s", buffer); |
1027 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
1028 |
|
} |
1029 |
|
|
1030 |
|
/* kill_client() |
1074 |
|
{ |
1075 |
|
va_list args; |
1076 |
|
int have_uid = 0; |
1077 |
< |
struct Client *client_p; |
1169 |
< |
dlink_node *ptr; |
1077 |
> |
dlink_node *ptr = NULL; |
1078 |
|
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1079 |
< |
int len_uid = 0, len_nick; |
1079 |
> |
int len_uid = 0, len_nick = 0; |
1080 |
|
|
1081 |
< |
va_start(args, pattern); |
1174 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
1081 |
> |
if (HasID(source_p)) |
1082 |
|
{ |
1083 |
|
have_uid = 1; |
1084 |
+ |
va_start(args, pattern); |
1085 |
|
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1086 |
|
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
1087 |
|
args); |
1088 |
+ |
va_end(args); |
1089 |
|
} |
1090 |
+ |
|
1091 |
+ |
va_start(args, pattern); |
1092 |
|
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1093 |
|
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
1094 |
|
args); |
1096 |
|
|
1097 |
|
DLINK_FOREACH(ptr, serv_list.head) |
1098 |
|
{ |
1099 |
< |
client_p = ptr->data; |
1099 |
> |
struct Client *client_p = ptr->data; |
1100 |
|
|
1101 |
|
if (one != NULL && (client_p == one->from)) |
1102 |
|
continue; |
1103 |
|
if (IsDefunct(client_p)) |
1104 |
|
continue; |
1105 |
|
|
1106 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
1107 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
1108 |
< |
!ServerInfo.hub || |
1109 |
< |
(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 |
< |
} |
1106 |
> |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1107 |
> |
send_message(client_p, buf_uid, len_uid); |
1108 |
> |
else |
1109 |
> |
send_message(client_p, buf_nick, len_nick); |
1110 |
|
} |
1111 |
|
} |