disco.c
changeset 51 30b410060a65
parent 49 a9c3cc3626ca
parent 43 751d06b00558
child 52 ab752dd11b45
equal deleted inserted replaced
50:d7a61b1745f4 51:30b410060a65
     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_dev = {
    50 static module_info_t info_disco_dev = {
    51 	.branch      = "dev",
    51 	.branch      = "dev",
    52 	.api         = 13,
    52 	.api         = 20,
    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,
    58 	.next        = NULL,
    58 	.next        = NULL,
    59 };
    59 };
    60 
    60 
    61 module_info_t info_disco = {
    61 module_info_t info_disco_0_10_0 = {
    62 	.branch      = "0.10.0",
    62 	.branch      = "0.10.0",
    63 	.api         = 1,
    63 	.api         = 1,
    64 	.version     = PROJECT_VERSION,
    64 	.version     = PROJECT_VERSION,
    65 	.description = DESCRIPTION,
    65 	.description = DESCRIPTION,
    66 	.requires    = NULL,
    66 	.requires    = NULL,
    67 	.init        = disco_init,
    67 	.init        = disco_init,
    68 	.uninit      = disco_uninit,
    68 	.uninit      = disco_uninit,
    69 	.next        = &info_disco_dev,
    69 	.next        = &info_disco_dev,
    70 };
    70 };
    71 
    71 
       
    72 module_info_t info_disco = {
       
    73 	.branch      = "0.10.1",
       
    74 	.api         = 1,
       
    75 	.version     = PROJECT_VERSION,
       
    76 	.description = DESCRIPTION,
       
    77 	.requires    = NULL,
       
    78 	.init        = disco_init,
       
    79 	.uninit      = disco_uninit,
       
    80 	.next        = &info_disco_0_10_0,
       
    81 };
       
    82 
    72 //
    83 //
    73 // private types
    84 // private types
    74 //
    85 //
    75 
    86 
    76 // lm message handler userdata
    87 // lm message handler userdata
   172 						identity -> reserved = NULL;
   183 						identity -> reserved = NULL;
   173 
   184 
   174 						identities = g_slist_append (identities, identity);
   185 						identities = g_slist_append (identities, identity);
   175 					} else if (!strcasecmp (node->name, "feature"))
   186 					} else if (!strcasecmp (node->name, "feature"))
   176 						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);
   177 			
   188 
   178 			// call handler
   189 			// call handler
   179 			cb -> handler (identities, features, cb -> data);
   190 			cb -> handler (identities, features, cb -> data);
   180 
   191 
   181 			{ // free resources
   192 			{ // free resources
   182 				GSList *iel;
   193 				GSList *iel;
   250 						item -> jid  = lm_message_node_get_attribute (node, "jid");
   261 						item -> jid  = lm_message_node_get_attribute (node, "jid");
   251 						item -> node = lm_message_node_get_attribute (node, "node");
   262 						item -> node = lm_message_node_get_attribute (node, "node");
   252 
   263 
   253 						items = g_slist_append (items, item);
   264 						items = g_slist_append (items, item);
   254 					}
   265 					}
   255 			
   266 
   256 			// call handler
   267 			// call handler
   257 			cb -> handler (items, cb -> data);
   268 			cb -> handler (items, cb -> data);
   258 
   269 
   259 			{ // free resources
   270 			{ // free resources
   260 				GSList *iel;
   271 				GSList *iel;
   356 		if (dnode)
   367 		if (dnode)
   357 			lm_message_node_set_attribute (node, "node", dnode);
   368 			lm_message_node_set_attribute (node, "node", dnode);
   358 
   369 
   359 		{
   370 		{
   360 			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);
   361 			
   372 
   362 			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);
   363 
   374 
   364 			cb -> handler = handler;
   375 			cb -> handler = handler;
   365 			cb -> data    = userdata;
   376 			cb -> data    = userdata;
   366 			cb -> notify  = notify;
   377 			cb -> notify  = notify;
   405 		if (dnode)
   416 		if (dnode)
   406 			lm_message_node_set_attribute (node, "node", dnode);
   417 			lm_message_node_set_attribute (node, "node", dnode);
   407 
   418 
   408 		{
   419 		{
   409 			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);
   410 			
   421 
   411 			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);
   412 
   423 
   413 			cb -> handler = handler;
   424 			cb -> handler = handler;
   414 			cb -> data    = userdata;
   425 			cb -> data    = userdata;
   415 			cb -> notify  = notify;
   426 			cb -> notify  = notify;
   569 		scr_log_print (LPRINT_NORMAL, "Unknown subcomand.");
   580 		scr_log_print (LPRINT_NORMAL, "Unknown subcomand.");
   570 
   581 
   571 	if (info != -1) {
   582 	if (info != -1) {
   572 		char *to    = NULL;
   583 		char *to    = NULL;
   573 		char *dnode = NULL;
   584 		char *dnode = NULL;
   574 		
   585 
   575 		if (args[0] && args[1]) {
   586 		if (args[0] && args[1]) {
   576 			char *p = args[1];
   587 			char *p = args[1];
   577 
   588 
   578 			if (*p == '.') {
   589 			if (*p == '.') {
   579 				if (*(p + 1) == JID_RESOURCE_SEPARATOR) {
   590 				if (*(p + 1) == JID_RESOURCE_SEPARATOR) {
   587 				to = to_utf8 (p);
   598 				to = to_utf8 (p);
   588 
   599 
   589 			if (args[2])
   600 			if (args[2])
   590 				dnode = to_utf8 (args[2]);
   601 				dnode = to_utf8 (args[2]);
   591 		}
   602 		}
   592 			// 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?
   593 
   623 
   594 		{
   624 		{
   595 			disco_handler_t *cb = g_new (disco_handler_t, 1);
   625 			disco_handler_t *cb = g_new (disco_handler_t, 1);
   596 
   626 
   597 			cb -> jid  = to ? to : g_strdup (CURRENT_JID);
   627 			cb -> jid  = to;
   598 			cb -> node = dnode;
   628 			cb -> node = dnode;
   599 
   629 
   600 			if (info)
   630 			if (info)
   601 				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);
   602 			else
   632 			else
   670 #endif
   700 #endif
   671 
   701 
   672 	// completion
   702 	// completion
   673 	if (disco_cid)
   703 	if (disco_cid)
   674 		compl_del_category (disco_cid);
   704 		compl_del_category (disco_cid);
   675 	
   705 
   676 	// hook handler
   706 	// hook handler
   677 	hk_del_handler (HOOK_PRE_DISCONNECT, disco_hid);
   707 	hk_del_handler (HOOK_PRE_DISCONNECT, disco_hid);
   678 
   708 
   679 	// unregister handlers
   709 	// unregister handlers
   680 	disco_unregister_handlers ();
   710 	disco_unregister_handlers ();