diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-08-12 19:20:18 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-08-12 19:20:18 +0200 |
commit | 6d39615998dee7b30565d34a9f209b569678fb6a (patch) | |
tree | 477fdbe6d1f385e797e58e64cbc3af9bdbda9a64 /src/configparser.cpp | |
parent | 1e89f510705753a33644b0356cdd902ecc2d9128 (diff) |
Add ConfigTag::getDuration() with optional bounds checking
Diffstat (limited to 'src/configparser.cpp')
-rw-r--r-- | src/configparser.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp index 1783e901e..d3723d350 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -445,13 +445,30 @@ long ConfigTag::getInt(const std::string &key, long def, long min, long max) res = res * 1024 * 1024 * 1024; break; } + + CheckRange(key, res, def, min, max); + return res; +} + +void ConfigTag::CheckRange(const std::string& key, long& res, long def, long min, long max) +{ 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; +} + +time_t ConfigTag::getDuration(const std::string& key, long def, long min, long max) +{ + std::string duration; + if (!readString(key, duration)) + return def; + + time_t ret = InspIRCd::Duration(duration); + CheckRange(key, ret, def, min, max); + return ret; } double ConfigTag::getFloat(const std::string &key, double def) |