soc.2009.transport: 76da5feb: Execute PurpleMenuAction from node_menu ...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu May 28 07:41:29 EDT 2009


-----------------------------------------------------------------
Revision: 76da5feb3d5626935771e186b2153c0327ae5c1e
Ancestor: df416a48d8c5517febc7e2a88764f52545a36125
Author: hanzz at soc.pidgin.im
Date: 2009-05-28T11:31:05
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/76da5feb3d5626935771e186b2153c0327ae5c1e

Modified files:
        adhochandler.cpp

ChangeLog: 

Execute PurpleMenuAction from node_menu through Adhoc

-------------- next part --------------
============================================================
--- adhochandler.cpp	767d9a535e6d6567a449e393030e5149bf3d2700
+++ adhochandler.cpp	f487be801da13789e79eced10a1713e2c43d4e41
@@ -126,41 +126,71 @@ bool AdhocHandler::handleIq( Stanza *sta
 	const std::string& node = tag->findAttribute( "node" );
 	if (node.empty()) return false;
 
-	if (to == main->jid()) {
-		User *user = main->userManager()->getUserByJID(from);
-		if (user) {
-			if (user->isConnected() && purple_account_get_connection(user->account())) {
-				if (hasSession(stanza->from().full())) {
-					return m_sessions[stanza->from().full()]->handleIq(stanza);
-				}
-				else {
-					PurpleConnection *gc = purple_account_get_connection(user->account());
-					PurplePlugin *plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? gc->prpl : NULL;
-					if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
-						PurplePluginAction *action = NULL;
-						GList *actions, *l;
+	User *user = main->userManager()->getUserByJID(from);
+	if (user) {
+		if (user->isConnected() && purple_account_get_connection(user->account())) {
+			if (hasSession(stanza->from().full())) {
+				return m_sessions[stanza->from().full()]->handleIq(stanza);
+			}
+			else if (to == main->jid()) {
+				PurpleConnection *gc = purple_account_get_connection(user->account());
+				PurplePlugin *plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? gc->prpl : NULL;
+				if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
+					PurplePluginAction *action = NULL;
+					GList *actions, *l;
 
-						actions = PURPLE_PLUGIN_ACTIONS(plugin, gc);
+					actions = PURPLE_PLUGIN_ACTIONS(plugin, gc);
 
-						for (l = actions; l != NULL; l = l->next) {
-							if (l->data) {
-								action = (PurplePluginAction *) l->data;
-								if (node == (std::string) action->label) {
-									AdhocData data;
-									data.id = stanza->id();
-									data.from = stanza->from().full();
-									data.node = node;
-									user->setAdhocData(data);
-									action->plugin = plugin;
-									action->context = gc;
-									action->callback(action);
-								}
-								purple_plugin_action_free(action);
+					for (l = actions; l != NULL; l = l->next) {
+						if (l->data) {
+							action = (PurplePluginAction *) l->data;
+							if (node == (std::string) action->label) {
+								AdhocData data;
+								data.id = stanza->id();
+								data.from = stanza->from().full();
+								data.node = node;
+								user->setAdhocData(data);
+								action->plugin = plugin;
+								action->context = gc;
+								action->callback(action);
 							}
+							purple_plugin_action_free(action);
 						}
 					}
 				}
 			}
+			else {
+				GList *l, *ll;
+				PurpleConnection *gc = purple_account_get_connection(user->account());
+				PurplePlugin *plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? gc->prpl : NULL;
+				PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
+
+				if(!prpl_info || !prpl_info->blist_node_menu)
+					return true;
+				PurpleBuddy *buddy = purple_find_buddy(user->account(), JID(to).username().c_str());
+
+				for(l = ll = prpl_info->blist_node_menu((PurpleBlistNode*)buddy); l; l = l->next) {
+					PurpleMenuAction *action = (PurpleMenuAction *) l->data;
+					if (node == (std::string) action->label) {
+						void (*callback)(PurpleBlistNode *, gpointer);
+						callback = (void (*)(PurpleBlistNode *, gpointer))action->callback;
+						if (callback)
+							callback((PurpleBlistNode*)buddy, action->data);
+
+						Stanza *response = Stanza::createIqStanza(stanza->from().full(), stanza->id(), StanzaIqResult, "", 0);
+						response->addAttribute("from", main->jid());
+
+						Tag *c = new Tag("command");
+						c->addAttribute("xmlns","http://jabber.org/protocol/commands");
+						c->addAttribute("sessionid",tag->findAttribute("sessionid"));
+						c->addAttribute("node","configuration");
+						c->addAttribute("status","completed");
+						main->j->send(response);
+
+					}
+					purple_menu_action_free(action);
+				}
+			}
 		}
 	}
 	return true;


More information about the Commits mailing list