From c0e5fcf7371953820bb12418abe1cef0e55d12a1 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Tue, 25 Jul 2017 20:25:36 +0200 Subject: [PATCH] Some work on Jingle File Transfer --- .../smackx/jft/internal/JingleFileOffer.java | 31 ++++++++++ .../jft/internal/JingleFileRequest.java | 7 +++ .../JingleFileRequest.java | 2 + .../exception/FailedTransportException.java | 13 ++++ .../smackx/jingle/internal/JingleContent.java | 15 +++++ .../jingle/internal/JingleDescription.java | 3 + .../jingle/internal/JingleTransport.java | 18 ++++-- .../jingle_ibb/JingleIBBTransport.java | 60 +++++++++++-------- .../jingle_s5b/JingleS5BTransport.java | 31 ++++++---- .../jingle_s5b/S5BTransportException.java | 29 +++++++++ 10 files changed, 166 insertions(+), 43 deletions(-) create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/exception/FailedTransportException.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/S5BTransportException.java diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileOffer.java index 448e78acb..68427a13e 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileOffer.java @@ -1,7 +1,38 @@ package org.jivesoftware.smackx.jft.internal; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jivesoftware.smackx.bytestreams.BytestreamSession; + /** * Created by vanitas on 22.07.17. */ public class JingleFileOffer extends JingleFileTransfer { + + private static final Logger LOGGER = Logger.getLogger(JingleFileOffer.class.getName()); + + private File file; + + public JingleFileOffer(File file) { + super(); + this.file = file; + } + + @Override + public void onTransportReady(BytestreamSession bytestreamSession) { + OutputStream outputStream; + + try { + outputStream = bytestreamSession.getOutputStream(); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "Error retrieving outputStream: " + e, e); + return; + } + + + } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileRequest.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileRequest.java index 94a986601..75465d757 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileRequest.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleFileRequest.java @@ -1,7 +1,14 @@ package org.jivesoftware.smackx.jft.internal; +import org.jivesoftware.smackx.bytestreams.BytestreamSession; + /** * Created by vanitas on 22.07.17. */ public class JingleFileRequest extends JingleFileTransfer { + + @Override + public void onTransportReady(BytestreamSession bytestreamSession) { + + } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java index 2dcddaf26..8a81c293f 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java @@ -17,6 +17,8 @@ package org.jivesoftware.smackx.jingle_filetransfer; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smackx.jingle.JingleManager; +import org.jivesoftware.smackx.jingle.Role; import org.jivesoftware.smackx.jingle.element.JingleElement; import org.jxmpp.jid.FullJid; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/exception/FailedTransportException.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/exception/FailedTransportException.java new file mode 100644 index 000000000..86eb907ff --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/exception/FailedTransportException.java @@ -0,0 +1,13 @@ +package org.jivesoftware.smackx.jingle.exception; + +/** + * Created by vanitas on 25.07.17. + */ +public class FailedTransportException extends Exception { + + protected static final long serialVersionUID = 1L; + + public FailedTransportException(Throwable throwable) { + super(throwable); + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java index bd79c1f96..abce4ca62 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.adapter.JingleDescriptionAdapter; import org.jivesoftware.smackx.jingle.adapter.JingleTransportAdapter; @@ -176,6 +177,20 @@ public class JingleContent { } } + public void onTransportReady() { + BytestreamSession bytestreamSession = transport.getBytestreamSession(); + + if (bytestreamSession == null) { + throw new AssertionError("bytestreamSession MUST NOT be null at this point."); + } + + description.onTransportReady(bytestreamSession); + } + + public void onTransportFailed(Exception e) { + + } + public static String randomName() { return "cont-" + StringUtils.randomString(16); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java index cd77c9a83..bcbd1c93b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java @@ -16,6 +16,7 @@ */ package org.jivesoftware.smackx.jingle.internal; +import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement; /** @@ -36,4 +37,6 @@ public abstract class JingleDescription { private JingleTransport peersProposal; private boolean isPeersProposal; + protected BytestreamSession bytestreamSession; + public abstract D getElement(); public void addCandidate(JingleTransportCandidate candidate) { @@ -72,11 +74,11 @@ public abstract class JingleTransport { public abstract String getNamespace(); - public abstract void establishIncomingBytestreamSession(BytestreamSessionEstablishedListener listener, - XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException; + public abstract void establishIncomingBytestreamSession(XMPPConnection connection) + throws SmackException.NotConnectedException, InterruptedException; - public abstract void establishOutgoingBytestreamSession(BytestreamSessionEstablishedListener listener, - XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException; + public abstract void establishOutgoingBytestreamSession(XMPPConnection connection) + throws SmackException.NotConnectedException, InterruptedException; public void setPeersProposal(JingleTransport peersProposal) { this.peersProposal = peersProposal; @@ -102,4 +104,8 @@ public abstract class JingleTransport { public JingleContent getParent() { return parent; } + + public BytestreamSession getBytestreamSession() { + return bytestreamSession; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java index 58517829c..7349d6786 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java @@ -20,16 +20,16 @@ import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.util.StringUtils; -import org.jivesoftware.smackx.bytestreams.BytestreamListener; -import org.jivesoftware.smackx.bytestreams.BytestreamRequest; import org.jivesoftware.smackx.bytestreams.BytestreamSession; +import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamListener; import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager; +import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamRequest; +import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement; import org.jivesoftware.smackx.jingle.element.JingleElement; +import org.jivesoftware.smackx.jingle.internal.JingleSession; import org.jivesoftware.smackx.jingle.internal.JingleTransport; import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate; import org.jivesoftware.smackx.jingle.transport.BytestreamSessionEstablishedListener; -import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement; -import org.jivesoftware.smackx.jingle.internal.JingleSession; import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement; /** @@ -71,38 +71,48 @@ public class JingleIBBTransport extends JingleTransport peers.getSelectedCandidate().getPriority()) { nominated = getSelectedCandidate(); } else if (getSelectedCandidate().getPriority() < peers.getSelectedCandidate().getPriority()) { @@ -197,6 +198,7 @@ public class JingleS5BTransport extends JingleTransport