36 |
|
#include "send.h" |
37 |
|
#include "conf.h" |
38 |
|
#include "memory.h" |
39 |
< |
#include "s_user.h" |
40 |
< |
#include "s_serv.h" |
39 |
> |
#include "user.h" |
40 |
> |
#include "server.h" |
41 |
|
|
42 |
|
|
43 |
|
/* |
104 |
|
|
105 |
|
static int cancel_clients(struct Client *, struct Client *, char *); |
106 |
|
static void remove_unknown(struct Client *, char *, char *); |
107 |
< |
static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]); |
108 |
< |
static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]); |
107 |
> |
static void handle_numeric(unsigned int, struct Client *, int, char *[]); |
108 |
> |
static void handle_command(struct Message *, struct Client *, unsigned int, char *[]); |
109 |
|
|
110 |
|
|
111 |
|
/* |
120 |
|
struct Message *msg_ptr = NULL; |
121 |
|
char *ch = NULL; |
122 |
|
char *s = NULL; |
123 |
< |
char *numeric = NULL; |
123 |
> |
unsigned int numeric = 0; |
124 |
|
unsigned int parc = 0; |
125 |
|
unsigned int paramcount; |
126 |
|
|
141 |
|
*/ |
142 |
|
char *sender = ++ch; |
143 |
|
|
144 |
< |
if ((s = strchr(ch, ' ')) != NULL) |
144 |
> |
if ((s = strchr(ch, ' '))) |
145 |
|
{ |
146 |
|
*s = '\0'; |
147 |
|
ch = ++s; |
194 |
|
if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */ |
195 |
|
IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2))) |
196 |
|
{ |
197 |
< |
numeric = ch; |
197 |
> |
numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0'); |
198 |
|
paramcount = 2; /* destination, and the rest of it */ |
199 |
|
++ServerStats.is_num; |
200 |
|
s = ch + 3; /* I know this is ' ' from above if */ |
204 |
|
{ |
205 |
|
unsigned int ii = 0; |
206 |
|
|
207 |
< |
if ((s = strchr(ch, ' ')) != NULL) |
207 |
> |
if ((s = strchr(ch, ' '))) |
208 |
|
*s++ = '\0'; |
209 |
|
|
210 |
|
if ((msg_ptr = find_command(ch)) == NULL) |
220 |
|
* Hm, when is the buffer empty -- if a command |
221 |
|
* code has been found ?? -Armin |
222 |
|
*/ |
223 |
< |
if (*pbuffer != '\0') |
224 |
< |
{ |
223 |
> |
if (*pbuffer) |
224 |
|
if (IsClient(from)) |
225 |
|
sendto_one_numeric(from, &me, ERR_UNKNOWNCOMMAND, ch); |
227 |
– |
} |
226 |
|
|
227 |
|
++ServerStats.is_unco; |
228 |
|
return; |
229 |
|
} |
230 |
|
|
231 |
< |
assert(msg_ptr->cmd != NULL); |
231 |
> |
assert(msg_ptr->cmd); |
232 |
|
|
233 |
|
paramcount = msg_ptr->args_max; |
234 |
|
ii = bufend - ((s) ? s : ch); |
242 |
|
* this last parameter (about same effect as ":" has...) --msa |
243 |
|
*/ |
244 |
|
|
245 |
< |
/* Note initially true: s==NULL || *(s-1) == '\0' !! */ |
245 |
> |
/* Note initially true: s == NULL || *(s - 1) == '\0' !! */ |
246 |
|
|
247 |
|
para[parc] = ch; |
248 |
|
|
262 |
|
if (*s == ':') |
263 |
|
{ |
264 |
|
/* The rest is a single parameter */ |
265 |
< |
para[++parc] = s + (!numeric); /* keep the colon if it's a numeric */ |
265 |
> |
para[++parc] = s + (!numeric); /* Keep the colon if it's a numeric */ |
266 |
|
break; |
267 |
|
} |
268 |
|
|
278 |
|
|
279 |
|
para[++parc] = NULL; |
280 |
|
|
281 |
< |
if (msg_ptr != NULL) |
282 |
< |
handle_command(msg_ptr, client_p, from, parc, para); |
281 |
> |
if (msg_ptr) |
282 |
> |
handle_command(msg_ptr, from, parc, para); |
283 |
|
else |
284 |
< |
handle_numeric(numeric, client_p, from, parc, para); |
284 |
> |
handle_numeric(numeric, from, parc, para); |
285 |
|
} |
286 |
|
|
287 |
|
/* handle_command() |
295 |
|
* side effects - |
296 |
|
*/ |
297 |
|
static void |
298 |
< |
handle_command(struct Message *mptr, struct Client *client_p, |
299 |
< |
struct Client *from, unsigned int i, char *hpara[]) |
298 |
> |
handle_command(struct Message *mptr, struct Client *source_p, |
299 |
> |
unsigned int i, char *hpara[]) |
300 |
|
{ |
301 |
< |
MessageHandler handler = 0; |
302 |
< |
|
305 |
< |
if (IsServer(client_p)) |
306 |
< |
mptr->rcount++; |
307 |
< |
|
308 |
< |
mptr->count++; |
301 |
> |
if (IsServer(source_p->from)) |
302 |
> |
++mptr->rcount; |
303 |
|
|
304 |
< |
handler = mptr->handlers[client_p->handler]; |
304 |
> |
++mptr->count; |
305 |
|
|
306 |
< |
/* check right amount of params is passed... --is */ |
306 |
> |
/* Check right amount of params is passed... --is */ |
307 |
|
if (i < mptr->args_min) |
308 |
< |
{ |
315 |
< |
if (!IsServer(client_p)) |
316 |
< |
{ |
317 |
< |
sendto_one_numeric(client_p, &me, ERR_NEEDMOREPARAMS, mptr->cmd); |
318 |
< |
} |
319 |
< |
else |
320 |
< |
{ |
321 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
322 |
< |
"Dropping server %s due to (invalid) command '%s' " |
323 |
< |
"with only %d arguments (expecting %d).", |
324 |
< |
client_p->name, mptr->cmd, i, mptr->args_min); |
325 |
< |
ilog(LOG_TYPE_IRCD, "Insufficient parameters (%d) for command '%s' from %s.", |
326 |
< |
i, mptr->cmd, client_p->name); |
327 |
< |
exit_client(client_p, client_p, |
328 |
< |
"Not enough arguments to server command."); |
329 |
< |
} |
330 |
< |
} |
308 |
> |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, mptr->cmd); |
309 |
|
else |
310 |
< |
(*handler)(client_p, from, i, hpara); |
310 |
> |
mptr->handlers[source_p->from->handler](source_p, i, hpara); |
311 |
|
} |
312 |
|
|
313 |
|
/* add_msg_element() |
334 |
|
add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p, |
335 |
|
const char *cmd) |
336 |
|
{ |
337 |
< |
struct MessageTree *ntree_p; |
337 |
> |
struct MessageTree *ntree_p = NULL; |
338 |
|
|
339 |
|
if (*cmd == '\0') |
340 |
|
{ |
351 |
|
*/ |
352 |
|
if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL) |
353 |
|
{ |
354 |
< |
ntree_p = MyMalloc(sizeof(struct MessageTree)); |
354 |
> |
ntree_p = MyCalloc(sizeof(struct MessageTree)); |
355 |
|
mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = ntree_p; |
356 |
|
|
357 |
|
mtree_p->links++; /* Have new pointer, so up ref count */ |
387 |
|
static void |
388 |
|
del_msg_element(struct MessageTree *mtree_p, const char *cmd) |
389 |
|
{ |
390 |
< |
struct MessageTree *ntree_p; |
390 |
> |
struct MessageTree *ntree_p = NULL; |
391 |
|
|
392 |
|
/* |
393 |
|
* In case this is called for a nonexistent command |
394 |
|
* check that there is a msg pointer here, else links-- goes -ve |
395 |
|
* -db |
396 |
|
*/ |
397 |
< |
if ((*cmd == '\0') && (mtree_p->msg != NULL)) |
397 |
> |
if (*cmd == '\0' && mtree_p->msg) |
398 |
|
{ |
399 |
|
mtree_p->msg = NULL; |
400 |
|
mtree_p->links--; |
401 |
|
} |
402 |
|
else |
403 |
|
{ |
404 |
< |
if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) != NULL) |
404 |
> |
if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)])) |
405 |
|
{ |
406 |
|
del_msg_element(ntree_p, cmd + 1); |
407 |
|
|
426 |
|
msg_tree_parse(const char *cmd) |
427 |
|
{ |
428 |
|
struct MessageTree *mtree = &msg_tree; |
429 |
+ |
|
430 |
|
assert(cmd && *cmd); |
431 |
|
|
432 |
|
while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)])) |
449 |
|
{ |
450 |
|
assert(msg && msg->cmd); |
451 |
|
|
452 |
< |
/* command already added? */ |
452 |
> |
/* Command already added? */ |
453 |
|
if (msg_tree_parse(msg->cmd)) |
454 |
|
return; |
455 |
|
|
468 |
|
{ |
469 |
|
assert(msg && msg->cmd); |
470 |
|
|
471 |
+ |
if (!msg_tree_parse(msg->cmd)) |
472 |
+ |
return; |
473 |
+ |
|
474 |
|
del_msg_element(&msg_tree, msg->cmd); |
475 |
|
} |
476 |
|
|
489 |
|
static void |
490 |
|
recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree) |
491 |
|
{ |
492 |
< |
unsigned int i; |
511 |
< |
|
512 |
< |
if (mtree->msg != NULL) |
492 |
> |
if (mtree->msg) |
493 |
|
sendto_one_numeric(source_p, &me, RPL_STATSCOMMANDS, |
494 |
|
mtree->msg->cmd, |
495 |
|
mtree->msg->count, mtree->msg->bytes, |
496 |
|
mtree->msg->rcount); |
497 |
|
|
498 |
< |
for (i = 0; i < MAXPTRLEN; ++i) |
499 |
< |
if (mtree->pointers[i] != NULL) |
498 |
> |
for (unsigned int i = 0; i < MAXPTRLEN; ++i) |
499 |
> |
if (mtree->pointers[i]) |
500 |
|
recurse_report_messages(source_p, mtree->pointers[i]); |
501 |
|
} |
502 |
|
|
510 |
|
report_messages(struct Client *source_p) |
511 |
|
{ |
512 |
|
const struct MessageTree *mtree = &msg_tree; |
533 |
– |
unsigned int i; |
513 |
|
|
514 |
< |
for (i = 0; i < MAXPTRLEN; ++i) |
515 |
< |
if (mtree->pointers[i] != NULL) |
514 |
> |
for (unsigned int i = 0; i < MAXPTRLEN; ++i) |
515 |
> |
if (mtree->pointers[i]) |
516 |
|
recurse_report_messages(source_p, mtree->pointers[i]); |
517 |
|
} |
518 |
|
|
584 |
|
"Message for %s[%s@%s!%s] from %s (TS, ignored)", |
585 |
|
source_p->name, source_p->username, source_p->host, |
586 |
|
source_p->from->name, get_client_name(client_p, MASK_IP)); |
608 |
– |
|
587 |
|
return 0; |
588 |
|
} |
589 |
|
|
606 |
|
* 'nodots' is a nickname (KILL) |
607 |
|
* 'no.dot.at.start' is a server (SQUIT) |
608 |
|
*/ |
609 |
< |
if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) || |
632 |
< |
strchr(lsender, '.') != NULL) |
609 |
> |
if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) || strchr(lsender, '.')) |
610 |
|
{ |
611 |
|
sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE, |
612 |
|
"Unknown prefix (%s) from %s, Squitting %s", |
615 |
|
"Unknown prefix (%s) from %s, Squitting %s", |
616 |
|
lbuffer, client_p->name, lsender); |
617 |
|
sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)", |
618 |
< |
me.name, lsender, lbuffer, client_p->name); |
618 |
> |
me.id, lsender, lbuffer, client_p->name); |
619 |
|
} |
620 |
|
else |
621 |
|
sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", |
622 |
< |
me.name, lsender, me.name); |
622 |
> |
me.id, lsender, me.name); |
623 |
|
} |
624 |
|
|
625 |
|
/* |
644 |
|
* the savvy approach is NEVER generate an error in response to an... error :) |
645 |
|
*/ |
646 |
|
static void |
647 |
< |
handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p, |
671 |
< |
int parc, char *parv[]) |
647 |
> |
handle_numeric(unsigned int numeric, struct Client *source_p, int parc, char *parv[]) |
648 |
|
{ |
649 |
|
struct Client *target_p = NULL; |
650 |
|
struct Channel *chptr = NULL; |
665 |
|
if (IsChanPrefix(*parv[1])) |
666 |
|
chptr = hash_find_channel(parv[1]); |
667 |
|
else |
668 |
< |
target_p = find_person(client_p, parv[1]); |
668 |
> |
target_p = find_person(source_p, parv[1]); |
669 |
|
|
670 |
< |
if (((!target_p) || (target_p->from == client_p)) && !chptr) |
670 |
> |
if (((!target_p) || (target_p->from == source_p->from)) && !chptr) |
671 |
|
return; |
672 |
|
|
673 |
|
/* |
679 |
|
* remotely - but the information they contain may be useful, so we |
680 |
|
* remap them up. Weird, but true. -- Isomer |
681 |
|
*/ |
682 |
< |
if (numeric[0] == '0') |
683 |
< |
numeric[0] = '1'; |
682 |
> |
if (numeric < 100) |
683 |
> |
numeric += 100; |
684 |
|
|
685 |
|
if (target_p) |
686 |
|
{ |
687 |
|
/* Fake it for server hiding, if its our client */ |
688 |
|
if (ConfigServerHide.hide_servers && MyClient(target_p) && |
689 |
|
!HasUMode(target_p, UMODE_OPER)) |
690 |
< |
sendto_one(target_p, ":%s %s %s %s", me.name, numeric, target_p->name, parv[2]); |
690 |
> |
sendto_one_numeric(target_p, &me, numeric|SND_EXPLICIT, "%s", parv[2]); |
691 |
|
else |
692 |
< |
sendto_one(target_p, ":%s %s %s %s", ID_or_name(source_p, target_p), |
717 |
< |
numeric, ID_or_name(target_p, target_p), parv[2]); |
692 |
> |
sendto_one_numeric(target_p, source_p, numeric|SND_EXPLICIT, "%s", parv[2]); |
693 |
|
} |
694 |
|
else |
695 |
< |
sendto_channel_butone(client_p, source_p, chptr, 0, "%s %s %s", |
695 |
> |
sendto_channel_butone(source_p, source_p, chptr, 0, "%u %s %s", |
696 |
|
numeric, chptr->chname, parv[2]); |
697 |
|
} |
698 |
|
|
702 |
|
* side effects - just returns a nastyogram to given user |
703 |
|
*/ |
704 |
|
int |
705 |
< |
m_not_oper(struct Client *client_p, struct Client *source_p, |
731 |
< |
int parc, char *parv[]) |
705 |
> |
m_not_oper(struct Client *source_p, int parc, char *parv[]) |
706 |
|
{ |
707 |
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
708 |
|
return 0; |
709 |
|
} |
710 |
|
|
711 |
|
int |
712 |
< |
m_unregistered(struct Client *client_p, struct Client *source_p, |
739 |
< |
int parc, char *parv[]) |
712 |
> |
m_unregistered(struct Client *source_p, int parc, char *parv[]) |
713 |
|
{ |
714 |
|
sendto_one_numeric(source_p, &me, ERR_NOTREGISTERED); |
715 |
|
return 0; |
716 |
|
} |
717 |
|
|
718 |
|
int |
719 |
< |
m_registered(struct Client *client_p, struct Client *source_p, |
747 |
< |
int parc, char *parv[]) |
719 |
> |
m_registered(struct Client *source_p, int parc, char *parv[]) |
720 |
|
{ |
721 |
|
sendto_one_numeric(source_p, &me, ERR_ALREADYREGISTRED); |
722 |
|
return 0; |
723 |
|
} |
724 |
|
|
725 |
|
int |
726 |
< |
m_ignore(struct Client *client_p, struct Client *source_p, |
755 |
< |
int parc, char *parv[]) |
726 |
> |
m_ignore(struct Client *source_p, int parc, char *parv[]) |
727 |
|
{ |
728 |
|
return 0; |
729 |
|
} |