summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:13 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:13 +0000
commitd8f98565a8617658f610bc94a5d87266930beee4 (patch)
tree365a153c59bc8b521b094c27f25b484a69e5154b
parent984cc96a1f832abf9b5fcfddcd8260c5b12bd2a9 (diff)
Use ConfigTagList as a faster access method for access to configuration
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11948 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/configreader.h7
-rw-r--r--include/users.h10
-rw-r--r--src/configreader.cpp86
-rw-r--r--src/logger.cpp15
-rw-r--r--src/modules.cpp28
-rw-r--r--src/modules/m_alias.cpp7
-rw-r--r--src/modules/m_helpop.cpp7
-rw-r--r--src/modules/m_opermodes.cpp18
-rw-r--r--src/modules/m_restrictchans.cpp7
-rw-r--r--src/modules/m_spanningtree/utils.cpp21
-rw-r--r--src/modules/m_vhost.cpp7
-rw-r--r--src/socket.cpp7
-rw-r--r--src/stats.cpp9
13 files changed, 108 insertions, 121 deletions
diff --git a/include/configreader.h b/include/configreader.h
index 6afea4504..024e28909 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -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
diff --git a/include/users.h b/include/users.h
index 241eed0c6..49e43f0bf 100644
--- a/include/users.h
+++ b/include/users.h
@@ -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;
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 5d47e1931..20e244dcc 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -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)
diff --git a/src/logger.cpp b/src/logger.cpp
index f1bbaa7ea..e92762b46 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -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);
diff --git a/src/modules.cpp b/src/modules.cpp
index a4b9e05fa..f70c45bf2 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -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;
}
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 8a58e3dd4..a5f543508 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -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);
diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp
index 8f19bd72b..43da5b4ac 100644
--- a/src/modules/m_helpop.cpp
+++ b/src/modules/m_helpop.cpp
@@ -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 */
diff --git a/src/modules/m_opermodes.cpp b/src/modules/m_opermodes.cpp
index 6b5ca10f9..94a9eefe9 100644
--- a/src/modules/m_opermodes.cpp
+++ b/src/modules/m_opermodes.cpp
@@ -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);
}
}
diff --git a/src/modules/m_restrictchans.cpp b/src/modules/m_restrictchans.cpp
index 8cc882d90..557515fe0 100644
--- a/src/modules/m_restrictchans.cpp
+++ b/src/modules/m_restrictchans.cpp
@@ -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());
}
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index b8560aaba..10a888833 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -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;
diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp
index 18c2a1eb0..1fac18514 100644
--- a/src/modules/m_vhost.cpp
+++ b/src/modules/m_vhost.cpp
@@ -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");
diff --git a/src/socket.cpp b/src/socket.cpp
index c4be23a60..1666e3e8b 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -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");
diff --git a/src/stats.cpp b/src/stats.cpp
index 588953f35..a469600af 100644
--- a/src/stats.cpp
+++ b/src/stats.cpp
@@ -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) */