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: send.c,v 7.307 2005/10/02 12:45:07 adx Exp $ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file send.c |
23 |
> |
* \brief Functions for sending messages. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
< |
#include "tools.h" |
28 |
> |
#include "list.h" |
29 |
|
#include "send.h" |
30 |
|
#include "channel.h" |
31 |
|
#include "client.h" |
30 |
– |
#include "common.h" |
32 |
|
#include "dbuf.h" |
33 |
|
#include "irc_string.h" |
34 |
|
#include "ircd.h" |
34 |
– |
#include "handlers.h" |
35 |
|
#include "numeric.h" |
36 |
|
#include "fdlist.h" |
37 |
|
#include "s_bsd.h" |
38 |
|
#include "s_serv.h" |
39 |
< |
#include "sprintf_irc.h" |
40 |
< |
#include "s_conf.h" |
41 |
< |
#include "list.h" |
42 |
< |
#include "s_log.h" |
39 |
> |
#include "conf.h" |
40 |
> |
#include "log.h" |
41 |
|
#include "memory.h" |
44 |
– |
#include "hook.h" |
45 |
– |
#include "irc_getnameinfo.h" |
42 |
|
#include "packet.h" |
43 |
|
|
48 |
– |
#define LOG_BUFSIZE 2048 |
49 |
– |
|
50 |
– |
struct Callback *iosend_cb = NULL; |
51 |
– |
struct Callback *iosendctrl_cb = NULL; |
44 |
|
|
45 |
< |
static void send_message(struct Client *, char *, int); |
54 |
< |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
45 |
> |
static unsigned int current_serial = 0; |
46 |
|
|
56 |
– |
static unsigned long current_serial = 0L; |
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 |
|
{ |
70 |
– |
int len; |
71 |
– |
|
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); |
73 |
< |
if (len > bufsize - 2) |
74 |
< |
len = bufsize - 2; /* required by some versions of vsnprintf */ |
75 |
< |
|
76 |
< |
lsendbuf[len++] = '\r'; |
77 |
< |
lsendbuf[len++] = '\n'; |
78 |
< |
return (len); |
72 |
> |
dbuf_put_args(buffer, pattern, args); |
73 |
> |
|
74 |
> |
if (buffer->size > sizeof(buffer->data) - 2) |
75 |
> |
buffer->size = sizeof(buffer->data) - 2; |
76 |
> |
|
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 |
< |
#ifdef INVARIANTS |
90 |
< |
if (IsMe(to)) |
103 |
< |
{ |
104 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
105 |
< |
"Trying to send message to myself!"); |
106 |
< |
return; |
107 |
< |
} |
108 |
< |
#endif |
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 |
|
dead_link_on_write(to, 0); |
103 |
|
return; |
104 |
|
} |
105 |
|
|
106 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, len); |
106 |
> |
dbuf_add(&to->localClient->buf_sendq, buf); |
107 |
|
|
108 |
|
/* |
109 |
|
** Update statistics. The following is slightly incorrect |
113 |
|
++to->localClient->send.messages; |
114 |
|
++me.localClient->send.messages; |
115 |
|
|
116 |
< |
if (dbuf_length(&to->localClient->buf_sendq) > |
135 |
< |
(IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096)) |
136 |
< |
send_queued_write(to); |
116 |
> |
send_queued_write(to); |
117 |
|
} |
118 |
|
|
119 |
|
/* send_message_remote() |
120 |
|
* |
121 |
|
* inputs - pointer to client from message is being sent |
122 |
|
* - pointer to client to send to |
123 |
< |
* - pointer to preformatted buffer |
144 |
< |
* - length of input buffer |
123 |
> |
* - pointer to buffer |
124 |
|
* output - none |
125 |
|
* side effects - Despite the function name, this only sends to directly |
126 |
|
* connected clients. |
127 |
< |
* |
127 |
> |
* |
128 |
|
*/ |
129 |
|
static void |
130 |
< |
send_message_remote(struct Client *to, struct Client *from, |
152 |
< |
char *buf, int len) |
130 |
> |
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
131 |
|
{ |
132 |
+ |
to = to->from; |
133 |
+ |
|
134 |
|
if (!MyConnect(to)) |
135 |
|
{ |
136 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
137 |
< |
"server send message to %s [%s] dropped from %s(Not local server)", |
138 |
< |
to->name, to->from->name, from->name); |
136 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
137 |
> |
"Server send message to %s [%s] dropped from %s(Not local server)", |
138 |
> |
to->name, to->from->name, from->name); |
139 |
|
return; |
140 |
|
} |
141 |
|
|
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 |
– |
|
142 |
|
/* Optimize by checking if (from && to) before everything */ |
143 |
|
/* we set to->from up there.. */ |
144 |
|
|
146 |
|
{ |
147 |
|
if (IsServer(from)) |
148 |
|
{ |
149 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
149 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
150 |
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
151 |
|
to->name, to->from->name, from->name); |
152 |
|
return; |
153 |
|
} |
154 |
|
|
155 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
155 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
156 |
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
157 |
|
to->name, to->username, to->host, |
158 |
|
from->name, from->username, from->host, |
159 |
|
to->from->name); |
160 |
|
|
161 |
< |
sendto_server(NULL, to, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
161 |
> |
sendto_server(NULL, NOCAPS, NOCAPS, |
162 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
163 |
|
me.id, to->name, me.name, to->name, |
164 |
|
to->username, to->host, to->from->name); |
192 |
– |
sendto_server(NULL, to, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
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); |
165 |
|
|
166 |
< |
SetKilled(to); |
166 |
> |
AddFlag(to, FLAGS_KILLED); |
167 |
|
|
168 |
|
if (IsClient(from)) |
169 |
< |
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
170 |
< |
me.name, from->name, to->name, to->username, |
202 |
< |
to->host, to->from); |
203 |
< |
|
204 |
< |
exit_client(to, &me, "Ghosted client"); |
169 |
> |
sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name, |
170 |
> |
to->username, to->host, to->from); |
171 |
|
|
172 |
+ |
exit_client(to, "Ghosted client"); |
173 |
|
return; |
174 |
< |
} |
174 |
> |
} |
175 |
|
|
176 |
< |
send_message(to, buf, len); |
176 |
> |
send_message(to, buf); |
177 |
|
} |
178 |
|
|
179 |
|
/* |
183 |
|
void |
184 |
|
sendq_unblocked(fde_t *fd, struct Client *client_p) |
185 |
|
{ |
186 |
< |
ClearSendqBlocked(client_p); |
187 |
< |
/* let send_queued_write be executed by send_queued_all */ |
221 |
< |
|
222 |
< |
#ifdef HAVE_LIBCRYPTO |
223 |
< |
if (fd->flags.pending_read) |
224 |
< |
{ |
225 |
< |
fd->flags.pending_read = 0; |
226 |
< |
read_packet(fd, client_p); |
227 |
< |
} |
228 |
< |
#endif |
229 |
< |
} |
230 |
< |
|
231 |
< |
/* |
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); |
186 |
> |
assert(fd == &client_p->localClient->fd); |
187 |
> |
send_queued_write(client_p); |
188 |
|
} |
189 |
|
|
190 |
|
/* |
196 |
|
void |
197 |
|
send_queued_write(struct Client *to) |
198 |
|
{ |
199 |
< |
int retlen; |
252 |
< |
struct dbuf_block *first; |
199 |
> |
int retlen = 0; |
200 |
|
|
201 |
|
/* |
202 |
|
** Once socket is marked dead, we cannot start writing to it, |
203 |
|
** even if the error is removed... |
204 |
|
*/ |
205 |
< |
if (IsDead(to) || IsSendqBlocked(to)) |
205 |
> |
if (IsDead(to)) |
206 |
|
return; /* no use calling send() now */ |
207 |
|
|
208 |
|
/* Next, lets try to write some data */ |
262 |
– |
|
209 |
|
if (dbuf_length(&to->localClient->buf_sendq)) |
210 |
|
{ |
211 |
< |
do { |
212 |
< |
first = to->localClient->buf_sendq.blocks.head->data; |
211 |
> |
do |
212 |
> |
{ |
213 |
> |
struct dbuf_block *first = to->localClient->buf_sendq.blocks.head->data; |
214 |
|
|
215 |
|
#ifdef HAVE_LIBCRYPTO |
216 |
|
if (to->localClient->fd.ssl) |
217 |
|
{ |
218 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size); |
218 |
> |
retlen = SSL_write(to->localClient->fd.ssl, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos); |
219 |
|
|
220 |
|
/* translate openssl error codes, sigh */ |
221 |
< |
if (retlen < 0) |
222 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
223 |
< |
{ |
221 |
> |
if (retlen < 0) |
222 |
> |
{ |
223 |
> |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
224 |
> |
{ |
225 |
|
case SSL_ERROR_WANT_READ: |
226 |
< |
return; /* retry later, don't register for write events */ |
227 |
< |
|
228 |
< |
case SSL_ERROR_WANT_WRITE: |
281 |
< |
errno = EWOULDBLOCK; |
226 |
> |
return; /* retry later, don't register for write events */ |
227 |
> |
case SSL_ERROR_WANT_WRITE: |
228 |
> |
errno = EWOULDBLOCK; |
229 |
|
case SSL_ERROR_SYSCALL: |
230 |
< |
break; |
231 |
< |
|
230 |
> |
break; |
231 |
> |
case SSL_ERROR_SSL: |
232 |
> |
if (errno == EAGAIN) |
233 |
> |
break; |
234 |
|
default: |
235 |
< |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
236 |
< |
} |
235 |
> |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
236 |
> |
} |
237 |
> |
} |
238 |
|
} |
239 |
|
else |
240 |
|
#endif |
241 |
< |
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
241 |
> |
retlen = send(to->localClient->fd.fd, first->data + to->localClient->buf_sendq.pos, first->size - to->localClient->buf_sendq.pos, 0); |
242 |
|
|
243 |
|
if (retlen <= 0) |
294 |
– |
{ |
295 |
– |
#ifdef _WIN32 |
296 |
– |
errno = WSAGetLastError(); |
297 |
– |
#endif |
244 |
|
break; |
299 |
– |
} |
245 |
|
|
301 |
– |
execute_callback(iosend_cb, to, retlen, first->data); |
246 |
|
dbuf_delete(&to->localClient->buf_sendq, retlen); |
247 |
|
|
248 |
|
/* We have some data written .. update counters */ |
253 |
|
if ((retlen < 0) && (ignoreErrno(errno))) |
254 |
|
{ |
255 |
|
/* we have a non-fatal error, reschedule a write */ |
312 |
– |
SetSendqBlocked(to); |
256 |
|
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
257 |
< |
(PF *)sendq_unblocked, (void *)to, 0); |
257 |
> |
(PF *)sendq_unblocked, to, 0); |
258 |
|
} |
259 |
|
else if (retlen <= 0) |
260 |
|
{ |
264 |
|
} |
265 |
|
} |
266 |
|
|
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 |
– |
|
267 |
|
/* send_queued_all() |
268 |
|
* |
269 |
|
* input - NONE |
279 |
|
* a notice to opers, which is to be delivered by this function. |
280 |
|
*/ |
281 |
|
DLINK_FOREACH(ptr, serv_list.head) |
282 |
< |
send_queued_write((struct Client *) ptr->data); |
282 |
> |
send_queued_write(ptr->data); |
283 |
|
|
284 |
|
DLINK_FOREACH(ptr, unknown_list.head) |
285 |
< |
send_queued_write((struct Client *) ptr->data); |
285 |
> |
send_queued_write(ptr->data); |
286 |
|
|
287 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
288 |
< |
send_queued_write((struct Client *) ptr->data); |
288 |
> |
send_queued_write(ptr->data); |
289 |
|
|
290 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
291 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
306 |
|
sendto_one(struct Client *to, const char *pattern, ...) |
307 |
|
{ |
308 |
|
va_list args; |
309 |
< |
char buffer[IRCD_BUFSIZE]; |
310 |
< |
int len; |
309 |
> |
struct dbuf_block *buffer; |
310 |
> |
|
311 |
> |
to = to->from; |
312 |
> |
|
313 |
> |
if (IsDead(to)) |
314 |
> |
return; /* This socket has already been marked as dead */ |
315 |
> |
|
316 |
> |
buffer = dbuf_alloc(); |
317 |
> |
|
318 |
> |
va_start(args, pattern); |
319 |
> |
send_format(buffer, pattern, args); |
320 |
> |
va_end(args); |
321 |
> |
|
322 |
> |
send_message(to, buffer); |
323 |
> |
|
324 |
> |
dbuf_ref_free(buffer); |
325 |
> |
} |
326 |
> |
|
327 |
> |
void |
328 |
> |
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
329 |
> |
{ |
330 |
> |
struct dbuf_block *buffer; |
331 |
> |
va_list args; |
332 |
> |
const char *dest; |
333 |
> |
|
334 |
> |
to = to->from; |
335 |
> |
|
336 |
> |
if (IsDead(to)) |
337 |
> |
return; |
338 |
> |
|
339 |
> |
dest = ID_or_name(to, to); |
340 |
> |
if (EmptyString(dest)) |
341 |
> |
dest = "*"; |
342 |
> |
|
343 |
> |
buffer = dbuf_alloc(); |
344 |
> |
|
345 |
> |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest); |
346 |
> |
|
347 |
> |
va_start(args, numeric); |
348 |
> |
send_format(buffer, numeric_form(numeric), args); |
349 |
> |
va_end(args); |
350 |
> |
|
351 |
> |
send_message(to, buffer); |
352 |
> |
|
353 |
> |
dbuf_ref_free(buffer); |
354 |
> |
} |
355 |
> |
|
356 |
> |
void |
357 |
> |
sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...) |
358 |
> |
{ |
359 |
> |
struct dbuf_block *buffer; |
360 |
> |
va_list args; |
361 |
> |
const char *dest; |
362 |
> |
|
363 |
> |
to = to->from; |
364 |
|
|
435 |
– |
if (to->from != NULL) |
436 |
– |
to = to->from; |
365 |
|
if (IsDead(to)) |
366 |
< |
return; /* This socket has already been marked as dead */ |
366 |
> |
return; |
367 |
> |
|
368 |
> |
dest = ID_or_name(to, to); |
369 |
> |
if (EmptyString(dest)) |
370 |
> |
dest = "*"; |
371 |
> |
|
372 |
> |
buffer = dbuf_alloc(); |
373 |
> |
|
374 |
> |
dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest); |
375 |
|
|
376 |
|
va_start(args, pattern); |
377 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
377 |
> |
send_format(buffer, pattern, args); |
378 |
|
va_end(args); |
379 |
|
|
380 |
< |
send_message(to, buffer, len); |
380 |
> |
send_message(to, buffer); |
381 |
> |
|
382 |
> |
dbuf_ref_free(buffer); |
383 |
|
} |
384 |
|
|
385 |
|
/* sendto_channel_butone() |
395 |
|
*/ |
396 |
|
void |
397 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
398 |
< |
struct Channel *chptr, const char *command, |
398 |
> |
struct Channel *chptr, unsigned int type, |
399 |
|
const char *pattern, ...) |
400 |
|
{ |
401 |
< |
va_list args; |
402 |
< |
char local_buf[IRCD_BUFSIZE]; |
403 |
< |
char remote_buf[IRCD_BUFSIZE]; |
404 |
< |
char uid_buf[IRCD_BUFSIZE]; |
405 |
< |
int local_len, remote_len, uid_len; |
468 |
< |
dlink_node *ptr; |
469 |
< |
dlink_node *ptr_next; |
470 |
< |
struct Client *target_p; |
401 |
> |
va_list alocal, aremote; |
402 |
> |
struct dbuf_block *local_buf, *remote_buf; |
403 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
404 |
> |
|
405 |
> |
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
406 |
|
|
407 |
|
if (IsServer(from)) |
408 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
474 |
< |
from->name, command, chptr->chname); |
408 |
> |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
409 |
|
else |
410 |
< |
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
477 |
< |
from->name, from->username, from->host, |
478 |
< |
command, chptr->chname); |
479 |
< |
remote_len = ircsprintf(remote_buf, ":%s %s %s ", |
480 |
< |
from->name, command, chptr->chname); |
481 |
< |
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
482 |
< |
ID(from), command, chptr->chname); |
410 |
> |
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
411 |
|
|
412 |
< |
va_start(args, pattern); |
413 |
< |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
414 |
< |
pattern, args); |
415 |
< |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
416 |
< |
pattern, args); |
417 |
< |
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
418 |
< |
args); |
419 |
< |
va_end(args); |
412 |
> |
dbuf_put_fmt(remote_buf, ":%s ", ID(from)); |
413 |
> |
|
414 |
> |
va_start(alocal, pattern); |
415 |
> |
va_start(aremote, pattern); |
416 |
> |
send_format(local_buf, pattern, alocal); |
417 |
> |
send_format(remote_buf, pattern, aremote); |
418 |
> |
|
419 |
> |
va_end(aremote); |
420 |
> |
va_end(alocal); |
421 |
|
|
422 |
|
++current_serial; |
423 |
|
|
424 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
425 |
|
{ |
426 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
427 |
< |
assert(target_p != NULL); |
426 |
> |
struct Membership *ms = ptr->data; |
427 |
> |
struct Client *target_p = ms->client_p; |
428 |
|
|
429 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
429 |
> |
assert(IsClient(target_p)); |
430 |
> |
|
431 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || |
432 |
> |
(one && target_p->from == one->from)) |
433 |
|
continue; |
434 |
|
|
435 |
< |
if (MyClient(target_p)) |
436 |
< |
{ |
437 |
< |
if (target_p->serial != current_serial) |
438 |
< |
{ |
439 |
< |
send_message(target_p, local_buf, local_len); |
440 |
< |
target_p->serial = current_serial; |
441 |
< |
} |
442 |
< |
} |
511 |
< |
else |
512 |
< |
{ |
513 |
< |
/* Now check whether a message has been sent to this |
514 |
< |
* remote link already |
515 |
< |
*/ |
516 |
< |
if (target_p->from->serial != current_serial) |
517 |
< |
{ |
518 |
< |
if (IsCapable(target_p->from, CAP_TS6)) |
519 |
< |
send_message_remote(target_p->from, from, uid_buf, uid_len); |
520 |
< |
else |
521 |
< |
send_message_remote(target_p->from, from, remote_buf, remote_len); |
522 |
< |
target_p->from->serial = current_serial; |
523 |
< |
} |
524 |
< |
} |
435 |
> |
if (type != 0 && (ms->flags & type) == 0) |
436 |
> |
continue; |
437 |
> |
|
438 |
> |
if (MyConnect(target_p)) |
439 |
> |
send_message(target_p, local_buf); |
440 |
> |
else if (target_p->from->localClient->serial != current_serial) |
441 |
> |
send_message_remote(target_p->from, from, remote_buf); |
442 |
> |
target_p->from->localClient->serial = current_serial; |
443 |
|
} |
444 |
+ |
|
445 |
+ |
dbuf_ref_free(local_buf); |
446 |
+ |
dbuf_ref_free(remote_buf); |
447 |
|
} |
448 |
|
|
449 |
|
/* sendto_server() |
450 |
< |
* |
450 |
> |
* |
451 |
|
* inputs - pointer to client to NOT send to |
452 |
< |
* - pointer to source client required by LL (if any) |
532 |
< |
* - pointer to channel required by LL (if any) |
452 |
> |
* - pointer to channel |
453 |
|
* - caps or'd together which must ALL be present |
454 |
|
* - caps or'd together which must ALL NOT be present |
535 |
– |
* - LL flags: LL_ICLIENT | LL_ICHAN |
455 |
|
* - printf style format string |
456 |
|
* - args to format string |
457 |
|
* output - NONE |
458 |
|
* side effects - Send a message to all connected servers, except the |
459 |
|
* client 'one' (if non-NULL), as long as the servers |
460 |
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
461 |
< |
* 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. |
549 |
< |
* |
461 |
> |
* |
462 |
|
* This function was written in an attempt to merge together the other |
463 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
464 |
|
* lazylinks, uids, etc. |
465 |
|
* -davidt |
466 |
|
*/ |
467 |
< |
void |
468 |
< |
sendto_server(struct Client *one, struct Client *source_p, |
469 |
< |
struct Channel *chptr, unsigned long caps, |
470 |
< |
unsigned long nocaps, unsigned long llflags, |
467 |
> |
void |
468 |
> |
sendto_server(struct Client *one, |
469 |
> |
const unsigned int caps, |
470 |
> |
const unsigned int nocaps, |
471 |
|
const char *format, ...) |
472 |
|
{ |
473 |
|
va_list args; |
474 |
< |
struct Client *client_p; |
475 |
< |
dlink_node *ptr; |
564 |
< |
char buffer[IRCD_BUFSIZE]; |
565 |
< |
int len; |
474 |
> |
dlink_node *ptr = NULL; |
475 |
> |
struct dbuf_block *buffer; |
476 |
|
|
477 |
< |
if (chptr != NULL) |
568 |
< |
{ |
569 |
< |
if (chptr->chname[0] != '#') |
570 |
< |
return; |
571 |
< |
} |
477 |
> |
buffer = dbuf_alloc(); |
478 |
|
|
479 |
|
va_start(args, format); |
480 |
< |
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
480 |
> |
send_format(buffer, format, args); |
481 |
|
va_end(args); |
482 |
|
|
483 |
|
DLINK_FOREACH(ptr, serv_list.head) |
484 |
|
{ |
485 |
< |
client_p = ptr->data; |
485 |
> |
struct Client *client_p = ptr->data; |
486 |
|
|
487 |
|
/* If dead already skip */ |
488 |
|
if (IsDead(client_p)) |
497 |
|
if ((client_p->localClient->caps & nocaps) != 0) |
498 |
|
continue; |
499 |
|
|
500 |
< |
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 |
< |
} |
623 |
< |
send_message(client_p, buffer, len); |
500 |
> |
send_message(client_p, buffer); |
501 |
|
} |
502 |
+ |
|
503 |
+ |
dbuf_ref_free(buffer); |
504 |
|
} |
505 |
|
|
506 |
|
/* sendto_common_channels_local() |
509 |
|
* - pattern to send |
510 |
|
* output - NONE |
511 |
|
* side effects - Sends a message to all people on local server who are |
512 |
< |
* in same channel with user. |
512 |
> |
* in same channel with user. |
513 |
|
* used by m_nick.c and exit_one_client. |
514 |
|
*/ |
515 |
|
void |
516 |
< |
sendto_common_channels_local(struct Client *user, int touser, |
516 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
517 |
|
const char *pattern, ...) |
518 |
|
{ |
519 |
|
va_list args; |
522 |
|
struct Channel *chptr; |
523 |
|
struct Membership *ms; |
524 |
|
struct Client *target_p; |
525 |
< |
char buffer[IRCD_BUFSIZE]; |
526 |
< |
int len; |
525 |
> |
struct dbuf_block *buffer; |
526 |
> |
|
527 |
> |
buffer = dbuf_alloc(); |
528 |
|
|
529 |
|
va_start(args, pattern); |
530 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
530 |
> |
send_format(buffer, pattern, args); |
531 |
|
va_end(args); |
532 |
|
|
533 |
|
++current_serial; |
534 |
|
|
535 |
|
DLINK_FOREACH(cptr, user->channel.head) |
536 |
|
{ |
537 |
< |
chptr = ((struct Membership *) cptr->data)->chptr; |
537 |
> |
chptr = ((struct Membership *)cptr->data)->chptr; |
538 |
|
assert(chptr != NULL); |
539 |
|
|
540 |
< |
DLINK_FOREACH(uptr, chptr->locmembers.head) |
540 |
> |
DLINK_FOREACH(uptr, chptr->members.head) |
541 |
|
{ |
542 |
|
ms = uptr->data; |
543 |
|
target_p = ms->client_p; |
544 |
|
assert(target_p != NULL); |
545 |
|
|
546 |
< |
if (target_p == user || IsDefunct(target_p) || |
547 |
< |
target_p->serial == current_serial) |
546 |
> |
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
547 |
> |
target_p->localClient->serial == current_serial) |
548 |
> |
continue; |
549 |
> |
|
550 |
> |
if (HasCap(target_p, cap) != cap) |
551 |
|
continue; |
552 |
|
|
553 |
< |
target_p->serial = current_serial; |
554 |
< |
send_message(target_p, buffer, len); |
553 |
> |
target_p->localClient->serial = current_serial; |
554 |
> |
send_message(target_p, buffer); |
555 |
|
} |
556 |
|
} |
557 |
|
|
558 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
559 |
< |
user->serial != current_serial) |
560 |
< |
send_message(user, buffer, len); |
559 |
> |
user->localClient->serial != current_serial) |
560 |
> |
if (HasCap(user, cap) == cap) |
561 |
> |
send_message(user, buffer); |
562 |
> |
|
563 |
> |
dbuf_ref_free(buffer); |
564 |
|
} |
565 |
|
|
566 |
|
/* sendto_channel_local() |
574 |
|
* locally connected to this server. |
575 |
|
*/ |
576 |
|
void |
577 |
< |
sendto_channel_local(int type, int nodeaf, struct Channel *chptr, |
577 |
> |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
578 |
|
const char *pattern, ...) |
579 |
|
{ |
580 |
|
va_list args; |
581 |
< |
char buffer[IRCD_BUFSIZE]; |
582 |
< |
int len; |
583 |
< |
dlink_node *ptr; |
584 |
< |
struct Membership *ms; |
699 |
< |
struct Client *target_p; |
581 |
> |
dlink_node *ptr = NULL; |
582 |
> |
struct dbuf_block *buffer; |
583 |
> |
|
584 |
> |
buffer = dbuf_alloc(); |
585 |
|
|
586 |
|
va_start(args, pattern); |
587 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
587 |
> |
send_format(buffer, pattern, args); |
588 |
|
va_end(args); |
589 |
|
|
590 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
590 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
591 |
|
{ |
592 |
< |
ms = ptr->data; |
593 |
< |
target_p = ms->client_p; |
592 |
> |
struct Membership *ms = ptr->data; |
593 |
> |
struct Client *target_p = ms->client_p; |
594 |
|
|
595 |
|
if (type != 0 && (ms->flags & type) == 0) |
596 |
|
continue; |
597 |
|
|
598 |
< |
if (IsDefunct(target_p) || (nodeaf && IsDeaf(target_p))) |
598 |
> |
if (!MyConnect(target_p) || IsDefunct(target_p) || |
599 |
> |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
600 |
|
continue; |
601 |
|
|
602 |
< |
send_message(target_p, buffer, len); |
602 |
> |
send_message(target_p, buffer); |
603 |
|
} |
604 |
+ |
|
605 |
+ |
dbuf_ref_free(buffer); |
606 |
|
} |
607 |
|
|
608 |
|
/* sendto_channel_local_butone() |
617 |
|
* |
618 |
|
* WARNING - +D clients are omitted |
619 |
|
*/ |
732 |
– |
void |
733 |
– |
sendto_channel_local_butone(struct Client *one, int type, |
734 |
– |
struct Channel *chptr, const char *pattern, ...) |
735 |
– |
{ |
736 |
– |
va_list args; |
737 |
– |
char buffer[IRCD_BUFSIZE]; |
738 |
– |
int len; |
739 |
– |
struct Client *target_p; |
740 |
– |
struct Membership *ms; |
741 |
– |
dlink_node *ptr; |
742 |
– |
|
743 |
– |
va_start(args, pattern); |
744 |
– |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
745 |
– |
va_end(args); |
746 |
– |
|
747 |
– |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
748 |
– |
{ |
749 |
– |
ms = ptr->data; |
750 |
– |
target_p = ms->client_p; |
751 |
– |
|
752 |
– |
if (type != 0 && (ms->flags & type) == 0) |
753 |
– |
continue; |
754 |
– |
|
755 |
– |
if (target_p == one || IsDefunct(target_p) || IsDeaf(target_p)) |
756 |
– |
continue; |
757 |
– |
send_message(target_p, buffer, len); |
758 |
– |
} |
759 |
– |
} |
760 |
– |
|
761 |
– |
|
762 |
– |
/* sendto_channel_remote() |
763 |
– |
* |
764 |
– |
* inputs - Client not to send towards |
765 |
– |
* - Client from whom message is from |
766 |
– |
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
767 |
– |
* - pointer to channel to send to |
768 |
– |
* - var args pattern |
769 |
– |
* output - NONE |
770 |
– |
* side effects - Send a message to all members of a channel that are |
771 |
– |
* remote to this server. |
772 |
– |
*/ |
620 |
|
void |
621 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps, |
622 |
< |
int nocaps, struct Channel *chptr, const char *pattern, ...) |
621 |
> |
sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap, |
622 |
> |
struct Channel *chptr, const char *pattern, ...) |
623 |
|
{ |
624 |
|
va_list args; |
625 |
< |
char buffer[IRCD_BUFSIZE]; |
626 |
< |
int len; |
627 |
< |
dlink_node *ptr; |
628 |
< |
struct Client *target_p; |
782 |
< |
struct Membership *ms; |
625 |
> |
dlink_node *ptr = NULL; |
626 |
> |
struct dbuf_block *buffer; |
627 |
> |
|
628 |
> |
buffer = dbuf_alloc(); |
629 |
|
|
630 |
|
va_start(args, pattern); |
631 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
631 |
> |
send_format(buffer, pattern, args); |
632 |
|
va_end(args); |
633 |
|
|
634 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
635 |
|
{ |
636 |
< |
ms = ptr->data; |
637 |
< |
target_p = ms->client_p; |
636 |
> |
struct Membership *ms = ptr->data; |
637 |
> |
struct Client *target_p = ms->client_p; |
638 |
|
|
639 |
|
if (type != 0 && (ms->flags & type) == 0) |
640 |
|
continue; |
641 |
|
|
642 |
< |
if (MyConnect(target_p)) |
642 |
> |
if (!MyConnect(target_p) || (one && target_p == one->from)) |
643 |
|
continue; |
798 |
– |
target_p = target_p->from; |
644 |
|
|
645 |
< |
if (target_p == one->from || |
801 |
< |
((target_p->from->localClient->caps & caps) != caps) || |
802 |
< |
((target_p->from->localClient->caps & nocaps) != 0)) |
645 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
646 |
|
continue; |
647 |
|
|
648 |
< |
send_message(target_p, buffer, len); |
649 |
< |
} |
648 |
> |
if (HasCap(target_p, cap) != cap) |
649 |
> |
continue; |
650 |
> |
|
651 |
> |
send_message(target_p, buffer); |
652 |
> |
} |
653 |
> |
|
654 |
> |
dbuf_ref_free(buffer); |
655 |
|
} |
656 |
|
|
657 |
|
/* |
672 |
|
* side effects - NONE |
673 |
|
*/ |
674 |
|
static int |
675 |
< |
match_it(const struct Client *one, const char *mask, int what) |
675 |
> |
match_it(const struct Client *one, const char *mask, unsigned int what) |
676 |
|
{ |
677 |
|
if (what == MATCH_HOST) |
678 |
< |
return(match(mask, one->host)); |
678 |
> |
return !match(mask, one->host); |
679 |
|
|
680 |
< |
return(match(mask, one->servptr->name)); |
680 |
> |
return !match(mask, one->servptr->name); |
681 |
|
} |
682 |
|
|
683 |
|
/* sendto_match_butone() |
688 |
|
* ugh. ONLY used by m_message.c to send an "oper magic" message. ugh. |
689 |
|
*/ |
690 |
|
void |
691 |
< |
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
691 |
> |
sendto_match_butone(struct Client *one, struct Client *from, const char *mask, |
692 |
|
int what, const char *pattern, ...) |
693 |
|
{ |
694 |
< |
va_list args; |
695 |
< |
struct Client *client_p; |
696 |
< |
dlink_node *ptr, *ptr_next; |
697 |
< |
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
698 |
< |
int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name, |
699 |
< |
from->username, from->host); |
700 |
< |
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
701 |
< |
|
702 |
< |
va_start(args, pattern); |
703 |
< |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
704 |
< |
pattern, args); |
705 |
< |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
706 |
< |
pattern, args); |
707 |
< |
va_end(args); |
694 |
> |
va_list alocal, aremote; |
695 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
696 |
> |
struct dbuf_block *local_buf, *remote_buf; |
697 |
> |
|
698 |
> |
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
699 |
> |
|
700 |
> |
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
701 |
> |
dbuf_put_fmt(remote_buf, ":%s ", ID(from)); |
702 |
> |
|
703 |
> |
va_start(alocal, pattern); |
704 |
> |
va_start(aremote, pattern); |
705 |
> |
send_format(local_buf, pattern, alocal); |
706 |
> |
send_format(remote_buf, pattern, aremote); |
707 |
> |
va_end(aremote); |
708 |
> |
va_end(alocal); |
709 |
|
|
710 |
|
/* scan the local clients */ |
711 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
712 |
|
{ |
713 |
< |
client_p = ptr->data; |
713 |
> |
struct Client *client_p = ptr->data; |
714 |
|
|
715 |
< |
if (client_p != one && !IsDefunct(client_p) && |
715 |
> |
if ((!one || client_p != one->from)&& !IsDefunct(client_p) && |
716 |
|
match_it(client_p, mask, what)) |
717 |
< |
send_message(client_p, local_buf, local_len); |
717 |
> |
send_message(client_p, local_buf); |
718 |
|
} |
719 |
|
|
720 |
|
/* Now scan servers */ |
721 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
722 |
|
{ |
723 |
< |
client_p = ptr->data; |
723 |
> |
struct Client *client_p = ptr->data; |
724 |
|
|
725 |
|
/* |
726 |
|
* The old code looped through every client on the |
746 |
|
* server deal with it. |
747 |
|
* -wnder |
748 |
|
*/ |
749 |
< |
if (client_p != one && !IsDefunct(client_p)) |
750 |
< |
send_message_remote(client_p, from, remote_buf, remote_len); |
749 |
> |
if ((!one || client_p != one->from) && !IsDefunct(client_p)) |
750 |
> |
send_message_remote(client_p, from, remote_buf); |
751 |
|
} |
752 |
+ |
|
753 |
+ |
dbuf_ref_free(local_buf); |
754 |
+ |
dbuf_ref_free(remote_buf); |
755 |
|
} |
756 |
|
|
757 |
|
/* sendto_match_servs() |
764 |
|
* side effects - data sent to servers matching with capab |
765 |
|
*/ |
766 |
|
void |
767 |
< |
sendto_match_servs(struct Client *source_p, const char *mask, int cap, |
767 |
> |
sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap, |
768 |
|
const char *pattern, ...) |
769 |
|
{ |
770 |
|
va_list args; |
771 |
< |
struct Client *target_p; |
772 |
< |
dlink_node *ptr; |
773 |
< |
char buffer[IRCD_BUFSIZE]; |
774 |
< |
int found = 0; |
771 |
> |
dlink_node *ptr = NULL; |
772 |
> |
struct dbuf_block *buff_suid; |
773 |
> |
|
774 |
> |
buff_suid = dbuf_alloc(); |
775 |
|
|
776 |
|
va_start(args, pattern); |
777 |
< |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
777 |
> |
dbuf_put_fmt(buff_suid, ":%s ", ID(source_p)); |
778 |
> |
dbuf_put_args(buff_suid, pattern, args); |
779 |
|
va_end(args); |
780 |
|
|
781 |
< |
current_serial++; |
781 |
> |
++current_serial; |
782 |
|
|
783 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
784 |
|
{ |
785 |
< |
target_p = ptr->data; |
785 |
> |
struct Client *target_p = ptr->data; |
786 |
|
|
787 |
|
/* Do not attempt to send to ourselves, or the source */ |
788 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
789 |
|
continue; |
790 |
|
|
791 |
< |
if (target_p->from->serial == current_serial) |
791 |
> |
if (target_p->from->localClient->serial == current_serial) |
792 |
|
continue; |
793 |
|
|
794 |
< |
if (match(mask, target_p->name)) |
794 |
> |
if (!match(mask, target_p->name)) |
795 |
|
{ |
796 |
|
/* |
797 |
|
* if we set the serial here, then we'll never do a |
798 |
|
* match() again, if !IsCapable() |
799 |
|
*/ |
800 |
< |
target_p->from->serial = current_serial; |
948 |
< |
found++; |
800 |
> |
target_p->from->localClient->serial = current_serial; |
801 |
|
|
802 |
|
if (!IsCapable(target_p->from, cap)) |
803 |
|
continue; |
804 |
|
|
805 |
< |
sendto_anywhere(target_p, source_p, "%s", buffer); |
805 |
> |
send_message_remote(target_p->from, source_p, buff_suid); |
806 |
|
} |
807 |
|
} |
808 |
+ |
|
809 |
+ |
dbuf_ref_free(buff_suid); |
810 |
|
} |
811 |
|
|
812 |
|
/* sendto_anywhere() |
820 |
|
*/ |
821 |
|
void |
822 |
|
sendto_anywhere(struct Client *to, struct Client *from, |
823 |
+ |
const char *command, |
824 |
|
const char *pattern, ...) |
825 |
|
{ |
826 |
|
va_list args; |
827 |
< |
char buffer[IRCD_BUFSIZE]; |
973 |
< |
int len; |
974 |
< |
struct Client *send_to = (to->from != NULL ? to->from : to); |
827 |
> |
struct dbuf_block *buffer; |
828 |
|
|
829 |
< |
if (IsDead(send_to)) |
829 |
> |
if (IsDead(to->from)) |
830 |
|
return; |
831 |
|
|
832 |
+ |
buffer = dbuf_alloc(); |
833 |
+ |
|
834 |
|
if (MyClient(to)) |
835 |
|
{ |
836 |
|
if (IsServer(from)) |
837 |
< |
{ |
983 |
< |
if (IsCapable(to, CAP_TS6) && HasID(from)) |
984 |
< |
len = ircsprintf(buffer, ":%s ", from->id); |
985 |
< |
else |
986 |
< |
len = ircsprintf(buffer, ":%s ", from->name); |
987 |
< |
} |
837 |
> |
dbuf_put_fmt(buffer, ":%s %s %s ", from->name, command, to->name); |
838 |
|
else |
839 |
< |
len = ircsprintf(buffer, ":%s!%s@%s ", |
990 |
< |
from->name, from->username, from->host); |
839 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, from->host, command, to->name); |
840 |
|
} |
841 |
< |
else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
841 |
> |
else |
842 |
> |
dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), command, ID_or_name(to, to)); |
843 |
|
|
844 |
|
va_start(args, pattern); |
845 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
845 |
> |
send_format(buffer, pattern, args); |
846 |
|
va_end(args); |
847 |
|
|
848 |
< |
if(MyClient(to)) |
849 |
< |
send_message(send_to, buffer, len); |
848 |
> |
if (MyClient(to)) |
849 |
> |
send_message(to, buffer); |
850 |
|
else |
851 |
< |
send_message_remote(send_to, from, buffer, len); |
851 |
> |
send_message_remote(to, from, buffer); |
852 |
> |
|
853 |
> |
dbuf_ref_free(buffer); |
854 |
|
} |
855 |
|
|
856 |
|
/* sendto_realops_flags() |
862 |
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
863 |
|
*/ |
864 |
|
void |
865 |
< |
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
865 |
> |
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
866 |
|
{ |
867 |
< |
struct Client *client_p; |
867 |
> |
const char *ntype = NULL; |
868 |
> |
dlink_node *ptr = NULL; |
869 |
|
char nbuf[IRCD_BUFSIZE]; |
1017 |
– |
dlink_node *ptr; |
870 |
|
va_list args; |
871 |
|
|
872 |
|
va_start(args, pattern); |
873 |
< |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
873 |
> |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
874 |
|
va_end(args); |
875 |
|
|
876 |
+ |
switch (type) |
877 |
+ |
{ |
878 |
+ |
case SEND_NOTICE: |
879 |
+ |
ntype = "Notice"; |
880 |
+ |
break; |
881 |
+ |
case SEND_GLOBAL: |
882 |
+ |
ntype = "Global"; |
883 |
+ |
break; |
884 |
+ |
case SEND_LOCOPS: |
885 |
+ |
ntype = "LocOps"; |
886 |
+ |
break; |
887 |
+ |
default: |
888 |
+ |
assert(0); |
889 |
+ |
} |
890 |
+ |
|
891 |
|
DLINK_FOREACH(ptr, oper_list.head) |
892 |
|
{ |
893 |
< |
client_p = ptr->data; |
894 |
< |
assert(client_p->umodes & UMODE_OPER); |
893 |
> |
struct Client *client_p = ptr->data; |
894 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
895 |
|
|
896 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
897 |
< |
* If we're sending it to admins, and theyre not, skip. |
896 |
> |
/* |
897 |
> |
* If we're sending it to opers and they're an admin, skip. |
898 |
> |
* If we're sending it to admins, and they're not, skip. |
899 |
|
*/ |
900 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
901 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
900 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
901 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
902 |
|
continue; |
903 |
|
|
904 |
< |
if (client_p->umodes & flags) |
905 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
906 |
< |
me.name, client_p->name, nbuf); |
904 |
> |
if (HasUMode(client_p, flags)) |
905 |
> |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
906 |
> |
me.name, client_p->name, ntype, nbuf); |
907 |
|
} |
908 |
|
} |
909 |
|
|
919 |
|
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
920 |
|
const char *pattern, ...) |
921 |
|
{ |
922 |
< |
struct Client *client_p; |
1055 |
< |
dlink_node *ptr; |
922 |
> |
dlink_node *ptr = NULL; |
923 |
|
va_list args; |
924 |
< |
char buffer[IRCD_BUFSIZE]; |
925 |
< |
int len; |
924 |
> |
struct dbuf_block *buffer; |
925 |
> |
|
926 |
> |
buffer = dbuf_alloc(); |
927 |
|
|
928 |
|
if (IsClient(source_p)) |
929 |
< |
len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :", |
1062 |
< |
source_p->name, source_p->username, source_p->host); |
929 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
930 |
|
else |
931 |
< |
len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name); |
931 |
> |
dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name); |
932 |
|
|
933 |
|
va_start(args, pattern); |
934 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
934 |
> |
send_format(buffer, pattern, args); |
935 |
|
va_end(args); |
936 |
|
|
937 |
|
DLINK_FOREACH(ptr, oper_list.head) |
938 |
|
{ |
939 |
< |
client_p = ptr->data; |
939 |
> |
struct Client *client_p = ptr->data; |
940 |
|
assert(client_p->umodes & UMODE_OPER); |
941 |
|
|
942 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
943 |
< |
send_message(client_p, buffer, len); |
942 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
943 |
> |
send_message(client_p, buffer); |
944 |
|
} |
945 |
+ |
|
946 |
+ |
dbuf_ref_free(buffer); |
947 |
|
} |
948 |
|
|
949 |
|
/* ts_warn() |
954 |
|
* (at most 5 warnings every 5 seconds) |
955 |
|
*/ |
956 |
|
void |
957 |
< |
ts_warn(const char *pattern, ...) |
957 |
> |
sendto_realops_flags_ratelimited(const char *pattern, ...) |
958 |
|
{ |
959 |
|
va_list args; |
960 |
< |
char buffer[LOG_BUFSIZE]; |
960 |
> |
char buffer[IRCD_BUFSIZE]; |
961 |
|
static time_t last = 0; |
962 |
|
static int warnings = 0; |
963 |
|
|
980 |
|
} |
981 |
|
|
982 |
|
va_start(args, pattern); |
983 |
< |
vsprintf_irc(buffer, pattern, args); |
983 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
984 |
|
va_end(args); |
985 |
|
|
986 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
987 |
< |
ilog(L_CRIT, "%s", buffer); |
986 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
987 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
988 |
|
} |
989 |
|
|
990 |
|
/* kill_client() |
1000 |
|
const char *pattern, ...) |
1001 |
|
{ |
1002 |
|
va_list args; |
1003 |
< |
char buffer[IRCD_BUFSIZE]; |
1004 |
< |
int len; |
1003 |
> |
struct dbuf_block *buffer; |
1004 |
> |
|
1005 |
> |
client_p = client_p->from; |
1006 |
|
|
1137 |
– |
if (client_p->from != NULL) |
1138 |
– |
client_p = client_p->from; |
1007 |
|
if (IsDead(client_p)) |
1008 |
|
return; |
1009 |
|
|
1010 |
< |
len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
1011 |
< |
ID_or_name(diedie, client_p)); |
1010 |
> |
buffer = dbuf_alloc(); |
1011 |
> |
|
1012 |
> |
dbuf_put_fmt(buffer, ":%s KILL %s :", |
1013 |
> |
ID_or_name(&me, client_p), |
1014 |
> |
ID_or_name(diedie, client_p)); |
1015 |
|
|
1016 |
|
va_start(args, pattern); |
1017 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
1017 |
> |
send_format(buffer, pattern, args); |
1018 |
|
va_end(args); |
1019 |
|
|
1020 |
< |
send_message(client_p, buffer, len); |
1020 |
> |
send_message(client_p, buffer); |
1021 |
> |
|
1022 |
> |
dbuf_ref_free(buffer); |
1023 |
|
} |
1024 |
|
|
1025 |
< |
/* kill_client_ll_serv_butone() |
1025 |
> |
/* kill_client_serv_butone() |
1026 |
|
* |
1027 |
|
* inputs - pointer to client to not send to |
1028 |
|
* - pointer to client to kill |
1033 |
|
* client being unknown to leaf, as in lazylink... |
1034 |
|
*/ |
1035 |
|
void |
1036 |
< |
kill_client_ll_serv_butone(struct Client *one, struct Client *source_p, |
1037 |
< |
const char *pattern, ...) |
1036 |
> |
kill_client_serv_butone(struct Client *one, struct Client *source_p, |
1037 |
> |
const char *pattern, ...) |
1038 |
|
{ |
1039 |
|
va_list args; |
1040 |
< |
int have_uid = 0; |
1041 |
< |
struct Client *client_p; |
1169 |
< |
dlink_node *ptr; |
1170 |
< |
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1171 |
< |
int len_uid = 0, len_nick; |
1040 |
> |
dlink_node *ptr = NULL; |
1041 |
> |
struct dbuf_block *uid_buffer = dbuf_alloc(); |
1042 |
|
|
1043 |
|
va_start(args, pattern); |
1044 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
1045 |
< |
{ |
1176 |
< |
have_uid = 1; |
1177 |
< |
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1178 |
< |
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
1179 |
< |
args); |
1180 |
< |
} |
1181 |
< |
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1182 |
< |
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
1183 |
< |
args); |
1044 |
> |
dbuf_put_fmt(uid_buffer, ":%s KILL %s :", ID(&me), ID(source_p)); |
1045 |
> |
send_format(uid_buffer, pattern, args); |
1046 |
|
va_end(args); |
1047 |
|
|
1048 |
|
DLINK_FOREACH(ptr, serv_list.head) |
1049 |
|
{ |
1050 |
< |
client_p = ptr->data; |
1050 |
> |
struct Client *client_p = ptr->data; |
1051 |
|
|
1052 |
|
if (one != NULL && (client_p == one->from)) |
1053 |
|
continue; |
1054 |
|
if (IsDefunct(client_p)) |
1055 |
|
continue; |
1056 |
|
|
1057 |
< |
/* XXX perhaps IsCapable should test for localClient itself ? -db */ |
1196 |
< |
if (client_p->localClient == NULL || !IsCapable(client_p, CAP_LL) || |
1197 |
< |
!ServerInfo.hub || |
1198 |
< |
(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 |
< |
} |
1057 |
> |
send_message(client_p, uid_buffer); |
1058 |
|
} |
1059 |
< |
} |
1059 |
> |
|
1060 |
> |
dbuf_ref_free(uid_buffer); |
1061 |
> |
} |