1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-27 14:32:06 +01:00

remove unused code

This commit is contained in:
vanitasvitae 2017-06-10 17:46:57 +02:00
parent 830b2deb2e
commit e5edb4cd04
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 45 additions and 54 deletions

View file

@ -47,6 +47,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.element.JingleReason;
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
import org.jivesoftware.smackx.jingle_filetransfer.callback.JingleFileTransferCallback;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
@ -120,10 +121,6 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
}
}
public void addFileTransferRejectedListener() {
}
/**
* QnD method.
* @param file
@ -189,64 +186,26 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
return null;
}
JingleTransportManager tm = JingleTransportManager.getInstanceFor(connection());
String transportNamespace = jingle.getContents().get(0).getJingleTransports().get(0).getNamespace();
AbstractJingleTransportManager<?> transportManager = null;
for (AbstractJingleTransportManager<?> b : tm.getAvailableJingleBytestreamManagers()) {
if (b.getNamespace().equals(transportNamespace)) {
transportManager = b;
}
}
if (transportManager == null) {
//TODO unsupported-transport?
return null;
}
final AbstractJingleTransportManager<?> finalTransportManager = transportManager;
notifyIncomingFileTransferListeners(jingle, new JingleFileTransferCallback() {
@Override
public void accept(final File target) throws Exception {
public void acceptFileTransfer(final File target) throws Exception {
connection().sendStanza(sessionAccept(jingle));
JingleManager.FullJidAndSessionId fullJidAndSessionId =
new JingleManager.FullJidAndSessionId(
jingle.getFrom().asFullJidIfPossible(), jingle.getSid());
ResponderIncomingFileTransferAccepted responded = new ResponderIncomingFileTransferAccepted(
JingleFileTransferManager.this, jingle, target);
jingleManager.registerJingleSessionHandler(jingle.getFrom().asFullJidIfPossible(), jingle.getSid(),
responded);
finalTransportManager.createJingleTransportHandler(responded).establishIncomingSession(fullJidAndSessionId,
jingle.getContents().get(0).getJingleTransports().get(0),
new JingleTransportEstablishedCallback() {
@Override
public void onSessionEstablished(BytestreamSession bytestreamSession) {
receiveFile(jingle, bytestreamSession, target);
}
@Override
public void onSessionFailure(JingleTransportFailureException reason) {
}
});
}
@Override
public void decline() throws SmackException.NotConnectedException, InterruptedException {
//TODO
public void declineFileTransfer() throws SmackException.NotConnectedException, InterruptedException {
connection().sendStanza(decline(jingle));
}
});
return IQ.createResultIQ(jingle);
}
protected Jingle sessionInitiate(FullJid recipient, JingleContentDescription contentDescription, JingleContentTransport transport) {
public Jingle sessionInitiate(FullJid recipient, JingleContentDescription contentDescription, JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setSessionId(StringUtils.randomString(24))
.setAction(JingleAction.session_initiate)
@ -267,7 +226,7 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
return jingle;
}
protected Jingle sessionAccept(Jingle request) throws Exception {
public Jingle sessionAccept(Jingle request) throws Exception {
JingleContent content = request.getContents().get(0);
Jingle.Builder jb = Jingle.getBuilder();
@ -295,6 +254,18 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
return jingle;
}
public Jingle decline(Jingle request) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setResponder(connection().getUser())
.setAction(JingleAction.session_terminate)
.setReason(JingleReason.Reason.decline)
.setSessionId(request.getSid());
Jingle jingle = jb.build();
jingle.setTo(request.getFrom());
jingle.setFrom(connection().getUser());
return jingle;
}
public void receiveFile(Jingle request, BytestreamSession session, File target) {
JingleFileTransferChild file = (JingleFileTransferChild)
request.getContents().get(0).getDescription().getJingleContentDescriptionChildren().get(0);

View file

@ -19,15 +19,13 @@ package org.jivesoftware.smackx.jingle_filetransfer.callback;
import java.io.File;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
/**
* Callback that allows the user to accept or cancel file transfers.
*/
public interface JingleFileTransferCallback {
void accept(File target) throws Exception;
void acceptFileTransfer(File target) throws Exception;
void decline() throws SmackException.NotConnectedException, InterruptedException;
void declineFileTransfer() throws SmackException.NotConnectedException, InterruptedException;
}

View file

@ -22,10 +22,14 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
import org.jivesoftware.smackx.jingle.JingleTransportEstablishedCallback;
import org.jivesoftware.smackx.jingle.JingleTransportManager;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
import org.jivesoftware.smackx.jingle_filetransfer.JingleFileTransferManager;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
@ -45,7 +49,7 @@ public class ResponderIncomingFileTransferAccepted implements JingleSessionHandl
private final FullJid initiator;
private final String sessionId;
public ResponderIncomingFileTransferAccepted(JingleFileTransferManager manager, Jingle initiate, File target) {
public ResponderIncomingFileTransferAccepted(final JingleFileTransferManager manager, final Jingle initiate, final File target) {
this.manager = new WeakReference<>(manager);
this.target = target;
this.size = ((JingleFileTransferChild) initiate.getContents().get(0).getDescription()
@ -57,6 +61,21 @@ public class ResponderIncomingFileTransferAccepted implements JingleSessionHandl
}
this.initiator = initiate.getInitiator();
this.sessionId = initiate.getSid();
transportManager.createJingleTransportHandler(this).establishIncomingSession(
new JingleManager.FullJidAndSessionId(initiate.getFrom().asFullJidIfPossible(), initiate.getSid()),
initiate.getContents().get(0).getJingleTransports().get(0),
new JingleTransportEstablishedCallback() {
@Override
public void onSessionEstablished(BytestreamSession bytestreamSession) {
manager.receiveFile(initiate, bytestreamSession, target);
}
@Override
public void onSessionFailure(JingleTransportFailureException reason) {
}
});
}
@Override

View file

@ -22,8 +22,11 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
}
@Override
public void establishOutgoingSession(JingleManager.FullJidAndSessionId target, JingleContentTransport transport, JingleTransportEstablishedCallback callback) {
public void establishOutgoingSession(JingleManager.FullJidAndSessionId target, JingleContentTransport hopefullyS5BTransport, JingleTransportEstablishedCallback callback) {
if (!hopefullyS5BTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) {
throw new IllegalArgumentException("Transport must be a JingleS5BTransport.");
}
JingleS5BTransport transport = (JingleS5BTransport) hopefullyS5BTransport;
}
@Override