Sun, 11 Aug 2013 18:55:41 +0530
Return a GError if load or unload fails
| libpurple/plugins.c | file | annotate | diff | comparison | revisions | |
| libpurple/plugins.h | file | annotate | diff | comparison | revisions |
--- a/libpurple/plugins.c Sun Aug 11 18:39:16 2013 +0530 +++ b/libpurple/plugins.c Sun Aug 11 18:55:41 2013 +0530 @@ -73,10 +73,10 @@ * Plugin API **************************************************************************/ gboolean -purple_plugin_load(PurplePlugin *plugin) +purple_plugin_load(PurplePlugin *plugin, GError **error) { #ifdef PURPLE_PLUGINS - GError *error = NULL; + GError *err = NULL; g_return_val_if_fail(plugin != NULL, FALSE); @@ -87,13 +87,24 @@ purple_debug_error("plugins", "Failed to load plugin %s: %s", purple_plugin_get_filename(plugin), purple_plugin_get_error(plugin)); + + if (error) { + *error = g_error_new(PURPLE_PLUGINS_DOMAIN, 0, + "Plugin is not loadable: %s", + purple_plugin_get_error(plugin)); + } + return FALSE; } - if (!gplugin_plugin_manager_load_plugin(plugin, &error)) { + if (!gplugin_plugin_manager_load_plugin(plugin, &err)) { purple_debug_error("plugins", "Failed to load plugin %s: %s", - purple_plugin_get_filename(plugin), error->message); - g_error_free(error); + purple_plugin_get_filename(plugin), err->message); + + if (error) + *error = g_error_copy(err); + g_error_free(err); + return FALSE; } @@ -112,14 +123,16 @@ } gboolean -purple_plugin_unload(PurplePlugin *plugin) +purple_plugin_unload(PurplePlugin *plugin, GError **error) { #ifdef PURPLE_PLUGINS - GError *error = NULL; + GError *err = NULL; PurplePluginInfoPrivate *priv; g_return_val_if_fail(plugin != NULL, FALSE); - g_return_val_if_fail(purple_plugin_is_loaded(plugin), FALSE); + + if (!purple_plugin_is_loaded(plugin)) + return TRUE; priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(purple_plugin_get_info(plugin)); @@ -128,10 +141,14 @@ purple_debug_info("plugins", "Unloading plugin %s\n", purple_plugin_get_filename(plugin)); - if (!gplugin_plugin_manager_unload_plugin(plugin, &error)) { + if (!gplugin_plugin_manager_unload_plugin(plugin, &err)) { purple_debug_error("plugins", "Failed to unload plugin %s: %s", - purple_plugin_get_filename(plugin), error->message); - g_error_free(error); + purple_plugin_get_filename(plugin), err->message); + + if (error) + *error = g_error_copy(err); + g_error_free(err); + return FALSE; } @@ -815,7 +832,7 @@ GPLUGIN_PLUGIN_INFO_FLAGS_LOAD_ON_QUERY) { purple_debug_info("plugins", "Auto-loading plugin %s\n", purple_plugin_get_filename(plugin)); - purple_plugin_load(plugin); + purple_plugin_load(plugin, NULL); } } @@ -916,7 +933,7 @@ if (plugin) { purple_debug_info("plugins", "Loading saved plugin %s\n", file); - purple_plugin_load(plugin); + purple_plugin_load(plugin, NULL); } else { purple_debug_error("plugins", "Unable to find saved plugin %s\n", file); } @@ -966,7 +983,7 @@ #ifdef PURPLE_PLUGINS purple_debug_info("plugins", "Unloading all plugins\n"); while (loaded_plugins != NULL) - purple_plugin_unload(loaded_plugins->data); + purple_plugin_unload(loaded_plugins->data, NULL); #endif purple_signals_disconnect_by_handle(handle);
--- a/libpurple/plugins.h Sun Aug 11 18:39:16 2013 +0530 +++ b/libpurple/plugins.h Sun Aug 11 18:55:41 2013 +0530 @@ -211,23 +211,27 @@ * Attempts to load a plugin. * * @param plugin The plugin to load. + * @param error Return location for a #GError or @c NULL. If provided, this + * will be set to the reason if the load fails. * - * @return @c TRUE if successful, or @c FALSE otherwise. + * @return @c TRUE if successful or already loaded, @c FALSE otherwise. * * @see purple_plugin_unload() */ -gboolean purple_plugin_load(PurplePlugin *plugin); +gboolean purple_plugin_load(PurplePlugin *plugin, GError **error); /** * Unloads the specified plugin. * * @param plugin The plugin handle. + * @param error Return location for a #GError or @c NULL. If provided, this + * will be set to the reason if the unload fails. * - * @return @c TRUE if successful, or @c FALSE otherwise. + * @return @c TRUE if successful or not loaded, @c FALSE otherwise. * * @see purple_plugin_load() */ -gboolean purple_plugin_unload(PurplePlugin *plugin); +gboolean purple_plugin_unload(PurplePlugin *plugin, GError **error); /** * Returns whether or not a plugin is currently loaded.