summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h47
-rw-r--r--src/modules.cpp31
2 files changed, 75 insertions, 3 deletions
diff --git a/include/modules.h b/include/modules.h
index 426ec9a65..d303f7c72 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -78,6 +78,9 @@ enum TargetTypeFlags {
class Server;
class ServerConfig;
+// Forward-delacare module for ModuleMessage etc
+class Module;
+
/** Low level definition of a FileReader classes file cache area
*/
typedef std::deque<std::string> file_cache;
@@ -88,6 +91,10 @@ typedef file_cache string_list;
typedef std::deque<userrec*> chanuserlist;
+/** Holds a list of 'published features' for modules.
+ */
+typedef std::map<std::string,Module*> featurelist;
+
/**
* This #define allows us to call a method in all
* loaded modules in a readable simple way, e.g.:
@@ -164,9 +171,6 @@ class Admin : public classbase
Admin(std::string name, std::string email, std::string nick);
};
-// Forward-delacare module for ModuleMessage etc
-class Module;
-
/** The ModuleMessage class is the base class of Request and Event
* This class is used to represent a basic data structure which is passed
* between modules for safe inter-module communications.
@@ -1302,6 +1306,43 @@ class Server : public classbase
*/
std::string GetVersion();
+ /** Publish a 'feature'.
+ * There are two ways for a module to find another module it depends on.
+ * Either by name, using Server::FindModule, or by feature, using this
+ * function. A feature is an arbitary string which identifies something this
+ * module can do. For example, if your module provides SSL support, but other
+ * modules provide SSL support too, all the modules supporting SSL should
+ * publish an identical 'SSL' feature. This way, any module requiring use
+ * of SSL functions can just look up the 'SSL' feature using FindFeature,
+ * then use the module pointer they are given.
+ * @param FeatureName The case sensitive feature name to make available
+ * @param Mod a pointer to your module class
+ * @returns True on success, false if the feature is already published by
+ * another module.
+ */
+ bool PublishFeature(std::string FeatureName, 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.
+ * @param FeatureName the feature to remove
+ */
+ bool UnpublishFeature(std::string FeatureName);
+
+ /** Find a 'feature'.
+ * There are two ways for a module to find another module it depends on.
+ * Either by name, using Server::FindModule, or by feature, using the
+ * Server::PublishFeature method. A feature is an arbitary string which
+ * identifies something this module can do. For example, if your module
+ * provides SSL support, but other modules provide SSL support too, all
+ * the modules supporting SSL should publish an identical 'SSL' feature.
+ * To find a module capable of providing the feature you want, simply
+ * call this method with the feature name you are looking for.
+ * @param FeatureName The feature name you wish to obtain the module for
+ * @returns A pointer to a valid module class on success, NULL on failure.
+ */
+ Module* FindFeature(std::string FeatureName);
+
/** Writes a log string.
* This method writes a line of text to the log. If the level given is lower than the
* level given in the configuration, this command has no effect.
diff --git a/src/modules.cpp b/src/modules.cpp
index 24b3e1945..b2fdc512d 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -60,6 +60,7 @@ extern command_table cmdlist;
class Server;
ExtModeList EMode;
+featurelist Features;
// returns true if an extended mode character is in use
bool ModeDefined(char modechar, int type)
@@ -350,6 +351,36 @@ long Server::PriorityBefore(const std::string &modulename)
return PRIORITY_DONTCARE;
}
+bool Server::PublishFeature(std::string FeatureName, Module* Mod)
+{
+ if (Features.find(FeatureName) == Features.end())
+ {
+ Features[FeatureName] = Mod;
+ return true;
+ }
+ return false;
+}
+
+bool Server::UnpublishFeature(std::string FeatureName)
+{
+ featurelist::iterator iter = Features.find(FeatureName);
+
+ if (iter == Features.end())
+ return false;
+
+ Features.erase(iter);
+}
+
+Module* Server::FindFeature(std::string FeatureName)
+{
+ featurelist::iterator iter = Features.find(FeatureName);
+
+ if (iter == Features.end())
+ return NULL;
+
+ return iter->second;
+}
+
void Server::RehashServer()
{
WriteOpers("*** Rehashing config file");