]> jfr.im git - solanum.git/blobdiff - src/parse.c
Remove trailing whitespace from all .c and .h files.
[solanum.git] / src / parse.c
index b26022ddc27cfe7f23ce4341724f9d728296406a..c382cadd246d8dd5387621ddb44b6174cb27621a 100644 (file)
 #include "channel.h"
 #include "common.h"
 #include "hash.h"
-#include "irc_string.h"
-#include "sprintf_irc.h"
+#include "match.h"
 #include "ircd.h"
 #include "numeric.h"
-#include "s_log.h"
+#include "logger.h"
 #include "s_stats.h"
 #include "send.h"
 #include "msg.h"
 #include "s_conf.h"
 #include "s_serv.h"
 #include "packet.h"
+#include "s_assert.h"
 
 static struct Dictionary *cmd_dict = NULL;
 struct Dictionary *alias_dict = NULL;
 
-/*
- * NOTE: parse() should not be called recursively by other functions!
- */
-static char *sender;
-
-/* parv[0] == source, and parv[LAST] == NULL */
+/* parv[0] is not used, and parv[LAST] == NULL */
 static char *para[MAXPARA + 2];
 
 static void cancel_clients(struct Client *, struct Client *, char *);
@@ -105,7 +100,7 @@ string_to_array(char *string, char **parv)
                if(*buf == '\0')
                        return x;
        }
-       /* we can go upto parv[MAXPARA], as parv[0] is taken by source */
+       /* we can go upto parv[MAXPARA], as parv[0] is skipped */
        while (x < MAXPARA);
 
        if(*p == ':')
@@ -118,12 +113,13 @@ string_to_array(char *string, char **parv)
 
 /* parse()
  *
- * given a raw buffer, parses it and generates parv, parc and sender
+ * given a raw buffer, parses it and generates parv and parc
  */
 void
 parse(struct Client *client_p, char *pbuffer, char *bufend)
 {
        struct Client *from = client_p;
+       char *sender;
        char *ch;
        char *s;
        char *end;
@@ -132,7 +128,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
        struct Message *mptr;
 
        s_assert(MyConnect(client_p));
-       s_assert(client_p->localClient->F->fd >= 0);
+       s_assert(client_p->localClient->F != NULL);
        if(IsAnyDead(client_p))
                return;
 
@@ -343,14 +339,14 @@ handle_command(struct Message *mptr, struct Client *client_p,
        handler = ehandler.handler;
 
        /* check right amount of params is passed... --is */
-       if(i < ehandler.min_para || 
+       if(i < ehandler.min_para ||
           (ehandler.min_para && EmptyString(hpara[ehandler.min_para - 1])))
        {
                if(!IsServer(client_p))
                {
                        sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
-                                  me.name, 
-                                  EmptyString(client_p->name) ? "*" : client_p->name, 
+                                  me.name,
+                                  EmptyString(client_p->name) ? "*" : client_p->name,
                                   mptr->cmd);
                        if(MyClient(client_p))
                                return (1);
@@ -365,7 +361,7 @@ handle_command(struct Message *mptr, struct Client *client_p,
                ilog(L_SERVER,
                     "Insufficient parameters (%d < %d) for command '%s' from %s.",
                     i, ehandler.min_para, mptr->cmd, client_p->name);
-               snprintf(squitreason, sizeof squitreason,
+               rb_snprintf(squitreason, sizeof squitreason,
                                "Insufficient parameters (%d < %d) for command '%s'",
                                i, ehandler.min_para, mptr->cmd);
                exit_client(client_p, client_p, client_p, squitreason);
@@ -394,7 +390,7 @@ handle_encap(struct Client *client_p, struct Client *source_p,
        ehandler = mptr->handlers[ENCAP_HANDLER];
        handler = ehandler.handler;
 
-       if(parc < ehandler.min_para || 
+       if(parc < ehandler.min_para ||
           (ehandler.min_para && EmptyString(parv[ehandler.min_para - 1])))
                return;
 
@@ -475,9 +471,9 @@ report_messages(struct Client *source_p)
        DICTIONARY_FOREACH(msg, &iter, cmd_dict)
        {
                s_assert(msg->cmd != NULL);
-               sendto_one_numeric(source_p, RPL_STATSCOMMANDS, 
+               sendto_one_numeric(source_p, RPL_STATSCOMMANDS,
                                   form_str(RPL_STATSCOMMANDS),
-                                  msg->cmd, msg->count, 
+                                  msg->cmd, msg->count,
                                   msg->bytes, msg->rcount);
        }
 
@@ -486,7 +482,7 @@ report_messages(struct Client *source_p)
                s_assert(amsg->name != NULL);
                sendto_one_numeric(source_p, RPL_STATSCOMMANDS,
                                   form_str(RPL_STATSCOMMANDS),
-                                  amsg->name, amsg->hits, 0, 0);
+                                  amsg->name, amsg->hits, 0L, 0);
        }
 }
 
@@ -509,7 +505,7 @@ cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
                sendto_realops_snomask(SNO_DEBUG, L_ALL,
                                     "Message for %s[%s] from %s",
                                     source_p->name, source_p->from->name,
-                                    get_server_name(client_p, SHOW_IP));
+                                    client_p->name);
        }
        else
        {
@@ -519,41 +515,55 @@ cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
                                     source_p->username,
                                     source_p->host,
                                     source_p->from->name,
-                                    get_server_name(client_p, SHOW_IP));
+                                    client_p->name);
        }
 }
 
 /* remove_unknown()
  *
  * inputs      - client who gave us message, supposed sender, buffer
- * output      - 
+ * output      -
  * side effects        - kills issued for clients, squits for servers
  */
 static void
 remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
 {
        int slen = strlen(lsender);
+       char sid[4];
+       struct Client *server;
 
-       /* meepfoo      is a nickname (KILL)
+       /* meepfoo      is a nickname (ignore)
         * #XXXXXXXX    is a UID (KILL)
         * #XX          is a SID (SQUIT)
         * meep.foo     is a server (SQUIT)
         */
-       if((IsDigit(lsender[0]) && slen == 3) || 
+       if((IsDigit(lsender[0]) && slen == 3) ||
           (strchr(lsender, '.') != NULL))
        {
                sendto_realops_snomask(SNO_DEBUG, L_ALL,
                                     "Unknown prefix (%s) from %s, Squitting %s",
-                                    lbuffer, get_server_name(client_p, SHOW_IP), lsender);
+                                    lbuffer, client_p->name, lsender);
 
                sendto_one(client_p,
                           ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
-                          get_id(&me, client_p), lsender, 
+                          get_id(&me, client_p), lsender,
                           lbuffer, client_p->name);
        }
+       else if(!IsDigit(lsender[0]))
+               ;
+       else if(slen != 9)
+               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+                                    "Invalid prefix (%s) from %s",
+                                    lbuffer, client_p->name);
        else
-               sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", 
-                          get_id(&me, client_p), lsender, me.name);
+       {
+               memcpy(sid, lsender, 3);
+               sid[3] = '\0';
+               server = find_server(NULL, sid);
+               if (server != NULL && server->from == client_p)
+                       sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
+                                       get_id(&me, client_p), lsender, me.name);
+       }
 }
 
 
@@ -561,7 +571,6 @@ remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
 /*
  *
  *      parc    number of arguments ('sender' counted as one!)
- *      parv[0] pointer to 'sender' (may point to empty string) (not used)
  *      parv[1]..parv[parc-1]
  *              pointers to additional parameters, this is a NULL
  *              terminated list (parv[parc] == NULL).
@@ -620,7 +629,7 @@ do_numeric(char numeric[], struct Client *client_p, struct Client *source_p, int
                         * because it will have been already killed by the local server.
                         *
                         * unfortunately, as we cant guarantee other servers will do the
-                        * "right thing" on a nick collision, we have to keep both kills.  
+                        * "right thing" on a nick collision, we have to keep both kills.
                         * ergo we need to ignore ERR_NOSUCHNICK. --fl_
                         */
                        /* quick comment. This _was_ tried. i.e. assume the other servers
@@ -651,8 +660,8 @@ do_numeric(char numeric[], struct Client *client_p, struct Client *source_p, int
                        return;
 
                /* Fake it for server hiding, if its our client */
-               sendto_one(target_p, ":%s %s %s%s", 
-                          get_id(source_p, target_p), numeric, 
+               sendto_one(target_p, ":%s %s %s%s",
+                          get_id(source_p, target_p), numeric,
                           get_id(target_p, target_p), buffer);
                return;
        }