summaryrefslogtreecommitdiffstats
blob: 4ba17de39858574979f8893f61e23ce82ac9cca1 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (c) 2010-2015 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */
/*
 * Copyright (c) 2015 Tarun Gupta.
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

package com.isode.stroke.filetransfer;

import com.isode.stroke.jid.JID;
import com.isode.stroke.queries.IQRouter;
import com.isode.stroke.signals.Signal1;
import com.isode.stroke.elements.ErrorPayload;
import com.isode.stroke.elements.StreamInitiation;
import com.isode.stroke.elements.Bytestreams;

public class OutgoingSIFileTransfer implements OutgoingFileTransfer {

	private long fileSizeInBytes = 0; //FileTransferVariables
	private String filename = ""; //FileTransferVariables

	/**
	* FileTransferMethod.
	*/
	@Override
	public String getFileName() {
		return filename;
	}

	/**
	* FileTransferMethod.
	*/
	@Override
	public long getFileSizeInBytes() {
		return fileSizeInBytes;
	}

	/**
	* FileTransferMethod.
	*/
	@Override
	public void setFileInfo(final String name, long size) {
		this.filename = name;
		this.fileSizeInBytes = size;
	}

	private String id = "";
	private JID from;
	private JID to;
	private String name = "";
	private long size;
	private String description = "";
	private ReadBytestream bytestream;
	private IQRouter iqRouter;
	private SOCKS5BytestreamServer socksServer;
	private IBBSendSession ibbSession;

	public OutgoingSIFileTransfer(final String id, final JID from, final JID to, final String name, long size, final String description, ReadBytestream bytestream, IQRouter iqRouter, SOCKS5BytestreamServer socksServer) {
		this.id = id;
		this.from = from;
		this.to = to;
		this.name = name;
		this.size = size;
		this.description = description;
		this.bytestream = bytestream;
		this.iqRouter = iqRouter;
		this.socksServer = socksServer;
		this.ibbSession = ibbSession;
	}

	/**
	* OutgoingFileTransferMethod.
	*/
	@Override
	public void 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(to, streamInitiation, iqRouter);
		request.onResponse.connect(boost::bind(&OutgoingSIFileTransfer::handleStreamInitiationRequestResponse, this, _1, _2));
		request.send();
		*/
	}

	public void stop() {
	}

	public final Signal1<FileTransferError> onFinished = new Signal1<FileTransferError>();

	private void handleStreamInitiationRequestResponse(StreamInitiation stream, ErrorPayload error) {
		/*
		if (error) {
			finish(FileTransferError());
		}
		else {
			if (response->getRequestedMethod() == "http://jabber.org/protocol/bytestreams") {
				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(to, bytestreams, iqRouter);
				request->onResponse.connect(boost::bind(&OutgoingSIFileTransfer::handleBytestreamsRequestResponse, this, _1, _2));
				request->send();
			}
			else if (response->getRequestedMethod() == "http://jabber.org/protocol/ibb") {
				ibbSession = boost::make_shared<IBBSendSession>(id, from, to, bytestream, iqRouter);
				ibbSession->onFinished.connect(boost::bind(&OutgoingSIFileTransfer::handleIBBSessionFinished, this, _1));
				ibbSession->start();
			}
		}
		*/
	}

	private void handleBytestreamsRequestResponse(Bytestreams stream, ErrorPayload error) {
		/*
		if (error) {
			finish(FileTransferError());
		}
		*/
		//socksServer->onTransferFinished.connect();
	}

	private void finish(FileTransferError error) {
		/*
		if (ibbSession) {
			ibbSession->onFinished.disconnect(boost::bind(&OutgoingSIFileTransfer::handleIBBSessionFinished, this, _1));
			ibbSession.reset();
		}
		socksServer->removeReadBytestream(id, from, to);
		onFinished(error);
		*/
	}

	private void handleIBBSessionFinished(FileTransferError error) {
		//finish(error);
	}

	public void cancel() {
		
	}
}