commit 413f51eb16bd7cbd4a7c96dc8b7914eaf47d41bd
parent 8c070cf623d0af34150f989efd6bfa475482ac06
Author: Ricardo Mones <mones@claws-mail.org>
Date: Thu, 21 Jul 2011 19:32:12 +0000
2011-07-21 [mones] 3.7.9cvs37
* src/common/plugin.c
* src/common/plugin.h
Make licences allowed for plugins more explicit and also
accept dual (or more) licences when properly formatted.
Doesn't require any change on current plugins.
Diffstat:
5 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,11 @@
+2011-07-21 [mones] 3.7.9cvs37
+
+ * src/common/plugin.c
+ * src/common/plugin.h
+ Make licences allowed for plugins more explicit and also
+ accept dual (or more) licences when properly formatted.
+ Doesn't require any change on current plugins.
+
2011-07-18 [mones] 3.7.9cvs36
* manual/advanced.xml
diff --git a/PATCHSETS b/PATCHSETS
@@ -4188,3 +4188,4 @@
( cvs diff -u -r 1.1.2.23 -r 1.1.2.24 src/edittags.c; ) > 3.7.9cvs34.patchset
( cvs diff -u -r 1.1.2.4 -r 1.1.2.5 claws-mail.desktop; ) > 3.7.9cvs35.patchset
( cvs diff -u -r 1.1.2.56 -r 1.1.2.57 manual/advanced.xml; cvs diff -u -r 1.1.2.17 -r 1.1.2.18 manual/glossary.xml; cvs diff -u -r 1.1.2.18 -r 1.1.2.19 manual/es/advanced.xml; cvs diff -u -r 1.1.2.5 -r 1.1.2.6 manual/es/glossary.xml; ) > 3.7.9cvs36.patchset
+( cvs diff -u -r 1.13.2.42 -r 1.13.2.43 src/common/plugin.c; cvs diff -u -r 1.5.2.16 -r 1.5.2.17 src/common/plugin.h; ) > 3.7.9cvs37.patchset
diff --git a/configure.ac b/configure.ac
@@ -12,7 +12,7 @@ MINOR_VERSION=7
MICRO_VERSION=9
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=36
+EXTRA_VERSION=37
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
diff --git a/src/common/plugin.c b/src/common/plugin.c
@@ -71,6 +71,22 @@ const gchar *plugin_feature_names[] =
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
*/
@@ -299,6 +315,39 @@ static gchar *plugin_check_features(struct PluginFeature *features) {
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
*
@@ -365,9 +414,8 @@ init_plugin:
return NULL;
}
- if (strcmp(plugin_licence(), "GPL2+") && strncmp(plugin_licence(), "GPL3", strlen("GPL3"))
- && strncmp(plugin_licence(), "GPL2+-compatible", strlen("GPL2+-compatible"))) {
- *error = g_strdup(_("This module is not licensed under a GPL v2 or later compatible license."));
+ 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);
diff --git a/src/common/plugin.h b/src/common/plugin.h
@@ -49,7 +49,7 @@ const gchar *plugin_desc (void);
const gchar *plugin_version (void);
struct PluginFeature *plugin_provides (void);
-/* Functions by the sylpheed plugin system */
+/* Functions by the Claws Mail plugin system */
Plugin *plugin_load (const gchar *filename,
gchar **error);
void plugin_unload (Plugin *plugin);