summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2013-07-10 14:28:05 +0100
committerPeter Powell <petpow@saberuk.com>2013-08-10 14:04:09 +0100
commit86f650e6b8c969b31fae65ea1143644723279b82 (patch)
treeca746c6fb3f5aa59215639ee5a8ab798b1f47862 /src
parenta2720d169743cda1b7812b28f79a34fd33802e72 (diff)
Replace range() with min and max arguments on getInt().
Diffstat (limited to 'src')
-rw-r--r--src/commands/cmd_whowas.cpp6
-rw-r--r--src/configparser.cpp14
-rw-r--r--src/configreader.cpp20
-rw-r--r--src/modules/m_blockcaps.cpp14
-rw-r--r--src/modules/m_connectban.cpp15
5 files changed, 20 insertions, 49 deletions
diff --git a/src/commands/cmd_whowas.cpp b/src/commands/cmd_whowas.cpp
index 28daf7311..8a1c9a820 100644
--- a/src/commands/cmd_whowas.cpp
+++ b/src/commands/cmd_whowas.cpp
@@ -342,12 +342,10 @@ class ModuleWhoWas : public Module
void OnRehash(User* user)
{
ConfigTag* tag = ServerInstance->Config->ConfValue("whowas");
- int NewGroupSize = tag->getInt("groupsize");
- int NewMaxGroups = tag->getInt("maxgroups");
+ int NewGroupSize = tag->getInt("groupsize", 10, 0, 10000);
+ int NewMaxGroups = tag->getInt("maxgroups", 10240, 0, 1000000);
int NewMaxKeep = InspIRCd::Duration(tag->getString("maxkeep"));
- RangeCheck(NewGroupSize, 0, 10000, 10, "<whowas:groupsize>");
- RangeCheck(NewMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>");
RangeCheck(NewMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>");
if ((NewGroupSize == cmd.WhoWasGroupSize) && (NewMaxGroups == cmd.WhoWasMaxGroups) && (NewMaxKeep == cmd.WhoWasMaxKeep))
diff --git a/src/configparser.cpp b/src/configparser.cpp
index 3289cf396..f3e79e2fd 100644
--- a/src/configparser.cpp
+++ b/src/configparser.cpp
@@ -420,7 +420,7 @@ std::string ConfigTag::getString(const std::string& key, const std::string& def)
return res;
}
-long ConfigTag::getInt(const std::string &key, long def)
+long ConfigTag::getInt(const std::string &key, long def, long min, long max)
{
std::string result;
if(!readString(key, result))
@@ -434,15 +434,21 @@ long ConfigTag::getInt(const std::string &key, long def)
switch (toupper(*res_tail))
{
case 'K':
- res= res* 1024;
+ res = res * 1024;
break;
case 'M':
- res= res* 1024 * 1024;
+ res = res * 1024 * 1024;
break;
case 'G':
- res= res* 1024 * 1024 * 1024;
+ res = res * 1024 * 1024 * 1024;
break;
}
+ if (res < min || res > max)
+ {
+ ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: <%s:%s> value of %ld is not between %ld and %ld; set to %ld.",
+ tag.c_str(), key.c_str(), res, min, max, def);
+ res = def;
+ }
return res;
}
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 2dbd6e606..e697113e2 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -44,16 +44,6 @@ ServerConfig::ServerConfig()
c_ipv6_range = 128;
}
-template<typename T, typename V>
-static void range(T& value, V min, V max, V def, const char* msg)
-{
- if (value >= (T)min && value <= (T)max)
- return;
- ServerInstance->Logs->Log("CONFIG", LOG_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 ValidHost(const std::string& p, const std::string& msg)
{
int num_dots = 0;
@@ -384,7 +374,7 @@ void ServerConfig::Fill()
PrefixPart = options->getString("prefixpart");
SuffixPart = options->getString("suffixpart");
FixedPart = options->getString("fixedpart");
- SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds());
+ SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds(), 10, ServerInstance->SE->GetMaxFds());
CCOnConnect = ConfValue("performance")->getBool("clonesonconnect", true);
MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
MoronBanner = options->getString("moronbanner", "You're banned!");
@@ -394,7 +384,7 @@ void ServerConfig::Fill()
AdminEmail = ConfValue("admin")->getString("email", "null@example.com");
AdminNick = ConfValue("admin")->getString("nick", "admin");
ModPath = ConfValue("path")->getString("moduledir", MOD_PATH);
- NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240);
+ NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240, 1024, 65534);
dns_timeout = ConfValue("dns")->getInt("timeout", 5);
DisabledCommands = ConfValue("disabled")->getString("commands", "");
DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
@@ -410,7 +400,7 @@ void ServerConfig::Fill()
CycleHostsFromUser = options->getBool("cyclehostsfromuser");
UndernetMsgPrefix = options->getBool("ircumsgprefix");
FullHostInTopic = options->getBool("hostintopic");
- MaxTargets = security->getInt("maxtargets", 20);
+ MaxTargets = security->getInt("maxtargets", 20, 1, 31);
DefaultModes = options->getString("defaultmodes", "nt");
PID = ConfValue("pid")->getString("file");
MaxChans = ConfValue("channels")->getInt("users", 20);
@@ -433,10 +423,6 @@ void ServerConfig::Fill()
if (Network.find(' ') != std::string::npos)
throw CoreException(Network + " is not a valid network name. A network name must not contain spaces.");
- range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>");
- range(MaxTargets, 1, 31, 20, "<security:maxtargets>");
- range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>");
-
std::string defbind = options->getString("defaultbind");
if (assign(defbind) == "ipv4")
{
diff --git a/src/modules/m_blockcaps.cpp b/src/modules/m_blockcaps.cpp
index 8e7d76f4a..f80c6d16d 100644
--- a/src/modules/m_blockcaps.cpp
+++ b/src/modules/m_blockcaps.cpp
@@ -104,22 +104,12 @@ public:
void ReadConf()
{
ConfigTag* tag = ServerInstance->Config->ConfValue("blockcaps");
- percent = tag->getInt("percent", 100);
- minlen = tag->getInt("minlen", 1);
+ percent = tag->getInt("percent", 100, 1, 100);
+ minlen = tag->getInt("minlen", 1, 1, ServerInstance->Config->Limits.MaxLine);
std::string hmap = tag->getString("capsmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
memset(capsmap, 0, sizeof(capsmap));
for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
capsmap[(unsigned char)*n] = 1;
- if (percent < 1 || percent > 100)
- {
- ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
- percent = 100;
- }
- if (minlen < 1 || minlen > ServerInstance->Config->Limits.MaxLine)
- {
- ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
- minlen = 1;
- }
}
Version GetVersion() CXX11_OVERRIDE
diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp
index c730602a1..36e10ec5b 100644
--- a/src/modules/m_connectban.cpp
+++ b/src/modules/m_connectban.cpp
@@ -43,18 +43,9 @@ class ModuleConnectBan : public Module
{
ConfigTag* tag = ServerInstance->Config->ConfValue("connectban");
- ipv4_cidr = tag->getInt("ipv4cidr", 32);
- if (ipv4_cidr == 0)
- ipv4_cidr = 32;
-
- ipv6_cidr = tag->getInt("ipv6cidr", 128);
- if (ipv6_cidr == 0)
- ipv6_cidr = 128;
-
- threshold = tag->getInt("threshold", 10);
- if (threshold == 0)
- threshold = 10;
-
+ ipv4_cidr = tag->getInt("ipv4cidr", 32, 1, 32);
+ ipv6_cidr = tag->getInt("ipv6cidr", 128, 1, 128);
+ threshold = tag->getInt("threshold", 10, 1);
banduration = InspIRCd::Duration(tag->getString("duration", "10m"));
if (banduration == 0)
banduration = 10*60;