1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

module check irssi version

Add explicit checks into every module to match the ABI version defined
in common.h
This commit is contained in:
ailin-nemui 2015-11-24 00:08:20 +01:00
parent 4dc2bab4b4
commit ff8ccaf08b
10 changed files with 58 additions and 1 deletions

View File

@ -6,6 +6,8 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
#define IRSSI_ABI_VERSION 1
#define DEFAULT_SERVER_ADD_PORT 6667 #define DEFAULT_SERVER_ADD_PORT 6667
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

View File

@ -414,6 +414,13 @@ static char *expando_releasetime(SERVER_REC *server, void *item, int *free_ret)
return g_strdup_printf("%04d", IRSSI_VERSION_TIME); return g_strdup_printf("%04d", IRSSI_VERSION_TIME);
} }
/* client abi */
static char *expando_abiversion(SERVER_REC *server, void *item, int *free_ret)
{
*free_ret = TRUE;
return g_strdup_printf("%d", IRSSI_ABI_VERSION);
}
/* current working directory */ /* current working directory */
static char *expando_workdir(SERVER_REC *server, void *item, int *free_ret) static char *expando_workdir(SERVER_REC *server, void *item, int *free_ret)
{ {
@ -658,6 +665,8 @@ void expandos_init(void)
"", EXPANDO_NEVER, NULL); "", EXPANDO_NEVER, NULL);
expando_create("versiontime", expando_releasetime, expando_create("versiontime", expando_releasetime,
"", EXPANDO_NEVER, NULL); "", EXPANDO_NEVER, NULL);
expando_create("abiversion", expando_abiversion,
"", EXPANDO_NEVER, NULL);
expando_create("W", expando_workdir, NULL); expando_create("W", expando_workdir, NULL);
expando_create("Y", expando_realname, expando_create("Y", expando_realname,
"window changed", EXPANDO_ARG_NONE, "window changed", EXPANDO_ARG_NONE,

View File

@ -160,11 +160,14 @@ static int module_load_name(const char *path, const char *rootmodule,
{ {
void (*module_init) (void); void (*module_init) (void);
void (*module_deinit) (void); void (*module_deinit) (void);
void (*module_version) (int *);
GModule *gmodule; GModule *gmodule;
MODULE_REC *module; MODULE_REC *module;
MODULE_FILE_REC *rec; MODULE_FILE_REC *rec;
gpointer value_version = NULL;
gpointer value1, value2 = NULL; gpointer value1, value2 = NULL;
char *initfunc, *deinitfunc; char *versionfunc, *initfunc, *deinitfunc;
int module_abi_version = 0;
int found; int found;
gmodule = module_open(path, &found); gmodule = module_open(path, &found);
@ -176,6 +179,27 @@ static int module_load_name(const char *path, const char *rootmodule,
return found ? 0 : -1; return found ? 0 : -1;
} }
/* get the module's irssi abi version and bail out on mismatch */
versionfunc = module_get_func(rootmodule, submodule, "abicheck");
if (!g_module_symbol(gmodule, versionfunc, &value_version)) {
g_free(versionfunc);
module_error(MODULE_ERROR_VERSION_MISMATCH, "0",
rootmodule, submodule);
g_module_close(gmodule);
return 0;
}
g_free(versionfunc);
module_version = value_version;
module_version(&module_abi_version);
if (module_abi_version != IRSSI_ABI_VERSION) {
char *module_abi_versionstr = g_strdup_printf("%d", module_abi_version);
module_error(MODULE_ERROR_VERSION_MISMATCH, module_abi_versionstr,
rootmodule, submodule);
g_free(module_abi_versionstr);
g_module_close(gmodule);
return 0;
}
/* get the module's init() and deinit() functions */ /* get the module's init() and deinit() functions */
initfunc = module_get_func(rootmodule, submodule, "init"); initfunc = module_get_func(rootmodule, submodule, "init");
deinitfunc = module_get_func(rootmodule, submodule, "deinit"); deinitfunc = module_get_func(rootmodule, submodule, "deinit");

View File

@ -27,6 +27,7 @@
enum { enum {
MODULE_ERROR_ALREADY_LOADED, MODULE_ERROR_ALREADY_LOADED,
MODULE_ERROR_LOAD, MODULE_ERROR_LOAD,
MODULE_ERROR_VERSION_MISMATCH,
MODULE_ERROR_INVALID MODULE_ERROR_INVALID
}; };

View File

@ -43,6 +43,10 @@ static void sig_module_error(void *number, const char *data,
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_MODULE_LOAD_ERROR, rootmodule, submodule, data); TXT_MODULE_LOAD_ERROR, rootmodule, submodule, data);
break; break;
case MODULE_ERROR_VERSION_MISMATCH:
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_MODULE_VERSION_MISMATCH, rootmodule, submodule, data);
break;
case MODULE_ERROR_INVALID: case MODULE_ERROR_INVALID:
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_MODULE_INVALID, rootmodule, submodule); TXT_MODULE_INVALID, rootmodule, submodule);

View File

@ -196,6 +196,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "module_already_loaded", "Module {hilight $0/$1} already loaded", 2, { 0, 0 } }, { "module_already_loaded", "Module {hilight $0/$1} already loaded", 2, { 0, 0 } },
{ "module_not_loaded", "Module {hilight $0/$1} is not loaded", 2, { 0, 0 } }, { "module_not_loaded", "Module {hilight $0/$1} is not loaded", 2, { 0, 0 } },
{ "module_load_error", "Error loading module {hilight $0/$1}: $2", 3, { 0, 0, 0 } }, { "module_load_error", "Error loading module {hilight $0/$1}: $2", 3, { 0, 0, 0 } },
{ "module_version_mismatch", "{hilight $0/$1} is ABI version $2 but Irssi is version $abiversion, cannot load", 3, { 0, 0, 0 } },
{ "module_invalid", "{hilight $0/$1} isn't Irssi module", 2, { 0, 0 } }, { "module_invalid", "{hilight $0/$1} isn't Irssi module", 2, { 0, 0 } },
{ "module_loaded", "Loaded module {hilight $0/$1}", 2, { 0, 0 } }, { "module_loaded", "Loaded module {hilight $0/$1}", 2, { 0, 0 } },
{ "module_unloaded", "Unloaded module {hilight $0/$1}", 2, { 0, 0 } }, { "module_unloaded", "Unloaded module {hilight $0/$1}", 2, { 0, 0 } },

View File

@ -166,6 +166,7 @@ enum {
TXT_MODULE_ALREADY_LOADED, TXT_MODULE_ALREADY_LOADED,
TXT_MODULE_NOT_LOADED, TXT_MODULE_NOT_LOADED,
TXT_MODULE_LOAD_ERROR, TXT_MODULE_LOAD_ERROR,
TXT_MODULE_VERSION_MISMATCH,
TXT_MODULE_INVALID, TXT_MODULE_INVALID,
TXT_MODULE_LOADED, TXT_MODULE_LOADED,
TXT_MODULE_UNLOADED, TXT_MODULE_UNLOADED,

View File

@ -108,3 +108,8 @@ void irc_proxy_deinit(void)
{ {
proxy_listen_deinit(); proxy_listen_deinit();
} }
void irc_proxy_abicheck(int *version)
{
*version = IRSSI_ABI_VERSION;
}

View File

@ -466,3 +466,8 @@ void perl_core_deinit(void)
signal_remove("script error", (SIGNAL_FUNC) sig_script_error); signal_remove("script error", (SIGNAL_FUNC) sig_script_error);
PERL_SYS_TERM(); PERL_SYS_TERM();
} }
void perl_core_abicheck(int *version)
{
*version = IRSSI_ABI_VERSION;
}

View File

@ -278,3 +278,8 @@ void fe_perl_deinit(void)
perl_core_print_script_error(TRUE); perl_core_print_script_error(TRUE);
} }
void fe_perl_abicheck(int *version)
{
*version = IRSSI_ABI_VERSION;
}