soc.2009.transport: cc4367c4: First test of AdHoc commands for prpl ac...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Wed May 27 09:15:50 EDT 2009


-----------------------------------------------------------------
Revision: cc4367c49f9c7103ea481322e97bdc3f8575ceaa
Ancestor: c076559f9be33427654a3883a9b677eb070b6c66
Author: hanzz at soc.pidgin.im
Date: 2009-05-27T07:15:57
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/cc4367c49f9c7103ea481322e97bdc3f8575ceaa

Added files:
        adhochandler.cpp adhochandler.h adhocrepeater.cpp
        adhocrepeater.h
Modified files:
        CMakeLists.txt main.cpp main.h protocols/abstractprotocol.h
        protocols/facebook.cpp protocols/facebook.h
        protocols/icq.cpp protocols/icq.h

ChangeLog: 

First test of AdHoc commands for prpl action menu.

-------------- next part --------------
============================================================
--- adhochandler.cpp	ad626ad80b6666a32d8e445646257ff72f90ad38
+++ adhochandler.cpp	ad626ad80b6666a32d8e445646257ff72f90ad38
@@ -0,0 +1,113 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+ 
+ #include "adhochandler.h"
+ #include "usermanager.h"
+ 
+AdhocHandler::AdhocHandler(GlooxMessageHandler *m) {
+	main = m;
+	main->j->registerIqHandler( this, XMLNS_ADHOC_COMMANDS );
+	main->j->disco()->addFeature( XMLNS_ADHOC_COMMANDS );
+	main->j->disco()->registerNodeHandler( this, XMLNS_ADHOC_COMMANDS );
+	main->j->disco()->registerNodeHandler( this, std::string() );
+
+}
+
+AdhocHandler::~AdhocHandler() { }
+
+StringList AdhocHandler::handleDiscoNodeFeatures( const std::string& /*node*/ ) {
+	StringList features;
+	features.push_back( XMLNS_ADHOC_COMMANDS );
+	return features;
+}
+
+DiscoNodeItemList AdhocHandler::handleDiscoNodeItems( const std::string &from, const std::string &to, const std::string& node ) {
+	DiscoNodeItemList lst;
+	if (node.empty()) {
+		DiscoNodeItem item;
+		item.node = XMLNS_ADHOC_COMMANDS;
+		item.jid = main->jid();
+		item.name = "Ad-Hoc Commands";
+		lst.push_back( item );
+	}
+	else if (node == XMLNS_ADHOC_COMMANDS) {
+		if (to == main->jid()) {
+			User *user = main->userManager()->getUserByJID(from);
+			if (user) {
+				if (user->isConnected() && purple_account_get_connection(user->account())) {
+					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);
+
+						for (l = actions; l != NULL; l = l->next) {
+							if (l->data) {
+								action = (PurplePluginAction *) l->data;
+								DiscoNodeItem item;
+								item.node = (std::string) action->label;
+								item.jid = main->jid();
+								item.name = (std::string) action->label;
+								purple_plugin_action_free(action);
+								lst.push_back( item );
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	return lst;
+}
+
+StringMap AdhocHandler::handleDiscoNodeIdentities( const std::string& node, std::string& name ) {
+	name = (std::string) node;
+
+	StringMap ident;
+	if( node == XMLNS_ADHOC_COMMANDS )
+		ident["automation"] = "command-list";
+	else
+		ident["automation"] = "command-node";
+	return ident;
+}
+
+bool AdhocHandler::handleIq( Stanza *stanza ) {
+	return true;
+}
+
+bool AdhocHandler::handleIqID( Stanza *stanza, int context ) {
+	return true;
+}
+
+void AdhocHandler::handleDiscoInfoResult( Stanza *stanza, int context ) {
+	
+}
+
+void AdhocHandler::handleDiscoItemsResult( Stanza *stanza, int context ) {
+	
+}
+
+void AdhocHandler::handleDiscoError( Stanza *stanza, int context ) {
+	
+}
+
+
============================================================
--- adhochandler.h	f4b96fd3044807fa1af0f44ffb1a63247340fc53
+++ adhochandler.h	f4b96fd3044807fa1af0f44ffb1a63247340fc53
@@ -0,0 +1,51 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+ 
+#ifndef _HI_ADHOC_HANDLER_H
+#define _HI_ADHOC_HANDLER_H
+
+#include <string>
+#include "account.h"
+#include "user.h"
+#include "glib.h"
+
+class GlooxMessageHandler;
+
+class AdhocHandler : public DiscoNodeHandler, public DiscoHandler, public IqHandler
+{
+	public:
+		AdhocHandler(GlooxMessageHandler *m);
+		~AdhocHandler();
+		virtual StringList handleDiscoNodeFeatures( const std::string& node );
+		virtual StringMap handleDiscoNodeIdentities( const std::string& node, std::string& name );
+		virtual DiscoNodeItemList handleDiscoNodeItems( const std::string &from, const std::string &to, const std::string& node );
+		virtual bool handleIq( Stanza *stanza );
+		virtual bool handleIqID( Stanza *stanza, int context );
+		virtual void handleDiscoInfoResult( Stanza *stanza, int context );
+		virtual void handleDiscoItemsResult( Stanza *stanza, int context );
+		virtual void handleDiscoError( Stanza *stanza, int context );
+
+	private:
+		GlooxMessageHandler *main;
+	
+};
+
+#endif
+ 
\ No newline at end of file
============================================================
--- adhocrepeater.cpp	59b6e3e792c3fab3f7ab0e61083bf4325f02c31b
+++ adhocrepeater.cpp	59b6e3e792c3fab3f7ab0e61083bf4325f02c31b
@@ -0,0 +1,30 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+ 
+ #include "adhocrepeater.h"
+ 
+AdhocRepeater::AdhocRepeater(GlooxMessageHandler *m){
+	main = m;
+}
+
+AdhocRepeater::~AdhocRepeater(){
+
+}
+
============================================================
--- adhocrepeater.h	0aefa435fa4eaaaaed0fca9aaf68f24e35f3a304
+++ adhocrepeater.h	0aefa435fa4eaaaaed0fca9aaf68f24e35f3a304
@@ -0,0 +1,43 @@
+/**
+ * XMPP - libpurple transport
+ *
+ * Copyright (C) 2009, Jan Kaluza <hanzz at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+ 
+#ifndef _HI_ADHOC_REPEATER_H
+#define _HI_ADHOC_REPEATER_H
+
+#include <string>
+#include "account.h"
+#include "user.h"
+#include "glib.h"
+
+class GlooxMessageHandler;
+
+class AdhocRepeater
+{
+	public:
+		AdhocRepeater(GlooxMessageHandler *m);
+		~AdhocRepeater();
+	
+	private:
+		GlooxMessageHandler *main;
+	
+};
+
+#endif
+ 
\ No newline at end of file
============================================================
--- CMakeLists.txt	8d6000485868f9d47fb86e9d2345a3b011fbd7b7
+++ CMakeLists.txt	3c853a524803637ff27b19c0a7ba8602503f7a8f
@@ -78,6 +78,8 @@
 	geventloop.cpp
 	autoconnectloop.cpp
 	usermanager.cpp
+	adhochandler.cpp
+	adhocrepeater.cpp
 	protocols/icq.cpp
 	protocols/facebook.cpp
 )
@@ -102,6 +104,8 @@
 	geventloop.h
 	autoconnectloop.h
 	usermanager.h
+	adhocrepeater.h
+	adhochandler.h
 	protocols/abstractprotocol.h
 	protocols/icq.h
 	protocols/facebook.h
============================================================
--- main.cpp	417f0eae2062719610348e8f69a0496ebd2c25d6
+++ main.cpp	30569edd31ad6ea72359c459a7916c0d7844aff0
@@ -24,6 +24,8 @@
 #include "geventloop.h"
 #include "autoconnectloop.h"
 #include "usermanager.h"
+#include "adhochandler.h"
+#include "adhocrepeater.h"
 #include "protocols/abstractprotocol.h"
 #include "protocols/icq.h"
 #include "protocols/facebook.h"
@@ -460,6 +462,8 @@ GlooxMessageHandler::GlooxMessageHandler
  	m_discoInfoHandler=new GlooxDiscoInfoHandler(this);
  	j->registerIqHandler(m_discoInfoHandler,XMLNS_DISCO_INFO);
 	
+	m_adhoc = new AdhocHandler(this);
+	
 	ftManager = new FileTransferManager();
 	ft = new SIProfileFT(j, ftManager );
 	ftManager->setSIProfileFT(ft,this);
@@ -506,6 +510,23 @@ void GlooxMessageHandler::loadProtocol()
 		m_protocol = (AbstractProtocol*) new ICQProtocol(this);
 	else if (configuration().protocol == "facebook")
 		m_protocol = (AbstractProtocol*) new FacebookProtocol(this);
+
+	
+// 	PurplePlugin *plugin = purple_find_prpl(m_protocol->protocol().c_str());
+// 	if (plugin && PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
+// 		PurplePluginAction *action = NULL;
+// 		GList *actions, *l;
+// 
+// 		actions = PURPLE_PLUGIN_ACTIONS(plugin, gc);
+// 
+// 		for (l = actions; l != NULL; l = l->next) {
+// 			if (l->data) {
+// 				action = (PurplePluginAction *) l->data;
+// 				m_adhoc->registerAdhocCommandProvider(adhocProvider, (std::string) action->label ,(std::string) action->label);
+// 				purple_plugin_action_free(action);
+// 			}
+// 		}
+// 	}
 }
 
 void GlooxMessageHandler::onSessionCreateError (SessionCreateError error){
@@ -704,7 +725,7 @@ void GlooxMessageHandler::purpleFileRece
         if (*it == '\\' || *it == '&' || *it == '/' || *it == '?' || *it == '*' || *it == ':') {
             *it = '_';
         }
-    } 
+    }
 
 	purple_xfer_request_accepted(xfer, std::string(configuration().filetransferCache+"/"+remote_user+"-"+j->getID()+"-"+filename).c_str());
 	User *user = userManager()->getUserByAccount(purple_xfer_get_account(xfer));
============================================================
--- main.h	eaa8de36fbccbdd2acf5943611cc6b6061547ee6
+++ main.h	745c6c9e006fe45c5c41ecac7b5cd789ee148b9b
@@ -81,10 +81,13 @@ class GlooxGatewayHandler;
 class GlooxStatsHandler;
 class GlooxVCardHandler;
 class GlooxGatewayHandler;
+class GlooxAdhocHandler;
 class SQLClass;
 class FileTranferManager;
 class UserManager;
 class AbstractProtocol;
+class AdhocHandler;
+class AdhocRepeater;
 
 struct User;
 struct UserRow;
@@ -173,6 +176,7 @@ public:
 	SQLClass *sql() { return m_sql; }
 	GlooxVCardHandler *vcard() { return m_vcard; }
 	AbstractProtocol *protocol() { return m_protocol; }
+	AdhocRepeater *adhocRepeater() { return m_adhocRepeater; }
 	
 	FileTransferManager* ftManager;
 	SIProfileFT* ft;
@@ -204,6 +208,9 @@ private:
 	GlooxXPingHandler *m_xping;
 	GlooxStatsHandler *m_stats;
 	GlooxVCardHandler *m_vcard;
+// 	std::list <GlooxAdhocHandler *> m_adhoc_handlers;
+	AdhocRepeater *m_adhocRepeater;
+	AdhocHandler *m_adhoc;
 	
 	GIOChannel *connectIO;
 	
============================================================
--- protocols/abstractprotocol.h	a4abd233d5e5df60a25c5942a9e6a5a584d5ba59
+++ protocols/abstractprotocol.h	1f040c126cc65db67ecbb0f8c0a70b8be915f908
@@ -55,7 +55,7 @@ class AbstractProtocol
 		/*
 		 * Returns pregenerated text according to key
 		 */
-		virtual std::string text(std::string &key) = 0;
+		virtual std::string text(const std::string &key) = 0;
 };
 
 #endif
============================================================
--- protocols/facebook.cpp	a80c86a6c25c07de1ea72c4e538c34f750a5c32d
+++ protocols/facebook.cpp	5c180c4e96e36e228cf7b381a644b96d6bed9e60
@@ -28,6 +28,7 @@ FacebookProtocol::FacebookProtocol(Gloox
 	m_transportFeatures.push_back("http://jabber.org/protocol/caps");
 	m_transportFeatures.push_back("http://jabber.org/protocol/chatstates");
 	m_transportFeatures.push_back("http://jabber.org/protocol/activity+notify");
+	m_transportFeatures.push_back("http://jabber.org/protocol/commands");
 	
 	m_buddyFeatures.push_back("http://jabber.org/protocol/disco#info");
 	m_buddyFeatures.push_back("http://jabber.org/protocol/caps");
@@ -91,7 +92,7 @@ std::list<std::string> FacebookProtocol:
 	return m_buddyFeatures;
 }
 
-std::string FacebookProtocol::text(std::string &key) {
+std::string FacebookProtocol::text(const std::string &key) {
 	if (key == "instructions")
 		return "Enter your Facebook email and password:";
 	return "not defined";
============================================================
--- protocols/facebook.h	c6cf237a3751cf92e61b3d785339ee305196f1a1
+++ protocols/facebook.h	db5d0a4da098fb78fff4dbde2d1db2ebc90f597c
@@ -36,7 +36,7 @@ class FacebookProtocol : AbstractProtoco
 		std::string prepareUserName(std::string &username);
 		std::list<std::string> transportFeatures();
 		std::list<std::string> buddyFeatures();
-		std::string text(std::string &key);
+		std::string text(const std::string &key);
 		
 		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
 	
============================================================
--- protocols/icq.cpp	da0cd1d0e160e880a8bff2d808139e1dbaf9a307
+++ protocols/icq.cpp	a01d688223f2151170123c614b9991ebf899962f
@@ -27,6 +27,7 @@ ICQProtocol::ICQProtocol(GlooxMessageHan
 	m_transportFeatures.push_back("http://jabber.org/protocol/disco#info");
 	m_transportFeatures.push_back("http://jabber.org/protocol/caps");
 	m_transportFeatures.push_back("http://jabber.org/protocol/chatstates");
+	m_transportFeatures.push_back("http://jabber.org/protocol/commands");
 	
 	m_buddyFeatures.push_back("http://jabber.org/protocol/disco#info");
 	m_buddyFeatures.push_back("http://jabber.org/protocol/caps");
@@ -73,7 +74,7 @@ std::list<std::string> ICQProtocol::budd
 	return m_buddyFeatures;
 }
 
-std::string ICQProtocol::text(std::string &key) {
+std::string ICQProtocol::text(const std::string &key) {
 	if (key == "instructions")
 		return "Enter your UIN and password:";
 	return "not defined";
============================================================
--- protocols/icq.h	344cd6f756c3d67139bf4c679525d3b8f69cf76e
+++ protocols/icq.h	d6039d86545350beddf0bea3a6f561b7e46eeb53
@@ -36,7 +36,7 @@ class ICQProtocol : AbstractProtocol
 		std::string prepareUserName(std::string &username);
 		std::list<std::string> transportFeatures();
 		std::list<std::string> buddyFeatures();
-		std::string text(std::string &key);
+		std::string text(const std::string &key);
 		
 		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
 	


More information about the Commits mailing list