summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes1
-rw-r--r--include/modules.h16
-rw-r--r--src/core/os_modload.c11
-rw-r--r--src/core/os_modunload.c10
-rw-r--r--src/modules.c100
-rw-r--r--src/process.c20
-rw-r--r--version.log6
7 files changed, 129 insertions, 35 deletions
diff --git a/Changes b/Changes
index ff8f3a9b4..405e37704 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@ Anope Version S V N
--------------------
Provided by Anope Dev. <dev@anope.org> - 2005
09/28 A Event for fantasy commands triggered without channel access. [ #00]
+09/28 F Made module (un)loading code more friendly for modularized core. [ #00]
09/28 F NickServ SASET didn't fill the nick in the 'not registered' line. [ #00]
Provided by Hal9000 <hal9000@pimpmylinux.org> - 2005
diff --git a/include/modules.h b/include/modules.h
index ad56cbf87..f9c16f7b3 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -97,6 +97,7 @@ typedef void * ano_module_t;
/*************************************************************************/
typedef enum { CORE,PROTOCOL,THIRD,SUPPORTED,QATESTED } MODType;
+typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation;
/*************************************************************************/
/* Structure for information about a *Serv command. */
@@ -106,6 +107,7 @@ typedef struct CommandHash_ CommandHash;
typedef struct Module_ Module;
typedef struct ModuleLang_ ModuleLang;
typedef struct ModuleHash_ ModuleHash;
+typedef struct ModuleQueue_ ModuleQueue;
typedef struct Message_ Message;
typedef struct MessageHash_ MessageHash;
typedef struct ModuleCallBack_ ModuleCallBack;
@@ -160,6 +162,14 @@ struct ModuleHash_ {
ModuleHash *next;
};
+struct ModuleQueue_ {
+ Module *m;
+ ModuleOperation op;
+ User *u;
+
+ ModuleQueue *next;
+};
+
struct Command_ {
char *name;
int (*routine)(User *u);
@@ -357,6 +367,12 @@ int moduleDataDebug(ModuleData **md); /* Allow for debug output of a moduleD
MDE boolean moduleMinVersion(int major,int minor,int patch,int build); /* Checks if the current version of anope is before or after a given verison */
/*************************************************************************/
+/* Module Queue Operations */
+MDE int queueModuleLoad(char *name, User *u);
+MDE int queueModuleUnload(char *name, User *u);
+MDE void handleModuleOperationQueue(void);
+
+/*************************************************************************/
/* Some IRCD protocol module support functions */
/** Update the protect deatials, could be either protect or admin etc.. */
diff --git a/src/core/os_modload.c b/src/core/os_modload.c
index 732d629f4..c8541bb23 100644
--- a/src/core/os_modload.c
+++ b/src/core/os_modload.c
@@ -76,21 +76,14 @@ void myOperServHelp(User * u)
int do_modload(User * u)
{
char *name;
- Module *m;
name = strtok(NULL, "");
if (!name) {
syntax_error(s_OperServ, u, "MODLOAD", OPER_MODULE_LOAD_SYNTAX);
return MOD_CONT;
}
- m = findModule(name);
- if (!m) {
- m = createModule(name);
- mod_current_module = m;
- mod_current_user = u;
- mod_current_op = 1;
- } else {
+ if (!queueModuleLoad(name, u))
notice_lang(s_OperServ, u, OPER_MODULE_LOAD_FAIL, name);
- }
+
return MOD_CONT;
}
diff --git a/src/core/os_modunload.c b/src/core/os_modunload.c
index 315c7a7c4..6bfb00595 100644
--- a/src/core/os_modunload.c
+++ b/src/core/os_modunload.c
@@ -75,7 +75,6 @@ void myOperServHelp(User * u)
int do_modunload(User * u)
{
char *name;
- Module *m;
name = strtok(NULL, "");
if (!name) {
@@ -83,13 +82,8 @@ int do_modunload(User * u)
OPER_MODULE_UNLOAD_SYNTAX);
return MOD_CONT;
}
- m = findModule(name);
- if (m) {
- mod_current_user = u;
- mod_current_module = m;
- mod_current_op = 2;
- } else {
+ if (!queueModuleUnload(name, u))
notice_lang(s_OperServ, u, OPER_MODULE_REMOVE_FAIL, name);
- }
+
return MOD_CONT;
}
diff --git a/src/modules.c b/src/modules.c
index d420bfa1a..1b2bc0966 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -53,9 +53,10 @@ ModuleHash *MODULE_HASH[MAX_CMD_HASH];
Module *mod_current_module;
char *mod_current_module_name = NULL;
char *mod_current_buffer = NULL;
-int mod_current_op;
User *mod_current_user;
ModuleCallBack *moduleCallBackHead = NULL;
+ModuleQueue *mod_operation_queue = NULL;
+
int displayCommand(Command * c);
int displayCommandFromHash(CommandHash * cmdTable[], char *name);
int displayMessageFromHashl(char *name);
@@ -2578,4 +2579,101 @@ void moduleDeleteLanguage(int langNumber)
mod_current_module->lang[langNumber].argc = 0;
}
+/**
+ * Enqueue a module operation (load/unload/reload)
+ * @param m Module to perform the operation on
+ * @param op Operation to perform on the module
+ * @param u User who requested the operation
+ **/
+void queueModuleOperation(Module *m, ModuleOperation op, User *u)
+{
+ ModuleQueue *qm;
+
+ qm = scalloc(1, sizeof(ModuleQueue));
+ qm->m = m;
+ qm->op = op;
+ qm->u = u;
+ qm->next = mod_operation_queue;
+ mod_operation_queue = qm;
+}
+
+/**
+ * Enqueue a module to load
+ * @param name Name of the module to load
+ * @param u User who requested the load
+ * @return 1 on success, 0 on error
+ **/
+int queueModuleLoad(char *name, User *u)
+{
+ Module *m;
+
+ if (!name || !u)
+ return 0;
+
+ if (findModule(name))
+ return 0;
+ m = createModule(name);
+ queueModuleOperation(m, MOD_OP_LOAD, u);
+
+ return 1;
+}
+
+/**
+ * Enqueue a module to unload
+ * @param name Name of the module to unload
+ * @param u User who requested the unload
+ * @return 1 on success, 0 on error
+ **/
+int queueModuleUnload(char *name, User *u)
+{
+ Module *m;
+
+ if (!name || !u)
+ return 0;
+
+ m = findModule(name);
+ if (!m)
+ return 0;
+ queueModuleOperation(m, MOD_OP_UNLOAD, u);
+
+ return 1;
+}
+
+/**
+ * Execute all queued module operations
+ **/
+void handleModuleOperationQueue(void)
+{
+ ModuleQueue *next;
+ int status;
+
+ if (!mod_operation_queue)
+ return;
+
+ while (mod_operation_queue) {
+ next = mod_operation_queue->next;
+
+ mod_current_module = mod_operation_queue->m;
+ mod_current_user = mod_operation_queue->u;
+
+ if (mod_operation_queue->op == MOD_OP_LOAD) {
+ alog("Trying to load module [%s]", mod_operation_queue->m->name);
+ status = loadModule(mod_operation_queue->m, mod_operation_queue->u);
+ alog("Module loading status: %d", status);
+ } else if (mod_operation_queue->op == MOD_OP_UNLOAD) {
+ alog("Trying to unload module [%s]", mod_operation_queue->m->name);
+ status = unloadModule(mod_operation_queue->m, mod_operation_queue->u);
+ alog("Module unloading status: %d", status);
+ }
+
+ /* Remove the ModuleQueue from memory */
+ free(mod_operation_queue);
+
+ mod_operation_queue = next;
+ }
+
+ mod_current_module = NULL;
+ mod_current_user = NULL;
+}
+
/* EOF */
diff --git a/src/process.c b/src/process.c
index 5f5f27a50..8bf1ebb9d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -18,7 +18,6 @@
extern Module *mod_current_module;
extern char *mod_current_module_name;
extern User *mod_current_user;
-extern int mod_current_op;
extern char *mod_current_buffer;
/*************************************************************************/
/*************************************************************************/
@@ -285,21 +284,10 @@ void process()
if (debug)
alog("debug: unknown message from server (%s)", inbuf);
}
- if (mod_current_op == 1) {
- alog("trying to load [%s]", mod_current_module->name);
- alog("status: [%d]",
- loadModule(mod_current_module, mod_current_user));
- mod_current_module = NULL;
- mod_current_user = NULL;
- mod_current_op = 0;
- } else if (mod_current_op == 2) {
- alog("trying to unload [%s]", mod_current_module->name);
- alog("status: [%d]",
- unloadModule(mod_current_module, mod_current_user));
- mod_current_module = NULL;
- mod_current_user = NULL;
- mod_current_op = 0;
- }
+
+ /* Load/unload modules if needed */
+ handleModuleOperationQueue();
+
/* Free argument list we created */
free(av);
}
diff --git a/version.log b/version.log
index 50530ae47..dc8afe5bf 100644
--- a/version.log
+++ b/version.log
@@ -9,10 +9,14 @@ VERSION_MAJOR="1"
VERSION_MINOR="7"
VERSION_PATCH="11"
VERSION_EXTRA="-svn"
-VERSION_BUILD="901"
+VERSION_BUILD="902"
# $Log$
#
+# BUILD : 1.7.11 (902)
+# BUGS :
+# NOTES : Changed how /os modload and /os modunload load/unload modules; they are now handled in a queue instead of using the mod_current_* variables
+#
# BUILD : 1.7.11 (901)
# BUGS :
# NOTES : Updated Italian translation (by Hal9000); updated German translation for cs_appendtopic (by Cloud); added Changes message for ns_saset fix accidently comitted when comitting the dev framework