Added missing files
This commit is contained in:
parent
941bba0427
commit
88b7dd86b2
4 changed files with 308 additions and 0 deletions
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Tobias Markmann
|
||||
* Licensed under the simplified BSD license.
|
||||
* See Documentation/Licenses/BSD-simplified.txt for more information.
|
||||
*/
|
||||
|
||||
#include "CombinedOutgoingFileTransferManager.h"
|
||||
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
#include <Swiften/JID/JID.h>
|
||||
#include "Swiften/Disco/EntityCapsProvider.h"
|
||||
#include <Swiften/Jingle/JingleSessionManager.h>
|
||||
#include <Swiften/Jingle/JingleSessionImpl.h>
|
||||
#include <Swiften/Jingle/JingleContentID.h>
|
||||
#include <Swiften/FileTransfer/OutgoingJingleFileTransfer.h>
|
||||
#include <Swiften/FileTransfer/MyOutgoingSIFileTransfer.h>
|
||||
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
|
||||
#include <Swiften/Base/IDGenerator.h>
|
||||
#include <Swiften/Elements/Presence.h>
|
||||
#include <Swiften/Presence/PresenceOracle.h>
|
||||
#include <Swiften/Base/foreach.h>
|
||||
|
||||
|
||||
namespace Swift {
|
||||
|
||||
CombinedOutgoingFileTransferManager::CombinedOutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, PresenceOracle *presOracle, SOCKS5BytestreamServer *bytestreamServer) : jsManager(jingleSessionManager), iqRouter(router), capsProvider(capsProvider), remoteFactory(remoteFactory), localFactory(localFactory), bytestreamRegistry(bytestreamRegistry), bytestreamProxy(bytestreamProxy), presenceOracle(presOracle), bytestreamServer(bytestreamServer) {
|
||||
idGenerator = new IDGenerator();
|
||||
}
|
||||
|
||||
CombinedOutgoingFileTransferManager::~CombinedOutgoingFileTransferManager() {
|
||||
delete idGenerator;
|
||||
}
|
||||
|
||||
boost::shared_ptr<OutgoingFileTransfer> CombinedOutgoingFileTransferManager::createOutgoingFileTransfer(const JID& from, const JID& receipient, boost::shared_ptr<ReadBytestream> readBytestream, const StreamInitiationFileInfo& fileInfo) {
|
||||
// check if receipient support Jingle FT
|
||||
boost::optional<JID> fullJID = highestPriorityJIDSupportingJingle(receipient);
|
||||
if (!fullJID.is_initialized()) {
|
||||
fullJID = highestPriorityJIDSupportingSI(receipient);
|
||||
}
|
||||
else {
|
||||
JingleSessionImpl::ref jingleSession = boost::make_shared<JingleSessionImpl>(from, receipient, idGenerator->generateID(), iqRouter);
|
||||
|
||||
//jsManager->getSession(receipient, idGenerator->generateID());
|
||||
assert(jingleSession);
|
||||
jsManager->registerOutgoingSession(from, jingleSession);
|
||||
boost::shared_ptr<OutgoingJingleFileTransfer> jingleFT = boost::shared_ptr<OutgoingJingleFileTransfer>(new OutgoingJingleFileTransfer(jingleSession, remoteFactory, localFactory, iqRouter, idGenerator, from, receipient, readBytestream, fileInfo, bytestreamRegistry, bytestreamProxy));
|
||||
return jingleFT;
|
||||
}
|
||||
|
||||
if (!fullJID.is_initialized()) {
|
||||
return boost::shared_ptr<OutgoingFileTransfer>();
|
||||
}
|
||||
|
||||
// otherwise try SI
|
||||
boost::shared_ptr<MyOutgoingSIFileTransfer> jingleFT = boost::shared_ptr<MyOutgoingSIFileTransfer>(new MyOutgoingSIFileTransfer(idGenerator->generateID(), from, fullJID.get(), fileInfo.getName(), fileInfo.getSize(), fileInfo.getDescription(), readBytestream, iqRouter, bytestreamServer, bytestreamRegistry));
|
||||
// else fail
|
||||
|
||||
return jingleFT;
|
||||
}
|
||||
|
||||
boost::optional<JID> CombinedOutgoingFileTransferManager::highestPriorityJIDSupportingJingle(const JID& bareJID) {
|
||||
JID fullReceipientJID;
|
||||
int priority = INT_MIN;
|
||||
|
||||
//getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Remko Tronçon @ 11:11
|
||||
std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID);
|
||||
|
||||
//iterate over them
|
||||
foreach(Presence::ref pres, presences) {
|
||||
if (pres->getPriority() > priority) {
|
||||
// look up caps from the jid
|
||||
DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom());
|
||||
if (info && info->hasFeature(DiscoInfo::JingleFeature) && info->hasFeature(DiscoInfo::JingleFTFeature) &&
|
||||
info->hasFeature(DiscoInfo::JingleTransportsIBBFeature)) {
|
||||
|
||||
priority = pres->getPriority();
|
||||
fullReceipientJID = pres->getFrom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fullReceipientJID.isValid() ? boost::optional<JID>(fullReceipientJID) : boost::optional<JID>();
|
||||
}
|
||||
|
||||
boost::optional<JID> CombinedOutgoingFileTransferManager::highestPriorityJIDSupportingSI(const JID& bareJID) {
|
||||
JID fullReceipientJID;
|
||||
int priority = INT_MIN;
|
||||
|
||||
//getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Remko Tronçon @ 11:11
|
||||
std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID);
|
||||
|
||||
//iterate over them
|
||||
foreach(Presence::ref pres, presences) {
|
||||
if (pres->getPriority() > priority) {
|
||||
// look up caps from the jid
|
||||
DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom());
|
||||
if (info && info->hasFeature("http://jabber.org/protocol/si/profile/file-transfer")) {
|
||||
|
||||
priority = pres->getPriority();
|
||||
fullReceipientJID = pres->getFrom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fullReceipientJID.isValid() ? boost::optional<JID>(fullReceipientJID) : boost::optional<JID>();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Tobias Markmann
|
||||
* Licensed under the simplified BSD license.
|
||||
* See Documentation/Licenses/BSD-simplified.txt for more information.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <Swiften/JID/JID.h>
|
||||
|
||||
namespace Swift {
|
||||
|
||||
class JingleSessionManager;
|
||||
class IQRouter;
|
||||
class EntityCapsProvider;
|
||||
class RemoteJingleTransportCandidateSelectorFactory;
|
||||
class LocalJingleTransportCandidateGeneratorFactory;
|
||||
class OutgoingFileTransfer;
|
||||
class JID;
|
||||
class IDGenerator;
|
||||
class ReadBytestream;
|
||||
class StreamInitiationFileInfo;
|
||||
class SOCKS5BytestreamRegistry;
|
||||
class SOCKS5BytestreamProxy;
|
||||
class SOCKS5BytestreamServer;
|
||||
class PresenceOracle;
|
||||
|
||||
class CombinedOutgoingFileTransferManager {
|
||||
public:
|
||||
CombinedOutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, PresenceOracle* presOracle, SOCKS5BytestreamServer *server);
|
||||
~CombinedOutgoingFileTransferManager();
|
||||
|
||||
boost::shared_ptr<OutgoingFileTransfer> createOutgoingFileTransfer(const JID& from, const JID& to, boost::shared_ptr<ReadBytestream>, const StreamInitiationFileInfo&);
|
||||
|
||||
private:
|
||||
boost::optional<JID> highestPriorityJIDSupportingJingle(const JID& bareJID);
|
||||
boost::optional<JID> highestPriorityJIDSupportingSI(const JID& bareJID);
|
||||
JingleSessionManager* jsManager;
|
||||
IQRouter* iqRouter;
|
||||
EntityCapsProvider* capsProvider;
|
||||
RemoteJingleTransportCandidateSelectorFactory* remoteFactory;
|
||||
LocalJingleTransportCandidateGeneratorFactory* localFactory;
|
||||
IDGenerator *idGenerator;
|
||||
SOCKS5BytestreamRegistry* bytestreamRegistry;
|
||||
SOCKS5BytestreamProxy* bytestreamProxy;
|
||||
PresenceOracle* presenceOracle;
|
||||
SOCKS5BytestreamServer *bytestreamServer;
|
||||
};
|
||||
|
||||
}
|
90
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.cpp
Normal file
90
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Remko Tronçon
|
||||
* Licensed under the GNU General Public License v3.
|
||||
* See Documentation/Licenses/GPLv3.txt for more information.
|
||||
*/
|
||||
|
||||
#include <Swiften/FileTransfer/MyOutgoingSIFileTransfer.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <Swiften/FileTransfer/StreamInitiationRequest.h>
|
||||
#include <Swiften/FileTransfer/BytestreamsRequest.h>
|
||||
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
|
||||
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
|
||||
#include <Swiften/FileTransfer/IBBSendSession.h>
|
||||
|
||||
namespace Swift {
|
||||
|
||||
MyOutgoingSIFileTransfer::MyOutgoingSIFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer, SOCKS5BytestreamRegistry* registry) : id(id), from(from), to(to), name(name), size(size), description(description), bytestream(bytestream), iqRouter(iqRouter), socksServer(socksServer), registry(registry) {
|
||||
}
|
||||
|
||||
void MyOutgoingSIFileTransfer::start() {
|
||||
StreamInitiation::ref streamInitiation(new StreamInitiation());
|
||||
streamInitiation->setID(id);
|
||||
streamInitiation->setFileInfo(StreamInitiationFileInfo(name, description, size));
|
||||
streamInitiation->addProvidedMethod("http://jabber.org/protocol/bytestreams");
|
||||
streamInitiation->addProvidedMethod("http://jabber.org/protocol/ibb");
|
||||
StreamInitiationRequest::ref request = StreamInitiationRequest::create(from, to, streamInitiation, iqRouter);
|
||||
request->onResponse.connect(boost::bind(&MyOutgoingSIFileTransfer::handleStreamInitiationRequestResponse, this, _1, _2));
|
||||
request->send();
|
||||
}
|
||||
|
||||
void MyOutgoingSIFileTransfer::stop() {
|
||||
}
|
||||
|
||||
void MyOutgoingSIFileTransfer::handleStreamInitiationRequestResponse(StreamInitiation::ref response, ErrorPayload::ref error) {
|
||||
if (error) {
|
||||
finish(FileTransferError());
|
||||
}
|
||||
else {
|
||||
if (response->getRequestedMethod() == "http://jabber.org/protocol/bytestreams") {
|
||||
registry->addReadBytestream(SOCKS5BytestreamRegistry::getHostname(id, from, to), bytestream);
|
||||
socksServer->addReadBytestream(id, from, to, bytestream);
|
||||
Bytestreams::ref bytestreams(new Bytestreams());
|
||||
bytestreams->setStreamID(id);
|
||||
HostAddressPort addressPort = socksServer->getAddressPort();
|
||||
bytestreams->addStreamHost(Bytestreams::StreamHost(addressPort.getAddress().toString(), from, addressPort.getPort()));
|
||||
BytestreamsRequest::ref request = BytestreamsRequest::create(from, to, bytestreams, iqRouter);
|
||||
request->onResponse.connect(boost::bind(&MyOutgoingSIFileTransfer::handleBytestreamsRequestResponse, this, _1, _2));
|
||||
request->send();
|
||||
}
|
||||
else if (response->getRequestedMethod() == "http://jabber.org/protocol/ibb") {
|
||||
ibbSession = boost::shared_ptr<IBBSendSession>(new IBBSendSession(id, from, to, bytestream, iqRouter));
|
||||
ibbSession->onFinished.connect(boost::bind(&MyOutgoingSIFileTransfer::handleIBBSessionFinished, this, _1));
|
||||
ibbSession->start();
|
||||
|
||||
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyOutgoingSIFileTransfer::handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref error) {
|
||||
if (error) {
|
||||
finish(FileTransferError());
|
||||
return;
|
||||
}
|
||||
|
||||
SOCKS5BytestreamServerSession *serverSession = registry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(id, from, to));
|
||||
// serverSession->onBytesSent.connect(boost::bind(boost::ref(onProcessedBytes), _1));
|
||||
// serverSession->onFinished.connect(boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1));
|
||||
serverSession->startTransfer();
|
||||
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
|
||||
|
||||
//socksServer->onTransferFinished.connect();
|
||||
}
|
||||
|
||||
void MyOutgoingSIFileTransfer::finish(boost::optional<FileTransferError> error) {
|
||||
if (ibbSession) {
|
||||
ibbSession->onFinished.disconnect(boost::bind(&MyOutgoingSIFileTransfer::handleIBBSessionFinished, this, _1));
|
||||
ibbSession.reset();
|
||||
}
|
||||
socksServer->removeReadBytestream(id, from, to);
|
||||
onFinished(error);
|
||||
}
|
||||
|
||||
void MyOutgoingSIFileTransfer::handleIBBSessionFinished(boost::optional<FileTransferError> error) {
|
||||
finish(error);
|
||||
}
|
||||
|
||||
}
|
56
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.h
Normal file
56
include/Swiften/FileTransfer/MyOutgoingSIFileTransfer.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Remko Tronçon
|
||||
* Licensed under the GNU General Public License v3.
|
||||
* See Documentation/Licenses/GPLv3.txt for more information.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
|
||||
#include <Swiften/FileTransfer/ReadBytestream.h>
|
||||
#include <Swiften/Base/boost_bsignals.h>
|
||||
#include <Swiften/FileTransfer/FileTransferError.h>
|
||||
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
|
||||
#include <Swiften/JID/JID.h>
|
||||
#include <Swiften/Elements/StreamInitiation.h>
|
||||
#include <Swiften/Elements/Bytestreams.h>
|
||||
#include <Swiften/Elements/ErrorPayload.h>
|
||||
#include <Swiften/FileTransfer/IBBSendSession.h>
|
||||
|
||||
namespace Swift {
|
||||
class IQRouter;
|
||||
class SOCKS5BytestreamServer;
|
||||
class SOCKS5BytestreamRegistry;
|
||||
|
||||
class MyOutgoingSIFileTransfer : public OutgoingFileTransfer {
|
||||
public:
|
||||
MyOutgoingSIFileTransfer(const std::string& id, const JID& from, const JID& to, const std::string& name, int size, const std::string& description, boost::shared_ptr<ReadBytestream> bytestream, IQRouter* iqRouter, SOCKS5BytestreamServer* socksServer, SOCKS5BytestreamRegistry* registry);
|
||||
|
||||
virtual void start();
|
||||
virtual void stop();
|
||||
virtual void cancel() {}
|
||||
|
||||
boost::signal<void (const boost::optional<FileTransferError>&)> onFinished;
|
||||
|
||||
private:
|
||||
void handleStreamInitiationRequestResponse(StreamInitiation::ref, ErrorPayload::ref);
|
||||
void handleBytestreamsRequestResponse(Bytestreams::ref, ErrorPayload::ref);
|
||||
void finish(boost::optional<FileTransferError> error);
|
||||
void handleIBBSessionFinished(boost::optional<FileTransferError> error);
|
||||
|
||||
private:
|
||||
std::string id;
|
||||
JID from;
|
||||
JID to;
|
||||
std::string name;
|
||||
int size;
|
||||
std::string description;
|
||||
boost::shared_ptr<ReadBytestream> bytestream;
|
||||
IQRouter* iqRouter;
|
||||
SOCKS5BytestreamServer* socksServer;
|
||||
boost::shared_ptr<IBBSendSession> ibbSession;
|
||||
SOCKS5BytestreamRegistry *registry;
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue