disco.c
changeset 39 ab9dad1e6d66
parent 37 92c8a28f133e
parent 34 1a62a570e66b
child 40 d1826ea1d01f
equal deleted inserted replaced
38:c398184bb752 39:ab9dad1e6d66
     1 
     1 
     2 /* Copyright 2009 Myhailo Danylenko
     2 /* Copyright 2009,2010 Myhailo Danylenko
     3  *
     3  *
     4  * Service discovery requests
     4  * Service discovery requests
     5  *
     5  *
     6  * This file is part of mcabber-disco
     6  * This file is part of mcabber-disco
     7  *
     7  *
    47 
    47 
    48 #define DESCRIPTION ( "Service discovery requests\nProvides command /disco" )
    48 #define DESCRIPTION ( "Service discovery requests\nProvides command /disco" )
    49 
    49 
    50 static module_info_t info_disco_experimental = {
    50 static module_info_t info_disco_experimental = {
    51 	.branch      = "experimental",
    51 	.branch      = "experimental",
    52 	.api         = 27,
    52 	.api         = 32,
    53 	.version     = PROJECT_VERSION,
    53 	.version     = PROJECT_VERSION,
    54 	.description = DESCRIPTION,
    54 	.description = DESCRIPTION,
    55 	.requires    = NULL,
    55 	.requires    = NULL,
    56 	.init        = disco_init,
    56 	.init        = disco_init,
    57 	.uninit      = disco_uninit,
    57 	.uninit      = disco_uninit,
    68 	.uninit      = disco_uninit,
    68 	.uninit      = disco_uninit,
    69 	.next        = &info_disco_experimental,
    69 	.next        = &info_disco_experimental,
    70 };
    70 };
    71 
    71 
    72 module_info_t info_disco = {
    72 module_info_t info_disco = {
    73 	.branch      = "0.10.0",
    73 	.branch      = "0.10.1",
    74 	.api         = 1,
    74 	.api         = 1,
    75 	.version     = PROJECT_VERSION,
    75 	.version     = PROJECT_VERSION,
    76 	.description = DESCRIPTION,
    76 	.description = DESCRIPTION,
    77 	.requires    = NULL,
    77 	.requires    = NULL,
    78 	.init        = disco_init,
    78 	.init        = disco_init,
   183 						identity -> reserved = NULL;
   183 						identity -> reserved = NULL;
   184 
   184 
   185 						identities = g_slist_append (identities, identity);
   185 						identities = g_slist_append (identities, identity);
   186 					} else if (!strcasecmp (node->name, "feature"))
   186 					} else if (!strcasecmp (node->name, "feature"))
   187 						features = g_slist_insert_sorted (features, (gpointer) lm_message_node_get_attribute (node, "var"), (GCompareFunc) g_strcmp0);
   187 						features = g_slist_insert_sorted (features, (gpointer) lm_message_node_get_attribute (node, "var"), (GCompareFunc) g_strcmp0);
   188 			
   188 
   189 			// call handler
   189 			// call handler
   190 			cb -> handler (identities, features, cb -> data);
   190 			cb -> handler (identities, features, cb -> data);
   191 
   191 
   192 			{ // free resources
   192 			{ // free resources
   193 				GSList *iel;
   193 				GSList *iel;
   261 						item -> jid  = lm_message_node_get_attribute (node, "jid");
   261 						item -> jid  = lm_message_node_get_attribute (node, "jid");
   262 						item -> node = lm_message_node_get_attribute (node, "node");
   262 						item -> node = lm_message_node_get_attribute (node, "node");
   263 
   263 
   264 						items = g_slist_append (items, item);
   264 						items = g_slist_append (items, item);
   265 					}
   265 					}
   266 			
   266 
   267 			// call handler
   267 			// call handler
   268 			cb -> handler (items, cb -> data);
   268 			cb -> handler (items, cb -> data);
   269 
   269 
   270 			{ // free resources
   270 			{ // free resources
   271 				GSList *iel;
   271 				GSList *iel;
   367 		if (dnode)
   367 		if (dnode)
   368 			lm_message_node_set_attribute (node, "node", dnode);
   368 			lm_message_node_set_attribute (node, "node", dnode);
   369 
   369 
   370 		{
   370 		{
   371 			disco_info_reply_handler_t *cb = g_new (disco_info_reply_handler_t, 1);
   371 			disco_info_reply_handler_t *cb = g_new (disco_info_reply_handler_t, 1);
   372 			
   372 
   373 			lhandler = lm_message_handler_new (disco_info_reply_handler, cb, disco_info_reply_handler_destroy_notify);
   373 			lhandler = lm_message_handler_new (disco_info_reply_handler, cb, disco_info_reply_handler_destroy_notify);
   374 
   374 
   375 			cb -> handler = handler;
   375 			cb -> handler = handler;
   376 			cb -> data    = userdata;
   376 			cb -> data    = userdata;
   377 			cb -> notify  = notify;
   377 			cb -> notify  = notify;
   416 		if (dnode)
   416 		if (dnode)
   417 			lm_message_node_set_attribute (node, "node", dnode);
   417 			lm_message_node_set_attribute (node, "node", dnode);
   418 
   418 
   419 		{
   419 		{
   420 			disco_items_reply_handler_t *cb       = g_new (disco_items_reply_handler_t, 1);
   420 			disco_items_reply_handler_t *cb       = g_new (disco_items_reply_handler_t, 1);
   421 			
   421 
   422 			lhandler = lm_message_handler_new (disco_items_reply_handler, cb, disco_items_reply_handler_destroy_notify);
   422 			lhandler = lm_message_handler_new (disco_items_reply_handler, cb, disco_items_reply_handler_destroy_notify);
   423 
   423 
   424 			cb -> handler = handler;
   424 			cb -> handler = handler;
   425 			cb -> data    = userdata;
   425 			cb -> data    = userdata;
   426 			cb -> notify  = notify;
   426 			cb -> notify  = notify;
   580 		scr_log_print (LPRINT_NORMAL, "Unknown subcomand.");
   580 		scr_log_print (LPRINT_NORMAL, "Unknown subcomand.");
   581 
   581 
   582 	if (info != -1) {
   582 	if (info != -1) {
   583 		char *to    = NULL;
   583 		char *to    = NULL;
   584 		char *dnode = NULL;
   584 		char *dnode = NULL;
   585 		
   585 
   586 		if (args[0] && args[1]) {
   586 		if (args[0] && args[1]) {
   587 			char *p = args[1];
   587 			char *p = args[1];
   588 
   588 
   589 			if (*p == '.') {
   589 			if (*p == '.') {
   590 				if (*(p + 1) == JID_RESOURCE_SEPARATOR) {
   590 				if (*(p + 1) == JID_RESOURCE_SEPARATOR) {
   598 				to = to_utf8 (p);
   598 				to = to_utf8 (p);
   599 
   599 
   600 			if (args[2])
   600 			if (args[2])
   601 				dnode = to_utf8 (args[2]);
   601 				dnode = to_utf8 (args[2]);
   602 		}
   602 		}
   603 			// XXX send to all resources/current resource?
   603 
       
   604 		if (!to) {
       
   605 			// Use currently selected item, if possible
       
   606 			if (current_buddy) {
       
   607 				gpointer bud = BUDDATA(current_buddy);
       
   608 				if (bud) {
       
   609 					guint type = buddy_gettype (bud);
       
   610 					if (type != ROSTER_TYPE_GROUP && type != ROSTER_TYPE_SPECIAL)
       
   611 						to = g_strdup (buddy_getjid (bud)); // XXX memleak!
       
   612 				}
       
   613 			}
       
   614 		}
       
   615 
       
   616 		if (!to) {
       
   617 			scr_log_print (LPRINT_NORMAL, "Invalid disco target.");
       
   618 			free_arg_lst (args);
       
   619 			return;
       
   620 		}
       
   621 
       
   622 		// XXX send to all resources/current resource?
   604 
   623 
   605 		{
   624 		{
   606 			disco_handler_t *cb = g_new (disco_handler_t, 1);
   625 			disco_handler_t *cb = g_new (disco_handler_t, 1);
   607 
   626 
   608 			cb -> jid  = to ? to : g_strdup (CURRENT_JID);
   627 			cb -> jid  = to;
   609 			cb -> node = dnode;
   628 			cb -> node = dnode;
   610 
   629 
   611 			if (info)
   630 			if (info)
   612 				disco_info_request (cb -> jid, cb -> node, disco_info_handler, cb, disco_handler_destroy_notify);
   631 				disco_info_request (cb -> jid, cb -> node, disco_info_handler, cb, disco_handler_destroy_notify);
   613 			else
   632 			else
   681 #endif
   700 #endif
   682 
   701 
   683 	// completion
   702 	// completion
   684 	if (disco_cid)
   703 	if (disco_cid)
   685 		compl_del_category (disco_cid);
   704 		compl_del_category (disco_cid);
   686 	
   705 
   687 	// hook handler
   706 	// hook handler
   688 	hk_del_handler (HOOK_PRE_DISCONNECT, disco_hid);
   707 	hk_del_handler (HOOK_PRE_DISCONNECT, disco_hid);
   689 
   708 
   690 	// unregister handlers
   709 	// unregister handlers
   691 	disco_unregister_handlers ();
   710 	disco_unregister_handlers ();