diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index c61f7a8e..9c3c9b08 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -638,7 +638,7 @@ class SpectrumNetworkPlugin : public NetworkPlugin { st = PURPLE_STATUS_OFFLINE; break; } - case 255: + case 6: st = PURPLE_STATUS_INVISIBLE; break; default: diff --git a/include/transport/filetransfer.h b/include/transport/filetransfer.h new file mode 100644 index 00000000..3c78ef48 --- /dev/null +++ b/include/transport/filetransfer.h @@ -0,0 +1,49 @@ +/** + * XMPP - libpurple transport + * + * Copyright (C) 2009, Jan Kaluza + * + * 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 +#include +#include +#include +#include +#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; +}; + +} diff --git a/include/transport/transport.h b/include/transport/transport.h index 79cb2546..bb7df43a 100644 --- a/include/transport/transport.h +++ b/include/transport/transport.h @@ -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 #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; diff --git a/include/transport/user.h b/include/transport/user.h index 0ad6693a..ade960d0 100644 --- a/include/transport/user.h +++ b/include/transport/user.h @@ -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; } diff --git a/include/transport/usermanager.h b/include/transport/usermanager.h index 0c23b245..cd02aade 100644 --- a/include/transport/usermanager.h +++ b/include/transport/usermanager.h @@ -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 onUserCreated; diff --git a/src/filetransfer.cpp b/src/filetransfer.cpp new file mode 100644 index 00000000..7b01db7d --- /dev/null +++ b/src/filetransfer.cpp @@ -0,0 +1,59 @@ +/** + * XMPP - libpurple transport + * + * Copyright (C) 2009, Jan Kaluza + * + * 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 + +#include +#include + +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; +} + +} diff --git a/src/transport.cpp b/src/transport.cpp index 612b51bc..383ced45 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -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(); diff --git a/src/user.cpp b/src/user.cpp index 7b3ba237..2cf74cbd 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -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::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; diff --git a/src/usermanager.cpp b/src/usermanager.cpp index b42eef41..6110c45e 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -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::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)