]> jfr.im git - solanum.git/blobdiff - ircd/parse.c
Add tests for valid_temp_time
[solanum.git] / ircd / parse.c
index e880d425d82484bc7b9ffb4beecdb92ffcd98bcf..bef6be15e37581d75344b74648a11f23ee27d312 100644 (file)
@@ -1,11 +1,11 @@
 /*
- *  charybdis: an advanced ircd.
+ *  Solanum: a slightly advanced ircd
  *  parse.c: The message parser.
  *
  *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
  *  Copyright (C) 1996-2002 Hybrid Development Team
  *  Copyright (C) 2002-2005 ircd-ratbox development team
- *  Copyright (C) 2007-2016 William Pitcock
+ *  Copyright (C) 2007-2016 Ariadne Conill <ariadne@dereferenced.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id: parse.c 3177 2007-02-01 00:19:14Z jilles $
  */
 
 #include "stdinc.h"
 #include "parse.h"
 #include "client.h"
 #include "channel.h"
-#include "common.h"
 #include "hash.h"
 #include "match.h"
 #include "ircd.h"
 #include "packet.h"
 #include "s_assert.h"
 
-static struct Dictionary *cmd_dict = NULL;
-struct Dictionary *alias_dict = NULL;
-
-/* parv[0] is not used, and parv[LAST] == NULL */
-static char *para[MAXPARA + 2];
+rb_dictionary *cmd_dict = NULL;
+rb_dictionary *alias_dict = NULL;
 
 static void cancel_clients(struct Client *, struct Client *);
-static void remove_unknown(struct Client *, char *, char *);
+static void remove_unknown(struct Client *, const char *, char *);
 
 static void do_numeric(int, struct Client *, struct Client *, int, const char **);
-static void do_alias(struct alias_entry *, struct Client *, char *);
 
-static int handle_command(struct Message *, struct Client *, struct Client *, int, const char**);
+static int handle_command(struct Message *, struct MsgBuf *, struct Client *, struct Client *);
 
 static char buffer[1024];
 
@@ -83,17 +76,15 @@ void
 parse(struct Client *client_p, char *pbuffer, char *bufend)
 {
        struct Client *from = client_p;
-       char *sender;
-       char *ch;
-       char *s;
        char *end;
-       int i = 1, res;
+       int res;
        int numeric = 0;
        struct Message *mptr;
        struct MsgBuf msgbuf;
 
-       s_assert(MyConnect(client_p));
-       s_assert(client_p->localClient->F != NULL);
+       s_assert(MyConnect(client_p) &&
+                       (client_p->localClient->F != NULL ||
+                               client_p->localClient->localflags & LFLAGS_FAKE));
        if(IsAnyDead(client_p))
                return;
 
@@ -112,7 +103,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
                return;
        }
 
-       if (msgbuf.origin != NULL)
+       if (msgbuf.origin != NULL && IsServer(client_p))
        {
                from = find_client(msgbuf.origin);
 
@@ -120,7 +111,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
                if(from == NULL)
                {
                        ServerStats.is_unpf++;
-                       remove_unknown(client_p, sender, pbuffer);
+                       remove_unknown(client_p, msgbuf.origin, pbuffer);
                        return;
                }
 
@@ -141,30 +132,19 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
        }
        else
        {
-               mptr = irc_dictionary_retrieve(cmd_dict, msgbuf.cmd);
+               mptr = rb_dictionary_retrieve(cmd_dict, msgbuf.cmd);
 
                /* no command or its encap only, error */
                if(!mptr || !mptr->cmd)
                {
-                       if (IsPerson(client_p))
-                       {
-                               struct alias_entry *aptr = irc_dictionary_retrieve(alias_dict, msgbuf.cmd);
-                               if (aptr != NULL)
-                               {
-                                       do_alias(aptr, client_p, reconstruct_parv(msgbuf.n_para - 1, msgbuf.para + 1));
-                                       return;
-                               }
-                       }
                        if(IsPerson(from))
                        {
                                sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
-                                          me.name, from->name, ch);
+                                          me.name, from->name, msgbuf.cmd);
                        }
                        ServerStats.is_unco++;
                        return;
                }
-
-               mptr->bytes += msgbuf.parselen;
        }
 
        if(mptr == NULL)
@@ -173,7 +153,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
                return;
        }
 
-       if(handle_command(mptr, client_p, from, msgbuf.n_para, /* XXX discards const!!! */ (const char **)(void *) msgbuf.para) < -1)
+       if(handle_command(mptr, &msgbuf, client_p, from) < -1)
        {
                char *p;
                for (p = pbuffer; p <= end; p += 8)
@@ -182,7 +162,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
                        /* Its expected this nasty code can be removed
                         * or rewritten later if still needed.
                         */
-                       if((unsigned long) (p + 8) > (unsigned long) end)
+                       if((p + 8) > end)
                        {
                                for (; p <= end; p++)
                                {
@@ -203,16 +183,14 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
  * handle_command
  *
  * inputs      - pointer to message block
+ *             - pointer to message buffer
  *             - pointer to client
  *             - pointer to client message is from
- *             - count of number of args
- *             - pointer to argv[] array
  * output      - -1 if error from server
  * side effects        -
  */
 static int
-handle_command(struct Message *mptr, struct Client *client_p,
-              struct Client *from, int i, const char** hpara)
+handle_command(struct Message *mptr, struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *from)
 {
        struct MessageEntry ehandler;
        MessageHandler handler = 0;
@@ -226,25 +204,12 @@ handle_command(struct Message *mptr, struct Client *client_p,
 
        mptr->count++;
 
-       /* New patch to avoid server flooding from unregistered connects
-          - Pie-Man 07/27/2000 */
-
-       if(!IsRegistered(client_p))
-       {
-               /* if its from a possible server connection
-                * ignore it.. more than likely its a header thats sneaked through
-                */
-
-               if(IsAnyServer(client_p) && !(mptr->flags & MFLG_UNREG))
-                       return (1);
-       }
-
        ehandler = mptr->handlers[from->handler];
        handler = ehandler.handler;
 
        /* check right amount of params is passed... --is */
-       if(i < ehandler.min_para ||
-          (ehandler.min_para && EmptyString(hpara[ehandler.min_para - 1])))
+       if(msgbuf_p->n_para < ehandler.min_para ||
+          (ehandler.min_para && EmptyString(msgbuf_p->para[ehandler.min_para - 1])))
        {
                if(!IsServer(client_p))
                {
@@ -258,33 +223,33 @@ handle_command(struct Message *mptr, struct Client *client_p,
                                return (-1);
                }
 
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                     "Dropping server %s due to (invalid) command '%s'"
-                                    " with only %d arguments (expecting %d).",
-                                    client_p->name, mptr->cmd, i, ehandler.min_para);
+                                    " with only %zu arguments (expecting %zu).",
+                                    client_p->name, mptr->cmd, msgbuf_p->n_para, ehandler.min_para);
                ilog(L_SERVER,
-                    "Insufficient parameters (%d < %d) for command '%s' from %s.",
-                    i, ehandler.min_para, mptr->cmd, client_p->name);
+                    "Insufficient parameters (%zu < %zu) for command '%s' from %s.",
+                    msgbuf_p->n_para, ehandler.min_para, mptr->cmd, client_p->name);
                snprintf(squitreason, sizeof squitreason,
-                               "Insufficient parameters (%d < %d) for command '%s'",
-                               i, ehandler.min_para, mptr->cmd);
+                               "Insufficient parameters (%zu < %zu) for command '%s'",
+                               msgbuf_p->n_para, ehandler.min_para, mptr->cmd);
                exit_client(client_p, client_p, client_p, squitreason);
                return (-1);
        }
 
-       (*handler) (client_p, from, i, hpara);
+       (*handler) (msgbuf_p, client_p, from, msgbuf_p->n_para, msgbuf_p->para);
        return (1);
 }
 
 void
-handle_encap(struct Client *client_p, struct Client *source_p,
+handle_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
             const char *command, int parc, const char *parv[])
 {
        struct Message *mptr;
        struct MessageEntry ehandler;
        MessageHandler handler = 0;
 
-       mptr = irc_dictionary_retrieve(cmd_dict, command);
+       mptr = rb_dictionary_retrieve(cmd_dict, command);
 
        if(mptr == NULL || mptr->cmd == NULL)
                return;
@@ -292,11 +257,11 @@ handle_encap(struct Client *client_p, struct Client *source_p,
        ehandler = mptr->handlers[ENCAP_HANDLER];
        handler = ehandler.handler;
 
-       if(parc < ehandler.min_para ||
+       if((size_t)parc < ehandler.min_para ||
           (ehandler.min_para && EmptyString(parv[ehandler.min_para - 1])))
                return;
 
-       (*handler) (client_p, source_p, parc, parv);
+       (*handler) (msgbuf_p, client_p, source_p, parc, parv);
 }
 
 /*
@@ -306,12 +271,11 @@ handle_encap(struct Client *client_p, struct Client *source_p,
  * output       - NONE
  * side effects - MUST MUST be called at startup ONCE before
  *                any other keyword hash routine is used.
- *
  */
 void
 clear_hash_parse()
 {
-       cmd_dict = irc_dictionary_create("command", strcasecmp);
+       cmd_dict = rb_dictionary_create("command", rb_strcasecmp);
 }
 
 /* mod_add_cmd
@@ -330,14 +294,17 @@ mod_add_cmd(struct Message *msg)
        if(msg == NULL)
                return;
 
-       if (irc_dictionary_find(cmd_dict, msg->cmd) != NULL)
+       if (rb_dictionary_find(cmd_dict, msg->cmd) != NULL) {
+               ilog(L_MAIN, "Add command: %s already exists", msg->cmd);
+               s_assert(0);
                return;
+       }
 
        msg->count = 0;
        msg->rcount = 0;
        msg->bytes = 0;
 
-       irc_dictionary_add(cmd_dict, msg->cmd, msg);
+       rb_dictionary_add(cmd_dict, msg->cmd, msg);
 }
 
 /* mod_del_cmd
@@ -353,38 +320,9 @@ mod_del_cmd(struct Message *msg)
        if(msg == NULL)
                return;
 
-       irc_dictionary_delete(cmd_dict, msg->cmd);
-}
-
-/*
- * report_messages
- *
- * inputs      - pointer to client to report to
- * output      - NONE
- * side effects        - NONE
- */
-void
-report_messages(struct Client *source_p)
-{
-       struct DictionaryIter iter;
-       struct Message *msg;
-       struct alias_entry *amsg;
-
-       DICTIONARY_FOREACH(msg, &iter, cmd_dict)
-       {
-               s_assert(msg->cmd != NULL);
-               sendto_one_numeric(source_p, RPL_STATSCOMMANDS,
-                                  form_str(RPL_STATSCOMMANDS),
-                                  msg->cmd, msg->count,
-                                  msg->bytes, msg->rcount);
-       }
-
-       DICTIONARY_FOREACH(amsg, &iter, alias_dict)
-       {
-               s_assert(amsg->name != NULL);
-               sendto_one_numeric(source_p, RPL_STATSCOMMANDS,
-                                  form_str(RPL_STATSCOMMANDS),
-                                  amsg->name, amsg->hits, 0L, 0);
+       if (rb_dictionary_delete(cmd_dict, msg->cmd) == NULL) {
+               ilog(L_MAIN, "Delete command: %s not found", msg->cmd);
+               s_assert(0);
        }
 }
 
@@ -428,7 +366,7 @@ cancel_clients(struct Client *client_p, struct Client *source_p)
  * side effects        - kills issued for clients, squits for servers
  */
 static void
-remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
+remove_unknown(struct Client *client_p, const char *lsender, char *lbuffer)
 {
        int slen = strlen(lsender);
        char sid[4];
@@ -442,7 +380,7 @@ remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
        if((IsDigit(lsender[0]) && slen == 3) ||
           (strchr(lsender, '.') != NULL))
        {
-               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE,
                                     "Unknown prefix (%s) from %s, Squitting %s",
                                     lbuffer, client_p->name, lsender);
 
@@ -454,7 +392,7 @@ remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
        else if(!IsDigit(lsender[0]))
                ;
        else if(slen != 9)
-               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE,
                                     "Invalid prefix (%s) from %s",
                                     lbuffer, client_p->name);
        else
@@ -543,7 +481,7 @@ do_numeric(int numeric, struct Client *client_p, struct Client *source_p, int pa
                         */
                        if(numeric != ERR_NOSUCHNICK &&
                           numeric != ERR_NOSUCHSERVER)
-                               sendto_realops_snomask(SNO_GENERAL, L_ADMIN,
+                               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                                     "*** %s(via %s) sent a %03d numeric to me: %s",
                                                     source_p->name,
                                                     client_p->name, numeric, buffer);
@@ -573,63 +511,18 @@ do_numeric(int numeric, struct Client *client_p, struct Client *source_p, int pa
                                     numeric, chptr->chname, buffer);
 }
 
-static void do_alias(struct alias_entry *aptr, struct Client *source_p, char *text)
-{
-       char *p;
-       struct Client *target_p;
-
-       if (!IsFloodDone(source_p) && source_p->localClient->receiveM > 20)
-               flood_endgrace(source_p);
-
-       p = strchr(aptr->target, '@');
-       if (p != NULL)
-       {
-               /* user@server */
-               target_p = find_server(NULL, p + 1);
-               if (target_p != NULL && IsMe(target_p))
-                       target_p = NULL;
-       }
-       else
-       {
-               /* nick, must be +S */
-               target_p = find_named_person(aptr->target);
-               if (target_p != NULL && !IsService(target_p))
-                       target_p = NULL;
-       }
-
-       if (target_p == NULL)
-       {
-               sendto_one_numeric(source_p, ERR_SERVICESDOWN, form_str(ERR_SERVICESDOWN), aptr->target);
-               return;
-       }
-
-       if (text != NULL && *text == ':')
-               text++;
-       if (text == NULL || *text == '\0')
-       {
-               sendto_one(source_p, form_str(ERR_NOTEXTTOSEND), me.name, source_p->name);
-               return;
-       }
-
-       /* increment the hitcounter on this alias */
-       aptr->hits++;
-
-       sendto_one(target_p, ":%s PRIVMSG %s :%s",
-                       get_id(source_p, target_p),
-                       p != NULL ? aptr->target : get_id(target_p, target_p),
-                       text);
-}
-
-int
-m_not_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+void
+m_not_oper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
-       return 0;
 }
 
-int
-m_unregistered(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+void
+m_unregistered(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
+       if(IsAnyServer(client_p))
+               return;
+
        /* bit of a hack.
         * I don't =really= want to waste a bit in a flag
         * number_of_nick_changes is only really valid after the client
@@ -640,19 +533,16 @@ m_unregistered(struct Client *client_p, struct Client *source_p, int parc, const
                sendto_one(client_p, form_str(ERR_NOTREGISTERED), me.name);
                client_p->localClient->number_of_nick_changes++;
        }
-
-       return 0;
 }
 
-int
-m_registered(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+void
+m_registered(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        sendto_one(client_p, form_str(ERR_ALREADYREGISTRED), me.name, source_p->name);
-       return 0;
 }
 
-int
-m_ignore(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+void
+m_ignore(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
-       return 0;
+       /* Does nothing */
 }