soc.2009.transport: 9b79ee59: Move some IRC related stuff to IRCProtoc...
hanzz at soc.pidgin.im
hanzz at soc.pidgin.im
Tue Jul 14 13:05:49 EDT 2009
-----------------------------------------------------------------
Revision: 9b79ee59b6c40b373c609d487979d63fd22307f0
Ancestor: c2027ef2f1afa212548ba9cfd30f85a1cca0d297
Author: hanzz at soc.pidgin.im
Date: 2009-07-14T09:12:17
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/9b79ee59b6c40b373c609d487979d63fd22307f0
Modified files:
protocols/abstractprotocol.h protocols/irc.cpp
protocols/irc.h user.cpp user.h
ChangeLog:
Move some IRC related stuff to IRCProtocol and create some protocols signals to allow protocol classes to catch them :)
-------------- next part --------------
============================================================
--- protocols/abstractprotocol.h 9df065a02dc9dc29df749a7e80a3d9fe51d60069
+++ protocols/abstractprotocol.h 512950c30f7c96c9a2880229609edea5cef0b152
@@ -96,6 +96,14 @@ class AbstractProtocol
* Called when user gets connected
*/
virtual void onConnected(User *user) { }
+ /*
+ * Called when user class is getting destroyed
+ */
+ virtual void onDestroy(User *user) { }
+ /*
+ * Presence Received. Returns true if the presence was handled.
+ */
+ virtual bool onPresenceReceived(User *user, const Presence &stanza) { return false; }
};
#endif
============================================================
--- protocols/irc.cpp c88d74f16c37e1318e0ef2ac7f309f584011aef0
+++ protocols/irc.cpp f95d3d8e4f56dced0ce40fe439c16ee9ed7997c6
@@ -20,6 +20,7 @@
#include "irc.h"
#include "../main.h"
+#include "../muchandler.h"
IRCProtocol::IRCProtocol(GlooxMessageHandler *main){
m_main = main;
@@ -68,14 +69,62 @@ void IRCProtocol::onUserCreated(User *us
purple_value_set_string(value, "");
g_hash_table_replace(user->settings(), g_strdup("nickserv"), value);
}
+ user->setProtocolData(new IRCProtocolData());
}
void IRCProtocol::onConnected(User *user) {
+ IRCProtocolData *data = (IRCProtocolData *) user->protocolData();
std::string nickserv(purple_value_get_string(user->getSetting("nickserv")));
if (!nickserv.empty()) {
Message msg(Message::Chat, JID("NickServ at server.cz"), "identify " + nickserv);
msg.setFrom(user->jid());
user->receivedMessage(msg);
}
+
+ for (std::list <Tag*>::iterator it = data->autoConnectRooms.begin(); it != data->autoConnectRooms.end() ; it++ ) {
+ Presence stanza((*it));
+ MUCHandler *muc = new MUCHandler(user, stanza.to().bare(), stanza.from().full());
+ g_hash_table_replace(user->mucs(), g_strdup(stanza.to().username().c_str()), muc);
+ Tag * ret = muc->handlePresence(stanza);
+ if (ret)
+ m_main->j->send(ret);
+ delete (*it);
+ };
}
+bool IRCProtocol::onPresenceReceived(User *user, const Presence &stanza) {
+ if (stanza.to().username()!="") {
+ IRCProtocolData *data = (IRCProtocolData *) user->protocolData();
+ GHashTable *m_mucs = user->mucs();
+ MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().username().c_str());
+ if (muc) {
+ Tag * ret = muc->handlePresence(stanza);
+ if (ret)
+ m_main->j->send(ret);
+ if (stanza.presence() == Presence::Unavailable) {
+ g_hash_table_remove(m_mucs, stanza.to().username().c_str());
+ user->conversations().erase(stanza.to().username());
+ delete muc;
+ }
+ }
+ else if (isMUC(user, stanza.to().bare()) && stanza.presence() != Presence::Unavailable) {
+ if (user->isConnected()) {
+ MUCHandler *muc = new MUCHandler(user, stanza.to().bare(), stanza.from().full());
+ g_hash_table_replace(m_mucs, g_strdup(stanza.to().username().c_str()), muc);
+ Tag * ret = muc->handlePresence(stanza);
+ if (ret)
+ m_main->j->send(ret);
+ }
+ else {
+ data->autoConnectRooms.push_back(stanza.tag());
+ }
+ }
+ }
+ return false;
+}
+
+
+void IRCProtocol::onDestroy(User *user) {
+ delete user->protocolData();
+}
+
============================================================
--- protocols/irc.h c9bac8219ffc068ba28eac96322789d31980ce31
+++ protocols/irc.h a2ced6847e70ad6a2ec2027265bb5aae18c48c5b
@@ -26,6 +26,14 @@ extern Localization localization;
class GlooxMessageHandler;
extern Localization localization;
+class IRCProtocolData {
+ public:
+ IRCProtocolData() {}
+ ~IRCProtocolData() {}
+
+ std::list <Tag *> autoConnectRooms;
+};
+
class IRCProtocol : AbstractProtocol
{
public:
@@ -46,6 +54,8 @@ class IRCProtocol : AbstractProtocol
void onUserCreated(User *user);
void onConnected(User *user);
+ void onDestroy(User *user);
+ bool onPresenceReceived(User *user, const Presence &stanza);
private:
GlooxMessageHandler *m_main;
============================================================
--- user.cpp 9eea50cb678ec74a140b43bf212b9d04872c9d74
+++ user.cpp c9338d2e560bd740805757911c09b82be3f05dde
@@ -923,17 +923,6 @@ void User::connected() {
m_connected = true;
m_reconnectCount = 0;
p->protocol()->onConnected(this);
- // TODO: move me to IRCProtocol
- for (std::list <Tag*>::iterator it = m_autoConnectRooms.begin(); it != m_autoConnectRooms.end() ; it++ ) {
- Presence stanza((*it));
- MUCHandler *muc = new MUCHandler(this, stanza.to().bare(), stanza.from().full());
- g_hash_table_replace(m_mucs, g_strdup(stanza.to().username().c_str()), muc);
- Tag * ret = muc->handlePresence(stanza);
- if (ret)
- p->j->send(ret);
- delete (*it);
- };
-
}
void User::receivedSubscription(const Subscription &subscription) {
@@ -1064,31 +1053,8 @@ void User::receivedPresence(const Presen
*/
void User::receivedPresence(const Presence &stanza){
- if (stanza.to().username()!="") {
- MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().username().c_str());
- if (muc) {
- Tag * ret = muc->handlePresence(stanza);
- if (ret)
- p->j->send(ret);
- if (stanza.presence() == Presence::Unavailable) {
- g_hash_table_remove(m_mucs, stanza.to().username().c_str());
- m_conversations.erase(stanza.to().username());
- delete muc;
- }
- }
- else if (p->protocol()->isMUC(this, stanza.to().bare()) && stanza.presence() != Presence::Unavailable) {
- if (m_connected) {
- MUCHandler *muc = new MUCHandler(this, stanza.to().bare(), stanza.from().full());
- g_hash_table_replace(m_mucs, g_strdup(stanza.to().username().c_str()), muc);
- Tag * ret = muc->handlePresence(stanza);
- if (ret)
- p->j->send(ret);
- }
- else {
- m_autoConnectRooms.push_back(stanza.tag());
- }
- }
- }
+ if (p->protocol()->onPresenceReceived(this, stanza))
+ return;
if (m_connected){
@@ -1313,6 +1279,8 @@ User::~User(){
m_authRequests.clear();
g_hash_table_destroy(m_mucs);
g_hash_table_destroy(m_settings);
+
+ p->protocol()->onDestroy(this);
}
============================================================
--- user.h ccc42d58043900956d3beb4b3695c875bb8c2b98
+++ user.h 9b3bb92926f4d285cadb3dad89ed59f0701509a4
@@ -162,11 +162,15 @@ class User {
GlooxMessageHandler *p;
std::string & userKey() { return m_userKey; }
+ void setProtocolData(void *protocolData) { m_protocolData = protocolData; }
+ void *protocolData() { return m_protocolData; }
+ GHashTable *mucs() { return m_mucs; }
+ std::map<std::string,Conversation> conversations() { return m_conversations; }
private:
std::string m_userKey;
PurpleAccount *m_account; // PurpleAccount to which this user is connected
- std::list <Tag *> m_autoConnectRooms;
+ void *m_protocolData;
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
bool m_vip; // true if the user is VIP
More information about the Commits
mailing list