diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-18 17:58:41 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-18 17:58:41 +0000 |
commit | 4fca1ffbc43dd0eda8e6df665dac0fa83512daf8 (patch) | |
tree | 06787715deb971b657d4580394818dd02ea13fa6 /src/modules | |
parent | fa452641bf37077fcda964d59e404a76e1fb13e5 (diff) |
More classbase cleanup, hold ConfigTag reference in Autoconnect/Link
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11906 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 2 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_openssl.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_alias.cpp | 48 | ||||
-rw-r--r-- | src/modules/m_helpop.cpp | 22 | ||||
-rw-r--r-- | src/modules/m_spanningtree/link.h | 4 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 119 |
6 files changed, 80 insertions, 117 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index ec8993f4b..0267b6595 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -74,7 +74,7 @@ static ssize_t gnutls_push_wrapper(gnutls_transport_ptr_t user_wrap, const void* /** Represents an SSL user's extra data */ -class issl_session : public classbase +class issl_session { public: issl_session() diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index cd648c1b4..0c01e4d08 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -48,7 +48,7 @@ static int error_callback(const char *str, size_t len, void *u); /** Represents an SSL user's extra data */ -class issl_session : public classbase +class issl_session { public: SSL* sess; diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 62c02396a..522259ebd 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -58,7 +58,7 @@ class ModuleAlias : public Module * We can, however, use a fancy invention: the multimap. Maps a key to one or more values. * -- w00t */ - std::multimap<std::string, Alias> Aliases; + std::multimap<irc::string, Alias> Aliases; /* whether or not +B users are allowed to use fantasy commands */ bool AllowBots; @@ -73,33 +73,33 @@ class ModuleAlias : public Module fprefix = fpre.empty() ? '!' : fpre[0]; Aliases.clear(); - for (int i = 0; i < MyConf.Enumerate("alias"); i++) + for (int i = 0;; i++) { + ConfigTag* tag = ServerInstance->Config->ConfValue("alias", i); + if (!tag) + break; Alias a; - std::string txt; - txt = MyConf.ReadValue("alias", "text", i); - a.AliasedCommand = txt.c_str(); - a.ReplaceFormat = MyConf.ReadValue("alias", "replace", i, true); - a.RequiredNick = MyConf.ReadValue("alias", "requires", i); - a.ULineOnly = MyConf.ReadFlag("alias", "uline", i); - a.ChannelCommand = MyConf.ReadFlag("alias", "channelcommand", "no", i); - a.UserCommand = MyConf.ReadFlag("alias", "usercommand", "yes", i); - a.OperOnly = MyConf.ReadFlag("alias", "operonly", i); - a.format = MyConf.ReadValue("alias", "format", i); - a.CaseSensitive = MyConf.ReadFlag("alias", "matchcase", i); - Aliases.insert(std::make_pair(txt, a)); + a.AliasedCommand = tag->getString("text").c_str(); + tag->readString("replace", a.ReplaceFormat, true); + a.RequiredNick = tag->getString("requires"); + a.ULineOnly = tag->getBool("uline"); + a.ChannelCommand = tag->getBool("channelcommand", "no"); + a.UserCommand = tag->getBool("usercommand", "yes"); + a.OperOnly = tag->getBool("operonly"); + a.format = tag->getString("format"); + a.CaseSensitive = tag->getBool("matchcase"); + Aliases.insert(std::make_pair(a.AliasedCommand, a)); } } public: ModuleAlias() - { + { ReadAliases(); ServerInstance->Modules->Attach(I_OnPreCommand, this); ServerInstance->Modules->Attach(I_OnRehash, this); ServerInstance->Modules->Attach(I_OnUserMessage, this); - } virtual ~ModuleAlias() @@ -138,7 +138,7 @@ class ModuleAlias : public Module virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, User *user, bool validated, const std::string &original_line) { - std::multimap<std::string, Alias>::iterator i, upperbound; + std::multimap<irc::string, Alias>::iterator i, upperbound; /* If theyre not registered yet, we dont want * to know. @@ -147,11 +147,11 @@ class ModuleAlias : public Module return MOD_RES_PASSTHRU; /* We dont have any commands looking like this? Stop processing. */ - i = Aliases.find(command); + i = Aliases.find(command.c_str()); if (i == Aliases.end()) return MOD_RES_PASSTHRU; /* Avoid iterating on to different aliases if no patterns match. */ - upperbound = Aliases.upper_bound(command); + upperbound = Aliases.upper_bound(command.c_str()); irc::string c = command.c_str(); /* The parameters for the command in their original form, with the command stripped off */ @@ -196,11 +196,12 @@ class ModuleAlias : public Module } Channel *c = (Channel *)dest; - std::string fcommand; + std::string scommand; // text is like "!moo cows bite me", we want "!moo" first irc::spacesepstream ss(text); - ss.GetToken(fcommand); + ss.GetToken(scommand); + irc::string fcommand = scommand.c_str(); if (fcommand.empty()) { @@ -215,15 +216,14 @@ class ModuleAlias : public Module // nor do we give a shit about the prefix fcommand.erase(fcommand.begin()); - std::transform(fcommand.begin(), fcommand.end(), fcommand.begin(), ::toupper); - std::multimap<std::string, Alias>::iterator i = Aliases.find(fcommand); + std::multimap<irc::string, Alias>::iterator i = Aliases.find(fcommand); if (i == Aliases.end()) return; /* Avoid iterating on to other aliases if no patterns match */ - std::multimap<std::string, Alias>::iterator upperbound = Aliases.upper_bound(fcommand); + std::multimap<irc::string, Alias>::iterator upperbound = Aliases.upper_bound(fcommand); /* The parameters for the command in their original form, with the command stripped off */ diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp index cba630bbc..8f19bd72b 100644 --- a/src/modules/m_helpop.cpp +++ b/src/modules/m_helpop.cpp @@ -104,11 +104,7 @@ class CommandHelpop : public Command user->WriteServ("292 %s : -", user->nick.c_str()); user->WriteServ("292 %s :*** End of HELPOP", user->nick.c_str()); } - - /* We dont want these going out over the network, return CMD_FAILURE - * to make sure the protocol module thinks theyre not worth sending. - */ - return CMD_FAILURE; + return CMD_SUCCESS; } }; @@ -137,10 +133,14 @@ class ModuleHelpop : public Module helpop_map.clear(); - for (int i = 0; i < MyConf.Enumerate("helpop"); i++) + for (int i = 0;; i++) { - irc::string key = assign(MyConf.ReadValue("helpop", "key", i)); - std::string value = MyConf.ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */ + ConfigTag* tag = ServerInstance->Config->ConfValue("helpop", i); + if (!tag) + break; + irc::string key = assign(tag->getString("key")); + std::string value; + tag->readString("value", value, true); /* Linefeeds allowed */ if (key == "index") { @@ -153,12 +153,12 @@ class ModuleHelpop : public Module if (helpop_map.find("start") == helpop_map.end()) { // error! - throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf."); + throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf."); } else if (helpop_map.find("nohelp") == helpop_map.end()) { // error! - throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf."); + throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf."); } } @@ -183,7 +183,7 @@ class ModuleHelpop : public Module virtual Version GetVersion() { - return Version("/helpop Command, Works like Unreal helpop", VF_COMMON | VF_VENDOR); + return Version("/helpop Command, Works like Unreal helpop", VF_VENDOR | VF_COMMON); } }; diff --git a/src/modules/m_spanningtree/link.h b/src/modules/m_spanningtree/link.h index ae7655ebb..484569892 100644 --- a/src/modules/m_spanningtree/link.h +++ b/src/modules/m_spanningtree/link.h @@ -17,6 +17,7 @@ class Link : public refcountbase { public: + reference<ConfigTag> tag; irc::string Name; std::string IPAddr; int Port; @@ -29,16 +30,19 @@ class Link : public refcountbase int Timeout; std::string Bind; bool Hidden; + Link(ConfigTag* Tag) : tag(tag) {} }; class Autoconnect : public refcountbase { public: + reference<ConfigTag> tag; std::vector<std::string> servers; unsigned long Period; time_t NextConnectTime; /** Negative == inactive */ int position; + Autoconnect(ConfigTag* Tag) : tag(tag) {} }; diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index c4d5755e6..b8560aaba 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -23,8 +23,6 @@ #include "treesocket.h" #include "resolvers.h" -/* $ModDep: m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */ - /* Create server sockets off a listener. */ void ServerSocketListener::OnAcceptReady(int newsock) { @@ -342,34 +340,19 @@ void SpanningTreeUtilities::RefreshIPCache() continue; } - ValidIPs.push_back(L->IPAddr); - if (L->AllowMask.length()) ValidIPs.push_back(L->AllowMask); - /* Needs resolving */ - bool ipvalid = true; - QueryType start_type = DNS_QUERY_A; - start_type = DNS_QUERY_AAAA; - if (strchr(L->IPAddr.c_str(),':')) - { - in6_addr n; - if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1) - ipvalid = false; - } + irc::sockets::sockaddrs dummy; + bool ipvalid = irc::sockets::aptosa(L->IPAddr, L->Port, &dummy); + if (ipvalid) + ValidIPs.push_back(L->IPAddr); else { - in_addr n; - if (inet_aton(L->IPAddr.c_str(),&n) < 1) - ipvalid = false; - } - - if (!ipvalid) - { try { bool cached; - SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, L, cached, start_type); + SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, L, cached, DNS_QUERY_AAAA); ServerInstance->AddResolver(sr, cached); } catch (...) @@ -385,12 +368,15 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) if (rebind) { - for (int j = 0; j < Conf.Enumerate("bind"); j++) + for (int j = 0; ; j++) { - std::string Type = Conf.ReadValue("bind","type",j); - std::string IP = Conf.ReadValue("bind","address",j); - std::string Port = Conf.ReadValue("bind","port",j); - std::string ssl = Conf.ReadValue("bind","ssl",j); + ConfigTag* tag = ServerInstance->Config->ConfValue("bind", j); + if (!tag) + break; + std::string Type = tag->getString("type"); + std::string IP = tag->getString("address"); + std::string Port = tag->getString("port"); + std::string ssl = tag->getString("ssl"); if (Type == "servers") { irc::portparser portrange(Port, false); @@ -431,22 +417,24 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) AutoconnectBlocks.clear(); LinkBlocks.clear(); ValidIPs.clear(); - for (int j = 0; j < Conf.Enumerate("link"); ++j) + for (int j = 0;; ++j) { - reference<Link> L = new Link; - std::string Allow = Conf.ReadValue("link", "allowmask", j); - L->Name = (Conf.ReadValue("link", "name", j)).c_str(); - L->AllowMask = Allow; - L->IPAddr = Conf.ReadValue("link", "ipaddr", j); - L->Port = Conf.ReadInteger("link", "port", j, true); - L->SendPass = Conf.ReadValue("link", "sendpass", j); - L->RecvPass = Conf.ReadValue("link", "recvpass", j); - L->Fingerprint = Conf.ReadValue("link", "fingerprint", j); - L->HiddenFromStats = Conf.ReadFlag("link", "statshidden", j); - L->Timeout = Conf.ReadInteger("link", "timeout", j, true); - L->Hook = Conf.ReadValue("link", "ssl", j); - L->Bind = Conf.ReadValue("link", "bind", j); - L->Hidden = Conf.ReadFlag("link", "hidden", j); + ConfigTag* tag = ServerInstance->Config->ConfValue("link", j); + if (!tag) + break; + reference<Link> L = new Link(tag); + L->Name = tag->getString("name").c_str(); + L->AllowMask = tag->getString("allowmask"); + L->IPAddr = tag->getString("ipaddr"); + L->Port = tag->getInt("port"); + L->SendPass = tag->getString("sendpass"); + L->RecvPass = tag->getString("recvpass"); + L->Fingerprint = tag->getString("fingerprint"); + L->HiddenFromStats = tag->getBool("statshidden"); + L->Timeout = tag->getInt("timeout"); + L->Hook = tag->getString("ssl"); + L->Bind = tag->getString("bind"); + L->Hidden = tag->getBool("hidden"); if (L->Name.find('.') == std::string::npos) throw CoreException("The link name '"+assign(L->Name)+"' is invalid and must contain at least one '.' character"); @@ -456,40 +444,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) if ((!L->IPAddr.empty()) && (!L->RecvPass.empty()) && (!L->SendPass.empty()) && (!L->Name.empty()) && (L->Port)) { - if (Allow.length()) - ValidIPs.push_back(Allow); - ValidIPs.push_back(L->IPAddr); - - /* Needs resolving */ - bool ipvalid = true; - QueryType start_type = DNS_QUERY_A; - start_type = DNS_QUERY_AAAA; - if (strchr(L->IPAddr.c_str(),':')) - { - in6_addr n; - if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1) - ipvalid = false; - } - else - { - in_addr n; - if (inet_aton(L->IPAddr.c_str(),&n) < 1) - ipvalid = false; - } - - if (!ipvalid) - { - try - { - bool cached; - SecurityIPResolver* sr = new SecurityIPResolver(Creator, this, L->IPAddr, L, cached, start_type); - ServerInstance->AddResolver(sr, cached); - } - catch (...) - { - } - } } else { @@ -524,14 +479,16 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) LinkBlocks.push_back(L); } - for (int j = 0; j < Conf.Enumerate("autoconnect"); ++j) + for (int j = 0;; ++j) { - reference<Autoconnect> A = new Autoconnect; - A->Period = Conf.ReadInteger("autoconnect", "period", j, true); + ConfigTag* tag = ServerInstance->Config->ConfValue("autoconnect", j); + if (!tag) + break; + reference<Autoconnect> A = new Autoconnect(tag); + A->Period = tag->getInt("period"); A->NextConnectTime = ServerInstance->Time() + A->Period; A->position = -1; - std::string servers = Conf.ReadValue("autoconnect", "server", j); - irc::spacesepstream ss(servers); + irc::spacesepstream ss(tag->getString("server")); std::string server; while (ss.GetToken(server)) { @@ -550,6 +507,8 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) AutoconnectBlocks.push_back(A); } + + RefreshIPCache(); } Link* SpanningTreeUtilities::FindLink(const std::string& name) |