diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-11-18 17:30:38 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2017-11-16 14:15:25 +0000 |
commit | 3b51dfb1d611a874c3f1138d1c1ec1bb8984334c (patch) | |
tree | 83e33012964806048fc9f1b69056c24f4246d8d0 /src | |
parent | 5287af979e5abffb2cfcdadb9a7663b42a5c43e5 (diff) |
Add events which are fired when a service is added or deleted.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_pbkdf2.cpp | 68 |
2 files changed, 23 insertions, 53 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index de2fe96b3..065f12a1f 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -139,6 +139,8 @@ ModResult Module::OnNumeric(User*, const Numeric::Numeric&) { DetachEvent(I_OnNu ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { DetachEvent(I_OnAcceptConnection); return MOD_RES_PASSTHRU; } ModResult Module::OnSendWhoLine(User*, const std::vector<std::string>&, User*, Membership*, Numeric::Numeric&) { DetachEvent(I_OnSendWhoLine); return MOD_RES_PASSTHRU; } void Module::OnSetUserIP(LocalUser*) { DetachEvent(I_OnSetUserIP); } +void Module::OnServiceAdd(ServiceProvider&) { DetachEvent(I_OnServiceAdd); } +void Module::OnServiceDel(ServiceProvider&) { DetachEvent(I_OnServiceDel); } #ifdef INSPIRCD_ENABLE_TESTSUITE void Module::OnRunTestSuite() { } @@ -547,11 +549,13 @@ void ModuleManager::AddService(ServiceProvider& item) DataProviders.insert(std::make_pair(item.name.substr(slash + 1), &item)); } dynamic_reference_base::reset_all(); - return; + break; } default: item.RegisterService(); } + + FOREACH_MOD(OnServiceAdd, (item)); } void ModuleManager::DelService(ServiceProvider& item) @@ -571,6 +575,8 @@ void ModuleManager::DelService(ServiceProvider& item) default: throw ModuleException("Cannot delete unknown service type"); } + + FOREACH_MOD(OnServiceDel, (item)); } ServiceProvider* ModuleManager::FindService(ServiceType type, const std::string& name) diff --git a/src/modules/m_pbkdf2.cpp b/src/modules/m_pbkdf2.cpp index 314f6b836..8b1346c84 100644 --- a/src/modules/m_pbkdf2.cpp +++ b/src/modules/m_pbkdf2.cpp @@ -180,71 +180,35 @@ class ModulePBKDF2 : public Module stdalgo::delete_all(providers); } - void Prioritize() CXX11_OVERRIDE + void OnServiceAdd(ServiceProvider& provider) CXX11_OVERRIDE { - OnLoadModule(NULL); - } - - void OnLoadModule(Module* mod) CXX11_OVERRIDE - { - bool newProv = false; - // As the module doesn't tell us what ServiceProviders it has, let's iterate all (yay ...) the ServiceProviders - // Good thing people don't run loading and unloading those all the time - for (std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules->DataProviders.begin(); i != ServerInstance->Modules->DataProviders.end(); ++i) - { - ServiceProvider* provider = i->second; - - // Does the service belong to the new mod? - // In the case this is our first run (mod == NULL, continue anyway) - if (mod && provider->creator != mod) - continue; - - // Check if it's a hash provider - if (provider->name.compare(0, 5, "hash/")) - continue; - - HashProvider* hp = static_cast<HashProvider*>(provider); - - if (hp->IsKDF()) - continue; - - bool has_prov = false; - for (std::vector<PBKDF2Provider*>::const_iterator j = providers.begin(); j != providers.end(); ++j) - { - if ((*j)->provider == hp) - { - has_prov = true; - break; - } - } - if (has_prov) - continue; + // Check if it's a hash provider + if (provider.name.compare(0, 5, "hash/")) + return; - newProv = true; + HashProvider* hp = static_cast<HashProvider*>(&provider); + if (hp->IsKDF()) + return; - PBKDF2Provider* prov = new PBKDF2Provider(this, hp); - providers.push_back(prov); - ServerInstance->Modules->AddService(*prov); - } + PBKDF2Provider* prov = new PBKDF2Provider(this, hp); + providers.push_back(prov); + ServerInstance->Modules.AddService(*prov); - if (newProv) - GetConfig(); + GetConfig(); } - void OnUnloadModule(Module* mod) CXX11_OVERRIDE + void OnServiceDel(ServiceProvider& prov) CXX11_OVERRIDE { - for (std::vector<PBKDF2Provider*>::iterator i = providers.begin(); i != providers.end(); ) + for (std::vector<PBKDF2Provider*>::iterator i = providers.begin(); i != providers.end(); ++i) { PBKDF2Provider* item = *i; - if (item->provider->creator != mod) - { - ++i; + if (item->provider != &prov) continue; - } ServerInstance->Modules->DelService(*item); delete item; - i = providers.erase(i); + providers.erase(i); + break; } } |