Changeset - 02b2f22f3e96
[Not reviewed]
0 7 2
HanzZ - 14 years ago 2011-09-28 10:58:48
hanzz.k@gmail.com
First part of filetransfer
9 files changed with 145 insertions and 3 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -638,7 +638,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
						st = PURPLE_STATUS_OFFLINE;
 
						break;
 
					}
 
					case 255:
 
					case 6:
 
						st = PURPLE_STATUS_INVISIBLE;
 
						break;
 
					default:
include/transport/filetransfer.h
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@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
 
 */
 

	
 
#pragma once
 

	
 
#include <string>
 
#include <algorithm>
 
#include <map>
 
#include <boost/pool/pool_alloc.hpp>
 
#include <boost/pool/object_pool.hpp>
 
#include "Swiften/Swiften.h"
 
// #include "rosterstorage.h"
 

	
 
namespace Transport {
 

	
 
class Component;
 
class User;
 

	
 
class FileTransfer {
 
	public:
 
		FileTransfer(User *user, Component *component, const Swift::JID &from);
 

	
 
		/// Destructor.
 
		virtual ~FileTransfer();
 

	
 
	private:
 
		Swift::FileTransferManager* m_ftManager;
 
		Component *m_component;
 
		User *m_user;
 
};
 

	
 
}
include/transport/transport.h
Show inline comments
 
@@ -32,6 +32,7 @@
 
#include "Swiften/Network/BoostIOServiceThread.h"
 
#include "Swiften/Server/UserRegistry.h"
 
#include "Swiften/Base/SafeByteArray.h"
 
#include "Swiften/Jingle/JingleSessionManager.h"
 

	
 
#include <boost/bind.hpp>
 
#include "transport/config.h"
 
@@ -93,6 +94,8 @@ namespace Transport {
 
			/// \return Swift::PresenceOracle associated with this Transport::Component.
 
			Swift::PresenceOracle *getPresenceOracle();
 

	
 
			Swift::JingleSessionManager *getJingleSessionManager() { return m_jingleSessionManager; }
 

	
 
			/// Returns True if the component is in server mode.
 

	
 
			/// \return True if the component is in server mode.
 
@@ -181,6 +184,7 @@ namespace Transport {
 
			Swift::PresenceOracle *m_presenceOracle;
 
			Swift::StanzaChannel *m_stanzaChannel;
 
			Swift::IQRouter *m_iqRouter;
 
			Swift::JingleSessionManager *m_jingleSessionManager;
 
			Transport::UserRegistry *m_userRegistry;
 
			StorageBackend *m_storageBackend;
 
 			DiscoInfoResponder *m_discoInfoResponder;
include/transport/user.h
Show inline comments
 
@@ -24,6 +24,7 @@
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Presence/PresenceOracle.h"
 
#include "Swiften/Disco/EntityCapsManager.h"
 
#include "Swiften/Disco/EntityCapsProvider.h"
 
#include "storagebackend.h"
 

	
 
namespace Transport {
 
@@ -35,7 +36,7 @@ class UserManager;
 
struct UserInfo;
 

	
 
/// Represents online XMPP user.
 
class User {
 
class User : public Swift::EntityCapsProvider {
 
	public:
 
		/// Creates new User class.
 
		/// \param jid XMPP JID associated with this user
 
@@ -56,6 +57,8 @@ class User {
 
		/// \return full JID which supports particular feature or invalid JID.
 
		Swift::JID getJIDWithFeature(const std::string &feature);
 

	
 
		Swift::DiscoInfo::ref getCaps(const Swift::JID &jid) const;
 

	
 
		/// Returns UserInfo struct with informations needed to connect the legacy network.
 
		/// \return UserInfo struct
 
		UserInfo &getUserInfo() { return m_userInfo; }
include/transport/usermanager.h
Show inline comments
 
@@ -50,7 +50,7 @@ class RosterResponder;
 
	UserManager->User [label="handlePresence(...)", URL="\ref User::handlePresence()"];
 
	\endmsc
 
*/
 
class UserManager {
 
class UserManager : public Swift::EntityCapsProvider {
 
	public:
 
		/// Creates new UserManager.
 
		/// \param component Component which's presence will be handled
 
@@ -82,6 +82,8 @@ class UserManager {
 

	
 
		void removeAllUsers();
 

	
 
		Swift::DiscoInfo::ref getCaps(const Swift::JID&) const;
 

	
 
		/// Called when new User class is created.
 
		/// \param user newly created User class
 
		boost::signal<void (User *user)> onUserCreated;
src/filetransfer.cpp
Show inline comments
 
new file 100644
 
/**
 
 * XMPP - libpurple transport
 
 *
 
 * Copyright (C) 2009, Jan Kaluza <hanzz@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 "transport/filetransfer.h"
 
#include "transport/usermanager.h"
 
#include "transport/transport.h"
 
#include "transport/user.h"
 
#include "Swiften/Roster/SetRosterRequest.h"
 
#include "Swiften/Elements/RosterPayload.h"
 
#include "Swiften/Elements/RosterItemPayload.h"
 
#include "Swiften/Elements/RosterItemExchangePayload.h"
 
#include "Swiften/FileTransfer/FileTransferManagerImpl.h"
 
#include "log4cxx/logger.h"
 
#include <boost/foreach.hpp>
 

	
 
#include <map>
 
#include <iterator>
 

	
 
using namespace log4cxx;
 

	
 
namespace Transport {
 

	
 
static LoggerPtr logger = Logger::getLogger("FileTransfer");
 

	
 
FileTransfer::FileTransfer(User *user, Component *component, const Swift::JID &from) {
 
	m_user = user;
 
	m_component = component;
 
	m_ftManager = new Swift::FileTransferManagerImpl(from, m_component->getJingleSessionManager(), m_component->getIQRouter(),
 
											  user, m_component->getPresenceOracle(),
 
											  m_component->getNetworkFactories()->getConnectionFactory(),
 
											  m_component->getNetworkFactories()->getConnectionServerFactory(),
 
											  m_component->getNetworkFactories()->getTimerFactory(),
 
											  m_component->getNetworkFactories()->getNATTraverser());
 
	LOG4CXX_INFO(logger, "FileTransfer " << this << " from '" << from.toString() << "' to '" << user->getJID().toString() << "' created");
 
}
 

	
 
FileTransfer::~FileTransfer() {
 
	LOG4CXX_INFO(logger, "FileTransfer " << this << " destroyed");
 
	delete m_ftManager;
 
}
 

	
 
}
src/transport.cpp
Show inline comments
 
@@ -125,6 +125,8 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
	m_discoItemsResponder = new DiscoItemsResponder(m_iqRouter);
 
	m_discoItemsResponder->start();
 

	
 
	m_jingleSessionManager = new Swift::JingleSessionManager(m_iqRouter);
 

	
 
// 
 
// 	m_registerHandler = new SpectrumRegisterHandler(m_component);
 
// 	m_registerHandler->start();
src/user.cpp
Show inline comments
 
@@ -111,6 +111,19 @@ Swift::JID User::getJIDWithFeature(const std::string &feature) {
 
	return jid;
 
}
 

	
 
Swift::DiscoInfo::ref User::getCaps(const Swift::JID &jid) const {
 
	Swift::DiscoInfo::ref discoInfo = m_entityCapsManager->getCaps(jid);
 
#ifdef SUPPORT_LEGACY_CAPS
 
	if (!discoInfo) {
 
		std::map<Swift::JID, Swift::DiscoInfo::ref>::const_iterator it = m_legacyCaps.find(jid);
 
		if (it != m_legacyCaps.end()) {
 
			discoInfo = it->second;
 
		}
 
	}
 
#endif
 
	return discoInfo;
 
}
 

	
 
void User::sendCurrentPresence() {
 
	if (m_component->inServerMode()) {
 
		return;
src/usermanager.cpp
Show inline comments
 
@@ -91,6 +91,16 @@ User *UserManager::getUser(const std::string &barejid){
 
	return NULL;
 
}
 

	
 
Swift::DiscoInfo::ref UserManager::getCaps(const Swift::JID &jid) const {
 
	std::map<std::string, User *>::const_iterator it = m_users.find(jid.toBare().toString());
 
	if (it == m_users.end()) {
 
		return Swift::DiscoInfo::ref();
 
	}
 

	
 
	User *user = it->second;
 
	return user->getCaps(jid);
 
}
 

	
 
void UserManager::removeUser(User *user) {
 
	m_users.erase(user->getJID().toBare().toString());
 
	if (m_cachedUser == user)
0 comments (0 inline, 0 general)