]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configparser.cpp
Rename the spanningtree module header to server.
[user/henk/code/inspircd.git] / src / configparser.cpp
index 60770d16d9c8f9b735679fc02747fdc3adc96740..2af796b21c771c3532781d881c7470ec652809f2 100644 (file)
@@ -91,7 +91,7 @@ struct Parser
                unget(ch);
        }
 
-       bool kv(std::vector<KeyVal>* items, std::set<std::string>& seen)
+       bool kv(ConfigItems* items)
        {
                std::string key;
                nextword(key);
@@ -155,7 +155,7 @@ struct Parser
                                }
                                else
                                {
-                                       std::map<std::string, std::string>::iterator var = stack.vars.find(varname);
+                                       insp::flat_map<std::string, std::string>::iterator var = stack.vars.find(varname);
                                        if (var == stack.vars.end())
                                                throw CoreException("Undefined XML entity reference '&" + varname + ";'");
                                        value.append(var->second);
@@ -173,14 +173,14 @@ struct Parser
                        }
                        else if (ch == '"')
                                break;
-                       else
+                       else if (ch != '\r')
                                value.push_back(ch);
                }
 
-               if (!seen.insert(key).second)
+               if (items->find(key) != items->end())
                        throw CoreException("Duplicate key '" + key + "' found");
 
-               items->push_back(KeyVal(key, value));
+               (*items)[key] = value;
                return true;
        }
 
@@ -199,11 +199,10 @@ struct Parser
                if (name.empty())
                        throw CoreException("Empty tag name");
 
-               std::vector<KeyVal>* items;
-               std::set<std::string> seen;
+               ConfigItems* items;
                tag = ConfigTag::create(name, current.filename, current.line, items);
 
-               while (kv(items, seen))
+               while (kv(items))
                {
                        // Do nothing here (silences a GCC warning).
                }
@@ -220,14 +219,14 @@ struct Parser
                }
                else if (name == "files")
                {
-                       for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++)
+                       for(ConfigItems::iterator i = items->begin(); i != items->end(); i++)
                        {
                                stack.DoReadFile(i->first, i->second, flags, false);
                        }
                }
                else if (name == "execfiles")
                {
-                       for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++)
+                       for(ConfigItems::iterator i = items->begin(); i != items->end(); i++)
                        {
                                stack.DoReadFile(i->first, i->second, flags, true);
                        }
@@ -367,7 +366,7 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
 bool ParseStack::ParseFile(const std::string& path, int flags, const std::string& mandatory_tag, bool isexec)
 {
        ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Reading (isexec=%d) %s", isexec, path.c_str());
-       if (std::find(reading.begin(), reading.end(), path) != reading.end())
+       if (stdalgo::isin(reading, path))
                throw CoreException((isexec ? "Executable " : "File ") + path + " is included recursively (looped inclusion)");
 
        /* It's not already included, add it to the list of files we've loaded */
@@ -385,9 +384,7 @@ bool ParseStack::ParseFile(const std::string& path, int flags, const std::string
 
 bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf)
 {
-       if (!this)
-               return false;
-       for(std::vector<KeyVal>::iterator j = items.begin(); j != items.end(); ++j)
+       for(ConfigItems::iterator j = items.begin(); j != items.end(); ++j)
        {
                if(j->first != key)
                        continue;
@@ -405,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;
 }
 
@@ -490,7 +495,7 @@ 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, ConfigItems*& Items)
 {
        ConfigTag* rv = new ConfigTag(Tag, file, line);
        Items = &rv->items;
@@ -502,6 +507,11 @@ ConfigTag::ConfigTag(const std::string& Tag, const std::string& file, int line)
 {
 }
 
+OperInfo::OperInfo(const std::string& Name)
+       : name(Name)
+{
+}
+
 std::string OperInfo::getConfig(const std::string& key)
 {
        std::string rv;