soc.2009.transport: 7e3dc10a: Initial support for MUC

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Tue Jun 9 04:25:24 EDT 2009


-----------------------------------------------------------------
Revision: 7e3dc10a10a797b97bfb091331c5bed134aa8a2c
Ancestor: 92e44b7650ae7647ced8030526e3879263c66890
Author: hanzz at soc.pidgin.im
Date: 2009-06-09T08:24:08
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/7e3dc10a10a797b97bfb091331c5bed134aa8a2c

Modified files:
        CMakeLists.txt protocols/abstractprotocol.h
        protocols/facebook.h protocols/gg.h protocols/icq.h
        protocols/msn.h user.cpp user.h

ChangeLog: 

Initial support for MUC

-------------- next part --------------
============================================================
--- CMakeLists.txt	b9e02ee4e08479cf3199baf70003bd19b124575e
+++ CMakeLists.txt	25c09d1f5f9d96fa52616c8b94ba534ba432f472
@@ -89,10 +89,12 @@
 	adhochandler.cpp
 	adhocrepeater.cpp
 	localization.cpp
+	muchandler.cpp
 	protocols/icq.cpp
 	protocols/facebook.cpp
 	protocols/gg.cpp
 	protocols/msn.cpp
+	protocols/irc.cpp
 )
 
 set(hiicq_MOC_HDRS
@@ -118,11 +120,13 @@
 	adhocrepeater.h
 	adhochandler.h
 	localization.h
+	muchandler.h
 	protocols/abstractprotocol.h
 	protocols/icq.h
 	protocols/facebook.h
 	protocols/gg.h
 	protocols/msn.h
+	protocols/irc.h
 )
 
 add_executable(hiicq ${hiicq_SRCS} ${lrelease_outputs})
============================================================
--- protocols/abstractprotocol.h	a465917ba088118515e655568c2df0af6d0a820a
+++ protocols/abstractprotocol.h	ed090b52d257490fab1eef28f81a6dbcb047ac8e
@@ -65,6 +65,10 @@ class AbstractProtocol
 		 * Returns VCard Tag*
 		 */
 		virtual Tag *getVCardTag(User *user, GList *vcardEntries) = 0;
+		/*
+		 * Returns true if this jid is jid of MUC
+		 */
+		virtual bool isMUC(User *user, const std::string &jid) = 0 ;
 };
 
 #endif
============================================================
--- protocols/facebook.h	033c22b317a94dacfd7b649680cb1208e7b62a23
+++ protocols/facebook.h	5c75c40ab867d47637f8fbe9a929a781221dc7fb
@@ -39,6 +39,7 @@ class FacebookProtocol : AbstractProtoco
 		std::list<std::string> buddyFeatures();
 		std::string text(const std::string &key);
 		Tag *getVCardTag(User *user, GList *vcardEntries);
+		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);
 	
============================================================
--- protocols/gg.h	e291b5a76382c26cb6a086e2192c64a129f68eb6
+++ protocols/gg.h	e7a5ecb510141a43f85151e2c6610647d3e8caa7
@@ -38,6 +38,7 @@ class GGProtocol : AbstractProtocol
 		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);
 	
============================================================
--- protocols/icq.h	f0a24f0e9b3480870d210c503a356b6613410f38
+++ protocols/icq.h	ca57e4291a6294fd4ad3b65025e6ca946d789a6d
@@ -38,6 +38,7 @@ class ICQProtocol : AbstractProtocol
 		std::list<std::string> buddyFeatures();
 		std::string text(const std::string &key);
 		Tag *getVCardTag(User *user, GList *vcardEntries);
+		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);
 	
============================================================
--- protocols/msn.h	976f3ce4eb6c3988f7c1debeabb255c36e481ea5
+++ protocols/msn.h	6c9be9c7b9990b624ae909b84c196fb463b891ff
@@ -38,6 +38,7 @@ class MSNProtocol : AbstractProtocol
 		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);
 	
============================================================
--- user.cpp	4e2fd35380c4829ff740d3d7bd45a71fd668076d
+++ user.cpp	d174f5b8c7df35f9cd2fa7ca822f59b4dcc3186b
@@ -24,6 +24,7 @@
 #include "protocols/abstractprotocol.h"
 #include "usermanager.h"
 #include "gloox/chatstate.h"
+#include "muchandler.h"
 
 /*
  * Called when contact list has been received from legacy network.
@@ -52,6 +53,7 @@ User::User(GlooxMessageHandler *parent, 
 	m_reconnectCount = 0;
 	m_lang = NULL;
 	this->features = 6; // TODO: I can't be hardcoded
+	m_mucs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 }
 
 bool User::syncCallback() {
@@ -812,6 +814,26 @@ void User::receivedPresence(const Presen
  */
 void User::receivedPresence(const Presence &stanza){
 	// we're connected
+
+	Tag *stanzaTag = stanza.tag();
+
+	if (stanza.to().username()!="" && stanzaTag->hasChild ("x", "xmlns", "http://jabber.org/protocol/muc")) {
+		MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().bare().c_str());
+		if (muc) {
+			Tag * ret = muc->handlePresence(stanza);
+			if (ret)
+				p->j->send(ret);
+		}
+		else if (p->protocol()->isMUC(this, stanza.to().bare())) {
+			MUCHandler *muc = new MUCHandler(this, stanza.to().full());
+			g_hash_table_replace(m_mucs, g_strdup(stanza.to().bare().c_str()), muc);
+			Tag * ret = muc->handlePresence(stanza);
+			if (ret)
+				p->j->send(ret);
+		}
+	}
+	delete stanzaTag;
+
 	if (m_connected){
 	
 		// respond to probe presence
============================================================
--- user.h	c82e8bca2ae3d93136f61c136159bf605771bb61
+++ user.h	f18bdd5b164071c004b69a8fec7791be8160366b
@@ -151,7 +151,8 @@ class User {
 		std::string m_resource;		// active resource
 		std::string m_capsVersion;	// caps version of client which connected as first (TODO: this should be changed with active resource)
 		const char *m_lang;			// xml:lang
-		time_t m_connectionStart;		// connection start timestamp
+		time_t m_connectionStart;	// connection start timestamp
+		GHashTable *m_mucs;			// MUCs
 		std::map<std::string,RosterRow> m_roster;	// jabber roster of this user
 		std::map<std::string,int> m_resources;	// list of all resources which are connected to the transport
 		std::map<std::string,authRequest> m_authRequests;	// list of authorization requests (holds callbacks and user data)


More information about the Commits mailing list