/** * Dyna-deleter for plugin pool * * @param __self - descriptor of deleting plugin */ static void plugin_dyna_deleter (void *__self) { plugin_deactivate (__self); plugin_call_onunload (__self); plugin_free (__self); }
int plugin_kill (char *name, int by_filename) { GSList *list; hexchat_plugin *pl; list = plugin_list; while (list) { pl = list->data; /* static-plugins (plugin-timer.c) have a NULL filename */ if ((by_filename && pl->filename && g_ascii_strcasecmp (name, pl->filename) == 0) || (by_filename && pl->filename && g_ascii_strcasecmp (name, file_part (pl->filename)) == 0) || (!by_filename && g_ascii_strcasecmp (name, pl->name) == 0)) { /* statically linked plugins have a NULL filename */ if (pl->filename != NULL && !pl->fake) { if (plugin_free (pl, TRUE, TRUE)) return 1; return 2; } } list = list->next; } return 0; }
void hexchat_plugingui_remove (hexchat_plugin *ph, void *handle) { #ifdef USE_PLUGIN plugin_free (handle, FALSE, FALSE); #endif }
int plugin_kill(char *name, int by_filename) { GSList *list; xchat_plugin *pl; list = plugin_list; while (list) { pl = (xchat_plugin*)list->data; // static-plugins (plugin-timer.c) have a nullptr filename if ((by_filename && pl->filename && strcasecmp(name, pl->filename) == 0) || (by_filename && pl->filename && strcasecmp(name, file_part(pl->filename)) == 0) || (!by_filename && strcasecmp(name, pl->name) == 0)) { // statically linked plugins have a nullptr filename if (pl->filename != nullptr && !pl->fake) { if (plugin_free(pl, TRUE, TRUE)) return 1; return 2; } } list = list->next; } return 0; }
void plugin_kill_all() { GSList *list, *next; xchat_plugin *pl; list = plugin_list; while (list) { pl = (xchat_plugin*)list->data; next = list->next; if (!pl->fake) plugin_free((xchat_plugin*)list->data, TRUE, FALSE); list = next; } }
/** * Load plugin * * @param __fn - file name of library to use * @param zero on sucess, non-zero otherwise */ int plugin_load (char *__fn) { plugin_t *plugin; strcpy (error, ""); plugin = plugin_new (__fn); if (plugin_probe (plugin) || plugin_on_load (plugin)) { plugin_free (plugin); return -1; } return 0; }
Plugin *plugin_new(PluginType pluginType, const char *url, const char *hostname, const char *ip, Window windowId) { Plugin *plugin = calloc(1, sizeof(Plugin)); if (!plugin) return NULL; plugin->type = pluginType; plugin->url = strdup(url); plugin->hostname = strdup(hostname); plugin->ip = strdup(ip); plugin->windowId = windowId; if (!plugin->url || !plugin->hostname || !plugin->ip) { plugin_free(plugin); return NULL; } return plugin; }
static void free_plugins(list_t * plugin_list) { lnode_t *p; if (plugin_list == NULL) { return; } if (list_isempty(plugin_list)) { return; } p = list_first(plugin_list); while (p) { WsManPlugin *plugin = (WsManPlugin *)p->list_data; plugin_free(plugin); p = list_next(plugin_list, p); } list_destroy_nodes(plugin_list); list_destroy(plugin_list); }
static void scan_plugins_in_directory ( WsManListenerH *listener, const char *dir_name) { list_t *files = scan_files_in_dir ( dir_name, select_all_files); lnode_t *node = list_first(files); listener->plugins = list_create(LISTCOUNT_T_MAX); while (node != NULL) { const char* entry_name; int retv = -1; entry_name = (const char*) node->list_data; node = list_next(files, node); if ((NULL != entry_name) && strlen (entry_name) > strlen(PLUGIN_EXT) && (0 == strcmp (&entry_name[strlen(entry_name)-strlen(PLUGIN_EXT)], PLUGIN_EXT))) { char *plugin_path = u_strdup_printf ("%s/%s", dir_name, entry_name); WsManPlugin *plugin = plugin_new(); if ((NULL != plugin) && (NULL != plugin_path)) { if (load_plugin(plugin, plugin_path) == 0 ) { lnode_t *plg = lnode_create (plugin); list_append (listener->plugins, plg); retv = 0 ; } } else { error("Out of memory scanning for plugins."); } if (plugin_path) u_free (plugin_path); if (retv != 0 && (NULL != plugin)) plugin_free(plugin); } } list_destroy_nodes(files); list_destroy(files); return; }
void plugins_free(server *srv) { size_t i; plugins_call_cleanup(srv); for (i = 0; i < srv->plugins.used; i++) { plugin *p = ((plugin **)srv->plugins.ptr)[i]; plugin_free(p); } for (i = 0; srv->plugin_slots && i < PLUGIN_FUNC_SIZEOF; i++) { plugin **slot = ((plugin ***)(srv->plugin_slots))[i]; if (slot) free(slot); } free(srv->plugin_slots); srv->plugin_slots = NULL; free(srv->plugins.ptr); srv->plugins.ptr = NULL; srv->plugins.used = 0; }
int plugin_reload (session *sess, char *name, int by_filename) { GSList *list; char *filename; char *ret; hexchat_plugin *pl; list = plugin_list; while (list) { pl = list->data; /* static-plugins (plugin-timer.c) have a NULL filename */ if ((by_filename && pl->filename && g_ascii_strcasecmp (name, pl->filename) == 0) || (by_filename && pl->filename && g_ascii_strcasecmp (name, file_part (pl->filename)) == 0) || (!by_filename && g_ascii_strcasecmp (name, pl->name) == 0)) { /* statically linked plugins have a NULL filename */ if (pl->filename != NULL && !pl->fake) { filename = g_strdup (pl->filename); plugin_free (pl, TRUE, FALSE); ret = plugin_load (sess, filename, NULL); g_free (filename); if (ret == NULL) return 1; else return 0; } else return 2; } list = list->next; } return 0; }
int plugins_load(server *srv) { plugin *p; size_t i, j; for (i = 0; i < srv->srvconf.modules->used; i++) { data_string *d = (data_string *)srv->srvconf.modules->data[i]; char *module = d->value->ptr; for (j = 0; j < i; j++) { if (buffer_is_equal(d->value, ((data_string *) srv->srvconf.modules->data[j])->value)) { log_error_write(srv, __FILE__, __LINE__, "sbs", "Cannot load plugin", d->value, "more than once, please fix your config (lighttpd may not accept such configs in future releases)"); continue; } } for (j = 0; load_functions[j].name; ++j) { if (0 == strcmp(load_functions[j].name, module)) { p = plugin_init(); if ((*load_functions[j].plugin_init)(p)) { log_error_write(srv, __FILE__, __LINE__, "ss", module, "plugin init failed" ); plugin_free(p); return -1; } plugins_register(srv, p); break; } } if (!load_functions[j].name) { log_error_write(srv, __FILE__, __LINE__, "ss", module, " plugin not found" ); return -1; } } return 0; }
void plugin_add (session *sess, char *filename, void *handle, void *init_func, void *deinit_func, char *arg, int fake) { hexchat_plugin *pl; char *file; file = g_strdup (filename); pl = plugin_list_add (sess, file, file, NULL, NULL, handle, deinit_func, fake, FALSE); if (!fake) { /* win32 uses these because it doesn't have --export-dynamic! */ pl->hexchat_hook_command = hexchat_hook_command; pl->hexchat_hook_server = hexchat_hook_server; pl->hexchat_hook_print = hexchat_hook_print; pl->hexchat_hook_timer = hexchat_hook_timer; pl->hexchat_hook_fd = hexchat_hook_fd; pl->hexchat_unhook = hexchat_unhook; pl->hexchat_print = hexchat_print; pl->hexchat_printf = hexchat_printf; pl->hexchat_command = hexchat_command; pl->hexchat_commandf = hexchat_commandf; pl->hexchat_nickcmp = hexchat_nickcmp; pl->hexchat_set_context = hexchat_set_context; pl->hexchat_find_context = hexchat_find_context; pl->hexchat_get_context = hexchat_get_context; pl->hexchat_get_info = hexchat_get_info; pl->hexchat_get_prefs = hexchat_get_prefs; pl->hexchat_list_get = hexchat_list_get; pl->hexchat_list_free = hexchat_list_free; pl->hexchat_list_fields = hexchat_list_fields; pl->hexchat_list_str = hexchat_list_str; pl->hexchat_list_next = hexchat_list_next; pl->hexchat_list_int = hexchat_list_int; pl->hexchat_plugingui_add = hexchat_plugingui_add; pl->hexchat_plugingui_remove = hexchat_plugingui_remove; pl->hexchat_emit_print = hexchat_emit_print; #ifdef WIN32 pl->hexchat_read_fd = (void *) hexchat_read_fd; #else pl->hexchat_read_fd = hexchat_dummy; #endif pl->hexchat_list_time = hexchat_list_time; pl->hexchat_gettext = hexchat_gettext; pl->hexchat_send_modes = hexchat_send_modes; pl->hexchat_strip = hexchat_strip; pl->hexchat_free = hexchat_free; pl->hexchat_pluginpref_set_str = hexchat_pluginpref_set_str; pl->hexchat_pluginpref_get_str = hexchat_pluginpref_get_str; pl->hexchat_pluginpref_set_int = hexchat_pluginpref_set_int; pl->hexchat_pluginpref_get_int = hexchat_pluginpref_get_int; pl->hexchat_pluginpref_delete = hexchat_pluginpref_delete; pl->hexchat_pluginpref_list = hexchat_pluginpref_list; pl->hexchat_hook_server_attrs = hexchat_hook_server_attrs; pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs; pl->hexchat_emit_print_attrs = hexchat_emit_print_attrs; pl->hexchat_event_attrs_create = hexchat_event_attrs_create; pl->hexchat_event_attrs_free = hexchat_event_attrs_free; /* run hexchat_plugin_init, if it returns 0, close the plugin */ if (((hexchat_init_func *)init_func) (pl, &pl->name, &pl->desc, &pl->version, arg) == 0) { plugin_free (pl, FALSE, FALSE); return; } } #ifdef USE_PLUGIN fe_pluginlist_update (); #endif }
int plugins_load(server *srv) { plugin *p; int (*init)(plugin *pl); const char *error; size_t i, j; for (i = 0; i < srv->srvconf.modules->used; i++) { data_string *d = (data_string *)srv->srvconf.modules->data[i]; char *modules = d->value->ptr; for (j = 0; j < i; j++) { if (buffer_is_equal(d->value, ((data_string *) srv->srvconf.modules->data[j])->value)) { log_error_write(srv, __FILE__, __LINE__, "sbs", "Cannot load plugin", d->value, "more than once, please fix your config (we may not accept such configs in future releases"); continue; } } buffer_copy_string_buffer(srv->tmp_buf, srv->srvconf.modules_dir); buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("/")); buffer_append_string(srv->tmp_buf, modules); #if defined(__WIN32) || defined(__CYGWIN__) buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".dll")); #else buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".so")); #endif p = plugin_init(); #ifdef __WIN32 if (NULL == (p->lib = LoadLibrary(srv->tmp_buf->ptr))) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); log_error_write(srv, __FILE__, __LINE__, "ssb", "LoadLibrary() failed", lpMsgBuf, srv->tmp_buf); plugin_free(p); return -1; } #else if (NULL == (p->lib = dlopen(srv->tmp_buf->ptr, RTLD_NOW|RTLD_GLOBAL))) { log_error_write(srv, __FILE__, __LINE__, "sbs", "dlopen() failed for:", srv->tmp_buf, dlerror()); plugin_free(p); return -1; } #endif buffer_reset(srv->tmp_buf); buffer_copy_string(srv->tmp_buf, modules); buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("_plugin_init")); #ifdef __WIN32 init = GetProcAddress(p->lib, srv->tmp_buf->ptr); if (init == NULL) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); log_error_write(srv, __FILE__, __LINE__, "sbs", "getprocaddress failed:", srv->tmp_buf, lpMsgBuf); plugin_free(p); return -1; } #else #if 1 init = (int (*)(plugin *))(intptr_t)dlsym(p->lib, srv->tmp_buf->ptr); #else *(void **)(&init) = dlsym(p->lib, srv->tmp_buf->ptr); #endif if ((error = dlerror()) != NULL) { log_error_write(srv, __FILE__, __LINE__, "s", error); plugin_free(p); return -1; } #endif if ((*init)(p)) { log_error_write(srv, __FILE__, __LINE__, "ss", modules, "plugin init failed" ); plugin_free(p); return -1; } #if 0 log_error_write(srv, __FILE__, __LINE__, "ss", modules, "plugin loaded" ); #endif plugins_register(srv, p); } return 0; }
void plugin_add (session *sess, char *filename, void *handle, void *init_func, void *deinit_func, char *arg, int fake) { xchat_plugin *pl; char *file; file = NULL; if (filename) file = strdup (filename); pl = plugin_list_add (sess, file, file, NULL, NULL, handle, deinit_func, fake, FALSE); if (!fake) { /* win32 uses these because it doesn't have --export-dynamic! */ pl->xchat_hook_command = xchat_hook_command; pl->xchat_hook_server = xchat_hook_server; pl->xchat_hook_print = xchat_hook_print; pl->xchat_hook_timer = xchat_hook_timer; pl->xchat_hook_fd = xchat_hook_fd; pl->xchat_unhook = xchat_unhook; pl->xchat_print = xchat_print; pl->xchat_printf = xchat_printf; pl->xchat_command = xchat_command; pl->xchat_commandf = xchat_commandf; pl->xchat_nickcmp = xchat_nickcmp; pl->xchat_set_context = xchat_set_context; pl->xchat_find_context = xchat_find_context; pl->xchat_get_context = xchat_get_context; pl->xchat_get_info = xchat_get_info; pl->xchat_get_prefs = xchat_get_prefs; pl->xchat_list_get = xchat_list_get; pl->xchat_list_free = xchat_list_free; pl->xchat_list_fields = xchat_list_fields; pl->xchat_list_str = xchat_list_str; pl->xchat_list_next = xchat_list_next; pl->xchat_list_int = xchat_list_int; pl->xchat_plugingui_add = xchat_plugingui_add; pl->xchat_plugingui_remove = xchat_plugingui_remove; pl->xchat_emit_print = xchat_emit_print; pl->xchat_read_fd = (void *) xchat_read_fd; pl->xchat_list_time = xchat_list_time; pl->xchat_gettext = xchat_gettext; pl->xchat_send_modes = xchat_send_modes; pl->xchat_strip = xchat_strip; pl->xchat_free = xchat_free; /* incase new plugins are loaded on older xchat */ pl->xchat_dummy4 = xchat_dummy; pl->xchat_dummy3 = xchat_dummy; pl->xchat_dummy2 = xchat_dummy; pl->xchat_dummy1 = xchat_dummy; /* run xchat_plugin_init, if it returns 0, close the plugin */ if (((xchat_init_func *)init_func) (pl, &pl->name, &pl->desc, &pl->version, arg) == 0) { plugin_free (pl, FALSE, FALSE); return; } } #ifdef USE_PLUGIN fe_pluginlist_update (); #endif }
static void objDeallocate(NPObject *npobj) { PluginObject *this = (PluginObject*)npobj; plugin_free(this->plugin); free(this); }