Replace getInt/getUInt/getFloat with type safe templated functions.

This commit is contained in:
Sadie Powell 2023-01-24 23:41:50 +00:00
parent babc733d2d
commit af8effe4f0
43 changed files with 161 additions and 137 deletions

View File

@ -67,6 +67,30 @@ public:
private:
Items items;
/** Retrieves the value of a signed integer from the server config.
* @param key The config key to retrieve.
* @param def The default value to return if not set, empty, or out of range.
* @param min The minimum valid value.
* @param max The maximum valid value.
*/
long double getFloat(const std::string& key, long double def, long double min, long double max) const;
/** Retrieves the value of a signed integer from the server config.
* @param key The config key to retrieve.
* @param def The default value to return if not set, empty, or out of range.
* @param min The minimum valid value.
* @param max The maximum valid value.
*/
intmax_t getSInt(const std::string& key, intmax_t def, intmax_t min, intmax_t max) const;
/** Retrieves the value of an unsigned integer from the server config.
* @param key The config key to retrieve.
* @param def The default value to return if not set, empty, or out of range.
* @param min The minimum valid value.
* @param max The maximum valid value.
*/
uintmax_t getUInt(const std::string& key, uintmax_t def, uintmax_t min, uintmax_t max) const;
public:
/** The name of the configuration tag (e.g. "foo" for \<foo bar="baz">). */
const std::string name;
@ -80,17 +104,32 @@ public:
*/
ConfigTag(const std::string& Name, const FilePosition& Source);
/** @copydoc getFloat */
template<typename T>
std::enable_if_t<std::is_floating_point_v<T>, T> getNum(const std::string& key, T def, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()) const
{
return static_cast<T>(getFloat(key, def, min, max));
}
/** @copydoc getSInt */
template<typename T>
std::enable_if_t<std::is_signed_v<T> && !std::is_floating_point_v<T>, T> getNum(const std::string& key, T def, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()) const
{
return static_cast<T>(getSInt(key, def, min, max));
}
/** @copydoc getUInt */
template<typename T>
std::enable_if_t<std::is_unsigned_v<T> && !std::is_floating_point_v<T>, T> getNum(const std::string& key, T def, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()) const
{
return static_cast<T>(getUInt(key, def, min, max));
}
/** Get the value of an option, using def if it does not exist */
std::string getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) const;
/** Get the value of an option, using def if it does not exist */
std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX) const;
/** Get the value of an option, using def if it does not exist */
long getInt(const std::string& key, long def, long min = LONG_MIN, long max = LONG_MAX) const;
/** Get the value of an option, using def if it does not exist */
unsigned long getUInt(const std::string& key, unsigned long def, unsigned long min = 0, unsigned long max = ULONG_MAX) const;
/** Get the value of an option, using def if it does not exist */
double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX) const;
/** Get the value of an option, using def if it does not exist */
bool getBool(const std::string& key, bool def = false) const;
/** Get the value of an option, using def if it does not exist */
unsigned char getCharacter(const std::string& key, unsigned char def = '\0') const;
@ -408,7 +447,7 @@ public:
* The IRC server will not allow more than this
* number of local users.
*/
unsigned long SoftLimit;
size_t SoftLimit;
/** Maximum number of targets for a multi target command
* such as PRIVMSG or KICK

View File

@ -22,6 +22,7 @@
*/
#include <cinttypes>
#include <filesystem>
#include <fstream>
@ -655,7 +656,7 @@ namespace
}
}
long ConfigTag::getInt(const std::string& key, long def, long min, long max) const
intmax_t ConfigTag::getSInt(const std::string& key, intmax_t def, intmax_t min, intmax_t max) const
{
std::string result;
if(!readString(key, result) || result.empty())
@ -663,7 +664,7 @@ long ConfigTag::getInt(const std::string& key, long def, long min, long max) con
const char* res_cstr = result.c_str();
char* res_tail = nullptr;
long res = strtol(res_cstr, &res_tail, 0);
intmax_t res = strtoimax(res_cstr, &res_tail, 0);
if (res_tail == res_cstr)
return def;
@ -672,7 +673,7 @@ long ConfigTag::getInt(const std::string& key, long def, long min, long max) con
return res;
}
unsigned long ConfigTag::getUInt(const std::string& key, unsigned long def, unsigned long min, unsigned long max) const
uintmax_t ConfigTag::getUInt(const std::string& key, uintmax_t def, uintmax_t min, uintmax_t max) const
{
std::string result;
if (!readString(key, result) || result.empty())
@ -680,7 +681,7 @@ unsigned long ConfigTag::getUInt(const std::string& key, unsigned long def, unsi
const char* res_cstr = result.c_str();
char* res_tail = nullptr;
unsigned long res = strtoul(res_cstr, &res_tail, 0);
uintmax_t res = strtoumax(res_cstr, &res_tail, 0);
if (res_tail == res_cstr)
return def;
@ -706,13 +707,13 @@ unsigned long ConfigTag::getDuration(const std::string& key, unsigned long def,
return ret;
}
double ConfigTag::getFloat(const std::string& key, double def, double min, double max) const
long double ConfigTag::getFloat(const std::string& key, long double def, long double min, long double max) const
{
std::string result;
if (!readString(key, result))
return def;
double res = strtod(result.c_str(), nullptr);
long double res = strtold(result.c_str(), nullptr);
CheckRange(this, key, res, def, min, max);
return res;
}

View File

@ -41,17 +41,17 @@
#include "exitcodes.h"
ServerLimits::ServerLimits(const std::shared_ptr<ConfigTag>& tag)
: MaxLine(tag->getUInt("maxline", 512, 512))
, MaxNick(tag->getUInt("maxnick", 30, 1, MaxLine))
, MaxChannel(tag->getUInt("maxchan", 60, 1, MaxLine))
, MaxModes(tag->getUInt("maxmodes", 20, 1))
, MaxUser(tag->getUInt("maxident", 10, 1))
, MaxQuit(tag->getUInt("maxquit", 300, 0, MaxLine))
, MaxTopic(tag->getUInt("maxtopic", 330, 1, MaxLine))
, MaxKick(tag->getUInt("maxkick", 300, 1, MaxLine))
, MaxReal(tag->getUInt("maxreal", 130, 1, MaxLine))
, MaxAway(tag->getUInt("maxaway", 200, 1, MaxLine))
, MaxHost(tag->getUInt("maxhost", 64, 1, MaxLine))
: MaxLine(tag->getNum<size_t>("maxline", 512, 512))
, MaxNick(tag->getNum<size_t>("maxnick", 30, 1, MaxLine))
, MaxChannel(tag->getNum<size_t>("maxchan", 60, 1, MaxLine))
, MaxModes(tag->getNum<size_t>("maxmodes", 20, 1))
, MaxUser(tag->getNum<size_t>("maxident", 10, 1))
, MaxQuit(tag->getNum<size_t>("maxquit", 300, 0, MaxLine))
, MaxTopic(tag->getNum<size_t>("maxtopic", 330, 1, MaxLine))
, MaxKick(tag->getNum<size_t>("maxkick", 300, 1, MaxLine))
, MaxReal(tag->getNum<size_t>("maxreal", 130, 1, MaxLine))
, MaxAway(tag->getNum<size_t>("maxaway", 200, 1, MaxLine))
, MaxHost(tag->getNum<size_t>("maxhost", 64, 1, MaxLine))
{
}
@ -298,22 +298,22 @@ void ServerConfig::Fill()
if (!nsid.empty() && nsid != sid)
throw CoreException("You must restart to change the server id");
}
SoftLimit = ConfValue("performance")->getUInt("softlimit", (SocketEngine::GetMaxFds() > 0 ? SocketEngine::GetMaxFds() : LONG_MAX), 10);
MaxConn = static_cast<int>(ConfValue("performance")->getUInt("somaxconn", SOMAXCONN));
SoftLimit = ConfValue("performance")->getNum<size_t>("softlimit", (SocketEngine::GetMaxFds() > 0 ? SocketEngine::GetMaxFds() : SIZE_MAX), 10);
MaxConn = ConfValue("performance")->getNum<int>("somaxconn", SOMAXCONN, 1);
TimeSkipWarn = ConfValue("performance")->getDuration("timeskipwarn", 2, 0, 30);
XLineMessage = options->getString("xlinemessage", "You're banned!", 1);
ServerDesc = server->getString("description", "Configure Me", 1);
Network = server->getString("network", "Network", 1);
NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240, 1024, 65534);
NetBufferSize = ConfValue("performance")->getNum<size_t>("netbuffersize", 10240, 1024, 65534);
CustomVersion = security->getString("customversion");
HideBans = security->getBool("hidebans");
HideServer = security->getString("hideserver", "", InspIRCd::IsFQDN);
SyntaxHints = options->getBool("syntaxhints");
FullHostInTopic = options->getBool("hostintopic");
MaxTargets = security->getUInt("maxtargets", 20, 1, 31);
MaxTargets = security->getNum<unsigned long>("maxtargets", 5, 1, 50);
DefaultModes = options->getString("defaultmodes", "not");
c_ipv4_range = ConfValue("cidr")->getUInt("ipv4clone", 32, 1, 32);
c_ipv6_range = ConfValue("cidr")->getUInt("ipv6clone", 128, 1, 128);
c_ipv4_range = ConfValue("cidr")->getNum<unsigned char>("ipv4clone", 32, 1, 32);
c_ipv6_range = ConfValue("cidr")->getNum<unsigned char>("ipv6clone", 128, 1, 128);
Limits = ServerLimits(ConfValue("limits"));
Paths = ServerPaths(ConfValue("path"));
NoSnoticeStack = options->getBool("nosnoticestack", false);

View File

@ -215,7 +215,7 @@ public:
ServerInstance->Modules.Detach(events, this, sizeof(events)/sizeof(Implementation));
const auto& limitstag = ServerInstance->Config->ConfValue("limits");
keymode.maxkeylen = limitstag->getUInt("maxkey", 32, 1, ModeParser::MODE_PARAM_MAX);
keymode.maxkeylen = limitstag->getNum<size_t>("maxkey", 32, 1, ModeParser::MODE_PARAM_MAX);
}
void OnBuildISupport(ISupport::TokenMap& tokens) override
@ -258,7 +258,7 @@ public:
*/
unsigned long maxchans = user->GetClass()->maxchans;
if (user->IsOper())
maxchans = user->oper->GetConfig()->getUInt("maxchans", maxchans, maxchans);
maxchans = user->oper->GetConfig()->getNum<unsigned long>("maxchans", maxchans, maxchans);
if (user->chans.size() >= maxchans)
{

View File

@ -919,7 +919,7 @@ public:
SourceIP = tag->getString("sourceip");
const in_port_t oldport = SourcePort;
SourcePort = static_cast<in_port_t>(tag->getUInt("sourceport", 0, 0, 65535));
SourcePort = tag->getNum<in_port_t>("sourceport", 0);
if (DNSServer.empty())
FindDNSServer();

View File

@ -448,8 +448,8 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("whowas");
unsigned int NewGroupSize = static_cast<unsigned int>(tag->getUInt("groupsize", 10, 0, 10000));
unsigned int NewMaxGroups = static_cast<unsigned int>(tag->getUInt("maxgroups", 10240, 0, 1000000));
unsigned int NewGroupSize = tag->getNum<unsigned int>("groupsize", 10, 0, 10000);
unsigned int NewMaxGroups = tag->getNum<unsigned int>("maxgroups", 10240, 0, 1000000);
unsigned int NewMaxKeep = static_cast<unsigned int>(tag->getDuration("maxkeep", 3600, 3600));
cmd.manager.UpdateConfig(NewGroupSize, NewMaxGroups, NewMaxKeep);

View File

@ -32,7 +32,7 @@ bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User
if (insane->getBool(confkey))
return false;
float itrigger = insane->getFloat("trigger", 95.5, 0.0, 100.0);
float itrigger = insane->getNum<float>("trigger", 95.5, 0.0, 100.0);
long matches = test.Run(mask);

View File

@ -80,7 +80,7 @@ void ListModeBase::DoRehash()
if (!mname.empty() && !stdalgo::string::equalsci(mname, name) && !(mname.length() == 1 && GetModeChar() == mname[0]))
continue;
ListLimit limit(c->getString("chan", "*", 1), c->getUInt("limit", DEFAULT_LIST_SIZE));
ListLimit limit(c->getString("chan", "*", 1), c->getNum<unsigned long>("limit", DEFAULT_LIST_SIZE));
if (limit.mask.empty())
throw ModuleException(creator, INSP_FORMAT("<maxlist:chan> is empty, at {}", c->source.str()));

View File

@ -131,7 +131,7 @@ Log::MethodPtr Log::FileEngine::Create(const std::shared_ptr<ConfigTag>& tag)
tag->source.str(), strerror(errno)));
}
const unsigned long flush = tag->getUInt("flush", 20, 1);
const unsigned long flush = tag->getNum<unsigned long>("flush", 20, 1);
return std::make_shared<FileMethod>(fulltarget, fh, flush, true);
}

View File

@ -34,25 +34,6 @@
class ProviderConfig final
{
private:
static Argon2_version SanitizeArgon2Version(unsigned long version)
{
// Note, 10 is 0x10, and 13 is 0x13. Referring to it as
// dec 10 or 13 in the config file, for the name to
// match better.
switch (version)
{
case 10:
return ARGON2_VERSION_10;
case 13:
return ARGON2_VERSION_13;
}
ServerInstance->Logs.Warning(MODNAME, "Unknown Argon2 version ({}) specified; assuming 13",
version);
return ARGON2_VERSION_13;
}
public:
uint32_t iterations;
uint32_t lanes;
@ -72,25 +53,28 @@ public:
const auto& tag = ServerInstance->Config->ConfValue(tagname);
uint32_t def_iterations = def ? def->iterations : 3;
this->iterations = static_cast<uint32_t>(tag->getUInt("iterations", def_iterations, 1, UINT32_MAX));
this->iterations = tag->getNum<uint32_t>("iterations", def_iterations, 1);
uint32_t def_lanes = def ? def->lanes : 1;
this->lanes = static_cast<uint32_t>(tag->getUInt("lanes", def_lanes, ARGON2_MIN_LANES, ARGON2_MAX_LANES));
this->lanes = tag->getNum<uint32_t>("lanes", def_lanes, ARGON2_MIN_LANES, ARGON2_MAX_LANES);
uint32_t def_memory = def ? def->memory : 131072; // 128 MiB
this->memory = static_cast<uint32_t>(tag->getUInt("memory", def_memory, ARGON2_MIN_MEMORY, ARGON2_MAX_MEMORY));
this->memory = tag->getNum<uint32_t>("memory", def_memory, ARGON2_MIN_MEMORY, ARGON2_MAX_MEMORY);
uint32_t def_outlen = def ? def->outlen : 32;
this->outlen = static_cast<uint32_t>(tag->getUInt("length", def_outlen, ARGON2_MIN_OUTLEN, ARGON2_MAX_OUTLEN));
this->outlen = tag->getNum<int32_t>("length", def_outlen, ARGON2_MIN_OUTLEN, ARGON2_MAX_OUTLEN);
uint32_t def_saltlen = def ? def->saltlen : 16;
this->saltlen = static_cast<uint32_t>(tag->getUInt("saltlength", def_saltlen, ARGON2_MIN_SALT_LENGTH, ARGON2_MAX_SALT_LENGTH));
this->saltlen = tag->getNum<uint32_t>("saltlength", def_saltlen, ARGON2_MIN_SALT_LENGTH, ARGON2_MAX_SALT_LENGTH);
uint32_t def_threads = def ? def->threads : 1;
this->threads = static_cast<uint32_t>(tag->getUInt("threads", def_threads, ARGON2_MIN_THREADS, ARGON2_MAX_THREADS));
this->threads = tag->getNum<uint32_t>("threads", def_threads, ARGON2_MIN_THREADS, ARGON2_MAX_THREADS);
uint32_t def_version = def ? def->version : 13;
this->version = SanitizeArgon2Version(tag->getUInt("version", def_version));
Argon2_version def_version = def ? def->version : ARGON2_VERSION_13;
this->version = tag->getEnum("version", def_version, {
{ "10", ARGON2_VERSION_10 },
{ "13", ARGON2_VERSION_13 },
});
}
};

View File

@ -145,7 +145,7 @@ public:
fulltarget, tag->source.str(), strerror(errno)));
}
const unsigned long flush = tag->getUInt("flush", 20, 1);
const unsigned long flush = tag->getNum<unsigned long>("flush", 20, 1);
return std::make_shared<JSONMethod>(fulltarget, fh, flush, true);
}
};

View File

@ -335,7 +335,7 @@ public:
const std::string user = config->getString("user");
const std::string pass = config->getString("pass");
const std::string dbname = config->getString("name");
unsigned int port = static_cast<unsigned int>(config->getUInt("port", 3306, 1, 65535));
unsigned int port = config->getNum<unsigned int>("port", 3306, 1, 65535);
if (!mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(), dbname.c_str(), port, nullptr, CLIENT_IGNORE_SIGPIPE))
{
ServerInstance->Logs.Error(MODNAME, "Unable to connect to the {} MySQL server: {}",

View File

@ -541,7 +541,7 @@ namespace GnuTLS
, dh(DHParams::Import(ReadFile(tag->getString("dhfile", "dhparams.pem", 1))))
#endif
, priostr(GetPrioStr(profilename, tag))
, mindh(static_cast<unsigned int>(tag->getUInt("mindhbits", 1024, 0, UINT32_MAX)))
, mindh(tag->getNum<unsigned int>("mindhbits", 1024))
, hashstr(tag->getString("hash", "sha256", 1))
, requestclientcert(tag->getBool("requestclientcert", true))
{
@ -556,7 +556,7 @@ namespace GnuTLS
crl.reset(new X509CRL(ReadFile(filename)));
}
outrecsize = static_cast<unsigned int>(tag->getUInt("outrecsize", 2048, 512, UINT32_MAX));
outrecsize = tag->getNum<unsigned int>("outrecsize", 2048, 512);
}
};

View File

@ -451,12 +451,12 @@ namespace mbedTLS
, dhstr(ReadFile(tag->getString("dhfile", "dhparams.pem", 1)))
, ciphersuitestr(tag->getString("ciphersuites"))
, curvestr(tag->getString("curves"))
, mindh(static_cast<unsigned int>(tag->getUInt("mindhbits", 2048, 0, UINT32_MAX)))
, mindh(tag->getNum<unsigned int>("mindhbits", 2048))
, hashstr(tag->getString("hash", "sha256", 1))
, castr(tag->getString("cafile"))
, minver(static_cast<int>(tag->getUInt("minver", 0, 0, INT32_MAX)))
, maxver(static_cast<int>(tag->getUInt("maxver", 0, 0, INT32_MAX)))
, outrecsize(static_cast<unsigned int>(tag->getUInt("outrecsize", 2048, 512, 16384)))
, minver(tag->getNum<int>("minver", 0))
, maxver(tag->getNum<int>("maxver", 0))
, outrecsize(tag->getNum<unsigned int>("outrecsize", 2048, 512, 16384))
, requestclientcert(tag->getBool("requestclientcert", true))
{
if (!castr.empty())

View File

@ -326,8 +326,8 @@ namespace OpenSSL
*/
void SetContextOptions(const std::string& ctxname, const std::shared_ptr<ConfigTag>& tag, Context& context)
{
long setoptions = tag->getInt(ctxname + "setoptions", 0);
long clearoptions = tag->getInt(ctxname + "clearoptions", 0);
long setoptions = tag->getNum<long>(ctxname + "setoptions", 0);
long clearoptions = tag->getNum<long>(ctxname + "clearoptions", 0);
#ifdef SSL_OP_NO_COMPRESSION
// Disable compression by default
@ -370,7 +370,7 @@ namespace OpenSSL
, ctx(SSL_CTX_new(TLS_server_method()))
, clientctx(SSL_CTX_new(TLS_client_method()))
, allowrenego(tag->getBool("renegotiation")) // Disallow by default
, outrecsize(static_cast<unsigned int>(tag->getUInt("outrecsize", 2048, 512, 16384)))
, outrecsize(tag->getNum<unsigned int>("outrecsize", 2048, 512, 16384))
{
#ifndef INSPIRCD_OPENSSL_AUTO_DH
if ((!ctx.SetDH(dh)) || (!clientctx.SetDH(dh)))

View File

@ -87,7 +87,7 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& conf = ServerInstance->Config->ConfValue("bcrypt");
bcrypt.rounds = conf->getUInt("rounds", 10, 1);
bcrypt.rounds = conf->getNum<unsigned long>("rounds", 10, 1);
}
};

View File

@ -460,7 +460,7 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("callerid");
cmd.maxaccepts = tag->getUInt("maxaccepts", 30);
cmd.maxaccepts = tag->getNum<unsigned long>("maxaccepts", 30, 1);
tracknick = tag->getBool("tracknick");
notify_cooldown = tag->getDuration("cooldown", 60);
}

View File

@ -107,7 +107,7 @@ public:
{
const auto& tag = ServerInstance->Config->ConfValue("chanfilter");
hidemask = tag->getBool("hidemask");
cf.maxlen = tag->getUInt("maxlen", 35, 10, ModeParser::MODE_PARAM_MAX);
cf.maxlen = tag->getNum<unsigned long>("maxlen", 35, 10, ModeParser::MODE_PARAM_MAX);
notifyuser = tag->getBool("notifyuser", true);
cf.DoRehash();
}

View File

@ -210,7 +210,7 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("chanhistory");
historymode.maxlines = tag->getUInt("maxlines", 50, 1);
historymode.maxlines = tag->getNum<unsigned long>("maxlines", 50, 1);
prefixmsg = tag->getBool("prefixmsg", true);
dobots = tag->getBool("bots", true);
}

View File

@ -306,7 +306,7 @@ public:
if (halfcloak)
{
unsigned int domainparts = static_cast<unsigned int>(tag->getUInt("domainparts", 3, 1, 10));
unsigned int domainparts = tag->getNum<unsigned int>("domainparts", 3, 1, 10);
return std::make_shared<CloakInfo>(this, MODE_HALF_CLOAK, key, prefix, suffix, ignorecase, domainparts);
}
else

View File

@ -188,9 +188,9 @@ public:
SHA256Method(const Cloak::Engine* engine, const std::shared_ptr<ConfigTag>& tag, const std::string& k, psl_ctx_t* p, bool ch) ATTR_NOT_NULL(2)
: Cloak::Method(engine)
, cloakhost(ch)
, hostparts(tag->getUInt("hostparts", 3, 0, ServerInstance->Config->Limits.MaxHost / 2))
, hostparts(tag->getNum<unsigned long>("hostparts", 3, 0, ServerInstance->Config->Limits.MaxHost / 2))
, key(k)
, pathparts(tag->getUInt("pathparts", 1, 0, ServerInstance->Config->Limits.MaxHost / 2))
, pathparts(tag->getNum<unsigned long>("pathparts", 1, 0, ServerInstance->Config->Limits.MaxHost / 2))
, prefix(tag->getString("prefix"))
#ifdef HAS_LIBPSL
, psl(p)

View File

@ -264,11 +264,11 @@ public:
std::unique_ptr<Codepage> newcodepage = std::make_unique<SingleByteCodepage>();
for (const auto& [_, tag] : ServerInstance->Config->ConfTags("cpchars"))
{
unsigned long begin = tag->getUInt("begin", tag->getUInt("index", 0));
unsigned long begin = tag->getNum<unsigned long>("begin", tag->getNum<unsigned long>("index", 0));
if (!begin)
throw ModuleException(this, "<cpchars> tag without index or begin specified at " + tag->source.str());
unsigned long end = tag->getUInt("end", begin);
unsigned long end = tag->getNum<unsigned long>("end", begin);
if (begin > end)
throw ModuleException(this, "<cpchars:begin> must be lower than <cpchars:end> at " + tag->source.str());
@ -296,11 +296,11 @@ public:
for (const auto& [_, tag] : ServerInstance->Config->ConfTags("cpcase"))
{
unsigned long lower = tag->getUInt("lower", 0);
unsigned long lower = tag->getNum<unsigned long>("lower", 0);
if (!lower)
throw ModuleException(this, "<cpcase:lower> is required at " + tag->source.str());
unsigned long upper = tag->getUInt("upper", 0);
unsigned long upper = tag->getNum<unsigned long>("upper", 0);
if (!upper)
throw ModuleException(this, "<cpcase:upper> is required at " + tag->source.str());

View File

@ -100,9 +100,9 @@ public:
{
const auto& tag = ServerInstance->Config->ConfValue("connectban");
ipv4_cidr = static_cast<unsigned int>(tag->getUInt("ipv4cidr", ServerInstance->Config->c_ipv4_range, 1, 32));
ipv6_cidr = static_cast<unsigned int>(tag->getUInt("ipv6cidr", ServerInstance->Config->c_ipv6_range, 1, 128));
threshold = tag->getUInt("threshold", 10, 1);
ipv4_cidr = tag->getNum<unsigned int>("ipv4cidr", ServerInstance->Config->c_ipv4_range, 1, 32);
ipv6_cidr = tag->getNum<unsigned int>("ipv6cidr", ServerInstance->Config->c_ipv6_range, 1, 128);
threshold = tag->getNum<unsigned long>("threshold", 10, 1);
bootwait = tag->getDuration("bootwait", 60*2);
splitwait = tag->getDuration("splitwait", 60*2);
banduration = tag->getDuration("banduration", 6*60*60, 1);

View File

@ -60,7 +60,7 @@ public:
const auto& tag = ServerInstance->Config->ConfValue("connflood");
/* throttle configuration */
seconds = tag->getDuration("period", 30);
maxconns = tag->getUInt("maxconns", 3);
maxconns = tag->getNum<unsigned long>("maxconns", 3);
timeout = tag->getDuration("timeout", 30);
quitmsg = tag->getString("quitmsg");

View File

@ -32,9 +32,9 @@ public:
: PrefixMode(parent, Name, Letter, 0, Prefix)
, tag(Tag)
{
ModeHandler::Rank rank = static_cast<ModeHandler::Rank>(tag->getUInt("rank", 1, 1, std::numeric_limits<ModeHandler::Rank>::max()));
ModeHandler::Rank setrank = static_cast<ModeHandler::Rank>(tag->getUInt("ranktoset", prefixrank, rank, std::numeric_limits<ModeHandler::Rank>::max()));
ModeHandler::Rank unsetrank = static_cast<ModeHandler::Rank>(tag->getUInt("ranktounset", setrank, setrank, std::numeric_limits<ModeHandler::Rank>::max()));
ModeHandler::Rank rank = tag->getNum<ModeHandler::Rank>("rank", 1, 1);
ModeHandler::Rank setrank = tag->getNum<ModeHandler::Rank>("ranktoset", prefixrank, rank);
ModeHandler::Rank unsetrank = tag->getNum<ModeHandler::Rank>("ranktounset", setrank, setrank);
bool depriv = tag->getBool("depriv", true);
this->Update(rank, setrank, unsetrank, depriv);
@ -77,9 +77,9 @@ public:
if (!pm)
throw ModuleException(this, "<customprefix:change> specified for a non-prefix mode at " + tag->source.str());
ModeHandler::Rank rank = static_cast<ModeHandler::Rank>(tag->getUInt("rank", pm->GetPrefixRank(), 1, std::numeric_limits<ModeHandler::Rank>::max()));
ModeHandler::Rank setrank = static_cast<ModeHandler::Rank>(tag->getUInt("ranktoset", pm->GetLevelRequired(true), rank, std::numeric_limits<ModeHandler::Rank>::max()));
ModeHandler::Rank unsetrank = static_cast<ModeHandler::Rank>(tag->getUInt("ranktounset", pm->GetLevelRequired(false), setrank, std::numeric_limits<ModeHandler::Rank>::max()));
ModeHandler::Rank rank = tag->getNum<ModeHandler::Rank>("rank", pm->GetPrefixRank(), 1);
ModeHandler::Rank setrank = tag->getNum<ModeHandler::Rank>("ranktoset", pm->GetLevelRequired(true), rank);
ModeHandler::Rank unsetrank = tag->getNum<ModeHandler::Rank>("ranktounset", pm->GetLevelRequired(false), setrank);
bool depriv = tag->getBool("depriv", pm->CanSelfRemove());
pm->Update(rank, setrank, unsetrank, depriv);

View File

@ -617,7 +617,7 @@ public:
bfl.swap(newbfl);
const auto& tag = ServerInstance->Config->ConfValue("dccallow");
cmd.ext.maxentries = tag->getUInt("maxentries", 20, 1);
cmd.ext.maxentries = tag->getNum<unsigned long>("maxentries", 20, 1);
cmd.defaultlength = tag->getDuration("length", 0);
blockchat = tag->getBool("blockchat");
defaultaction = tag->getString("action");

View File

@ -134,7 +134,7 @@ public:
{
type = Type::BITMASK;
bitmask = static_cast<unsigned int>(tag->getUInt("bitmask", 0, 0, UINT_MAX));
bitmask = tag->getNum<unsigned int>("bitmask", 0);
records = 0;
}
else if (stdalgo::string::equalsci(typestr, "record"))

View File

@ -71,7 +71,7 @@ public:
throw ModuleException(this, "Empty <hidelist:mode> at " + tag->source.str());
// If rank is set to 0 everyone inside the channel can view the list,
// but non-members may not
ModeHandler::Rank rank = tag->getUInt("rank", HALFOP_VALUE);
ModeHandler::Rank rank = tag->getNum<ModeHandler::Rank>("rank", HALFOP_VALUE);
newconfigs.emplace_back(modename, rank);
}

View File

@ -27,11 +27,11 @@ namespace
{
class Settings final
{
typedef insp::flat_map<std::string, unsigned int> RanksToSeeMap;
typedef insp::flat_map<std::string, ModeHandler::Rank> RanksToSeeMap;
RanksToSeeMap rankstosee;
public:
unsigned int GetRequiredRank(const ModeHandler& mh) const
ModeHandler::Rank GetRequiredRank(const ModeHandler& mh) const
{
RanksToSeeMap::const_iterator it = rankstosee.find(mh.name);
if (it != rankstosee.end())
@ -49,7 +49,7 @@ public:
if (modename.empty())
throw ModuleException(mod, "<hidemode:mode> is empty at " + tag->source.str());
unsigned long rank = tag->getUInt("rank", 0);
ModeHandler::Rank rank = tag->getNum<ModeHandler::Rank>("rank", 0);
if (!rank)
throw ModuleException(mod, "<hidemode:rank> must be greater than 0 at " + tag->source.str());

View File

@ -181,7 +181,7 @@ public:
if (host.empty())
throw ModuleException(this, "<sts:host> must contain a hostname, at " + tag->source.str());
in_port_t port = static_cast<in_port_t>(tag->getUInt("port", 6697, 1, 65535));
in_port_t port = tag->getNum<in_port_t>("port", 6697, 1);
if (!HasValidSSLPort(port))
throw ModuleException(this, "<sts:port> must be a TLS port, at " + tag->source.str());

View File

@ -138,9 +138,9 @@ public:
void ReadConfig(ConfigStatus&) override
{
const auto& tag = ServerInstance->Config->ConfValue("messageflood");
notice = tag->getFloat("notice", 1.0);
privmsg = tag->getFloat("privmsg", 1.0);
tagmsg = tag->getFloat("tagmsg", 0.2);
notice = tag->getNum<float>("notice", 1.0);
privmsg = tag->getNum<float>("privmsg", 1.0);
tagmsg = tag->getNum<float>("tagmsg", 0.2);
kickmessage = tag->getString("kickmessage", "Message flood (trigger is %lines% messages in %duration%)", 1);
}

View File

@ -393,7 +393,7 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("monitor");
cmd.maxmonitor = tag->getUInt("maxentries", 30, 1);
cmd.maxmonitor = tag->getNum<unsigned long>("maxentries", 30, 1);
}
void OnPostConnect(User* user) override

View File

@ -40,8 +40,8 @@ public:
// oper killing an oper?
if (dest->IsOper() && source->IsOper())
{
unsigned long dest_level = dest->oper->GetConfig()->getUInt("level", 0);
unsigned long source_level = source->oper->GetConfig()->getUInt("level", 0);
unsigned long dest_level = dest->oper->GetConfig()->getNum<unsigned long>("level", 0);
unsigned long source_level = source->oper->GetConfig()->getNum<unsigned long>("level", 0);
if (dest_level > source_level)
{

View File

@ -185,8 +185,8 @@ class ModulePBKDF2 final
// First set the common values
const auto& tag = ServerInstance->Config->ConfValue("pbkdf2");
ProviderConfig newglobal;
newglobal.iterations = tag->getUInt("iterations", 12288, 1);
newglobal.dkey_length = tag->getUInt("length", 32, 1, 1024);
newglobal.iterations = tag->getNum<unsigned long>("iterations", 12288, 1);
newglobal.dkey_length = tag->getNum<size_t>("length", 32, 1, 1024);
// Then the specific values
ProviderConfigMap newconfigs;
@ -195,8 +195,8 @@ class ModulePBKDF2 final
std::string hash_name = "hash/" + ptag->getString("hash");
ProviderConfig& config = newconfigs[hash_name];
config.iterations = ptag->getUInt("iterations", newglobal.iterations, 1);
config.dkey_length = ptag->getUInt("length", newglobal.dkey_length, 1, 1024);
config.iterations = ptag->getNum<unsigned long>("iterations", newglobal.iterations, 1);
config.dkey_length = ptag->getNum<size_t>("length", newglobal.dkey_length, 1, 1024);
}
// Config is valid, apply it

View File

@ -218,10 +218,10 @@ public:
auto* c = ServerInstance->Channels.Find(channel);
if (!c)
{
time_t TS = tag->getInt("ts", ServerInstance->Time(), 1);
time_t TS = tag->getNum<time_t>("ts", ServerInstance->Time(), 1);
c = new Channel(channel, TS);
time_t topicset = tag->getInt("topicts", 0);
time_t topicset = tag->getNum<time_t>("topicts", 0);
std::string topic = tag->getString("topic");
if ((topicset != 0) || (!topic.empty()))

View File

@ -175,7 +175,7 @@ public:
{
const auto& tag = ServerInstance->Config->ConfValue("remove");
cmd.supportnokicks = tag->getBool("supportnokicks");
cmd.protectedrank = tag->getUInt("protectedrank", 50000);
cmd.protectedrank = tag->getNum<ModeHandler::Rank>("protectedrank", 50000, 1);
}
};

View File

@ -248,13 +248,13 @@ public:
void ReadConfig()
{
const auto& conf = ServerInstance->Config->ConfValue("repeat");
ms.MaxLines = conf->getUInt("maxlines", 20);
ms.MaxBacklog = conf->getUInt("maxbacklog", 20);
ms.MaxLines = conf->getNum<unsigned long>("maxlines", 20);
ms.MaxBacklog = conf->getNum<unsigned long>("maxbacklog", 20);
ms.MaxSecs = conf->getDuration("maxtime", 0);
ms.MaxDiff = static_cast<unsigned int>(conf->getUInt("maxdistance", 50, 0, 100));
ms.MaxDiff = conf->getNum<unsigned int>("maxdistance", 50, 0, 100);
unsigned long newsize = conf->getUInt("size", 512);
size_t newsize = conf->getNum<size_t>("size", 512);
if (newsize > ServerInstance->Config->Limits.MaxLine)
newsize = ServerInstance->Config->Limits.MaxLine;
Resize(newsize);

View File

@ -67,7 +67,7 @@ public:
const auto& tag = ServerInstance->Config->ConfValue("securelist");
exemptregistered = tag->getBool("exemptregistered", true);
fakechans = tag->getUInt("fakechans", 5, 0);
fakechans = tag->getNum<unsigned long>("fakechans", 5, 0);
fakechanprefix = tag->getString("fakechanprefix", "#", 1, ServerInstance->Config->Limits.MaxChannel - 1);
fakechantopic = tag->getString("fakechantopic", "Fake channel for confusing spambots", 1, ServerInstance->Config->Limits.MaxTopic - 1);
showmsg = tag->getBool("showmsg", true);

View File

@ -84,9 +84,9 @@ public:
{
introtext = tag->getString("introtext", "Showing " + name);
endtext = tag->getString("endtext", "End of " + name);
intronumeric = static_cast<unsigned int>(tag->getUInt("intronumeric", RPL_RULESTART, 0, 999));
textnumeric = static_cast<unsigned int>(tag->getUInt("numeric", RPL_RULES, 0, 999));
endnumeric = static_cast<unsigned int>(tag->getUInt("endnumeric", RPL_RULESEND, 0, 999));
intronumeric = tag->getNum<unsigned int>("intronumeric", RPL_RULESTART, 0, 999);
textnumeric = tag->getNum<unsigned int>("numeric", RPL_RULES, 0, 999);
endnumeric = tag->getNum<unsigned int>("endnumeric", RPL_RULESEND, 0, 999);
std::string smethod = tag->getString("method");
method = SF_NUMERIC;

View File

@ -459,7 +459,7 @@ public:
{
const auto& tag = ServerInstance->Config->ConfValue("silence");
exemptservice = tag->getBool("exemptservice", tag->getBool("exemptuline", true));
cmd.ext.maxsilence = tag->getUInt("maxentries", 32, 1);
cmd.ext.maxsilence = tag->getNum<unsigned long>("maxentries", 32, 1);
}
void OnBuildISupport(ISupport::TokenMap& tokens) override

View File

@ -262,7 +262,7 @@ void SpanningTreeUtilities::ReadConfiguration()
if (path.empty())
{
L->IPAddr = tag->getString("ipaddr");
L->Port = static_cast<in_port_t>(tag->getUInt("port", 0, 0, 65535));
L->Port = tag->getNum<in_port_t>("port", 0);
if (tag->getBool("sctp"))
{
#ifdef IPPROTO_SCTP

View File

@ -219,7 +219,7 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("watch");
cmd.maxwatch = tag->getUInt("maxwatch", 30, 1);
cmd.maxwatch = tag->getNum<unsigned long>("maxwatch", 30, 1);
}
void OnPostConnect(User* user) override

View File

@ -1091,20 +1091,20 @@ void ConnectClass::Configure(const std::string& classname, const std::shared_ptr
ports.insert(static_cast<in_port_t>(port));
}
commandrate = tag->getUInt("commandrate", commandrate, 1);
commandrate = tag->getNum<unsigned long>("commandrate", commandrate, 1);
fakelag = tag->getBool("fakelag", fakelag);
hardsendqmax = tag->getUInt("hardsendq", hardsendqmax, ServerInstance->Config->Limits.MaxLine);
limit = tag->getUInt("limit", limit, 1);
maxchans = tag->getUInt("maxchans", maxchans);
hardsendqmax = tag->getNum<unsigned long>("hardsendq", hardsendqmax, ServerInstance->Config->Limits.MaxLine);
limit = tag->getNum<unsigned long>("limit", limit, 1);
maxchans = tag->getNum<unsigned long>("maxchans", maxchans);
maxconnwarn = tag->getBool("maxconnwarn", maxconnwarn);
maxlocal = tag->getUInt("localmax", maxlocal);
maxglobal = tag->getUInt("globalmax", maxglobal, maxlocal);
penaltythreshold = tag->getUInt("threshold", penaltythreshold, 1);
maxlocal = tag->getNum<unsigned long>("localmax", maxlocal);
maxglobal = tag->getNum<unsigned long>("globalmax", maxglobal, maxlocal);
penaltythreshold = tag->getNum<unsigned long>("threshold", penaltythreshold, 1);
pingtime = tag->getDuration("pingfreq", pingtime);
recvqmax = tag->getUInt("recvq", recvqmax, ServerInstance->Config->Limits.MaxLine);
recvqmax = tag->getNum<unsigned long>("recvq", recvqmax, ServerInstance->Config->Limits.MaxLine);
connection_timeout = tag->getDuration("timeout", connection_timeout);
resolvehostnames = tag->getBool("resolvehostnames", resolvehostnames);
softsendqmax = tag->getUInt("softsendq", softsendqmax, ServerInstance->Config->Limits.MaxLine);
softsendqmax = tag->getNum<unsigned long>("softsendq", softsendqmax, ServerInstance->Config->Limits.MaxLine);
uniqueusername = tag->getBool("uniqueusername", uniqueusername);
}