]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Fixified some more
[user/henk/code/inspircd.git] / src / configreader.cpp
index 28c82ef77af802ea122d1512c630e52ec96a612b..96f46116239cdd655b0ca875ea9c81d8a02db219 100644 (file)
  */
 
 /* $Core: libIRCDconfigreader */
+/* $CopyInstall: conf/inspircd.quotes.example $(CONPATH) */
+/* $CopyInstall: conf/inspircd.rules.example $(CONPATH) */
+/* $CopyInstall: conf/inspircd.motd.example $(CONPATH) */
+/* $CopyInstall: conf/inspircd.helpop-full.example $(CONPATH) */
+/* $CopyInstall: conf/inspircd.helpop.example $(CONPATH) */
+/* $CopyInstall: conf/inspircd.censor.example $(CONPATH) */
+/* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */
+/* $CopyInstall: docs/inspircd.conf.example $(CONPATH) */
 
 #include "inspircd.h"
 #include <fstream>
@@ -173,6 +181,11 @@ bool NoValidation(ServerConfig*, const char*, const char*, ValueItem&)
        return true;
 }
 
+bool DoneConfItem(ServerConfig* conf, const char* tag)
+{
+       return true;
+}
+
 bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if ((data.GetInteger() < 0) || (data.GetInteger() > 31))
@@ -413,18 +426,27 @@ bool InitConnect(ServerConfig* conf, const char*)
 {
        conf->GetInstance()->Log(DEFAULT,"Reading connect classes...");
 
-goagain:
-       /* change this: only delete a class with refcount 0 */
        for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end(); i++)
        {
-               ConnectClass *c = &(*i);
+               ConnectClass *c = *i;
+
+               conf->GetInstance()->Log(DEBUG, "Address of class is %p", c);
+       }
+
+       for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end(); i++)
+       {
+               ConnectClass *c = *i;
 
+               /* only delete a class with refcount 0 */
                if (c->RefCount == 0)
                {
                        conf->GetInstance()->Log(DEFAULT, "Removing connect class, refcount is 0!");
                        conf->Classes.erase(i);
-                       goto goagain; // XXX fucking hell.. how better to  do this
+                       i = conf->Classes.begin(); // start over so we don't trample on a bad iterator
                }
+
+               /* also mark all existing classes disabled, if they still exist in the conf, they will be reenabled. */
+               c->SetDisabled(true);
        }
 
        return true;
@@ -434,7 +456,6 @@ goagain:
  */
 bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
 {
-       conf->GetInstance()->Log(DEFAULT,"Adding a connect class!");
        ConnectClass c;
        const char* allow = values[0].GetString(); /* Yeah, there are a lot of values. Live with it. */
        const char* deny = values[1].GetString();
@@ -451,35 +472,60 @@ bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
        const char* name = values[12].GetString();
        const char* parent = values[13].GetString();
        int maxchans = values[14].GetInteger();
+       unsigned long limit = values[15].GetInteger();
+
+       /*
+        * duplicates check: Now we don't delete all connect classes on rehash, we need to ensure we don't add dupes.
+        * easier said than done, but for now we'll just disallow anything with a duplicate host or name. -- w00t
+        */
+       for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
+       {
+               ConnectClass* c = *item;
+               if ((*name && (c->GetName() == name)) || (*allow && (c->GetHost() == allow)) || (*deny && (c->GetHost() == deny)))
+               {
+                       /* reenable class so users can be shoved into it :P */
+                       c->SetDisabled(false);
+                       conf->GetInstance()->Log(DEFAULT, "Not adding class, it already exists!");
+                       return true;
+               } 
+       }
+
+       conf->GetInstance()->Log(DEFAULT,"Adding a connect class!");
 
        if (*parent)
        {
                /* Find 'parent' and inherit a new class from it,
                 * then overwrite any values that are set here
                 */
-               for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
+               ClassVector::iterator item = conf->Classes.begin();
+               for (; item != conf->Classes.end(); ++item)
                {
-                       if (item->GetName() == parent)
+                       ConnectClass* c = *item;
+                       conf->GetInstance()->Log(DEBUG,"Class: %s", c->GetName().c_str());
+                       if (c->GetName() == parent)
                        {
-                               ConnectClass c(name, *item);
-                               c.Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port);
-                               conf->Classes.push_back(c);
+                               ConnectClass* newclass = new ConnectClass(name, c);
+                               newclass->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
+                               conf->Classes.push_back(newclass);
+                               break;
                        }
                }
-               throw CoreException("Class name '" + std::string(name) + "' is configured to inherit from class '" + std::string(parent) + "' which cannot be found.");
+               if (item == conf->Classes.end())
+                       throw CoreException("Class name '" + std::string(name) + "' is configured to inherit from class '" + std::string(parent) + "' which cannot be found.");
        }
        else
        {
                if (*allow)
                {
-                       ConnectClass c(name, timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans);
-                       c.SetPort(port);
+                       ConnectClass* c = new ConnectClass(name, timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans);
+                       c->limit = limit;
+                       c->SetPort(port);
                        conf->Classes.push_back(c);
                }
                else
                {
-                       ConnectClass c(name, deny);
-                       c.SetPort(port);
+                       ConnectClass* c = new ConnectClass(name, deny);
+                       c->SetPort(port);
                        conf->Classes.push_back(c);
                }
        }
@@ -719,15 +765,15 @@ void ServerConfig::Read(bool bail, User* user)
                {"connect",
                                {"allow",       "deny",         "password",     "timeout",      "pingfreq",     "flood",
                                "threshold",    "sendq",        "recvq",        "localmax",     "globalmax",    "port",
-                               "name",         "parent",       "maxchans",
+                               "name",         "parent",       "maxchans",     "limit",
                                NULL},
                                {"",            "",             "",             "",             "120",          "",
                                 "",            "",             "",             "3",            "3",            "0",
-                                "",            "",             "0",
+                                "",            "",             "0",            "0",
                                 NULL},
                                {DT_CHARPTR,    DT_CHARPTR,     DT_CHARPTR,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
                                 DT_INTEGER,    DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
-                                DT_CHARPTR,    DT_CHARPTR,     DT_INTEGER},
+                                DT_CHARPTR,    DT_CHARPTR,     DT_INTEGER,     DT_INTEGER},
                                InitConnect, DoConnect, DoneConnect},
 
                {"uline",
@@ -752,19 +798,19 @@ void ServerConfig::Read(bool bail, User* user)
                                {"reason",      "ipmask",       NULL},
                                {"No reason",   "",             NULL},
                                {DT_CHARPTR,    DT_CHARPTR},
-                               InitXLine, DoZLine, DoneZLine},
+                               InitXLine, DoZLine, DoneConfItem},
 
                {"badnick",
                                {"reason",      "nick",         NULL},
                                {"No reason",   "",             NULL},
                                {DT_CHARPTR,    DT_CHARPTR},
-                               InitXLine, DoQLine, DoneQLine},
+                               InitXLine, DoQLine, DoneConfItem},
 
                {"badhost",
                                {"reason",      "host",         NULL},
                                {"No reason",   "",             NULL},
                                {DT_CHARPTR,    DT_CHARPTR},
-                               InitXLine, DoKLine, DoneKLine},
+                               InitXLine, DoKLine, DoneConfItem},
 
                {"exception",
                                {"reason",      "host",         NULL},
@@ -1350,15 +1396,10 @@ bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, st
        confpath = ServerInstance->ConfigFileName;
        newfile = file;
 
-       for (std::string::iterator c = newfile.begin(); c != newfile.end(); c++)
-       {
-               if (*c == '\\')
-               {
-                       *c = '/';
-               }
-       }
+       std::replace(newfile.begin(),newfile.end(),'\\','/');
+       std::replace(confpath.begin(),confpath.end(),'\\','/');
 
-       if (file[0] != '/')
+       if (newfile[0] != '/')
        {
                if((pos = confpath.rfind("/")) != std::string::npos)
                {
@@ -1367,7 +1408,7 @@ bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, st
                }
                else
                {
-                       errorstream << "Couldn't get config path from: " << confpath << std::endl;
+                       errorstream << "Couldn't get config path from: " << ServerInstance->ConfigFileName << std::endl;
                        return false;
                }
        }
@@ -1871,3 +1912,64 @@ bool DoneClassesAndTypes(ServerConfig*, const char*)
        return true;
 }
 
+
+
+bool InitXLine(ServerConfig* conf, const char* tag)
+{
+       return true;
+}
+
+bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+       const char* reason = values[0].GetString();
+       const char* ipmask = values[1].GetString();
+
+       ZLine* zl = new ZLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ipmask);
+       if (!conf->GetInstance()->XLines->AddLine(zl))
+               delete zl;
+
+       return true;
+}
+
+bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+       const char* reason = values[0].GetString();
+       const char* nick = values[1].GetString();
+
+       QLine* ql = new QLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, nick);
+       if (!conf->GetInstance()->XLines->AddLine(ql))
+               delete ql;
+
+       return true;
+}
+
+bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+       const char* reason = values[0].GetString();
+       const char* host = values[1].GetString();
+
+       XLineManager* xlm = conf->GetInstance()->XLines;
+
+       IdentHostPair ih = xlm->IdentSplit(host);
+
+       KLine* kl = new KLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
+       if (!xlm->AddLine(kl))
+               delete kl;
+       return true;
+}
+
+bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+{
+       const char* reason = values[0].GetString();
+       const char* host = values[1].GetString();
+
+       XLineManager* xlm = conf->GetInstance()->XLines;
+
+       IdentHostPair ih = xlm->IdentSplit(host);
+
+       ELine* el = new ELine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
+       if (!xlm->AddLine(el))
+               delete el;
+       return true;
+}
+