summaryrefslogtreecommitdiff
path: root/src/configreader.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-17 02:14:44 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-17 02:14:44 +0000
commitbf6724c049ba0f156544c49aab2008d6280e5ffa (patch)
tree0c56caccf906b87575dfefe52acc526f38c1fc81 /src/configreader.cpp
parent62a1eab66838294f2b88d5ea94c1678c167d6189 (diff)
Rewrite ConfigReader again
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11879 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/configreader.cpp')
-rw-r--r--src/configreader.cpp1344
1 files changed, 375 insertions, 969 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index d1fb5e197..6157b4d4b 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -32,6 +32,28 @@
#include "commands/cmd_whowas.h"
#include "modes/cmode_h.h"
+static void ReqRead(ServerConfig* src, const std::string& tag, const std::string& key, std::string& dest)
+{
+ ConfigTag* t = src->ConfValue(tag);
+ if (!t || !t->readString(key, dest))
+ throw CoreException("You must specify a value for <" + tag + ":" + key + ">");
+}
+
+/** Represents a deprecated configuration tag.
+ */
+struct Deprecated
+{
+ /** Tag name
+ */
+ const char* tag;
+ /** Tag value
+ */
+ const char* value;
+ /** Reason for deprecation
+ */
+ const char* reason;
+};
+
ServerConfig::ServerConfig()
{
WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
@@ -85,32 +107,33 @@ void ServerConfig::Send005(User* user)
user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), line->c_str());
}
-bool ServerConfig::CheckOnce(const char* tag)
+template<typename T, typename V>
+static void range(T& value, V min, V max, V def, const char* msg)
{
- int count = ConfValueEnum(tag);
-
- if (count > 1)
- throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted.");
- if (count < 1)
- throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required.");
- return true;
+ if (value >= (T)min && value <= (T)max)
+ return;
+ ServerInstance->Logs->Log("CONFIG", DEFAULT,
+ "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.",
+ msg, (long)value, (long)min, (long)max, (long)def);
+ value = def;
}
-static void ValidateNoSpaces(const char* p, const std::string &tag, const std::string &val)
+bool ServerConfig::CheckOnce(const char* tag)
{
- for (const char* ptr = p; *ptr; ++ptr)
- {
- if (*ptr == ' ')
- throw CoreException("The value of <"+tag+":"+val+"> cannot contain spaces");
- }
+ if (!ConfValue(tag))
+ throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required.");
+ if (ConfValue(tag, 1))
+ throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted.");
+ return true;
}
/* NOTE: Before anyone asks why we're not using inet_pton for this, it is because inet_pton and friends do not return so much detail,
* even in strerror(errno). They just return 'yes' or 'no' to an address without such detail as to whats WRONG with the address.
* Because ircd users arent as technical as they used to be (;)) we are going to give more of a useful error message.
*/
-static void ValidateIP(const char* p, const std::string &tag, const std::string &val, bool wild)
+static void ValidIP(const std::string& ip, const std::string& key)
{
+ const char* p = ip.c_str();
int num_dots = 0;
int num_seps = 0;
int not_numbers = false;
@@ -119,13 +142,10 @@ static void ValidateIP(const char* p, const std::string &tag, const std::string
if (*p)
{
if (*p == '.')
- throw CoreException("The value of <"+tag+":"+val+"> is not an IP address");
+ throw CoreException("The value of "+key+" is not an IP address");
for (const char* ptr = p; *ptr; ++ptr)
{
- if (wild && (*ptr == '*' || *ptr == '?' || *ptr == '/'))
- continue;
-
if (*ptr != ':' && *ptr != '.')
{
if (*ptr < '0' || *ptr > '9')
@@ -136,7 +156,7 @@ static void ValidateIP(const char* p, const std::string &tag, const std::string
switch (*ptr)
{
case ' ':
- throw CoreException("The value of <"+tag+":"+val+"> is not an IP address");
+ throw CoreException("The value of "+key+" is not an IP address");
case '.':
num_dots++;
break;
@@ -147,77 +167,47 @@ static void ValidateIP(const char* p, const std::string &tag, const std::string
}
if (num_dots > 3)
- throw CoreException("The value of <"+tag+":"+val+"> is an IPv4 address with too many fields!");
+ throw CoreException("The value of "+key+" is an IPv4 address with too many fields!");
if (num_seps > 8)
- throw CoreException("The value of <"+tag+":"+val+"> is an IPv6 address with too many fields!");
+ throw CoreException("The value of "+key+" is an IPv6 address with too many fields!");
- if (num_seps == 0 && num_dots < 3 && !wild)
- throw CoreException("The value of <"+tag+":"+val+"> looks to be a malformed IPv4 address");
+ if (num_seps == 0 && num_dots < 3)
+ throw CoreException("The value of "+key+" looks to be a malformed IPv4 address");
if (num_seps == 0 && num_dots == 3 && not_numbers)
- throw CoreException("The value of <"+tag+":"+val+"> contains non-numeric characters in an IPv4 address");
+ throw CoreException("The value of "+key+" contains non-numeric characters in an IPv4 address");
if (num_seps != 0 && not_hex)
- throw CoreException("The value of <"+tag+":"+val+"> contains non-hexdecimal characters in an IPv6 address");
+ throw CoreException("The value of "+key+" contains non-hexdecimal characters in an IPv6 address");
- if (num_seps != 0 && num_dots != 3 && num_dots != 0 && !wild)
- throw CoreException("The value of <"+tag+":"+val+"> is a malformed IPv6 4in6 address");
+ if (num_seps != 0 && num_dots != 3 && num_dots != 0)
+ throw CoreException("The value of "+key+" is a malformed IPv6 4in6 address");
}
}
-static void ValidateHostname(const char* p, const std::string &tag, const std::string &val)
+static void ValidHost(const std::string& p, const std::string& msg)
{
int num_dots = 0;
- if (*p)
+ if (p.empty() || p[0] == '.')
+ throw CoreException("The value of "+msg+" is not a valid hostname");
+ for (unsigned int i=0;i < p.length();i++)
{
- if (*p == '.')
- throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
- for (const char* ptr = p; *ptr; ++ptr)
+ switch (p[i])
{
- switch (*ptr)
- {
- case ' ':
- throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
- case '.':
- num_dots++;
- break;
- }
+ case ' ':
+ throw CoreException("The value of "+msg+" is not a valid hostname");
+ case '.':
+ num_dots++;
+ break;
}
- if (num_dots == 0)
- throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
}
+ if (num_dots == 0)
+ throw CoreException("The value of "+msg+" is not a valid hostname");
}
// Specialized validators
-static bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- if ((data.GetInteger() < 1) || (data.GetInteger() > 31))
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <security:maxtargets> value is greater than 31 or less than 1, set to 20.");
- data.Set(20);
- }
- return true;
-}
-
-static bool ValidateSoftLimit(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- if ((data.GetInteger() < 1) || (data.GetInteger() > ServerInstance->SE->GetMaxFds()))
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:softlimit> value is greater than %d or less than 0, set to %d.",ServerInstance->SE->GetMaxFds(),ServerInstance->SE->GetMaxFds());
- data.Set(ServerInstance->SE->GetMaxFds());
- }
- return true;
-}
-
-static bool ValidateMaxConn(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- if (data.GetInteger() > SOMAXCONN)
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
- return true;
-}
-
bool ServerConfig::ApplyDisabledCommands(const std::string& data)
{
std::stringstream dcmds(data);
@@ -239,348 +229,84 @@ bool ServerConfig::ApplyDisabledCommands(const std::string& data)
return true;
}
-static bool ValidateDisabledUModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- memset(conf->DisabledUModes, 0, sizeof(conf->DisabledUModes));
- for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
- {
- if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found.");
- conf->DisabledUModes[*p - 'A'] = 1;
- }
- return true;
-}
-
-static bool ValidateDisabledCModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- memset(conf->DisabledCModes, 0, sizeof(conf->DisabledCModes));
- for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
- {
- if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found.");
- conf->DisabledCModes[*p - 'A'] = 1;
- }
- return true;
-}
-
#ifdef WINDOWS
// Note: the windows validator is in win32wrapper.cpp
-bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data);
+void ValidateDnsServer(std::string& server);
#else
-static bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- if (!*(data.GetString()))
- {
- std::string nameserver;
- // attempt to look up their nameserver from /etc/resolv.conf
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
- std::ifstream resolv("/etc/resolv.conf");
- bool found_server = false;
-
- if (resolv.is_open())
- {
- while (resolv >> nameserver)
- {
- if ((nameserver == "nameserver") && (!found_server))
- {
- resolv >> nameserver;
- data.Set(nameserver.c_str());
- found_server = true;
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",nameserver.c_str());
- }
- }
-
- if (!found_server)
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
- data.Set("127.0.0.1");
- }
- }
- else
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!");
- data.Set("127.0.0.1");
- }
- }
- return true;
-}
-#endif
-
-static bool ValidateServerName(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"Validating server name");
- /* If we already have a servername, and they changed it, we should throw an exception. */
- if (!strchr(data.GetString(), '.'))
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <server:name> '%s' is not a fully-qualified domain name. Changed to '%s.'",
- data.GetString(),data.GetString());
- std::string moo = data.GetValue();
- data.Set(moo.append("."));
- }
- ValidateHostname(data.GetString(), "server", "name");
- return true;
-}
-
-static bool ValidateNetBufferSize(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- // 65534 not 65535 because of null terminator
- if ((!data.GetInteger()) || (data.GetInteger() > 65534) || (data.GetInteger() < 1024))
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
- data.Set(10240);
- }
- return true;
-}
-
-static bool ValidateMaxWho(ServerConfig* conf, const char*, const char*, ValueItem &data)
+static void ValidateDnsServer(std::string& server)
{
- if ((data.GetInteger() > 65535) || (data.GetInteger() < 1))
+ if (!server.empty())
{
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"<performance:maxwho> size out of range, setting to default of 1024.");
- data.Set(1024);
- }
- return true;
-}
-
-static bool ValidateHalfOp(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL);
- if (data.GetBool() && !mh) {
- ServerInstance->Logs->Log("CONFIG", DEFAULT, "Enabling halfop mode.");
- mh = new ModeChannelHalfOp;
- ServerInstance->Modes->AddMode(mh);
- } else if (!data.GetBool() && mh) {
- ServerInstance->Logs->Log("CONFIG", DEFAULT, "Disabling halfop mode.");
- ServerInstance->Modes->DelMode(mh);
- delete mh;
+ ValidIP(server, "<dns:server>");
+ return;
}
- return true;
-}
-
-static bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- conf->ReadFile(conf->MOTD, data.GetString());
- return true;
-}
-
-static bool ValidateNotEmpty(ServerConfig*, const char* tag, const char* val, ValueItem &data)
-{
- if (data.GetValue().empty())
- throw CoreException(std::string("The value for <")+tag+":"+val+"> cannot be empty!");
- return true;
-}
-
-static bool ValidateRules(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- conf->ReadFile(conf->RULES, data.GetString());
- return true;
-}
-
-static bool ValidateModeLists(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- memset(conf->HideModeLists, 0, sizeof(conf->HideModeLists));
- for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
- conf->HideModeLists[*x] = true;
- return true;
-}
-
-static bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- const std::string& v = data.GetValue();
-
- if (v == "ops")
- conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
- else if (v == "all")
- conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
- else if (v == "dynamic")
- conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
- else
- conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
- return true;
-}
+ // attempt to look up their nameserver from /etc/resolv.conf
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
-static bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data)
-{
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"Validating server id");
+ std::ifstream resolv("/etc/resolv.conf");
- const std::string& sid = data.GetValue();
-
- if (!sid.empty() && !ServerInstance->IsSID(sid))
+ while (resolv >> server)
{
- throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
+ if (server == "nameserver")
+ {
+ resolv >> server;
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",server.c_str());
+ return;
+ }
}
- conf->sid = sid;
-
- return true;
+ ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
+ server = "127.0.0.1";
}
+#endif
-static bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueItem &data)
+static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
{
- conf->WhoWasMaxKeep = ServerInstance->Duration(data.GetString());
-
- if (conf->WhoWasGroupSize < 0)
- conf->WhoWasGroupSize = 0;
-
- if (conf->WhoWasMaxGroups < 0)
- conf->WhoWasMaxGroups = 0;
-
- if (conf->WhoWasMaxKeep < 3600)
+ for(int i=0;; ++i)
{
- conf->WhoWasMaxKeep = 3600;
- ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600");
+ ConfigTag* ctag = conf->ConfValue(tag, i);
+ if (!ctag)
+ break;
+ std::string mask;
+ if (!ctag->readString(key, mask))
+ throw CoreException("<"+tag+":"+key+"> missing");
+ std::string reason = ctag->getString("reason", "<Config>");
+ XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask);
+ if (!ServerInstance->XLines->AddLine(xl, NULL))
+ delete xl;
}
-
- Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
- if (whowas)
- {
- WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send();
- }
-
- return true;
}
-/* Callback called to process a single <uline> tag
- */
-static bool DoULine(ServerConfig* conf, const char*, const char**, ValueList &values, int*)
-{
- const char* server = values[0].GetString();
- const bool silent = values[1].GetBool();
- conf->ulines[server] = silent;
- return true;
-}
-
-/* Callback called to process a single <banlist> tag
- */
-static bool DoMaxBans(ServerConfig* conf, const char*, const char**, ValueList &values, int*)
-{
- const char* channel = values[0].GetString();
- int limit = values[1].GetInteger();
- conf->maxbans[channel] = limit;
- return true;
-}
-
-static bool DoZLine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types)
-{
- const char* reason = values[0].GetString();
- const char* ipmask = values[1].GetString();
-
- ZLine* zl = new ZLine(ServerInstance->Time(), 0, "<Config>", reason, ipmask);
- if (!ServerInstance->XLines->AddLine(zl, NULL))
- delete zl;
-
- return true;
-}
-
-static bool DoQLine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types)
-{
- const char* reason = values[0].GetString();
- const char* nick = values[1].GetString();
-
- QLine* ql = new QLine(ServerInstance->Time(), 0, "<Config>", reason, nick);
- if (!ServerInstance->XLines->AddLine(ql, NULL))
- delete ql;
-
- return true;
-}
-
-static bool DoKLine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types)
-{
- const char* reason = values[0].GetString();
- const char* host = values[1].GetString();
-
- XLineManager* xlm = ServerInstance->XLines;
-
- IdentHostPair ih = xlm->IdentSplit(host);
-
- KLine* kl = new KLine(ServerInstance->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
- if (!xlm->AddLine(kl, NULL))
- delete kl;
- return true;
-}
-
-static bool DoELine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types)
-{
- const char* reason = values[0].GetString();
- const char* host = values[1].GetString();
-
- XLineManager* xlm = ServerInstance->XLines;
-
- IdentHostPair ih = xlm->IdentSplit(host);
-
- ELine* el = new ELine(ServerInstance->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
- if (!xlm->AddLine(el, NULL))
- delete el;
- return true;
-}
-
-static bool DoType(ServerConfig* conf, const char*, const char**, ValueList &values, int*)
-{
- const char* TypeName = values[0].GetString();
- const char* Classes = values[1].GetString();
-
- conf->opertypes[TypeName] = std::string(Classes);
- return true;
-}
-
-static bool DoClass(ServerConfig* conf, const char* tag, const char**, ValueList &values, int*)
+void ServerConfig::CrossCheckOperClassType()
{
- const char* ClassName = values[0].GetString();
- const char* CommandList = values[1].GetString();
- const char* UModeList = values[2].GetString();
- const char* CModeList = values[3].GetString();
- const char *PrivsList = values[4].GetString();
-
- for (const char* c = UModeList; *c; ++c)
+ for (int i = 0;; ++i)
{
- if ((*c < 'A' || *c > 'z') && *c != '*')
- {
- throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:usermodes>");
- }
+ ConfigTag* tag = ConfValue("class", i);
+ if (!tag)
+ break;
+ std::string name = tag->getString("name");
+ if (name.empty())
+ throw CoreException("<class:name> is required for all <class> tags");
+ operclass[name] = tag;
}
- for (const char* c = CModeList; *c; ++c)
+ for (int i = 0;; ++i)
{
- if ((*c < 'A' || *c > 'z') && *c != '*')
- {
- throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:chanmodes>");
- }
- }
+ ConfigTag* tag = ConfValue("type", i);
+ if (!tag)
+ break;
- conf->operclass[ClassName].commandlist = CommandList;
- conf->operclass[ClassName].umodelist = UModeList;
- conf->operclass[ClassName].cmodelist = CModeList;
- conf->operclass[ClassName].privs = PrivsList;
- return true;
-}
+ std::string name = tag->getString("name");
+ if (name.empty())
+ throw CoreException("<type:name> is required for all <type> tags");
+ opertypes[name] = tag;
-void ServerConfig::CrossCheckOperClassType()
-{
- for (int i = 0; i < ConfValueEnum("type"); ++i)
- {
- char item[MAXBUF], classn[MAXBUF], classes[MAXBUF];
std::string classname;
- ConfValue("type", "classes", "", i, classes, MAXBUF, false);
- irc::spacesepstream str(classes);
- ConfValue("type", "name", "", i, item, MAXBUF, false);
+ irc::spacesepstream str(tag->getString("classes"));
while (str.GetToken(classname))
{
- std::string lost;
- bool foundclass = false;
- for (int j = 0; j < ConfValueEnum("class"); ++j)
- {
- ConfValue("class", "name", "", j, classn, MAXBUF, false);
- if (!strcmp(classn, classname.c_str()))
- {
- foundclass = true;
- break;
- }
- }
- if (!foundclass)
- {
- char msg[MAXBUF];
- snprintf(msg, MAXBUF, " Warning: Oper type '%s' has a missing class named '%s', this does nothing!\n",
- item, classname.c_str());
- throw CoreException(msg);
- }
+ if (operclass.find(classname) == operclass.end())
+ throw CoreException("Oper type " + name + " has missing class " + classname);
}
}
}
@@ -600,38 +326,41 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
}
}
- int block_count = ConfValueEnum("connect");
ClassMap newBlocksByMask;
- Classes.resize(block_count, NULL);
std::map<std::string, int> names;
bool try_again = true;
- for(int tries=0; try_again && tries < block_count + 1; tries++)
+ for(int tries=0; try_again; tries++)
{
try_again = false;
- for(int i=0; i < block_count; i++)
+ for(unsigned int i=0;; i++)
{
+ ConfigTag* tag = ConfValue("connect", i);
+ if (!tag)
+ break;
+ if (Classes.size() <= i)
+ Classes.resize(i+1);
if (Classes[i])
continue;
ConnectClass* parent = NULL;
- std::string parentName;
- if (ConfValue("connect", "parent", i, parentName, false))
+ std::string parentName = tag->getString("parent");
+ if (!parentName.empty())
{
std::map<std::string,int>::iterator parentIter = names.find(parentName);
if (parentIter == names.end())
{
try_again = true;
// couldn't find parent this time. If it's the last time, we'll never find it.
- if (tries == block_count)
+ if (tries == 50)
throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block " + ConvToStr(i));
continue;
}
parent = Classes[parentIter->second];
}
- std::string name;
- if (ConfValue("connect", "name", i, name, false))
+ std::string name = tag->getString("name");
+ if (!name.empty())
{
if (names.find(name) != names.end())
throw CoreException("Two connect classes with name \"" + name + "\" defined!");
@@ -641,12 +370,12 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
std::string mask, typeMask;
char type;
- if (ConfValue("connect", "allow", i, mask, false))
+ if (tag->readString("allow", mask, false))
{
type = CC_ALLOW;
typeMask = 'a' + mask;
}
- else if (ConfValue("connect", "deny", i, mask, false))
+ else if (tag->readString("deny", mask, false))
{
type = CC_DENY;
typeMask = 'd' + mask;
@@ -666,41 +395,29 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
if (!name.empty())
me->name = name;
- std::string tmpv;
- if (ConfValue("connect", "password", i, tmpv, false))
- me->pass= tmpv;
- if (ConfValue("connect", "hash", i, tmpv, false))
- me->hash = tmpv;
- if (ConfValue("connect", "timeout", i, tmpv, false))
- me->registration_timeout = atol(tmpv.c_str());
- if (ConfValue("connect", "pingfreq", i, tmpv, false))
- me->pingtime = atol(tmpv.c_str());
- if (ConfValue("connect", "sendq", i, tmpv, false))
+ tag->readString("password", me->pass);
+ tag->readString("hash", me->hash);
+ me->registration_timeout = tag->getInt("timeout", me->registration_timeout);
+ me->pingtime = tag->getInt("pingfreq", me->pingtime);
+ std::string sendq;
+ if (tag->readString("sendq", sendq))
{
// attempt to guess a good hard/soft sendq from a single value
- long value = atol(tmpv.c_str());
+ long value = atol(sendq.c_str());
if (value > 16384)
me->softsendqmax = value / 16;
else
me->softsendqmax = value;
me->hardsendqmax = value * 8;
}
- if (ConfValue("connect", "softsendq", i, tmpv, false))
- me->softsendqmax = atol(tmpv.c_str());
- if (ConfValue("connect", "hardsendq", i, tmpv, false))
- me->hardsendqmax = atol(tmpv.c_str());
- if (ConfValue("connect", "recvq", i, tmpv, false))
- me->recvqmax = atol(tmpv.c_str());
- if (ConfValue("connect", "localmax", i, tmpv, false))
- me->maxlocal = atol(tmpv.c_str());
- if (ConfValue("connect", "globalmax", i, tmpv, false))
- me->maxglobal = atol(tmpv.c_str());
- if (ConfValue("connect", "port", i, tmpv, false))
- me->port = atol(tmpv.c_str());
- if (ConfValue("connect", "maxchans", i, tmpv, false))
- me->maxchans = atol(tmpv.c_str());
- if (ConfValue("connect", "limit", i, tmpv, false))
- me->limit = atol(tmpv.c_str());
+ me->softsendqmax = tag->getInt("softsendq", me->softsendqmax);
+ me->hardsendqmax = tag->getInt("hardsendq", me->hardsendqmax);
+ me->recvqmax = tag->getInt("recvq", me->recvqmax);
+ me->maxlocal = tag->getInt("localmax", me->maxlocal);
+ me->maxglobal = tag->getInt("globalmax", me->maxglobal);
+ me->port = tag->getInt("port", me->port);
+ me->maxchans = tag->getInt("maxchans", me->maxchans);
+ me->limit = tag->getInt("limit", me->limit);
ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask);
if (oldMask != oldBlocksByMask.end())
@@ -717,7 +434,6 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
}
}
-
static const Deprecated ChangedConfig[] = {
{"options", "hidelinks", "has been moved to <security:hidelinks> as of 1.2a3"},
{"options", "hidewhois", "has been moved to <security:hidewhois> as of 1.2a3"},
@@ -740,163 +456,170 @@ static const Deprecated ChangedConfig[] = {
{"die", "value", "has always been deprecated"},
};
-/* These tags can occur ONCE or not at all */
-static const InitialConfig Values[] = {
- {"performance", "softlimit", "0", new ValueContainerUInt (&ServerConfig::SoftLimit), DT_INTEGER, ValidateSoftLimit},
- {"performance", "somaxconn", SOMAXCONN_S, new ValueContainerInt (&ServerConfig::MaxConn), DT_INTEGER, ValidateMaxConn},
- {"options", "moronbanner", "You're banned!", new ValueContainerString (&ServerConfig::MoronBanner), DT_CHARPTR, NULL},
- {"server", "name", "", new ValueContainerString (&ServerConfig::ServerName), DT_HOSTNAME, ValidateServerName},
- {"server", "description", "Configure Me", new ValueContainerString (&ServerConfig::ServerDesc), DT_CHARPTR, NULL},
- {"server", "network", "Network", new ValueContainerString (&ServerConfig::Network), DT_NOSPACES, NULL},
- {"server", "id", "", new ValueContainerString (&ServerConfig::sid), DT_CHARPTR, ValidateSID},
- {"admin", "name", "", new ValueContainerString (&ServerConfig::AdminName), DT_CHARPTR, NULL},
- {"admin", "email", "Mis@configu.red", new ValueContainerString (&ServerConfig::AdminEmail), DT_CHARPTR, NULL},
- {"admin", "nick", "Misconfigured", new ValueContainerString (&ServerConfig::AdminNick), DT_CHARPTR, NULL},
- {"files", "motd", "", new ValueContainerString (&ServerConfig::motd), DT_CHARPTR, ValidateMotd},
- {"files", "rules", "", new ValueContainerString (&ServerConfig::rules), DT_CHARPTR, ValidateRules},
- {"power", "diepass", "", new ValueContainerString (&ServerConfig::diepass), DT_CHARPTR, ValidateNotEmpty},
- {"power", "pause", "", new ValueContainerInt (&ServerConfig::DieDelay), DT_INTEGER, NULL},
- {"power", "hash", "", new ValueContainerString (&ServerConfig::powerhash), DT_CHARPTR, NULL},
- {"power", "restartpass", "", new ValueContainerString (&ServerConfig::restartpass), DT_CHARPTR, ValidateNotEmpty},
- {"options", "prefixquit", "", new ValueContainerString (&ServerConfig::PrefixQuit), DT_CHARPTR, NULL},
- {"options", "suffixquit", "", new ValueContainerString (&ServerConfig::SuffixQuit), DT_CHARPTR, NULL},
- {"options", "fixedquit", "", new ValueContainerString (&ServerConfig::FixedQuit), DT_CHARPTR, NULL},
- {"options", "prefixpart", "", new ValueContainerString (&ServerConfig::PrefixPart), DT_CHARPTR, NULL},
- {"options", "suffixpart", "", new ValueContainerString (&ServerConfig::SuffixPart), DT_CHARPTR, NULL},
- {"options", "fixedpart", "", new ValueContainerString (&ServerConfig::FixedPart), DT_CHARPTR, NULL},
- {"performance", "netbuffersize","10240", new ValueContainerInt (&ServerConfig::NetBufferSize), DT_INTEGER, ValidateNetBufferSize},
- {"performance", "maxwho", "1024", new ValueContainerInt (&ServerConfig::MaxWhoResults), DT_INTEGER, ValidateMaxWho},
- {"options", "allowhalfop", "0", new ValueContainerBool (&ServerConfig::AllowHalfop), DT_BOOLEAN, ValidateHalfOp},
- {"dns", "server", "", new ValueContainerString (&ServerConfig::DNSServer), DT_IPADDRESS,ValidateDnsServer},
- {"dns", "timeout", "5", new ValueContainerInt (&ServerConfig::dns_timeout), DT_INTEGER, NULL},
- {"options", "moduledir", MOD_PATH, new ValueContainerString (&ServerConfig::ModPath), DT_CHARPTR, NULL},
- {"disabled", "commands", "", new ValueContainerString (&ServerConfig::DisabledCommands), DT_CHARPTR, NULL},
- {"disabled", "usermodes", "", NULL, DT_NOTHING, ValidateDisabledUModes},
- {"disabled", "chanmodes", "", NULL, DT_NOTHING, ValidateDisabledCModes},
- {"disabled", "fakenonexistant", "0", new ValueContainerBool (&ServerConfig::DisabledDontExist), DT_BOOLEAN, NULL},
-
- {"security", "runasuser", "", new ValueContainerString(&ServerConfig::SetUser), DT_CHARPTR, NULL},
- {"security", "runasgroup", "", new ValueContainerString(&ServerConfig::SetGroup), DT_CHARPTR, NULL},
- {"security", "userstats", "", new ValueContainerString (&ServerConfig::UserStats), DT_CHARPTR, NULL},
- {"security", "customversion","", new ValueContainerString (&ServerConfig::CustomVersion), DT_CHARPTR, NULL},
- {"security", "hidesplits", "0", new ValueContainerBool (&ServerConfig::HideSplits), DT_BOOLEAN, NULL},
- {"security", "hidebans", "0", new ValueContainerBool (&ServerConfig::HideBans), DT_BOOLEAN, NULL},
- {"security", "hidewhois", "", new ValueContainerString (&ServerConfig::HideWhoisServer), DT_NOSPACES, NULL},
- {"security", "hidekills", "", new ValueContainerString (&ServerConfig::HideKillsServer), DT_NOSPACES, NULL},
- {"security", "operspywhois", "0", new ValueContainerBool (&ServerConfig::OperSpyWhois), DT_BOOLEAN, NULL},
- {"security", "restrictbannedusers", "1", new ValueContainerBool (&ServerConfig::RestrictBannedUsers), DT_BOOLEAN, NULL},
- {"security", "genericoper", "0", new ValueContainerBool (&ServerConfig::GenericOper), DT_BOOLEAN, NULL},
- {"performance", "nouserdns", "0", new ValueContainerBool (&ServerConfig::NoUserDns), DT_BOOLEAN, NULL},
- {"options", "syntaxhints", "0", new ValueContainerBool (&ServerConfig::SyntaxHints), DT_BOOLEAN, NULL},
- {"options", "cyclehosts", "0", new ValueContainerBool (&ServerConfig::CycleHosts), DT_BOOLEAN, NULL},
- {"options", "ircumsgprefix","0", new ValueContainerBool (&ServerConfig::UndernetMsgPrefix), DT_BOOLEAN, NULL},
- {"security", "announceinvites", "1", NULL, DT_NOTHING, ValidateInvite},
- {"options", "hostintopic", "1", new ValueContainerBool (&ServerConfig::FullHostInTopic), DT_BOOLEAN, NULL},
- {"security", "hidemodes", "", NULL, DT_NOTHING, ValidateModeLists},
- {"security", "maxtargets", "20", new ValueContainerUInt (&ServerConfig::MaxTargets), DT_INTEGER, ValidateMaxTargets},
- {"options", "defaultmodes", "nt", new ValueContainerString (&ServerConfig::DefaultModes), DT_CHARPTR, NULL},
- {"pid", "file", "", new ValueContainerString (&ServerConfig::PID), DT_CHARPTR, NULL},
- {"whowas", "groupsize", "10", new ValueContainerInt (&ServerConfig::WhoWasGroupSize), DT_INTEGER, NULL},
- {"whowas", "maxgroups", "10240", new ValueContainerInt (&ServerConfig::WhoWasMaxGroups), DT_INTEGER, NULL},
- {"whowas", "maxkeep", "3600", NULL, DT_NOTHING, ValidateWhoWas},
- {"die", "value", "", new ValueContainerString (&ServerConfig::DieValue), DT_CHARPTR, NULL},
- {"channels", "users", "20", new ValueContainerUInt (&ServerConfig::MaxChans), DT_INTEGER, NULL},
- {"channels", "opers", "60", new ValueContainerUInt (&ServerConfig::OperMaxChans), DT_INTEGER, NULL},
- {"cidr", "ipv4clone", "32", new ValueContainerInt (&ServerConfig::c_ipv4_range), DT_INTEGER, NULL},
- {"cidr", "ipv6clone", "128", new ValueContainerInt (&ServerConfig::c_ipv6_range), DT_INTEGER, NULL},
- {"limits", "maxnick", "32", new ValueContainerLimit (&ServerLimits::NickMax), DT_LIMIT, NULL},
- {"limits", "maxchan", "64", new ValueContainerLimit (&ServerLimits::ChanMax), DT_LIMIT, NULL},
- {"limits", "maxmodes", "20", new ValueContainerLimit (&ServerLimits::MaxModes), DT_LIMIT, NULL},
- {"limits", "maxident", "11", new ValueContainerLimit (&ServerLimits::IdentMax), DT_LIMIT, NULL},
- {"limits", "maxquit", "255", new ValueContainerLimit (&ServerLimits::MaxQuit), DT_LIMIT, NULL},
- {"limits", "maxtopic", "307", new ValueContainerLimit (&ServerLimits::MaxTopic), DT_LIMIT, NULL},
- {"limits", "maxkick", "255", new ValueContainerLimit (&ServerLimits::MaxKick), DT_LIMIT, NULL},
- {"limits", "maxgecos", "128", new ValueContainerLimit (&ServerLimits::MaxGecos), DT_LIMIT, NULL},
- {"limits", "maxaway", "200", new ValueContainerLimit (&ServerLimits::MaxAway), DT_LIMIT, NULL},
- {"options", "invitebypassmodes", "1", new ValueContainerBool (&ServerConfig::InvBypassModes), DT_BOOLEAN, NULL},
-};
+void ServerConfig::Fill()
+{
+ ReqRead(this, "server", "name", ServerName);
+ ReqRead(this, "power", "diepass", diepass);
+ ReqRead(this, "power", "restartpass", restartpass);
+
+ ConfigTag* options = ConfValue("options");
+ ConfigTag* security = ConfValue("security");
+ powerhash = ConfValue("power")->getString("hash");
+ DieDelay = ConfValue("power")->getInt("pause");
+ PrefixQuit = options->getString("prefixquit");
+ SuffixQuit = options->getString("suffixquit");
+ FixedQuit = options->getString("fixedquit");
+ PrefixPart = options->getString("prefixpart");
+ SuffixPart = options->getString("suffixpart");
+ FixedPart = options->getString("fixedpart");
+ SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds());
+ MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
+ MoronBanner = options->getString("moronbanner", "You're banned!");
+ ServerDesc = ConfValue("server")->getString("description", "Configure Me");
+ Network = ConfValue("server")->getString("network", "Network");
+ sid = ConfValue("server")->getString("id", "");
+ AdminName = ConfValue("admin")->getString("name", "");
+ AdminEmail = ConfValue("admin")->getString("email", "null@example.com");
+ AdminNick = ConfValue("admin")->getString("nick", "admin");
+ ModPath = options->getString("moduledir", MOD_PATH);
+ NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240);
+ MaxWhoResults = ConfValue("performance")->getInt("maxwho", 1024);
+ DNSServer = ConfValue("dns")->getString("server");
+ dns_timeout = ConfValue("dns")->getInt("timeout", 5);
+ DisabledCommands = ConfValue("disabled")->getString("commands", "");
+ DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
+ SetUser = security->getString("runasuser");
+ SetGroup = security->getString("runasgroup");
+ UserStats = security->getString("userstats");
+ CustomVersion = security->getString("customversion");
+ HideSplits = security->getBool("hidesplits");
+ HideBans = security->getBool("hidebans");
+ HideWhoisServer = security->getString("hidewhois");
+ HideKillsServer = security->getString("hidekills");
+ OperSpyWhois = security->getBool("operspywhois");
+ RestrictBannedUsers = security->getBool("restrictbannedusers");
+ GenericOper = security->getBool("genericoper");
+ NoUserDns = ConfValue("performance")->getBool("nouserdns");
+ SyntaxHints = options->getBool("syntaxhints");
+ CycleHosts = options->getBool("cyclehosts");
+ UndernetMsgPrefix = options->getBool("ircumsgprefix");
+ FullHostInTopic = options->getBool("hostintopic");
+ MaxTargets = security->getInt("maxtargets");
+ DefaultModes = options->getString("defaultmodes");
+ PID = ConfValue("pid")->getString("file");
+ WhoWasGroupSize = ConfValue("whowas")->getInt("groupsize");
+ WhoWasMaxGroups = ConfValue("whowas")->getInt("maxgroups");
+ WhoWasMaxKeep = ServerInstance->Duration(ConfValue("whowas")->getString("maxkeep"));
+ DieValue = ConfValue("die")->getString("value");
+ MaxChans = ConfValue("channels")->getInt("users");
+ OperMaxChans = ConfValue("channels")->getInt("opers");
+ c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone");
+ c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone");
+ Limits.NickMax = ConfValue("limits")->getInt("maxnick");
+ Limits.ChanMax = ConfValue("limits")->getInt("maxchan");
+ Limits.MaxModes = ConfValue("limits")->getInt("maxmodes");
+ Limits.IdentMax = ConfValue("limits")->getInt("maxident");
+ Limits.MaxQuit = ConfValue("limits")->getInt("maxquit");
+ Limits.MaxTopic = ConfValue("limits")->getInt("maxtopic");
+ Limits.MaxKick = ConfValue("limits")->getInt("maxkick");
+ Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos");
+ Limits.MaxAway = ConfValue("limits")->getInt("maxaway");
+ InvBypassModes = options->getBool("invitebypassmodes");
+
+ ReadFile(MOTD, ConfValue("files")->getString("motd"));
+ ReadFile(RULES, ConfValue("files")->getString("rules"));
+ ValidateDnsServer(DNSServer);
+
+ range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>");
+ range(MaxConn, 0, SOMAXCONN, SOMAXCONN, "<performance:somaxconn>");
+ range(MaxTargets, 1, 31, 20, "<security:maxtargets>");
+ range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>");
+ range(MaxWhoResults, 1, 65535, 1024, "<performace:maxwho>");
+ range(WhoWasGroupSize, 0, 10000, 10, "<whowas:groupsize>");
+ range(WhoWasMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>");
+ range(WhoWasMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>");
+
+ ValidHost(ServerName, "<server:name>");
+ if (!sid.empty() && !ServerInstance->IsSID(sid))
+ throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
+
+ for (int i = 0;; ++i)
+ {
+ ConfigTag* tag = ConfValue("uline", i);
+ if (!tag)
+ break;
+ std::string server;
+ if (!tag->readString("server", server))
+ throw CoreException("<uline> tag missing server");
+ ulines[assign(server)] = tag->getBool("silent");
+ }
-InitialConfig::~InitialConfig()
-{
- delete val;
-}
+ for(int i=0;; ++i)
+ {
+ ConfigTag* tag = ConfValue("banlist", i);
+ if (!tag)
+ break;
+ std::string chan;
+ if (!tag->readString("chan", chan))
+ throw CoreException("<banlist> tag missing chan");
+ maxbans[chan] = tag->getInt("limit");
+ }
-/* These tags can occur multiple times, and therefore they have special code to read them
- * which is different to the code for reading the singular tags listed above.
- */
-MultiConfig MultiValues[] = {
-
- {"connect",
- {"allow", "deny", "password", "timeout", "pingfreq",
- "sendq", "recvq", "localmax", "globalmax", "port",
- "name", "parent", "maxchans", "limit", "hash",
- NULL},
- {"", "", "", "", "120",
- "", "", "3", "3", "0",
- "", "", "0", "0", "",
- NULL},
- {DT_IPADDRESS|DT_ALLOW_WILD, DT_IPADDRESS|DT_ALLOW_WILD, DT_CHARPTR, DT_INTEGER, DT_INTEGER,
- DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER,
- DT_NOSPACES, DT_NOSPACES, DT_INTEGER, DT_INTEGER, DT_CHARPTR},
- NULL,},
-
- {"uline",
- {"server", "silent", NULL},
- {"", "0", NULL},
- {DT_HOSTNAME, DT_BOOLEAN},
- DoULine},
-
- {"banlist",
- {"chan", "limit", NULL},
- {"", "", NULL},
- {DT_CHARPTR, DT_INTEGER},
- DoMaxBans},
-
- {"module",
- {"name", NULL},
- {"", NULL},
- {DT_CHARPTR},
- NULL},
-
- {"badip",
- {"reason", "ipmask", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_IPADDRESS|DT_ALLOW_WILD},
- DoZLine},
-
- {"badnick",
- {"reason", "nick", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_CHARPTR},
- DoQLine},
-
- {"badhost",
- {"reason", "host", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_CHARPTR},
- DoKLine},
-
- {"exception",
- {"reason", "host", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_CHARPTR},
- DoELine},
-
- {"type",
- {"name", "classes", NULL},
- {"", "", NULL},
- {DT_NOSPACES, DT_CHARPTR},
- DoType},
-
- {"class",
- {"name", "commands", "usermodes", "chanmodes", "privs", NULL},
- {"", "", "", "", "", NULL},
- {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR},
- DoClass},
-};
+ ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
+ ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
+ ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
+ ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E"));
+
+ memset(DisabledUModes, 0, sizeof(DisabledUModes));
+ for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("usermodes").c_str(); *p; ++p)
+ {
+ if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found.");
+ DisabledUModes[*p - 'A'] = 1;
+ }
+
+ memset(DisabledCModes, 0, sizeof(DisabledCModes));
+ for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("chanmodes").c_str(); *p; ++p)
+ {
+ if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found.");
+ DisabledCModes[*p - 'A'] = 1;
+ }
+
+ memset(HideModeLists, 0, sizeof(HideModeLists));
+ for (const unsigned char* p = (const unsigned char*)ConfValue("security")->getString("hidemodes").c_str(); *p; ++p)
+ HideModeLists[*p] = true;
+
+ std::string v = security->getString("announceinvites");
+
+ if (v == "ops")
+ AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
+ else if (v == "all")
+ AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
+ else if (v == "dynamic")
+ AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
+ else
+ AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
+
+ bool AllowHalfOp = options->getBool("allowhalfop");
+ ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL);
+ if (AllowHalfOp && !mh) {
+ ServerInstance->Logs->Log("CONFIG", DEFAULT, "Enabling halfop mode.");
+ mh = new ModeChannelHalfOp;
+ ServerInstance->Modes->AddMode(mh);
+ } else if (!AllowHalfOp && mh) {
+ ServerInstance->Logs->Log("CONFIG", DEFAULT, "Disabling halfop mode.");
+ ServerInstance->Modes->DelMode(mh);
+ delete mh;
+ }
+
+ Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
+ if (whowas)
+ WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send();
+ Limits.Finalise();
+
+}
/* These tags MUST occur and must ONLY occur once in the config file */
-static const char* Once[] = { "server", "admin", "files", "power", "options" };
+static const char* const Once[] = { "server", "admin", "files", "power", "options" };
// WARNING: it is not safe to use most of the codebase in this function, as it
// will run in the config reader thread
@@ -929,190 +652,12 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
for (int Index = 0; Index * sizeof(Deprecated) < sizeof(ChangedConfig); Index++)
{
- char item[MAXBUF];
- *item = 0;
- if (ConfValue(ChangedConfig[Index].tag, ChangedConfig[Index].value, "", 0, item, MAXBUF, true) || *item)
+ std::string dummy;
+ if (ConfValue(ChangedConfig[Index].tag)->readString(ChangedConfig[Index].value, dummy, true))
throw CoreException(std::string("Your configuration contains a deprecated value: <") + ChangedConfig[Index].tag + ":" + ChangedConfig[Index].value + "> - " + ChangedConfig[Index].reason);
}
- /* Read the values of all the tags which occur once or not at all, and call their callbacks.
- */
- for (int Index = 0; Index * sizeof(*Values) < sizeof(Values); ++Index)
- {
- char item[MAXBUF];
- int dt = Values[Index].datatype;
- bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
- bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
- dt &= ~DT_ALLOW_NEWLINE;
- dt &= ~DT_ALLOW_WILD;
-
- ConfValue(Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines);
- ValueItem vi(item);
-
- if (Values[Index].validation_function && !Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
- throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
-
- switch (dt)
- {
- case DT_NOSPACES:
- {
- ValueContainerString* vcc = (ValueContainerString*)Values[Index].val;
- ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value);
- vcc->Set(this, vi.GetValue());
- }
- break;
- case DT_HOSTNAME:
- {
- ValueContainerString* vcc = (ValueContainerString*)Values[Index].val;
- ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value);
- vcc->Set(this, vi.GetValue());
- }
- break;
- case DT_IPADDRESS:
- {
- ValueContainerString* vcc = (ValueContainerString*)Values[Index].val;
- ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild);
- vcc->Set(this, vi.GetValue());
- }
- break;
- case DT_CHANNEL:
- {
- ValueContainerString* vcc = (ValueContainerString*)Values[Index].val;
- if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF))
- {
- throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name");
- }
- vcc->Set(this, vi.GetValue());
- }
- break;
- case DT_CHARPTR:
- {
- ValueContainerString* vcs = dynamic_cast<ValueContainerString*>(Values[Index].val);
- if (vcs)
- vcs->Set(this, vi.GetValue());
- }
- break;
- case DT_INTEGER:
- {
- int val = vi.GetInteger();
- ValueContainerInt* vci = (ValueContainerInt*)Values[Index].val;
- vci->Set(this, val);
- }
- break;
- case DT_LIMIT:
- {
- int val = vi.GetInteger();
- ValueContainerLimit* vci = (ValueContainerLimit*)Values[Index].val;
- vci->Set(this, val);
- }
- break;
- case DT_BOOLEAN:
- {
- bool val = vi.GetBool();
- ValueContainerBool* vcb = (ValueContainerBool*)Values[Index].val;
- vcb->Set(this, val);
- }
- break;
- }
- }
-
- /* Read the multiple-tag items (class tags, connect tags, etc)
- * and call the callbacks associated with them. We have three
- * callbacks for these, a 'start', 'item' and 'end' callback.
- */
- for (int Index = 0; Index * sizeof(MultiConfig) < sizeof(MultiValues); ++Index)
- {
- int number_of_tags = ConfValueEnum(MultiValues[Index].tag);
-
- for (int tagnum = 0; tagnum < number_of_tags; ++tagnum)
- {
- ValueList vl;
- for (int valuenum = 0; (MultiValues[Index].items[valuenum]) && (valuenum < MAX_VALUES_PER_TAG); ++valuenum)
- {
- int dt = MultiValues[Index].datatype[valuenum];
- bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
- bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
- dt &= ~DT_ALLOW_NEWLINE;
- dt &= ~DT_ALLOW_WILD;
-
- switch (dt)
- {
- case DT_NOSPACES:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- ValidateNoSpaces(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
- }
- break;
- case DT_HOSTNAME:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- ValidateHostname(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
- }
- break;
- case DT_IPADDRESS:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- ValidateIP(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild);
- }
- break;
- case DT_CHANNEL:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- if (!ServerInstance->IsChannel(vl[vl.size()-1].GetString(), MAXBUF))
- throw CoreException("The value of <"+std::string(MultiValues[Index].tag)+":"+MultiValues[Index].items[valuenum]+"> number "+ConvToStr(tagnum + 1)+" is not a valid channel name");
- }
- break;
- case DT_CHARPTR:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- }
- break;
- case DT_INTEGER:
- {
- int item = 0;
- if (ConfValueInteger(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(0));
- }
- break;
- case DT_BOOLEAN:
- {
- bool item = ConfValueBool(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum);
- vl.push_back(ValueItem(item));
- }
- break;
- }
- }
- if (MultiValues[Index].validation_function)
- MultiValues[Index].validation_function(this, MultiValues[Index].tag, MultiValues[Index].items, vl, MultiValues[Index].datatype);
- }
- }
-
- /* Finalise the limits, increment them all by one so that we can just put assign(str, 0, val)
- * rather than assign(str, 0, val + 1)
- */
- Limits.Finalise();
+ Fill();
// Handle special items
CrossCheckOperClassType();
@@ -1206,11 +751,13 @@ void ServerConfig::ApplyModules(User* user)
std::vector<std::string> added_modules;
std::set<std::string> removed_modules(v.begin(), v.end());
- int new_module_count = ConfValueEnum("module");
- for(int i=0; i < new_module_count; i++)
+ for(int i=0; ; i++)
{
+ ConfigTag* tag = ConfValue("module", i);
+ if (!tag)
+ break;
std::string name;
- if (ConfValue("module", "name", i, name, false))
+ if (tag->readString("name", name))
{
// if this module is already loaded, the erase will succeed, so we need do nothing
// otherwise, we need to add the module (which will be done later)
@@ -1490,17 +1037,16 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon
std::string tagname;
std::string current_key;
std::string current_value;
- KeyValList results;
+ reference<ConfigTag> result;
char last_char = 0;
- bool got_name;
bool got_key;
bool in_quote;
- got_name = got_key = in_quote = false;
+ got_key = in_quote = false;
for(std::string::iterator c = line.begin(); c != line.end(); c++)
{
- if (!got_name)
+ if (!result)
{
/* We don't know the tag name yet. */
@@ -1522,7 +1068,7 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon
/* We got to a space, we should have the tagname now. */
if(tagname.length())
{
- got_name = true;
+ result = new ConfigTag(tagname);
}
}
}
@@ -1594,7 +1140,7 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon
else
{
/* Leaving the quotes, we have the current value */
- results.push_back(KeyVal(current_key, current_value));
+ result->items.push_back(KeyVal(current_key, current_value));
// std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl;
@@ -1639,7 +1185,7 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon
}
/* Finished parsing the tag, add it to the config hash */
- config_data.insert(std::pair<std::string, KeyValList > (tagname, results));
+ config_data.insert(std::make_pair(tagname, result));
return true;
}
@@ -1681,193 +1227,97 @@ bool ServerConfig::DoInclude(const std::string &file, bool allowexeinc)
return ret;
}
-bool ServerConfig::ConfValue(const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds)
-{
- return ConfValue(tag, var, "", index, result, length, allow_linefeeds);
-}
-
-bool ServerConfig::ConfValue(const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds)
+ConfigTag* ServerConfig::ConfValue(const std::string &tag, int offset)
{
- std::string value;
- bool r = ConfValue(std::string(tag), std::string(var), std::string(default_value), index, value, allow_linefeeds);
- strlcpy(result, value.c_str(), length);
- return r;
-}
+ ConfigDataHash::size_type pos = offset;
+ if (pos >= config_data.count(tag))
+ return NULL;
+
+ ConfigDataHash::iterator iter = config_data.find(tag);
-bool ServerConfig::ConfValue(const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds)
-{
- return ConfValue(tag, var, "", index, result, allow_linefeeds);
+ for(int i = 0; i < offset; i++)
+ iter++;
+
+ return iter->second;
}
-bool ServerConfig::ConfValue(const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds)
+bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf)
{
- ConfigDataHash::size_type pos = index;
- if (pos < config_data.count(tag))
- {
- ConfigDataHash::iterator iter = config_data.find(tag);
-
- for(int i = 0; i < index; i++)
- iter++;
-
- for(KeyValList::iterator j = iter->second.begin(); j != iter->second.end(); j++)
- {
- if(j->first == var)
- {
- if ((!allow_linefeeds) && (j->second.find('\n') != std::string::npos))
- {
- ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + var+ "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces.");
- for (std::string::iterator n = j->second.begin(); n != j->second.end(); n++)
- if (*n == '\n')
- *n = ' ';
- }
- else
- {
- result = j->second;
- return true;
- }
- }
- }
- if (!default_value.empty())
- {
- result = default_value;
- return true;
- }
- }
- else if (pos == 0)
+ if (!this)
+ return false;
+ for(std::vector<KeyVal>::iterator j = items.begin(); j != items.end(); ++j)
{
- if (!default_value.empty())
+ if(j->first != key)
+ continue;
+ value = j->second;
+ if (!allow_lf && (value.find('\n') != std::string::npos))
{
- result = default_value;
- return true;
+ ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + key + "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces.");
+ for (std::string::iterator n = value.begin(); n != value.end(); n++)
+ if (*n == '\n')
+ *n = ' ';
}
+ return true;
}
return false;
}
-bool ServerConfig::ConfValueInteger(const char* tag, const char* var, int index, int &result)
-{
- return ConfValueInteger(std::string(tag), std::string(var), "", index, result);
-}
-
-bool ServerConfig::ConfValueInteger(const char* tag, const char* var, const char* default_value, int index, int &result)
-{
- return ConfValueInteger(std::string(tag), std::string(var), std::string(default_value), index, result);
-}
-
-bool ServerConfig::ConfValueInteger(const std::string &tag, const std::string &var, int index, int &result)
+std::string ConfigTag::getString(const std::string& key, const std::string& def)
{
- return ConfValueInteger(tag, var, "", index, result);
+ std::string res = def;
+ if (this)
+ readString(key, res);
+ return res;
}
-bool ServerConfig::ConfValueInteger(const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result)
+long ConfigTag::getInt(const std::string &key, long def)
{
- std::string value;
- std::istringstream stream;
- bool r = ConfValue(tag, var, default_value, index, value);
- stream.str(value);
- if(!(stream >> result))
- return false;
- else
+ std::string result;
+ if(!this || !readString(key, result))
+ return def;
+
+ const char* res_cstr = result.c_str();
+ char* res_tail = NULL;
+ long res = strtol(res_cstr, &res_tail, 0);
+ if (res_tail == res_cstr)
+ return def;
+ switch (toupper(*res_tail))
{
- if (!value.empty())
- {
- if (value.substr(0,2) == "0x")
- {
- char* endptr;
-
- value.erase(0,2);
- result = strtol(value.c_str(), &endptr, 16);
-
- /* No digits found */
- if (endptr == value.c_str())
- return false;
- }
- else
- {
- char denominator = *(value.end() - 1);
- switch (toupper(denominator))
- {
- case 'K':
- /* Kilobytes -> bytes */
- result = result * 1024;
- break;
- case 'M':
- /* Megabytes -> bytes */
- result = result * 1024 * 1024;
- break;
- case 'G':
- /* Gigabytes -> bytes */
- result = result * 1024 * 1024 * 1024;
- break;
- }
- }
- }
+ case 'K':
+ res= res* 1024;
+ break;
+ case 'M':
+ res= res* 1024 * 1024;
+ break;
+ case 'G':
+ res= res* 1024 * 1024 * 1024;
+ break;
}
- return r;
+ return res;
}
-
-bool ServerConfig::ConfValueBool(const char* tag, const char* var, int index)
-{
- return ConfValueBool(std::string(tag), std::string(var), "", index);
-}
-
-bool ServerConfig::ConfValueBool(const char* tag, const char* var, const char* default_value, int index)
-{
- return ConfValueBool(std::string(tag), std::string(var), std::string(default_value), index);
-}
-
-bool ServerConfig::ConfValueBool(const std::string &tag, const std::string &var, int index)
-{
- return ConfValueBool(tag, var, "", index);
-}
-
-bool ServerConfig::ConfValueBool(const std::string &tag, const std::string &var, const std::string &default_value, int index)
+double ConfigTag::getFloat(const std::string &key, double def)
{
std::string result;
- if(!ConfValue(tag, var, default_value, index, result))
- return false;
-
- return ((result == "yes") || (result == "true") || (result == "1"));
-}
-
-int ServerConfig::ConfValueEnum(const char* tag)
-{
- return config_data.count(tag);
-}
-
-int ServerConfig::ConfValueEnum(const std::string &tag)
-{
- return config_data.count(tag);
+ if (!readString(key, result))
+ return def;
+ return strtod(result.c_str(), NULL);
}
-int ServerConfig::ConfVarEnum(const char* tag, int index)
+bool ConfigTag::getBool(const std::string &key, bool def)
{
- return ConfVarEnum(std::string(tag), index);
-}
-
-int ServerConfig::ConfVarEnum(const std::string &tag, int index)
-{
- ConfigDataHash::size_type pos = index;
-
- if (pos < config_data.count(tag))
- {
- ConfigDataHash::const_iterator iter = config_data.find(tag);
-
- for(int i = 0; i < index; i++)
- iter++;
-
- return iter->second.size();
- }
+ std::string result;
+ if(!readString(key, result))
+ return def;
- return 0;
+ return (result == "yes" || result == "true" || result == "1" || result == "on");
}
/** Read the contents of a file located by `fname' into a file_cache pointed at by `F'.
*/
-bool ServerConfig::ReadFile(file_cache &F, const char* fname)
+bool ServerConfig::ReadFile(file_cache &F, const std::string& fname)
{
- if (!fname || !*fname)
+ if (fname.empty())
return false;
FILE* file = NULL;
@@ -1875,9 +1325,9 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
F.clear();
- if (!FileExists(fname))
+ if (!FileExists(fname.c_str()))
return false;
- file = fopen(fname, "r");
+ file = fopen(fname.c_str(), "r");
if (file)
{
@@ -1931,50 +1381,6 @@ std::string ServerConfig::GetSID()
return sid;
}
-ValueItem::ValueItem(int value)
-{
- std::stringstream n;
- n << value;
- v = n.str();
-}
-
-ValueItem::ValueItem(bool value)
-{
- std::stringstream n;
- n << value;
- v = n.str();
-}
-
-void ValueItem::Set(const std::string& value)
-{
- v = value;
-}
-
-void ValueItem::Set(int value)
-{
- std::stringstream n;
- n << value;
- v = n.str();
-}
-
-int ValueItem::GetInteger()
-{
- if (v.empty())
- return 0;
- return atoi(v.c_str());
-}
-
-const char* ValueItem::GetString() const
-{
- return v.c_str();
-}
-
-bool ValueItem::GetBool()
-{
- return (GetInteger() || v == "yes" || v == "true");
-}
-
-
void ConfigReaderThread::Run()
{
Config = new ServerConfig;