From c0ca5c8d41a71eae4ec132e492b546fa03510871 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 17 Aug 2017 14:54:49 +0100 Subject: Add support for length arguments in getString. --- src/configparser.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/configparser.cpp') diff --git a/src/configparser.cpp b/src/configparser.cpp index 7c03fe58a..86268a132 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -402,10 +402,18 @@ bool ConfigTag::readString(const std::string& key, std::string& value, bool allo return false; } -std::string ConfigTag::getString(const std::string& key, const std::string& def) +std::string ConfigTag::getString(const std::string& key, const std::string& def, size_t minlen, size_t maxlen) { - std::string res = def; - readString(key, res); + std::string res; + if (!readString(key, res)) + return def; + + if (res.length() < minlen || res.length() > maxlen) + { + ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: The length of <%s:%s> is not between %ld and %ld; value set to %s.", + tag.c_str(), key.c_str(), minlen, maxlen, def.c_str()); + return def; + } return res; } -- cgit v1.2.3