summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/extern.h1
-rw-r--r--include/modules.h15
-rw-r--r--src/main.c3
-rw-r--r--src/module.cpp11
-rw-r--r--src/modulemanager.cpp1
-rw-r--r--src/modules.c98
6 files changed, 30 insertions, 99 deletions
diff --git a/include/extern.h b/include/extern.h
index 958eb45cc..4d998a0a9 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -715,7 +715,6 @@ E int str_is_cidr(char *str, uint32 * ip, uint32 * mask, char **host);
/**** modules.c ****/
E void modules_unload_all(bool fini, bool unload_proto); /* Read warnings near function source */
-E void moduleCallBackRun(void);
E void moduleCleanStruct(ModuleData **moduleData);
E void ModuleDatabaseBackup(const char *dbname);
E void ModuleRemoveBackups(const char *dbname);
diff --git a/include/modules.h b/include/modules.h
index 30875e664..b0f5898d2 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -269,28 +269,29 @@ CoreExport class Module
CoreExport class ModuleManager
{
public:
- /**
- * Load up a list of modules.
+ /** Load up a list of modules.
* @param total_modules The number of modules to load
* @param module_list The list of modules to load
**/
static void LoadModuleList(int total_modules, char **module_list);
- /**
- * Loads a given module.
+ /** Loads a given module.
* @param m the module to load
* @param u the user who loaded it, NULL for auto-load
* @return MOD_ERR_OK on success, anything else on fail
*/
static int LoadModule(const std::string &modname, User * u);
- /**
- * Unload the given module.
+ /** Unload the given module.
* @param m the module to unload
* @param u the user who unloaded it
* @return MOD_ERR_OK on success, anything else on fail
*/
static int UnloadModule(Module *m, User * u);
+
+ /** Run all pending module timer callbacks.
+ */
+ static void RunCallbacks();
};
@@ -421,9 +422,7 @@ MDE Message *createMessage(const char *name,int (*func)(const char *source, int
Message *findMessage(MessageHash *msgTable[], const char *name); /* Find a Message */
MDE int addMessage(MessageHash *msgTable[], Message *m, int pos); /* Add a Message to a Message table */
MDE int addCoreMessage(MessageHash *msgTable[], Message *m); /* Add a Message to a Message table */
-MDE int moduleAddMessage(Message *m, int pos);
int delMessage(MessageHash *msgTable[], Message *m, const char *mod_name); /* Del a Message from a msg table */
-MDE int moduleDelMessage(const char *name);
int destroyMessage(Message *m); /* destroy a Message*/
/*************************************************************************/
diff --git a/src/main.c b/src/main.c
index dcbf8a303..ff4968ed3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,6 +30,7 @@
#include "timeout.h"
#include "version.h"
#include "datafiles.h"
+#include "modules.h"
/******** Global variables! ********/
@@ -540,7 +541,7 @@ int main(int ac, char **av, char **envp)
if (delayed_quit)
break;
- moduleCallBackRun();
+ ModuleManager::RunCallbacks();
waiting = -1;
if (t - last_check >= TimeoutCheck) {
diff --git a/src/module.cpp b/src/module.cpp
index f20404467..5676b16fb 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -77,11 +77,9 @@ Module::~Module()
int idx;
CommandHash *current = NULL;
- MessageHash *mcurrent = NULL;
EvtHookHash *ehcurrent = NULL;
Command *c;
- Message *msg;
EvtHook *eHook;
int status = 0;
@@ -151,15 +149,6 @@ Module::~Module()
}
}
- for (mcurrent = IRCD[idx]; mcurrent; mcurrent = mcurrent->next) {
- for (msg = mcurrent->m; msg; msg = msg->next) {
- if ((msg->mod_name)
- && (stricmp(msg->mod_name, this->name.c_str()) == 0)) {
- moduleDelMessage(msg->name);
- }
- }
- }
-
for (ehcurrent = EVENTHOOKS[idx]; ehcurrent;
ehcurrent = ehcurrent->next) {
for (eHook = ehcurrent->evh; eHook; eHook = eHook->next) {
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index edccd8dc5..c248817bc 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -248,4 +248,3 @@ int ModuleManager::UnloadModule(Module *m, User *u)
delete m;
return MOD_ERR_OK;
}
-
diff --git a/src/modules.c b/src/modules.c
index 79ef12420..e2e40a7c8 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -294,7 +294,7 @@ int destroyCommand(Command * c)
* @param pos the position in the cmd call stack to add the command
* @return MOD_ERR_OK will be returned on success.
*/
-static int internal_addCommand(CommandHash * cmdTable[], Command * c, int pos)
+static int internal_addCommand(Module *m, CommandHash * cmdTable[], Command * c, int pos)
{
/* We can assume both param's have been checked by this point.. */
int index = 0;
@@ -307,9 +307,6 @@ static int internal_addCommand(CommandHash * cmdTable[], Command * c, int pos)
return MOD_ERR_PARAMS;
}
- if (mod_current_module_name && !c->mod_name)
- return MOD_ERR_NO_MOD_NAME;
-
index = CMD_HASH(c->name);
for (current = cmdTable[index]; current; current = current->next) {
@@ -416,7 +413,7 @@ int Module::AddCommand(CommandHash * cmdTable[], Command * c, int pos)
} else
c->service = sstrdup("Unknown");
- status = internal_addCommand(cmdTable, c, pos);
+ status = internal_addCommand(this, cmdTable, c, pos);
if (status != MOD_ERR_OK)
{
alog("ERROR! [%d]", status);
@@ -677,59 +674,6 @@ int addCoreMessage(MessageHash * msgTable[], Message * m)
}
/**
- * Add a module message to the IRCD message hash
- * @param m the Message to add
- * @param pos the Position to add the message to, e.g. MOD_HEAD, MOD_TAIL, MOD_UNIQUE
- * @return MOD_ERR_OK on success, althing else on fail.
- **/
-int moduleAddMessage(Message * m, int pos)
-{
- int status;
-
- if (!m) {
- return MOD_ERR_PARAMS;
- }
-
- /* ok, this appears to be a module adding a message from outside of AnopeInit, try to look up its module struct for it */
- if ((mod_current_module_name) && (!mod_current_module)) {
- mod_current_module = findModule(mod_current_module_name);
- }
-
- if (!mod_current_module) {
- return MOD_ERR_UNKNOWN;
- } /* shouldnt happen */
- m->core = 0;
- if (!m->mod_name) {
- m->mod_name = sstrdup(mod_current_module->name.c_str());
- }
-
- status = addMessage(IRCD, m, pos);
- return status;
-}
-
-/**
- * remove the given message from the IRCD message hash
- * @param name the name of the message to remove
- * @return MOD_ERR_OK on success, althing else on fail.
- **/
-int moduleDelMessage(const char *name)
-{
- Message *m;
- int status;
-
- if (!mod_current_module) {
- return MOD_ERR_UNKNOWN;
- }
- m = findMessage(IRCD, name);
- if (!m) {
- return MOD_ERR_NOEXIST;
- }
-
- status = delMessage(IRCD, m, mod_current_module->name.c_str());
- return status;
-}
-
-/**
* remove the given message from the given message hash, for the given module
* @param msgTable which MessageHash we are removing from
* @param m the Message we want to remove
@@ -887,25 +831,6 @@ int moduleAddCallback(const char *name, time_t when,
}
/**
- * Execute a stored call back
- **/
-void moduleCallBackRun(void)
-{
- ModuleCallBack *tmp;
-
- while ((tmp = moduleCallBackHead) && (tmp->when <= time(NULL))) {
- if (debug)
- alog("debug: executing callback: %s", tmp->name ? tmp->name : "<unknown>");
- if (tmp->func) {
- mod_current_module_name = tmp->owner_name;
- tmp->func(tmp->argc, tmp->argv);
- mod_current_module = NULL;
- moduleCallBackDeleteEntry(NULL);
- }
- }
-}
-
-/**
* Removes a entry from the modules callback list
* @param prev a pointer to the previous entry in the list, NULL for the head
**/
@@ -1840,4 +1765,23 @@ void ModuleRunTimeDirCleanUp(void)
}
}
+/**
+ * Execute a stored call back
+ **/
+void ModuleManager::RunCallbacks()
+{
+ ModuleCallBack *tmp;
+
+ while ((tmp = moduleCallBackHead) && (tmp->when <= time(NULL))) {
+ if (debug)
+ alog("debug: executing callback: %s", tmp->name ? tmp->name : "<unknown>");
+ if (tmp->func) {
+ mod_current_module_name = tmp->owner_name;
+ tmp->func(tmp->argc, tmp->argv);
+ mod_current_module = NULL;
+ moduleCallBackDeleteEntry(NULL);
+ }
+ }
+}
+
/* EOF */