2007-06-21 [colin] 2.9.2cvs72
authorColin Leroy <colin@colino.net>
Thu, 21 Jun 2007 17:04:01 +0000 (17:04 +0000)
committerColin Leroy <colin@colino.net>
Thu, 21 Jun 2007 17:04:01 +0000 (17:04 +0000)
* src/common/plugin.c
* src/common/plugin.h
Change plugin API to know whether it's safe to
unload plugins or whether we should just hide
them
* src/plugins/bogofilter/bogofilter.c
* src/plugins/clamav/clamav_plugin.c
* src/plugins/demo/demo.c
* src/plugins/dillo_viewer/dillo_viewer.c
* src/plugins/pgpcore/plugin.c
* src/plugins/pgpinline/plugin.c
* src/plugins/pgpmime/plugin.c
* src/plugins/spamassassin/spamassassin.c
* src/plugins/trayicon/trayicon.c
Update API

14 files changed:
ChangeLog
PATCHSETS
configure.ac
src/common/plugin.c
src/common/plugin.h
src/plugins/bogofilter/bogofilter.c
src/plugins/clamav/clamav_plugin.c
src/plugins/demo/demo.c
src/plugins/dillo_viewer/dillo_viewer.c
src/plugins/pgpcore/plugin.c
src/plugins/pgpinline/plugin.c
src/plugins/pgpmime/plugin.c
src/plugins/spamassassin/spamassassin.c
src/plugins/trayicon/trayicon.c

index 9cd723c395f12756b373d71e4840e411de1d82cf..a2dc773a44b6af9f5038e5a660c31135405a84a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2007-06-21 [colin]     2.9.2cvs72
+
+       * src/common/plugin.c
+       * src/common/plugin.h
+               Change plugin API to know whether it's safe to 
+               unload plugins or whether we should just hide
+               them
+       * src/plugins/bogofilter/bogofilter.c
+       * src/plugins/clamav/clamav_plugin.c
+       * src/plugins/demo/demo.c
+       * src/plugins/dillo_viewer/dillo_viewer.c
+       * src/plugins/pgpcore/plugin.c
+       * src/plugins/pgpinline/plugin.c
+       * src/plugins/pgpmime/plugin.c
+       * src/plugins/spamassassin/spamassassin.c
+       * src/plugins/trayicon/trayicon.c
+               Update API
+
 2007-06-19 [colin]     2.9.2cvs71
 
        * src/compose.c
index 4e9fb66131fc783ad500ed7a872eaab350dfc5b9..1e15112267d885ea68ad2aa11404a47452d1745e 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.654.2.2699 -r 1.654.2.2700 configure.ac;  ) > 2.9.2cvs69.patchset
 ( cvs diff -u -r 1.14.2.14 -r 1.14.2.15 src/importldif.c;  ) > 2.9.2cvs70.patchset
 ( cvs diff -u -r 1.382.2.390 -r 1.382.2.391 src/compose.c;  cvs diff -u -r 1.94.2.135 -r 1.94.2.136 src/messageview.c;  ) > 2.9.2cvs71.patchset
+( cvs diff -u -r 1.13.2.27 -r 1.13.2.28 src/common/plugin.c;  cvs diff -u -r 1.5.2.10 -r 1.5.2.11 src/common/plugin.h;  cvs diff -u -r 1.1.2.30 -r 1.1.2.31 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.13.2.32 -r 1.13.2.33 src/plugins/clamav/clamav_plugin.c;  cvs diff -u -r 1.13.2.14 -r 1.13.2.15 src/plugins/demo/demo.c;  cvs diff -u -r 1.12.2.20 -r 1.12.2.21 src/plugins/dillo_viewer/dillo_viewer.c;  cvs diff -u -r 1.1.2.17 -r 1.1.2.18 src/plugins/pgpcore/plugin.c;  cvs diff -u -r 1.1.2.16 -r 1.1.2.17 src/plugins/pgpinline/plugin.c;  cvs diff -u -r 1.1.2.25 -r 1.1.2.26 src/plugins/pgpmime/plugin.c;  cvs diff -u -r 1.18.2.53 -r 1.18.2.54 src/plugins/spamassassin/spamassassin.c;  cvs diff -u -r 1.14.2.53 -r 1.14.2.54 src/plugins/trayicon/trayicon.c;  ) > 2.9.2cvs72.patchset
index 7cd107d85252cb9ae35fe686bf593cbb6d911dca..90d0af0628197436c2ab00da165de8d3c09a4eeb 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=71
+EXTRA_VERSION=72
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 9b5925e59c1cf24ada595beb541335db12bfe863..bff74aa0d6a3c607ac2bcb6ef1142bd596b401f0 100644 (file)
@@ -49,6 +49,7 @@ struct _Plugin
        
        GSList *rdeps;
        gchar *error;
+       gboolean unloaded_hidden;
 };
 
 const gchar *plugin_feature_names[] =
@@ -116,11 +117,17 @@ void plugin_save_list(void)
                for (plugin_cur = plugins; plugin_cur != NULL; plugin_cur = g_slist_next(plugin_cur)) {
                        plugin = (Plugin *) plugin_cur->data;
                        
+                       if (plugin->unloaded_hidden)
+                               continue;
+
                        if (!strcmp(plugin->type(), type_cur->data))
                                fprintf(pfile->fp, "%s\n", plugin->filename);
                }
                for (plugin_cur = unloaded_plugins; plugin_cur != NULL; plugin_cur = g_slist_next(plugin_cur)) {
                        plugin = (Plugin *) plugin_cur->data;
+
+                       if (plugin->unloaded_hidden)
+                               continue;
                        
                        if (!strcmp(plugin->type(), type_cur->data))
                                fprintf(pfile->fp, "%s\n", plugin->filename);
@@ -252,6 +259,8 @@ static gchar *plugin_check_features(struct PluginFeature *features) {
        for(; cur; cur = cur->next) {
                Plugin *p = (Plugin *)cur->data;
                struct PluginFeature *cur_features = p->provides();
+               if (p->unloaded_hidden)
+                       continue;
                for (j = 0; cur_features[j].type != PLUGIN_NOTHING; j++) {
                        for (i = 0; features[i].type != PLUGIN_NOTHING; i++) {
                                if (cur_features[j].type == features[i].type &&
@@ -292,8 +301,14 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
 
        /* check duplicate plugin path name */
        if (plugin_is_loaded(filename)) {
-               *error = g_strdup(_("Plugin already loaded"));
-               return NULL;            
+               plugin = plugin_get_by_filename(filename);
+               if (plugin->unloaded_hidden) {
+                       /* reshow it */
+                       goto init_plugin;
+               } else {
+                       *error = g_strdup(_("Plugin already loaded"));
+                       return NULL;            
+               }
        }                              
        
        plugin_remove_from_unloaded_list(filename);
@@ -314,6 +329,7 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
                return NULL;
        }
 
+init_plugin:
        if (!g_module_symbol(plugin->module, "plugin_name", &plugin_name) ||
            !g_module_symbol(plugin->module, "plugin_desc", &plugin_desc) ||
            !g_module_symbol(plugin->module, "plugin_version", &plugin_version) ||
@@ -322,6 +338,8 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
            !g_module_symbol(plugin->module, "plugin_provides", (gpointer)&plugin_provides) ||
            !g_module_symbol(plugin->module, "plugin_init", (gpointer)&plugin_init)) {
                *error = g_strdup(g_module_error());
+               if (plugin->unloaded_hidden)
+                       return NULL;
                g_module_close(plugin->module);
                g_free(plugin);
                return NULL;
@@ -330,6 +348,8 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
        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->unloaded_hidden)
+                       return NULL;
                g_module_close(plugin->module);
                g_free(plugin);
                return NULL;
@@ -337,12 +357,16 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
 
        if (!strcmp(plugin_type(), "GTK")) {
                *error = g_strdup(_("This module is for Claws Mail GTK1."));
+               if (plugin->unloaded_hidden)
+                       return NULL;
                g_module_close(plugin->module);
                g_free(plugin);
                return NULL;
        }
 
        if ((*error = plugin_check_features(plugin_provides())) != NULL) {
+               if (plugin->unloaded_hidden)
+                       return NULL;
                g_module_close(plugin->module);
                g_free(plugin);
                return NULL;
@@ -355,6 +379,7 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
        plugin->provides = plugin_provides;
        plugin->filename = g_strdup(filename);
        plugin->error = NULL;
+
        if ((ok = plugin_init(error)) < 0) {
                if (*error)
                        plugin->error = g_strdup(*error);
@@ -362,7 +387,9 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
                return NULL;
        }
 
-       plugins = g_slist_append(plugins, plugin);
+       if (!plugin->unloaded_hidden)
+               plugins = g_slist_append(plugins, plugin);
+       plugin->unloaded_hidden = FALSE;
 
        debug_print("Plugin %s (from file %s) loaded\n", plugin->name(), filename);
 
@@ -371,28 +398,37 @@ Plugin *plugin_load(const gchar *filename, gchar **error)
 
 void plugin_unload(Plugin *plugin)
 {
-       void (*plugin_done) (void);
+       gboolean (*plugin_done) (void);
+       gboolean can_unload = TRUE;
 
        plugin_unload_rdeps(plugin);
 
+       if (plugin->unloaded_hidden)
+               return;
+
        if (plugin->error) {
                plugin_remove_from_unloaded_list(plugin->filename);
                return;
        }
        if (g_module_symbol(plugin->module, "plugin_done", (gpointer) &plugin_done)) {
-               plugin_done();
+               can_unload = plugin_done();
        }
 
+       if (can_unload) {
 #ifdef HAVE_VALGRIND
-       if (!RUNNING_ON_VALGRIND) {
-               g_module_close(plugin->module);
-       }
+               if (!RUNNING_ON_VALGRIND) {
+                       g_module_close(plugin->module);
+               }
 #else
-       g_module_close(plugin->module);
+               g_module_close(plugin->module);
 #endif
-       plugins = g_slist_remove(plugins, plugin);
-       g_free(plugin->filename);
-       g_free(plugin);
+               plugins = g_slist_remove(plugins, plugin);
+               g_free(plugin->filename);
+               g_free(plugin);
+       } else {
+               plugin->unloaded_hidden = TRUE;
+       }
+
 }
 
 void plugin_load_all(const gchar *type)
@@ -502,7 +538,15 @@ void plugin_load_standard_plugins (void)
 
 GSList *plugin_get_list(void)
 {
-       return g_slist_copy(plugins);
+       GSList *new = NULL;
+       GSList *cur = plugins;
+       for (; cur; cur = cur->next) {
+               Plugin *p = (Plugin *)cur->data;
+               if (!p->unloaded_hidden)
+                       new = g_slist_prepend(new, p);
+       }
+       new = g_slist_reverse(new);
+       return new;
 }
 
 GSList *plugin_get_unloaded_list(void)
index 9c308b453fc428c84d705d1ca7aa9111437583dd..55af9a2f8d0b988826fc86424d18180f871efdbc 100644 (file)
@@ -42,7 +42,7 @@ struct PluginFeature {
 
 /* Functions to implement by the plugin */
 gint plugin_init               (gchar          **error);
-void plugin_done               (void);
+gboolean plugin_done           (void);
 const gchar *plugin_name       (void);
 const gchar *plugin_desc       (void);
 const gchar *plugin_version    (void);
index e044ac405aa641d24e0bf9b37ee9c62d69874c4c..d43a0058a4bf5bbf8918dded61754375a6d4d5e2 100644 (file)
@@ -883,7 +883,7 @@ gint plugin_init(gchar **error)
 
        hook_id = -1;
 
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 9, 3, 86),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -937,7 +937,7 @@ FolderItem *bogofilter_get_spam_folder(MsgInfo *msginfo)
        return item;
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        if (hook_id != -1) {
                bogofilter_unregister_hook();
@@ -950,6 +950,7 @@ void plugin_done(void)
        procmsg_unregister_spam_learner(bogofilter_learn);
        procmsg_spam_set_folder(NULL, NULL);
        debug_print("Bogofilter plugin unloaded\n");
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index a4c71e0e304aa07c0db8447a0b76a69272dfae40..623487c336003446a10d682f9ed2e23e5bb5cb94 100644 (file)
@@ -229,7 +229,7 @@ gint plugin_init(gchar **error)
        unsigned int no;
 #endif
 
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 9, 3, 86),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -279,7 +279,7 @@ gint plugin_init(gchar **error)
        
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
        g_free(config.clamav_save_folder);
@@ -291,6 +291,7 @@ void plugin_done(void)
        clamav_gtk_done();
 
        debug_print("ClamAV plugin unloaded\n");
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index 5972fea9c65329dd8da5abeef19e94f95f2ea6ec..fa5e9b91feabc2233b44bcd2228e9a7e4bb40a5b 100644 (file)
@@ -43,7 +43,7 @@ static guint hook_id;
 
 gint plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 8, 11, 39),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -58,11 +58,12 @@ gint plugin_init(gchar **error)
        return 0;
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        hooks_unregister_hook(LOG_APPEND_TEXT_HOOKLIST, hook_id);
 
        printf("Demo plugin unloaded\n");
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index 4880d2fcbdedff46232e2ed7cf170505a3b668e5..d452a1d74233cb97d540bc76561891b73b4a9097 100644 (file)
@@ -167,7 +167,7 @@ static MimeViewerFactory dillo_viewer_factory =
 
 gint plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 9, 3, 86),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -178,11 +178,12 @@ gint plugin_init(gchar **error)
        return 0;       
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        mimeview_unregister_viewer_factory(&dillo_viewer_factory);
 
         dillo_prefs_done();
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index ccd1a350b52940b3986c52d238b0257cc2f40936..9ef930f84aa1d8f4e3b85da4369d7a11cd7a81b1 100644 (file)
@@ -36,7 +36,7 @@
 
 gint plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2, 1, 0, 1),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -47,11 +47,12 @@ gint plugin_init(gchar **error)
        return 0;       
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        pgp_viewer_done();
        prefs_gpg_done();
        sgpgme_done();
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index c764311cd1dbbb886ec10c636f9163e03b8f152b..9615b258046635399931349c132a981025f8cde3 100644 (file)
@@ -34,7 +34,7 @@
 
 gint plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2, 1, 0, 1),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -43,9 +43,10 @@ gint plugin_init(gchar **error)
        return 0;       
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        pgpinline_done();
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index e1e48cf6949a79050ec4ecd49f263dd97e09bff6..6ec46e82054bbef8b6d4ac0a0d8929379353cad8 100644 (file)
@@ -34,7 +34,7 @@
 
 gint plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2, 1, 0, 1),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -43,9 +43,10 @@ gint plugin_init(gchar **error)
        return 0;       
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        pgpmime_done();
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index 034f32e8ab9e202f49feb6c421675a39e5ba0f2d..97839c3ac14a513653c279811eabb48fa6ab1bd6 100644 (file)
@@ -504,7 +504,7 @@ gint plugin_init(gchar **error)
 
        hook_id = -1;
 
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 9, 3, 86),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -538,7 +538,7 @@ gint plugin_init(gchar **error)
        
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        if (hook_id != -1) {
                spamassassin_unregister_hook();
@@ -549,6 +549,7 @@ void plugin_done(void)
        procmsg_unregister_spam_learner(spamassassin_learn);
        procmsg_spam_set_folder(NULL, NULL);
        debug_print("SpamAssassin plugin unloaded\n");
+       return TRUE;
 }
 
 const gchar *plugin_name(void)
index da974279b2efe125f4c3f9662547a0d732ab640b..a9e29eb4e6cc63c338311b8f7e59730deced5755 100644 (file)
@@ -395,7 +395,7 @@ static void create_trayicon()
 
 int plugin_init(gchar **error)
 {
-       if (!check_plugin_version(MAKE_NUMERIC_VERSION(0, 9, 3, 86),
+       if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
                                VERSION_NUMERIC, PLUGIN_NAME, error))
                return -1;
 
@@ -451,7 +451,7 @@ int plugin_init(gchar **error)
        return 0;
 }
 
-void plugin_done(void)
+gboolean plugin_done(void)
 {
        trayicon_prefs_done();
 
@@ -463,7 +463,7 @@ void plugin_done(void)
        hooks_unregister_hook(MAIN_WINDOW_GOT_ICONIFIED, iconified_hook_id);
 
        if (claws_is_exiting())
-               return;
+               return TRUE;
 
        g_signal_handler_disconnect(G_OBJECT(trayicon), destroy_signal_id);
        
@@ -472,6 +472,7 @@ void plugin_done(void)
        while (gtk_events_pending()) {
                gtk_main_iteration();
        }
+       return TRUE;
 }
 
 const gchar *plugin_name(void)