/* Returns 1 if ok, 0 if error in module and -1 if module wasn't found */ static int module_load_name(const char *path, const char *rootmodule, const char *submodule, int silent) { void (*module_init) (void); void (*module_deinit) (void); GModule *gmodule; MODULE_REC *module; MODULE_FILE_REC *rec; gpointer value1, value2; char *initfunc, *deinitfunc; int found; gmodule = module_open(path, &found); if (gmodule == NULL) { if (!silent || found) { module_error(MODULE_ERROR_LOAD, g_module_error(), rootmodule, submodule); } return found ? 0 : -1; } /* get the module's init() and deinit() functions */ initfunc = module_get_func(rootmodule, submodule, "init"); deinitfunc = module_get_func(rootmodule, submodule, "deinit"); found = g_module_symbol(gmodule, initfunc, &value1) && g_module_symbol(gmodule, deinitfunc, &value2); g_free(initfunc); g_free(deinitfunc); module_init = value1; module_deinit = value2; if (!found) { module_error(MODULE_ERROR_INVALID, NULL, rootmodule, submodule); g_module_close(gmodule); return 0; } /* Call the module's init() function - it should register itself with module_register() function, abort if it doesn't. */ module_init(); module = module_find(rootmodule); rec = module == NULL ? NULL : strcmp(rootmodule, submodule) == 0 ? module_file_find(module, "core") : module_file_find(module, submodule); if (rec == NULL) { rec = module_register_full(rootmodule, submodule, NULL); rec->gmodule = gmodule; module_file_unload(rec); module_error(MODULE_ERROR_INVALID, NULL, rootmodule, submodule); return 0; } rec->module_deinit = module_deinit; rec->gmodule = gmodule; rec->initialized = TRUE; settings_check_module(rec->defined_module_name); signal_emit("module loaded", 2, rec->root, rec); return 1; }
/* Returns 1 if ok, 0 if error in module and -1 if module wasn't found */ static int module_load_name(const char *path, const char *rootmodule, const char *submodule, int silent) { void (*module_init) (void); void (*module_deinit) (void); void (*module_version) (int *); GModule *gmodule; MODULE_REC *module; MODULE_FILE_REC *rec; gpointer value_version = NULL; gpointer value1, value2 = NULL; char *versionfunc, *initfunc, *deinitfunc; int module_abi_version = 0; int found; gmodule = module_open(path, &found); if (gmodule == NULL) { if (!silent || found) { module_error(MODULE_ERROR_LOAD, g_module_error(), rootmodule, submodule); } 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 */ initfunc = module_get_func(rootmodule, submodule, "init"); deinitfunc = module_get_func(rootmodule, submodule, "deinit"); found = g_module_symbol(gmodule, initfunc, &value1) && g_module_symbol(gmodule, deinitfunc, &value2); g_free(initfunc); g_free(deinitfunc); if (!found) { module_error(MODULE_ERROR_INVALID, NULL, rootmodule, submodule); g_module_close(gmodule); return 0; } module_init = value1; module_deinit = value2; /* Call the module's init() function - it should register itself with module_register() function, abort if it doesn't. */ module_init(); module = module_find(rootmodule); rec = module == NULL ? NULL : g_strcmp0(rootmodule, submodule) == 0 ? module_file_find(module, "core") : module_file_find(module, submodule); if (rec == NULL) { rec = module_register_full(rootmodule, submodule, NULL); rec->gmodule = gmodule; module_file_unload(rec); module_error(MODULE_ERROR_INVALID, NULL, rootmodule, submodule); return 0; } rec->module_deinit = module_deinit; rec->gmodule = gmodule; rec->initialized = TRUE; settings_check_module(rec->defined_module_name); signal_emit("module loaded", 2, rec->root, rec); return 1; }