2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2006 Jive Software.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.filetransfer;
|
|
|
|
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.si.packet.StreamInitiation;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2017-07-06 14:01:28 +02:00
|
|
|
* A request to send a file received from another user.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Alexander Wenckus
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
|
|
|
public class FileTransferRequest {
|
2017-02-07 22:02:40 +01:00
|
|
|
private final StreamInitiation streamInitiation;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
private final FileTransferManager manager;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2017-07-06 14:01:28 +02:00
|
|
|
* A receive request is constructed from the Stream Initiation request
|
|
|
|
* received from the initiator.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param manager TODO javadoc me please
|
2017-02-07 22:02:40 +01:00
|
|
|
* The manager handling this file transfer
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param si TODO javadoc me please
|
2017-07-06 14:01:28 +02:00
|
|
|
* The Stream initiation received from the initiator.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
|
|
|
public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
|
|
|
|
this.streamInitiation = si;
|
|
|
|
this.manager = manager;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the name of the file.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return Returns the name of the file.
|
|
|
|
*/
|
|
|
|
public String getFileName() {
|
|
|
|
return streamInitiation.getFile().getName();
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the size in bytes of the file.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return Returns the size in bytes of the file.
|
|
|
|
*/
|
|
|
|
public long getFileSize() {
|
|
|
|
return streamInitiation.getFile().getSize();
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2017-07-06 14:01:28 +02:00
|
|
|
* Returns the description of the file provided by the requester.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-07-06 14:01:28 +02:00
|
|
|
* @return Returns the description of the file provided by the requester.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
|
|
|
public String getDescription() {
|
|
|
|
return streamInitiation.getFile().getDesc();
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the mime-type of the file.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return Returns the mime-type of the file.
|
|
|
|
*/
|
|
|
|
public String getMimeType() {
|
|
|
|
return streamInitiation.getMimeType();
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the fully-qualified jabber ID of the user that requested this
|
|
|
|
* file transfer.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return Returns the fully-qualified jabber ID of the user that requested
|
|
|
|
* this file transfer.
|
|
|
|
*/
|
|
|
|
public Jid getRequestor() {
|
|
|
|
return streamInitiation.getFrom();
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Returns the stream ID that uniquely identifies this file transfer.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-02-07 22:02:40 +01:00
|
|
|
* @return Returns the stream ID that uniquely identifies this file
|
|
|
|
* transfer.
|
|
|
|
*/
|
|
|
|
public String getStreamID() {
|
|
|
|
return streamInitiation.getSessionID();
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Returns the stream initiation stanza that was sent by the requester which
|
2017-02-07 22:02:40 +01:00
|
|
|
* contains the parameters of the file transfer being transfer and also the
|
|
|
|
* methods available to transfer the file.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return Returns the stream initiation stanza that was sent by the
|
2017-07-06 14:01:28 +02:00
|
|
|
* requester which contains the parameters of the file transfer
|
2017-02-07 22:02:40 +01:00
|
|
|
* being transfer and also the methods available to transfer the
|
|
|
|
* file.
|
|
|
|
*/
|
|
|
|
protected StreamInitiation getStreamInitiation() {
|
|
|
|
return streamInitiation;
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Accepts this file transfer and creates the incoming file transfer.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2017-12-25 12:51:41 +01:00
|
|
|
* @return Returns the IncomingFileTransfer on which the
|
2017-02-07 22:02:40 +01:00
|
|
|
* file transfer can be carried out.
|
|
|
|
*/
|
|
|
|
public IncomingFileTransfer accept() {
|
|
|
|
return manager.createIncomingFileTransfer(this);
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
/**
|
|
|
|
* Rejects the file transfer request.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws NotConnectedException if the XMPP connection is not connected.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
2017-02-07 22:02:40 +01:00
|
|
|
*/
|
|
|
|
public void reject() throws NotConnectedException, InterruptedException {
|
|
|
|
manager.rejectIncomingFileTransfer(this);
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
}
|