disco.c
changeset 4 b18eee368baa
parent 3 c409300aa352
child 5 6411dbdd32be
equal deleted inserted replaced
3:c409300aa352 4:b18eee368baa
    30 #include "xmpp.h"
    30 #include "xmpp.h"
    31 #include "compl.h"
    31 #include "compl.h"
    32 #include "xmpp_defines.h"
    32 #include "xmpp_defines.h"
    33 #include "screen.h"
    33 #include "screen.h"
    34 #include "hbuf.h"
    34 #include "hbuf.h"
       
    35 #include "hooks.h"
    35 
    36 
    36 static GSList *disco_handlers = NULL;
    37 static GSList *disco_handlers = NULL;
    37 static guint   disco_cid      = 0;
    38 static guint   disco_cid      = 0;
    38 
    39 
    39 static LmHandlerResult disco_handler (LmMessageHandler *handler, LmConnection *connection, LmMessage *message, gpointer udata)
    40 static LmHandlerResult disco_handler (LmMessageHandler *handler, LmConnection *connection, LmMessage *message, gpointer udata)
   216 		g_free (dnode);
   217 		g_free (dnode);
   217 		g_free (to);
   218 		g_free (to);
   218 	}
   219 	}
   219 }
   220 }
   220 
   221 
       
   222 static void disco_free_handlers (void)
       
   223 {
       
   224 	GSList *hel;
       
   225 
       
   226 	if (lconnection) { // XXX more checks?
       
   227 		// let's hope, that after invalidation, lm will remove and free unreffed by us handler
       
   228 		for (hel = disco_handlers; hel; hel = hel->next) {
       
   229 			LmMessageHandler *handler = (LmMessageHandler *) hel->data;
       
   230 			lm_message_handler_invalidate (handler);
       
   231 		}
       
   232 	}
       
   233 
       
   234 	g_slist_free (disco_handlers);
       
   235 	disco_handlers = NULL;
       
   236 }
       
   237 
       
   238 // release handlers before reconnect
       
   239 static void disco_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
       
   240 {
       
   241 		hk_arg_t *arg = args;
       
   242 
       
   243 		for (arg = args; arg->name; arg++) {
       
   244 				if (!strcmp (arg->name, "hook-pre-disconnect")) {
       
   245 						disco_free_handlers ();
       
   246 						return;
       
   247 				}
       
   248 		}
       
   249 }
       
   250 
   221 const gchar *g_module_check_init(GModule *module)
   251 const gchar *g_module_check_init(GModule *module)
   222 {
   252 {
   223 	disco_handlers = NULL;
   253 	disco_handlers = NULL;
   224 
   254 
   225 	// completion
   255 	// completion
   235 	return NULL;
   265 	return NULL;
   236 }
   266 }
   237 
   267 
   238 void g_module_unload(GModule *module)
   268 void g_module_unload(GModule *module)
   239 {
   269 {
   240 	GSList *hel;
   270 	// release handlers
   241 
   271 	disco_free_handlers ();
   242 	// let's hope, that after invalidation, lm will remove and free unreffed by us handler
       
   243 	for (hel = disco_handlers; hel; hel = hel->next) {
       
   244 		LmMessageHandler *handler = (LmMessageHandler *) hel->data;
       
   245 		lm_message_handler_invalidate (handler);
       
   246 	}
       
   247 
       
   248 	// free list
       
   249 	g_slist_free (disco_handlers);
       
   250 	disco_handlers = NULL;
       
   251 
   272 
   252 	// command
   273 	// command
   253 	cmd_del ("disco");
   274 	cmd_del ("disco");
   254 
   275 
   255 	// completion
   276 	// completion