summaryrefslogtreecommitdiffstats
blob: aabeec28e01c8260c69447f651ae404100cb47de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2013-2015 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <Swiften/Base/API.h>

#include <boost/shared_ptr.hpp>
#include <vector>
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/Elements/JingleS5BTransportPayload.h>
#include <Swiften/FileTransfer/FileTransfer.h>
#include <Swiften/Jingle/AbstractJingleSessionListener.h>
#include <Swiften/Jingle/JingleContentID.h>

namespace Swift {
	class CryptoProvider;
	class IQRouter;
	class RemoteJingleTransportCandidateSelector;
	class LocalJingleTransportCandidateGenerator;
	class JingleSession;
	class FileTransferTransporter;
	class FileTransferTransporterFactory;
	class TransportSession;

	class SWIFTEN_API JingleFileTransfer : public AbstractJingleSessionListener {
		public:
			JingleFileTransfer(
					boost::shared_ptr<JingleSession>, 
					const JID& target,
					FileTransferTransporterFactory*);
			virtual ~JingleFileTransfer();

		protected:
			virtual void handleTransportInfoReceived(const JingleContentID&, JingleTransportPayload::ref);
			virtual void handleLocalTransportCandidatesGenerated(
					const std::string& s5bSessionID, 
					const std::vector<JingleS5BTransportPayload::Candidate>&,
					const std::string& dstAddr) = 0;
			virtual void handleProxyActivateFinished(
					const std::string& s5bSessionID, 
					ErrorPayload::ref error);
			virtual void decideOnCandidates();
			void handleRemoteTransportCandidateSelectFinished(
					const std::string& s5bSessionID, const boost::optional<JingleS5BTransportPayload::Candidate>&);
			virtual JingleContentID getContentID() const = 0;
			virtual void startTransferring(boost::shared_ptr<TransportSession>) = 0;
			virtual void terminate(JinglePayload::Reason::Type reason) = 0;
			virtual void fallback() = 0;
			virtual bool hasPriorityOnCandidateTie() const = 0;
			virtual bool isWaitingForPeerProxyActivate() const = 0;
			virtual bool isWaitingForLocalProxyActivate() const = 0;
			virtual bool isTryingCandidates() const = 0;
			virtual boost::shared_ptr<TransportSession> createLocalCandidateSession() = 0;
			virtual boost::shared_ptr<TransportSession> createRemoteCandidateSession() = 0;
			virtual void startTransferViaLocalCandidate() = 0;
			virtual void startTransferViaRemoteCandidate() = 0;

		protected:
			typedef std::map<std::string, JingleS5BTransportPayload::Candidate> CandidateMap;

			void setTransporter(FileTransferTransporter* transporter);
			void fillCandidateMap(
					CandidateMap& map, 
					const std::vector<JingleS5BTransportPayload::Candidate>&);
			const JID& getInitiator() const;
			const JID& getResponder() const;

			static FileTransfer::State::Type getExternalFinishedState(JinglePayload::Reason::Type);
			static boost::optional<FileTransferError> getFileTransferError(JinglePayload::Reason::Type);

			boost::shared_ptr<JingleSession> session;
			JID target;
			FileTransferTransporterFactory* transporterFactory;
			FileTransferTransporter* transporter;

			std::string candidateSelectRequestID;
			bool ourCandidateSelectFinished;
			boost::optional<JingleS5BTransportPayload::Candidate> ourCandidateChoice;
			bool theirCandidateSelectFinished;
			boost::optional<JingleS5BTransportPayload::Candidate> theirCandidateChoice;
			CandidateMap localCandidates;

			boost::shared_ptr<TransportSession> transportSession;

			boost::bsignals::scoped_connection localTransportCandidatesGeneratedConnection;
			boost::bsignals::scoped_connection remoteTransportCandidateSelectFinishedConnection;
			boost::bsignals::scoped_connection proxyActivatedConnection;
	};
}