summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-09 02:50:14 +0000
committerRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-09 02:50:14 +0000
commit04e2597df27393930796569a08ebda5e75ccfcad (patch)
treeaac7707ea4e0e3908872fd6d419e8d3c1788335b /src
parentd2cb6b78c11888dbcf10187ff9c2cc192ef2d9a5 (diff)
Merge prepForUnload with module destructor.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1609 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/modules.c240
1 files changed, 106 insertions, 134 deletions
diff --git a/src/modules.c b/src/modules.c
index b7c0d142c..7ccd4529c 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -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
*******************************************************************************/