Changeset - 943dc1925b7c
[Not reviewed]
0 5 0
HanzZ - 14 years ago 2011-05-19 00:05:17
hanzz.k@gmail.com
working PM
5 files changed with 40 insertions and 18 deletions:
0 comments (0 inline, 0 general)
docs/Doxyfile
Show inline comments
 
@@ -1436,25 +1436,25 @@ GRAPHICAL_HIERARCHY    = YES
 

	
 
DIRECTORY_GRAPH        = YES
 

	
 
# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 
 
# generated by dot. Possible values are png, jpg, or gif 
 
# If left blank png will be used.
 

	
 
DOT_IMAGE_FORMAT       = png
 

	
 
# The tag DOT_PATH can be used to specify the path where the dot tool can be 
 
# found. If left blank, it is assumed the dot tool can be found in the path.
 

	
 
DOT_PATH               = ""
 
DOT_PATH               = "/usr/bin"
 

	
 
# The DOTFILE_DIRS tag can be used to specify one or more directories that 
 
# contain dot files that are included in the documentation (see the 
 
# \dotfile command).
 

	
 
DOTFILE_DIRS           = 
 

	
 
# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of 
 
# nodes that will be shown in the graph. If the number of nodes in a graph 
 
# becomes larger than this value, doxygen will truncate the graph, which is 
 
# visualized by representing a node as a red box. Note that doxygen if the 
 
# number of direct children of the root node in a graph is already larger than 
include/transport/conversation.h
Show inline comments
 
@@ -25,39 +25,52 @@
 
#include "transport/transport.h"
 

	
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Elements/Message.h"
 

	
 
namespace Transport {
 

	
 
class ConversationManager;
 

	
 
class Conversation {
 
	public:
 
		/// Constructor.
 
		Conversation(ConversationManager *conversationManager, const std::string &legacyName);
 
		Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool m_muc = false);
 

	
 
		/// Destructor
 
		virtual ~Conversation();
 

	
 
		const std::string &getLegacyName() { return m_legacyName; }
 

	
 
		void handleMessage(boost::shared_ptr<Swift::Message> &message, const std::string &nickname = "");
 
		void handleParticipantChanged(const std::string &nickname, int flag);
 
		void setNickname(const std::string &nickname) {
 
			m_nickname = nickname;
 
		}
 

	
 
		virtual void sendMessage(boost::shared_ptr<Swift::Message> &message) = 0;
 

	
 
		ConversationManager *getConversationManager() {
 
			return m_conversationManager;
 
		}
 

	
 
		bool isMUC() {
 
			return m_muc;
 
		}
 

	
 
		void setRoom(const std::string &room) {
 
			m_room = room;
 
		}
 

	
 
		const std::string &getRoom() {
 
			return m_room;
 
		}
 

	
 
	private:
 
		ConversationManager *m_conversationManager;
 
		std::string m_legacyName;
 
		std::string m_nickname;
 
		int m_muc;
 
		std::string m_room;
 
		bool m_muc;
 
};
 

	
 
}
src/conversation.cpp
Show inline comments
 
@@ -19,62 +19,65 @@
 
 */
 

	
 
#include <iostream>
 
#include "transport/conversation.h"
 
#include "transport/conversationmanager.h"
 
#include "transport/user.h"
 
#include "transport/transport.h"
 
#include "transport/buddy.h"
 
#include "transport/rostermanager.h"
 

	
 
namespace Transport {
 

	
 
Conversation::Conversation(ConversationManager *conversationManager, const std::string &legacyName) : m_conversationManager(conversationManager) {
 
Conversation::Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool isMUC) : m_conversationManager(conversationManager) {
 
	m_legacyName = legacyName;
 
	m_conversationManager->setConversation(this);
 
	m_muc = -1;
 
	m_muc = isMUC;
 
}
 

	
 
Conversation::~Conversation() {
 
	m_conversationManager->unsetConversation(this);
 
}
 

	
 
void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, const std::string &nickname) {
 
	if (m_muc == -1)
 
		m_muc = message->getType() != Swift::Message::Groupchat;
 
	if (m_muc == 0) {
 
	if (m_muc) {
 
		message->setType(Swift::Message::Groupchat);
 
	}
 
	else {
 
		message->setType(Swift::Message::Chat);
 
	}
 
	if (message->getType() != Swift::Message::Groupchat) {
 
		
 
		message->setTo(m_conversationManager->getUser()->getJID().toBare());
 
		// normal message
 
		if (nickname.empty()) {
 
			Buddy *buddy = m_conversationManager->getUser()->getRosterManager()->getBuddy(m_legacyName);
 
			if (buddy) {
 
				std::cout << m_legacyName << " 222222\n";
 
				message->setFrom(buddy->getJID());
 
			}
 
			else {
 
				std::cout << m_legacyName << " 1111111\n";
 
				// TODO: escape from and setFrom
 
			}
 
		}
 
		// PM message
 
		else {
 
			if (m_room.empty()) {
 
				message->setFrom(Swift::JID(nickname, m_conversationManager->getComponent()->getJID().toBare(), "user"));
 
			}
 
			else {
 
				message->setFrom(Swift::JID(m_room, m_conversationManager->getComponent()->getJID().toBare(), nickname));
 
			}
 
		}
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
 
	}
 
	else {
 
		message->setTo(m_conversationManager->getUser()->getJID().toString());
 
		message->setFrom(Swift::JID(m_legacyName, m_conversationManager->getComponent()->getJID().toBare(), nickname));
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
 
	}
 
}
 

	
 
void Conversation::handleParticipantChanged(const std::string &nick, int flag) {
 
	std::string nickname = nick;
 
	if (nickname.find("@") == 0) {
src/conversationmanager.cpp
Show inline comments
 
@@ -34,28 +34,42 @@ ConversationManager::ConversationManager(User *user, Component *component){
 
	m_user = user;
 
	m_component = component;
 
}
 

	
 
ConversationManager::~ConversationManager() {
 
}
 

	
 
void ConversationManager::setConversation(Conversation *conv) {
 
	m_convs[conv->getLegacyName()] = conv;
 
}
 

	
 
void ConversationManager::unsetConversation(Conversation *conv) {
 
	for (std::map<std::string, Conversation *>::const_iterator it = m_convs.begin(); it != m_convs.end(); it++) {
 
		if ((*it).second->getRoom() == conv->getLegacyName()) {
 
			(*it).second->setRoom("");
 
		}
 
	}
 
	m_convs.erase(conv->getLegacyName());
 
}
 

	
 
void ConversationManager::handleMessageReceived(Swift::Message::ref message) {
 
	std::string name = message->getTo().getUnescapedNode();
 
	if (name.find_last_of("%") != std::string::npos) {
 
		name.replace(name.find_last_of("%"), 1, "@");
 
	}
 

	
 
	if (!m_convs[name]) {
 
		m_convs[name] = m_component->getFactory()->createConversation(this, name);
 
	}
 
	else if (m_convs[name]->isMUC() && message->getType() != Swift::Message::Groupchat) {
 
		std::string room_name = name;
 
		name = message->getTo().getResource();
 
		if (!m_convs[name]) {
 
			m_convs[name] = m_component->getFactory()->createConversation(this, name);
 
			m_convs[name]->setRoom(room_name);
 
		}
 
	}
 

	
 
	m_convs[name]->sendMessage(message);
 
}
 

	
 
}
 
\ No newline at end of file
src/networkpluginserver.cpp
Show inline comments
 
@@ -30,25 +30,25 @@
 
#include "transport/conversation.h"
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Elements/StreamError.h"
 
#include "pbnetwork.pb.h"
 
#include "sys/wait.h"
 
#include "sys/signal.h"
 

	
 
namespace Transport {
 

	
 
class NetworkConversation : public Conversation {
 
	public:
 
		NetworkConversation(ConversationManager *conversationManager, const std::string &legacyName) : Conversation(conversationManager, legacyName) {
 
		NetworkConversation(ConversationManager *conversationManager, const std::string &legacyName, bool muc = false) : Conversation(conversationManager, legacyName, muc) {
 
		}
 

	
 
		void sendMessage(boost::shared_ptr<Swift::Message> &message) {
 
			onMessageToSend(this, message);
 
		}
 

	
 
		boost::signal<void (NetworkConversation *, boost::shared_ptr<Swift::Message> &)> onMessageToSend;
 
};
 

	
 
class NetworkFactory : public Factory {
 
	public:
 
		NetworkFactory(NetworkPluginServer *nps) {
 
@@ -254,32 +254,24 @@ void NetworkPluginServer::handleConvMessagePayload(const std::string &data) {
 
	User *user = m_userManager->getUser(payload.username());
 
	if (!user)
 
		return;
 

	
 
	boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
	msg->setBody(payload.message());
 

	
 
	NetworkConversation *conv = (NetworkConversation *) user->getConversationManager()->getConversation(payload.buddyname());
 
	if (!conv) {
 
		conv = new NetworkConversation(user->getConversationManager(), payload.buddyname());
 
		conv->onMessageToSend.connect(boost::bind(&NetworkPluginServer::handleMessageReceived, this, _1, _2));
 
	}
 
	else {
 
		// groupchat messages can be created only for conversations initiated from XMPP side, not from legacy network side.
 
		// ie. you can't create Groupchat conversation from legacy network side.
 
		if (!payload.nickname().empty()) {
 
			msg->setType(Swift::Message::Groupchat);
 
		}
 
	}
 

	
 

	
 
	conv->handleMessage(msg, payload.nickname());
 
}
 

	
 
void NetworkPluginServer::handleDataRead(boost::shared_ptr<Swift::Connection> c, const Swift::ByteArray &data) {
 
	long expected_size = 0;
 
	m_data += data.toString();
 
// 	std::cout << "received data; size = " << m_data.size() << "\n";
 
	while (m_data.size() != 0) {
 
		if (m_data.size() >= 4) {
 
			unsigned char * head = (unsigned char*) m_data.c_str();
 
			expected_size = (((((*head << 8) | *(head + 1)) << 8) | *(head + 2)) << 8) | *(head + 3);
 
@@ -378,25 +370,25 @@ void NetworkPluginServer::handleRoomJoined(User *user, const std::string &r, con
 
	room.set_username(user->getJID().toBare());
 
	room.set_nickname(nickname);
 
	room.set_room(r);
 
	room.set_password(password);
 

	
 
	std::string message;
 
	room.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_JOIN_ROOM);
 
 
 
	send(m_client, message);
 

	
 
	NetworkConversation *conv = new NetworkConversation(user->getConversationManager(), r);
 
	NetworkConversation *conv = new NetworkConversation(user->getConversationManager(), r, true);
 
	conv->onMessageToSend.connect(boost::bind(&NetworkPluginServer::handleMessageReceived, this, _1, _2));
 
	conv->setNickname(nickname);
 
}
 

	
 
void NetworkPluginServer::handleRoomLeft(User *user, const std::string &r) {
 
	UserInfo userInfo = user->getUserInfo();
 

	
 
	pbnetwork::Room room;
 
	room.set_username(user->getJID().toBare());
 
	room.set_nickname("");
 
	room.set_room(r);
 
	room.set_password("");
0 comments (0 inline, 0 general)