void purple_plugins_load_saved(const char *key) { #ifdef PURPLE_PLUGINS GList *f, *files; g_return_if_fail(key != NULL); files = purple_prefs_get_path_list(key); for (f = files; f; f = f->next) { char *filename; char *basename; PurplePlugin *plugin; if (f->data == NULL) continue; filename = f->data; /* * 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 * of either. */ basename = strrchr(filename, '/'); if ((basename == NULL) || (basename < strrchr(filename, '\\'))) basename = strrchr(filename, '\\'); if (basename != NULL) basename++; /* Strip the extension */ if (basename) 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", plugin->path); purple_plugin_load(plugin); } else { purple_debug_error("plugins", "Unable to find saved plugin %s\n", filename); } g_free(basename); g_free(f->data); } g_list_free(files); #endif /* PURPLE_PLUGINS */ }
static void install_selected_file_cb(gpointer handle, const char *filename) { /* Try to init the selected file. * If it succeeds, try to make a copy of the file in $USERDIR/plugins/. * If the copy succeeds, unload and destroy the plugin in the original * location and init+load the new one. * Select the plugin in the plugin list. */ char *path; PurplePlugin *plugin; g_return_if_fail(plugins.window); plugin = purple_plugin_probe(filename); if (!plugin) { purple_notify_error(handle, _("Error loading plugin"), _("The selected file is not a valid plugin."), _("Please open the debug window and try again to see the exact error message."), NULL); return; } if (g_list_find(gnt_tree_get_rows(GNT_TREE(plugins.tree)), plugin)) { purple_plugin_load(plugin); gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin)); gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin); return; } path = g_build_filename(purple_user_dir(), "plugins", NULL); if (purple_build_dir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) { char *content = NULL; gsize length = 0; if (g_file_get_contents(filename, &content, &length, NULL)) { char *file = g_path_get_basename(filename); g_free(path); path = g_build_filename(purple_user_dir(), "plugins", file, NULL); if (purple_util_write_data_to_file_absolute(path, content, length)) { purple_plugin_destroy(plugin); plugin = purple_plugin_probe(path); if (!plugin) { purple_debug_warning("gntplugin", "This is really strange. %s can be loaded, but %s can't!\n", filename, path); g_unlink(path); plugin = purple_plugin_probe(filename); } } else { } } g_free(content); } g_free(path); purple_plugin_load(plugin); if (plugin->info->type == PURPLE_PLUGIN_LOADER) { GList *cur; for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; cur != NULL; cur = cur->next) purple_plugins_probe(cur->data); return; } if (plugin->info->type != PURPLE_PLUGIN_STANDARD || (plugin->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) || plugin->error) return; gnt_tree_add_choice(GNT_TREE(plugins.tree), plugin, gnt_tree_create_row(GNT_TREE(plugins.tree), plugin->info->name), NULL, NULL); gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin)); gnt_tree_set_row_flags(GNT_TREE(plugins.tree), plugin, GNT_TEXT_FLAG_BOLD); gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin); }
void purple_plugins_probe(const char *ext) { #ifdef PURPLE_PLUGINS GDir *dir; const gchar *file; gchar *path; PurplePlugin *plugin; GList *cur; const char *search_path; if (!g_module_supported()) return; /* Probe plugins */ for (cur = search_paths; cur != NULL; cur = cur->next) { search_path = cur->data; dir = g_dir_open(search_path, 0, NULL); if (dir != 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); g_free(path); } g_dir_close(dir); } } /* 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) continue; if (plugin->info->type == PURPLE_PLUGIN_LOADER) { /* We'll just load this right now. */ if (!purple_plugin_load(plugin)) { purple_plugin_destroy(plugin); continue; } plugin_loaders = g_list_append(plugin_loaders, plugin); for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; cur != NULL; cur = cur->next) { 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); continue; } /* 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); continue; } protocol_plugins = g_list_insert_sorted(protocol_plugins, plugin, (GCompareFunc)compare_prpl); } } #endif /* PURPLE_PLUGINS */ }