]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configparser.cpp
Change storage of UserManager::all_opers to be a vector
[user/henk/code/inspircd.git] / src / configparser.cpp
index f3e79e2fdcbc8bc0f374c6b00b1a90b02d54f53f..92f05edd40d33fbf630e769d7bc43dc688bfa61c 100644 (file)
@@ -300,7 +300,7 @@ void ParseStack::DoInclude(ConfigTag* tag, int flags)
                        flags |= FLAG_NO_INC;
                if (tag->getBool("noexec", false))
                        flags |= FLAG_NO_EXEC;
-               if (!ParseFile(name, flags, mandatorytag))
+               if (!ParseFile(ServerInstance->Config->Paths.PrependConfig(name), flags, mandatorytag))
                        throw CoreException("Included");
        }
        else if (tag->readString("executable", name))
@@ -323,9 +323,10 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
        if (exec && (flags & FLAG_NO_EXEC))
                throw CoreException("Invalid <execfiles> tag in file included with noexec=\"yes\"");
 
-       FileWrapper file(exec ? popen(name.c_str(), "r") : fopen(name.c_str(), "r"), exec);
+       std::string path = ServerInstance->Config->Paths.PrependConfig(name);
+       FileWrapper file(exec ? popen(name.c_str(), "r") : fopen(path.c_str(), "r"), exec);
        if (!file)
-               throw CoreException("Could not read \"" + name + "\" for \"" + key + "\" file");
+               throw CoreException("Could not read \"" + path + "\" for \"" + key + "\" file");
 
        file_cache& cache = FilesOutput[key];
        cache.clear();
@@ -343,25 +344,25 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
        }
 }
 
-bool ParseStack::ParseFile(const std::string& name, int flags, const std::string& mandatory_tag)
+bool ParseStack::ParseFile(const std::string& path, int flags, const std::string& mandatory_tag)
 {
-       ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Reading file %s", name.c_str());
+       ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Reading file %s", path.c_str());
        for (unsigned int t = 0; t < reading.size(); t++)
        {
-               if (std::string(name) == reading[t])
+               if (path == reading[t])
                {
-                       throw CoreException("File " + name + " is included recursively (looped inclusion)");
+                       throw CoreException("File " + path + " is included recursively (looped inclusion)");
                }
        }
 
        /* It's not already included, add it to the list of files we've loaded */
 
-       FileWrapper file(fopen(name.c_str(), "r"));
+       FileWrapper file(fopen(path.c_str(), "r"));
        if (!file)
-               throw CoreException("Could not read \"" + name + "\" for include");
+               throw CoreException("Could not read \"" + path + "\" for include");
 
-       reading.push_back(name);
-       Parser p(*this, flags, file, name, mandatory_tag);
+       reading.push_back(path);
+       Parser p(*this, flags, file, path, mandatory_tag);
        bool ok = p.outer_parse();
        reading.pop_back();
        return ok;
@@ -443,13 +444,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;
+}
+
+long ConfigTag::getDuration(const std::string& key, long def, long min, long max)
+{
+       std::string duration;
+       if (!readString(key, duration))
+               return def;
+
+       long ret = InspIRCd::Duration(duration);
+       CheckRange(key, ret, def, min, max);
+       return ret;
 }
 
 double ConfigTag::getFloat(const std::string &key, double def)
@@ -481,10 +499,10 @@ std::string ConfigTag::getTagLocation()
        return src_name + ":" + ConvToStr(src_line);
 }
 
-ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*&items)
+ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*& Items)
 {
        ConfigTag* rv = new ConfigTag(Tag, file, line);
-       items = &rv->items;
+       Items = &rv->items;
        return rv;
 }