]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add support for length arguments in getString.
authorPeter Powell <petpow@saberuk.com>
Thu, 17 Aug 2017 13:54:49 +0000 (14:54 +0100)
committerPeter Powell <petpow@saberuk.com>
Sun, 3 Sep 2017 21:44:33 +0000 (22:44 +0100)
include/configreader.h
src/configparser.cpp
src/modules/m_alias.cpp
src/modules/m_operprefix.cpp

index 8da037e9a1fd99efc327435942fc0d93ff241c25..1a0e700808871b9ec10c3f8a2ef9676098464259 100644 (file)
@@ -42,7 +42,7 @@ class CoreExport ConfigTag : public refcountbase
        const int src_line;
 
        /** Get the value of an option, using def if it does not exist */
-       std::string getString(const std::string& key, const std::string& def = "");
+       std::string getString(const std::string& key, const std::string& def = "", size_t minlen = 0, size_t maxlen = UINT32_MAX);
        /** Get the value of an option, using def if it does not exist */
        long getInt(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX);
        /** Get the value of an option, using def if it does not exist */
index 7c03fe58a1ad4869c6fc8acd8704f8e7a0cf5da1..86268a13284c4aefe838a217d64ce0df45e4b289 100644 (file)
@@ -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;
 }
 
index 6d8e3a1c64cbab135466443f2d62bc18ddf2937b..95667e7ed359c9ebe57f4887eabdb4fa319ecd3c 100644 (file)
@@ -73,8 +73,7 @@ class ModuleAlias : public Module
        {
                ConfigTag* fantasy = ServerInstance->Config->ConfValue("fantasy");
                AllowBots = fantasy->getBool("allowbots", false);
-               std::string fpre = fantasy->getString("prefix");
-               fprefix = fpre.empty() ? "!" : fpre;
+               fprefix = fantasy->getString("prefix", "!", 1, ServerInstance->Config->Limits.MaxLine);
 
                Aliases.clear();
                ConfigTagList tags = ServerInstance->Config->ConfTags("alias");
index b355047ee0bcbdafd881ca6a47df5e726e26fadf..73155b39473c577fec04b7c8ccfd9d04b92eec70 100644 (file)
@@ -32,8 +32,7 @@ class OperPrefixMode : public PrefixMode
                OperPrefixMode(Module* Creator)
                        : PrefixMode(Creator, "operprefix", 'y', OPERPREFIX_VALUE)
                {
-                       std::string pfx = ServerInstance->Config->ConfValue("operprefix")->getString("prefix", "!");
-                       prefix = pfx.empty() ? '!' : pfx[0];
+                       prefix = ServerInstance->Config->ConfValue("operprefix")->getString("prefix", "!", 1, 1)[0];
                        levelrequired = INT_MAX;
                }
 };