diff options
| -rw-r--r-- | Documentation/API/Doxyfile | 7 | ||||
| -rw-r--r-- | Swiften/FileTransfer/FileTransfer.cpp | 13 | ||||
| -rw-r--r-- | Swiften/FileTransfer/FileTransfer.h | 20 | ||||
| -rw-r--r-- | Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp | 24 | ||||
| -rw-r--r-- | Swiften/FileTransfer/OutgoingJingleFileTransfer.h | 18 |
5 files changed, 50 insertions, 32 deletions
diff --git a/Documentation/API/Doxyfile b/Documentation/API/Doxyfile index 84fdaac..0634800 100644 --- a/Documentation/API/Doxyfile +++ b/Documentation/API/Doxyfile @@ -83,29 +83,30 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- INPUT = \ Swiften/Avatars \ Swiften/Base \ Swiften/Chat \ Swiften/Client/Client.h \ - Swiften/Client/CoreClient.h \ Swiften/Client/ClientError.h \ - Swiften/Client/StanzaChannel.h \ + Swiften/Client/CoreClient.h \ + Swiften/Client/MemoryStorages.h \ Swiften/Client/NickResolver.h \ + Swiften/Client/StanzaChannel.h \ Swiften/Client/Storages.h \ - Swiften/Client/MemoryStorages.h \ Swiften/Component/Component.h \ Swiften/Component/CoreComponent.h \ Swiften/Disco \ Swiften/Elements \ Swiften/EventLoop \ + Swiften/FileTransfer \ Swiften/JID \ Swiften/MUC \ Swiften/Presence \ Swiften/Queries \ Swiften/Roster/XMPPRoster.h \ Swiften/StringCodecs \ Swiften/TLS/BlindCertificateTrustChecker.h \ Swiften/TLS/Certificate.h \ Swiften/TLS/CertificateTrustChecker.h \ diff --git a/Swiften/FileTransfer/FileTransfer.cpp b/Swiften/FileTransfer/FileTransfer.cpp index 6b594aa..f63a4e8 100644 --- a/Swiften/FileTransfer/FileTransfer.cpp +++ b/Swiften/FileTransfer/FileTransfer.cpp @@ -1,20 +1,25 @@ /* - * Copyright (c) 2013-2014 Isode Limited. + * Copyright (c) 2013-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/FileTransfer/FileTransfer.h> using namespace Swift; -FileTransfer::FileTransfer() : fileSizeInBytes(0) { +FileTransfer::FileTransfer() : fileSizeInBytes_(0), state_(State::Initial) { } FileTransfer::~FileTransfer() { } +void FileTransfer::setState(const State& state) { + state_ = state; + onStateChanged(state); +} + void FileTransfer::setFileInfo(const std::string& name, boost::uintmax_t size) { - filename = name; - fileSizeInBytes = size; + filename_ = name; + fileSizeInBytes_ = size; } diff --git a/Swiften/FileTransfer/FileTransfer.h b/Swiften/FileTransfer/FileTransfer.h index 01c8295..afb3f7b 100644 --- a/Swiften/FileTransfer/FileTransfer.h +++ b/Swiften/FileTransfer/FileTransfer.h @@ -15,18 +15,24 @@ #include <boost/cstdint.hpp> #include <boost/optional.hpp> #include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/FileTransfer/FileTransferError.h> namespace Swift { + /** + * The FileTransfer class provides a general interface for file-transfer + * implmenetations. Currently, only Jingle File Transfer based on XEP-0234 is + * implementated in the \ref OutgoingJingleFileTransfer and + * \ref IncomingJingleFileTransfer classes. + */ class SWIFTEN_API FileTransfer { public: struct State { enum Type { Initial, WaitingForStart, Negotiating, WaitingForAccept, Transferring, @@ -43,29 +49,35 @@ namespace Swift { typedef boost::shared_ptr<FileTransfer> ref; public: FileTransfer(); virtual ~FileTransfer(); virtual void cancel() = 0; const std::string& getFileName() const { - return filename; + return filename_; } boost::uintmax_t getFileSizeInBytes() const { - return fileSizeInBytes; + return fileSizeInBytes_; + } + + const State& getState() const { + return state_; } public: boost::signal<void (size_t /* proccessedBytes */)> onProcessedBytes; boost::signal<void (const State&)> onStateChanged; boost::signal<void (boost::optional<FileTransferError>)> onFinished; protected: + void setState(const State& state); void setFileInfo(const std::string& name, boost::uintmax_t size); private: - boost::uintmax_t fileSizeInBytes; - std::string filename; + boost::uintmax_t fileSizeInBytes_; + std::string filename_; + State state_; }; } diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index f9441cd..6369581 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp @@ -83,19 +83,19 @@ OutgoingJingleFileTransfer::~OutgoingJingleFileTransfer() { void OutgoingJingleFileTransfer::start() { SWIFT_LOG(debug) << std::endl; if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } setTransporter(transporterFactory->createInitiatorTransporter(getInitiator(), getResponder(), options)); - setState(GeneratingInitialLocalCandidates); + setInternalState(GeneratingInitialLocalCandidates); transporter->startGeneratingLocalCandidates(); } void OutgoingJingleFileTransfer::cancel() { terminate(JinglePayload::Reason::Cancel); } void OutgoingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) { SWIFT_LOG(debug) << reason << std::endl; @@ -110,19 +110,19 @@ void OutgoingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) { void OutgoingJingleFileTransfer::handleSessionAcceptReceived( const JingleContentID&, JingleDescription::ref, JingleTransportPayload::ref transportPayload) { SWIFT_LOG(debug) << std::endl; if (state != WaitingForAccept) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) { transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr()); - setState(TryingCandidates); + setInternalState(TryingCandidates); transporter->startTryingRemoteCandidates(); } else { SWIFT_LOG(debug) << "Unknown transport payload. Falling back." << std::endl; fallback(); } } void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) { @@ -172,46 +172,46 @@ void OutgoingJingleFileTransfer::sendSessionInfoHash() { JingleFileTransferHash::ref hashElement = boost::make_shared<JingleFileTransferHash>(); hashElement->getFileInfo().addHash(HashElement("sha-1", hashCalculator->getSHA1Hash())); hashElement->getFileInfo().addHash(HashElement("md5", hashCalculator->getMD5Hash())); session->sendInfo(hashElement); } void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { SWIFT_LOG(debug) << std::endl; - if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } + if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } fillCandidateMap(localCandidates, candidates); JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>(); fileInfo.addHash(HashElement("sha-1", ByteArray())); fileInfo.addHash(HashElement("md5", ByteArray())); description->setFileInfo(fileInfo); JingleS5BTransportPayload::ref transport = boost::make_shared<JingleS5BTransportPayload>(); transport->setSessionID(s5bSessionID); transport->setMode(JingleS5BTransportPayload::TCPMode); transport->setDstAddr(dstAddr); foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { transport->addCandidate(candidate); SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl; } - setState(WaitingForAccept); + setInternalState(WaitingForAccept); session->sendInitiate(contentID, description, transport); } void OutgoingJingleFileTransfer::fallback() { if (options.isInBandAllowed()) { SWIFT_LOG(debug) << "Trying to fallback to IBB transport." << std::endl; JingleIBBTransportPayload::ref ibbTransport = boost::make_shared<JingleIBBTransportPayload>(); ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); ibbTransport->setSessionID(idGenerator->generateID()); - setState(FallbackRequested); + setInternalState(FallbackRequested); session->sendTransportReplace(contentID, ibbTransport); } else { SWIFT_LOG(debug) << "Fallback to IBB transport not allowed." << std::endl; terminate(JinglePayload::Reason::ConnectivityError); } } void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) { @@ -219,40 +219,40 @@ void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTran if (state != Transferring) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } if (error) { terminate(JinglePayload::Reason::ConnectivityError); } else { sendSessionInfoHash(); // wait for other party to terminate session after they have verified the hash - setState(WaitForTermination); + setInternalState(WaitForTermination); waitForRemoteTermination->start(); } } void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSession> transportSession) { SWIFT_LOG(debug) << std::endl; this->transportSession = transportSession; processedBytesConnection = transportSession->onBytesSent.connect( boost::bind(boost::ref(onProcessedBytes), _1)); transferFinishedConnection = transportSession->onFinished.connect( boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1)); - setState(Transferring); + setInternalState(Transferring); transportSession->start(); } -void OutgoingJingleFileTransfer::setState(State state) { +void OutgoingJingleFileTransfer::setInternalState(State state) { SWIFT_LOG(debug) << state << std::endl; this->state = state; - onStateChanged(FileTransfer::State(getExternalState(state))); + setState(FileTransfer::State(getExternalState(state))); } void OutgoingJingleFileTransfer::setFinishedState( FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) { SWIFT_LOG(debug) << std::endl; this->state = Finished; onStateChanged(type); onFinished(error); } @@ -300,45 +300,45 @@ void OutgoingJingleFileTransfer::stopAll() { if (state != Initial) { removeTransporter(); } } void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { SWIFT_LOG(debug) << std::endl; if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { - setState(WaitingForPeerProxyActivate); + setInternalState(WaitingForPeerProxyActivate); } else { transportSession = createRemoteCandidateSession(); startTransferringIfCandidateAcknowledged(); } } void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { SWIFT_LOG(debug) << std::endl; if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { - setState(WaitingForLocalProxyActivate); + setInternalState(WaitingForLocalProxyActivate); transporter->startActivatingProxy(theirCandidateChoice->jid); } else { transportSession = createLocalCandidateSession(); startTransferringIfCandidateAcknowledged(); } } void OutgoingJingleFileTransfer::startTransferringIfCandidateAcknowledged() { if (candidateAcknowledged) { startTransferring(transportSession); } else { - setState(WaitingForCandidateAcknowledge); + setInternalState(WaitingForCandidateAcknowledge); } } void OutgoingJingleFileTransfer::handleTransportInfoAcknowledged(const std::string& id) { if (id == candidateSelectRequestID) { candidateAcknowledged = true; } if (state == WaitingForCandidateAcknowledge) { startTransferring(transportSession); diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h index 4cb2685..96b465b 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h @@ -6,39 +6,39 @@ /* * Copyright (c) 2013-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> #include <boost/optional/optional.hpp> +#include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> #include <Swiften/Base/Override.h> -#include <Swiften/Jingle/JingleContentID.h> #include <Swiften/Elements/JingleFileTransferFileInfo.h> -#include <Swiften/FileTransfer/OutgoingFileTransfer.h> -#include <Swiften/FileTransfer/JingleFileTransfer.h> #include <Swiften/FileTransfer/FileTransferOptions.h> +#include <Swiften/FileTransfer/JingleFileTransfer.h> +#include <Swiften/FileTransfer/OutgoingFileTransfer.h> +#include <Swiften/Jingle/JingleContentID.h> #include <Swiften/Network/Timer.h> namespace Swift { - class ReadBytestream; - class IDGenerator; - class IncrementalBytestreamHashCalculator; class CryptoProvider; class FileTransferTransporter; class FileTransferTransporterFactory; - class TransportSession; + class IDGenerator; + class IncrementalBytestreamHashCalculator; + class ReadBytestream; class TimerFactory; + class TransportSession; class SWIFTEN_API OutgoingJingleFileTransfer : public OutgoingFileTransfer, public JingleFileTransfer { public: OutgoingJingleFileTransfer( const JID& to, boost::shared_ptr<JingleSession>, boost::shared_ptr<ReadBytestream>, FileTransferTransporterFactory*, TimerFactory*, @@ -92,19 +92,19 @@ namespace Swift { virtual bool isWaitingForPeerProxyActivate() const SWIFTEN_OVERRIDE; virtual bool isWaitingForLocalProxyActivate() const SWIFTEN_OVERRIDE; virtual bool isTryingCandidates() const SWIFTEN_OVERRIDE; virtual boost::shared_ptr<TransportSession> createLocalCandidateSession() SWIFTEN_OVERRIDE; virtual boost::shared_ptr<TransportSession> createRemoteCandidateSession() SWIFTEN_OVERRIDE; void handleWaitForRemoteTerminationTimeout(); void stopAll(); - void setState(State state); + void setInternalState(State state); void setFinishedState(FileTransfer::State::Type, const boost::optional<FileTransferError>& error); static FileTransfer::State::Type getExternalState(State state); private: IDGenerator* idGenerator; boost::shared_ptr<ReadBytestream> stream; JingleFileTransferFileInfo fileInfo; FileTransferOptions options; |
Swift