disco.c
changeset 8 859e715adfcd
parent 7 c9ae7744e2f7
child 9 ff475b333e44
equal deleted inserted replaced
7:c9ae7744e2f7 8:859e715adfcd
    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 #include "hooks.h"
    36 
    36 
    37 static GSList *disco_handlers = NULL;
    37 static GSList *reply_handlers = NULL;
    38 static guint   disco_cid      = 0;
    38 static guint   disco_cid      = 0;
    39 
    39 
    40 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)
    41 {
    41 {
    42 	int info_request = (int) udata;
    42 	int info_request = (int) udata;
    43 
    43 
    44 	disco_handlers = g_slist_remove (disco_handlers, handler);
    44 	reply_handlers = g_slist_remove (reply_handlers, handler);
    45 
    45 
    46 	switch (lm_message_get_sub_type (message)) {
    46 	switch (lm_message_get_sub_type (message)) {
    47 	case LM_MESSAGE_SUB_TYPE_RESULT:
    47 	case LM_MESSAGE_SUB_TYPE_RESULT:
    48 
    48 
    49 		{
    49 		{
   197 		}
   197 		}
   198 			// XXX send to all resources/current resource?
   198 			// XXX send to all resources/current resource?
   199 
   199 
   200 		handler = lm_message_handler_new (disco_handler, (gpointer) info, NULL);
   200 		handler = lm_message_handler_new (disco_handler, (gpointer) info, NULL);
   201 
   201 
       
   202 		reply_handlers = g_slist_append (reply_handlers, handler);
       
   203 
   202 		{ // create message
   204 		{ // create message
   203 			LmMessageNode *node;
   205 			LmMessageNode *node;
   204 
   206 
   205 			request = lm_message_new_with_sub_type (to ? to : CURRENT_JID, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET);
   207 			request = lm_message_new_with_sub_type (to ? to : CURRENT_JID, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET);
   206 			node    = lm_message_get_node (request);
   208 			node    = lm_message_get_node (request);
   225 {
   227 {
   226 	GSList *hel;
   228 	GSList *hel;
   227 
   229 
   228 	if (lconnection) { // XXX more checks?
   230 	if (lconnection) { // XXX more checks?
   229 		// let's hope, that after invalidation, lm will remove and free unreffed by us handler
   231 		// let's hope, that after invalidation, lm will remove and free unreffed by us handler
   230 		for (hel = disco_handlers; hel; hel = hel->next) {
   232 		for (hel = reply_handlers; hel; hel = hel->next) {
   231 			LmMessageHandler *handler = (LmMessageHandler *) hel->data;
   233 			LmMessageHandler *handler = (LmMessageHandler *) hel->data;
   232 			lm_message_handler_invalidate (handler);
   234 			lm_message_handler_invalidate (handler);
   233 		}
   235 		}
   234 	}
   236 	}
   235 
   237 
   236 	g_slist_free (disco_handlers);
   238 	g_slist_free (reply_handlers);
   237 	disco_handlers = NULL;
   239 	reply_handlers = NULL;
   238 }
   240 }
   239 
   241 
   240 // release handlers before reconnect
   242 // release handlers before reconnect
   241 static void disco_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
   243 static void disco_hh (guint32 hid, hk_arg_t *args, gpointer userdata)
   242 {
   244 {
   250 	}
   252 	}
   251 }
   253 }
   252 
   254 
   253 const gchar *g_module_check_init(GModule *module)
   255 const gchar *g_module_check_init(GModule *module)
   254 {
   256 {
   255 	disco_handlers = NULL;
   257 	reply_handlers = NULL;
   256 
   258 
   257 	// completion
   259 	// completion
   258 	disco_cid = compl_new_category ();
   260 	disco_cid = compl_new_category ();
   259 	if (disco_cid) {
   261 	if (disco_cid) {
   260 		compl_add_category_word (disco_cid, "info");
   262 		compl_add_category_word (disco_cid, "info");