summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-11-18 17:30:38 +0100
committerPeter Powell <petpow@saberuk.com>2017-11-16 14:15:25 +0000
commit3b51dfb1d611a874c3f1138d1c1ec1bb8984334c (patch)
tree83e33012964806048fc9f1b69056c24f4246d8d0
parent5287af979e5abffb2cfcdadb9a7663b42a5c43e5 (diff)
Add events which are fired when a service is added or deleted.
-rw-r--r--include/modules.h11
-rw-r--r--src/modules.cpp8
-rw-r--r--src/modules/m_pbkdf2.cpp68
3 files changed, 34 insertions, 53 deletions
diff --git a/include/modules.h b/include/modules.h
index 5244930d0..33b41e28f 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -243,6 +243,7 @@ enum Implementation
I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass,
I_OnText, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric,
I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent, I_OnSetUserIP,
+ I_OnServiceAdd, I_OnServiceDel,
I_END
};
@@ -1006,6 +1007,16 @@ class CoreExport Module : public classbase, public usecountbase
* @param user The user whose IP is being set
*/
virtual void OnSetUserIP(LocalUser* user);
+
+ /** Called whenever a ServiceProvider is registered.
+ * @param service ServiceProvider being registered.
+ */
+ virtual void OnServiceAdd(ServiceProvider& service);
+
+ /** Called whenever a ServiceProvider is unregistered.
+ * @param service ServiceProvider being unregistered.
+ */
+ virtual void OnServiceDel(ServiceProvider& service);
};
/** A list of modules
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;
}
}