disco.c
changeset 39 ab9dad1e6d66
parent 37 92c8a28f133e
parent 34 1a62a570e66b
child 40 d1826ea1d01f
--- a/disco.c	Sun Apr 11 22:37:12 2010 +0300
+++ b/disco.c	Mon Mar 07 19:41:44 2011 +0100
@@ -1,5 +1,5 @@
 
-/* Copyright 2009 Myhailo Danylenko
+/* Copyright 2009,2010 Myhailo Danylenko
  *
  * Service discovery requests
  *
@@ -49,7 +49,7 @@
 
 static module_info_t info_disco_experimental = {
 	.branch      = "experimental",
-	.api         = 27,
+	.api         = 32,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
 	.requires    = NULL,
@@ -70,7 +70,7 @@
 };
 
 module_info_t info_disco = {
-	.branch      = "0.10.0",
+	.branch      = "0.10.1",
 	.api         = 1,
 	.version     = PROJECT_VERSION,
 	.description = DESCRIPTION,
@@ -185,7 +185,7 @@
 						identities = g_slist_append (identities, identity);
 					} else if (!strcasecmp (node->name, "feature"))
 						features = g_slist_insert_sorted (features, (gpointer) lm_message_node_get_attribute (node, "var"), (GCompareFunc) g_strcmp0);
-			
+
 			// call handler
 			cb -> handler (identities, features, cb -> data);
 
@@ -263,7 +263,7 @@
 
 						items = g_slist_append (items, item);
 					}
-			
+
 			// call handler
 			cb -> handler (items, cb -> data);
 
@@ -369,7 +369,7 @@
 
 		{
 			disco_info_reply_handler_t *cb = g_new (disco_info_reply_handler_t, 1);
-			
+
 			lhandler = lm_message_handler_new (disco_info_reply_handler, cb, disco_info_reply_handler_destroy_notify);
 
 			cb -> handler = handler;
@@ -418,7 +418,7 @@
 
 		{
 			disco_items_reply_handler_t *cb       = g_new (disco_items_reply_handler_t, 1);
-			
+
 			lhandler = lm_message_handler_new (disco_items_reply_handler, cb, disco_items_reply_handler_destroy_notify);
 
 			cb -> handler = handler;
@@ -582,7 +582,7 @@
 	if (info != -1) {
 		char *to    = NULL;
 		char *dnode = NULL;
-		
+
 		if (args[0] && args[1]) {
 			char *p = args[1];
 
@@ -600,12 +600,31 @@
 			if (args[2])
 				dnode = to_utf8 (args[2]);
 		}
-			// XXX send to all resources/current resource?
+
+		if (!to) {
+			// Use currently selected item, if possible
+			if (current_buddy) {
+				gpointer bud = BUDDATA(current_buddy);
+				if (bud) {
+					guint type = buddy_gettype (bud);
+					if (type != ROSTER_TYPE_GROUP && type != ROSTER_TYPE_SPECIAL)
+						to = g_strdup (buddy_getjid (bud)); // XXX memleak!
+				}
+			}
+		}
+
+		if (!to) {
+			scr_log_print (LPRINT_NORMAL, "Invalid disco target.");
+			free_arg_lst (args);
+			return;
+		}
+
+		// XXX send to all resources/current resource?
 
 		{
 			disco_handler_t *cb = g_new (disco_handler_t, 1);
 
-			cb -> jid  = to ? to : g_strdup (CURRENT_JID);
+			cb -> jid  = to;
 			cb -> node = dnode;
 
 			if (info)
@@ -683,7 +702,7 @@
 	// completion
 	if (disco_cid)
 		compl_del_category (disco_cid);
-	
+
 	// hook handler
 	hk_del_handler (HOOK_PRE_DISCONNECT, disco_hid);