soc.2009.transport: 98a386d0: Added XMPP Support

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Sat Jun 27 05:55:22 EDT 2009


-----------------------------------------------------------------
Revision: 98a386d03efd85806d937e5975ada78fe3bbad12
Ancestor: 38a0566dc2f65d492ba8decb664ee4d68b1369d8
Author: hanzz at soc.pidgin.im
Date: 2009-06-27T09:52:15
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/98a386d03efd85806d937e5975ada78fe3bbad12

Added files:
        protocols/xmpp.cpp protocols/xmpp.h
Modified files:
        CMakeLists.txt main.cpp

ChangeLog: 

Added XMPP Support

-------------- next part --------------
============================================================
--- protocols/xmpp.cpp	1532f2e61289f918799c5013cb0ba679b5cca6b7
+++ protocols/xmpp.cpp	1532f2e61289f918799c5013cb0ba679b5cca6b7
@@ -0,0 +1,82 @@
+/**
+ * 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 "xmpp.h"
+#include "../main.h"
+
+XMPPProtocol::XMPPProtocol(GlooxMessageHandler *main){
+	m_main = main;
+	m_transportFeatures.push_back("jabber:iq:register");
+	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/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");
+	m_buddyFeatures.push_back("http://jabber.org/protocol/chatstates");
+	m_buddyFeatures.push_back("http://jabber.org/protocol/commands");
+
+	m_buddyFeatures.push_back("http://jabber.org/protocol/si/profile/file-transfer");
+	m_buddyFeatures.push_back("http://jabber.org/protocol/bytestreams");
+	m_buddyFeatures.push_back("http://jabber.org/protocol/si");
+}
+	
+XMPPProtocol::~XMPPProtocol() {}
+
+std::string XMPPProtocol::replace(std::string &str, const char *string_to_replace, const char *new_string)
+{
+	// Find the first string to replace
+	int index = str.find(string_to_replace);
+	// while there is one
+	while(index != (int) std::string::npos)
+	{
+		// Replace it
+		str.replace(index, strlen(string_to_replace), new_string);
+		// Find the next one
+		index = str.find(string_to_replace, index + strlen(new_string));
+	}
+	return str;
+}
+
+std::string XMPPProtocol::prepareUserName(std::string &str){
+	str = replace(str," ","");
+	return str;
+}
+
+bool XMPPProtocol::isValidUsername(std::string &str){
+	// TODO: check valid email address
+	return true;
+}
+
+std::list<std::string> XMPPProtocol::transportFeatures(){
+	return m_transportFeatures;
+}
+
+std::list<std::string> XMPPProtocol::buddyFeatures(){
+	return m_buddyFeatures;
+}
+
+std::string XMPPProtocol::text(const std::string &key) {
+	if (key == "instructions")
+		return "Enter your Jabber ID and password:";
+	return "not defined";
+}
============================================================
--- protocols/xmpp.h	f02ca6d9a8d1fdfaf792615cd4bc7de1b2f736eb
+++ protocols/xmpp.h	f02ca6d9a8d1fdfaf792615cd4bc7de1b2f736eb
@@ -0,0 +1,53 @@
+/**
+ * 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_XMPP_PROTOCOL_H
+#define _HI_XMPP_PROTOCOL_H
+
+#include "abstractprotocol.h"
+
+class GlooxMessageHandler;
+
+class XMPPProtocol : AbstractProtocol
+{
+	public:
+		XMPPProtocol(GlooxMessageHandler *main);
+		~XMPPProtocol();
+		std::string gatewayIdentity() { return "jabber"; }
+		std::string protocol() { return "prpl-jabber"; }
+		bool isValidUsername(std::string &username);
+		std::string prepareUserName(std::string &username);
+		std::list<std::string> transportFeatures();
+		std::list<std::string> buddyFeatures();
+		std::string text(const std::string &key);
+		Tag *getVCardTag(User *user, GList *vcardEntries) { return NULL; }
+		bool isMUC(User *user, const std::string &jid) { return false; }
+		
+		std::string replace(std::string &str, const char *string_to_replace, const char *new_string);
+	
+	private:
+		GlooxMessageHandler *m_main;
+		std::list<std::string> m_transportFeatures;
+		std::list<std::string> m_buddyFeatures;
+	
+};
+
+#endif	
+	
\ No newline at end of file
============================================================
--- CMakeLists.txt	ed71cfac2085a29b4f45be9009f2aac690cabc0a
+++ CMakeLists.txt	9c21f6d33a8d1ded00417f5d57a4c8c18c0e8d4c
@@ -99,6 +99,7 @@
 	protocols/gg.cpp
 	protocols/msn.cpp
 	protocols/irc.cpp
+	protocols/xmpp.cpp
 )
 
 set(hiicq_MOC_HDRS
@@ -137,6 +138,7 @@
 	protocols/gg.h
 	protocols/msn.h
 	protocols/irc.h
+	protocols/xmpp.h
 )
 
 add_executable(hiicq ${hiicq_SRCS} ${lrelease_outputs})
============================================================
--- main.cpp	2692cc5d95ca9b9bed6acb24075bcc22c8a5a3a6
+++ main.cpp	d95e5e617cf799efea6ccaebb5f351b424250a11
@@ -34,6 +34,7 @@
 #include "protocols/gg.h"
 #include "protocols/msn.h"
 #include "protocols/irc.h"
+#include "protocols/xmpp.h"
 #include "blistsaving.h"
 #include "cmds.h"
 
@@ -706,6 +707,8 @@ void GlooxMessageHandler::loadProtocol()
 		m_protocol = (AbstractProtocol*) new MSNProtocol(this);
 	else if (configuration().protocol == "irc")
 		m_protocol = (AbstractProtocol*) new IRCProtocol(this);
+	else if (configuration().protocol == "xmpp")
+		m_protocol = (AbstractProtocol*) new XMPPProtocol(this);
 	if (!m_protocol->userSearchAction().empty()) {
 		m_searchHandler = new GlooxSearchHandler(this);
 		j->registerIqHandler(m_searchHandler, ExtSearch);


More information about the Commits mailing list