--- a/disco.c Sun Nov 01 05:35:01 2009 +0200
+++ b/disco.c Sun Nov 01 06:20:33 2009 +0200
@@ -32,6 +32,7 @@
#include "xmpp_defines.h"
#include "screen.h"
#include "hbuf.h"
+#include "hooks.h"
static GSList *disco_handlers = NULL;
static guint disco_cid = 0;
@@ -218,6 +219,35 @@
}
}
+static void disco_free_handlers (void)
+{
+ GSList *hel;
+
+ if (lconnection) { // XXX more checks?
+ // let's hope, that after invalidation, lm will remove and free unreffed by us handler
+ for (hel = disco_handlers; hel; hel = hel->next) {
+ LmMessageHandler *handler = (LmMessageHandler *) hel->data;
+ lm_message_handler_invalidate (handler);
+ }
+ }
+
+ g_slist_free (disco_handlers);
+ disco_handlers = NULL;
+}
+
+// release handlers before reconnect
+static void disco_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
+{
+ hk_arg_t *arg = args;
+
+ for (arg = args; arg->name; arg++) {
+ if (!strcmp (arg->name, "hook-pre-disconnect")) {
+ disco_free_handlers ();
+ return;
+ }
+ }
+}
+
const gchar *g_module_check_init(GModule *module)
{
disco_handlers = NULL;
@@ -237,17 +267,8 @@
void g_module_unload(GModule *module)
{
- GSList *hel;
-
- // let's hope, that after invalidation, lm will remove and free unreffed by us handler
- for (hel = disco_handlers; hel; hel = hel->next) {
- LmMessageHandler *handler = (LmMessageHandler *) hel->data;
- lm_message_handler_invalidate (handler);
- }
-
- // free list
- g_slist_free (disco_handlers);
- disco_handlers = NULL;
+ // release handlers
+ disco_free_handlers ();
// command
cmd_del ("disco");