diff options
-rw-r--r-- | include/modules.h | 38 | ||||
-rw-r--r-- | modules/commands/os_dns.cpp | 6 | ||||
-rw-r--r-- | modules/commands/os_news.cpp | 3 | ||||
-rw-r--r-- | modules/extra/m_ldap.cpp | 4 | ||||
-rw-r--r-- | modules/extra/m_xmlrpc.cpp | 44 | ||||
-rw-r--r-- | modules/m_dns.cpp | 9 | ||||
-rw-r--r-- | src/modulemanager.cpp | 29 |
7 files changed, 74 insertions, 59 deletions
diff --git a/include/modules.h b/include/modules.h index 14661d1c7..084a8dc26 100644 --- a/include/modules.h +++ b/include/modules.h @@ -62,7 +62,7 @@ #define FOREACH_MOD(ename, args) \ if (true) \ { \ - static std::vector<Module *> &_modules = ModuleManager::GetEventHandlers(#ename); \ + std::vector<Module *> &_modules = ModuleManager::EventHandlers[I_ ## ename]; \ for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \ { \ try \ @@ -96,7 +96,7 @@ else \ if (true) \ { \ ret = EVENT_CONTINUE; \ - static std::vector<Module *> &_modules = ModuleManager::GetEventHandlers(#ename); \ + std::vector<Module *> &_modules = ModuleManager::EventHandlers[I_ ## ename]; \ for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \ { \ try \ @@ -1084,15 +1084,41 @@ class CoreExport Module : public Extensible virtual EventReturn OnNickValidate(User *u, NickAlias *na) { throw NotImplementedException(); } }; +enum Implementation +{ + I_OnPreUserKicked, I_OnUserKicked, I_OnReload, I_OnPreBotAssign, I_OnBotAssign, I_OnBotUnAssign, I_OnUserConnect, + I_OnNewServer, I_OnUserNickChange, I_OnPreHelp, I_OnPostHelp, I_OnPreCommand, I_OnPostCommand, I_OnSaveDatabase, + I_OnLoadDatabase, I_OnEncrypt, I_OnDecrypt, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, + I_OnBadWordDel, I_OnCreateBot, I_OnDelBot, I_OnBotKick, I_OnPrePartChannel, I_OnPartChannel, I_OnLeaveChannel, + I_OnJoinChannel, I_OnTopicUpdated, I_OnPreChanExpire, I_OnChanExpire, I_OnPreServerConnect, I_OnServerConnect, + I_OnPreUplinkSync, I_OnServerDisconnect, I_OnRestart, I_OnShutdown, I_OnPreNickExpire, I_OnNickExpire, I_OnDefconLevel, + I_OnExceptionAdd, I_OnExceptionDel, I_OnAddXLine, I_OnDelXLine, I_IsServicesOper, I_OnServerQuit, I_OnUserQuit, + I_OnPreUserLogoff, I_OnPostUserLogoff, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnAccessDel, I_OnAccessAdd, + I_OnAccessClear, I_OnLevelChange, I_OnChanDrop, I_OnChanRegistered, I_OnChanSuspend, I_OnChanUnsuspend, + I_OnCreateChan, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick, + I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, I_OnNickDrop, I_OnNickForbidden, I_OnNickGroup, I_OnNickIdentify, + I_OnUserLogin, I_OnNickLogout, I_OnNickRegister, I_OnNickSuspend, I_OnNickUnsuspended, I_OnDelNick, I_OnNickCoreCreate, + I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearCert, + I_OnNickAddCert, I_OnNickEraseCert, I_OnNickInfo, I_OnBotInfo, I_OnCheckAuthentication, I_OnNickUpdate, + I_OnFingerprint, I_OnUserAway, I_OnInvite, I_OnDeleteVhost, I_OnSetVhost, I_OnMemoSend, I_OnMemoDel, + I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd, + I_OnMLock, I_OnUnMLock, I_OnModuleLoad, I_OnModuleUnload, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnBotNotice, + I_OnPrivmsg, I_OnLog, I_OnLogMessage, I_OnDnsRequest, I_OnCheckModes, I_OnChannelSync, I_OnSetCorrectModes, + I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate, + I_OnSerializeTypeCreate, I_OnSetChannelOption, I_OnSetNickOption, I_OnMessage, I_OnCanSet, I_OnCheckDelete, + I_OnExpireTick, I_OnNickValidate, + I_SIZE +}; + /** Used to manage modules. */ class CoreExport ModuleManager { + public: /** Event handler hooks. */ - static std::map<Anope::string, std::vector<Module *> > EventHandlers; + static std::vector<Module *> EventHandlers[I_SIZE]; - public: /** List of all modules loaded in Anope */ static std::list<Module *> Modules; @@ -1103,8 +1129,6 @@ class CoreExport ModuleManager static void CleanupRuntimeDirectory(); #endif - static std::vector<Module *> &GetEventHandlers(const Anope::string &name); - /** Loads a given module. * @param m the module to load * @param u the user who loaded it, NULL for auto-load @@ -1154,7 +1178,7 @@ class CoreExport ModuleManager * @param sz The number of modules being passed for PRIO_BEFORE and PRIO_AFTER. Defaults to 1, as most of the time you will only want to prioritize your module * to be before or after one other module. */ - static bool SetPriority(Module *mod, const Anope::string &event, Priority s, Module **modules = NULL, size_t sz = 1); + static bool SetPriority(Module *mod, Implementation i, Priority s, Module **modules = NULL, size_t sz = 1); /** Change the priority of all events in a module. * @param mod The module to set the priority of diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index 717cbf29b..ee651f702 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -663,9 +663,12 @@ class ModuleDNS : public Module bool remove_split_servers; bool readd_connected_servers; + time_t last_warn; + public: ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this) + zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this), + last_warn(0) { @@ -840,7 +843,6 @@ class ModuleDNS : public Module if (packet->answers.size() == answer_size) { - static time_t last_warn = 0; if (last_warn + 60 < Anope::CurTime) { last_warn = Anope::CurTime; diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp index bdff3c5eb..487a45300 100644 --- a/modules/commands/os_news.cpp +++ b/modules/commands/os_news.cpp @@ -325,6 +325,8 @@ class CommandOSRandomNews : public NewsBase } }; +static unsigned cur_rand_news = 0; + class OSNews : public Module { Serialize::Type newsitem_type; @@ -356,7 +358,6 @@ class OSNews : public Module else if (Type == NEWS_RANDOM) msg = _("[\002Random News\002 - %s] %s"); - static unsigned cur_rand_news = 0; unsigned displayed = 0, news_count = Config->GetModule(this)->Get<unsigned>("newscount", "3"); for (unsigned i = 0, end = newsList.size(); i < end; ++i) { diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp index 4bceb0a61..01e927633 100644 --- a/modules/extra/m_ldap.cpp +++ b/modules/extra/m_ldap.cpp @@ -80,7 +80,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition int i = ldap_initialize(&this->con, this->server.c_str()); if (i != LDAP_SUCCESS) throw LDAPException("Unable to connect to LDAP service " + this->name + ": " + ldap_err2string(i)); - static const int version = LDAP_VERSION3; + const int version = LDAP_VERSION3; i = ldap_set_option(this->con, LDAP_OPT_PROTOCOL_VERSION, &version); if (i != LDAP_OPT_SUCCESS) throw LDAPException("Unable to set protocol version for " + this->name + ": " + ldap_err2string(i)); @@ -269,7 +269,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition break; } - static struct timeval tv = { 1, 0 }; + struct timeval tv = { 1, 0 }; LDAPMessage *result; int rtype = ldap_result(this->con, LDAP_RES_ANY, 1, &tv, &result); if (rtype <= 0 || this->GetExitState()) diff --git a/modules/extra/m_xmlrpc.cpp b/modules/extra/m_xmlrpc.cpp index 3c16f997e..36401b800 100644 --- a/modules/extra/m_xmlrpc.cpp +++ b/modules/extra/m_xmlrpc.cpp @@ -3,6 +3,28 @@ #include "modules/xmlrpc.h" #include "modules/httpd.h" +static struct special_chars +{ + Anope::string character; + Anope::string replace; + + special_chars(const Anope::string &c, const Anope::string &r) : character(c), replace(r) { } +} +special[] = { + special_chars("&", "&"), + special_chars("\"", """), + special_chars("<", "<"), + special_chars(">", "&qt;"), + special_chars("'", "'"), + special_chars("\n", "
"), + special_chars("\002", ""), // bold + special_chars("\003", ""), // color + special_chars("\035", ""), // italics + special_chars("\037", ""), // underline + special_chars("\026", ""), // reverses + special_chars("", "") +}; + class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage { std::deque<XMLRPCEvent *> events; @@ -25,28 +47,6 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage Anope::string Sanitize(const Anope::string &string) anope_override { - static struct special_chars - { - Anope::string character; - Anope::string replace; - - special_chars(const Anope::string &c, const Anope::string &r) : character(c), replace(r) { } - } - special[] = { - special_chars("&", "&"), - special_chars("\"", """), - special_chars("<", "<"), - special_chars(">", "&qt;"), - special_chars("'", "'"), - special_chars("\n", "
"), - special_chars("\002", ""), // bold - special_chars("\003", ""), // color - special_chars("\035", ""), // italics - special_chars("\037", ""), // underline - special_chars("\026", ""), // reverses - special_chars("", "") - }; - Anope::string ret = string; for (int i = 0; special[i].character.empty() == false; ++i) ret = ret.replace_all_cs(special[i].character, special[i].replace); diff --git a/modules/m_dns.cpp b/modules/m_dns.cpp index 214e97cf4..01524d1ca 100644 --- a/modules/m_dns.cpp +++ b/modules/m_dns.cpp @@ -281,7 +281,7 @@ class Packet : public Query if (q.name.find(':') != Anope::string::npos) { - static const char *const hex = "0123456789abcdef"; + const char *const hex = "0123456789abcdef"; char reverse_ip[128]; unsigned reverse_ip_count = 0; for (int j = 15; j >= 0; --j) @@ -662,7 +662,8 @@ class MyManager : public Manager, public Timer public: std::map<unsigned short, Request *> requests; - MyManager(Module *creator) : Manager(creator), Timer(300, Anope::CurTime, true), serial(Anope::CurTime), tcpsock(NULL), udpsock(NULL), listen(false) + MyManager(Module *creator) : Manager(creator), Timer(300, Anope::CurTime, true), serial(Anope::CurTime), tcpsock(NULL), udpsock(NULL), + listen(false), cur_id(rand()) { } @@ -717,13 +718,13 @@ class MyManager : public Manager, public Timer } private: + unsigned short cur_id; + unsigned short GetID() { if (this->udpsock->GetPackets().size() == 65535) throw SocketException("DNS queue full"); - static unsigned short cur_id = rand(); - do cur_id = (cur_id + 1) & 0xFFFF; while (!cur_id || this->requests.count(cur_id)); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index a4df9004c..5b22e9419 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -22,7 +22,7 @@ #endif std::list<Module *> ModuleManager::Modules; -std::map<Anope::string, std::vector<Module *> > ModuleManager::EventHandlers; +std::vector<Module *> ModuleManager::EventHandlers[I_SIZE]; #ifdef _WIN32 void ModuleManager::CleanupRuntimeDirectory() @@ -112,19 +112,6 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out } #endif -std::vector<Module *> &ModuleManager::GetEventHandlers(const Anope::string &name) -{ - std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.find(name); - if (it != EventHandlers.end()) - return it->second; - - std::vector<Module *> &modules = EventHandlers[name]; - /* Populate initial vector */ - std::copy(Modules.begin(), Modules.end(), std::back_inserter(modules)); - - return modules; -} - /* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593 * * This function will take a pointer from either dlsym or GetProcAddress and cast it in @@ -263,8 +250,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) Log(LOG_DEBUG) << "Module " << modname << " loaded."; /* Attach module to all events */ - for (std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) - it->second.push_back(m); + for (unsigned i = 0; i < I_SIZE; ++i) + EventHandlers[i].push_back(m); FOREACH_MOD(OnModuleLoad, (u, m)); @@ -365,9 +352,9 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) void ModuleManager::DetachAll(Module *mod) { - for (std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) + for (unsigned i = 0; i < I_SIZE; ++i) { - std::vector<Module *> &mods = it->second; + std::vector<Module *> &mods = EventHandlers[i]; std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod); if (it2 != mods.end()) mods.erase(it2); @@ -376,13 +363,13 @@ void ModuleManager::DetachAll(Module *mod) bool ModuleManager::SetPriority(Module *mod, Priority s) { - for (std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) - SetPriority(mod, it->first, s); + for (unsigned i = 0; i < I_SIZE; ++i) + SetPriority(mod, static_cast<Implementation>(i), s); return true; } -bool ModuleManager::SetPriority(Module *mod, const Anope::string &i, Priority s, Module **modules, size_t sz) +bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Module **modules, size_t sz) { /** To change the priority of a module, we first find its position in the vector, * then we find the position of the other modules in the vector that this module |