]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/command_parse.cpp
Passing invalid instance to dns isnt a good idea
[user/henk/code/inspircd.git] / src / command_parse.cpp
index b483c410bbe46b4bf4087fc116e17825bb97ccb9..4a375f3654189cfe598b3c349a02c140ed84d5c1 100644 (file)
 #include <string>
 #include <sstream>
 #include <vector>
-#include <sched.h>
-#ifdef THREADED_DNS
-#include <pthread.h>
-#endif
+#include <algorithm>
 #include "users.h"
 #include "globals.h"
 #include "modules.h"
@@ -40,7 +37,6 @@
 #include "commands.h"
 #include "xline.h"
 #include "inspstring.h"
-#include "dnsqueue.h"
 #include "helperfuncs.h"
 #include "hashcomp.h"
 #include "socketengine.h"
@@ -57,22 +53,12 @@ extern InspIRCd* ServerInstance;
 
 extern std::vector<Module*> modules;
 extern std::vector<ircd_module*> factory;
-extern std::vector<InspSocket*> module_sockets;
-extern std::vector<userrec*> local_users;
 
 extern int MODCOUNT;
-extern InspSocket* socket_ref[MAX_DESCRIPTORS];
 extern time_t TIME;
 
-// This table references users by file descriptor.
-// its an array to make it VERY fast, as all lookups are referenced
-// by an integer, meaning there is no need for a scan/search operation.
-extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-
 extern Server* MyServer;
-extern ServerConfig *Config;
 
-extern user_hash clientlist;
 extern chan_hash chanlist;
 
 /* Special commands which may occur without registration of the user */
@@ -89,7 +75,7 @@ cmd_pass* command_pass;
  * Therefore, we need to deal with both lists concurrently. The first instance of this method does that by creating
  * two instances of irc::commasepstream and reading them both together until the first runs out of tokens.
  * The second version is much simpler and just has the one stream to read, and is used in NAMES, WHOIS, PRIVMSG etc.
- * Both will only parse until they reach Config->MaxTargets number of targets, to stop abuse via spam.
+ * Both will only parse until they reach ServerInstance->Config->MaxTargets number of targets, to stop abuse via spam.
  */
 int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** parameters, int pcnt, unsigned int splithere, unsigned int extra)
 {
@@ -110,7 +96,7 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
         * which called us, for every parameter pair until there are
         * no more left to parse.
         */
-       while (((item = items1.GetToken()) != "") && (max++ < Config->MaxTargets))
+       while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
        {
                std::string extrastuff = items2.GetToken();
                parameters[splithere] = item.c_str();
@@ -137,7 +123,7 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
         * Each token we parse out, call the command handler that called us
         * with it
         */
-       while (((item = items1.GetToken()) != "") && (max++ < Config->MaxTargets))
+       while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
        {
                parameters[splithere] = item.c_str();
                CommandObj->Handle(parameters,pcnt,user);
@@ -212,8 +198,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
        while (((para[items] = tokens.GetToken()) != "") && (items < 127))
                command_p[items] = para[items++].c_str();
 
-       for (std::string::iterator makeupper = command.begin(); makeupper != command.end(); makeupper++)
-               *makeupper = toupper(*makeupper);
+       std::transform(command.begin(), command.end(), command.begin(), ::toupper);
                
        int MOD_RESULT = 0;
        FOREACH_RESULT(I_OnPreCommand,OnPreCommand(command,command_p,items,user,false));
@@ -229,34 +214,34 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
                {
                        /* activity resets the ping pending timer */
                        user->nping = TIME + user->pingmax;
-                       if (items < cm->second->min_params)
-                       {
-                               log(DEBUG,"not enough parameters: %s %s",user->nick,command.c_str());
-                               WriteServ(user->fd,"461 %s %s :Not enough parameters",user->nick,command.c_str());
-                               return;
-                       }
                        if (cm->second->flags_needed)
                        {
                                if (!user->IsModeSet(cm->second->flags_needed))
                                {
-                                       log(DEBUG,"permission denied: %s %s",user->nick,command.c_str());
-                                       WriteServ(user->fd,"481 %s :Permission Denied- You do not have the required operator privilages",user->nick);
+                                       user->WriteServ("481 %s :Permission Denied- You do not have the required operator privilages",user->nick);
+                                       return;
+                               }
+                               if (!user->HasPermission(command))
+                               {
+                                       user->WriteServ("481 %s :Permission Denied- Oper type %s does not have access to command %s",user->nick,user->oper,command.c_str());
                                        return;
                                }
                        }
-                       if ((cm->second->flags_needed) && (!user->HasPermission(command)))
+                       if ((user->registered == REG_ALL) && (!*user->oper) && (cm->second->IsDisabled()))
                        {
-                               log(DEBUG,"permission denied: %s %s",user->nick,command.c_str());
-                               WriteServ(user->fd,"481 %s :Permission Denied- Oper type %s does not have access to command %s",user->nick,user->oper,command.c_str());
+                               /* command is disabled! */
+                               user->WriteServ("421 %s %s :This command has been disabled.",user->nick,command.c_str());
                                return;
                        }
-                       if ((user->registered == 7) && (!*user->oper) && (cm->second->IsDisabled()))
+                       if (items < cm->second->min_params)
                        {
-                               /* command is disabled! */
-                               WriteServ(user->fd,"421 %s %s :This command has been disabled.",user->nick,command.c_str());
+                               user->WriteServ("461 %s %s :Not enough parameters.", user->nick, command.c_str());
+                               /* If syntax is given, display this as the 461 reply */
+                               if ((ServerInstance->Config->SyntaxHints) && (cm->second->syntax.length()))
+                                       user->WriteServ("304 %s :SYNTAX %s %s", user->nick, cm->second->command.c_str(), cm->second->syntax.c_str());
                                return;
                        }
-                       if ((user->registered == 7) || (cm->second == command_user) || (cm->second == command_nick) || (cm->second == command_pass))
+                       if ((user->registered == REG_ALL) || (cm->second == command_user) || (cm->second == command_nick) || (cm->second == command_pass))
                        {
                                /* ikky /stats counters */
                                cm->second->use_count++;
@@ -278,7 +263,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
                        }
                        else
                        {
-                               WriteServ(user->fd,"451 %s :You have not registered",command.c_str());
+                               user->WriteServ("451 %s :You have not registered",command.c_str());
                                return;
                        }
                }
@@ -286,7 +271,7 @@ void CommandParser::ProcessCommand(userrec *user, std::string &cmd)
        else if (user)
        {
                ServerInstance->stats->statsUnknown++;
-               WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command.c_str());
+               user->WriteServ("421 %s %s :Unknown command",user->nick,command.c_str());
        }
 }
 
@@ -326,9 +311,11 @@ void CommandParser::ProcessBuffer(std::string &buffer,userrec *user)
        while ((a = buffer.find("\r")) != std::string::npos)
                buffer.erase(a);
 
-       log(DEBUG,"CMDIN: %s %s",user->nick,buffer.c_str());
-
-       this->ProcessCommand(user,buffer);
+       if (buffer.length())
+       {
+               log(DEBUG,"CMDIN: %s %s",user->nick,buffer.c_str());
+               this->ProcessCommand(user,buffer);
+       }
 }
 
 bool CommandParser::CreateCommand(command_t *f)