]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Adjust m_mysql to match the assumed behaviour of m_pgsql exactly, e.g. when there...
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 1a12b7039cbe27df6bf22cc782c71bd7c7d5cdb2..b9cd9f36c072340e7bc3b803dda80ed925dd64a9 100644 (file)
@@ -63,6 +63,7 @@
 #include "helperfuncs.h"
 #include "hashcomp.h"
 #include "socketengine.h"
+#include "inspircd_se_config.h"
 #include "userprocess.h"
 #include "socket.h"
 #include "typedefs.h"
@@ -70,9 +71,6 @@
 
 InspIRCd* ServerInstance;
 
-int WHOWAS_STALE = 48; // default WHOWAS Entries last 2 days before they go 'stale'
-int WHOWAS_MAX = 100;  // default 100 people maximum in the WHOWAS list
-
 extern ModuleList modules;
 extern FactoryList factory;
 
@@ -81,29 +79,23 @@ std::vector<userrec*> local_users;
 
 extern int MODCOUNT;
 extern char LOG_FILE[MAXBUF];
-int openSockfd[MAX_DESCRIPTORS];
-int yield_depth;
+
 int iterations = 0;
 
 insp_sockaddr client, server;
-
 socklen_t length;
 
 extern InspSocket* socket_ref[MAX_DESCRIPTORS];
-
 time_t TIME = time(NULL), OLDTIME = time(NULL);
 
 // 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.
 userrec* fd_ref_table[MAX_DESCRIPTORS];
-
 Server* MyServer = new Server;
 ServerConfig *Config = new ServerConfig;
-
 user_hash clientlist;
 chan_hash chanlist;
-
 servernamelist servernames;
 char lowermap[255];
 
@@ -246,6 +238,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
 {
        this->Start();
        module_sockets.clear();
+       init_dns();
        this->startup_time = time(NULL);
        srand(time(NULL));
        log(DEBUG,"*** InspIRCd starting up!");
@@ -302,13 +295,14 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        OpenLog(argv, argc);
        this->stats = new serverstats();
+       this->Parser = new CommandParser();
        Config->ClearStack();
        Config->Read(true,NULL);
        CheckRoot();
        this->ModeGrok = new ModeParser();
-       this->Parser = new CommandParser();
        AddServerName(Config->ServerName);
        CheckDie();
+       InitializeDisabledCommands(Config->DisabledCommands, this);
        stats->BoundPortCount = BindPorts(true);
 
        for(int t = 0; t < 255; t++)
@@ -330,7 +324,9 @@ InspIRCd::InspIRCd(int argc, char** argv)
        /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
         * initialize the socket engine.
         */
-       SE = new SocketEngine();
+       SocketEngineFactory* SEF = new SocketEngineFactory();
+       SE = SEF->Create();
+       delete SEF;
 
        /* We must load the modules AFTER initializing the socket engine, now */
 
@@ -694,11 +690,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
        insp_sockaddr sock_us;     // our port number
        socklen_t uslen;         // length of our port number
 
-       if (yield_depth > 100)
-               return;
-
-       yield_depth++;
-
        /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
         * Once per loop iteration is pleanty.
         */
@@ -731,7 +722,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                }
                TickMissedTimers(TIME);
                expire_run = true;
-               yield_depth--;
                return;
        }   
        else if ((TIME % 5) == 1)
@@ -772,10 +762,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
         * servers... so its nice and easy, just one call.
         */
        if (!(numberactive = SE->Wait(activefds)))
-       {
-               yield_depth--;
                return;
-       }
 
        /**
         * Now process each of the fd's. For users, we have a fast
@@ -851,6 +838,15 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
 #endif
                        break;
 
+                       case X_ESTAB_CLASSDNS:
+                               /* Handles instances of the Resolver class,
+                                * a simple class extended by modules for
+                                * nonblocking resolving of addresses.
+                                */
+
+                               dns_deal_with_classes(activefds[activefd]);
+                       break;
+
                        case X_LISTEN:
 
                                log(DEBUG,"Type: X_LISTEN_MODULE: fd=%d",activefds[activefd]);
@@ -904,7 +900,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                        break;
                }
        }
-       yield_depth--;
 }
 
 int InspIRCd::Run()
@@ -928,14 +923,13 @@ int InspIRCd::Run()
        /* Add the listening sockets used for client inbound connections
         * to the socket engine
         */
-       for (int count = 0; count < stats->BoundPortCount; count++)
-               SE->AddFd(openSockfd[count],true,X_LISTEN);
+       for (unsigned long count = 0; count < stats->BoundPortCount; count++)
+               SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
 
        this->WritePID(Config->PID);
 
        /* main loop, this never returns */
        expire_run = false;
-       yield_depth = 0;
        iterations = 0;
 
        while (true)
@@ -954,6 +948,61 @@ int InspIRCd::Run()
 
 int main(int argc, char** argv)
 {
+       /* TEST SUITE FOR TOKENSTREAM
+        *
+        * Expected output:
+        * 
+        * String: 'PRIVMSG #test FOO BAR'
+        * Token 0 = 'PRIVMSG'
+        * Token 1 = '#test'
+        * Token 2 = 'FOO'
+        * Token 3 = 'BAR'
+        * String: 'PRIVMSG #test :FOO BAR BAZ'
+        * Token 0 = 'PRIVMSG'
+        * Token 1 = '#test'
+        * Token 2 = 'FOO BAR BAZ'
+        * String: ':PRIVMSG #test :FOO BAR BAZ'
+        * Token 0 = ':PRIVMSG'
+        * String: 'AAAAAAA'
+        * Token 0 = 'AAAAAAA'
+        * String: ''
+        * NumItems = 0
+        *
+       std::string a = "PRIVMSG #test FOO BAR";
+       printf("String: '%s'\n",a.c_str());
+       irc::tokenstream test(a);
+       printf("Token 0 = '%s'\n",test.GetToken().c_str());
+       printf("Token 1 = '%s'\n",test.GetToken().c_str());
+       printf("Token 2 = '%s'\n",test.GetToken().c_str());
+       printf("Token 3 = '%s'\n",test.GetToken().c_str());
+       printf("Token 4 = '%s'\n",test.GetToken().c_str());
+
+       std::string b = "PRIVMSG #test :FOO BAR BAZ";
+       printf("String: '%s'\n",b.c_str());
+       irc::tokenstream test2(b);
+       printf("Token 0 = '%s'\n",test2.GetToken().c_str());
+       printf("Token 1 = '%s'\n",test2.GetToken().c_str());
+       printf("Token 2 = '%s'\n",test2.GetToken().c_str());
+       printf("Token 3 = '%s'\n",test2.GetToken().c_str());
+
+       std::string c = ":PRIVMSG #test :FOO BAR BAZ";
+       printf("String: '%s'\n",c.c_str());
+       irc::tokenstream test3(c);
+       printf("Token 0 = '%s'\n",test3.GetToken().c_str());
+
+       c = "AAAAAAA";
+       printf("String: '%s'\n",c.c_str());
+       irc::tokenstream test4(c);
+       printf("Token 0 = '%s'\n",test4.GetToken().c_str());
+       printf("Token 1 = '%s'\n",test4.GetToken().c_str());
+
+       c = "";
+       printf("String: '%s'\n",c.c_str());
+       irc::tokenstream test5(c);
+       printf("Token 0 = '%s'\n",test5.GetToken().c_str());
+
+       exit(0);
+       */
        try
        {
                ServerInstance = new InspIRCd(argc, argv);