soc.2009.transport: e6715b83: Connect to IRC just when caps arrive. Fi...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu Jul 9 02:25:28 EDT 2009


-----------------------------------------------------------------
Revision: e6715b8397bbf5709be70510944ab8b8b6bc099f
Ancestor: df1bcd1abffc000060e72cbf51963d52a5e06116
Author: hanzz at soc.pidgin.im
Date: 2009-07-09T06:21:23
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/e6715b8397bbf5709be70510944ab8b8b6bc099f

Modified files:
        caps.cpp caps.h main.cpp user.cpp user.h

ChangeLog: 

Connect to IRC just when caps arrive. Fixed disconnecting from IRC server.

-------------- next part --------------
============================================================
--- caps.cpp	0107eb249451a3048b26f8c3d796099b433d4654
+++ caps.cpp	1dc3ad487ce8c19c492b198a28822cafcf262387
@@ -24,6 +24,7 @@
 #include "main.h"
 #include "sql.h"
 #include "usermanager.h"
+#include "protocols/abstractprotocol.h"
 
 GlooxDiscoHandler::GlooxDiscoHandler(GlooxMessageHandler *parent) : DiscoHandler(){
 	p=parent;
@@ -34,7 +35,7 @@ bool GlooxDiscoHandler::hasVersion(int n
 }
 
 bool GlooxDiscoHandler::hasVersion(int name){
-	std::map<int,std::string> ::iterator iter = versions.begin();
+	std::map<int,Version> ::iterator iter = versions.begin();
 	iter = versions.find(name);
 	if(iter != versions.end())
 		return true;
@@ -78,8 +79,16 @@ void GlooxDiscoHandler::handleDiscoInfo(
 			}
 		}
 	std::cout << "*** FEATURES ARRIVED: " << feature << "\n";
-	p->capsCache[versions[context]]=feature;
-	User *user = p->userManager()->getUserByJID(jid.bare());
+	p->capsCache[versions[context].version]=feature;
+	User *user;
+	JID j(versions[context].jid);
+	if (p->protocol()->isMUC(NULL, j.bare())) {
+		std::string server = j.username().substr(j.username().find("%") + 1, j.username().length() - j.username().find("%"));
+		user = p->userManager()->getUserByJID(jid.bare() + server);
+	}
+	else {
+		User *user = p->userManager()->getUserByJID(jid.bare());
+	}
 	if (user==NULL){
 		std::cout << "no user?! wtf...";
 	}
@@ -88,7 +97,7 @@ void GlooxDiscoHandler::handleDiscoInfo(
 			std::cout << "1" << "\n";
 			if (user->getResource(jid.resource()).capsVersion.empty()){
 				std::cout << "2" << "\n";
-				user->setResource(jid.resource(), -256, versions[context]);
+				user->setResource(jid.resource(), -256, versions[context].version);
 				if (user->readyForConnect()) {
 					std::cout << "3" << "\n";
 					user->connect();
============================================================
--- caps.h	74f862cf51540d0ddba195bcf6fe5a6a21153c79
+++ caps.h	2f5b88f42baa96d60f6db98d3a29f509f9db9c6d
@@ -35,6 +35,10 @@ using namespace gloox;
 
 using namespace gloox;
 
+struct Version {
+	std::string version;
+	std::string jid;
+};
 
 class GlooxDiscoHandler : public DiscoHandler
 {
@@ -50,7 +54,7 @@ public:
 	void handleDiscoError(const JID &jid, const Error *error, int context);
 	bool hasVersion(int i);
 	GlooxMessageHandler *p;
-	std::map<int,std::string> versions;
+	std::map<int,Version> versions;
 	int version;
 };
 
============================================================
--- main.cpp	e0f407e8249bf0ef194d20b688f32f902d5c25d4
+++ main.cpp	9a9276b0b0c7489c39317f35c3374c1fc28bcfc6
@@ -1152,7 +1152,8 @@ void GlooxMessageHandler::handlePresence
 				// ask for caps
 				std::string id = j->getID();
 				Log().Get(stanza.from().full()) << "asking for caps with ID: " << id;
-				m_discoHandler->versions[m_discoHandler->version]=c->findAttribute("ver");
+				m_discoHandler->versions[m_discoHandler->version].version=c->findAttribute("ver");
+				m_discoHandler->versions[m_discoHandler->version].jid=stanza.to().full();
 				std::string node;
 				node = c->findAttribute("node")+std::string("#")+c->findAttribute("ver");
 				j->disco()->getDiscoInfo(stanza.from(),node,m_discoHandler,m_discoHandler->version,id);
@@ -1161,7 +1162,8 @@ void GlooxMessageHandler::handlePresence
 			else {
 				std::string id = j->getID();
 				Log().Get(stanza.from().full()) << "asking for disco#info with ID: " << id;
-				m_discoHandler->versions[m_discoHandler->version]=stanza.from().full();
+				m_discoHandler->versions[m_discoHandler->version].version=stanza.from().full();
+				m_discoHandler->versions[m_discoHandler->version].jid=stanza.to().full();
 				j->disco()->getDiscoInfo(stanza.from(),"",m_discoHandler,m_discoHandler->version,id);
 				m_discoHandler->version++;
 			}
@@ -1169,7 +1171,8 @@ void GlooxMessageHandler::handlePresence
 		else {
 			std::string id = j->getID();
 			Log().Get(stanza.from().full()) << "asking for disco#info with ID: " << id;
-			m_discoHandler->versions[m_discoHandler->version]=stanza.from().full();
+			m_discoHandler->versions[m_discoHandler->version].version=stanza.from().full();
+			m_discoHandler->versions[m_discoHandler->version].jid=stanza.to().full();
 			j->disco()->getDiscoInfo(stanza.from(),"",m_discoHandler,m_discoHandler->version,id);
 			m_discoHandler->version++;
 		}
============================================================
--- user.cpp	778cf3e19c98e3208643e0f187da5760f118c008
+++ user.cpp	1166d5f5ea74bd5a98805d12f96327f2f748603d
@@ -71,7 +71,6 @@ User::User(GlooxMessageHandler *parent, 
 	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);
-	m_tempAccounts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 	PurpleValue *value;
 	
 	// check default settings
@@ -1126,24 +1125,26 @@ void User::receivedPresence(const Presen
 		if(stanza.presence() == Presence::Unavailable) {
 			// disconnect from legacy network if we are connected
 			std::map<std::string,Resource> ::iterator iter = m_resources.begin();
-			if ((m_connected==false && int(time(NULL))>int(m_connectionStart)+10) || m_connected==true){
-				iter = m_resources.find(stanza.from().resource());
-				if(iter != m_resources.end()){
-					m_resources.erase(stanza.from().resource());
-					for(std::map<std::string, Conversation>::iterator u = m_conversations.begin(); u != m_conversations.end() ; u++){
-						if ((*u).second.resource == stanza.from().resource()){
-							m_conversations[(*u).first].resource = "";
+			if (stanza.to().username() == "") {
+				if ((m_connected==false && int(time(NULL))>int(m_connectionStart)+10) || m_connected==true){
+					iter = m_resources.find(stanza.from().resource());
+					if(iter != m_resources.end()){
+						m_resources.erase(stanza.from().resource());
+						for(std::map<std::string, Conversation>::iterator u = m_conversations.begin(); u != m_conversations.end() ; u++){
+							if ((*u).second.resource == stanza.from().resource()){
+								m_conversations[(*u).first].resource = "";
+							}
 						}
 					}
 				}
 			}
 			if (m_connected){
-				if (m_resources.empty()){
+				if (m_resources.empty() || (p->protocol()->tempAccountsAllowed() && g_hash_table_size(m_mucs) == 0)){
 					Log().Get(m_jid) << "disconecting";
 					purple_account_disconnect(m_account);
+					p->userManager()->removeUserTimer(this);
 				}
-				else{
-
+				else {
 					iter = m_resources.begin();
 					m_resource=(*iter).first;
 				}
@@ -1303,7 +1304,6 @@ User::~User(){
 	m_conversations.clear();
 	m_authRequests.clear();
 	g_hash_table_destroy(m_mucs);
-	g_hash_table_destroy(m_tempAccounts);
 	g_hash_table_destroy(m_settings);
 }
 
============================================================
--- user.h	0c0847596a3083b310d20db37596fd764f0c6939
+++ user.h	ccc42d58043900956d3beb4b3695c875bb8c2b98
@@ -166,7 +166,6 @@ class User {
 	private:
 		std::string m_userKey;
 		PurpleAccount *m_account;	// PurpleAccount to which this user is connected
-		GHashTable *m_tempAccounts;	// temp accounts for MUC (need to have them because of connection to more network)
 		std::list <Tag *> m_autoConnectRooms;
 		guint m_syncTimer;			// timer used for syncing purple buddy list and roster
 		int m_subscribeLastCount;	// number of buddies which was in subscribeCache in previous iteration of m_syncTimer


More information about the Commits mailing list