* Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #define _PURPLE_PLUGIN_C_ PurpleSignalMarshalFunc marshal; } PurplePluginIpcCommand; static GList *search_paths = NULL; static GList *plugins = NULL; static GList *loaded_plugins = NULL; static GList *protocol_plugins = NULL; static GList *load_queue = NULL; static GList *plugin_loaders = NULL; static GList *plugins_to_disable = NULL; static void (*probe_cb)(void *) = NULL; static void *probe_cb_data = NULL; static void (*load_cb)(PurplePlugin *, void *) = NULL; static void *load_cb_data = NULL; static void (*unload_cb)(PurplePlugin *, void *) = NULL; static void *unload_cb_data = NULL; has_file_extension(const char *filename, const char *ext) if (filename == NULL || *filename == '\0' || ext == NULL) len = strlen(filename) - extlen; return (strncmp(filename + len, ext, extlen) == 0); is_native(const char *filename) last_period = strrchr(filename, '.'); return !(strcmp(last_period, ".dll") & strcmp(last_period, ".sl") & strcmp(last_period, ".so")); purple_plugin_get_basename(const char *filename) basename = strrchr(filename, G_DIR_SEPARATOR); if (is_native(basename) && ((last_period = strrchr(basename, '.')) != NULL)) return g_strndup(basename, (last_period - basename)); return g_strdup(basename); loader_supports_file(PurplePlugin *loader, const char *filename) for (exts = PURPLE_PLUGIN_LOADER_INFO(loader)->exts; exts != NULL; exts = exts->next) { if (has_file_extension(filename, (char *)exts->data)) { find_loader_for_plugin(const PurplePlugin *plugin) if (plugin->path == NULL) for (l = purple_plugins_get_loaded(); l != NULL; l = l->next) { if (loader->info->type == PURPLE_PLUGIN_LOADER && loader_supports_file(loader, plugin->path)) { #endif /* PURPLE_PLUGINS */ * Negative if a before b, 0 if equal, positive if a after b. compare_prpl(PurplePlugin *a, PurplePlugin *b) if(PURPLE_IS_PROTOCOL_PLUGIN(a)) { if(PURPLE_IS_PROTOCOL_PLUGIN(b)) return strcmp(a->info->name, b->info->name); if(PURPLE_IS_PROTOCOL_PLUGIN(b)) purple_plugin_new(gboolean native, const char *path) plugin = g_new0(PurplePlugin, 1); plugin->native_plugin = native; plugin->path = g_strdup(path); PURPLE_DBUS_REGISTER_POINTER(plugin, PurplePlugin); purple_plugin_probe(const char *filename) PurplePlugin *plugin = NULL; gboolean (*purple_init_plugin)(PurplePlugin *); purple_debug_misc("plugins", "probing %s\n", filename); g_return_val_if_fail(filename != NULL, NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) /* If this plugin has already been probed then exit */ basename = purple_plugin_get_basename(filename); plugin = purple_plugins_find_with_basename(basename); if (purple_strequal(filename, plugin->path)) else if (!purple_plugin_is_unloadable(plugin)) purple_debug_warning("plugins", "Not loading %s. " "Another plugin with the same name (%s) has already been loaded.\n", /* The old plugin was a different file and it was unloadable. * There's no guarantee that this new file with the same name * will be loadable, but unless it fails in one of the silent * ways and the first one didn't, it's not any worse. The user * will still see a greyed-out plugin, which is what we want. */ purple_plugin_destroy(plugin); plugin = purple_plugin_new(has_file_extension(filename, G_MODULE_SUFFIX), filename); if (plugin->native_plugin) { /* Suppress error popups for failing to load plugins */ UINT old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS); * We pass G_MODULE_BIND_LOCAL here to prevent symbols from * plugins being added to the global name space. * G_MODULE_BIND_LOCAL was added in glib 2.3.3. plugin->handle = g_module_open(filename, G_MODULE_BIND_LOCAL); if (plugin->handle == NULL) const char *error = g_module_error(); if (error != NULL && purple_str_has_prefix(error, filename)) error = error + strlen(filename); /* These are just so we don't crash. If we * got this far, they should always be true. */ if (error == NULL || !*error) plugin->error = g_strdup(_("Unknown error")); purple_debug_error("plugins", "%s is not loadable: Unknown error\n", plugin->error = g_strdup(error); purple_debug_error("plugins", "%s is not loadable: %s\n", plugin->path, plugin->error); plugin->handle = g_module_open(filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (plugin->handle == NULL) /* Restore the original error mode */ SetErrorMode(old_error_mode); purple_plugin_destroy(plugin); /* We were able to load the plugin with lazy symbol binding. * This means we're missing some symbol. Mark it as * unloadable and keep going so we get the info to display * to the user so they know to rebuild this plugin. */ plugin->unloadable = TRUE; if (!g_module_symbol(plugin->handle, "purple_init_plugin", purple_debug_error("plugins", "%s is not usable because the " "'purple_init_plugin' symbol could not be " "found. Does the plugin call the " "PURPLE_INIT_PLUGIN() macro?\n", plugin->path); g_module_close(plugin->handle); error = g_module_error(); purple_debug_error("plugins", "Error closing module %s: %s\n", /* Restore the original error mode */ SetErrorMode(old_error_mode); purple_plugin_destroy(plugin); purple_init_plugin = unpunned; /* Restore the original error mode */ SetErrorMode(old_error_mode); loader = find_loader_for_plugin(plugin); purple_plugin_destroy(plugin); purple_init_plugin = PURPLE_PLUGIN_LOADER_INFO(loader)->probe; if (!purple_init_plugin(plugin) || plugin->info == NULL) purple_plugin_destroy(plugin); else if (plugin->info->ui_requirement && !purple_strequal(plugin->info->ui_requirement, purple_core_get_ui())) plugin->error = g_strdup_printf(_("You are using %s, but this plugin requires %s."), purple_core_get_ui(), plugin->info->ui_requirement); purple_debug_error("plugins", "%s is not loadable: The UI requirement is not met. (%s)\n", plugin->path, plugin->error); plugin->unloadable = TRUE; * Check to make sure a plugin has defined an id. * Not having this check caused purple_plugin_unload to * enter an infinite loop in certain situations by passing * purple_find_plugin_by_id a NULL value. -- ecoffey if (plugin->info->id == NULL || *plugin->info->id == '\0') plugin->error = g_strdup(_("This plugin has not defined an ID.")); purple_debug_error("plugins", "%s is not loadable: info->id is not defined.\n", plugin->path); plugin->unloadable = TRUE; /* Really old plugins. */ if (plugin->info->magic != PURPLE_PLUGIN_MAGIC) if (plugin->info->magic >= 2 && plugin->info->magic <= 4) struct _PurplePluginInfo2 unsigned int api_version; PurplePluginPriority priority; gboolean (*load)(PurplePlugin *plugin); gboolean (*unload)(PurplePlugin *plugin); void (*destroy)(PurplePlugin *plugin); PurplePluginUiInfo *prefs_info; GList *(*actions)(PurplePlugin *plugin, gpointer context); } *info2 = (struct _PurplePluginInfo2 *)plugin->info; /* This leaks... but only for ancient plugins, so deal with it. */ plugin->info = g_new0(PurplePluginInfo, 1); /* We don't really need all these to display the plugin info, but * I'm copying them all for good measure. */ plugin->info->magic = info2->api_version; plugin->info->type = info2->type; plugin->info->ui_requirement = info2->ui_requirement; plugin->info->flags = info2->flags; plugin->info->dependencies = info2->dependencies; plugin->info->id = info2->id; plugin->info->name = info2->name; plugin->info->version = info2->version; plugin->info->summary = info2->summary; plugin->info->description = info2->description; plugin->info->author = info2->author; plugin->info->homepage = info2->homepage; plugin->info->load = info2->load; plugin->info->unload = info2->unload; plugin->info->destroy = info2->destroy; plugin->info->ui_info = info2->ui_info; plugin->info->extra_info = info2->extra_info; if (info2->api_version >= 3) plugin->info->prefs_info = info2->prefs_info; if (info2->api_version >= 4) plugin->info->actions = info2->actions; plugin->error = g_strdup_printf(_("Plugin magic mismatch %d (need %d)"), plugin->info->magic, PURPLE_PLUGIN_MAGIC); purple_debug_error("plugins", "%s is not loadable: Plugin magic mismatch %d (need %d)\n", plugin->path, plugin->info->magic, PURPLE_PLUGIN_MAGIC); plugin->unloadable = TRUE; purple_debug_error("plugins", "%s is not loadable: Plugin magic mismatch %d (need %d)\n", plugin->path, plugin->info->magic, PURPLE_PLUGIN_MAGIC); purple_plugin_destroy(plugin); if (plugin->info->major_version != PURPLE_MAJOR_VERSION || plugin->info->minor_version > PURPLE_MINOR_VERSION) plugin->error = g_strdup_printf(_("ABI version mismatch %d.%d.x (need %d.%d.x)"), plugin->info->major_version, plugin->info->minor_version, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION); purple_debug_error("plugins", "%s is not loadable: ABI version mismatch %d.%d.x (need %d.%d.x)\n", plugin->path, plugin->info->major_version, plugin->info->minor_version, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION); plugin->unloadable = TRUE; if (plugin->info->type == PURPLE_PLUGIN_PROTOCOL) /* If plugin is a PRPL, make sure it implements the required functions */ if ((PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->list_icon == NULL) || (PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->login == NULL) || (PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->close == NULL)) plugin->error = g_strdup(_("Plugin does not implement all required functions (list_icon, login and close)")); purple_debug_error("plugins", "%s is not loadable: %s\n", plugin->path, plugin->error); plugin->unloadable = TRUE; /* For debugging, let's warn about prpl prefs. */ if (plugin->info->prefs_info != NULL) purple_debug_error("plugins", "%s has a prefs_info, but is a prpl. This is no longer supported.\n", #endif /* !PURPLE_PLUGINS */ compare_plugins(gconstpointer a, gconstpointer b) const PurplePlugin *plugina = a; const PurplePlugin *pluginb = b; return strcmp(plugina->info->name, pluginb->info->name); #endif /* PURPLE_PLUGINS */ purple_plugin_load(PurplePlugin *plugin) g_return_val_if_fail(plugin != NULL, FALSE); if (purple_plugin_is_loaded(plugin)) if (purple_plugin_is_unloadable(plugin)) g_return_val_if_fail(plugin->error == NULL, FALSE); * Go through the list of the plugin's dependencies. * First pass: Make sure all the plugins needed are probed. for (l = plugin->info->dependencies; l != NULL; l = l->next) const char *dep_name = (const char *)l->data; PurplePlugin *dep_plugin; dep_plugin = purple_plugins_find_with_id(dep_name); tmp = g_strdup_printf(_("The required plugin %s was not found. " "Please install this plugin and try again."), purple_notify_error(NULL, NULL, _("Unable to load the plugin"), tmp); dep_list = g_list_append(dep_list, dep_plugin); /* Second pass: load all the required plugins. */ for (l = dep_list; l != NULL; l = l->next) PurplePlugin *dep_plugin = (PurplePlugin *)l->data; if (!purple_plugin_is_loaded(dep_plugin)) if (!purple_plugin_load(dep_plugin)) tmp = g_strdup_printf(_("The required plugin %s was unable to load."), purple_notify_error(NULL, NULL, _("Unable to load your plugin."), tmp); /* Third pass: note that other plugins are dependencies of this plugin. * This is done separately in case we had to bail out earlier. */ for (l = dep_list; l != NULL; l = l->next) PurplePlugin *dep_plugin = (PurplePlugin *)l->data; dep_plugin->dependent_plugins = g_list_prepend(dep_plugin->dependent_plugins, plugin->info->id); if (plugin->native_plugin) if (plugin->info->load != NULL && !plugin->info->load(plugin)) PurplePluginLoaderInfo *loader_info; loader = find_loader_for_plugin(plugin); loader_info = PURPLE_PLUGIN_LOADER_INFO(loader); if (loader_info->load != NULL) if (!loader_info->load(plugin)) loaded_plugins = g_list_insert_sorted(loaded_plugins, plugin, compare_plugins); load_cb(plugin, load_cb_data); purple_signal_emit(purple_plugins_get_handle(), "plugin-load", plugin); #endif /* !PURPLE_PLUGINS */ purple_plugin_unload(PurplePlugin *plugin) g_return_val_if_fail(plugin != NULL, FALSE); g_return_val_if_fail(purple_plugin_is_loaded(plugin), FALSE); purple_debug_info("plugins", "Unloading plugin %s\n", plugin->info->name); /* Unload all plugins that depend on this plugin. */ for (l = plugin->dependent_plugins; l != NULL; l = ll) { const char * dep_name = (const char *)l->data; PurplePlugin *dep_plugin; /* Store a pointer to the next element in the list. * This is because we'll be modifying this list in the loop. */ dep_plugin = purple_plugins_find_with_id(dep_name); if (dep_plugin != NULL && purple_plugin_is_loaded(dep_plugin)) if (!purple_plugin_unload(dep_plugin)) plugin->error = g_strdup_printf(_("%s requires %s, but it failed to unload."), _(dep_plugin->info->name)); /* This isn't necessary. This has already been done when unloading dep_plugin. */ plugin->dependent_plugins = g_list_delete_link(plugin->dependent_plugins, l); /* Remove this plugin from each dependency's dependent_plugins list. */ for (l = plugin->info->dependencies; l != NULL; l = l->next) const char *dep_name = (const char *)l->data; PurplePlugin *dependency; dependency = purple_plugins_find_with_id(dep_name); dependency->dependent_plugins = g_list_remove(dependency->dependent_plugins, plugin->info->id); purple_debug_error("plugins", "Unable to remove from dependency list for %s\n", dep_name); if (plugin->native_plugin) { if (plugin->info->unload && !plugin->info->unload(plugin)) if (plugin->info->type == PURPLE_PLUGIN_PROTOCOL) { PurplePluginProtocolInfo *prpl_info; prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); for (l = prpl_info->user_splits; l != NULL; l = l->next) purple_account_user_split_destroy(l->data); for (l = prpl_info->protocol_options; l != NULL; l = l->next) purple_account_option_destroy(l->data); if (prpl_info->user_splits != NULL) { g_list_free(prpl_info->user_splits); prpl_info->user_splits = NULL; if (prpl_info->protocol_options != NULL) { g_list_free(prpl_info->protocol_options); prpl_info->protocol_options = NULL; PurplePluginLoaderInfo *loader_info; loader = find_loader_for_plugin(plugin); loader_info = PURPLE_PLUGIN_LOADER_INFO(loader); if (loader_info->unload && !loader_info->unload(plugin)) /* cancel any pending dialogs the plugin has */ purple_request_close_with_handle(plugin); purple_notify_close_with_handle(plugin); purple_signals_disconnect_by_handle(plugin); purple_plugin_ipc_unregister_all(plugin); loaded_plugins = g_list_remove(loaded_plugins, plugin); if ((plugin->info != NULL) && PURPLE_IS_PROTOCOL_PLUGIN(plugin)) protocol_plugins = g_list_remove(protocol_plugins, plugin); plugins_to_disable = g_list_remove(plugins_to_disable, plugin); /* We wouldn't be anywhere near here if the plugin wasn't loaded, so * if plugin->error is set at all, it had to be from a previous * unload failure. It's obviously okay now. unload_cb(plugin, unload_cb_data); purple_signal_emit(purple_plugins_get_handle(), "plugin-unload", plugin); purple_prefs_disconnect_by_handle(plugin); #endif /* PURPLE_PLUGINS */ purple_plugin_disable(PurplePlugin *plugin) g_return_if_fail(plugin != NULL); if (!g_list_find(plugins_to_disable, plugin)) plugins_to_disable = g_list_prepend(plugins_to_disable, plugin); purple_plugin_reload(PurplePlugin *plugin) g_return_val_if_fail(plugin != NULL, FALSE); g_return_val_if_fail(purple_plugin_is_loaded(plugin), FALSE); if (!purple_plugin_unload(plugin)) if (!purple_plugin_load(plugin)) #endif /* !PURPLE_PLUGINS */ purple_plugin_destroy(PurplePlugin *plugin) g_return_if_fail(plugin != NULL); if (purple_plugin_is_loaded(plugin)) purple_plugin_unload(plugin); plugins = g_list_remove(plugins, plugin); load_queue = g_list_remove(load_queue, plugin); /* true, this may leak a little memory if there is a major version * mismatch, but it's a lot better than trying to free something * we shouldn't, and crashing while trying to load an old plugin */ if(plugin->info == NULL || plugin->info->magic != PURPLE_PLUGIN_MAGIC || plugin->info->major_version != PURPLE_MAJOR_VERSION) g_module_close(plugin->handle); PURPLE_DBUS_UNREGISTER_POINTER(plugin); if (plugin->info != NULL) g_list_free(plugin->info->dependencies); if (plugin->native_plugin) if (plugin->info != NULL && plugin->info->type == PURPLE_PLUGIN_LOADER) PurplePluginLoaderInfo *loader_info; GList *exts, *l, *next_l; loader_info = PURPLE_PLUGIN_LOADER_INFO(plugin); if (loader_info != NULL && loader_info->exts != NULL) for (exts = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; for (l = purple_plugins_get_all(); l != NULL; l = next_l) has_file_extension(p2->path, exts->data)) purple_plugin_destroy(p2); g_list_free(loader_info->exts); loader_info->exts = NULL; plugin_loaders = g_list_remove(plugin_loaders, plugin); if (plugin->info != NULL && plugin->info->destroy != NULL) plugin->info->destroy(plugin); * I find it extremely useful to do this when using valgrind, as * it keeps all the plugins open, meaning that valgrind is able to * resolve symbol names in leak traces from plugins. if (!g_getenv("PURPLE_LEAKCHECK_HELP") && !RUNNING_ON_VALGRIND) if (plugin->handle != NULL) g_module_close(plugin->handle); PurplePluginLoaderInfo *loader_info; loader = find_loader_for_plugin(plugin); loader_info = PURPLE_PLUGIN_LOADER_INFO(loader); if (loader_info->destroy != NULL) loader_info->destroy(plugin); PURPLE_DBUS_UNREGISTER_POINTER(plugin); #endif /* !PURPLE_PLUGINS */ purple_plugin_is_loaded(const PurplePlugin *plugin) g_return_val_if_fail(plugin != NULL, FALSE); purple_plugin_is_unloadable(const PurplePlugin *plugin) g_return_val_if_fail(plugin != NULL, FALSE); return plugin->unloadable; purple_plugin_get_id(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); purple_plugin_get_name(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); return _(plugin->info->name); purple_plugin_get_version(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); return plugin->info->version; purple_plugin_get_summary(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); return _(plugin->info->summary); purple_plugin_get_description(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); return _(plugin->info->description); purple_plugin_get_author(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); return _(plugin->info->author); purple_plugin_get_homepage(const PurplePlugin *plugin) { g_return_val_if_fail(plugin, NULL); g_return_val_if_fail(plugin->info, NULL); return plugin->info->homepage; /************************************************************************** **************************************************************************/ destroy_ipc_info(void *data) PurplePluginIpcCommand *ipc_command = (PurplePluginIpcCommand *)data; if (ipc_command->params != NULL) for (i = 0; i < ipc_command->num_params; i++) purple_value_destroy(ipc_command->params[i]); g_free(ipc_command->params); if (ipc_command->ret_value != NULL) purple_value_destroy(ipc_command->ret_value); purple_plugin_ipc_register(PurplePlugin *plugin, const char *command, PurpleCallback func, PurpleSignalMarshalFunc marshal, PurpleValue *ret_value, int num_params, ...) PurplePluginIpcInfo *ipc_info; PurplePluginIpcCommand *ipc_command; g_return_val_if_fail(plugin != NULL, FALSE); g_return_val_if_fail(command != NULL, FALSE); g_return_val_if_fail(func != NULL, FALSE); g_return_val_if_fail(marshal != NULL, FALSE); if (plugin->ipc_data == NULL) ipc_info = plugin->ipc_data = g_new0(PurplePluginIpcInfo, 1); ipc_info->commands = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_ipc_info); ipc_info = (PurplePluginIpcInfo *)plugin->ipc_data; ipc_command = g_new0(PurplePluginIpcCommand, 1); ipc_command->func = func; ipc_command->marshal = marshal; ipc_command->num_params = num_params; ipc_command->ret_value = ret_value; ipc_command->params = g_new0(PurpleValue *, num_params); va_start(args, num_params); for (i = 0; i < num_params; i++) ipc_command->params[i] = va_arg(args, PurpleValue *); g_hash_table_replace(ipc_info->commands, g_strdup(command), ipc_command); ipc_info->command_count++; purple_plugin_ipc_unregister(PurplePlugin *plugin, const char *command) PurplePluginIpcInfo *ipc_info; g_return_if_fail(plugin != NULL); g_return_if_fail(command != NULL); ipc_info = (PurplePluginIpcInfo *)plugin->ipc_data; g_hash_table_lookup(ipc_info->commands, command) == NULL) purple_debug_error("plugins", "IPC command '%s' was not registered for plugin %s\n", command, plugin->info->name); g_hash_table_remove(ipc_info->commands, command); ipc_info->command_count--; if (ipc_info->command_count == 0) g_hash_table_destroy(ipc_info->commands); purple_plugin_ipc_unregister_all(PurplePlugin *plugin) PurplePluginIpcInfo *ipc_info; g_return_if_fail(plugin != NULL); if (plugin->ipc_data == NULL) return; /* Silently ignore it. */ ipc_info = (PurplePluginIpcInfo *)plugin->ipc_data; g_hash_table_destroy(ipc_info->commands); purple_plugin_ipc_get_params(PurplePlugin *plugin, const char *command, PurpleValue **ret_value, int *num_params, PurplePluginIpcInfo *ipc_info; PurplePluginIpcCommand *ipc_command; g_return_val_if_fail(plugin != NULL, FALSE); g_return_val_if_fail(command != NULL, FALSE); ipc_info = (PurplePluginIpcInfo *)plugin->ipc_data; (ipc_command = g_hash_table_lookup(ipc_info->commands, purple_debug_error("plugins", "IPC command '%s' was not registered for plugin %s\n", command, plugin->info->name); *num_params = ipc_command->num_params; *params = ipc_command->params; *ret_value = ipc_command->ret_value; purple_plugin_ipc_call(PurplePlugin *plugin, const char *command, PurplePluginIpcInfo *ipc_info; PurplePluginIpcCommand *ipc_command; g_return_val_if_fail(plugin != NULL, NULL); g_return_val_if_fail(command != NULL, NULL); ipc_info = (PurplePluginIpcInfo *)plugin->ipc_data; (ipc_command = g_hash_table_lookup(ipc_info->commands, purple_debug_error("plugins", "IPC command '%s' was not registered for plugin %s\n", command, plugin->info->name); ipc_command->marshal(ipc_command->func, args, NULL, &ret_value); /************************************************************************** **************************************************************************/ purple_plugins_get_handle(void) { purple_plugins_init(void) { void *handle = purple_plugins_get_handle(); purple_plugins_add_search_path(LIBDIR); purple_signal_register(handle, "plugin-load", purple_marshal_VOID__POINTER, purple_value_new(PURPLE_TYPE_SUBTYPE, purple_signal_register(handle, "plugin-unload", purple_marshal_VOID__POINTER, purple_value_new(PURPLE_TYPE_SUBTYPE, purple_plugins_uninit(void) void *handle = purple_plugins_get_handle(); purple_signals_disconnect_by_handle(handle); purple_signals_unregister_by_instance(handle); g_free(search_paths->data); search_paths = g_list_delete_link(search_paths, search_paths); /************************************************************************** **************************************************************************/ purple_plugins_add_search_path(const char *path) g_return_if_fail(path != NULL); if (g_list_find_custom(search_paths, path, (GCompareFunc)strcmp)) search_paths = g_list_append(search_paths, g_strdup(path)); purple_plugins_get_search_paths() purple_plugins_unload_all(void) while (loaded_plugins != NULL) purple_plugin_unload(loaded_plugins->data); #endif /* PURPLE_PLUGINS */ purple_plugins_unload(PurplePluginType type) for (l = plugins; l; l = l->next) { PurplePlugin *plugin = l->data; if (plugin->info->type == type && purple_plugin_is_loaded(plugin)) purple_plugin_unload(plugin); #endif /* PURPLE_PLUGINS */ purple_plugins_destroy_all(void) purple_plugin_destroy(plugins->data); #endif /* PURPLE_PLUGINS */ purple_plugins_save_loaded(const char *key) for (pl = purple_plugins_get_loaded(); pl != NULL; pl = pl->next) { PurplePlugin *plugin = pl->data; if (plugin->info->type != PURPLE_PLUGIN_PROTOCOL && plugin->info->type != PURPLE_PLUGIN_LOADER && !g_list_find(plugins_to_disable, plugin)) { files = g_list_append(files, plugin->path); purple_prefs_set_path_list(key, files); purple_plugins_load_saved(const char *key) g_return_if_fail(key != NULL); files = purple_prefs_get_path_list(key); for (f = files; f; f = f->next) * We don't know if the filename uses Windows or Unix path * separators (because people might be sharing a prefs.xml * file across systems), so we find the last occurrence basename = strrchr(filename, '/'); if ((basename == NULL) || (basename < strrchr(filename, '\\'))) basename = strrchr(filename, '\\'); /* Strip the extension */ basename = purple_plugin_get_basename(basename); if (((plugin = purple_plugins_find_with_filename(filename)) != NULL) || (basename && (plugin = purple_plugins_find_with_basename(basename)) != NULL) || ((plugin = purple_plugin_probe(filename)) != NULL)) purple_debug_info("plugins", "Loading saved plugin %s\n", purple_plugin_load(plugin); purple_debug_error("plugins", "Unable to find saved plugin %s\n", #endif /* PURPLE_PLUGINS */ purple_plugins_probe(const char *ext) if (!g_module_supported()) for (cur = search_paths; cur != NULL; cur = cur->next) dir = g_dir_open(search_path, 0, NULL); while ((file = g_dir_read_name(dir)) != NULL) path = g_build_filename(search_path, file, NULL); if (ext == NULL || has_file_extension(file, ext)) purple_plugin_probe(path); /* See if we have any plugins waiting to load */ while (load_queue != NULL) plugin = (PurplePlugin *)load_queue->data; load_queue = g_list_remove(load_queue, plugin); if (plugin == NULL || plugin->info == NULL) if (plugin->info->type == PURPLE_PLUGIN_LOADER) /* We'll just load this right now. */ if (!purple_plugin_load(plugin)) purple_plugin_destroy(plugin); plugin_loaders = g_list_append(plugin_loaders, plugin); for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; purple_plugins_probe(cur->data); else if (plugin->info->type == PURPLE_PLUGIN_PROTOCOL) /* We'll just load this right now. */ if (!purple_plugin_load(plugin)) purple_plugin_destroy(plugin); /* Make sure we don't load two PRPLs with the same name? */ if (purple_find_prpl(plugin->info->id)) /* Nothing to see here--move along, move along */ purple_plugin_destroy(plugin); protocol_plugins = g_list_insert_sorted(protocol_plugins, plugin, (GCompareFunc)compare_prpl); #endif /* PURPLE_PLUGINS */ purple_plugin_register(PurplePlugin *plugin) g_return_val_if_fail(plugin != NULL, FALSE); /* If this plugin has been registered already then exit */ if (g_list_find(plugins, plugin)) /* Ensure the plugin has the requisite information */ if (plugin->info->type == PURPLE_PLUGIN_LOADER) PurplePluginLoaderInfo *loader_info; loader_info = PURPLE_PLUGIN_LOADER_INFO(plugin); purple_debug_error("plugins", "%s is not loadable, loader plugin missing loader_info\n", else if (plugin->info->type == PURPLE_PLUGIN_PROTOCOL) PurplePluginProtocolInfo *prpl_info; prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); purple_debug_error("plugins", "%s is not loadable, protocol plugin missing prpl_info\n", /* This plugin should be probed and maybe loaded--add it to the queue */ load_queue = g_list_append(load_queue, plugin); if (plugin->info != NULL) if (plugin->info->type == PURPLE_PLUGIN_PROTOCOL) protocol_plugins = g_list_insert_sorted(protocol_plugins, plugin, (GCompareFunc)compare_prpl); if (plugin->info->load != NULL) if (!plugin->info->load(plugin)) plugins = g_list_append(plugins, plugin); purple_plugins_enabled(void) purple_plugins_register_probe_notify_cb(void (*func)(void *), void *data) purple_plugins_unregister_probe_notify_cb(void (*func)(void *)) purple_plugins_register_load_notify_cb(void (*func)(PurplePlugin *, void *), purple_plugins_unregister_load_notify_cb(void (*func)(PurplePlugin *, void *)) purple_plugins_register_unload_notify_cb(void (*func)(PurplePlugin *, void *), purple_plugins_unregister_unload_notify_cb(void (*func)(PurplePlugin *, void *)) purple_plugins_find_with_name(const char *name) for (l = plugins; l != NULL; l = l->next) { if (purple_strequal(plugin->info->name, name)) purple_plugins_find_with_filename(const char *filename) for (l = plugins; l != NULL; l = l->next) { if (purple_strequal(plugin->path, filename)) purple_plugins_find_with_basename(const char *basename) g_return_val_if_fail(basename != NULL, NULL); for (l = plugins; l != NULL; l = l->next) plugin = (PurplePlugin *)l->data; if (plugin->path != NULL) { tmp = purple_plugin_get_basename(plugin->path); if (purple_strequal(tmp, basename)) #endif /* PURPLE_PLUGINS */ purple_plugins_find_with_id(const char *id) g_return_val_if_fail(id != NULL, NULL); for (l = plugins; l != NULL; l = l->next) if (purple_strequal(plugin->info->id, id)) purple_plugins_get_loaded(void) purple_plugins_get_protocols(void) purple_plugins_get_all(void) purple_plugin_action_new(const char* label, void (*callback)(PurplePluginAction *)) PurplePluginAction *act = g_new0(PurplePluginAction, 1); act->label = g_strdup(label); act->callback = callback; purple_plugin_action_free(PurplePluginAction *action) g_return_if_fail(action != NULL);