]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Use ConfigTagList as a faster access method for access to configuration
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 21 Oct 2009 23:46:13 +0000 (23:46 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 21 Oct 2009 23:46:13 +0000 (23:46 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11948 e03df62e-2008-0410-955e-edbf42e46eb7

13 files changed:
include/configreader.h
include/users.h
src/configreader.cpp
src/logger.cpp
src/modules.cpp
src/modules/m_alias.cpp
src/modules/m_helpop.cpp
src/modules/m_opermodes.cpp
src/modules/m_restrictchans.cpp
src/modules/m_spanningtree/utils.cpp
src/modules/m_vhost.cpp
src/socket.cpp
src/stats.cpp

index 6afea4504610c0370e268536fb78d5dba243a5b7..024e28909fcaf0dd365691fc5377224ffc0536ac 100644 (file)
@@ -143,6 +143,8 @@ class CoreExport OperInfo : public refcountbase
 
 typedef std::map<std::string, reference<ConfigTag> > TagIndex;
 typedef std::map<std::string, reference<OperInfo> > OperIndex;
+typedef ConfigDataHash::iterator ConfigIter;
+typedef std::pair<ConfigDataHash::iterator, ConfigDataHash::iterator> ConfigTagList;
 
 /** This class holds the bulk of the runtime configuration for the ircd.
  * It allows for reading new config values, accessing configuration files,
@@ -161,7 +163,9 @@ class CoreExport ServerConfig
         * @param tag The name of the tag to get
         * @param offset get the Nth occurance of the tag
         */
-       ConfigTag* ConfValue(const std::string& tag, int offset = 0);
+       ConfigTag* ConfValue(const std::string& tag);
+
+       ConfigTagList ConfTags(const std::string& tag);
 
        /** Error stream, contains error output from any failed configuration parsing.
         */
@@ -616,4 +620,5 @@ class CoreExport ServerConfig
        bool InvBypassModes;
 
 };
+
 #endif
index 241eed0c6ffd65c29e7fcb504ffe679074010399..49e43f0bf4a748bef63f3cb934125a69049ebf92 100644 (file)
@@ -210,19 +210,19 @@ struct CoreExport ConnectClass : public refcountbase
 
 /** Holds a complete list of all channels to which a user has been invited and has not yet joined, and the time at which they'll expire.
  */
-CoreExport typedef std::vector< std::pair<irc::string, time_t> > InvitedList;
+typedef std::vector< std::pair<irc::string, time_t> > InvitedList;
 
 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
  */
-CoreExport typedef std::vector<reference<ConnectClass> > ClassVector;
+typedef std::vector<reference<ConnectClass> > ClassVector;
 
 /** Typedef for the list of user-channel records for a user
  */
-CoreExport typedef std::set<Channel*> UserChanList;
+typedef std::set<Channel*> UserChanList;
 
 /** Shorthand for an iterator into a UserChanList
  */
-CoreExport typedef UserChanList::iterator UCListIter;
+typedef UserChanList::iterator UCListIter;
 
 /* Required forward declaration
  */
@@ -283,7 +283,7 @@ class CoreExport User : public StreamSocket
        time_t idle_lastmsg;
 
        /** Client address that the user is connected from.
-        * Do not modify this value directly, use SetClientIP() to change it
+        * Do not modify this value directly, use SetClientIP() to change it.
         * Port is not valid for remote users.
         */
        irc::sockets::sockaddrs client_sa;
index 5d47e1931ad9a3d77181d67c63cc1af969813be3..20e244dcc74c6b4f71de35de1d665768e6a8786c 100644 (file)
@@ -574,11 +574,10 @@ static void FindDNS(std::string& server)
 
 static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
 {
-       for(int i=0;; ++i)
+       ConfigTagList tags = conf->ConfTags(tag);
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* ctag = conf->ConfValue(tag, i);
-               if (!ctag)
-                       break;
+               ConfigTag* ctag = i->second;
                std::string mask;
                if (!ctag->readString(key, mask))
                        throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation());
@@ -593,22 +592,19 @@ typedef std::map<std::string, ConfigTag*> LocalIndex;
 void ServerConfig::CrossCheckOperClassType()
 {
        LocalIndex operclass;
-       for (int i = 0;; ++i)
+       ConfigTagList tags = ConfTags("class");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ConfValue("class", i);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string name = tag->getString("name");
                if (name.empty())
                        throw CoreException("<class:name> missing from tag at " + tag->getTagLocation());
                operclass[name] = tag;
        }
-       for (int i = 0;; ++i)
+       tags = ConfTags("type");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ConfValue("type", i);
-               if (!tag)
-                       break;
-
+               ConfigTag* tag = i->second;
                std::string name = tag->getString("name");
                if (name.empty())
                        throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation());
@@ -631,11 +627,10 @@ void ServerConfig::CrossCheckOperClassType()
                }
        }
 
-       for (int i = 0;; ++i)
+       tags = ConfTags("oper");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ConfValue("oper", i);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
 
                std::string name = tag->getString("name");
                if (name.empty())
@@ -673,19 +668,18 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
        }
 
        ClassMap newBlocksByMask;
+       Classes.resize(config_data.count("type"));
        std::map<std::string, int> names;
 
        bool try_again = true;
        for(int tries=0; try_again; tries++)
        {
                try_again = false;
-               for(unsigned int i=0;; i++)
+               ConfigTagList tags = ConfTags("type");
+               int i=0;
+               for(ConfigIter it = tags.first; it != tags.second; ++it, ++i)
                {
-                       ConfigTag* tag = ConfValue("connect", i);
-                       if (!tag)
-                               break;
-                       if (Classes.size() <= i)
-                               Classes.resize(i+1);
+                       ConfigTag* tag = it->second;
                        if (Classes[i])
                                continue;
 
@@ -901,22 +895,20 @@ void ServerConfig::Fill()
        if (!sid.empty() && !ServerInstance->IsSID(sid))
                throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
 
-       for (int i = 0;; ++i)
+       ConfigTagList tags = ConfTags("uline");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ConfValue("uline", i);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string server;
                if (!tag->readString("server", server))
                        throw CoreException("<uline> tag missing server at " + tag->getTagLocation());
                ulines[assign(server)] = tag->getBool("silent");
        }
 
-       for(int i=0;; ++i)
+       tags = ConfTags("banlist");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ConfValue("banlist", i);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string chan;
                if (!tag->readString("chan", chan))
                        throw CoreException("<banlist> tag missing chan at " + tag->getTagLocation());
@@ -1002,11 +994,13 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
                        std::string tag = Once[Index];
                        if (!ConfValue(tag))
                                throw CoreException("You have not defined a <"+tag+"> tag, this is required.");
-                       if (ConfValue(tag, 1))
+                       ConfigTagList tags = ConfTags(tag);
+                       if (tags.first != tags.second)
                        {
+                               tags.first++;
                                errstr << "You have more than one <" << tag << "> tag.\n"
-                                       << "First occurrence at " << ConfValue(tag, 0)->getTagLocation()
-                                       << "; second occurrence at " << ConfValue(tag, 1)->getTagLocation() << std::endl;
+                                       << "First occurrence at " << ConfValue(tag)->getTagLocation()
+                                       << "; second occurrence at " << tags.first->second->getTagLocation() << std::endl;
                        }
                }
 
@@ -1135,11 +1129,10 @@ void ServerConfig::ApplyModules(User* user)
        std::vector<std::string> added_modules;
        std::set<std::string> removed_modules(v.begin(), v.end());
 
-       for(int i=0; ; i++)
+       ConfigTagList tags = ConfTags("module");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ConfValue("module", i);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string name;
                if (tag->readString("name", name))
                {
@@ -1199,20 +1192,19 @@ bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
        return (path.length() > 2 && isalpha(path[0]) && path[1] == ':');
 }
 
-ConfigTag* ServerConfig::ConfValue(const std::string &tag, int offset)
+ConfigTag* ServerConfig::ConfValue(const std::string &tag)
 {
-       ConfigDataHash::size_type pos = offset;
-       if (pos >= config_data.count(tag))
-               return NULL;
-
        ConfigDataHash::iterator iter = config_data.find(tag);
-
-       for(int i = 0; i < offset; i++)
-               iter++;
-
+       if (iter == config_data.end())
+               return NULL;
        return iter->second;
 }
 
+ConfigTagList ServerConfig::ConfTags(const std::string& tag)
+{
+       return config_data.equal_range(tag);
+}
+
 bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf)
 {
        if (!this)
index f1bbaa7ea70ca95abf7b52aa9fa7e1129e20ab34..e92762b46e0b7b516858b9ba7501ca31909cc743 100644 (file)
@@ -86,12 +86,10 @@ void LogManager::OpenFileLogs()
        }
        ConfigReader Conf;
        std::map<std::string, FileWriter*> logmap;
-       std::map<std::string, FileWriter*>::iterator i;
-       for (int index = 0;; ++index)
+       ConfigTagList tags = ServerInstance->Config->ConfTags("log");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("log", index);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string method = tag->getString("method");
                if (method != "file")
                {
@@ -122,8 +120,9 @@ void LogManager::OpenFileLogs()
                        loglevel = NONE;
                }
                FileWriter* fw;
-               std::string target = Conf.ReadValue("log", "target", index);
-               if ((i = logmap.find(target)) == logmap.end())
+               std::string target = tag->getString("target");
+               std::map<std::string, FileWriter*>::iterator fwi = logmap.find(target);
+               if (fwi == logmap.end())
                {
                        FILE* f = fopen(target.c_str(), "a");
                        fw = new FileWriter(f);
@@ -131,7 +130,7 @@ void LogManager::OpenFileLogs()
                }
                else
                {
-                       fw = i->second;
+                       fw = fwi->second;
                }
                FileLogStream* fls = new FileLogStream(loglevel, fw);
                AddLogTypes(type, fls, true);
index a4b9e05fa7a13d04fbe41ca47bbcc16c536f79af..f70c45bf2b048096d4194bf8146daabecfe8d83b 100644 (file)
@@ -588,11 +588,10 @@ void ModuleManager::LoadAll()
                printf("\n");
        }
 
-       for(int count = 0;; count++)
+       ConfigTagList tags = ServerInstance->Config->ConfTags("module");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("module", count);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string name = tag->getString("name");
                printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",name.c_str());
 
@@ -825,12 +824,23 @@ ConfigReader::~ConfigReader()
 {
 }
 
+static ConfigTag* SlowGetTag(const std::string &tag, int index)
+{
+       ConfigTagList tags = ServerInstance->Config->ConfTags(tag);
+       while (tags.first != tags.second)
+       {
+               if (!index)
+                       return tags.first->second;
+               tags.first++;
+               index--;
+       }
+       return NULL;
+}
 
 std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
 {
-       /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
        std::string result = default_value;
-       if (!ServerInstance->Config->ConfValue(tag, index)->readString(name, result, allow_linefeeds))
+       if (!SlowGetTag(tag, index)->readString(name, result, allow_linefeeds))
        {
                this->error = CONF_VALUE_NOT_FOUND;
        }
@@ -845,7 +855,7 @@ std::string ConfigReader::ReadValue(const std::string &tag, const std::string &n
 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
 {
        bool def = (default_value == "yes");
-       return ServerInstance->Config->ConfValue(tag, index)->getBool(name, def);
+       return SlowGetTag(tag, index)->getBool(name, def);
 }
 
 bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
@@ -857,7 +867,7 @@ bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int
 int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
 {
        int v = atoi(default_value.c_str());
-       int result = ServerInstance->Config->ConfValue(tag, index)->getInt(name, v);
+       int result = SlowGetTag(tag, index)->getInt(name, v);
 
        if ((need_positive) && (result < 0))
        {
@@ -885,7 +895,7 @@ int ConfigReader::Enumerate(const std::string &tag)
        ServerInstance->Logs->Log("MODULE", DEBUG, "Module is using ConfigReader::Enumerate on %s; this is slow!",
                tag.c_str());
        int i=0;
-       while (ServerInstance->Config->ConfValue(tag, i)) i++;
+       while (SlowGetTag(tag, i)) i++;
        return i;
 }
 
index 8a58e3dd4a18675ae37119556c56bb8bdf3f8004..a5f543508a3fb18f450f7a71eb28183a4fb65dd4 100644 (file)
@@ -73,11 +73,10 @@ class ModuleAlias : public Module
                fprefix = fpre.empty() ? '!' : fpre[0];
 
                Aliases.clear();
-               for (int i = 0;; i++)
+               ConfigTagList tags = ServerInstance->Config->ConfTags("alias");
+               for(ConfigIter i = tags.first; i != tags.second; ++i)
                {
-                       ConfigTag* tag = ServerInstance->Config->ConfValue("alias", i);
-                       if (!tag)
-                               break;
+                       ConfigTag* tag = i->second;
                        Alias a;
                        a.AliasedCommand = tag->getString("text").c_str();
                        tag->readString("replace", a.ReplaceFormat, true);
index 8f19bd72b739bfbae57e3363b91de7d83e942d2c..43da5b4ac841a6faed8ff885a7836b7160c7e09e 100644 (file)
@@ -133,11 +133,10 @@ class ModuleHelpop : public Module
 
                        helpop_map.clear();
 
-                       for (int i = 0;; i++)
+                       ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
+                       for(ConfigIter i = tags.first; i != tags.second; ++i)
                        {
-                               ConfigTag* tag = ServerInstance->Config->ConfValue("helpop", i);
-                               if (!tag)
-                                       break;
+                               ConfigTag* tag = i->second;
                                irc::string key = assign(tag->getString("key"));
                                std::string value;
                                tag->readString("value", value, true); /* Linefeeds allowed */
index 6b5ca10f95de62d70a3c0425dd1b8b6a8a86b05a..94a9eefe901b232c301dc88d52673b79bc29df3b 100644 (file)
@@ -49,22 +49,10 @@ class ModuleModesOnOper : public Module
                        ApplyModes(user, ThisOpersModes);
                }
 
-               if (!opername.empty()) // if user is local ..
+               ThisOpersModes = user->oper->getConfig("modes");
+               if (!ThisOpersModes.empty())
                {
-                       for (int i = 0;; i++)
-                       {
-                               ConfigTag* tag = ServerInstance->Config->ConfValue("oper", i);
-                               if (!tag)
-                                       break;
-                               if (tag->getString("name") != opername)
-                                       continue;
-                               ThisOpersModes = tag->getString("modes");
-                               if (!ThisOpersModes.empty())
-                               {
-                                       ApplyModes(user, ThisOpersModes);
-                               }
-                               break;
-                       }
+                       ApplyModes(user, ThisOpersModes);
                }
        }
 
index 8cc882d9050e736d0d387180a92e6962dc5fbf9c..557515fe041a307607715895758f4c572a28b0ed 100644 (file)
@@ -22,11 +22,10 @@ class ModuleRestrictChans : public Module
        void ReadConfig()
        {
                allowchans.clear();
-               for (int i = 0;; i++)
+               ConfigTagList tags = ServerInstance->Config->ConfTags("allowchannel");
+               for(ConfigIter i = tags.first; i != tags.second; ++i)
                {
-                       ConfigTag* tag = ServerInstance->Config->ConfValue("allowchannel", i);
-                       if (!tag)
-                               return;
+                       ConfigTag* tag = i->second;
                        std::string txt = tag->getString("name");
                        allowchans.insert(txt.c_str());
                }
index b8560aaba7c5efd382f9c741649927914e304279..10a8888334ff0eae1076a652877bb7a97c4aa924 100644 (file)
@@ -368,11 +368,10 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
 
        if (rebind)
        {
-               for (int j = 0; ; j++)
+               ConfigTagList tags = ServerInstance->Config->ConfTags("bind");
+               for(ConfigIter i = tags.first; i != tags.second; ++i)
                {
-                       ConfigTag* tag = ServerInstance->Config->ConfValue("bind", j);
-                       if (!tag)
-                               break;
+                       ConfigTag* tag = i->second;
                        std::string Type = tag->getString("type");
                        std::string IP = tag->getString("address");
                        std::string Port = tag->getString("port");
@@ -417,11 +416,10 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
        AutoconnectBlocks.clear();
        LinkBlocks.clear();
        ValidIPs.clear();
-       for (int j = 0;; ++j)
+       ConfigTagList tags = ServerInstance->Config->ConfTags("link");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("link", j);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                reference<Link> L = new Link(tag);
                L->Name = tag->getString("name").c_str();
                L->AllowMask = tag->getString("allowmask");
@@ -479,11 +477,10 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
                LinkBlocks.push_back(L);
        }
 
-       for (int j = 0;; ++j)
+       tags = ServerInstance->Config->ConfTags("autoconnect");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("autoconnect", j);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                reference<Autoconnect> A = new Autoconnect(tag);
                A->Period = tag->getInt("period");
                A->NextConnectTime = ServerInstance->Time() + A->Period;
index 18c2a1eb059fbded40b417dccd88fe47c5576a14..1fac18514e04f4c765b65eb9c2cede840b7a78c6 100644 (file)
@@ -27,11 +27,10 @@ class CommandVhost : public Command
 
        CmdResult Handle (const std::vector<std::string> &parameters, User *user)
        {
-               for (int index = 0;; index++)
+               ConfigTagList tags = ServerInstance->Config->ConfTags("vhost");
+               for(ConfigIter i = tags.first; i != tags.second; ++i)
                {
-                       ConfigTag* tag = ServerInstance->Config->ConfValue("vhost", index);
-                       if (!tag)
-                               break;
+                       ConfigTag* tag = i->second;
                        std::string mask = tag->getString("host");
                        std::string username = tag->getString("user");
                        std::string pass = tag->getString("pass");
index c4be23a6092b0483a024f916011c4b7200f17d57..1666e3e8b1c89e63e84b910274feeb52ca27406b 100644 (file)
@@ -108,11 +108,10 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports)
        int bound = 0;
        std::vector<ListenSocketBase*> old_ports(ports.begin(), ports.end());
 
-       for (int count = 0;; count++)
+       ConfigTagList tags = ServerInstance->Config->ConfTags("bind");
+       for(ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("bind", count);
-               if (!tag)
-                       break;
+               ConfigTag* tag = i->second;
                std::string porttag = tag->getString("port");
                std::string Addr = tag->getString("address");
                std::string Type = tag->getString("type");
index 588953f35c2447d715d5091327c54fab53e64c1c..a469600af891e19fc55f9953e9d410751ed05699 100644 (file)
@@ -234,14 +234,15 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results)
 
                /* stats o */
                case 'o':
-                       for (int i = 0;; i++)
+               {
+                       ConfigTagList tags = ServerInstance->Config->ConfTags("oper");
+                       for(ConfigIter i = tags.first; i != tags.second; ++i)
                        {
-                               ConfigTag* tag = Config->ConfValue("oper", i);
-                               if (!tag)
-                                       break;
+                               ConfigTag* tag = i->second;
                                results.push_back(sn+" 243 "+user->nick+" O "+tag->getString("host")+" * "+
                                        tag->getString("name") + " " + tag->getString("type")+" 0");
                        }
+               }
                break;
 
                /* stats l (show user I/O stats) */