| 1 |
|
/* |
| 2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
< |
* send.c: Functions for sending messages. |
| 2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
|
* |
| 4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
* it under the terms of the GNU General Public License as published by |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
|
* USA |
| 20 |
< |
* |
| 21 |
< |
* $Id$ |
| 20 |
> |
*/ |
| 21 |
> |
|
| 22 |
> |
/*! \file send.c |
| 23 |
> |
* \brief Functions for sending messages. |
| 24 |
> |
* \version $Id$ |
| 25 |
|
*/ |
| 26 |
|
|
| 27 |
|
#include "stdinc.h" |
| 35 |
|
#include "numeric.h" |
| 36 |
|
#include "fdlist.h" |
| 37 |
|
#include "s_bsd.h" |
| 38 |
< |
#include "s_serv.h" |
| 37 |
< |
#include "sprintf_irc.h" |
| 38 |
> |
#include "server.h" |
| 39 |
|
#include "conf.h" |
| 40 |
|
#include "log.h" |
| 41 |
|
#include "memory.h" |
| 41 |
– |
#include "hook.h" |
| 42 |
|
#include "packet.h" |
| 43 |
|
|
| 44 |
|
|
| 45 |
– |
struct Callback *iosend_cb = NULL; |
| 45 |
|
static unsigned int current_serial = 0; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
/* send_format() |
| 49 |
|
* |
| 50 |
< |
* inputs - buffer to format into |
| 51 |
< |
* - size of the buffer |
| 50 |
> |
* inputs |
| 51 |
> |
* - buffer |
| 52 |
|
* - format pattern to use |
| 53 |
|
* - var args |
| 54 |
|
* output - number of bytes formatted output |
| 55 |
|
* side effects - modifies sendbuf |
| 56 |
|
*/ |
| 57 |
< |
static inline int |
| 58 |
< |
send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args) |
| 57 |
> |
static void |
| 58 |
> |
send_format(struct dbuf_block *buffer, const char *pattern, va_list args) |
| 59 |
|
{ |
| 61 |
– |
int len; |
| 62 |
– |
|
| 60 |
|
/* |
| 61 |
|
* from rfc1459 |
| 62 |
|
* |
| 63 |
|
* IRC messages are always lines of characters terminated with a CR-LF |
| 64 |
|
* (Carriage Return - Line Feed) pair, and these messages shall not |
| 65 |
< |
* exceed 512 characters in length, counting all characters |
| 65 |
> |
* exceed 512 characters in length, counting all characters |
| 66 |
|
* including the trailing CR-LF. |
| 67 |
|
* Thus, there are 510 characters maximum allowed |
| 68 |
|
* for the command and its parameters. There is no provision for |
| 69 |
|
* continuation message lines. See section 7 for more details about |
| 70 |
|
* current implementations. |
| 71 |
|
*/ |
| 72 |
< |
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 |
< |
return len; |
| 82 |
< |
} |
| 72 |
> |
dbuf_put_args(buffer, pattern, args); |
| 73 |
|
|
| 74 |
< |
/* |
| 75 |
< |
* 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 *); |
| 74 |
> |
if (buffer->size > sizeof(buffer->data) - 2) |
| 75 |
> |
buffer->size = sizeof(buffer->data) - 2; |
| 76 |
|
|
| 77 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, length); |
| 78 |
< |
return NULL; |
| 77 |
> |
buffer->data[buffer->size++] = '\r'; |
| 78 |
> |
buffer->data[buffer->size++] = '\n'; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
/* |
| 84 |
|
** sendq. |
| 85 |
|
*/ |
| 86 |
|
static void |
| 87 |
< |
send_message(struct Client *to, char *buf, int len) |
| 87 |
> |
send_message(struct Client *to, struct dbuf_block *buf) |
| 88 |
|
{ |
| 89 |
|
assert(!IsMe(to)); |
| 90 |
|
assert(to != &me); |
| 91 |
|
|
| 92 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
| 92 |
> |
if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs)) |
| 93 |
|
{ |
| 94 |
|
if (IsServer(to)) |
| 95 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 96 |
< |
"Max SendQ limit exceeded for %s: %lu > %lu", |
| 95 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 96 |
> |
"Max SendQ limit exceeded for %s: %lu > %u", |
| 97 |
|
get_client_name(to, HIDE_IP), |
| 98 |
< |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len), |
| 99 |
< |
get_sendq(to)); |
| 98 |
> |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size), |
| 99 |
> |
get_sendq(&to->localClient->confs)); |
| 100 |
|
if (IsClient(to)) |
| 101 |
|
SetSendQExceeded(to); |
| 102 |
+ |
|
| 103 |
|
dead_link_on_write(to, 0); |
| 104 |
|
return; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
< |
execute_callback(iosend_cb, to, len, buf); |
| 107 |
> |
dbuf_add(&to->localClient->buf_sendq, buf); |
| 108 |
|
|
| 109 |
|
/* |
| 110 |
< |
** Update statistics. The following is slightly incorrect |
| 111 |
< |
** because it counts messages even if queued, but bytes |
| 112 |
< |
** only really sent. Queued bytes get updated in SendQueued. |
| 110 |
> |
* Update statistics. The following is slightly incorrect because |
| 111 |
> |
* it counts messages even if queued, but bytes only really sent. |
| 112 |
> |
* Queued bytes get updated in send_queued_write(). |
| 113 |
|
*/ |
| 114 |
|
++to->localClient->send.messages; |
| 115 |
|
++me.localClient->send.messages; |
| 116 |
|
|
| 117 |
< |
if (dbuf_length(&to->localClient->buf_sendq) > |
| 134 |
< |
(IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096)) |
| 135 |
< |
send_queued_write(to); |
| 117 |
> |
send_queued_write(to); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
/* send_message_remote() |
| 121 |
|
* |
| 122 |
|
* inputs - pointer to client from message is being sent |
| 123 |
|
* - pointer to client to send to |
| 124 |
< |
* - pointer to preformatted buffer |
| 143 |
< |
* - length of input buffer |
| 124 |
> |
* - pointer to buffer |
| 125 |
|
* output - none |
| 126 |
|
* side effects - Despite the function name, this only sends to directly |
| 127 |
|
* connected clients. |
| 128 |
< |
* |
| 128 |
> |
* |
| 129 |
|
*/ |
| 130 |
|
static void |
| 131 |
< |
send_message_remote(struct Client *to, struct Client *from, |
| 151 |
< |
char *buf, int len) |
| 131 |
> |
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
| 132 |
|
{ |
| 133 |
+ |
to = to->from; |
| 134 |
+ |
|
| 135 |
|
if (!MyConnect(to)) |
| 136 |
|
{ |
| 137 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 138 |
< |
"server send message to %s [%s] dropped from %s(Not local server)", |
| 139 |
< |
to->name, to->from->name, from->name); |
| 137 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 138 |
> |
"Server send message to %s [%s] dropped from %s(Not local server)", |
| 139 |
> |
to->name, to->from->name, from->name); |
| 140 |
|
return; |
| 141 |
|
} |
| 142 |
|
|
| 147 |
|
{ |
| 148 |
|
if (IsServer(from)) |
| 149 |
|
{ |
| 150 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 150 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 151 |
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
| 152 |
|
to->name, to->from->name, from->name); |
| 153 |
|
return; |
| 154 |
|
} |
| 155 |
|
|
| 156 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 156 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
| 157 |
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
| 158 |
|
to->name, to->username, to->host, |
| 159 |
|
from->name, from->username, from->host, |
| 160 |
|
to->from->name); |
| 161 |
|
|
| 162 |
< |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
| 162 |
> |
sendto_server(NULL, NOCAPS, NOCAPS, |
| 163 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 164 |
< |
me.id, to->name, me.name, to->name, |
| 183 |
< |
to->username, to->host, to->from->name); |
| 184 |
< |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
| 185 |
< |
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
| 186 |
< |
me.name, to->name, me.name, to->name, |
| 164 |
> |
me.id, to->id, me.name, to->name, |
| 165 |
|
to->username, to->host, to->from->name); |
| 166 |
|
|
| 167 |
|
AddFlag(to, FLAGS_KILLED); |
| 168 |
|
|
| 169 |
|
if (IsClient(from)) |
| 170 |
< |
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
| 171 |
< |
me.name, from->name, to->name, to->username, |
| 194 |
< |
to->host, to->from); |
| 195 |
< |
|
| 196 |
< |
exit_client(to, &me, "Ghosted client"); |
| 170 |
> |
sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name, |
| 171 |
> |
to->username, to->host, to->from); |
| 172 |
|
|
| 173 |
+ |
exit_client(to, "Ghosted client"); |
| 174 |
|
return; |
| 175 |
< |
} |
| 175 |
> |
} |
| 176 |
|
|
| 177 |
< |
send_message(to, buf, len); |
| 177 |
> |
send_message(to, buf); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
/* |
| 184 |
|
void |
| 185 |
|
sendq_unblocked(fde_t *fd, struct Client *client_p) |
| 186 |
|
{ |
| 187 |
< |
ClearSendqBlocked(client_p); |
| 212 |
< |
/* let send_queued_write be executed by send_queued_all */ |
| 187 |
> |
assert(fd == &client_p->localClient->fd); |
| 188 |
|
|
| 189 |
< |
#ifdef HAVE_LIBCRYPTO |
| 190 |
< |
if (fd->flags.pending_read) |
| 216 |
< |
{ |
| 217 |
< |
fd->flags.pending_read = 0; |
| 218 |
< |
read_packet(fd, client_p); |
| 219 |
< |
} |
| 220 |
< |
#endif |
| 189 |
> |
DelFlag(client_p, FLAGS_BLOCKED); |
| 190 |
> |
send_queued_write(client_p); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
/* |
| 199 |
|
void |
| 200 |
|
send_queued_write(struct Client *to) |
| 201 |
|
{ |
| 202 |
< |
int retlen; |
| 233 |
< |
struct dbuf_block *first; |
| 202 |
> |
int retlen = 0; |
| 203 |
|
|
| 204 |
|
/* |
| 205 |
|
** Once socket is marked dead, we cannot start writing to it, |
| 206 |
|
** even if the error is removed... |
| 207 |
|
*/ |
| 208 |
< |
if (IsDead(to) || IsSendqBlocked(to)) |
| 208 |
> |
if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED)) |
| 209 |
|
return; /* no use calling send() now */ |
| 210 |
|
|
| 211 |
|
/* Next, lets try to write some data */ |
| 243 |
– |
|
| 212 |
|
if (dbuf_length(&to->localClient->buf_sendq)) |
| 213 |
|
{ |
| 214 |
< |
do { |
| 215 |
< |
first = to->localClient->buf_sendq.blocks.head->data; |
| 214 |
> |
do |
| 215 |
> |
{ |
| 216 |
> |
struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data; |
| 217 |
|
|
| 218 |
|
#ifdef HAVE_LIBCRYPTO |
| 219 |
|
if (to->localClient->fd.ssl) |
| 220 |
|
{ |
| 221 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size); |
| 221 |
> |
retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos); |
| 222 |
|
|
| 223 |
|
/* translate openssl error codes, sigh */ |
| 224 |
< |
if (retlen < 0) |
| 225 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
| 226 |
< |
{ |
| 224 |
> |
if (retlen < 0) |
| 225 |
> |
{ |
| 226 |
> |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
| 227 |
> |
{ |
| 228 |
|
case SSL_ERROR_WANT_READ: |
| 229 |
< |
return; /* retry later, don't register for write events */ |
| 230 |
< |
|
| 231 |
< |
case SSL_ERROR_WANT_WRITE: |
| 262 |
< |
errno = EWOULDBLOCK; |
| 229 |
> |
return; /* retry later, don't register for write events */ |
| 230 |
> |
case SSL_ERROR_WANT_WRITE: |
| 231 |
> |
errno = EWOULDBLOCK; |
| 232 |
|
case SSL_ERROR_SYSCALL: |
| 233 |
< |
break; |
| 233 |
> |
break; |
| 234 |
|
case SSL_ERROR_SSL: |
| 235 |
|
if (errno == EAGAIN) |
| 236 |
|
break; |
| 237 |
|
default: |
| 238 |
< |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
| 239 |
< |
} |
| 238 |
> |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
| 239 |
> |
} |
| 240 |
> |
} |
| 241 |
|
} |
| 242 |
|
else |
| 243 |
|
#endif |
| 244 |
< |
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
| 244 |
> |
retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0); |
| 245 |
|
|
| 246 |
|
if (retlen <= 0) |
| 247 |
|
break; |
| 253 |
|
me.localClient->send.bytes += retlen; |
| 254 |
|
} while (dbuf_length(&to->localClient->buf_sendq)); |
| 255 |
|
|
| 256 |
< |
if ((retlen < 0) && (ignoreErrno(errno))) |
| 256 |
> |
if (retlen < 0 && ignoreErrno(errno)) |
| 257 |
|
{ |
| 258 |
+ |
AddFlag(to, FLAGS_BLOCKED); |
| 259 |
+ |
|
| 260 |
|
/* we have a non-fatal error, reschedule a write */ |
| 289 |
– |
SetSendqBlocked(to); |
| 261 |
|
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
| 262 |
< |
(PF *)sendq_unblocked, (void *)to, 0); |
| 262 |
> |
(PF *)sendq_unblocked, to, 0); |
| 263 |
|
} |
| 264 |
|
else if (retlen <= 0) |
| 265 |
|
{ |
| 284 |
|
* a notice to opers, which is to be delivered by this function. |
| 285 |
|
*/ |
| 286 |
|
DLINK_FOREACH(ptr, serv_list.head) |
| 287 |
< |
send_queued_write((struct Client *) ptr->data); |
| 287 |
> |
send_queued_write(ptr->data); |
| 288 |
|
|
| 289 |
|
DLINK_FOREACH(ptr, unknown_list.head) |
| 290 |
< |
send_queued_write((struct Client *) ptr->data); |
| 290 |
> |
send_queued_write(ptr->data); |
| 291 |
|
|
| 292 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 293 |
< |
send_queued_write((struct Client *) ptr->data); |
| 293 |
> |
send_queued_write(ptr->data); |
| 294 |
|
|
| 295 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
| 296 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
| 311 |
|
sendto_one(struct Client *to, const char *pattern, ...) |
| 312 |
|
{ |
| 313 |
|
va_list args; |
| 314 |
< |
char buffer[IRCD_BUFSIZE]; |
| 315 |
< |
int len; |
| 314 |
> |
struct dbuf_block *buffer = NULL; |
| 315 |
> |
|
| 316 |
> |
if (IsDead(to->from)) |
| 317 |
> |
return; /* This socket has already been marked as dead */ |
| 318 |
> |
|
| 319 |
> |
buffer = dbuf_alloc(); |
| 320 |
> |
|
| 321 |
> |
va_start(args, pattern); |
| 322 |
> |
send_format(buffer, pattern, args); |
| 323 |
> |
va_end(args); |
| 324 |
> |
|
| 325 |
> |
send_message(to->from, buffer); |
| 326 |
> |
|
| 327 |
> |
dbuf_ref_free(buffer); |
| 328 |
> |
} |
| 329 |
> |
|
| 330 |
> |
void |
| 331 |
> |
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
| 332 |
> |
{ |
| 333 |
> |
struct dbuf_block *buffer = NULL; |
| 334 |
> |
const char *dest = NULL, *numstr = NULL; |
| 335 |
> |
va_list args; |
| 336 |
> |
|
| 337 |
> |
if (IsDead(to->from)) |
| 338 |
> |
return; |
| 339 |
> |
|
| 340 |
> |
dest = ID_or_name(to, to); |
| 341 |
|
|
| 342 |
< |
if (to->from != NULL) |
| 343 |
< |
to = to->from; |
| 344 |
< |
if (IsDead(to)) |
| 345 |
< |
return; /* This socket has already been marked as dead */ |
| 342 |
> |
if (EmptyString(dest)) |
| 343 |
> |
dest = "*"; |
| 344 |
> |
|
| 345 |
> |
buffer = dbuf_alloc(); |
| 346 |
> |
|
| 347 |
> |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest); |
| 348 |
> |
|
| 349 |
> |
va_start(args, numeric); |
| 350 |
> |
|
| 351 |
> |
if (numeric & SND_EXPLICIT) |
| 352 |
> |
numstr = va_arg(args, const char *); |
| 353 |
> |
else |
| 354 |
> |
numstr = numeric_form(numeric); |
| 355 |
> |
send_format(buffer, numstr, args); |
| 356 |
> |
va_end(args); |
| 357 |
> |
|
| 358 |
> |
send_message(to->from, buffer); |
| 359 |
> |
|
| 360 |
> |
dbuf_ref_free(buffer); |
| 361 |
> |
} |
| 362 |
> |
|
| 363 |
> |
void |
| 364 |
> |
sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...) |
| 365 |
> |
{ |
| 366 |
> |
struct dbuf_block *buffer = NULL; |
| 367 |
> |
const char *dest = NULL; |
| 368 |
> |
va_list args; |
| 369 |
> |
|
| 370 |
> |
if (IsDead(to->from)) |
| 371 |
> |
return; |
| 372 |
> |
|
| 373 |
> |
dest = ID_or_name(to, to); |
| 374 |
> |
|
| 375 |
> |
if (EmptyString(dest)) |
| 376 |
> |
dest = "*"; |
| 377 |
> |
|
| 378 |
> |
buffer = dbuf_alloc(); |
| 379 |
> |
|
| 380 |
> |
dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest); |
| 381 |
|
|
| 382 |
|
va_start(args, pattern); |
| 383 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 383 |
> |
send_format(buffer, pattern, args); |
| 384 |
|
va_end(args); |
| 385 |
|
|
| 386 |
< |
send_message(to, buffer, len); |
| 386 |
> |
send_message(to->from, buffer); |
| 387 |
> |
|
| 388 |
> |
dbuf_ref_free(buffer); |
| 389 |
|
} |
| 390 |
|
|
| 391 |
|
/* sendto_channel_butone() |
| 401 |
|
*/ |
| 402 |
|
void |
| 403 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
| 404 |
< |
struct Channel *chptr, const char *command, |
| 404 |
> |
struct Channel *chptr, unsigned int type, |
| 405 |
|
const char *pattern, ...) |
| 406 |
|
{ |
| 407 |
< |
va_list alocal, aremote, auid; |
| 408 |
< |
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; |
| 407 |
> |
va_list alocal, aremote; |
| 408 |
> |
struct dbuf_block *local_buf, *remote_buf; |
| 409 |
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 410 |
|
|
| 411 |
+ |
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 412 |
+ |
|
| 413 |
|
if (IsServer(from)) |
| 414 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
| 383 |
< |
from->name, command, chptr->chname); |
| 414 |
> |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
| 415 |
|
else |
| 416 |
< |
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
| 417 |
< |
from->name, from->username, from->host, |
| 418 |
< |
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); |
| 416 |
> |
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
| 417 |
> |
|
| 418 |
> |
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
| 419 |
|
|
| 420 |
|
va_start(alocal, pattern); |
| 421 |
|
va_start(aremote, pattern); |
| 422 |
< |
va_start(auid, pattern); |
| 423 |
< |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
| 424 |
< |
pattern, alocal); |
| 398 |
< |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
| 399 |
< |
pattern, aremote); |
| 400 |
< |
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
| 401 |
< |
auid); |
| 402 |
< |
va_end(auid); |
| 422 |
> |
send_format(local_buf, pattern, alocal); |
| 423 |
> |
send_format(remote_buf, pattern, aremote); |
| 424 |
> |
|
| 425 |
|
va_end(aremote); |
| 426 |
|
va_end(alocal); |
| 427 |
|
|
| 429 |
|
|
| 430 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
| 431 |
|
{ |
| 432 |
< |
struct Client *target_p = ((struct Membership *)ptr->data)->client_p; |
| 432 |
> |
struct Membership *ms = ptr->data; |
| 433 |
> |
struct Client *target_p = ms->client_p; |
| 434 |
|
|
| 435 |
|
assert(IsClient(target_p)); |
| 436 |
|
|
| 437 |
< |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || target_p->from == one) |
| 437 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || |
| 438 |
> |
(one && target_p->from == one->from)) |
| 439 |
> |
continue; |
| 440 |
> |
|
| 441 |
> |
if (type && (ms->flags & type) == 0) |
| 442 |
|
continue; |
| 443 |
|
|
| 444 |
|
if (MyConnect(target_p)) |
| 445 |
< |
{ |
| 446 |
< |
if (target_p->localClient->serial != current_serial) |
| 447 |
< |
{ |
| 448 |
< |
send_message(target_p, local_buf, local_len); |
| 422 |
< |
target_p->localClient->serial = current_serial; |
| 423 |
< |
} |
| 424 |
< |
} |
| 425 |
< |
else |
| 426 |
< |
{ |
| 427 |
< |
/* Now check whether a message has been sent to this |
| 428 |
< |
* remote link already |
| 429 |
< |
*/ |
| 430 |
< |
if (target_p->from->localClient->serial != current_serial) |
| 431 |
< |
{ |
| 432 |
< |
if (IsCapable(target_p->from, CAP_TS6)) |
| 433 |
< |
send_message_remote(target_p->from, from, uid_buf, uid_len); |
| 434 |
< |
else |
| 435 |
< |
send_message_remote(target_p->from, from, remote_buf, remote_len); |
| 436 |
< |
target_p->from->localClient->serial = current_serial; |
| 437 |
< |
} |
| 438 |
< |
} |
| 445 |
> |
send_message(target_p, local_buf); |
| 446 |
> |
else if (target_p->from->localClient->serial != current_serial) |
| 447 |
> |
send_message_remote(target_p->from, from, remote_buf); |
| 448 |
> |
target_p->from->localClient->serial = current_serial; |
| 449 |
|
} |
| 450 |
+ |
|
| 451 |
+ |
dbuf_ref_free(local_buf); |
| 452 |
+ |
dbuf_ref_free(remote_buf); |
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
/* sendto_server() |
| 456 |
< |
* |
| 456 |
> |
* |
| 457 |
|
* inputs - pointer to client to NOT send to |
| 458 |
|
* - pointer to channel |
| 459 |
|
* - caps or'd together which must ALL be present |
| 464 |
|
* side effects - Send a message to all connected servers, except the |
| 465 |
|
* client 'one' (if non-NULL), as long as the servers |
| 466 |
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
| 467 |
< |
* |
| 467 |
> |
* |
| 468 |
|
* This function was written in an attempt to merge together the other |
| 469 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
| 470 |
|
* lazylinks, uids, etc. |
| 471 |
|
* -davidt |
| 472 |
|
*/ |
| 473 |
< |
void |
| 474 |
< |
sendto_server(struct Client *one, const struct Channel *chptr, |
| 473 |
> |
void |
| 474 |
> |
sendto_server(struct Client *one, |
| 475 |
|
const unsigned int caps, |
| 476 |
|
const unsigned int nocaps, |
| 477 |
|
const char *format, ...) |
| 478 |
|
{ |
| 479 |
|
va_list args; |
| 480 |
|
dlink_node *ptr = NULL; |
| 481 |
< |
char buffer[IRCD_BUFSIZE]; |
| 469 |
< |
int len = 0; |
| 481 |
> |
struct dbuf_block *buffer; |
| 482 |
|
|
| 483 |
< |
if (chptr && chptr->chname[0] != '#') |
| 472 |
< |
return; |
| 483 |
> |
buffer = dbuf_alloc(); |
| 484 |
|
|
| 485 |
|
va_start(args, format); |
| 486 |
< |
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
| 486 |
> |
send_format(buffer, format, args); |
| 487 |
|
va_end(args); |
| 488 |
|
|
| 489 |
|
DLINK_FOREACH(ptr, serv_list.head) |
| 494 |
|
if (IsDead(client_p)) |
| 495 |
|
continue; |
| 496 |
|
/* check against 'one' */ |
| 497 |
< |
if (one != NULL && (client_p == one->from)) |
| 497 |
> |
if (one && (client_p == one->from)) |
| 498 |
|
continue; |
| 499 |
|
/* check we have required capabs */ |
| 500 |
|
if ((client_p->localClient->caps & caps) != caps) |
| 501 |
|
continue; |
| 502 |
|
/* check we don't have any forbidden capabs */ |
| 503 |
< |
if ((client_p->localClient->caps & nocaps) != 0) |
| 503 |
> |
if ((client_p->localClient->caps & nocaps)) |
| 504 |
|
continue; |
| 505 |
|
|
| 506 |
< |
send_message(client_p, buffer, len); |
| 506 |
> |
send_message(client_p, buffer); |
| 507 |
|
} |
| 508 |
+ |
|
| 509 |
+ |
dbuf_ref_free(buffer); |
| 510 |
|
} |
| 511 |
|
|
| 512 |
|
/* sendto_common_channels_local() |
| 515 |
|
* - pattern to send |
| 516 |
|
* output - NONE |
| 517 |
|
* side effects - Sends a message to all people on local server who are |
| 518 |
< |
* in same channel with user. |
| 518 |
> |
* in same channel with user. |
| 519 |
|
* used by m_nick.c and exit_one_client. |
| 520 |
|
*/ |
| 521 |
|
void |
| 522 |
< |
sendto_common_channels_local(struct Client *user, int touser, |
| 522 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
| 523 |
|
const char *pattern, ...) |
| 524 |
|
{ |
| 525 |
|
va_list args; |
| 528 |
|
struct Channel *chptr; |
| 529 |
|
struct Membership *ms; |
| 530 |
|
struct Client *target_p; |
| 531 |
< |
char buffer[IRCD_BUFSIZE]; |
| 532 |
< |
int len; |
| 531 |
> |
struct dbuf_block *buffer; |
| 532 |
> |
|
| 533 |
> |
buffer = dbuf_alloc(); |
| 534 |
|
|
| 535 |
|
va_start(args, pattern); |
| 536 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 536 |
> |
send_format(buffer, pattern, args); |
| 537 |
|
va_end(args); |
| 538 |
|
|
| 539 |
|
++current_serial; |
| 540 |
|
|
| 541 |
|
DLINK_FOREACH(cptr, user->channel.head) |
| 542 |
|
{ |
| 543 |
< |
chptr = ((struct Membership *) cptr->data)->chptr; |
| 530 |
< |
assert(chptr != NULL); |
| 543 |
> |
chptr = ((struct Membership *)cptr->data)->chptr; |
| 544 |
|
|
| 545 |
|
DLINK_FOREACH(uptr, chptr->members.head) |
| 546 |
|
{ |
| 547 |
|
ms = uptr->data; |
| 548 |
|
target_p = ms->client_p; |
| 536 |
– |
assert(target_p != NULL); |
| 549 |
|
|
| 550 |
|
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
| 551 |
|
target_p->localClient->serial == current_serial) |
| 552 |
|
continue; |
| 553 |
|
|
| 554 |
+ |
if (HasCap(target_p, cap) != cap) |
| 555 |
+ |
continue; |
| 556 |
+ |
|
| 557 |
|
target_p->localClient->serial = current_serial; |
| 558 |
< |
send_message(target_p, buffer, len); |
| 558 |
> |
send_message(target_p, buffer); |
| 559 |
|
} |
| 560 |
|
} |
| 561 |
|
|
| 562 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
| 563 |
|
user->localClient->serial != current_serial) |
| 564 |
< |
send_message(user, buffer, len); |
| 564 |
> |
if (HasCap(user, cap) == cap) |
| 565 |
> |
send_message(user, buffer); |
| 566 |
> |
|
| 567 |
> |
dbuf_ref_free(buffer); |
| 568 |
|
} |
| 569 |
|
|
| 570 |
|
/* sendto_channel_local() |
| 578 |
|
* locally connected to this server. |
| 579 |
|
*/ |
| 580 |
|
void |
| 581 |
< |
sendto_channel_local(int type, int nodeaf, struct Channel *chptr, |
| 581 |
> |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
| 582 |
|
const char *pattern, ...) |
| 583 |
|
{ |
| 584 |
|
va_list args; |
| 585 |
< |
char buffer[IRCD_BUFSIZE]; |
| 586 |
< |
int len; |
| 587 |
< |
dlink_node *ptr; |
| 588 |
< |
struct Membership *ms; |
| 571 |
< |
struct Client *target_p; |
| 585 |
> |
dlink_node *ptr = NULL; |
| 586 |
> |
struct dbuf_block *buffer; |
| 587 |
> |
|
| 588 |
> |
buffer = dbuf_alloc(); |
| 589 |
|
|
| 590 |
|
va_start(args, pattern); |
| 591 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 591 |
> |
send_format(buffer, pattern, args); |
| 592 |
|
va_end(args); |
| 593 |
|
|
| 594 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
| 595 |
|
{ |
| 596 |
< |
ms = ptr->data; |
| 597 |
< |
target_p = ms->client_p; |
| 596 |
> |
struct Membership *ms = ptr->data; |
| 597 |
> |
struct Client *target_p = ms->client_p; |
| 598 |
|
|
| 599 |
< |
if (type != 0 && (ms->flags & type) == 0) |
| 599 |
> |
if (type && (ms->flags & type) == 0) |
| 600 |
|
continue; |
| 601 |
|
|
| 602 |
|
if (!MyConnect(target_p) || IsDefunct(target_p) || |
| 603 |
|
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
| 604 |
|
continue; |
| 605 |
|
|
| 606 |
< |
send_message(target_p, buffer, len); |
| 606 |
> |
send_message(target_p, buffer); |
| 607 |
|
} |
| 608 |
+ |
|
| 609 |
+ |
dbuf_ref_free(buffer); |
| 610 |
|
} |
| 611 |
|
|
| 612 |
|
/* sendto_channel_local_butone() |
| 621 |
|
* |
| 622 |
|
* WARNING - +D clients are omitted |
| 623 |
|
*/ |
| 605 |
– |
void |
| 606 |
– |
sendto_channel_local_butone(struct Client *one, int type, |
| 607 |
– |
struct Channel *chptr, const char *pattern, ...) |
| 608 |
– |
{ |
| 609 |
– |
va_list args; |
| 610 |
– |
char buffer[IRCD_BUFSIZE]; |
| 611 |
– |
int len; |
| 612 |
– |
struct Client *target_p; |
| 613 |
– |
struct Membership *ms; |
| 614 |
– |
dlink_node *ptr; |
| 615 |
– |
|
| 616 |
– |
va_start(args, pattern); |
| 617 |
– |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 618 |
– |
va_end(args); |
| 619 |
– |
|
| 620 |
– |
DLINK_FOREACH(ptr, chptr->members.head) |
| 621 |
– |
{ |
| 622 |
– |
ms = ptr->data; |
| 623 |
– |
target_p = ms->client_p; |
| 624 |
– |
|
| 625 |
– |
if (type != 0 && (ms->flags & type) == 0) |
| 626 |
– |
continue; |
| 627 |
– |
|
| 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 |
– |
} |
| 633 |
– |
} |
| 634 |
– |
|
| 635 |
– |
|
| 636 |
– |
/* sendto_channel_remote() |
| 637 |
– |
* |
| 638 |
– |
* inputs - Client not to send towards |
| 639 |
– |
* - Client from whom message is from |
| 640 |
– |
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
| 641 |
– |
* - pointer to channel to send to |
| 642 |
– |
* - var args pattern |
| 643 |
– |
* output - NONE |
| 644 |
– |
* side effects - Send a message to all members of a channel that are |
| 645 |
– |
* remote to this server. |
| 646 |
– |
*/ |
| 624 |
|
void |
| 625 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
| 626 |
< |
const unsigned int caps, const unsigned int nocaps, |
| 650 |
< |
struct Channel *chptr, const char *pattern, ...) |
| 625 |
> |
sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap, |
| 626 |
> |
struct Channel *chptr, const char *pattern, ...) |
| 627 |
|
{ |
| 628 |
|
va_list args; |
| 629 |
< |
char buffer[IRCD_BUFSIZE]; |
| 630 |
< |
int len; |
| 631 |
< |
dlink_node *ptr; |
| 632 |
< |
struct Client *target_p; |
| 657 |
< |
struct Membership *ms; |
| 629 |
> |
dlink_node *ptr = NULL; |
| 630 |
> |
struct dbuf_block *buffer; |
| 631 |
> |
|
| 632 |
> |
buffer = dbuf_alloc(); |
| 633 |
|
|
| 634 |
|
va_start(args, pattern); |
| 635 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
| 635 |
> |
send_format(buffer, pattern, args); |
| 636 |
|
va_end(args); |
| 637 |
|
|
| 663 |
– |
++current_serial; |
| 664 |
– |
|
| 638 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
| 639 |
|
{ |
| 640 |
< |
ms = ptr->data; |
| 641 |
< |
target_p = ms->client_p; |
| 640 |
> |
struct Membership *ms = ptr->data; |
| 641 |
> |
struct Client *target_p = ms->client_p; |
| 642 |
|
|
| 643 |
< |
if (type != 0 && (ms->flags & type) == 0) |
| 643 |
> |
if (type && (ms->flags & type) == 0) |
| 644 |
|
continue; |
| 645 |
|
|
| 646 |
< |
if (MyConnect(target_p)) |
| 646 |
> |
if (!MyConnect(target_p) || (one && target_p == one->from)) |
| 647 |
|
continue; |
| 675 |
– |
target_p = target_p->from; |
| 648 |
|
|
| 649 |
< |
if (target_p == one->from || |
| 678 |
< |
((target_p->from->localClient->caps & caps) != caps) || |
| 679 |
< |
((target_p->from->localClient->caps & nocaps) != 0)) |
| 649 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
| 650 |
|
continue; |
| 651 |
< |
if (target_p->from->localClient->serial != current_serial) |
| 652 |
< |
{ |
| 653 |
< |
send_message(target_p, buffer, len); |
| 654 |
< |
target_p->from->localClient->serial = current_serial; |
| 655 |
< |
} |
| 656 |
< |
} |
| 651 |
> |
|
| 652 |
> |
if (HasCap(target_p, cap) != cap) |
| 653 |
> |
continue; |
| 654 |
> |
|
| 655 |
> |
send_message(target_p, buffer); |
| 656 |
> |
} |
| 657 |
> |
|
| 658 |
> |
dbuf_ref_free(buffer); |
| 659 |
|
} |
| 660 |
|
|
| 661 |
|
/* |
| 676 |
|
* side effects - NONE |
| 677 |
|
*/ |
| 678 |
|
static int |
| 679 |
< |
match_it(const struct Client *one, const char *mask, int what) |
| 679 |
> |
match_it(const struct Client *one, const char *mask, unsigned int what) |
| 680 |
|
{ |
| 681 |
|
if (what == MATCH_HOST) |
| 682 |
< |
return match(mask, one->host); |
| 682 |
> |
return !match(mask, one->host); |
| 683 |
|
|
| 684 |
< |
return match(mask, one->servptr->name); |
| 684 |
> |
return !match(mask, one->servptr->name); |
| 685 |
|
} |
| 686 |
|
|
| 687 |
|
/* sendto_match_butone() |
| 692 |
|
* ugh. ONLY used by m_message.c to send an "oper magic" message. ugh. |
| 693 |
|
*/ |
| 694 |
|
void |
| 695 |
< |
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
| 695 |
> |
sendto_match_butone(struct Client *one, struct Client *from, const char *mask, |
| 696 |
|
int what, const char *pattern, ...) |
| 697 |
|
{ |
| 698 |
|
va_list alocal, aremote; |
| 699 |
< |
struct Client *client_p; |
| 700 |
< |
dlink_node *ptr, *ptr_next; |
| 701 |
< |
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
| 702 |
< |
int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name, |
| 703 |
< |
from->username, from->host); |
| 704 |
< |
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
| 699 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 700 |
> |
struct dbuf_block *local_buf, *remote_buf; |
| 701 |
> |
|
| 702 |
> |
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
| 703 |
> |
|
| 704 |
> |
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
| 705 |
> |
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
| 706 |
|
|
| 707 |
|
va_start(alocal, pattern); |
| 708 |
|
va_start(aremote, pattern); |
| 709 |
< |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
| 710 |
< |
pattern, alocal); |
| 738 |
< |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
| 739 |
< |
pattern, aremote); |
| 709 |
> |
send_format(local_buf, pattern, alocal); |
| 710 |
> |
send_format(remote_buf, pattern, aremote); |
| 711 |
|
va_end(aremote); |
| 712 |
|
va_end(alocal); |
| 713 |
|
|
| 714 |
|
/* scan the local clients */ |
| 715 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
| 716 |
|
{ |
| 717 |
< |
client_p = ptr->data; |
| 717 |
> |
struct Client *client_p = ptr->data; |
| 718 |
|
|
| 719 |
< |
if (client_p != one && !IsDefunct(client_p) && |
| 719 |
> |
if ((!one || client_p != one->from) && !IsDefunct(client_p) && |
| 720 |
|
match_it(client_p, mask, what)) |
| 721 |
< |
send_message(client_p, local_buf, local_len); |
| 721 |
> |
send_message(client_p, local_buf); |
| 722 |
|
} |
| 723 |
|
|
| 724 |
|
/* Now scan servers */ |
| 725 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
| 726 |
|
{ |
| 727 |
< |
client_p = ptr->data; |
| 727 |
> |
struct Client *client_p = ptr->data; |
| 728 |
|
|
| 729 |
|
/* |
| 730 |
|
* The old code looped through every client on the |
| 750 |
|
* server deal with it. |
| 751 |
|
* -wnder |
| 752 |
|
*/ |
| 753 |
< |
if (client_p != one && !IsDefunct(client_p)) |
| 754 |
< |
send_message_remote(client_p, from, remote_buf, remote_len); |
| 753 |
> |
if ((!one || client_p != one->from) && !IsDefunct(client_p)) |
| 754 |
> |
send_message_remote(client_p, from, remote_buf); |
| 755 |
|
} |
| 756 |
+ |
|
| 757 |
+ |
dbuf_ref_free(local_buf); |
| 758 |
+ |
dbuf_ref_free(remote_buf); |
| 759 |
|
} |
| 760 |
|
|
| 761 |
|
/* sendto_match_servs() |
| 768 |
|
* side effects - data sent to servers matching with capab |
| 769 |
|
*/ |
| 770 |
|
void |
| 771 |
< |
sendto_match_servs(struct Client *source_p, const char *mask, int cap, |
| 771 |
> |
sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap, |
| 772 |
|
const char *pattern, ...) |
| 773 |
|
{ |
| 774 |
|
va_list args; |
| 775 |
< |
struct Client *target_p; |
| 776 |
< |
dlink_node *ptr; |
| 777 |
< |
char buffer[IRCD_BUFSIZE]; |
| 778 |
< |
int found = 0; |
| 775 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
| 776 |
> |
struct dbuf_block *buff_suid; |
| 777 |
> |
|
| 778 |
> |
buff_suid = dbuf_alloc(); |
| 779 |
|
|
| 780 |
|
va_start(args, pattern); |
| 781 |
< |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 781 |
> |
dbuf_put_fmt(buff_suid, ":%s ", source_p->id); |
| 782 |
> |
dbuf_put_args(buff_suid, pattern, args); |
| 783 |
|
va_end(args); |
| 784 |
|
|
| 785 |
|
++current_serial; |
| 786 |
|
|
| 787 |
< |
DLINK_FOREACH(ptr, global_serv_list.head) |
| 787 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, global_serv_list.head) |
| 788 |
|
{ |
| 789 |
< |
target_p = ptr->data; |
| 789 |
> |
struct Client *target_p = ptr->data; |
| 790 |
|
|
| 791 |
|
/* Do not attempt to send to ourselves, or the source */ |
| 792 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
| 795 |
|
if (target_p->from->localClient->serial == current_serial) |
| 796 |
|
continue; |
| 797 |
|
|
| 798 |
< |
if (match(mask, target_p->name)) |
| 798 |
> |
if (!match(mask, target_p->name)) |
| 799 |
|
{ |
| 800 |
|
/* |
| 801 |
|
* if we set the serial here, then we'll never do a |
| 802 |
|
* match() again, if !IsCapable() |
| 803 |
|
*/ |
| 804 |
|
target_p->from->localClient->serial = current_serial; |
| 830 |
– |
found++; |
| 805 |
|
|
| 806 |
|
if (!IsCapable(target_p->from, cap)) |
| 807 |
|
continue; |
| 808 |
|
|
| 809 |
< |
sendto_anywhere(target_p, source_p, "%s", buffer); |
| 809 |
> |
send_message_remote(target_p->from, source_p, buff_suid); |
| 810 |
|
} |
| 811 |
|
} |
| 812 |
+ |
|
| 813 |
+ |
dbuf_ref_free(buff_suid); |
| 814 |
|
} |
| 815 |
|
|
| 816 |
|
/* sendto_anywhere() |
| 824 |
|
*/ |
| 825 |
|
void |
| 826 |
|
sendto_anywhere(struct Client *to, struct Client *from, |
| 827 |
+ |
const char *command, |
| 828 |
|
const char *pattern, ...) |
| 829 |
|
{ |
| 830 |
|
va_list args; |
| 831 |
< |
char buffer[IRCD_BUFSIZE]; |
| 855 |
< |
int len; |
| 856 |
< |
struct Client *send_to = (to->from != NULL ? to->from : to); |
| 831 |
> |
struct dbuf_block *buffer = NULL; |
| 832 |
|
|
| 833 |
< |
if (IsDead(send_to)) |
| 833 |
> |
if (IsDead(to->from)) |
| 834 |
|
return; |
| 835 |
|
|
| 836 |
< |
if (MyClient(to)) |
| 837 |
< |
{ |
| 838 |
< |
if (IsServer(from)) |
| 839 |
< |
{ |
| 840 |
< |
if (IsCapable(to, CAP_TS6) && HasID(from)) |
| 841 |
< |
len = ircsprintf(buffer, ":%s ", from->id); |
| 842 |
< |
else |
| 843 |
< |
len = ircsprintf(buffer, ":%s ", from->name); |
| 869 |
< |
} |
| 870 |
< |
else |
| 871 |
< |
len = ircsprintf(buffer, ":%s!%s@%s ", |
| 872 |
< |
from->name, from->username, from->host); |
| 873 |
< |
} |
| 874 |
< |
else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
| 836 |
> |
buffer = dbuf_alloc(); |
| 837 |
> |
|
| 838 |
> |
if (MyClient(to) && IsClient(from)) |
| 839 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, |
| 840 |
> |
from->host, command, to->name); |
| 841 |
> |
else |
| 842 |
> |
dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), |
| 843 |
> |
command, ID_or_name(to, to)); |
| 844 |
|
|
| 845 |
|
va_start(args, pattern); |
| 846 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
| 846 |
> |
send_format(buffer, pattern, args); |
| 847 |
|
va_end(args); |
| 848 |
|
|
| 849 |
< |
if(MyClient(to)) |
| 850 |
< |
send_message(send_to, buffer, len); |
| 849 |
> |
if (MyClient(to)) |
| 850 |
> |
send_message(to, buffer); |
| 851 |
|
else |
| 852 |
< |
send_message_remote(send_to, from, buffer, len); |
| 852 |
> |
send_message_remote(to, from, buffer); |
| 853 |
> |
|
| 854 |
> |
dbuf_ref_free(buffer); |
| 855 |
|
} |
| 856 |
|
|
| 857 |
|
/* sendto_realops_flags() |
| 863 |
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
| 864 |
|
*/ |
| 865 |
|
void |
| 866 |
< |
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
| 866 |
> |
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
| 867 |
|
{ |
| 868 |
+ |
const char *ntype = NULL; |
| 869 |
|
dlink_node *ptr = NULL; |
| 870 |
< |
char nbuf[IRCD_BUFSIZE]; |
| 870 |
> |
char nbuf[IRCD_BUFSIZE] = ""; |
| 871 |
|
va_list args; |
| 872 |
|
|
| 873 |
|
va_start(args, pattern); |
| 874 |
< |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
| 874 |
> |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
| 875 |
|
va_end(args); |
| 876 |
|
|
| 877 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
| 877 |
> |
switch (type) |
| 878 |
|
{ |
| 879 |
< |
struct Client *client_p = ptr->data; |
| 880 |
< |
assert(HasUMode(client_p, UMODE_OPER)); |
| 881 |
< |
|
| 882 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
| 883 |
< |
* If we're sending it to admins, and theyre not, skip. |
| 884 |
< |
*/ |
| 885 |
< |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
| 886 |
< |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
| 887 |
< |
continue; |
| 888 |
< |
|
| 889 |
< |
if (HasUMode(client_p, flags)) |
| 918 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
| 919 |
< |
me.name, client_p->name, nbuf); |
| 879 |
> |
case SEND_NOTICE: |
| 880 |
> |
ntype = "Notice"; |
| 881 |
> |
break; |
| 882 |
> |
case SEND_GLOBAL: |
| 883 |
> |
ntype = "Global"; |
| 884 |
> |
break; |
| 885 |
> |
case SEND_LOCOPS: |
| 886 |
> |
ntype = "LocOps"; |
| 887 |
> |
break; |
| 888 |
> |
default: |
| 889 |
> |
assert(0); |
| 890 |
|
} |
| 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); |
| 891 |
|
|
| 892 |
|
DLINK_FOREACH(ptr, oper_list.head) |
| 893 |
|
{ |
| 894 |
|
struct Client *client_p = ptr->data; |
| 895 |
< |
assert(client_p->umodes & UMODE_OPER); |
| 895 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
| 896 |
|
|
| 897 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
| 898 |
< |
* If we're sending it to admins, and theyre not, skip. |
| 897 |
> |
/* |
| 898 |
> |
* If we're sending it to opers and they're an admin, skip. |
| 899 |
> |
* If we're sending it to admins, and they're not, skip. |
| 900 |
|
*/ |
| 901 |
|
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
| 902 |
|
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
| 903 |
|
continue; |
| 904 |
|
|
| 905 |
|
if (HasUMode(client_p, flags)) |
| 906 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Global -- %s", |
| 907 |
< |
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 |
| 955 |
< |
* - client sending request |
| 956 |
< |
* - var args input message |
| 957 |
< |
* output - NONE |
| 958 |
< |
* side effects - Send a wallops to local opers |
| 959 |
< |
*/ |
| 960 |
< |
void |
| 961 |
< |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 962 |
< |
const char *pattern, ...) |
| 963 |
< |
{ |
| 964 |
< |
dlink_node *ptr = NULL; |
| 965 |
< |
va_list args; |
| 966 |
< |
char buffer[IRCD_BUFSIZE]; |
| 967 |
< |
int len; |
| 968 |
< |
|
| 969 |
< |
if (IsClient(source_p)) |
| 970 |
< |
len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :", |
| 971 |
< |
source_p->name, source_p->username, source_p->host); |
| 972 |
< |
else |
| 973 |
< |
len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name); |
| 974 |
< |
|
| 975 |
< |
va_start(args, pattern); |
| 976 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
| 977 |
< |
va_end(args); |
| 978 |
< |
|
| 979 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
| 980 |
< |
{ |
| 981 |
< |
struct Client *client_p = ptr->data; |
| 982 |
< |
assert(client_p->umodes & UMODE_OPER); |
| 983 |
< |
|
| 984 |
< |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
| 985 |
< |
send_message(client_p, buffer, len); |
| 906 |
> |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
| 907 |
> |
me.name, client_p->name, ntype, nbuf); |
| 908 |
|
} |
| 909 |
|
} |
| 910 |
|
|
| 911 |
|
/* ts_warn() |
| 912 |
|
* |
| 913 |
< |
* inputs - var args message |
| 914 |
< |
* output - NONE |
| 915 |
< |
* side effects - Call sendto_realops_flags, with some flood checking |
| 916 |
< |
* (at most 5 warnings every 5 seconds) |
| 913 |
> |
* inputs - var args message |
| 914 |
> |
* output - NONE |
| 915 |
> |
* side effects - Call sendto_realops_flags, with some flood checking |
| 916 |
> |
* (at most 5 warnings every 5 seconds) |
| 917 |
|
*/ |
| 918 |
|
void |
| 919 |
< |
ts_warn(const char *pattern, ...) |
| 919 |
> |
sendto_realops_flags_ratelimited(const char *pattern, ...) |
| 920 |
|
{ |
| 921 |
|
va_list args; |
| 922 |
< |
char buffer[IRCD_BUFSIZE]; |
| 922 |
> |
char buffer[IRCD_BUFSIZE] = ""; |
| 923 |
|
static time_t last = 0; |
| 924 |
|
static int warnings = 0; |
| 925 |
|
|
| 1004 |
– |
/* |
| 1005 |
– |
** if we're running with TS_WARNINGS enabled and someone does |
| 1006 |
– |
** something silly like (remotely) connecting a nonTS server, |
| 1007 |
– |
** we'll get a ton of warnings, so we make sure we don't send |
| 1008 |
– |
** more than 5 every 5 seconds. -orabidoo |
| 1009 |
– |
*/ |
| 1010 |
– |
|
| 926 |
|
if (CurrentTime - last < 5) |
| 927 |
|
{ |
| 928 |
|
if (++warnings > 5) |
| 938 |
|
vsnprintf(buffer, sizeof(buffer), pattern, args); |
| 939 |
|
va_end(args); |
| 940 |
|
|
| 941 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
| 941 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
| 942 |
|
ilog(LOG_TYPE_IRCD, "%s", buffer); |
| 943 |
|
} |
| 944 |
|
|
| 945 |
< |
/* kill_client() |
| 945 |
> |
/* sendto_wallops_flags() |
| 946 |
|
* |
| 947 |
< |
* inputs - client to send kill towards |
| 948 |
< |
* - pointer to client to kill |
| 949 |
< |
* - reason for kill |
| 950 |
< |
* output - NONE |
| 951 |
< |
* side effects - NONE |
| 947 |
> |
* inputs - flag types of messages to show to real opers |
| 948 |
> |
* - client sending request |
| 949 |
> |
* - var args input message |
| 950 |
> |
* output - NONE |
| 951 |
> |
* side effects - Send a wallops to local opers |
| 952 |
|
*/ |
| 953 |
|
void |
| 954 |
< |
kill_client(struct Client *client_p, struct Client *diedie, |
| 955 |
< |
const char *pattern, ...) |
| 954 |
> |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
| 955 |
> |
const char *pattern, ...) |
| 956 |
|
{ |
| 957 |
+ |
dlink_node *ptr = NULL; |
| 958 |
|
va_list args; |
| 959 |
< |
char buffer[IRCD_BUFSIZE]; |
| 1044 |
< |
int len; |
| 1045 |
< |
|
| 1046 |
< |
if (client_p->from != NULL) |
| 1047 |
< |
client_p = client_p->from; |
| 1048 |
< |
if (IsDead(client_p)) |
| 1049 |
< |
return; |
| 1050 |
< |
|
| 1051 |
< |
len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
| 1052 |
< |
ID_or_name(diedie, client_p)); |
| 1053 |
< |
|
| 1054 |
< |
va_start(args, pattern); |
| 1055 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
| 1056 |
< |
va_end(args); |
| 959 |
> |
struct dbuf_block *buffer; |
| 960 |
|
|
| 961 |
< |
send_message(client_p, buffer, len); |
| 1059 |
< |
} |
| 1060 |
< |
|
| 1061 |
< |
/* kill_client_ll_serv_butone() |
| 1062 |
< |
* |
| 1063 |
< |
* inputs - pointer to client to not send to |
| 1064 |
< |
* - pointer to client to kill |
| 1065 |
< |
* output - NONE |
| 1066 |
< |
* side effects - Send a KILL for the given client |
| 1067 |
< |
* message to all connected servers |
| 1068 |
< |
* except the client 'one'. Also deal with |
| 1069 |
< |
* client being unknown to leaf, as in lazylink... |
| 1070 |
< |
*/ |
| 1071 |
< |
void |
| 1072 |
< |
kill_client_ll_serv_butone(struct Client *one, struct Client *source_p, |
| 1073 |
< |
const char *pattern, ...) |
| 1074 |
< |
{ |
| 1075 |
< |
va_list args; |
| 1076 |
< |
int have_uid = 0; |
| 1077 |
< |
dlink_node *ptr = NULL; |
| 1078 |
< |
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
| 1079 |
< |
int len_uid = 0, len_nick = 0; |
| 961 |
> |
buffer = dbuf_alloc(); |
| 962 |
|
|
| 963 |
< |
if (HasID(source_p)) |
| 964 |
< |
{ |
| 965 |
< |
have_uid = 1; |
| 966 |
< |
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 |
< |
} |
| 963 |
> |
if (IsClient(source_p)) |
| 964 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
| 965 |
> |
else |
| 966 |
> |
dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name); |
| 967 |
|
|
| 968 |
|
va_start(args, pattern); |
| 969 |
< |
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); |
| 969 |
> |
send_format(buffer, pattern, args); |
| 970 |
|
va_end(args); |
| 971 |
|
|
| 972 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
| 972 |
> |
DLINK_FOREACH(ptr, oper_list.head) |
| 973 |
|
{ |
| 974 |
|
struct Client *client_p = ptr->data; |
| 975 |
+ |
assert(client_p->umodes & UMODE_OPER); |
| 976 |
|
|
| 977 |
< |
if (one != NULL && (client_p == one->from)) |
| 978 |
< |
continue; |
| 1103 |
< |
if (IsDefunct(client_p)) |
| 1104 |
< |
continue; |
| 1105 |
< |
|
| 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); |
| 977 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
| 978 |
> |
send_message(client_p, buffer); |
| 979 |
|
} |
| 980 |
< |
} |
| 980 |
> |
|
| 981 |
> |
dbuf_ref_free(buffer); |
| 982 |
> |
} |