/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail Team
*
* 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
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* 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 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#endif
#include "defs.h"
#include <glib.h>
#include "plugin.h"
#include "prefs.h"
#include "claws.h"
-#ifdef HAVE_VALGRIND
-#include "valgrind.h"
-#endif
+#include "timing.h"
+
struct _Plugin
{
gchar *filename;
const gchar *plugin_feature_names[] =
{ N_("Nothing"),
N_("a viewer"),
+ N_("a MIME parser"),
N_("folders"),
N_("filtering"),
N_("a privacy interface"),
N_("things"),
NULL };
+/* The plugin must be at least under one of these licences and have
+ the corresponding token returned by the plugin_licence function.
+ */
+const gchar const *plugin_licence_tokens[] = {
+ "LGPL2.1+", "LGPLv2.1+", "LGPL2.1", "LGPLv2.1",
+ "LGPL3+", "LGPLv3+", "LGPL3", "LGPLv3",
+ "GPL3+", "GPLv3+", "GPL3", "GPLv3",
+ "GPL2+", "GPLv2+",
+ "Apache2.0", "Apache 2.0", "Apache v2.0",
+ NULL
+};
+
+/* Dual (or more) licences are allowed, must be separated by one of these.
+ */
+#define IS_LICENCE_SEP(a) ((a) == ',' || (a) == ';' || (a) == '|' || (a) == '/' || (a) == '\0')
+
/**
* List of all loaded plugins
*/
different directory. I think it would be better to compare
only the basename of the filename here (case-insensitive on
W32). */
- g_return_val_if_fail(plugin, 1);
- g_return_val_if_fail(plugin->filename, 1);
- g_return_val_if_fail(filename, 1);
+ cm_return_val_if_fail(plugin, 1);
+ cm_return_val_if_fail(plugin->filename, 1);
+ cm_return_val_if_fail(filename, 1);
return strcmp(filename, plugin->filename);
}
PrefFile *pfile;
GSList *type_cur, *plugin_cur;
Plugin *plugin;
-
+
for (type_cur = plugin_types; type_cur != NULL; type_cur = g_slist_next(type_cur)) {
rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
#ifdef G_OS_WIN32
continue;
if (!strcmp(plugin->type(), type_cur->data))
- fprintf(pfile->fp, "%s\n", plugin->filename);
+ if (fprintf(pfile->fp, "%s\n", plugin->filename) < 0)
+ goto revert;
}
for (plugin_cur = unloaded_plugins; plugin_cur != NULL; plugin_cur = g_slist_next(plugin_cur)) {
plugin = (Plugin *) plugin_cur->data;
continue;
if (!strcmp(plugin->type(), type_cur->data))
- fprintf(pfile->fp, "%s\n", plugin->filename);
+ if (fprintf(pfile->fp, "%s\n", plugin->filename) < 0)
+ goto revert;
}
- fprintf(pfile->fp, "\n");
+ if (fprintf(pfile->fp, "\n") < 0)
+ goto revert;
if (prefs_file_close(pfile) < 0)
g_warning("failed to write plugin list\n");
g_free(rcpath);
+
+ continue;
+
+revert:
+ g_warning("failed to write plugin list\n");
+ if (prefs_file_close_revert(pfile) < 0)
+ g_warning("failed to revert plugin list\n");
+
+ g_free(rcpath);
}
}
dep_plugin = plugin_load(path, error);
if (dep_plugin == NULL) {
g_free(path);
+ fclose(fp);
return -1;
}
}
return NULL;
}
+
+static gboolean plugin_licence_check(const gchar *licence) {
+ gint i = 0;
+ gint len = 0;
+
+ if (licence != NULL) {
+ len = strlen(licence);
+ }
+ if (len == 0) {
+ g_warning("plugin licence check failed: empty licence\n");
+ return FALSE;
+ }
+ while (plugin_licence_tokens[i] != NULL) {
+ gchar *found = g_strstr_len(licence, len, plugin_licence_tokens[i]);
+ if (found != NULL) {
+ gint tlen = strlen(plugin_licence_tokens[i]);
+ if (len != tlen) { /* not a single license */
+ if (((found == licence) && (!IS_LICENCE_SEP(licence[tlen])))
+ || (!IS_LICENCE_SEP(*(found - 1)))
+ || (!IS_LICENCE_SEP(*(found + tlen)))) {
+ debug_print("plugin licence check failed: invalid separator\n");
+ return FALSE;
+ }
+ }
+ debug_print("plugin licence check passed: %s found\n", plugin_licence_tokens[i]);
+ return TRUE;
+ }
+ ++i;
+ }
+ debug_print("plugin licence check failed: %s is not a valid licence\n", licence);
+ return FALSE;
+}
+
/**
* Loads a plugin
*
const gchar *(*plugin_type)(void);
const gchar *(*plugin_licence)(void);
struct PluginFeature *(*plugin_provides)(void);
-
gint ok;
-
- g_return_val_if_fail(filename != NULL, NULL);
- g_return_val_if_fail(error != NULL, NULL);
+ START_TIMING((filename?filename:"NULL plugin"));
+ cm_return_val_if_fail(filename != NULL, NULL);
+ cm_return_val_if_fail(error != NULL, NULL);
/* check duplicate plugin path name */
if (plugin_is_loaded(filename)) {
return NULL;
}
- if (strcmp(plugin_licence(), "GPL")
- && strncmp(plugin_licence(), "GPL-compatible", strlen("GPL-compatible"))) {
- *error = g_strdup(_("This module is not licenced under a GPL compatible licence."));
+ if (plugin_licence_check(plugin_licence()) != TRUE) {
+ *error = g_strdup(_("This module is not licensed under a GPL v3 or later compatible license."));
if (plugin->unloaded_hidden)
return NULL;
g_module_close(plugin->module);
plugin->unloaded_hidden = FALSE;
debug_print("Plugin %s (from file %s) loaded\n", plugin->name(), filename);
-
+ END_TIMING();
return plugin;
}
if ((pfile = prefs_read_open(rcpath)) == NULL ||
(prefs_set_block_label(pfile, block) < 0)) {
g_free(rcpath);
+ if (pfile)
+ prefs_file_close(pfile);
return;
}
g_free(block);
return new;
}
+Plugin *plugin_get_loaded_by_name(const gchar *name)
+{
+ Plugin *plugin = NULL;
+ GSList *new, *cur;
+ new = plugin_get_list();
+ for (cur = new; cur; cur = g_slist_next(cur)) {
+ plugin = (Plugin *)cur->data;
+ if (!g_ascii_strcasecmp(plugin->name(), name))
+ break;
+ else
+ plugin = NULL;
+ }
+ g_slist_free(new);
+ return plugin;
+}
+
GSList *plugin_get_unloaded_list(void)
{
return g_slist_copy(unloaded_plugins);