2 fe-common-core.c : irssi
4 Copyright (C) 1999-2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "module-formats.h"
27 #include "chat-protocols.h"
29 #include "printtext.h"
31 static void sig_module_error(void *number, const char *module,
34 switch (GPOINTER_TO_INT(number)) {
35 case MODULE_ERROR_ALREADY_LOADED:
36 printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
37 TXT_MODULE_ALREADY_LOADED, module);
39 case MODULE_ERROR_LOAD:
40 printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
41 TXT_MODULE_LOAD_ERROR, module, data);
43 case MODULE_ERROR_INVALID:
44 printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
45 TXT_MODULE_INVALID, module);
50 static void sig_module_loaded(MODULE_REC *rec)
52 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
53 TXT_MODULE_LOADED, rec->name);
56 static void sig_module_unloaded(MODULE_REC *rec)
58 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
59 TXT_MODULE_UNLOADED, rec->name);
62 static void cmd_load_list(void)
66 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_HEADER);
67 for (tmp = modules; tmp != NULL; tmp = tmp->next) {
68 MODULE_REC *rec = tmp->data;
70 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
71 TXT_MODULE_LINE, rec->name);
73 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_FOOTER);
76 static char **module_prefixes_get(void)
82 list = g_new(char *, 2 + 2*g_slist_length(chat_protocols));
86 for (tmp = chat_protocols; tmp != NULL; tmp = tmp->next) {
87 CHAT_PROTOCOL_REC *rec = tmp->data;
89 name = g_strdup(rec->name);
93 list[count++] = g_strconcat("fe_", name, NULL);
100 static void module_prefixes_free(char **list)
104 while (*pos != NULL) {
111 /* SYNTAX: LOAD <module> */
112 static void cmd_load(const char *data)
115 char **module_prefixes;
117 g_return_if_fail(data != NULL);
121 module_prefixes = module_prefixes_get();
122 module_load(data, module_prefixes);
123 module_prefixes_free(module_prefixes);
126 printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
127 "Dynamic modules loading not supported");
131 /* SYNTAX: UNLOAD <module> */
132 static void cmd_unload(const char *data)
136 g_return_if_fail(data != NULL);
137 if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
139 rec = module_find(data);
140 if (rec != NULL) module_unload(rec);
143 void fe_modules_init(void)
145 signal_add("module error", (SIGNAL_FUNC) sig_module_error);
146 signal_add("module loaded", (SIGNAL_FUNC) sig_module_loaded);
147 signal_add("module unloaded", (SIGNAL_FUNC) sig_module_unloaded);
149 command_bind("load", NULL, (SIGNAL_FUNC) cmd_load);
150 command_bind("unload", NULL, (SIGNAL_FUNC) cmd_unload);
153 void fe_modules_deinit(void)
155 signal_remove("module error", (SIGNAL_FUNC) sig_module_error);
156 signal_remove("module loaded", (SIGNAL_FUNC) sig_module_loaded);
157 signal_remove("module unloaded", (SIGNAL_FUNC) sig_module_unloaded);
159 command_unbind("load", (SIGNAL_FUNC) cmd_load);
160 command_unbind("unload", (SIGNAL_FUNC) cmd_unload);