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" |
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 "s_log.h" |
39 |
> |
#include "conf.h" |
40 |
> |
#include "log.h" |
41 |
|
#include "memory.h" |
43 |
– |
#include "hook.h" |
44 |
– |
#include "irc_getnameinfo.h" |
42 |
|
#include "packet.h" |
43 |
|
|
44 |
< |
#define LOG_BUFSIZE 2048 |
45 |
< |
|
46 |
< |
struct Callback *iosend_cb = NULL; |
50 |
< |
struct Callback *iosendctrl_cb = NULL; |
51 |
< |
|
52 |
< |
static void send_message(struct Client *, char *, int); |
53 |
< |
static void send_message_remote(struct Client *, struct Client *, char *, int); |
44 |
> |
#ifndef IOV_MAX |
45 |
> |
#define IOV_MAX 64 |
46 |
> |
#endif |
47 |
|
|
48 |
|
static unsigned int current_serial = 0; |
49 |
|
|
50 |
+ |
|
51 |
|
/* send_format() |
52 |
|
* |
53 |
< |
* inputs - buffer to format into |
54 |
< |
* - size of the buffer |
53 |
> |
* inputs |
54 |
> |
* - buffer |
55 |
|
* - format pattern to use |
56 |
|
* - var args |
57 |
|
* output - number of bytes formatted output |
58 |
|
* side effects - modifies sendbuf |
59 |
|
*/ |
60 |
< |
static inline int |
61 |
< |
send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args) |
60 |
> |
static void |
61 |
> |
send_format(struct dbuf_block *buffer, const char *pattern, va_list args) |
62 |
|
{ |
69 |
– |
int len; |
70 |
– |
|
63 |
|
/* |
64 |
|
* from rfc1459 |
65 |
|
* |
66 |
|
* IRC messages are always lines of characters terminated with a CR-LF |
67 |
|
* (Carriage Return - Line Feed) pair, and these messages shall not |
68 |
< |
* exceed 512 characters in length, counting all characters |
68 |
> |
* exceed 512 characters in length, counting all characters |
69 |
|
* including the trailing CR-LF. |
70 |
|
* Thus, there are 510 characters maximum allowed |
71 |
|
* for the command and its parameters. There is no provision for |
72 |
|
* continuation message lines. See section 7 for more details about |
73 |
|
* current implementations. |
74 |
|
*/ |
75 |
< |
len = vsnprintf(lsendbuf, bufsize - 1, pattern, args); |
84 |
< |
if (len > bufsize - 2) |
85 |
< |
len = bufsize - 2; /* required by some versions of vsnprintf */ |
86 |
< |
|
87 |
< |
lsendbuf[len++] = '\r'; |
88 |
< |
lsendbuf[len++] = '\n'; |
89 |
< |
return (len); |
90 |
< |
} |
75 |
> |
dbuf_put_args(buffer, pattern, args); |
76 |
|
|
77 |
< |
/* |
78 |
< |
* iosend_default - append a packet to the client's sendq. |
94 |
< |
*/ |
95 |
< |
void * |
96 |
< |
iosend_default(va_list args) |
97 |
< |
{ |
98 |
< |
struct Client *to = va_arg(args, struct Client *); |
99 |
< |
int length = va_arg(args, int); |
100 |
< |
char *buf = va_arg(args, char *); |
77 |
> |
if (buffer->size > sizeof(buffer->data) - 2) |
78 |
> |
buffer->size = sizeof(buffer->data) - 2; |
79 |
|
|
80 |
< |
dbuf_put(&to->localClient->buf_sendq, buf, length); |
81 |
< |
return NULL; |
80 |
> |
buffer->data[buffer->size++] = '\r'; |
81 |
> |
buffer->data[buffer->size++] = '\n'; |
82 |
|
} |
83 |
|
|
84 |
|
/* |
87 |
|
** sendq. |
88 |
|
*/ |
89 |
|
static void |
90 |
< |
send_message(struct Client *to, char *buf, int len) |
90 |
> |
send_message(struct Client *to, struct dbuf_block *buf) |
91 |
|
{ |
92 |
|
assert(!IsMe(to)); |
93 |
|
assert(to != &me); |
94 |
|
|
95 |
< |
if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to)) |
95 |
> |
if (dbuf_length(&to->localClient->buf_sendq) + buf->size > get_sendq(&to->localClient->confs)) |
96 |
|
{ |
97 |
|
if (IsServer(to)) |
98 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
99 |
< |
"Max SendQ limit exceeded for %s: %lu > %lu", |
98 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
99 |
> |
"Max SendQ limit exceeded for %s: %lu > %u", |
100 |
|
get_client_name(to, HIDE_IP), |
101 |
< |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len), |
102 |
< |
get_sendq(to)); |
101 |
> |
(unsigned long)(dbuf_length(&to->localClient->buf_sendq) + buf->size), |
102 |
> |
get_sendq(&to->localClient->confs)); |
103 |
|
if (IsClient(to)) |
104 |
|
SetSendQExceeded(to); |
105 |
+ |
|
106 |
|
dead_link_on_write(to, 0); |
107 |
|
return; |
108 |
|
} |
109 |
|
|
110 |
< |
execute_callback(iosend_cb, to, len, buf); |
110 |
> |
dbuf_add(&to->localClient->buf_sendq, buf); |
111 |
|
|
112 |
|
/* |
113 |
< |
** Update statistics. The following is slightly incorrect |
114 |
< |
** because it counts messages even if queued, but bytes |
115 |
< |
** only really sent. Queued bytes get updated in SendQueued. |
113 |
> |
* Update statistics. The following is slightly incorrect because |
114 |
> |
* it counts messages even if queued, but bytes only really sent. |
115 |
> |
* Queued bytes get updated in send_queued_write(). |
116 |
|
*/ |
117 |
|
++to->localClient->send.messages; |
118 |
|
++me.localClient->send.messages; |
119 |
|
|
120 |
< |
if (dbuf_length(&to->localClient->buf_sendq) > |
142 |
< |
(IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096)) |
143 |
< |
send_queued_write(to); |
120 |
> |
send_queued_write(to); |
121 |
|
} |
122 |
|
|
123 |
|
/* send_message_remote() |
124 |
|
* |
125 |
|
* inputs - pointer to client from message is being sent |
126 |
|
* - pointer to client to send to |
127 |
< |
* - pointer to preformatted buffer |
151 |
< |
* - length of input buffer |
127 |
> |
* - pointer to buffer |
128 |
|
* output - none |
129 |
|
* side effects - Despite the function name, this only sends to directly |
130 |
|
* connected clients. |
131 |
< |
* |
131 |
> |
* |
132 |
|
*/ |
133 |
|
static void |
134 |
< |
send_message_remote(struct Client *to, struct Client *from, |
159 |
< |
char *buf, int len) |
134 |
> |
send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf) |
135 |
|
{ |
136 |
+ |
to = to->from; |
137 |
+ |
|
138 |
|
if (!MyConnect(to)) |
139 |
|
{ |
140 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
141 |
< |
"server send message to %s [%s] dropped from %s(Not local server)", |
142 |
< |
to->name, to->from->name, from->name); |
140 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
141 |
> |
"Server send message to %s [%s] dropped from %s(Not local server)", |
142 |
> |
to->name, to->from->name, from->name); |
143 |
|
return; |
144 |
|
} |
145 |
|
|
150 |
|
{ |
151 |
|
if (IsServer(from)) |
152 |
|
{ |
153 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
153 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
154 |
|
"Send message to %s [%s] dropped from %s(Fake Dir)", |
155 |
|
to->name, to->from->name, from->name); |
156 |
|
return; |
157 |
|
} |
158 |
|
|
159 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
159 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
160 |
|
"Ghosted: %s[%s@%s] from %s[%s@%s] (%s)", |
161 |
|
to->name, to->username, to->host, |
162 |
|
from->name, from->username, from->host, |
163 |
|
to->from->name); |
164 |
|
|
165 |
< |
sendto_server(NULL, NULL, CAP_TS6, NOCAPS, |
189 |
< |
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
190 |
< |
me.id, to->name, me.name, to->name, |
191 |
< |
to->username, to->host, to->from->name); |
192 |
< |
sendto_server(NULL, NULL, NOCAPS, CAP_TS6, |
165 |
> |
sendto_server(NULL, NOCAPS, NOCAPS, |
166 |
|
":%s KILL %s :%s (%s[%s@%s] Ghosted %s)", |
167 |
< |
me.name, to->name, me.name, to->name, |
167 |
> |
me.id, to->id, me.name, to->name, |
168 |
|
to->username, to->host, to->from->name); |
169 |
|
|
170 |
< |
SetKilled(to); |
170 |
> |
AddFlag(to, FLAGS_KILLED); |
171 |
|
|
172 |
|
if (IsClient(from)) |
173 |
< |
sendto_one(from, form_str(ERR_GHOSTEDCLIENT), |
174 |
< |
me.name, from->name, to->name, to->username, |
202 |
< |
to->host, to->from); |
203 |
< |
|
204 |
< |
exit_client(to, &me, "Ghosted client"); |
173 |
> |
sendto_one_numeric(from, &me, ERR_GHOSTEDCLIENT, to->name, |
174 |
> |
to->username, to->host, to->from); |
175 |
|
|
176 |
+ |
exit_client(to, "Ghosted client"); |
177 |
|
return; |
178 |
< |
} |
178 |
> |
} |
179 |
|
|
180 |
< |
send_message(to, buf, len); |
180 |
> |
send_message(to, buf); |
181 |
|
} |
182 |
|
|
183 |
|
/* |
187 |
|
void |
188 |
|
sendq_unblocked(fde_t *fd, struct Client *client_p) |
189 |
|
{ |
190 |
< |
ClearSendqBlocked(client_p); |
191 |
< |
/* let send_queued_write be executed by send_queued_all */ |
190 |
> |
assert(fd == &client_p->localClient->fd); |
191 |
> |
send_queued_write(client_p); |
192 |
> |
} |
193 |
|
|
194 |
|
#ifdef HAVE_LIBCRYPTO |
195 |
< |
if (fd->flags.pending_read) |
195 |
> |
static int |
196 |
> |
send_SSL_writev(SSL *ssl, const struct iovec *vec, int iovcnt) |
197 |
> |
{ |
198 |
> |
int total_written = 0; |
199 |
> |
|
200 |
> |
for (int i = 0; i < iovcnt; ++i) |
201 |
|
{ |
202 |
< |
fd->flags.pending_read = 0; |
203 |
< |
read_packet(fd, client_p); |
202 |
> |
const struct iovec *iov = &vec[i]; |
203 |
> |
int ret = 0; |
204 |
> |
|
205 |
> |
/* Translate openssl error codes, sigh */ |
206 |
> |
if ((ret = SSL_write(ssl, iov->iov_base, iov->iov_len)) <= 0) |
207 |
> |
{ |
208 |
> |
switch (SSL_get_error(ssl, i)) |
209 |
> |
{ |
210 |
> |
case SSL_ERROR_WANT_READ: |
211 |
> |
return -1; |
212 |
> |
case SSL_ERROR_WANT_WRITE: |
213 |
> |
errno = EWOULDBLOCK; |
214 |
> |
case SSL_ERROR_SYSCALL: |
215 |
> |
break; |
216 |
> |
case SSL_ERROR_SSL: |
217 |
> |
if (errno == EAGAIN) |
218 |
> |
break; |
219 |
> |
default: |
220 |
> |
errno = 0; /* Either an SSL-specific error or EOF */ |
221 |
> |
} |
222 |
> |
|
223 |
> |
return 0; |
224 |
> |
} |
225 |
> |
|
226 |
> |
total_written += ret; |
227 |
|
} |
228 |
– |
#endif |
229 |
– |
} |
228 |
|
|
229 |
< |
/* |
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); |
229 |
> |
return total_written; |
230 |
|
} |
231 |
+ |
#endif |
232 |
|
|
233 |
|
/* |
234 |
|
** send_queued_write |
239 |
|
void |
240 |
|
send_queued_write(struct Client *to) |
241 |
|
{ |
242 |
< |
int retlen; |
243 |
< |
struct dbuf_block *first; |
242 |
> |
int retlen = 0, i = 0; |
243 |
> |
dlink_node *ptr = NULL; |
244 |
> |
struct iovec vec[IOV_MAX]; |
245 |
|
|
246 |
|
/* |
247 |
< |
** Once socket is marked dead, we cannot start writing to it, |
248 |
< |
** even if the error is removed... |
247 |
> |
* Once socket is marked dead, we cannot start writing to it, |
248 |
> |
* even if the error is removed... |
249 |
|
*/ |
250 |
< |
if (IsDead(to) || IsSendqBlocked(to)) |
251 |
< |
return; /* no use calling send() now */ |
260 |
< |
|
261 |
< |
/* Next, lets try to write some data */ |
262 |
< |
|
263 |
< |
if (dbuf_length(&to->localClient->buf_sendq)) |
264 |
< |
{ |
265 |
< |
do { |
266 |
< |
first = to->localClient->buf_sendq.blocks.head->data; |
267 |
< |
|
268 |
< |
#ifdef HAVE_LIBCRYPTO |
269 |
< |
if (to->localClient->fd.ssl) |
270 |
< |
{ |
271 |
< |
retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size); |
250 |
> |
if (IsDead(to)) |
251 |
> |
return; /* No use calling send() now */ |
252 |
|
|
253 |
< |
/* translate openssl error codes, sigh */ |
254 |
< |
if (retlen < 0) |
275 |
< |
switch (SSL_get_error(to->localClient->fd.ssl, retlen)) |
276 |
< |
{ |
277 |
< |
case SSL_ERROR_WANT_READ: |
278 |
< |
return; /* retry later, don't register for write events */ |
279 |
< |
|
280 |
< |
case SSL_ERROR_WANT_WRITE: |
281 |
< |
errno = EWOULDBLOCK; |
282 |
< |
case SSL_ERROR_SYSCALL: |
283 |
< |
break; |
284 |
< |
case SSL_ERROR_SSL: |
285 |
< |
if (errno == EAGAIN) |
286 |
< |
break; |
287 |
< |
default: |
288 |
< |
retlen = errno = 0; /* either an SSL-specific error or EOF */ |
289 |
< |
} |
290 |
< |
} |
291 |
< |
else |
292 |
< |
#endif |
293 |
< |
retlen = send(to->localClient->fd.fd, first->data, first->size, 0); |
253 |
> |
if (HasFlag(to, FLAGS_CORK)) |
254 |
> |
return; |
255 |
|
|
256 |
< |
if (retlen <= 0) |
257 |
< |
break; |
256 |
> |
/* Nothing to do? */ |
257 |
> |
if (!dbuf_length(&to->localClient->buf_sendq)) |
258 |
> |
return; |
259 |
|
|
260 |
< |
dbuf_delete(&to->localClient->buf_sendq, retlen); |
260 |
> |
/* Build iovec */ |
261 |
> |
DLINK_FOREACH(ptr, to->localClient->buf_sendq.blocks.head) |
262 |
> |
{ |
263 |
> |
struct dbuf_block *block = ptr->data; |
264 |
> |
struct iovec *iov; |
265 |
> |
int offset; |
266 |
> |
|
267 |
> |
if (i >= sizeof(vec) / sizeof(struct iovec)) |
268 |
> |
break; |
269 |
> |
|
270 |
> |
iov = &vec[i]; |
271 |
> |
offset = !i ? to->localClient->buf_sendq.pos : 0; |
272 |
|
|
273 |
< |
/* We have some data written .. update counters */ |
274 |
< |
to->localClient->send.bytes += retlen; |
302 |
< |
me.localClient->send.bytes += retlen; |
303 |
< |
} while (dbuf_length(&to->localClient->buf_sendq)); |
273 |
> |
iov->iov_base = block->data + offset; |
274 |
> |
iov->iov_len = block->size - offset; |
275 |
|
|
276 |
< |
if ((retlen < 0) && (ignoreErrno(errno))) |
306 |
< |
{ |
307 |
< |
/* we have a non-fatal error, reschedule a write */ |
308 |
< |
SetSendqBlocked(to); |
309 |
< |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
310 |
< |
(PF *)sendq_unblocked, (void *)to, 0); |
311 |
< |
} |
312 |
< |
else if (retlen <= 0) |
313 |
< |
{ |
314 |
< |
dead_link_on_write(to, errno); |
315 |
< |
return; |
316 |
< |
} |
276 |
> |
++i; |
277 |
|
} |
318 |
– |
} |
319 |
– |
|
320 |
– |
/* |
321 |
– |
** send_queued_slink_write |
322 |
– |
** This is called when there is a chance the some output would |
323 |
– |
** be possible. This attempts to empty the send queue as far as |
324 |
– |
** possible, and then if any data is left, a write is rescheduled. |
325 |
– |
*/ |
326 |
– |
void |
327 |
– |
send_queued_slink_write(struct Client *to) |
328 |
– |
{ |
329 |
– |
int retlen; |
330 |
– |
|
331 |
– |
/* |
332 |
– |
** Once socket is marked dead, we cannot start writing to it, |
333 |
– |
** even if the error is removed... |
334 |
– |
*/ |
335 |
– |
if (IsDead(to) || IsSlinkqBlocked(to)) |
336 |
– |
return; /* no use calling send() now */ |
278 |
|
|
279 |
|
/* Next, lets try to write some data */ |
280 |
< |
if (to->localClient->slinkq != NULL) |
280 |
> |
#ifdef HAVE_LIBCRYPTO |
281 |
> |
if (to->localClient->fd.ssl) |
282 |
|
{ |
283 |
< |
retlen = send(to->localClient->ctrlfd.fd, |
342 |
< |
to->localClient->slinkq + to->localClient->slinkq_ofs, |
343 |
< |
to->localClient->slinkq_len, 0); |
344 |
< |
if (retlen < 0) |
345 |
< |
{ |
346 |
< |
/* If we have a fatal error */ |
347 |
< |
if (!ignoreErrno(errno)) |
348 |
< |
{ |
349 |
< |
dead_link_on_write(to, errno); |
350 |
< |
return; |
351 |
< |
} |
352 |
< |
} |
353 |
< |
else if (retlen == 0) |
354 |
< |
{ |
355 |
< |
/* 0 bytes is an EOF .. */ |
356 |
< |
dead_link_on_write(to, 0); |
283 |
> |
if ((retlen = send_SSL_writev(to->localClient->fd.ssl, vec, i)) == -1) |
284 |
|
return; |
285 |
< |
} |
286 |
< |
else |
287 |
< |
{ |
288 |
< |
execute_callback(iosendctrl_cb, to, retlen, |
362 |
< |
to->localClient->slinkq + to->localClient->slinkq_ofs); |
363 |
< |
to->localClient->slinkq_len -= retlen; |
364 |
< |
|
365 |
< |
assert(to->localClient->slinkq_len >= 0); |
366 |
< |
if (to->localClient->slinkq_len) |
367 |
< |
to->localClient->slinkq_ofs += retlen; |
368 |
< |
else |
369 |
< |
{ |
370 |
< |
to->localClient->slinkq_ofs = 0; |
371 |
< |
MyFree(to->localClient->slinkq); |
372 |
< |
to->localClient->slinkq = NULL; |
373 |
< |
} |
374 |
< |
} |
285 |
> |
} |
286 |
> |
else |
287 |
> |
#endif |
288 |
> |
retlen = writev(to->localClient->fd.fd, vec, i); |
289 |
|
|
290 |
< |
/* Finally, if we have any more data, reschedule a write */ |
291 |
< |
if (to->localClient->slinkq_len) |
292 |
< |
{ |
293 |
< |
SetSlinkqBlocked(to); |
294 |
< |
comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE, |
295 |
< |
(PF *)slinkq_unblocked, (void *)to, 0); |
296 |
< |
} |
290 |
> |
if (retlen > 0) |
291 |
> |
{ |
292 |
> |
dbuf_delete(&to->localClient->buf_sendq, retlen); |
293 |
> |
|
294 |
> |
/* We have some data written .. update counters */ |
295 |
> |
to->localClient->send.bytes += retlen; |
296 |
> |
me.localClient->send.bytes += retlen; |
297 |
> |
|
298 |
> |
if (dbuf_length(&to->localClient->buf_sendq)) |
299 |
> |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
300 |
> |
(PF *)sendq_unblocked, to, 0); |
301 |
|
} |
302 |
+ |
else if (retlen < 0 && ignoreErrno(errno)) |
303 |
+ |
/* we have a non-fatal error, reschedule a write */ |
304 |
+ |
comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE, |
305 |
+ |
(PF *)sendq_unblocked, to, 0); |
306 |
+ |
else if (retlen <= 0) |
307 |
+ |
dead_link_on_write(to, errno); |
308 |
|
} |
309 |
|
|
310 |
|
/* send_queued_all() |
322 |
|
* a notice to opers, which is to be delivered by this function. |
323 |
|
*/ |
324 |
|
DLINK_FOREACH(ptr, serv_list.head) |
325 |
< |
send_queued_write((struct Client *) ptr->data); |
325 |
> |
send_queued_write(ptr->data); |
326 |
|
|
327 |
|
DLINK_FOREACH(ptr, unknown_list.head) |
328 |
< |
send_queued_write((struct Client *) ptr->data); |
328 |
> |
send_queued_write(ptr->data); |
329 |
|
|
330 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
331 |
< |
send_queued_write((struct Client *) ptr->data); |
331 |
> |
send_queued_write(ptr->data); |
332 |
|
|
333 |
|
/* NOTE: This can still put clients on aborted_list; unfortunately, |
334 |
|
* exit_aborted_clients takes precedence over send_queued_all, |
349 |
|
sendto_one(struct Client *to, const char *pattern, ...) |
350 |
|
{ |
351 |
|
va_list args; |
352 |
< |
char buffer[IRCD_BUFSIZE]; |
429 |
< |
int len; |
352 |
> |
struct dbuf_block *buffer = NULL; |
353 |
|
|
354 |
< |
if (to->from != NULL) |
355 |
< |
to = to->from; |
356 |
< |
if (IsDead(to)) |
357 |
< |
return; /* This socket has already been marked as dead */ |
354 |
> |
if (IsDead(to->from)) |
355 |
> |
return; /* This socket has already been marked as dead */ |
356 |
> |
|
357 |
> |
buffer = dbuf_alloc(); |
358 |
|
|
359 |
|
va_start(args, pattern); |
360 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
360 |
> |
send_format(buffer, pattern, args); |
361 |
|
va_end(args); |
362 |
|
|
363 |
< |
send_message(to, buffer, len); |
363 |
> |
send_message(to->from, buffer); |
364 |
> |
|
365 |
> |
dbuf_ref_free(buffer); |
366 |
> |
} |
367 |
> |
|
368 |
> |
void |
369 |
> |
sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...) |
370 |
> |
{ |
371 |
> |
struct dbuf_block *buffer = NULL; |
372 |
> |
const char *dest = NULL; |
373 |
> |
va_list args; |
374 |
> |
|
375 |
> |
if (IsDead(to->from)) |
376 |
> |
return; |
377 |
> |
|
378 |
> |
dest = ID_or_name(to, to); |
379 |
> |
if (EmptyString(dest)) |
380 |
> |
dest = "*"; |
381 |
> |
|
382 |
> |
buffer = dbuf_alloc(); |
383 |
> |
|
384 |
> |
dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric, dest); |
385 |
> |
|
386 |
> |
va_start(args, numeric); |
387 |
> |
send_format(buffer, numeric_form(numeric), args); |
388 |
> |
va_end(args); |
389 |
> |
|
390 |
> |
send_message(to->from, buffer); |
391 |
> |
|
392 |
> |
dbuf_ref_free(buffer); |
393 |
> |
} |
394 |
> |
|
395 |
> |
void |
396 |
> |
sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...) |
397 |
> |
{ |
398 |
> |
struct dbuf_block *buffer = NULL; |
399 |
> |
const char *dest = NULL; |
400 |
> |
va_list args; |
401 |
> |
|
402 |
> |
if (IsDead(to->from)) |
403 |
> |
return; |
404 |
> |
|
405 |
> |
dest = ID_or_name(to, to); |
406 |
> |
if (EmptyString(dest)) |
407 |
> |
dest = "*"; |
408 |
> |
|
409 |
> |
buffer = dbuf_alloc(); |
410 |
> |
|
411 |
> |
dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest); |
412 |
> |
|
413 |
> |
va_start(args, pattern); |
414 |
> |
send_format(buffer, pattern, args); |
415 |
> |
va_end(args); |
416 |
> |
|
417 |
> |
send_message(to->from, buffer); |
418 |
> |
|
419 |
> |
dbuf_ref_free(buffer); |
420 |
|
} |
421 |
|
|
422 |
|
/* sendto_channel_butone() |
432 |
|
*/ |
433 |
|
void |
434 |
|
sendto_channel_butone(struct Client *one, struct Client *from, |
435 |
< |
struct Channel *chptr, const char *command, |
435 |
> |
struct Channel *chptr, unsigned int type, |
436 |
|
const char *pattern, ...) |
437 |
|
{ |
438 |
< |
va_list alocal, aremote, auid; |
439 |
< |
char local_buf[IRCD_BUFSIZE]; |
440 |
< |
char remote_buf[IRCD_BUFSIZE]; |
441 |
< |
char uid_buf[IRCD_BUFSIZE]; |
442 |
< |
int local_len, remote_len, uid_len; |
464 |
< |
dlink_node *ptr; |
465 |
< |
dlink_node *ptr_next; |
466 |
< |
struct Client *target_p; |
438 |
> |
va_list alocal, aremote; |
439 |
> |
struct dbuf_block *local_buf, *remote_buf; |
440 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
441 |
> |
|
442 |
> |
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
443 |
|
|
444 |
|
if (IsServer(from)) |
445 |
< |
local_len = ircsprintf(local_buf, ":%s %s %s ", |
470 |
< |
from->name, command, chptr->chname); |
445 |
> |
dbuf_put_fmt(local_buf, ":%s ", from->name); |
446 |
|
else |
447 |
< |
local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ", |
448 |
< |
from->name, from->username, from->host, |
449 |
< |
command, chptr->chname); |
475 |
< |
remote_len = ircsprintf(remote_buf, ":%s %s %s ", |
476 |
< |
from->name, command, chptr->chname); |
477 |
< |
uid_len = ircsprintf(uid_buf, ":%s %s %s ", |
478 |
< |
ID(from), command, chptr->chname); |
447 |
> |
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
448 |
> |
|
449 |
> |
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
450 |
|
|
451 |
|
va_start(alocal, pattern); |
452 |
|
va_start(aremote, pattern); |
453 |
< |
va_start(auid, pattern); |
454 |
< |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
455 |
< |
pattern, alocal); |
485 |
< |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
486 |
< |
pattern, aremote); |
487 |
< |
uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern, |
488 |
< |
auid); |
489 |
< |
va_end(auid); |
453 |
> |
send_format(local_buf, pattern, alocal); |
454 |
> |
send_format(remote_buf, pattern, aremote); |
455 |
> |
|
456 |
|
va_end(aremote); |
457 |
|
va_end(alocal); |
458 |
|
|
460 |
|
|
461 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head) |
462 |
|
{ |
463 |
< |
target_p = ((struct Membership *)ptr->data)->client_p; |
464 |
< |
assert(target_p != NULL); |
463 |
> |
struct Membership *ms = ptr->data; |
464 |
> |
struct Client *target_p = ms->client_p; |
465 |
> |
|
466 |
> |
assert(IsClient(target_p)); |
467 |
|
|
468 |
< |
if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one) |
468 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) || |
469 |
> |
(one && target_p->from == one->from)) |
470 |
|
continue; |
471 |
|
|
472 |
< |
if (MyClient(target_p)) |
473 |
< |
{ |
474 |
< |
if (target_p->serial != current_serial) |
475 |
< |
{ |
476 |
< |
send_message(target_p, local_buf, local_len); |
477 |
< |
target_p->serial = current_serial; |
478 |
< |
} |
479 |
< |
} |
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 |
< |
} |
472 |
> |
if (type && (ms->flags & type) == 0) |
473 |
> |
continue; |
474 |
> |
|
475 |
> |
if (MyConnect(target_p)) |
476 |
> |
send_message(target_p, local_buf); |
477 |
> |
else if (target_p->from->localClient->serial != current_serial) |
478 |
> |
send_message_remote(target_p->from, from, remote_buf); |
479 |
> |
target_p->from->localClient->serial = current_serial; |
480 |
|
} |
481 |
+ |
|
482 |
+ |
dbuf_ref_free(local_buf); |
483 |
+ |
dbuf_ref_free(remote_buf); |
484 |
|
} |
485 |
|
|
486 |
|
/* sendto_server() |
487 |
< |
* |
487 |
> |
* |
488 |
|
* inputs - pointer to client to NOT send to |
489 |
|
* - pointer to channel |
490 |
|
* - caps or'd together which must ALL be present |
495 |
|
* side effects - Send a message to all connected servers, except the |
496 |
|
* client 'one' (if non-NULL), as long as the servers |
497 |
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'. |
498 |
< |
* |
498 |
> |
* |
499 |
|
* This function was written in an attempt to merge together the other |
500 |
|
* billion sendto_*serv*() functions, which sprung up with capabs, |
501 |
|
* lazylinks, uids, etc. |
502 |
|
* -davidt |
503 |
|
*/ |
504 |
< |
void |
505 |
< |
sendto_server(struct Client *one, const struct Channel *chptr, |
504 |
> |
void |
505 |
> |
sendto_server(struct Client *one, |
506 |
|
const unsigned int caps, |
507 |
|
const unsigned int nocaps, |
508 |
|
const char *format, ...) |
509 |
|
{ |
510 |
|
va_list args; |
511 |
|
dlink_node *ptr = NULL; |
512 |
< |
char buffer[IRCD_BUFSIZE]; |
555 |
< |
int len = 0; |
512 |
> |
struct dbuf_block *buffer; |
513 |
|
|
514 |
< |
if (chptr && chptr->chname[0] != '#') |
558 |
< |
return; |
514 |
> |
buffer = dbuf_alloc(); |
515 |
|
|
516 |
|
va_start(args, format); |
517 |
< |
len = send_format(buffer, IRCD_BUFSIZE, format, args); |
517 |
> |
send_format(buffer, format, args); |
518 |
|
va_end(args); |
519 |
|
|
520 |
|
DLINK_FOREACH(ptr, serv_list.head) |
525 |
|
if (IsDead(client_p)) |
526 |
|
continue; |
527 |
|
/* check against 'one' */ |
528 |
< |
if (one != NULL && (client_p == one->from)) |
528 |
> |
if (one && (client_p == one->from)) |
529 |
|
continue; |
530 |
|
/* check we have required capabs */ |
531 |
|
if ((client_p->localClient->caps & caps) != caps) |
532 |
|
continue; |
533 |
|
/* check we don't have any forbidden capabs */ |
534 |
< |
if ((client_p->localClient->caps & nocaps) != 0) |
534 |
> |
if ((client_p->localClient->caps & nocaps)) |
535 |
|
continue; |
536 |
|
|
537 |
< |
send_message(client_p, buffer, len); |
537 |
> |
send_message(client_p, buffer); |
538 |
|
} |
539 |
+ |
|
540 |
+ |
dbuf_ref_free(buffer); |
541 |
|
} |
542 |
|
|
543 |
|
/* sendto_common_channels_local() |
546 |
|
* - pattern to send |
547 |
|
* output - NONE |
548 |
|
* side effects - Sends a message to all people on local server who are |
549 |
< |
* in same channel with user. |
549 |
> |
* in same channel with user. |
550 |
|
* used by m_nick.c and exit_one_client. |
551 |
|
*/ |
552 |
|
void |
553 |
< |
sendto_common_channels_local(struct Client *user, int touser, |
553 |
> |
sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, |
554 |
|
const char *pattern, ...) |
555 |
|
{ |
556 |
|
va_list args; |
559 |
|
struct Channel *chptr; |
560 |
|
struct Membership *ms; |
561 |
|
struct Client *target_p; |
562 |
< |
char buffer[IRCD_BUFSIZE]; |
563 |
< |
int len; |
562 |
> |
struct dbuf_block *buffer; |
563 |
> |
|
564 |
> |
buffer = dbuf_alloc(); |
565 |
|
|
566 |
|
va_start(args, pattern); |
567 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
567 |
> |
send_format(buffer, pattern, args); |
568 |
|
va_end(args); |
569 |
|
|
570 |
|
++current_serial; |
571 |
|
|
572 |
|
DLINK_FOREACH(cptr, user->channel.head) |
573 |
|
{ |
574 |
< |
chptr = ((struct Membership *) cptr->data)->chptr; |
616 |
< |
assert(chptr != NULL); |
574 |
> |
chptr = ((struct Membership *)cptr->data)->chptr; |
575 |
|
|
576 |
|
DLINK_FOREACH(uptr, chptr->members.head) |
577 |
|
{ |
578 |
|
ms = uptr->data; |
579 |
|
target_p = ms->client_p; |
622 |
– |
assert(target_p != NULL); |
580 |
|
|
581 |
|
if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) || |
582 |
< |
target_p->serial == current_serial) |
582 |
> |
target_p->localClient->serial == current_serial) |
583 |
> |
continue; |
584 |
> |
|
585 |
> |
if (HasCap(target_p, cap) != cap) |
586 |
|
continue; |
587 |
|
|
588 |
< |
target_p->serial = current_serial; |
589 |
< |
send_message(target_p, buffer, len); |
588 |
> |
target_p->localClient->serial = current_serial; |
589 |
> |
send_message(target_p, buffer); |
590 |
|
} |
591 |
|
} |
592 |
|
|
593 |
|
if (touser && MyConnect(user) && !IsDead(user) && |
594 |
< |
user->serial != current_serial) |
595 |
< |
send_message(user, buffer, len); |
594 |
> |
user->localClient->serial != current_serial) |
595 |
> |
if (HasCap(user, cap) == cap) |
596 |
> |
send_message(user, buffer); |
597 |
> |
|
598 |
> |
dbuf_ref_free(buffer); |
599 |
|
} |
600 |
|
|
601 |
|
/* sendto_channel_local() |
609 |
|
* locally connected to this server. |
610 |
|
*/ |
611 |
|
void |
612 |
< |
sendto_channel_local(int type, int nodeaf, struct Channel *chptr, |
612 |
> |
sendto_channel_local(unsigned int type, int nodeaf, struct Channel *chptr, |
613 |
|
const char *pattern, ...) |
614 |
|
{ |
615 |
|
va_list args; |
616 |
< |
char buffer[IRCD_BUFSIZE]; |
617 |
< |
int len; |
618 |
< |
dlink_node *ptr; |
619 |
< |
struct Membership *ms; |
657 |
< |
struct Client *target_p; |
616 |
> |
dlink_node *ptr = NULL; |
617 |
> |
struct dbuf_block *buffer; |
618 |
> |
|
619 |
> |
buffer = dbuf_alloc(); |
620 |
|
|
621 |
|
va_start(args, pattern); |
622 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
622 |
> |
send_format(buffer, pattern, args); |
623 |
|
va_end(args); |
624 |
|
|
625 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
626 |
|
{ |
627 |
< |
ms = ptr->data; |
628 |
< |
target_p = ms->client_p; |
627 |
> |
struct Membership *ms = ptr->data; |
628 |
> |
struct Client *target_p = ms->client_p; |
629 |
|
|
630 |
< |
if (type != 0 && (ms->flags & type) == 0) |
630 |
> |
if (type && (ms->flags & type) == 0) |
631 |
|
continue; |
632 |
|
|
633 |
|
if (!MyConnect(target_p) || IsDefunct(target_p) || |
634 |
< |
(nodeaf && IsDeaf(target_p))) |
634 |
> |
(nodeaf && HasUMode(target_p, UMODE_DEAF))) |
635 |
|
continue; |
636 |
|
|
637 |
< |
send_message(target_p, buffer, len); |
637 |
> |
send_message(target_p, buffer); |
638 |
|
} |
639 |
+ |
|
640 |
+ |
dbuf_ref_free(buffer); |
641 |
|
} |
642 |
|
|
643 |
|
/* sendto_channel_local_butone() |
652 |
|
* |
653 |
|
* WARNING - +D clients are omitted |
654 |
|
*/ |
691 |
– |
void |
692 |
– |
sendto_channel_local_butone(struct Client *one, int type, |
693 |
– |
struct Channel *chptr, const char *pattern, ...) |
694 |
– |
{ |
695 |
– |
va_list args; |
696 |
– |
char buffer[IRCD_BUFSIZE]; |
697 |
– |
int len; |
698 |
– |
struct Client *target_p; |
699 |
– |
struct Membership *ms; |
700 |
– |
dlink_node *ptr; |
701 |
– |
|
702 |
– |
va_start(args, pattern); |
703 |
– |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
704 |
– |
va_end(args); |
705 |
– |
|
706 |
– |
DLINK_FOREACH(ptr, chptr->members.head) |
707 |
– |
{ |
708 |
– |
ms = ptr->data; |
709 |
– |
target_p = ms->client_p; |
710 |
– |
|
711 |
– |
if (type != 0 && (ms->flags & type) == 0) |
712 |
– |
continue; |
713 |
– |
|
714 |
– |
if (!MyConnect(target_p) || target_p == one || |
715 |
– |
IsDefunct(target_p) || IsDeaf(target_p)) |
716 |
– |
continue; |
717 |
– |
send_message(target_p, buffer, len); |
718 |
– |
} |
719 |
– |
} |
720 |
– |
|
721 |
– |
|
722 |
– |
/* sendto_channel_remote() |
723 |
– |
* |
724 |
– |
* inputs - Client not to send towards |
725 |
– |
* - Client from whom message is from |
726 |
– |
* - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE |
727 |
– |
* - pointer to channel to send to |
728 |
– |
* - var args pattern |
729 |
– |
* output - NONE |
730 |
– |
* side effects - Send a message to all members of a channel that are |
731 |
– |
* remote to this server. |
732 |
– |
*/ |
655 |
|
void |
656 |
< |
sendto_channel_remote(struct Client *one, struct Client *from, int type, |
657 |
< |
const unsigned int caps, const unsigned int nocaps, |
736 |
< |
struct Channel *chptr, const char *pattern, ...) |
656 |
> |
sendto_channel_local_butone(struct Client *one, unsigned int type, unsigned int cap, |
657 |
> |
struct Channel *chptr, const char *pattern, ...) |
658 |
|
{ |
659 |
|
va_list args; |
660 |
< |
char buffer[IRCD_BUFSIZE]; |
661 |
< |
int len; |
662 |
< |
dlink_node *ptr; |
663 |
< |
struct Client *target_p; |
743 |
< |
struct Membership *ms; |
660 |
> |
dlink_node *ptr = NULL; |
661 |
> |
struct dbuf_block *buffer; |
662 |
> |
|
663 |
> |
buffer = dbuf_alloc(); |
664 |
|
|
665 |
|
va_start(args, pattern); |
666 |
< |
len = send_format(buffer, IRCD_BUFSIZE, pattern, args); |
666 |
> |
send_format(buffer, pattern, args); |
667 |
|
va_end(args); |
668 |
|
|
749 |
– |
++current_serial; |
750 |
– |
|
669 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
670 |
|
{ |
671 |
< |
ms = ptr->data; |
672 |
< |
target_p = ms->client_p; |
671 |
> |
struct Membership *ms = ptr->data; |
672 |
> |
struct Client *target_p = ms->client_p; |
673 |
|
|
674 |
< |
if (type != 0 && (ms->flags & type) == 0) |
674 |
> |
if (type && (ms->flags & type) == 0) |
675 |
|
continue; |
676 |
|
|
677 |
< |
if (MyConnect(target_p)) |
677 |
> |
if (!MyConnect(target_p) || (one && target_p == one->from)) |
678 |
|
continue; |
761 |
– |
target_p = target_p->from; |
679 |
|
|
680 |
< |
if (target_p == one->from || |
764 |
< |
((target_p->from->localClient->caps & caps) != caps) || |
765 |
< |
((target_p->from->localClient->caps & nocaps) != 0)) |
680 |
> |
if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) |
681 |
|
continue; |
682 |
< |
if (target_p->from->serial != current_serial) |
683 |
< |
{ |
684 |
< |
send_message(target_p, buffer, len); |
685 |
< |
target_p->from->serial = current_serial; |
686 |
< |
} |
687 |
< |
} |
682 |
> |
|
683 |
> |
if (HasCap(target_p, cap) != cap) |
684 |
> |
continue; |
685 |
> |
|
686 |
> |
send_message(target_p, buffer); |
687 |
> |
} |
688 |
> |
|
689 |
> |
dbuf_ref_free(buffer); |
690 |
|
} |
691 |
|
|
692 |
|
/* |
707 |
|
* side effects - NONE |
708 |
|
*/ |
709 |
|
static int |
710 |
< |
match_it(const struct Client *one, const char *mask, int what) |
710 |
> |
match_it(const struct Client *one, const char *mask, unsigned int what) |
711 |
|
{ |
712 |
|
if (what == MATCH_HOST) |
713 |
< |
return(match(mask, one->host)); |
713 |
> |
return !match(mask, one->host); |
714 |
|
|
715 |
< |
return(match(mask, one->servptr->name)); |
715 |
> |
return !match(mask, one->servptr->name); |
716 |
|
} |
717 |
|
|
718 |
|
/* sendto_match_butone() |
723 |
|
* ugh. ONLY used by m_message.c to send an "oper magic" message. ugh. |
724 |
|
*/ |
725 |
|
void |
726 |
< |
sendto_match_butone(struct Client *one, struct Client *from, char *mask, |
726 |
> |
sendto_match_butone(struct Client *one, struct Client *from, const char *mask, |
727 |
|
int what, const char *pattern, ...) |
728 |
|
{ |
729 |
|
va_list alocal, aremote; |
730 |
< |
struct Client *client_p; |
731 |
< |
dlink_node *ptr, *ptr_next; |
732 |
< |
char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE]; |
733 |
< |
int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name, |
734 |
< |
from->username, from->host); |
735 |
< |
int remote_len = ircsprintf(remote_buf, ":%s ", from->name); |
730 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
731 |
> |
struct dbuf_block *local_buf, *remote_buf; |
732 |
> |
|
733 |
> |
local_buf = dbuf_alloc(), remote_buf = dbuf_alloc(); |
734 |
> |
|
735 |
> |
dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host); |
736 |
> |
dbuf_put_fmt(remote_buf, ":%s ", from->id); |
737 |
|
|
738 |
|
va_start(alocal, pattern); |
739 |
|
va_start(aremote, pattern); |
740 |
< |
local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len, |
741 |
< |
pattern, alocal); |
824 |
< |
remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len, |
825 |
< |
pattern, aremote); |
740 |
> |
send_format(local_buf, pattern, alocal); |
741 |
> |
send_format(remote_buf, pattern, aremote); |
742 |
|
va_end(aremote); |
743 |
|
va_end(alocal); |
744 |
|
|
745 |
|
/* scan the local clients */ |
746 |
|
DLINK_FOREACH(ptr, local_client_list.head) |
747 |
|
{ |
748 |
< |
client_p = ptr->data; |
748 |
> |
struct Client *client_p = ptr->data; |
749 |
|
|
750 |
< |
if (client_p != one && !IsDefunct(client_p) && |
750 |
> |
if ((!one || client_p != one->from) && !IsDefunct(client_p) && |
751 |
|
match_it(client_p, mask, what)) |
752 |
< |
send_message(client_p, local_buf, local_len); |
752 |
> |
send_message(client_p, local_buf); |
753 |
|
} |
754 |
|
|
755 |
|
/* Now scan servers */ |
756 |
|
DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head) |
757 |
|
{ |
758 |
< |
client_p = ptr->data; |
758 |
> |
struct Client *client_p = ptr->data; |
759 |
|
|
760 |
|
/* |
761 |
|
* The old code looped through every client on the |
781 |
|
* server deal with it. |
782 |
|
* -wnder |
783 |
|
*/ |
784 |
< |
if (client_p != one && !IsDefunct(client_p)) |
785 |
< |
send_message_remote(client_p, from, remote_buf, remote_len); |
784 |
> |
if ((!one || client_p != one->from) && !IsDefunct(client_p)) |
785 |
> |
send_message_remote(client_p, from, remote_buf); |
786 |
|
} |
787 |
+ |
|
788 |
+ |
dbuf_ref_free(local_buf); |
789 |
+ |
dbuf_ref_free(remote_buf); |
790 |
|
} |
791 |
|
|
792 |
|
/* sendto_match_servs() |
799 |
|
* side effects - data sent to servers matching with capab |
800 |
|
*/ |
801 |
|
void |
802 |
< |
sendto_match_servs(struct Client *source_p, const char *mask, int cap, |
802 |
> |
sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap, |
803 |
|
const char *pattern, ...) |
804 |
|
{ |
805 |
|
va_list args; |
806 |
< |
struct Client *target_p; |
807 |
< |
dlink_node *ptr; |
808 |
< |
char buffer[IRCD_BUFSIZE]; |
809 |
< |
int found = 0; |
806 |
> |
dlink_node *ptr = NULL; |
807 |
> |
struct dbuf_block *buff_suid; |
808 |
> |
|
809 |
> |
buff_suid = dbuf_alloc(); |
810 |
|
|
811 |
|
va_start(args, pattern); |
812 |
< |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
812 |
> |
dbuf_put_fmt(buff_suid, ":%s ", source_p->id); |
813 |
> |
dbuf_put_args(buff_suid, pattern, args); |
814 |
|
va_end(args); |
815 |
|
|
816 |
|
++current_serial; |
817 |
|
|
818 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
819 |
|
{ |
820 |
< |
target_p = ptr->data; |
820 |
> |
struct Client *target_p = ptr->data; |
821 |
|
|
822 |
|
/* Do not attempt to send to ourselves, or the source */ |
823 |
|
if (IsMe(target_p) || target_p->from == source_p->from) |
824 |
|
continue; |
825 |
|
|
826 |
< |
if (target_p->from->serial == current_serial) |
826 |
> |
if (target_p->from->localClient->serial == current_serial) |
827 |
|
continue; |
828 |
|
|
829 |
< |
if (match(mask, target_p->name)) |
829 |
> |
if (!match(mask, target_p->name)) |
830 |
|
{ |
831 |
|
/* |
832 |
|
* if we set the serial here, then we'll never do a |
833 |
|
* match() again, if !IsCapable() |
834 |
|
*/ |
835 |
< |
target_p->from->serial = current_serial; |
916 |
< |
found++; |
835 |
> |
target_p->from->localClient->serial = current_serial; |
836 |
|
|
837 |
|
if (!IsCapable(target_p->from, cap)) |
838 |
|
continue; |
839 |
|
|
840 |
< |
sendto_anywhere(target_p, source_p, "%s", buffer); |
840 |
> |
send_message_remote(target_p->from, source_p, buff_suid); |
841 |
|
} |
842 |
|
} |
843 |
+ |
|
844 |
+ |
dbuf_ref_free(buff_suid); |
845 |
|
} |
846 |
|
|
847 |
|
/* sendto_anywhere() |
855 |
|
*/ |
856 |
|
void |
857 |
|
sendto_anywhere(struct Client *to, struct Client *from, |
858 |
+ |
const char *command, |
859 |
|
const char *pattern, ...) |
860 |
|
{ |
861 |
|
va_list args; |
862 |
< |
char buffer[IRCD_BUFSIZE]; |
941 |
< |
int len; |
942 |
< |
struct Client *send_to = (to->from != NULL ? to->from : to); |
862 |
> |
struct dbuf_block *buffer = NULL; |
863 |
|
|
864 |
< |
if (IsDead(send_to)) |
864 |
> |
if (IsDead(to->from)) |
865 |
|
return; |
866 |
|
|
867 |
< |
if (MyClient(to)) |
868 |
< |
{ |
869 |
< |
if (IsServer(from)) |
870 |
< |
{ |
871 |
< |
if (IsCapable(to, CAP_TS6) && HasID(from)) |
872 |
< |
len = ircsprintf(buffer, ":%s ", from->id); |
873 |
< |
else |
874 |
< |
len = ircsprintf(buffer, ":%s ", from->name); |
955 |
< |
} |
956 |
< |
else |
957 |
< |
len = ircsprintf(buffer, ":%s!%s@%s ", |
958 |
< |
from->name, from->username, from->host); |
959 |
< |
} |
960 |
< |
else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to)); |
867 |
> |
buffer = dbuf_alloc(); |
868 |
> |
|
869 |
> |
if (MyClient(to) && IsClient(from)) |
870 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username, |
871 |
> |
from->host, command, to->name); |
872 |
> |
else |
873 |
> |
dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to), |
874 |
> |
command, ID_or_name(to, to)); |
875 |
|
|
876 |
|
va_start(args, pattern); |
877 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
877 |
> |
send_format(buffer, pattern, args); |
878 |
|
va_end(args); |
879 |
|
|
880 |
< |
if(MyClient(to)) |
881 |
< |
send_message(send_to, buffer, len); |
880 |
> |
if (MyClient(to)) |
881 |
> |
send_message(to, buffer); |
882 |
|
else |
883 |
< |
send_message_remote(send_to, from, buffer, len); |
883 |
> |
send_message_remote(to, from, buffer); |
884 |
> |
|
885 |
> |
dbuf_ref_free(buffer); |
886 |
|
} |
887 |
|
|
888 |
|
/* sendto_realops_flags() |
894 |
|
* side effects - Send to *local* ops only but NOT +s nonopers. |
895 |
|
*/ |
896 |
|
void |
897 |
< |
sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...) |
897 |
> |
sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...) |
898 |
|
{ |
899 |
< |
struct Client *client_p; |
900 |
< |
char nbuf[IRCD_BUFSIZE]; |
901 |
< |
dlink_node *ptr; |
899 |
> |
const char *ntype = NULL; |
900 |
> |
dlink_node *ptr = NULL; |
901 |
> |
char nbuf[IRCD_BUFSIZE] = ""; |
902 |
|
va_list args; |
903 |
|
|
904 |
|
va_start(args, pattern); |
905 |
< |
vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args); |
905 |
> |
vsnprintf(nbuf, sizeof(nbuf), pattern, args); |
906 |
|
va_end(args); |
907 |
|
|
908 |
< |
DLINK_FOREACH(ptr, oper_list.head) |
908 |
> |
switch (type) |
909 |
|
{ |
910 |
< |
client_p = ptr->data; |
911 |
< |
assert(client_p->umodes & UMODE_OPER); |
912 |
< |
|
913 |
< |
/* If we're sending it to opers and theyre an admin, skip. |
914 |
< |
* If we're sending it to admins, and theyre not, skip. |
915 |
< |
*/ |
916 |
< |
if (((level == L_ADMIN) && !IsAdmin(client_p)) || |
917 |
< |
((level == L_OPER) && IsAdmin(client_p))) |
918 |
< |
continue; |
919 |
< |
|
920 |
< |
if (client_p->umodes & flags) |
1005 |
< |
sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s", |
1006 |
< |
me.name, client_p->name, nbuf); |
910 |
> |
case SEND_NOTICE: |
911 |
> |
ntype = "Notice"; |
912 |
> |
break; |
913 |
> |
case SEND_GLOBAL: |
914 |
> |
ntype = "Global"; |
915 |
> |
break; |
916 |
> |
case SEND_LOCOPS: |
917 |
> |
ntype = "LocOps"; |
918 |
> |
break; |
919 |
> |
default: |
920 |
> |
assert(0); |
921 |
|
} |
1008 |
– |
} |
1009 |
– |
|
1010 |
– |
/* sendto_wallops_flags() |
1011 |
– |
* |
1012 |
– |
* inputs - flag types of messages to show to real opers |
1013 |
– |
* - client sending request |
1014 |
– |
* - var args input message |
1015 |
– |
* output - NONE |
1016 |
– |
* side effects - Send a wallops to local opers |
1017 |
– |
*/ |
1018 |
– |
void |
1019 |
– |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
1020 |
– |
const char *pattern, ...) |
1021 |
– |
{ |
1022 |
– |
struct Client *client_p; |
1023 |
– |
dlink_node *ptr; |
1024 |
– |
va_list args; |
1025 |
– |
char buffer[IRCD_BUFSIZE]; |
1026 |
– |
int len; |
1027 |
– |
|
1028 |
– |
if (IsClient(source_p)) |
1029 |
– |
len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :", |
1030 |
– |
source_p->name, source_p->username, source_p->host); |
1031 |
– |
else |
1032 |
– |
len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name); |
1033 |
– |
|
1034 |
– |
va_start(args, pattern); |
1035 |
– |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
1036 |
– |
va_end(args); |
922 |
|
|
923 |
|
DLINK_FOREACH(ptr, oper_list.head) |
924 |
|
{ |
925 |
< |
client_p = ptr->data; |
926 |
< |
assert(client_p->umodes & UMODE_OPER); |
925 |
> |
struct Client *client_p = ptr->data; |
926 |
> |
assert(HasUMode(client_p, UMODE_OPER)); |
927 |
|
|
928 |
< |
if ((client_p->umodes & flags) && !IsDefunct(client_p)) |
929 |
< |
send_message(client_p, buffer, len); |
928 |
> |
/* |
929 |
> |
* If we're sending it to opers and they're an admin, skip. |
930 |
> |
* If we're sending it to admins, and they're not, skip. |
931 |
> |
*/ |
932 |
> |
if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) || |
933 |
> |
((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN))) |
934 |
> |
continue; |
935 |
> |
|
936 |
> |
if (HasUMode(client_p, flags)) |
937 |
> |
sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s", |
938 |
> |
me.name, client_p->name, ntype, nbuf); |
939 |
|
} |
940 |
|
} |
941 |
|
|
942 |
|
/* ts_warn() |
943 |
|
* |
944 |
< |
* inputs - var args message |
945 |
< |
* output - NONE |
946 |
< |
* side effects - Call sendto_realops_flags, with some flood checking |
947 |
< |
* (at most 5 warnings every 5 seconds) |
944 |
> |
* inputs - var args message |
945 |
> |
* output - NONE |
946 |
> |
* side effects - Call sendto_realops_flags, with some flood checking |
947 |
> |
* (at most 5 warnings every 5 seconds) |
948 |
|
*/ |
949 |
|
void |
950 |
< |
ts_warn(const char *pattern, ...) |
950 |
> |
sendto_realops_flags_ratelimited(const char *pattern, ...) |
951 |
|
{ |
952 |
|
va_list args; |
953 |
< |
char buffer[LOG_BUFSIZE]; |
953 |
> |
char buffer[IRCD_BUFSIZE] = ""; |
954 |
|
static time_t last = 0; |
955 |
|
static int warnings = 0; |
956 |
|
|
973 |
|
} |
974 |
|
|
975 |
|
va_start(args, pattern); |
976 |
< |
vsprintf_irc(buffer, pattern, args); |
976 |
> |
vsnprintf(buffer, sizeof(buffer), pattern, args); |
977 |
|
va_end(args); |
978 |
|
|
979 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer); |
980 |
< |
ilog(L_CRIT, "%s", buffer); |
979 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s", buffer); |
980 |
> |
ilog(LOG_TYPE_IRCD, "%s", buffer); |
981 |
|
} |
982 |
|
|
983 |
< |
/* kill_client() |
983 |
> |
/* sendto_wallops_flags() |
984 |
|
* |
985 |
< |
* inputs - client to send kill towards |
986 |
< |
* - pointer to client to kill |
987 |
< |
* - reason for kill |
988 |
< |
* output - NONE |
989 |
< |
* side effects - NONE |
985 |
> |
* inputs - flag types of messages to show to real opers |
986 |
> |
* - client sending request |
987 |
> |
* - var args input message |
988 |
> |
* output - NONE |
989 |
> |
* side effects - Send a wallops to local opers |
990 |
|
*/ |
991 |
|
void |
992 |
< |
kill_client(struct Client *client_p, struct Client *diedie, |
993 |
< |
const char *pattern, ...) |
992 |
> |
sendto_wallops_flags(unsigned int flags, struct Client *source_p, |
993 |
> |
const char *pattern, ...) |
994 |
|
{ |
995 |
+ |
dlink_node *ptr = NULL; |
996 |
|
va_list args; |
997 |
< |
char buffer[IRCD_BUFSIZE]; |
1103 |
< |
int len; |
997 |
> |
struct dbuf_block *buffer; |
998 |
|
|
999 |
< |
if (client_p->from != NULL) |
1106 |
< |
client_p = client_p->from; |
1107 |
< |
if (IsDead(client_p)) |
1108 |
< |
return; |
1109 |
< |
|
1110 |
< |
len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from), |
1111 |
< |
ID_or_name(diedie, client_p)); |
1112 |
< |
|
1113 |
< |
va_start(args, pattern); |
1114 |
< |
len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args); |
1115 |
< |
va_end(args); |
1116 |
< |
|
1117 |
< |
send_message(client_p, buffer, len); |
1118 |
< |
} |
1119 |
< |
|
1120 |
< |
/* kill_client_ll_serv_butone() |
1121 |
< |
* |
1122 |
< |
* inputs - pointer to client to not send to |
1123 |
< |
* - pointer to client to kill |
1124 |
< |
* output - NONE |
1125 |
< |
* side effects - Send a KILL for the given client |
1126 |
< |
* message to all connected servers |
1127 |
< |
* except the client 'one'. Also deal with |
1128 |
< |
* client being unknown to leaf, as in lazylink... |
1129 |
< |
*/ |
1130 |
< |
void |
1131 |
< |
kill_client_ll_serv_butone(struct Client *one, struct Client *source_p, |
1132 |
< |
const char *pattern, ...) |
1133 |
< |
{ |
1134 |
< |
va_list args; |
1135 |
< |
int have_uid = 0; |
1136 |
< |
dlink_node *ptr = NULL; |
1137 |
< |
char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE]; |
1138 |
< |
int len_uid = 0, len_nick = 0; |
999 |
> |
buffer = dbuf_alloc(); |
1000 |
|
|
1001 |
< |
if (HasID(source_p) && (me.id[0] != '\0')) |
1002 |
< |
{ |
1003 |
< |
have_uid = 1; |
1004 |
< |
va_start(args, pattern); |
1144 |
< |
len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p)); |
1145 |
< |
len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern, |
1146 |
< |
args); |
1147 |
< |
va_end(args); |
1148 |
< |
} |
1001 |
> |
if (IsClient(source_p)) |
1002 |
> |
dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host); |
1003 |
> |
else |
1004 |
> |
dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name); |
1005 |
|
|
1006 |
|
va_start(args, pattern); |
1007 |
< |
len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name); |
1152 |
< |
len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern, |
1153 |
< |
args); |
1007 |
> |
send_format(buffer, pattern, args); |
1008 |
|
va_end(args); |
1009 |
|
|
1010 |
< |
DLINK_FOREACH(ptr, serv_list.head) |
1010 |
> |
DLINK_FOREACH(ptr, oper_list.head) |
1011 |
|
{ |
1012 |
|
struct Client *client_p = ptr->data; |
1013 |
+ |
assert(client_p->umodes & UMODE_OPER); |
1014 |
|
|
1015 |
< |
if (one != NULL && (client_p == one->from)) |
1016 |
< |
continue; |
1162 |
< |
if (IsDefunct(client_p)) |
1163 |
< |
continue; |
1164 |
< |
|
1165 |
< |
if (have_uid && IsCapable(client_p, CAP_TS6)) |
1166 |
< |
send_message(client_p, buf_uid, len_uid); |
1167 |
< |
else |
1168 |
< |
send_message(client_p, buf_nick, len_nick); |
1015 |
> |
if (HasUMode(client_p, flags) && !IsDefunct(client_p)) |
1016 |
> |
send_message(client_p, buffer); |
1017 |
|
} |
1018 |
< |
} |
1018 |
> |
|
1019 |
> |
dbuf_ref_free(buffer); |
1020 |
> |
} |