X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fparse.c;h=b79ebb8ace48f6f52a9e50dce8812c4ddb2c82c2;hb=refs%2Fheads%2Fupstream;hp=9bd0513276abe01b2e9835ec7c09885bb0d59deb;hpb=9fe540badb1e92fc0a81ed9e0da738ed6b1cab0d;p=ircu2.10.12-pk.git diff --git a/ircd/parse.c b/ircd/parse.c index 9bd0513..b79ebb8 100644 --- a/ircd/parse.c +++ b/ircd/parse.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* @file +/** @file * @brief Parse input from IRC clients and other servers. * @version $Id$ */ @@ -32,6 +32,7 @@ #include "ircd_alloc.h" #include "ircd_chattr.h" #include "ircd_features.h" +#include "ircd_log.h" #include "ircd_reply.h" #include "ircd_string.h" #include "msg.h" @@ -52,7 +53,7 @@ #include "whocmds.h" #include "whowas.h" -#include +/* #include -- Now using assert in ircd_log.h */ #include #include @@ -101,6 +102,7 @@ struct MessageTree { /** Root of command lookup trie. */ static struct MessageTree msg_tree; +static struct MessageTree tok_tree; /** Array of all supported commands. */ struct Message msgtab[] = { @@ -340,7 +342,7 @@ struct Message msgtab[] = { TOK_NAMES, 0, MAXPARA, MFLG_SLOW, 0, NULL, /* UNREG, CLIENT, SERVER, OPER, SERVICE */ - { m_unregistered, m_names, ms_names, m_names, m_ignore } + { m_unregistered, m_names, m_names, m_names, m_ignore } }, { MSG_USERHOST, @@ -389,7 +391,7 @@ struct Message msgtab[] = { TOK_SETTIME, 0, MAXPARA, MFLG_SLOW, 0, NULL, /* UNREG, CLIENT, SERVER, OPER, SERVICE */ - { m_unregistered, m_ignore, ms_settime, mo_settime, m_ignore } + { m_unregistered, m_not_oper, ms_settime, mo_settime, m_ignore } }, { MSG_RPING, @@ -599,7 +601,7 @@ struct Message msgtab[] = { TOK_PRIVS, 0, MAXPARA, MFLG_SLOW, 0, NULL, /* UNREG, CLIENT, SERVER, OPER, SERVICE */ - { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore } + { m_unregistered, m_not_oper, ms_privs, mo_privs, m_ignore } }, { MSG_ACCOUNT, @@ -615,6 +617,29 @@ struct Message msgtab[] = { /* UNREG, CLIENT, SERVER, OPER, SERVICE */ { m_ignore, m_not_oper, ms_asll, mo_asll, m_ignore } }, + { + MSG_XQUERY, + TOK_XQUERY, + 0, MAXPARA, MFLG_SLOW, 0, NULL, + /* UNREG, CLIENT, SERVER, OPER, SERVICE */ + { m_ignore, m_ignore, ms_xquery, mo_xquery, m_ignore } + }, + { + MSG_XREPLY, + TOK_XREPLY, + 0, MAXPARA, MFLG_SLOW, 0, NULL, + /* UNREG, CLIENT, SERVER, OPER, SERVICE */ + { m_ignore, m_ignore, ms_xreply, m_ignore, m_ignore } + }, +#if WE_HAVE_A_REAL_CAPABILITY_NOW + { + MSG_CAP, + TOK_CAP, + 0, MAXPARA, 0, 0, NULL, + /* UNREG, CLIENT, SERVER, OPER, SERVICE */ + { m_cap, m_cap, m_ignore, m_cap, m_ignore } + }, +#endif /* This command is an alias for QUIT during the unregistered part of * of the server. This is because someone jumping via a broken web * proxy will send a 'POST' as their first command - which we will @@ -667,20 +692,28 @@ add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p, char *cmd) * @param[in,out] mtree_p Trie node to remove command from. * @param[in] cmd Text of command to remove. */ -void +struct MessageTree * del_msg_element(struct MessageTree *mtree_p, char *cmd) { - struct MessageTree *ntree_p; + int slot = *cmd & (MAXPTRLEN-1); + /* Either remove leaf message or from appropriate child. */ if (*cmd == '\0') - return; - - if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) != NULL) - { - del_msg_element(ntree_p, cmd+1); - MyFree(ntree_p); - mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = NULL; - } + mtree_p->msg = NULL; + else + mtree_p->pointers[slot] = del_msg_element(mtree_p->pointers[slot], cmd + 1); + + /* If current message or any child still exists, keep this node. */ + if (mtree_p->msg) + return mtree_p; + for (slot = 0; slot < MAXPTRLEN; ++slot) + if (mtree_p->pointers[slot]) + return mtree_p; + + /* Otherwise, if we're not a root node, free it and return null. */ + if (mtree_p != &msg_tree && mtree_p != &tok_tree) + MyFree(mtree_p); + return NULL; } /** Initialize the message lookup trie with all known commands. */ @@ -690,11 +723,12 @@ initmsgtree(void) int i; memset(&msg_tree, 0, sizeof(msg_tree)); + memset(&tok_tree, 0, sizeof(tok_tree)); for (i = 0; msgtab[i].cmd != NULL ; i++) { add_msg_element(&msg_tree, &msgtab[i], msgtab[i].cmd); - add_msg_element(&msg_tree, &msgtab[i], msgtab[i].tok); + add_msg_element(&tok_tree, &msgtab[i], msgtab[i].tok); } } @@ -733,18 +767,18 @@ int register_mapping(struct s_map *map) msg->tok = map->command; msg->count = 0; msg->parameters = 2; - msg->flags = MFLG_SLOW | MFLG_EXTRA; + msg->flags = MFLG_EXTRA; + if (!(map->flags & SMAP_FAST)) + msg->flags |= MFLG_SLOW; msg->bytes = 0; msg->extra = map; msg->handlers[UNREGISTERED_HANDLER] = m_ignore; msg->handlers[CLIENT_HANDLER] = m_pseudo; msg->handlers[SERVER_HANDLER] = m_ignore; - msg->handlers[OPER_HANDLER] = m_pseudo; + msg->handlers[OPER_HANDLER] = m_pseudo; msg->handlers[SERVICE_HANDLER] = m_ignore; - /* Service mappings are only applicable to clients; insert the - pseudocommand into the command tree only. */ add_msg_element(&msg_tree, msg, msg->cmd); map->msg = msg; @@ -774,7 +808,8 @@ int unregister_mapping(struct s_map *map) } /** Parse a line of data from a user. - * NOTE: parse_*() should not be called recusively by any other functions! + * NOTE: parse_*() should not be called recursively by any other + * functions! * @param[in] cptr Client that sent the data. * @param[in] buffer Start of input line. * @param[in] bufend End of input line. @@ -789,7 +824,6 @@ parse_client(struct Client *cptr, char *buffer, char *bufend) char* s; int i; int paramcount; - int noprefix = 0; struct Message* mptr; MessageHandler handler = 0; @@ -807,8 +841,6 @@ parse_client(struct Client *cptr, char *buffer, char *bufend) while (*ch == ' ') ch++; /* Advance to command */ } - else - noprefix = 1; if (*ch == '\0') { ServerStats->is_empt++; @@ -847,7 +879,7 @@ parse_client(struct Client *cptr, char *buffer, char *bufend) paramcount = mptr->parameters; i = bufend - ((s) ? s : ch); mptr->bytes += i; - if ((mptr->flags & MFLG_SLOW)) + if ((mptr->flags & MFLG_SLOW) || !IsAnOper(cptr)) cli_since(cptr) += (2 + i / 120); /* * Allow only 1 msg per 2 seconds @@ -963,7 +995,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend) /* * If the client corresponding to the * prefix is not found. We must ignore it, - * it is simply a lagged message travelling + * it is simply a lagged message traveling * upstream a SQUIT that removed the client * --Run */ @@ -1033,7 +1065,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend) /* * If the client corresponding to the * prefix is not found. We must ignore it, - * it is simply a lagged message travelling + * it is simply a lagged message traveling * upstream a SQUIT that removed the client * --Run * There turned out to be other reasons that @@ -1123,7 +1155,12 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend) * And for the record, this trie parser really does not care. - Dianora */ - mptr = msg_tree_parse(ch, &msg_tree); + mptr = msg_tree_parse(ch, &tok_tree); + + if (mptr == NULL) + { + mptr = msg_tree_parse(ch, &msg_tree); + } if (mptr == NULL) {