2011-07-21 [mones] 3.7.9cvs37
authorRicardo Mones <mones@claws-mail.org>
Thu, 21 Jul 2011 19:32:12 +0000 (19:32 +0000)
committerRicardo Mones <mones@claws-mail.org>
Thu, 21 Jul 2011 19:32:12 +0000 (19:32 +0000)
* 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.

ChangeLog
PATCHSETS
configure.ac
src/common/plugin.c
src/common/plugin.h

index 98b40c557e32e4b57ee85a7b85cef0257eb548cb..c436c31fcfb9c17e7f2f36bca9bc00305ef903a4 100644 (file)
--- 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
index 79a471ce183396ac332afa72d77172d1fcdc3c8b..c7197c215b9952c51504b675ab4de64b158ee425 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( 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
index 4a7e78d9bccfb71794b045536b98068bedb89b60..4a7cd383aeab50f1781e7a8c6d0e791bf6229c44 100644 (file)
@@ -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=
 
index 411dc240932487e32c1e991d39446c7c6a6d064b..328d2dba31babb3492d45dcad129468ccc0146f0 100644 (file)
@@ -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);
index 409864606fc79ac7557f1091bdaf7435698c655e..5d5767882b91e6645ced5cba59fd4002f8b1cb34 100644 (file)
@@ -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);