31 |
|
#include "sprintf_irc.h" |
32 |
|
#include "ircd.h" |
33 |
|
#include "numeric.h" |
34 |
< |
#include "s_log.h" |
34 |
> |
#include "log.h" |
35 |
|
#include "send.h" |
36 |
< |
#include "s_conf.h" |
36 |
> |
#include "conf.h" |
37 |
|
#include "memory.h" |
38 |
|
#include "s_user.h" |
39 |
|
#include "s_serv.h" |
102 |
|
* NOTE: parse() should not be called recursively by other functions! |
103 |
|
*/ |
104 |
|
static char *sender; |
105 |
< |
static char *para[MAXPARA + 1]; |
105 |
> |
static char *para[MAXPARA + 2]; /* <prefix> + <params> + NULL */ |
106 |
|
static char buffer[1024]; |
107 |
|
|
108 |
|
static int cancel_clients(struct Client *, struct Client *, char *); |
109 |
|
static void remove_unknown(struct Client *, char *, char *); |
110 |
|
static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]); |
111 |
|
static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]); |
112 |
– |
static void recurse_report_messages(struct Client *, const struct MessageTree *); |
113 |
– |
static void add_msg_element(struct MessageTree *, struct Message *, const char *); |
114 |
– |
static void del_msg_element(struct MessageTree *, const char *); |
112 |
|
|
113 |
|
|
114 |
|
/* |
121 |
|
{ |
122 |
|
struct Client *from = client_p; |
123 |
|
struct Message *msg_ptr = NULL; |
124 |
< |
char *ch; |
125 |
< |
char *s; |
126 |
< |
char *numeric = 0; |
124 |
> |
char *ch = NULL; |
125 |
> |
char *s = NULL; |
126 |
> |
char *numeric = NULL; |
127 |
|
unsigned int parc = 0; |
128 |
|
unsigned int paramcount; |
132 |
– |
int mpara = 0; |
129 |
|
|
130 |
|
if (IsDefunct(client_p)) |
131 |
|
return; |
133 |
|
assert(client_p->localClient->fd.flags.open); |
134 |
|
assert((bufend - pbuffer) < 512); |
135 |
|
|
136 |
< |
for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */ |
136 |
> |
for (ch = pbuffer; *ch == ' '; ++ch) /* skip spaces */ |
137 |
|
/* null statement */ ; |
138 |
|
|
139 |
|
if (*ch == ':') |
152 |
|
|
153 |
|
if (*sender && IsServer(client_p)) |
154 |
|
{ |
159 |
– |
/* |
160 |
– |
* XXX it could be useful to know which of these occurs most frequently. |
161 |
– |
* the ID check should always come first, though, since it is so easy. |
162 |
– |
*/ |
155 |
|
if ((from = find_person(client_p, sender)) == NULL) |
156 |
|
from = hash_find_server(sender); |
157 |
|
|
222 |
|
* Hm, when is the buffer empty -- if a command |
223 |
|
* code has been found ?? -Armin |
224 |
|
*/ |
225 |
< |
if (pbuffer[0] != '\0') |
225 |
> |
if (*pbuffer != '\0') |
226 |
|
{ |
227 |
|
if (IsClient(from)) |
228 |
|
sendto_one(from, form_str(ERR_UNKNOWNCOMMAND), |
236 |
|
assert(msg_ptr->cmd != NULL); |
237 |
|
|
238 |
|
paramcount = msg_ptr->args_max; |
247 |
– |
mpara = msg_ptr->args_min; |
248 |
– |
|
239 |
|
ii = bufend - ((s) ? s : ch); |
240 |
|
msg_ptr->bytes += ii; |
241 |
|
} |
301 |
|
*/ |
302 |
|
static void |
303 |
|
handle_command(struct Message *mptr, struct Client *client_p, |
304 |
< |
struct Client *from, unsigned int i, char *hpara[MAXPARA]) |
304 |
> |
struct Client *from, unsigned int i, char *hpara[]) |
305 |
|
{ |
306 |
|
MessageHandler handler = 0; |
307 |
|
|
310 |
|
|
311 |
|
mptr->count++; |
312 |
|
|
323 |
– |
/* New patch to avoid server flooding from unregistered connects |
324 |
– |
* - Pie-Man 07/27/2000 */ |
325 |
– |
if (!IsRegistered(client_p)) |
326 |
– |
{ |
327 |
– |
/* if its from a possible server connection |
328 |
– |
* ignore it.. more than likely its a header thats sneaked through |
329 |
– |
*/ |
330 |
– |
if ((IsHandshake(client_p) || IsConnecting(client_p) || |
331 |
– |
IsServer(client_p)) && !(mptr->flags & MFLG_UNREG)) |
332 |
– |
return; |
333 |
– |
} |
334 |
– |
|
313 |
|
handler = mptr->handlers[client_p->handler]; |
314 |
|
|
315 |
|
/* check right amount of params is passed... --is */ |
326 |
|
"Dropping server %s due to (invalid) command '%s' " |
327 |
|
"with only %d arguments (expecting %d).", |
328 |
|
client_p->name, mptr->cmd, i, mptr->args_min); |
329 |
< |
ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.", |
329 |
> |
ilog(LOG_TYPE_IRCD, "Insufficient parameters (%d) for command '%s' from %s.", |
330 |
|
i, mptr->cmd, client_p->name); |
331 |
|
exit_client(client_p, client_p, |
332 |
|
"Not enough arguments to server command."); |
336 |
|
(*handler)(client_p, from, i, hpara); |
337 |
|
} |
338 |
|
|
361 |
– |
/* clear_tree_parse() |
362 |
– |
* |
363 |
– |
* inputs - NONE |
364 |
– |
* output - NONE |
365 |
– |
* side effects - MUST MUST be called at startup ONCE before |
366 |
– |
* any other keyword routine is used. |
367 |
– |
*/ |
368 |
– |
void |
369 |
– |
clear_tree_parse(void) |
370 |
– |
{ |
371 |
– |
memset(&msg_tree, 0, sizeof(msg_tree)); |
372 |
– |
} |
373 |
– |
|
339 |
|
/* add_msg_element() |
340 |
|
* |
341 |
|
* inputs - pointer to MessageTree |
415 |
|
{ |
416 |
|
struct MessageTree *ntree_p; |
417 |
|
|
418 |
< |
/* In case this is called for a nonexistent command |
418 |
> |
/* |
419 |
> |
* In case this is called for a nonexistent command |
420 |
|
* check that there is a msg pointer here, else links-- goes -ve |
421 |
|
* -db |
422 |
|
*/ |
457 |
– |
|
423 |
|
if ((*cmd == '\0') && (mtree_p->msg != NULL)) |
424 |
|
{ |
425 |
|
mtree_p->msg = NULL; |
449 |
|
* side effects - none |
450 |
|
*/ |
451 |
|
static struct Message * |
452 |
< |
msg_tree_parse(const char *cmd, struct MessageTree *root) |
452 |
> |
msg_tree_parse(const char *cmd) |
453 |
|
{ |
454 |
< |
struct MessageTree *mtree = root; |
454 |
> |
struct MessageTree *mtree = &msg_tree; |
455 |
|
assert(cmd && *cmd); |
456 |
|
|
457 |
|
while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)])) |
472 |
|
void |
473 |
|
mod_add_cmd(struct Message *msg) |
474 |
|
{ |
475 |
< |
struct Message *found_msg; |
511 |
< |
|
512 |
< |
if (msg == NULL) |
513 |
< |
return; |
514 |
< |
|
515 |
< |
/* someone loaded a module with a bad messagetab */ |
516 |
< |
assert(msg->cmd != NULL); |
475 |
> |
assert(msg && msg->cmd); |
476 |
|
|
477 |
|
/* command already added? */ |
478 |
< |
if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL) |
478 |
> |
if (msg_tree_parse(msg->cmd)) |
479 |
|
return; |
480 |
|
|
481 |
|
add_msg_element(&msg_tree, msg, msg->cmd); |
491 |
|
void |
492 |
|
mod_del_cmd(struct Message *msg) |
493 |
|
{ |
494 |
< |
assert(msg != NULL); |
536 |
< |
|
537 |
< |
if (msg == NULL) |
538 |
< |
return; |
494 |
> |
assert(msg && msg->cmd); |
495 |
|
|
496 |
|
del_msg_element(&msg_tree, msg->cmd); |
497 |
|
} |
505 |
|
struct Message * |
506 |
|
find_command(const char *cmd) |
507 |
|
{ |
508 |
< |
return msg_tree_parse(cmd, &msg_tree); |
508 |
> |
return msg_tree_parse(cmd); |
509 |
> |
} |
510 |
> |
|
511 |
> |
static void |
512 |
> |
recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree) |
513 |
> |
{ |
514 |
> |
unsigned int i; |
515 |
> |
|
516 |
> |
if (mtree->msg != NULL) |
517 |
> |
sendto_one(source_p, form_str(RPL_STATSCOMMANDS), |
518 |
> |
me.name, source_p->name, mtree->msg->cmd, |
519 |
> |
mtree->msg->count, mtree->msg->bytes, |
520 |
> |
mtree->msg->rcount); |
521 |
> |
|
522 |
> |
for (i = 0; i < MAXPTRLEN; ++i) |
523 |
> |
if (mtree->pointers[i] != NULL) |
524 |
> |
recurse_report_messages(source_p, mtree->pointers[i]); |
525 |
|
} |
526 |
|
|
527 |
|
/* report_messages() |
536 |
|
const struct MessageTree *mtree = &msg_tree; |
537 |
|
unsigned int i; |
538 |
|
|
539 |
< |
for (i = 0; i < MAXPTRLEN; i++) |
568 |
< |
if (mtree->pointers[i] != NULL) |
569 |
< |
recurse_report_messages(source_p, mtree->pointers[i]); |
570 |
< |
} |
571 |
< |
|
572 |
< |
static void |
573 |
< |
recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree) |
574 |
< |
{ |
575 |
< |
unsigned int i; |
576 |
< |
|
577 |
< |
if (mtree->msg != NULL) |
578 |
< |
sendto_one(source_p, form_str(RPL_STATSCOMMANDS), |
579 |
< |
me.name, source_p->name, mtree->msg->cmd, |
580 |
< |
mtree->msg->count, mtree->msg->bytes, |
581 |
< |
mtree->msg->rcount); |
582 |
< |
|
583 |
< |
for (i = 0; i < MAXPTRLEN; i++) |
539 |
> |
for (i = 0; i < MAXPTRLEN; ++i) |
540 |
|
if (mtree->pointers[i] != NULL) |
541 |
|
recurse_report_messages(source_p, mtree->pointers[i]); |
542 |
|
} |
682 |
|
t += tl; |
683 |
|
} |
684 |
|
|
685 |
< |
ircsprintf(t," :%s", parv[parc-1]); |
685 |
> |
ircsprintf(t, " :%s", parv[parc-1]); |
686 |
|
|
687 |
|
if (((target_p = find_person(client_p, parv[1])) != NULL) || |
688 |
|
((target_p = hash_find_server(parv[1])) != NULL)) |
793 |
|
|
794 |
|
in_para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; |
795 |
|
|
796 |
< |
ilog(L_ERROR, "Received ERROR message from %s: %s", |
796 |
> |
ilog(LOG_TYPE_IRCD, "Received ERROR message from %s: %s", |
797 |
|
source_p->name, in_para); |
798 |
|
|
799 |
|
if (client_p == source_p) |