]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
m_ssl_gnutls Add convenience macro for library version checking, change checks to...
[user/henk/code/inspircd.git] / src / modules.cpp
index 4c0af3bace5e40baac7f348afb9a164f07d3a5a2..e1fb605c0a9a73f78cbe772e6ce466b0ce507bb2 100644 (file)
@@ -52,13 +52,6 @@ Version::Version(const std::string &desc, int flags, const std::string& linkdata
 {
 }
 
-Event::Event(Module* src, const std::string &eventid) : source(src), id(eventid) { }
-
-void Event::Send()
-{
-       FOREACH_MOD(OnEvent, (*this));
-}
-
 // These declarations define the behavours of the base class Module (which does nothing at all)
 
 Module::Module() { }
@@ -119,9 +112,7 @@ ModResult   Module::OnStats(char, User*, string_list&) { DetachEvent(I_OnStats); r
 ModResult      Module::OnChangeLocalUserHost(LocalUser*, const std::string&) { DetachEvent(I_OnChangeLocalUserHost); return MOD_RES_PASSTHRU; }
 ModResult      Module::OnChangeLocalUserGECOS(LocalUser*, const std::string&) { DetachEvent(I_OnChangeLocalUserGECOS); return MOD_RES_PASSTHRU; }
 ModResult      Module::OnPreTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPreTopicChange); return MOD_RES_PASSTHRU; }
-void           Module::OnEvent(Event&) { DetachEvent(I_OnEvent); }
 ModResult      Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { DetachEvent(I_OnPassCompare); return MOD_RES_PASSTHRU; }
-void           Module::OnGlobalOper(User*) { DetachEvent(I_OnGlobalOper); }
 void           Module::OnPostConnect(User*) { DetachEvent(I_OnPostConnect); }
 void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { DetachEvent(I_OnUserMessage); }
 void           Module::OnUserInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserInvite); }
@@ -178,7 +169,7 @@ ModuleManager::~ModuleManager()
 
 bool ModuleManager::Attach(Implementation i, Module* mod)
 {
-       if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end())
+       if (stdalgo::isin(EventHandlers[i], mod))
                return false;
 
        EventHandlers[i].push_back(mod);
@@ -198,22 +189,20 @@ void ModuleManager::Attach(Implementation* i, Module* mod, size_t sz)
 
 void ModuleManager::AttachAll(Module* mod)
 {
-       for (size_t i = I_BEGIN + 1; i != I_END; ++i)
+       for (size_t i = 0; i != I_END; ++i)
                Attach((Implementation)i, mod);
 }
 
 void ModuleManager::DetachAll(Module* mod)
 {
-       for (size_t n = I_BEGIN + 1; n != I_END; ++n)
+       for (size_t n = 0; n != I_END; ++n)
                Detach((Implementation)n, mod);
 }
 
-bool ModuleManager::SetPriority(Module* mod, Priority s)
+void ModuleManager::SetPriority(Module* mod, Priority s)
 {
-       for (size_t n = I_BEGIN + 1; n != I_END; ++n)
+       for (size_t n = 0; n != I_END; ++n)
                SetPriority(mod, (Implementation)n, s);
-
-       return true;
 }
 
 bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Module* which)
@@ -656,7 +645,7 @@ ServiceProvider* ModuleManager::FindService(ServiceType type, const std::string&
 }
 
 dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::string& Name)
-       : name(Name), value(NULL), creator(Creator)
+       : name(Name), hook(NULL), value(NULL), creator(Creator)
 {
        if (!dynrefs)
                dynrefs = new insp::intrusive_list<dynamic_reference_base>;
@@ -685,9 +674,19 @@ void dynamic_reference_base::SetProvider(const std::string& newname)
 
 void dynamic_reference_base::resolve()
 {
-       std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules->DataProviders.find(name);
-       if (i != ServerInstance->Modules->DataProviders.end())
-               value = static_cast<DataProvider*>(i->second);
+       // Because find() may return any element with a matching key in case count(key) > 1 use lower_bound()
+       // to ensure a dynref with the same name as another one resolves to the same object
+       std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules.DataProviders.lower_bound(name);
+       if ((i != ServerInstance->Modules.DataProviders.end()) && (i->first == this->name))
+       {
+               ServiceProvider* newvalue = i->second;
+               if (value != newvalue)
+               {
+                       value = newvalue;
+                       if (hook)
+                               hook->OnCapture();
+               }
+       }
        else
                value = NULL;
 }