1
0
mirror of https://github.com/anope/anope.git synced 2026-06-30 06:16:38 +02:00

Merge prepForUnload with module destructor.

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1609 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
Robin Burchell w00t@inspircd.org
2008-11-09 02:50:14 +00:00
parent d2cb6b78c1
commit 04e2597df2
2 changed files with 106 additions and 135 deletions
-1
View File
@@ -350,7 +350,6 @@ int loadModule(const std::string &modname, User *u);
int encryption_module_init(void); /* Load the encryption module */
int protocol_module_init(void); /* Load the IRCD Protocol Module up*/
int unloadModule(Module *m, User *u); /* Unload the given module from the pro */
int prepForUnload(Module *m); /* Prepare the module for unload */
void moduleCallBackPrepForUnload(const char *mod_name);
MDE void moduleCallBackDeleteEntry(ModuleCallBack * prev);
MDE char *moduleGetLastBuffer(void);
+106 -134
View File
@@ -270,10 +270,6 @@ void modules_unload_all(bool fini, bool unload_proto)
mod_current_module_name = mh->m->name.c_str();
mod_current_module_name = NULL;
if (prepForUnload(mh->m) != MOD_ERR_OK) {
mh = next;
continue;
}
delModule(mh->m);
}
mh = next;
@@ -321,10 +317,112 @@ Module::~Module()
alog("%s", ano_moderr());
}
/*
* No need to free our cmd/msg list, as they will always be empty by the module is destroyed
* XXX: not sure I like this assumption -- w00t
*/
int idx;
CommandHash *current = NULL;
MessageHash *mcurrent = NULL;
EvtMessageHash *ecurrent = NULL;
EvtHookHash *ehcurrent = NULL;
Command *c;
Message *msg;
EvtMessage *eMsg;
EvtHook *eHook;
int status = 0;
/* Kill any active callbacks this module has */
moduleCallBackPrepForUnload(this->name.c_str());
/* Remove any stored data this module has */
moduleDelAllDataMod(this);
/**
* ok, im going to walk every hash looking for commands we own, now, not exactly elegant or efficiant :)
**/
for (idx = 0; idx < MAX_CMD_HASH; idx++) {
for (current = HS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(HOSTSERV, c->name);
}
}
}
for (current = BS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(BOTSERV, c->name);
}
}
}
for (current = MS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(MEMOSERV, c->name);
}
}
}
for (current = NS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(NICKSERV, c->name);
}
}
}
for (current = CS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(CHANSERV, c->name);
}
}
}
for (current = HE_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(HELPSERV, c->name);
}
}
}
for (current = OS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (stricmp(c->mod_name, this->name.c_str()) == 0)) {
this->DelCommand(OPERSERV, c->name);
}
}
}
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 (ecurrent = EVENT[idx]; ecurrent; ecurrent = ecurrent->next) {
for (eMsg = ecurrent->evm; eMsg; eMsg = eMsg->next) {
if ((eMsg->mod_name)
&& (stricmp(eMsg->mod_name, this->name.c_str()) == 0)) {
status = delEventHandler(EVENT, eMsg, this->name.c_str());
}
}
}
for (ehcurrent = EVENTHOOKS[idx]; ehcurrent;
ehcurrent = ehcurrent->next) {
for (eHook = ehcurrent->evh; eHook; eHook = eHook->next) {
if ((eHook->mod_name)
&& (stricmp(eHook->mod_name, this->name.c_str()) == 0)) {
status = delEventHook(EVENTHOOKS, eHook, this->name.c_str());
}
}
}
}
}
void Module::SetType(MODType type)
@@ -712,10 +810,6 @@ int unloadModule(Module * m, User * u)
return MOD_ERR_NOUNLOAD;
}
if (prepForUnload(m) != MOD_ERR_OK) {
return MOD_ERR_UNKNOWN;
}
if (u) {
ircdproto->SendGlobops(s_OperServ, "%s unloaded module %s", u->nick,
m->name.c_str());
@@ -725,128 +819,6 @@ int unloadModule(Module * m, User * u)
return MOD_ERR_OK;
}
/**
* Prepare a module to be unloaded.
* Remove all commands and messages this module is providing, and delete
* any callbacks which are still pending.
* @param m the module to prepare for unload
* @return MOD_ERR_OK on success
*/
int prepForUnload(Module * m)
{
int idx;
CommandHash *current = NULL;
MessageHash *mcurrent = NULL;
EvtMessageHash *ecurrent = NULL;
EvtHookHash *ehcurrent = NULL;
Command *c;
Message *msg;
EvtMessage *eMsg;
EvtHook *eHook;
int status = 0;
if (!m) {
return MOD_ERR_PARAMS;
}
/* Kill any active callbacks this module has */
moduleCallBackPrepForUnload(m->name.c_str());
/* Remove any stored data this module has */
moduleDelAllDataMod(m);
/**
* ok, im going to walk every hash looking for commands we own, now, not exactly elegant or efficiant :)
**/
for (idx = 0; idx < MAX_CMD_HASH; idx++) {
for (current = HS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(HOSTSERV, c->name);
}
}
}
for (current = BS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(BOTSERV, c->name);
}
}
}
for (current = MS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(MEMOSERV, c->name);
}
}
}
for (current = NS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(NICKSERV, c->name);
}
}
}
for (current = CS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(CHANSERV, c->name);
}
}
}
for (current = HE_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (strcmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(HELPSERV, c->name);
}
}
}
for (current = OS_cmdTable[idx]; current; current = current->next) {
for (c = current->c; c; c = c->next) {
if ((c->mod_name) && (stricmp(c->mod_name, m->name.c_str()) == 0)) {
m->DelCommand(OPERSERV, c->name);
}
}
}
for (mcurrent = IRCD[idx]; mcurrent; mcurrent = mcurrent->next) {
for (msg = mcurrent->m; msg; msg = msg->next) {
if ((msg->mod_name)
&& (stricmp(msg->mod_name, m->name.c_str()) == 0)) {
moduleDelMessage(msg->name);
}
}
}
for (ecurrent = EVENT[idx]; ecurrent; ecurrent = ecurrent->next) {
for (eMsg = ecurrent->evm; eMsg; eMsg = eMsg->next) {
if ((eMsg->mod_name)
&& (stricmp(eMsg->mod_name, m->name.c_str()) == 0)) {
status = delEventHandler(EVENT, eMsg, m->name.c_str());
}
}
}
for (ehcurrent = EVENTHOOKS[idx]; ehcurrent;
ehcurrent = ehcurrent->next) {
for (eHook = ehcurrent->evh; eHook; eHook = eHook->next) {
if ((eHook->mod_name)
&& (stricmp(eHook->mod_name, m->name.c_str()) == 0)) {
status = delEventHook(EVENTHOOKS, eHook, m->name.c_str());
}
}
}
}
return MOD_ERR_OK;
}
/*******************************************************************************
* Command Functions
*******************************************************************************/