diff options
-rw-r--r-- | include/inspircd.h | 10 | ||||
-rw-r--r-- | include/modules.h | 8 | ||||
-rw-r--r-- | src/modules.cpp | 33 | ||||
-rw-r--r-- | src/modules/m_md5.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_oper_hash.cpp | 7 | ||||
-rw-r--r-- | src/modules/m_sha256.cpp | 2 |
6 files changed, 62 insertions, 0 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index f0f5a1d1f..321222aab 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -298,6 +298,10 @@ class InspIRCd : public classbase */ featurelist Features; + /** The interface names published by various modules + */ + interfacelist Interfaces; + /** The current time, updated in the mainloop */ time_t TIME; @@ -707,6 +711,8 @@ class InspIRCd : public classbase */ bool PublishFeature(const std::string &FeatureName, Module* Mod); + bool PublishInterface(const std::string &InterfaceName, Module* Mod); + /** Unpublish a 'feature'. * When your module exits, it must call this method for every feature it * is providing so that the feature table is cleaned up. @@ -714,6 +720,8 @@ class InspIRCd : public classbase */ bool UnpublishFeature(const std::string &FeatureName); + bool UnpublishInterface(const std::string &InterfaceName, Module* Mod); + /** Find a 'feature'. * There are two ways for a module to find another module it depends on. * Either by name, using InspIRCd::FindModule, or by feature, using the @@ -728,6 +736,8 @@ class InspIRCd : public classbase */ Module* FindFeature(const std::string &FeatureName); + modulelist* FindInterface(const std::string &InterfaceName); + /** Given a pointer to a Module, return its filename * @param m The module pointer to identify * @return The module name or an empty string diff --git a/include/modules.h b/include/modules.h index b3be6ae9f..670d32844 100644 --- a/include/modules.h +++ b/include/modules.h @@ -101,6 +101,14 @@ typedef file_cache string_list; */ typedef std::map<std::string,Module*> featurelist; +/** Holds a list of modules which implement an interface + */ +typedef std::deque<Module*> modulelist; + +/** Holds a list of all modules which implement interfaces, by interface name + */ +typedef std::map<std::string, modulelist> interfacelist; + /** * This #define allows us to call a method in all * loaded modules in a readable simple way, e.g.: diff --git a/src/modules.cpp b/src/modules.cpp index 68859b627..2b5a07296 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -249,6 +249,39 @@ Module* InspIRCd::FindFeature(const std::string &FeatureName) return iter->second; } +bool InspIRCd::PublishInterface(const std::string &InterfaceName, Module* Mod) +{ + Interfaces[InterfaceName].push_back(Mod); + return true; +} + +bool InspIRCd::UnpublishInterface(const std::string &InterfaceName, Module* Mod) +{ + interfacelist::iterator iter = Interfaces.find(InterfaceName); + + if (iter == Interfaces.end()) + return false; + + for (modulelist::iterator x = iter->second.begin(); x != iter->second.end(); x++) + { + if (*x == Mod) + { + iter->second.erase(x); + return true; + } + } + return false; +} + +modulelist* InspIRCd::FindInterface(const std::string &InterfaceName) +{ + interfacelist::iterator iter = Interfaces.find(InterfaceName); + if (iter == Interfaces.end()) + return NULL; + else + return &(iter->second); +} + const std::string& InspIRCd::GetModuleName(Module* m) { static std::string nothing = ""; /* Prevent compiler warning */ diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp index f8ccda26b..a42ccbb7e 100644 --- a/src/modules/m_md5.cpp +++ b/src/modules/m_md5.cpp @@ -278,10 +278,12 @@ class ModuleMD5 : public Module ModuleMD5(InspIRCd* Me) : Module::Module(Me), key(NULL), chars(NULL) { + ServerInstance->PublishInterface("HashRequest", this); } virtual ~ModuleMD5() { + ServerInstance->UnpublishInterface("HashRequest", this); } void Implements(char* List) diff --git a/src/modules/m_oper_hash.cpp b/src/modules/m_oper_hash.cpp index de6b3f993..be948b445 100644 --- a/src/modules/m_oper_hash.cpp +++ b/src/modules/m_oper_hash.cpp @@ -97,6 +97,13 @@ class ModuleOperHash : public Module Conf = NULL; OnRehash(""); + modulelist* ml = ServerInstance->FindInterface("HashRequest"); + + if (ml) + { + ServerInstance->Log(DEBUG, "Found interface 'HashRequest' containing %d modules", ml->size()); + } + /* Try to find the md5 service provider, bail if it can't be found */ MD5Provider = ServerInstance->FindModule("m_md5.so"); if (MD5Provider) diff --git a/src/modules/m_sha256.cpp b/src/modules/m_sha256.cpp index 07bcab3ae..c5df2aad3 100644 --- a/src/modules/m_sha256.cpp +++ b/src/modules/m_sha256.cpp @@ -249,10 +249,12 @@ class ModuleSHA256 : public Module ModuleSHA256(InspIRCd* Me) : Module::Module(Me), key(NULL), chars(NULL) { + ServerInstance->PublishInterface("HashRequest", this); } virtual ~ModuleSHA256() { + ServerInstance->UnpublishInterface("HashRequest", this); } void Implements(char *List) |