1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00
This commit is contained in:
vanitasvitae 2017-07-28 14:02:32 +02:00
parent b0c8a8027a
commit 185d569b89
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
18 changed files with 266 additions and 65 deletions

View file

@ -23,8 +23,11 @@ import java.util.List;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jft.adapter.JingleFileTransferAdapter;
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController; import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController; import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController;
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer; import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
@ -32,6 +35,7 @@ import org.jivesoftware.smackx.jft.internal.JingleIncomingFileOffer;
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileRequest; import org.jivesoftware.smackx.jft.internal.JingleIncomingFileRequest;
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer; import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer;
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileRequest; import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileRequest;
import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
import org.jivesoftware.smackx.jft.listener.IncomingFileOfferListener; import org.jivesoftware.smackx.jft.listener.IncomingFileOfferListener;
import org.jivesoftware.smackx.jft.listener.IncomingFileRequestListener; import org.jivesoftware.smackx.jft.listener.IncomingFileRequestListener;
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider; import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
@ -59,6 +63,10 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
private final List<IncomingFileRequestListener> requestListeners = private final List<IncomingFileRequestListener> requestListeners =
Collections.synchronizedList(new ArrayList<IncomingFileRequestListener>()); Collections.synchronizedList(new ArrayList<IncomingFileRequestListener>());
static {
JingleManager.addJingleDescriptionAdapter(new JingleFileTransferAdapter());
}
private JingleFileTransferManager(XMPPConnection connection) { private JingleFileTransferManager(XMPPConnection connection) {
super(connection); super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace()); ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
@ -78,7 +86,10 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
return manager; return manager;
} }
public OutgoingFileOfferController sendFile(File file, FullJid to) { public OutgoingFileOfferController sendFile(File file, FullJid to)
throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
SmackException.NoResponseException {
if (file == null || !file.exists()) { if (file == null || !file.exists()) {
throw new IllegalArgumentException("File MUST NOT be null and MUST exist."); throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
} }
@ -94,12 +105,13 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(); JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager();
content.setTransport(transportManager.createTransport(content)); content.setTransport(transportManager.createTransport(content));
//TODO session.initiate(connection());
return offer; return offer;
} }
public OutgoingFileRequestController requestFile() { public OutgoingFileRequestController requestFile(RemoteFile file) {
JingleOutgoingFileRequest request = new JingleOutgoingFileRequest(); JingleOutgoingFileRequest request = new JingleOutgoingFileRequest(file);
//TODO at some point. //TODO at some point.
@ -116,7 +128,7 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
public void notifyIncomingFileOfferListeners(JingleIncomingFileOffer offer) { public void notifyIncomingFileOfferListeners(JingleIncomingFileOffer offer) {
for (IncomingFileOfferListener l : offerListeners) { for (IncomingFileOfferListener l : offerListeners) {
l.onIncomingFileTransfer(offer); l.onIncomingFileOffer(offer);
} }
} }

View file

@ -0,0 +1,57 @@
/**
*
* Copyright 2017 Paul Schaub
*
* 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.jft.adapter;
import java.util.List;
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileOffer;
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileRequest;
import org.jivesoftware.smackx.jingle.adapter.JingleDescriptionAdapter;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
/**
* Created by vanitas on 28.07.17.
*/
public class JingleFileTransferAdapter implements JingleDescriptionAdapter<JingleFileTransfer> {
@Override
public JingleFileTransfer descriptionFromElement(JingleContentElement.Creator creator, JingleContentElement.Senders senders,
String contentName, String contentDisposition, JingleContentDescriptionElement element) {
JingleFileTransferElement description = (JingleFileTransferElement) element;
List<JingleContentDescriptionChildElement> childs = description.getJingleContentDescriptionChildren();
assert childs.size() == 1;
JingleFileTransferChildElement file = (JingleFileTransferChildElement) childs.get(0);
if (senders == JingleContentElement.Senders.initiator) {
return new JingleIncomingFileOffer(file);
} else if (senders == JingleContentElement.Senders.responder) {
return new JingleIncomingFileRequest(file);
} else {
throw new AssertionError("Senders attribute MUST be either initiator or responder. Is: " + senders);
}
}
@Override
public String getNamespace() {
return JingleFileTransfer.NAMESPACE;
}
}

View file

@ -16,9 +16,12 @@
*/ */
package org.jivesoftware.smackx.jft.controller; package org.jivesoftware.smackx.jft.controller;
import java.io.File;
import java.util.concurrent.Future;
/** /**
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public interface IncomingFileOfferController extends JingleFileTransferController { public interface IncomingFileOfferController extends JingleFileTransferController {
Future<Void> accept(File target);
} }

View file

@ -16,7 +16,6 @@
*/ */
package org.jivesoftware.smackx.jft.internal; package org.jivesoftware.smackx.jft.internal;
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile; import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
/** /**
@ -24,15 +23,7 @@ import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
*/ */
public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransferFile> extends JingleFileTransfer { public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransferFile> extends JingleFileTransfer {
protected D jingleFile;
public AbstractJingleFileOffer(D fileTransferFile) { public AbstractJingleFileOffer(D fileTransferFile) {
super(); super(fileTransferFile);
this.jingleFile = fileTransferFile;
}
@Override
public JingleFileTransferElement getElement() {
return new JingleFileTransferElement(jingleFile.getElement());
} }
} }

View file

@ -16,9 +16,15 @@
*/ */
package org.jivesoftware.smackx.jft.internal; package org.jivesoftware.smackx.jft.internal;
import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
/** /**
* Created by vanitas on 22.07.17. * Created by vanitas on 22.07.17.
*/ */
public abstract class AbstractJingleFileRequest extends JingleFileTransfer { public abstract class AbstractJingleFileRequest<D extends AbstractJingleFileTransferFile> extends JingleFileTransfer {
public AbstractJingleFileRequest(D fileTransferFile) {
super(fileTransferFile);
}
} }

View file

@ -22,6 +22,7 @@ import java.util.List;
import org.jivesoftware.smackx.jft.controller.JingleFileTransferController; import org.jivesoftware.smackx.jft.controller.JingleFileTransferController;
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement; import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
import org.jivesoftware.smackx.jft.listener.ProgressListener; import org.jivesoftware.smackx.jft.listener.ProgressListener;
import org.jivesoftware.smackx.jingle.components.JingleDescription; import org.jivesoftware.smackx.jingle.components.JingleDescription;
@ -37,9 +38,14 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
public abstract boolean isRequest(); public abstract boolean isRequest();
protected State state; protected State state;
protected AbstractJingleFileTransferFile file;
protected final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>()); protected final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>());
public JingleFileTransfer(AbstractJingleFileTransferFile file) {
this.file = file;
}
@Override @Override
public void addProgressListener(ProgressListener listener) { public void addProgressListener(ProgressListener listener) {
progressListeners.add(listener); progressListeners.add(listener);
@ -57,6 +63,16 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
} }
} }
@Override
public String getNamespace() {
return JingleFileTransfer.NAMESPACE;
}
@Override
public JingleFileTransferElement getElement() {
return new JingleFileTransferElement(file.getElement());
}
@Override @Override
public State getState() { public State getState() {
return state; return state;

View file

@ -16,8 +16,10 @@
*/ */
package org.jivesoftware.smackx.jft.internal; package org.jivesoftware.smackx.jft.internal;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -25,6 +27,9 @@ import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController; import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement; import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
import org.jivesoftware.smackx.jft.internal.file.RemoteFile; import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
/** /**
* Created by vanitas on 26.07.17. * Created by vanitas on 26.07.17.
@ -37,6 +42,11 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
super(new RemoteFile(offer)); super(new RemoteFile(offer));
} }
@Override
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
return null;
}
@Override @Override
public void onTransportReady(BytestreamSession bytestreamSession) { public void onTransportReady(BytestreamSession bytestreamSession) {
InputStream inputStream; InputStream inputStream;
@ -57,4 +67,14 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
public boolean isRequest() { public boolean isRequest() {
return false; return false;
} }
@Override
public Future<Void> accept(File target) {
JingleSession session = getParent().getParent();
if (session.getSessionState() == JingleSession.SessionState.pending) {
//session.accept();
}
return null;
}
} }

View file

@ -18,17 +18,32 @@ package org.jivesoftware.smackx.jft.internal;
import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jft.controller.IncomingFileRequestController; import org.jivesoftware.smackx.jft.controller.IncomingFileRequestController;
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement; import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
/** /**
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
* TODO: RemoteFile????
*/ */
public class JingleIncomingFileRequest extends AbstractJingleFileRequest implements IncomingFileRequestController { public class JingleIncomingFileRequest extends AbstractJingleFileRequest<RemoteFile> implements IncomingFileRequestController {
public JingleIncomingFileRequest(JingleFileTransferChildElement request) {
super(new RemoteFile(request));
}
@Override @Override
public JingleFileTransferElement getElement() { public JingleFileTransferElement getElement() {
return null; return null;
} }
@Override
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
return null;
}
@Override @Override
public boolean isOffer() { public boolean isOffer() {
return false; return false;

View file

@ -21,6 +21,8 @@ import java.io.File;
import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController; import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
import org.jivesoftware.smackx.jft.internal.file.LocalFile; import org.jivesoftware.smackx.jft.internal.file.LocalFile;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
/** /**
* Created by vanitas on 26.07.17. * Created by vanitas on 26.07.17.
@ -31,6 +33,11 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer<LocalFile>
super(new LocalFile(file)); super(new LocalFile(file));
} }
@Override
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
return null;
}
@Override @Override
public void onTransportReady(BytestreamSession bytestreamSession) { public void onTransportReady(BytestreamSession bytestreamSession) {

View file

@ -18,14 +18,21 @@ package org.jivesoftware.smackx.jft.internal;
import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController; import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController;
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement; import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
/** /**
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public class JingleOutgoingFileRequest extends AbstractJingleFileRequest implements OutgoingFileRequestController { public class JingleOutgoingFileRequest extends AbstractJingleFileRequest<RemoteFile> implements OutgoingFileRequestController {
public JingleOutgoingFileRequest(RemoteFile file) {
super(file);
}
@Override @Override
public JingleFileTransferElement getElement() { public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
return null; return null;
} }

View file

@ -23,5 +23,5 @@ import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
*/ */
public interface IncomingFileOfferListener { public interface IncomingFileOfferListener {
void onIncomingFileTransfer(IncomingFileOfferController offer); void onIncomingFileOffer(IncomingFileOfferController offer);
} }

View file

@ -243,10 +243,10 @@ public final class JingleManager extends Manager {
JingleSession session; JingleSession session;
if (role == Role.initiator) { if (role == Role.initiator) {
session = new JingleSession(this, connection().getUser().asDomainFullJidOrThrow(), peer, session = new JingleSession(this, connection().getUser().asFullJidOrThrow(), peer,
role, StringUtils.randomString(24)); role, StringUtils.randomString(24));
} else { } else {
session = new JingleSession(this, peer, connection().getUser().asDomainFullJidOrThrow(), session = new JingleSession(this, peer, connection().getUser().asFullJidOrThrow(),
role, StringUtils.randomString(24)); role, StringUtils.randomString(24));
} }

View file

@ -18,13 +18,15 @@ package org.jivesoftware.smackx.jingle.adapter;
import org.jivesoftware.smackx.jingle.components.JingleDescription; import org.jivesoftware.smackx.jingle.components.JingleDescription;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement; import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
/** /**
* Adapter that creates a Description object from an element. * Adapter that creates a Description object from an element.
*/ */
public interface JingleDescriptionAdapter<D extends JingleDescription<?>> { public interface JingleDescriptionAdapter<D extends JingleDescription<?>> {
D descriptionFromElement(JingleContentDescriptionElement element); D descriptionFromElement(JingleContentElement.Creator creator, JingleContentElement.Senders senders,
String contentName, String contentDisposition, JingleContentDescriptionElement element);
String getNamespace(); String getNamespace();
} }

View file

@ -95,7 +95,7 @@ public class JingleContent implements JingleTransportCallback {
if (descriptionElement != null) { if (descriptionElement != null) {
JingleDescriptionAdapter<?> descriptionAdapter = JingleManager.getJingleDescriptionAdapter(content.getDescription().getNamespace()); JingleDescriptionAdapter<?> descriptionAdapter = JingleManager.getJingleDescriptionAdapter(content.getDescription().getNamespace());
if (descriptionAdapter != null) { if (descriptionAdapter != null) {
description = descriptionAdapter.descriptionFromElement(descriptionElement); description = descriptionAdapter.descriptionFromElement(content.getCreator(), content.getSenders(), content.getName(), content.getDisposition(), descriptionElement);
} else { } else {
throw new AssertionError("DescriptionProvider for " + descriptionElement.getNamespace() + throw new AssertionError("DescriptionProvider for " + descriptionElement.getNamespace() +
" seems to be registered, but no corresponding JingleDescriptionAdapter was found."); " seems to be registered, but no corresponding JingleDescriptionAdapter was found.");
@ -108,7 +108,7 @@ public class JingleContent implements JingleTransportCallback {
if (transportAdapter != null) { if (transportAdapter != null) {
transport = transportAdapter.transportFromElement(transportElement); transport = transportAdapter.transportFromElement(transportElement);
} else { } else {
throw new AssertionError("DescriptionProvider for " + transportElement.getNamespace() + throw new AssertionError("TransportProvider for " + transportElement.getNamespace() +
" seems to be registered, but no corresponding JingleTransportAdapter was found."); " seems to be registered, but no corresponding JingleTransportAdapter was found.");
} }
} }
@ -132,15 +132,19 @@ public class JingleContent implements JingleTransportCallback {
} }
public JingleContentElement getElement() { public JingleContentElement getElement() {
return JingleContentElement.getBuilder() JingleContentElement.Builder builder = JingleContentElement.getBuilder()
.setName(name) .setName(name)
.setCreator(creator) .setCreator(creator)
.setSenders(senders) .setSenders(senders)
.setDescription(description.getElement()) .setDescription(description.getElement())
.setTransport(transport.getElement()) .setTransport(transport.getElement())
.setSecurity(security.getElement()) .setDisposition(disposition);
.setDisposition(disposition)
.build(); if (security != null) {
builder.setSecurity(security.getElement());
}
return builder.build();
} }
public Set<String> getTransportBlacklist() { public Set<String> getTransportBlacklist() {

View file

@ -27,6 +27,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.Async; import org.jivesoftware.smack.util.Async;
@ -60,6 +61,15 @@ public class JingleSession {
private final Role role; private final Role role;
private final String sessionId; private final String sessionId;
public enum SessionState {
fresh, //pre-session-inititate
pending, //pre-session-accept
active, //pre-session-terminate
ended //post-session-terminate
}
private SessionState sessionState;
private final Map<JingleContent, PendingJingleAction> pendingJingleActions = private final Map<JingleContent, PendingJingleAction> pendingJingleActions =
Collections.synchronizedMap(new HashMap<JingleContent, PendingJingleAction>()); Collections.synchronizedMap(new HashMap<JingleContent, PendingJingleAction>());
@ -69,6 +79,7 @@ public class JingleSession {
this.responder = responder; this.responder = responder;
this.role = role; this.role = role;
this.sessionId = sessionId; this.sessionId = sessionId;
this.sessionState = SessionState.fresh;
} }
public void addContent(JingleContent content) { public void addContent(JingleContent content) {
@ -114,9 +125,16 @@ public class JingleSession {
session.addContent(content); session.addContent(content);
} }
session.sessionState = SessionState.pending;
return session; return session;
} }
public void initiate(XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
connection.createStanzaCollectorAndSend(createSessionInitiate()).nextResultOrThrow();
this.sessionState = SessionState.pending;
}
public JingleElement createSessionInitiate() { public JingleElement createSessionInitiate() {
if (role != Role.initiator) { if (role != Role.initiator) {
throw new IllegalStateException("Sessions role is not initiator."); throw new IllegalStateException("Sessions role is not initiator.");
@ -216,6 +234,7 @@ public class JingleSession {
} }
private IQ handleSessionTerminate(JingleElement request) { private IQ handleSessionTerminate(JingleElement request) {
this.sessionState = SessionState.ended;
JingleReasonElement reason = request.getReason(); JingleReasonElement reason = request.getReason();
if (reason == null) { if (reason == null) {
@ -223,7 +242,6 @@ public class JingleSession {
} }
//TODO: Inform client. //TODO: Inform client.
jingleManager.removeSession(this); jingleManager.removeSession(this);
return IQ.createResultIQ(request); return IQ.createResultIQ(request);
@ -231,7 +249,9 @@ public class JingleSession {
private IQ handleTransportReject(JingleElement request) { private IQ handleTransportReject(JingleElement request) {
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request); HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
for (JingleContent c : affectedContents.values()) {
}
return null; return null;
} }
@ -283,6 +303,8 @@ public class JingleSession {
} }
private IQ handleSessionAccept(JingleElement request) { private IQ handleSessionAccept(JingleElement request) {
this.sessionState = SessionState.active;
return null; return null;
} }
@ -430,4 +452,8 @@ public class JingleSession {
} }
return map; return map;
} }
public SessionState getSessionState() {
return sessionState;
}
} }

View file

@ -37,6 +37,10 @@ public final class JingleIBBTransportManager extends Manager implements JingleTr
private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>(); private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>();
static {
JingleManager.addJingleTransportAdapter(new JingleIBBTransportAdapter());
}
private JingleIBBTransportManager(XMPPConnection connection) { private JingleIBBTransportManager(XMPPConnection connection) {
super(connection); super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace()); ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());

View file

@ -68,6 +68,10 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
private static boolean useLocalCandidates = true; private static boolean useLocalCandidates = true;
private static boolean useExternalCandidates = true; private static boolean useExternalCandidates = true;
static {
JingleManager.addJingleTransportAdapter(new JingleS5BTransportAdapter());
}
private JingleS5BTransportManager(XMPPConnection connection) { private JingleS5BTransportManager(XMPPConnection connection) {
super(connection); super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace()); ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());

View file

@ -16,20 +16,35 @@
*/ */
package org.jivesoftware.smackx.jft; package org.jivesoftware.smackx.jft;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertArrayEquals;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.Future;
import java.util.logging.Level;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy; import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
import org.jivesoftware.smackx.jft.listener.IncomingFileOfferListener;
import org.jivesoftware.smackx.jft.listener.ProgressListener;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransportManager;
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest; import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.jxmpp.jid.FullJid;
/** /**
* Created by vanitas on 29.06.17. * Created by vanitas on 29.06.17.
*/ */
public class FileTransferTest extends AbstractSmackIntegrationTest { public class JingleFileTransferTest extends AbstractSmackIntegrationTest {
private static final File tempDir; private static final File tempDir;
@ -43,13 +58,16 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
} }
} }
public FileTransferTest(SmackIntegrationTestEnvironment environment) { public JingleFileTransferTest(SmackIntegrationTestEnvironment environment) {
super(environment); super(environment);
} }
/*
@SmackIntegrationTest @SmackIntegrationTest
public void basicFileTransferTest() { public void basicFileTransferTest() throws Exception {
JingleIBBTransportManager.getInstanceFor(conOne);
JingleIBBTransportManager.getInstanceFor(conTwo);
final SimpleResultSyncPoint resultSyncPoint1 = new SimpleResultSyncPoint(); final SimpleResultSyncPoint resultSyncPoint1 = new SimpleResultSyncPoint();
final SimpleResultSyncPoint resultSyncPoint2 = new SimpleResultSyncPoint(); final SimpleResultSyncPoint resultSyncPoint2 = new SimpleResultSyncPoint();
@ -59,45 +77,55 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
File source = prepareNewTestFile("source"); File source = prepareNewTestFile("source");
final File target = new File(tempDir, "target"); final File target = new File(tempDir, "target");
JingleFileTransferManagerAlt aftm = JingleFileTransferManagerAlt.getInstanceFor(conOne); JingleFileTransferManager aftm = JingleFileTransferManager.getInstanceFor(conOne);
JingleFileTransferManagerAlt bftm = JingleFileTransferManagerAlt.getInstanceFor(conTwo); JingleFileTransferManager bftm = JingleFileTransferManager.getInstanceFor(conTwo);
bftm.addJingleFileTransferOfferListener(new JingleFileTransferOfferListener() { final ArrayList<Future<Void>> receiveFuture = new ArrayList<>(); //Uglaay
bftm.addIncomingFileOfferListener(new IncomingFileOfferListener() {
@Override @Override
public void onFileOffer(JingleElement request, IncomingFileOfferCallback callback) { public void onIncomingFileOffer(IncomingFileOfferController offer) {
FileTransferHandler handler2 = callback.acceptIncomingFileOffer(request, target); LOGGER.log(Level.INFO, "INCOMING FILE TRANSFER!");
handler2.addEndedListener(new FileTransferHandler.EndedListener() { offer.addProgressListener(new ProgressListener() {
@Override @Override
public void onEnded(JingleReasonElement.Reason reason) { public void started() {
}
@Override
public void progress(float percent) {
}
@Override
public void finished() {
resultSyncPoint2.signal(); resultSyncPoint2.signal();
} }
}); });
receiveFuture.add(offer.accept(target));
} }
}); });
try { OutgoingFileOfferController sending = aftm.sendFile(source, bob);
FileTransferHandler handler = aftm.sendFile(bob, source); sending.addProgressListener(new ProgressListener() {
handler.addEndedListener(new FileTransferHandler.EndedListener() { @Override
@Override public void started() {
public void onEnded(JingleReasonElement.Reason reason) {
resultSyncPoint1.signal();
}
});
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
fail();
}
try { }
resultSyncPoint1.waitForResult(10 * 1000);
} catch (Exception e) {
fail();
}
try { @Override
resultSyncPoint2.waitForResult(10 * 1000); public void progress(float percent) {
} catch (Exception e) {
fail(); }
}
@Override
public void finished() {
resultSyncPoint1.signal();
}
});
resultSyncPoint1.waitForResult(60 * 1000);
resultSyncPoint2.waitForResult(60 * 1000);
byte[] sBytes = new byte[(int) source.length()]; byte[] sBytes = new byte[(int) source.length()];
byte[] tBytes = new byte[(int) target.length()]; byte[] tBytes = new byte[(int) target.length()];
@ -116,7 +144,6 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
LOGGER.log(Level.INFO, "SUCCESSFULLY SENT AND RECEIVED"); LOGGER.log(Level.INFO, "SUCCESSFULLY SENT AND RECEIVED");
} }
*/
private File prepareNewTestFile(String name) { private File prepareNewTestFile(String name) {
File testFile = new File(tempDir, name); File testFile = new File(tempDir, name);