]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Try this w00t, compiles, test running now
[user/henk/code/inspircd.git] / src / configreader.cpp
index 3767fbda9d0df1fe06cd482b10b7cbbdc567e6e0..779c288b3888d1e1be2300e4f72abab1f3fd8347 100644 (file)
@@ -11,6 +11,8 @@
  * ---------------------------------------------------
  */
 
+/* $Core: libIRCDconfigreader */
+
 #include "inspircd.h"
 #include <fstream>
 #include "xline.h"
@@ -58,9 +60,9 @@ Module* ServerConfig::GetIOHook(int port)
        return (x != IOHookModule.end() ? x->second : NULL);
 }
 
-Module* ServerConfig::GetIOHook(InspSocket* is)
+Module* ServerConfig::GetIOHook(BufferedSocket* is)
 {
-       std::map<InspSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
+       std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
        return (x != SocketIOHookModule.end() ? x->second : NULL);
 }
 
@@ -78,7 +80,7 @@ bool ServerConfig::AddIOHook(int port, Module* iomod)
        }
 }
 
-bool ServerConfig::AddIOHook(Module* iomod, InspSocket* is)
+bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is)
 {
        if (!GetIOHook(is))
        {
@@ -88,7 +90,7 @@ bool ServerConfig::AddIOHook(Module* iomod, InspSocket* is)
        }
        else
        {
-               throw ModuleException("InspSocket derived class already hooked by another module");
+               throw ModuleException("BufferedSocket derived class already hooked by another module");
                return false;
        }
 }
@@ -104,9 +106,9 @@ bool ServerConfig::DelIOHook(int port)
        return false;
 }
 
-bool ServerConfig::DelIOHook(InspSocket* is)
+bool ServerConfig::DelIOHook(BufferedSocket* is)
 {
-       std::map<InspSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
+       std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
        if (x != SocketIOHookModule.end())
        {
                SocketIOHookModule.erase(x);
@@ -143,13 +145,13 @@ void ServerConfig::Update005()
        }
 }
 
-void ServerConfig::Send005(userrec* user)
+void ServerConfig::Send005(User* user)
 {
        for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
                user->WriteServ("005 %s %s", user->nick, line->c_str());
 }
 
-bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
+bool ServerConfig::CheckOnce(char* tag)
 {
        int count = ConfValueEnum(this->config_data, tag);
 
@@ -166,12 +168,12 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
        return true;
 }
 
-bool NoValidation(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool NoValidation(ServerConfig*, const char*, const char*, ValueItem&)
 {
        return true;
 }
 
-bool ValidateMaxTargets(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if ((data.GetInteger() < 0) || (data.GetInteger() > 31))
        {
@@ -181,7 +183,7 @@ bool ValidateMaxTargets(ServerConfig* conf, const char* tag, const char* value,
        return true;
 }
 
-bool ValidateSoftLimit(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateSoftLimit(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if ((data.GetInteger() < 1) || (data.GetInteger() > MAXCLIENTS))
        {
@@ -191,7 +193,7 @@ bool ValidateSoftLimit(ServerConfig* conf, const char* tag, const char* value, V
        return true;
 }
 
-bool ValidateMaxConn(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateMaxConn(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if (data.GetInteger() > SOMAXCONN)
                conf->GetInstance()->Log(DEFAULT,"WARNING: <options:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
@@ -204,13 +206,13 @@ bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance)
        std::string thiscmd;
 
        /* Enable everything first */
-       for (command_table::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
+       for (Commandable::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
                x->second->Disable(false);
 
        /* Now disable all the ones which the user wants disabled */
        while (dcmds >> thiscmd)
        {
-               command_table::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
+               Commandable::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
                if (cm != ServerInstance->Parser->cmdlist.end())
                {
                        cm->second->Disable(true);
@@ -219,7 +221,7 @@ bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance)
        return true;
 }
 
-bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if (!*(data.GetString()))
        {
@@ -257,13 +259,13 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V
        return true;
 }
 
-bool ValidateServerName(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateServerName(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        /* If we already have a servername, and they changed it, we should throw an exception. */
        if ((strcasecmp(conf->ServerName, data.GetString())) && (*conf->ServerName))
        {
                throw CoreException("Configuration error: You cannot change your servername at runtime! Please restart your server for this change to be applied.");
-               /* XXX: We don't actually reach this return of course... */
+               /* We don't actually reach this return of course... */
                return false;
        }
        if (!strchr(data.GetString(),'.'))
@@ -275,7 +277,7 @@ bool ValidateServerName(ServerConfig* conf, const char* tag, const char* value,
        return true;
 }
 
-bool ValidateNetBufferSize(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateNetBufferSize(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if ((!data.GetInteger()) || (data.GetInteger() > 65535) || (data.GetInteger() < 1024))
        {
@@ -285,7 +287,7 @@ bool ValidateNetBufferSize(ServerConfig* conf, const char* tag, const char* valu
        return true;
 }
 
-bool ValidateMaxWho(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateMaxWho(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        if ((data.GetInteger() > 65535) || (data.GetInteger() < 1))
        {
@@ -295,7 +297,7 @@ bool ValidateMaxWho(ServerConfig* conf, const char* tag, const char* value, Valu
        return true;
 }
 
-bool ValidateLogLevel(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateLogLevel(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        std::string dbg = data.GetString();
        conf->LogLevel = DEFAULT;
@@ -316,26 +318,26 @@ bool ValidateLogLevel(ServerConfig* conf, const char* tag, const char* value, Va
        return true;
 }
 
-bool ValidateMotd(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        conf->ReadFile(conf->MOTD, data.GetString());
        return true;
 }
 
-bool ValidateNotEmpty(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateNotEmpty(ServerConfig*, const char* tag, const char*, ValueItem &data)
 {
        if (!*data.GetString())
                throw CoreException(std::string("The value for ")+tag+" cannot be empty!");
        return true;
 }
 
-bool ValidateRules(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateRules(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        conf->ReadFile(conf->RULES, data.GetString());
        return true;
 }
 
-bool ValidateModeLists(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateModeLists(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        memset(conf->HideModeLists, 0, 256);
        for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
@@ -343,7 +345,7 @@ bool ValidateModeLists(ServerConfig* conf, const char* tag, const char* value, V
        return true;
 }
 
-bool ValidateExemptChanOps(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateExemptChanOps(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        memset(conf->ExemptChanOps, 0, 256);
        for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
@@ -351,7 +353,7 @@ bool ValidateExemptChanOps(ServerConfig* conf, const char* tag, const char* valu
        return true;
 }
 
-bool ValidateInvite(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        std::string v = data.GetString();
 
@@ -367,7 +369,7 @@ bool ValidateInvite(ServerConfig* conf, const char* tag, const char* value, Valu
        return true;
 }
 
-bool ValidateSID(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        int sid = data.GetInteger();
        if ((sid > 999) || (sid < 0))
@@ -379,7 +381,7 @@ bool ValidateSID(ServerConfig* conf, const char* tag, const char* value, ValueIt
        return true;
 }
 
-bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueItem &data)
 {
        conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
 
@@ -395,7 +397,7 @@ bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, Valu
                conf->GetInstance()->Log(DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600");
        }
 
-       command_t* whowas_command = conf->GetInstance()->Parser->GetHandler("WHOWAS");
+       Command* whowas_command = conf->GetInstance()->Parser->GetHandler("WHOWAS");
        if (whowas_command)
        {
                std::deque<classbase*> params;
@@ -407,17 +409,32 @@ bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, Valu
 
 /* Callback called before processing the first <connect> tag
  */
-bool InitConnect(ServerConfig* conf, const char* tag)
+bool InitConnect(ServerConfig* conf, const char*)
 {
        conf->GetInstance()->Log(DEFAULT,"Reading connect classes...");
-       conf->Classes.clear();
+
+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;
+
+               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
+               }
+       }
+
        return true;
 }
 
 /* Callback called to process a single <connect> tag
  */
-bool DoConnect(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+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();
@@ -442,10 +459,11 @@ bool DoConnect(ServerConfig* conf, const char* tag, char** entries, ValueList &v
                 */
                for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
                {
-                       if (item->GetName() == parent)
+                       ConnectClass* c = *item;
+                       if (c->GetName() == parent)
                        {
-                               ConnectClass c(name, *item);
-                               c.Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port);
+                               ConnectClass* c = new ConnectClass(name, c);
+                               c->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port);
                                conf->Classes.push_back(c);
                        }
                }
@@ -455,14 +473,14 @@ bool DoConnect(ServerConfig* conf, const char* tag, char** entries, ValueList &v
        {
                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->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);
                }
        }
@@ -472,14 +490,15 @@ bool DoConnect(ServerConfig* conf, const char* tag, char** entries, ValueList &v
 
 /* Callback called when there are no more <connect> tags
  */
-bool DoneConnect(ServerConfig* conf, const char* tag)
+bool DoneConnect(ServerConfig *conf, const char*)
 {
+       conf->GetInstance()->Log(DEFAULT, "Done adding connect classes!");
        return true;
 }
 
 /* Callback called before processing the first <uline> tag
  */
-bool InitULine(ServerConfig* conf, const char* tag)
+bool InitULine(ServerConfig* conf, const char*)
 {
        conf->ulines.clear();
        return true;
@@ -487,7 +506,7 @@ bool InitULine(ServerConfig* conf, const char* tag)
 
 /* Callback called to process a single <uline> tag
  */
-bool DoULine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+bool DoULine(ServerConfig* conf, const char*, char**, ValueList &values, int*)
 {
        const char* server = values[0].GetString();
        const bool silent = values[1].GetBool();
@@ -497,14 +516,14 @@ bool DoULine(ServerConfig* conf, const char* tag, char** entries, ValueList &val
 
 /* Callback called when there are no more <uline> tags
  */
-bool DoneULine(ServerConfig* conf, const char* tag)
+bool DoneULine(ServerConfig*, const char*)
 {
        return true;
 }
 
 /* Callback called before processing the first <module> tag
  */
-bool InitModule(ServerConfig* conf, const char* tag)
+bool InitModule(ServerConfig* conf, const char*)
 {
        old_module_names.clear();
        new_module_names.clear();
@@ -519,7 +538,7 @@ bool InitModule(ServerConfig* conf, const char* tag)
 
 /* Callback called to process a single <module> tag
  */
-bool DoModule(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+bool DoModule(ServerConfig*, const char*, char**, ValueList &values, int*)
 {
        const char* modname = values[0].GetString();
        new_module_names.push_back(modname);
@@ -528,7 +547,7 @@ bool DoModule(ServerConfig* conf, const char* tag, char** entries, ValueList &va
 
 /* Callback called when there are no more <module> tags
  */
-bool DoneModule(ServerConfig* conf, const char* tag)
+bool DoneModule(ServerConfig*, const char*)
 {
        // now create a list of new modules that are due to be loaded
        // and a seperate list of modules which are due to be unloaded
@@ -563,7 +582,7 @@ bool DoneModule(ServerConfig* conf, const char* tag)
 
 /* Callback called before processing the first <banlist> tag
  */
-bool InitMaxBans(ServerConfig* conf, const char* tag)
+bool InitMaxBans(ServerConfig* conf, const char*)
 {
        conf->maxbans.clear();
        return true;
@@ -571,7 +590,7 @@ bool InitMaxBans(ServerConfig* conf, const char* tag)
 
 /* Callback called to process a single <banlist> tag
  */
-bool DoMaxBans(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
+bool DoMaxBans(ServerConfig* conf, const char*, char**, ValueList &values, int*)
 {
        const char* channel = values[0].GetString();
        int limit = values[1].GetInteger();
@@ -581,12 +600,12 @@ bool DoMaxBans(ServerConfig* conf, const char* tag, char** entries, ValueList &v
 
 /* Callback called when there are no more <banlist> tags.
  */
-bool DoneMaxBans(ServerConfig* conf, const char* tag)
+bool DoneMaxBans(ServerConfig*, const char*)
 {
        return true;
 }
 
-void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, userrec* user)
+void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, User* user)
 {
        ServerInstance->Log(DEFAULT, "There were errors in your configuration file: %s", errormessage.c_str());
        if (bail)
@@ -625,7 +644,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail,
        }
 }
 
-void ServerConfig::Read(bool bail, userrec* user)
+void ServerConfig::Read(bool bail, User* user)
 {
        static char debug[MAXBUF];      /* Temporary buffer for debugging value */
        static char maxkeep[MAXBUF];    /* Temporary buffer for WhoWasMaxKeep value */
@@ -690,7 +709,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"die",         "value",        "",                     new ValueContainerChar (this->DieValue),                DT_CHARPTR, NoValidation},
                {"channels",    "users",        "20",                   new ValueContainerUInt (&this->MaxChans),               DT_INTEGER, NoValidation},
                {"channels",    "opers",        "60",                   new ValueContainerUInt (&this->OperMaxChans),           DT_INTEGER, NoValidation},
-               {NULL}
+               {NULL,          NULL,           NULL,                   NULL,                                                   DT_NOTHING, NoValidation}
        };
 
        /* These tags can occur multiple times, and therefore they have special code to read them
@@ -766,7 +785,11 @@ void ServerConfig::Read(bool bail, userrec* user)
                                {DT_CHARPTR,    DT_CHARPTR},
                                InitClasses, DoClass, DoneClassesAndTypes},
 
-               {NULL}
+               {NULL,
+                               {NULL},
+                               {NULL},
+                               {0},
+                               NULL, NULL, NULL}
        };
 
        include_stack.clear();
@@ -793,7 +816,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                /* Check we dont have more than one of singular tags, or any of them missing
                 */
                for (int Index = 0; Once[Index]; Index++)
-                       if (!CheckOnce(Once[Index], bail, user))
+                       if (!CheckOnce(Once[Index]))
                                return;
 
                /* Read the values of all the tags which occur once or not at all, and call their callbacks.
@@ -1374,7 +1397,7 @@ bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, con
 bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds)
 {
        ConfigDataHash::size_type pos = index;
-       if((pos >= 0) && (pos < target.count(tag)))
+       if (pos < target.count(tag))
        {
                ConfigDataHash::iterator iter = target.find(tag);
 
@@ -1522,7 +1545,7 @@ int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, in
 {
        ConfigDataHash::size_type pos = index;
 
-       if((pos >= 0) && (pos < target.count(tag)))
+       if (pos < target.count(tag))
        {
                ConfigDataHash::const_iterator iter = target.find(tag);
 
@@ -1777,3 +1800,75 @@ bool ValueItem::GetBool()
 {
        return (GetInteger() || v == "yes" || v == "true");
 }
+
+
+
+
+/*
+ * XXX should this be in a class? -- w00t
+ */
+bool InitTypes(ServerConfig* conf, const char*)
+{
+       if (conf->opertypes.size())
+       {
+               for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
+               {
+                       if (n->second)
+                               delete[] n->second;
+               }
+       }
+
+       conf->opertypes.clear();
+       return true;
+}
+
+/*
+ * XXX should this be in a class? -- w00t
+ */
+bool InitClasses(ServerConfig* conf, const char*)
+{
+       if (conf->operclass.size())
+       {
+               for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
+               {
+                       if (n->second)
+                               delete[] n->second;
+               }
+       }
+
+       conf->operclass.clear();
+       return true;
+}
+
+/*
+ * XXX should this be in a class? -- w00t
+ */
+bool DoType(ServerConfig* conf, const char*, char**, ValueList &values, int*)
+{
+       const char* TypeName = values[0].GetString();
+       const char* Classes = values[1].GetString();
+
+       conf->opertypes[TypeName] = strnewdup(Classes);
+       return true;
+}
+
+/*
+ * XXX should this be in a class? -- w00t
+ */
+bool DoClass(ServerConfig* conf, const char*, char**, ValueList &values, int*)
+{
+       const char* ClassName = values[0].GetString();
+       const char* CommandList = values[1].GetString();
+
+       conf->operclass[ClassName] = strnewdup(CommandList);
+       return true;
+}
+
+/*
+ * XXX should this be in a class? -- w00t
+ */
+bool DoneClassesAndTypes(ServerConfig*, const char*)
+{
+       return true;
+}
+