diff options
author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-05-05 20:09:28 +0000 |
---|---|---|
committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-05-05 20:09:28 +0000 |
commit | de902c6db3923facb7393fc63a315a04fe580434 (patch) | |
tree | ff730c9c9a5ebd4b03b44330f2f7ed5bf27e98c4 /src | |
parent | e02967bd4a78eba1646e6089406a443ecf13fe8a (diff) |
Always set mod_current_module and mod_current_module_name, fixes a few of the functions in modules.c relying on it.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/stable@2931 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 7 | ||||
-rw-r--r-- | src/events.c | 19 | ||||
-rw-r--r-- | src/modules.c | 45 | ||||
-rw-r--r-- | src/process.c | 4 |
4 files changed, 49 insertions, 26 deletions
diff --git a/src/commands.c b/src/commands.c index f846ee8db..cbc99b800 100644 --- a/src/commands.c +++ b/src/commands.c @@ -96,18 +96,18 @@ void do_run_cmd(char *service, User * u, Command * c, const char *cmd) } } else { mod_current_module_name = c->mod_name; - mod_current_module = NULL; + mod_current_module = findModule(c->mod_name); if ((c->has_priv == NULL) || c->has_priv(u)) { retVal = c->routine(u); - mod_current_module_name = NULL; if (retVal == MOD_CONT) { current = c->next; while (current && retVal == MOD_CONT) { mod_current_module_name = current->mod_name; - mod_current_module = NULL; + mod_current_module = findModule(current->mod_name); if (current->routine) retVal = current->routine(u); mod_current_module_name = NULL; + mod_current_module = NULL; current = current->next; } } @@ -117,6 +117,7 @@ void do_run_cmd(char *service, User * u, Command * c, const char *cmd) u->nick, service, cmd); } mod_current_module_name = NULL; + mod_current_module = NULL; } } else { if ((!checkDefCon(DEFCON_SILENT_OPER_ONLY)) || is_oper(u)) { diff --git a/src/events.c b/src/events.c index 2ca0abc63..2d7006a0c 100644 --- a/src/events.c +++ b/src/events.c @@ -129,14 +129,18 @@ void event_message_process(char *eventbuf) if (evm) { if (evm->func) { mod_current_module_name = evm->mod_name; + mod_current_module = findModule(evm->mod_name); retVal = evm->func(source, ac, av); mod_current_module_name = NULL; + mod_current_module = NULL; if (retVal == MOD_CONT) { current = evm->next; while (current && current->func && retVal == MOD_CONT) { mod_current_module_name = current->mod_name; + mod_current_module = findModule(current->mod_name); retVal = current->func(source, ac, av); mod_current_module_name = NULL; + mod_current_module = NULL; current = current->next; } } @@ -158,14 +162,18 @@ void event_process_hook(const char *name, int argc, char **argv) evh = find_eventhook(name); if (evh) { if (evh->func) { + mod_current_module = findModule(evh->mod_name); mod_current_module_name = evh->mod_name; retVal = evh->func(argc, argv); + mod_current_module = NULL; mod_current_module_name = NULL; if (retVal == MOD_CONT) { current = evh->next; while (current && current->func && retVal == MOD_CONT) { + mod_current_module = findModule(current->mod_name); mod_current_module_name = current->mod_name; retVal = current->func(argc, argv); + mod_current_module = NULL; mod_current_module_name = NULL; current = current->next; } @@ -495,14 +503,10 @@ int moduleAddEventHandler(EvtMessage * evm) 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 */ + evm->core = 0; if (!evm->mod_name) { evm->mod_name = sstrdup(mod_current_module->name); @@ -529,13 +533,10 @@ int moduleAddEventHook(EvtHook * evh) return MOD_ERR_PARAMS; } - 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 */ + evh->core = 0; if (!evh->mod_name) { evh->mod_name = sstrdup(mod_current_module->name); diff --git a/src/modules.c b/src/modules.c index 8e5bb8be7..728575005 100644 --- a/src/modules.c +++ b/src/modules.c @@ -105,6 +105,7 @@ void modules_init(void) if (!m) { m = createModule(ModulesAutoload[idx]); mod_current_module = m; + mod_current_module_name = m->name; mod_current_user = NULL; alog("trying to load [%s]", mod_current_module->name); ret = loadModule(mod_current_module, NULL); @@ -112,6 +113,7 @@ void modules_init(void) if (ret != MOD_ERR_OK) destroyModule(m); mod_current_module = NULL; + mod_current_module_name = NULL; mod_current_user = NULL; } } @@ -133,8 +135,11 @@ void modules_core_init(int number, char **list) if (!m) { m = createModule(list[idx]); mod_current_module = m; + mod_current_module_name = m->name; mod_current_user = NULL; status = loadModule(mod_current_module, NULL); + mod_current_module = m; + mod_current_module_name = m->name; if (debug || status) { alog("debug: trying to load core module [%s]", mod_current_module->name); @@ -143,6 +148,7 @@ void modules_core_init(int number, char **list) destroyModule(mod_current_module); } mod_current_module = NULL; + mod_current_module_name = NULL; mod_current_user = NULL; } } @@ -156,12 +162,16 @@ int encryption_module_init(void) { m = createModule(EncModule); mod_current_module = m; + mod_current_module_name = m->name; mod_current_user = NULL; alog("Loading Encryption Module: [%s]", mod_current_module->name); ret = loadModule(mod_current_module, NULL); + mod_current_module = m; + mod_current_module_name = m->name; moduleSetType(ENCRYPTION); alog("status: [%d][%s]", ret, ModuleGetErrStr(ret)); mod_current_module = NULL; + mod_current_module_name = NULL; if (ret != MOD_ERR_OK) { destroyModule(m); } @@ -178,12 +188,16 @@ int protocol_module_init(void) m = createModule(IRCDModule); mod_current_module = m; + mod_current_module_name = m->name; mod_current_user = NULL; alog("Loading IRCD Protocol Module: [%s]", mod_current_module->name); ret = loadModule(mod_current_module, NULL); + mod_current_module = m; + mod_current_module_name = m->name; moduleSetType(PROTOCOL); alog("status: [%d][%s]", ret, ModuleGetErrStr(ret)); mod_current_module = NULL; + mod_current_module_name = NULL; if (ret == MOD_ERR_OK) { /* This is really NOT the correct place to do config checks, but @@ -235,11 +249,13 @@ void modules_delayed_init(void) if (!m) { m = createModule(ModulesDelayedAutoload[idx]); mod_current_module = m; + mod_current_module_name = m->name; mod_current_user = NULL; alog("trying to load [%s]", mod_current_module->name); ret = loadModule(mod_current_module, NULL); alog("status: [%d][%s]", ret, ModuleGetErrStr(ret)); mod_current_module = NULL; + mod_current_module_name = NULL; mod_current_user = NULL; if (ret != MOD_ERR_OK) destroyModule(m); @@ -271,12 +287,11 @@ void modules_unload_all(boolean fini, boolean unload_proto) next = mh->next; if (unload_proto || (mh->m->type != PROTOCOL)) { mod_current_module = mh->m; + mod_current_module_name = mh->m->name; if(fini) { func = (void (*)(void))ano_modsym(mh->m->handle, "AnopeFini"); if (func) { - mod_current_module_name = mh->m->name; func(); /* exec AnopeFini */ - mod_current_module_name = NULL; } if (prepForUnload(mh->m) != MOD_ERR_OK) { @@ -291,6 +306,8 @@ void modules_unload_all(boolean fini, boolean unload_proto) } else { delModule(mh->m); } + mod_current_module = NULL; + mod_current_module_name = NULL; } mh = next; } @@ -347,6 +364,7 @@ int destroyModule(Module * m) } mod_current_module = m; + mod_current_module_name = m->name; for (i = 0; i < NUM_LANGS; i++) { moduleDeleteLanguage(i); } @@ -368,6 +386,10 @@ int destroyModule(Module * m) /* No need to free our cmd/msg list, as they will always be empty by the module is destroyed */ free(m); + + mod_current_module = NULL; + mod_current_module_name = NULL; + return MOD_ERR_OK; } @@ -651,6 +673,7 @@ int loadModule(Module * m, User * u) return MOD_ERR_NOLOAD; } /* TODO */ + mod_current_module = m; mod_current_module_name = m->name; /* argv[0] is the user if there was one, or NULL if not */ if (u) { @@ -674,10 +697,12 @@ int loadModule(Module * m, User * u) if (ret == MOD_STOP) { alog("%s requested unload...", m->name); unloadModule(m, NULL); + mod_current_module = NULL; mod_current_module_name = NULL; return MOD_ERR_NOLOAD; } + mod_current_module = NULL; mod_current_module_name = NULL; } @@ -726,8 +751,10 @@ int unloadModule(Module * m, User * u) func = (void (*)(void))ano_modsym(m->handle, "AnopeFini"); if (func) { + mod_current_module = m; mod_current_module_name = m->name; func(); /* exec AnopeFini */ + mod_current_module = NULL; mod_current_module_name = NULL; } @@ -761,9 +788,6 @@ int unloadModule(Module * m, User * u) **/ void moduleSetType(MODType type) { - if ((mod_current_module_name) && (!mod_current_module)) { - mod_current_module = findModule(mod_current_module_name); - } mod_current_module->type = type; } @@ -1018,10 +1042,6 @@ int moduleAddCommand(CommandHash * cmdTable[], Command * c, int pos) if (!cmdTable || !c) { return MOD_ERR_PARAMS; } - /* ok, this appears to be a module adding a command 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; @@ -1542,11 +1562,6 @@ int moduleAddMessage(Message * m, int pos) 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 */ @@ -1777,9 +1792,11 @@ void moduleCallBackRun(void) if (debug) alog("debug: executing callback: %s", tmp->name ? tmp->name : "<unknown>"); if (tmp->func) { + mod_current_module = findModule(tmp->owner_name); mod_current_module_name = tmp->owner_name; tmp->func(tmp->argc, tmp->argv); mod_current_module = NULL; + mod_current_module_name = NULL; moduleCallBackDeleteEntry(NULL); } } diff --git a/src/process.c b/src/process.c index 730745c46..f3e4ef0f1 100644 --- a/src/process.c +++ b/src/process.c @@ -395,14 +395,18 @@ void process() if (m) { if (m->func) { mod_current_module_name = m->mod_name; + mod_current_module = findModule(m->mod_name); retVal = m->func(source, ac, av); mod_current_module_name = NULL; + mod_current_module = NULL; if (retVal == MOD_CONT) { current = m->next; while (current && current->func && retVal == MOD_CONT) { mod_current_module_name = current->mod_name; + mod_current_module = findModule(current->mod_name); retVal = current->func(source, ac, av); mod_current_module_name = NULL; + mod_current_module = NULL; current = current->next; } } |