From e28bfa1a64c2a65882492ab20abf668ad07b92eb Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Fri, 21 Jul 2017 23:51:06 +0200 Subject: [PATCH] Complete JingleElement and fix jingle tests --- .../jivesoftware/smackx/jingle/Callback.java | 6 +- .../jingle/JingleDescriptionManager.java | 4 +- .../smackx/jingle/JingleManager.java | 8 +- .../smackx/jingle/JingleTransportManager.java | 8 +- .../adapter/JingleDescriptionAdapter.java | 4 +- .../jingle/adapter/JingleSecurityAdapter.java | 4 +- .../adapter/JingleTransportAdapter.java | 4 +- .../smackx/jingle/element/JingleElement.java | 187 ++++++++++ .../{Content.java => JingleContent.java} | 38 +- ...escription.java => JingleDescription.java} | 8 +- .../{Security.java => JingleSecurity.java} | 8 +- .../{Session.java => JingleSession.java} | 54 +-- .../{Transport.java => JingleTransport.java} | 22 +- ...ate.java => JingleTransportCandidate.java} | 8 +- .../jingle/internal/PendingJingleAction.java | 12 +- .../jingle_ibb/JingleIBBTransport.java | 14 +- .../jingle_ibb/JingleIBBTransportManager.java | 8 +- .../jingle_s5b/JingleS5BTransport.java | 26 +- .../JingleS5BTransportCandidate.java | 8 +- .../jingle_s5b/JingleS5BTransportManager.java | 26 +- .../legacy/JingleS5BTransportSession.java | 94 ----- .../jingle/transport/legacy/JingleUtil.java | 332 ------------------ .../JingleContentProviderManagerTest.java | 16 +- .../smackx/jingle/JingleManagerTest.java | 91 ----- .../smackx/jingle/JingleSessionTest.java | 216 ------------ .../JingleTransportMethodManagerTest.java | 126 ------- .../smackx/jingle/JingleUtilTest.java | 67 ++-- .../jingle_ibb/JingleIBBTransportTest.java | 2 +- .../jingle_s5b/JingleS5BTransportTest.java | 2 +- 29 files changed, 358 insertions(+), 1045 deletions(-) rename smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/{Content.java => JingleContent.java} (82%) rename smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/{Description.java => JingleDescription.java} (82%) rename smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/{Security.java => JingleSecurity.java} (85%) rename smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/{Session.java => JingleSession.java} (85%) rename smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/{Transport.java => JingleTransport.java} (81%) rename smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/{TransportCandidate.java => JingleTransportCandidate.java} (82%) delete mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/legacy/JingleUtil.java delete mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleManagerTest.java delete mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java delete mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManagerTest.java rename smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/{transports => transport}/jingle_ibb/JingleIBBTransportTest.java (98%) rename smack-extensions/src/test/java/org/jivesoftware/smackx/{jingle3 => jingle}/transport/jingle_s5b/JingleS5BTransportTest.java (99%) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Callback.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Callback.java index bb0c649f9..81bead64b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Callback.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Callback.java @@ -16,16 +16,16 @@ */ package org.jivesoftware.smackx.jingle; -import org.jivesoftware.smackx.jingle.internal.Content; +import org.jivesoftware.smackx.jingle.internal.JingleContent; /** * User callback that the user can use to control a jingle content. */ public abstract class Callback { - private final Content content; + private final JingleContent content; - public Callback(Content content) { + public Callback(JingleContent content) { this.content = content; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleDescriptionManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleDescriptionManager.java index e5f22fd70..83db5d3a5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleDescriptionManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleDescriptionManager.java @@ -18,7 +18,7 @@ package org.jivesoftware.smackx.jingle; import org.jivesoftware.smackx.jingle.callbacks.ContentAddCallback; import org.jivesoftware.smackx.jingle.element.JingleElement; -import org.jivesoftware.smackx.jingle.internal.Content; +import org.jivesoftware.smackx.jingle.internal.JingleContent; /** * Manager for JingleDescription components. @@ -27,5 +27,5 @@ public interface JingleDescriptionManager { String getNamespace(); - JingleElement notifyContentListeners(Content content, ContentAddCallback callback); + JingleElement notifyContentListeners(JingleContent content, ContentAddCallback callback); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java index a479ecbcc..714834b92 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java @@ -39,7 +39,7 @@ import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleReasonElement; import org.jivesoftware.smackx.jingle.exception.UnsupportedDescriptionException; import org.jivesoftware.smackx.jingle.exception.UnsupportedSecurityException; -import org.jivesoftware.smackx.jingle.internal.Session; +import org.jivesoftware.smackx.jingle.internal.JingleSession; import org.jivesoftware.smackx.jingle.provider.JingleContentDescriptionProvider; import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider; @@ -63,7 +63,7 @@ public class JingleManager extends Manager { private final WeakHashMap transportManagers = new WeakHashMap<>(); private final WeakHashMap securityManagers = new WeakHashMap<>(); - private final ConcurrentHashMap jingleSessions = new ConcurrentHashMap<>(); + private final ConcurrentHashMap jingleSessions = new ConcurrentHashMap<>(); private JingleManager(XMPPConnection connection) { super(connection); @@ -78,7 +78,7 @@ public class JingleManager extends Manager { String sid = jingle.getSid(); FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(fullFrom, sid); - Session session = jingleSessions.get(fullJidAndSessionId); + JingleSession session = jingleSessions.get(fullJidAndSessionId); // We have not seen this session before. // Either it is fresh, or unknown. @@ -87,7 +87,7 @@ public class JingleManager extends Manager { if (jingle.getAction() == JingleAction.session_initiate) { //fresh. phew! try { - session = Session.fromSessionInitiate(JingleManager.this, jingle); + session = JingleSession.fromSessionInitiate(JingleManager.this, jingle); jingleSessions.put(fullJidAndSessionId, session); } catch (UnsupportedDescriptionException e) { return JingleElement.createSessionTerminate(jingle.getFrom().asFullJidOrThrow(), diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportManager.java index 502e5d4b1..478c57f0d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportManager.java @@ -16,8 +16,8 @@ */ package org.jivesoftware.smackx.jingle; -import org.jivesoftware.smackx.jingle.internal.Content; -import org.jivesoftware.smackx.jingle.internal.Transport; +import org.jivesoftware.smackx.jingle.internal.JingleContent; +import org.jivesoftware.smackx.jingle.internal.JingleTransport; /** * Manager for JingleTransport components. @@ -26,7 +26,7 @@ public interface JingleTransportManager extends Comparable createTransport(Content content); + JingleTransport createTransport(JingleContent content); - Transport createTransport(Content content, Transport peersTransport); + JingleTransport createTransport(JingleContent content, JingleTransport peersTransport); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleDescriptionAdapter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleDescriptionAdapter.java index f382780ff..77d0ce0d7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleDescriptionAdapter.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleDescriptionAdapter.java @@ -17,12 +17,12 @@ package org.jivesoftware.smackx.jingle.adapter; import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement; -import org.jivesoftware.smackx.jingle.internal.Description; +import org.jivesoftware.smackx.jingle.internal.JingleDescription; /** * Adapter that creates a Description object from an element. */ -public interface JingleDescriptionAdapter> { +public interface JingleDescriptionAdapter> { D descriptionFromElement(JingleContentDescriptionElement element); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleSecurityAdapter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleSecurityAdapter.java index c2fef71db..267b83bb1 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleSecurityAdapter.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleSecurityAdapter.java @@ -17,12 +17,12 @@ package org.jivesoftware.smackx.jingle.adapter; import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement; -import org.jivesoftware.smackx.jingle.internal.Security; +import org.jivesoftware.smackx.jingle.internal.JingleSecurity; /** * Adapter that creates a Security object from an element. */ -public interface JingleSecurityAdapter> { +public interface JingleSecurityAdapter> { S securityFromElement(JingleContentSecurityElement element); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleTransportAdapter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleTransportAdapter.java index 4b485804b..b5f3c0e50 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleTransportAdapter.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/adapter/JingleTransportAdapter.java @@ -17,12 +17,12 @@ package org.jivesoftware.smackx.jingle.adapter; import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement; -import org.jivesoftware.smackx.jingle.internal.Transport; +import org.jivesoftware.smackx.jingle.internal.JingleTransport; /** * Adapter that creates a Transport element from an element. */ -public interface JingleTransportAdapter> { +public interface JingleTransportAdapter> { T transportFromElement(JingleContentTransportElement element); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleElement.java index 8bba68cec..148688056 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleElement.java @@ -227,6 +227,114 @@ public final class JingleElement extends IQ { return jingleElement; } + /** + * Accept a session. + * XEP-0166 Example 17. + * @param initiator recipient of the stanza. + * @param responder our jid. + * @param sessionId sessionId. + * @param content content + * @return session-accept stanza. + */ + public JingleElement createSessionAccept(FullJid initiator, + FullJid responder, + String sessionId, + JingleContentElement content) { + return createSessionAccept(initiator, responder, sessionId, Collections.singletonList(content)); + } + + /** + * Accept a session. + * XEP-0166 Example 17. + * @param initiator recipient of the stanza. + * @param responder our jid. + * @param sessionId sessionId. + * @param contents contents + * @return session-accept stanza. + */ + public JingleElement createSessionAccept(FullJid initiator, + FullJid responder, + String sessionId, + List contents) { + JingleElement.Builder jb = JingleElement.getBuilder(); + jb.setResponder(responder) + .setAction(JingleAction.session_accept) + .setSessionId(sessionId); + + for (JingleContentElement content : contents) { + jb.addJingleContent(content); + } + + JingleElement jingle = jb.build(); + jingle.setTo(initiator); + jingle.setFrom(responder); + + return jingle; + } + + /** + * Initiate a Jingle session. + * XEP-0166 Example 10. + * @param initiator our jid. + * @param responder jid of the recipient. + * @param sessionId sessionId. + * @param content content. + * @return session-initiate stanza. + */ + public JingleElement createSessionInitiate(FullJid initiator, + FullJid responder, + String sessionId, + JingleContentElement content) { + return createSessionInitiate(initiator, responder, sessionId, Collections.singletonList(content)); + } + + /** + * Initiate a Jingle session. + * XEP-0166 Example 10. + * @param initiator our jid. + * @param responder jid of the recipient. + * @param sessionId sessionId. + * @param contents contents. + * @return session-initiate stanza. + */ + public JingleElement createSessionInitiate(FullJid initiator, + FullJid responder, + String sessionId, + List contents) { + + JingleElement.Builder builder = JingleElement.getBuilder(); + builder.setAction(JingleAction.session_initiate) + .setSessionId(sessionId) + .setInitiator(initiator); + + for (JingleContentElement content : contents) { + builder.addJingleContent(content); + } + + JingleElement jingle = builder.build(); + jingle.setTo(responder); + + return jingle; + } + + /** + * Create a session ping stanza. + * XEP-0166 Example 32. + * @param recipient recipient of the stanza. + * @param sessionId id of the session. + * @return ping stanza + */ + public static JingleElement createSessionPing(FullJid recipient, String sessionId) { + JingleElement.Builder jb = JingleElement.getBuilder(); + jb.setSessionId(sessionId) + .setAction(JingleAction.session_info); + + JingleElement jingle = jb.build(); + jingle.setTo(recipient); + + return jingle; + } + /** * Create a session-terminate stanza. * XEP-0166 §6.7. @@ -259,6 +367,42 @@ public final class JingleElement extends IQ { return createSessionTerminate(recipient, sessionId, new JingleReasonElement(reason)); } + /** + * Cancel a single contents transfer. + * XEP-0234 Example 10. + * @param recipient recipient of the stanza. + * @param sessionId sessionId. + * @param contentCreator creator of the content. + * @param contentName name of the content. + * @return session-terminate stanza. + */ + public static JingleElement createSessionTerminateContentCancel(FullJid recipient, String sessionId, + JingleContentElement.Creator contentCreator, String contentName) { + JingleElement.Builder jb = JingleElement.getBuilder(); + jb.setAction(JingleAction.session_terminate) + .setSessionId(sessionId).setReason(JingleReasonElement.Reason.cancel); + + JingleContentElement.Builder cb = JingleContentElement.getBuilder(); + cb.setCreator(contentCreator).setName(contentName); + + JingleElement jingle = jb.addJingleContent(cb.build()).build(); + jingle.setTo(recipient); + + return jingle; + } + + + /** + * Accept a transport. + * XEP-0260 Example 17. + * @param recipient recipient of the stanza + * @param initiator initiator of the session + * @param sessionId sessionId + * @param contentCreator creator of the content + * @param contentName name of the content + * @param transport transport to accept + * @return transport-accept stanza + */ public static JingleElement createTransportAccept(FullJid initiator, FullJid recipient, String sessionId, JingleContentElement.Creator contentCreator, String contentName, JingleContentTransportElement transport) { @@ -276,6 +420,17 @@ public final class JingleElement extends IQ { return jingle; } + /** + * Reject a transport. + * XEP-0166 §7.2.14. + * @param recipient recipient of the stanza + * @param initiator initiator of the session + * @param sessionId sessionId + * @param contentCreator creator of the content + * @param contentName name of the content + * @param transport transport to reject + * @return transport-reject stanza + */ public static JingleElement createTransportReject(FullJid initiator, FullJid recipient, String sessionId, JingleContentElement.Creator contentCreator, String contentName, JingleContentTransportElement transport) { @@ -293,6 +448,38 @@ public final class JingleElement extends IQ { return jingle; } + /** + * Replace a transport with another one. + * XEP-0260 Example 15. + * @param recipient recipient of the stanza + * @param initiator initiator of the session + * @param sessionId sessionId + * @param contentCreator creator of the content + * @param contentName name of the content + * @param transport proposed transport + * @return transport-replace stanza + */ + public static JingleElement createTransportReplace(FullJid initiator, FullJid recipient, String sessionId, + JingleContentElement.Creator contentCreator, + String contentName, JingleContentTransportElement transport) { + JingleElement.Builder jb = JingleElement.getBuilder() + .setAction(JingleAction.transport_replace) + .setSessionId(sessionId) + .setInitiator(initiator); + + JingleContentElement content = JingleContentElement.getBuilder() + .setCreator(contentCreator) + .setName(contentName) + .setTransport(transport).build(); + + jb.addJingleContent(content); + + JingleElement jingle = jb.build(); + jingle.setTo(recipient); + + return jingle; + } + /** * Create an error response to a request with an unknown session id. * XEP-0166 Example 29. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Content.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java similarity index 82% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Content.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java index 7ed0e4171..bd79c1f96 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Content.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleContent.java @@ -36,21 +36,21 @@ import org.jivesoftware.smackx.jingle.element.JingleContentElement; /** * Internal class that holds the state of a content in a modifiable form. */ -public class Content { +public class JingleContent { - private Session parent; + private JingleSession parent; private JingleContentElement.Creator creator; private String name; private String disposition; private JingleContentElement.Senders senders; - private Description description; - private Transport transport; - private Security security; + private JingleDescription description; + private JingleTransport transport; + private JingleSecurity security; private final List callbacks = Collections.synchronizedList(new ArrayList()); private final Set transportBlacklist = Collections.synchronizedSet(new HashSet()); - public Content(Description description, Transport transport, Security security, String name, String disposition, JingleContentElement.Creator creator, JingleContentElement.Senders senders) { + public JingleContent(JingleDescription description, JingleTransport transport, JingleSecurity security, String name, String disposition, JingleContentElement.Creator creator, JingleContentElement.Senders senders) { this.description = description; this.transport = transport; this.security = security; @@ -60,10 +60,10 @@ public class Content { this.senders = senders; } - public static Content fromElement(JingleContentElement content) { - Description description = null; - Transport transport = null; - Security security = null; + public static JingleContent fromElement(JingleContentElement content) { + JingleDescription description = null; + JingleTransport transport = null; + JingleSecurity security = null; JingleContentDescriptionElement descriptionElement = content.getDescription(); if (descriptionElement != null) { @@ -98,7 +98,7 @@ public class Content { } } - return new Content(description, transport, security, content.getName(), content.getDisposition(), content.getCreator(), content.getSenders()); + return new JingleContent(description, transport, security, content.getName(), content.getDisposition(), content.getCreator(), content.getSenders()); } public void addCallback(Callback callback) { @@ -133,43 +133,43 @@ public class Content { return senders; } - public void setParent(Session session) { + public void setParent(JingleSession session) { if (this.parent != session) { this.parent = session; } } - public Session getParent() { + public JingleSession getParent() { return parent; } - public Description getDescription() { + public JingleDescription getDescription() { return description; } - public void setDescription(Description description) { + public void setDescription(JingleDescription description) { if (this.description != description) { this.description = description; description.setParent(this); } } - public Transport getTransport() { + public JingleTransport getTransport() { return transport; } - public void setTransport(Transport transport) { + public void setTransport(JingleTransport transport) { if (this.transport != transport) { this.transport = transport; transport.setParent(this); } } - public Security getSecurity() { + public JingleSecurity getSecurity() { return security; } - public void setSecurity(Security security) { + public void setSecurity(JingleSecurity security) { if (this.security != security) { this.security = security; security.setParent(this); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Description.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java similarity index 82% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Description.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java index f303211da..cd77c9a83 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Description.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleDescription.java @@ -21,19 +21,19 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement; /** * Class that represents a contents description component. */ -public abstract class Description { +public abstract class JingleDescription { - private Content parent; + private JingleContent parent; public abstract D getElement(); - public void setParent(Content parent) { + public void setParent(JingleContent parent) { if (this.parent != parent) { this.parent = parent; } } - public Content getParent() { + public JingleContent getParent() { return parent; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Security.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleSecurity.java similarity index 85% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Security.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleSecurity.java index 2c982c472..d7bbdc4b2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Security.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleSecurity.java @@ -23,21 +23,21 @@ import org.jivesoftware.smackx.jingle.element.JingleContentSecurityInfoElement; /** * Class that represents a contents security component. */ -public abstract class Security { +public abstract class JingleSecurity { - private Content parent; + private JingleContent parent; public abstract D getElement(); public abstract JingleElement handleSecurityInfo(JingleContentSecurityInfoElement element); - public void setParent(Content parent) { + public void setParent(JingleContent parent) { if (this.parent != parent) { this.parent = parent; } } - public Content getParent() { + public JingleContent getParent() { return parent; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Session.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleSession.java similarity index 85% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Session.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleSession.java index bad86988e..cd5abcfbd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Session.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleSession.java @@ -50,20 +50,20 @@ import org.jxmpp.jid.FullJid; /** * Class that represents a Jingle session. */ -public class Session { - private static final Logger LOGGER = Logger.getLogger(Session.class.getName()); +public class JingleSession { + private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName()); - private final ConcurrentHashMap contents = new ConcurrentHashMap<>(); + private final ConcurrentHashMap contents = new ConcurrentHashMap<>(); private final JingleManager jingleManager; private final FullJid initiator, responder; private final Role role; private final String sessionId; - private final Map pendingJingleActions = - Collections.synchronizedMap(new HashMap()); + private final Map pendingJingleActions = + Collections.synchronizedMap(new HashMap()); - public Session(JingleManager manager, FullJid initiator, FullJid responder, Role role, String sessionId) { + public JingleSession(JingleManager manager, FullJid initiator, FullJid responder, Role role, String sessionId) { this.jingleManager = manager; this.initiator = initiator; this.responder = responder; @@ -71,23 +71,23 @@ public class Session { this.sessionId = sessionId; } - void addContent(Content content) { + void addContent(JingleContent content) { contents.put(content.getName(), content); content.setParent(this); } void addContent(JingleContentElement content) throws UnsupportedSecurityException, UnsupportedTransportException, UnsupportedDescriptionException { - addContent(Content.fromElement(content)); + addContent(JingleContent.fromElement(content)); } - public static Session fromSessionInitiate(JingleManager manager, JingleElement initiate) + public static JingleSession fromSessionInitiate(JingleManager manager, JingleElement initiate) throws UnsupportedSecurityException, UnsupportedDescriptionException, UnsupportedTransportException { if (initiate.getAction() != JingleAction.session_initiate) { throw new IllegalArgumentException("Jingle-Action MUST be 'session-initiate'."); } - Session session = new Session(manager, initiate.getInitiator(), initiate.getResponder(), Role.responder, initiate.getSid()); + JingleSession session = new JingleSession(manager, initiate.getInitiator(), initiate.getResponder(), Role.responder, initiate.getSid()); List initiateContents = initiate.getContents(); for (JingleContentElement content : initiateContents) { @@ -139,7 +139,7 @@ public class Session { List responses = new ArrayList<>(); for (JingleContentElement affected : affectedContents) { - Content content = contents.get(affected.getName()); + JingleContent content = contents.get(affected.getName()); JingleContentTransportElement newTransport = affected.getTransport(); Set blacklist = content.getTransportBlacklist(); @@ -216,7 +216,7 @@ public class Session { } private IQ handleTransportReject(JingleElement request) { - HashMap affectedContents = getAffectedContents(request); + HashMap affectedContents = getAffectedContents(request); return null; } @@ -226,11 +226,11 @@ public class Session { } private IQ handleTransportInfo(JingleElement request) { - HashMap affectedContents = getAffectedContents(request); + HashMap affectedContents = getAffectedContents(request); - for (Map.Entry entry : affectedContents.entrySet()) { + for (Map.Entry entry : affectedContents.entrySet()) { - Transport transport = entry.getValue().getTransport(); + JingleTransport transport = entry.getValue().getTransport(); JingleContentTransportInfoElement info = entry.getKey().getTransport().getInfo(); transport.handleTransportInfo(info); } @@ -239,8 +239,8 @@ public class Session { } private IQ handleTransportAccept(JingleElement request) { - HashMap affectedContents = getAffectedContents(request); - for (Map.Entry entry : affectedContents.entrySet()) { + HashMap affectedContents = getAffectedContents(request); + for (Map.Entry entry : affectedContents.entrySet()) { PendingJingleAction pending = pendingJingleActions.get(entry.getValue()); if (pending == null) { @@ -264,10 +264,10 @@ public class Session { } private IQ handleSecurityInfo(JingleElement request) { - HashMap affectedContents = getAffectedContents(request); + HashMap affectedContents = getAffectedContents(request); List responses = new ArrayList<>(); - for (Map.Entry entry : affectedContents.entrySet()) { + for (Map.Entry entry : affectedContents.entrySet()) { responses.add(entry.getValue().getSecurity().handleSecurityInfo(entry.getKey().getSecurity().getSecurityInfo())); } @@ -306,19 +306,19 @@ public class Session { final List proposedContents = request.getContents(); final List acceptedContents = new ArrayList<>(); - final HashMap> contentsByDescription = new HashMap<>(); + final HashMap> contentsByDescription = new HashMap<>(); for (JingleContentElement p : proposedContents) { JingleContentDescriptionElement description = p.getDescription(); - List list = contentsByDescription.get(description.getNamespace()); + List list = contentsByDescription.get(description.getNamespace()); if (list == null) { list = new ArrayList<>(); contentsByDescription.put(description.getNamespace(), list); } - list.add(Content.fromElement(p)); + list.add(JingleContent.fromElement(p)); } - for (Map.Entry> descriptionCategory : contentsByDescription.entrySet()) { + for (Map.Entry> descriptionCategory : contentsByDescription.entrySet()) { JingleDescriptionManager descriptionManager = JingleManager.getInstanceFor(getJingleManager().getConnection()).getDescriptionManager(descriptionCategory.getKey()); if (descriptionManager == null) { @@ -326,7 +326,7 @@ public class Session { continue; } - for (final Content content : descriptionCategory.getValue()) { + for (final JingleContent content : descriptionCategory.getValue()) { ContentAddCallback callback = new ContentAddCallback() { @Override public void acceptContentAdd() { @@ -386,10 +386,10 @@ public class Session { return jingleManager; } - private HashMap getAffectedContents(JingleElement request) { - HashMap map = new HashMap<>(); + private HashMap getAffectedContents(JingleElement request) { + HashMap map = new HashMap<>(); for (JingleContentElement e : request.getContents()) { - Content c = contents.get(e.getName()); + JingleContent c = contents.get(e.getName()); if (c == null) { throw new AssertionError("Unknown content: " + e.getName()); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Transport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransport.java similarity index 81% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Transport.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransport.java index 481dbc5c5..e29aed921 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/Transport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransport.java @@ -28,17 +28,17 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement; /** * Class that represents a contents transport component. */ -public abstract class Transport { +public abstract class JingleTransport { - private Content parent; - private final ArrayList> candidates = new ArrayList<>(); + private JingleContent parent; + private final ArrayList> candidates = new ArrayList<>(); - private Transport peersProposal; + private JingleTransport peersProposal; private boolean isPeersProposal; public abstract D getElement(); - public void addCandidate(TransportCandidate candidate) { + public void addCandidate(JingleTransportCandidate candidate) { // Insert sorted by priority descending // Empty list -> insert @@ -50,7 +50,7 @@ public abstract class Transport { // Find appropriate index for (int i = 0; i < candidates.size(); i++) { - TransportCandidate c = candidates.get(i); + JingleTransportCandidate c = candidates.get(i); // list already contains element -> return if (c == candidate) { @@ -65,7 +65,7 @@ public abstract class Transport { } } - public List> getCandidates() { + public List> getCandidates() { return candidates; } @@ -77,7 +77,7 @@ public abstract class Transport { public abstract void establishOutgoingBytestreamSession(BytestreamSessionEstablishedListener listener, XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException; - public void setPeersProposal(Transport peersProposal) { + public void setPeersProposal(JingleTransport peersProposal) { this.peersProposal = peersProposal; peersProposal.isPeersProposal = true; } @@ -86,19 +86,19 @@ public abstract class Transport { return isPeersProposal; } - public Transport getPeersProposal() { + public JingleTransport getPeersProposal() { return peersProposal; } public abstract void handleTransportInfo(JingleContentTransportInfoElement info); - public void setParent(Content parent) { + public void setParent(JingleContent parent) { if (this.parent != parent) { this.parent = parent; } } - public Content getParent() { + public JingleContent getParent() { return parent; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/TransportCandidate.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransportCandidate.java similarity index 82% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/TransportCandidate.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransportCandidate.java index 392ef008d..017885c5f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/TransportCandidate.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransportCandidate.java @@ -21,18 +21,18 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidateEle /** * Class that represents a transports candidate component. */ -public abstract class TransportCandidate { +public abstract class JingleTransportCandidate { - private Transport parent; + private JingleTransport parent; private int priority; - public void setParent(Transport transport) { + public void setParent(JingleTransport transport) { if (parent != transport) { parent = transport; } } - public Transport getParent() { + public JingleTransport getParent() { return parent; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/PendingJingleAction.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/PendingJingleAction.java index 3c9997441..941e1012f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/PendingJingleAction.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/PendingJingleAction.java @@ -24,9 +24,9 @@ import org.jivesoftware.smackx.jingle.element.JingleAction; */ public abstract class PendingJingleAction { private final JingleAction action; - private final Content affectedContent; + private final JingleContent affectedContent; - public PendingJingleAction(JingleAction action, Content content) { + public PendingJingleAction(JingleAction action, JingleContent content) { this.action = action; this.affectedContent = content; } @@ -35,19 +35,19 @@ public abstract class PendingJingleAction { return action; } - public Content getAffectedContent() { + public JingleContent getAffectedContent() { return affectedContent; } public static class TransportReplace extends PendingJingleAction { - private final Transport newTransport; + private final JingleTransport newTransport; - public TransportReplace(Content content, Transport newTransport) { + public TransportReplace(JingleContent content, JingleTransport newTransport) { super(JingleAction.transport_replace, content); this.newTransport = newTransport; } - public Transport getNewTransport() { + public JingleTransport getNewTransport() { return newTransport; } } 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 47dd7d31c..ca932347e 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 @@ -24,17 +24,17 @@ import org.jivesoftware.smackx.bytestreams.BytestreamListener; import org.jivesoftware.smackx.bytestreams.BytestreamRequest; import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager; -import org.jivesoftware.smackx.jingle.internal.Transport; -import org.jivesoftware.smackx.jingle.internal.TransportCandidate; +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.Session; +import org.jivesoftware.smackx.jingle.internal.JingleSession; import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement; /** * Jingle InBandBytestream Transport component. */ -public class JingleIBBTransport extends Transport { +public class JingleIBBTransport extends JingleTransport { public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:ibb:1"; public static final String NAMESPACE = NAMESPACE_V1; @@ -71,7 +71,7 @@ public class JingleIBBTransport extends Transport { @Override public void establishIncomingBytestreamSession(final BytestreamSessionEstablishedListener listener, final XMPPConnection connection) { - final Session session = getParent().getParent(); + final JingleSession session = getParent().getParent(); InBandBytestreamManager.getByteStreamManager(connection) .addIncomingBytestreamListener(new BytestreamListener() { @Override @@ -94,7 +94,7 @@ public class JingleIBBTransport extends Transport { @Override public void establishOutgoingBytestreamSession(BytestreamSessionEstablishedListener listener, XMPPConnection connection) { - Session session = getParent().getParent(); + JingleSession session = getParent().getParent(); InBandBytestreamManager inBandBytestreamManager = InBandBytestreamManager.getByteStreamManager(connection); inBandBytestreamManager.setDefaultBlockSize(blockSize); try { @@ -106,7 +106,7 @@ public class JingleIBBTransport extends Transport { } @Override - public void addCandidate(TransportCandidate candidate) { + public void addCandidate(JingleTransportCandidate candidate) { // Sorry, we don't want any candidates. } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java index aeec2d30f..ad4361304 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java @@ -3,8 +3,8 @@ package org.jivesoftware.smackx.jingle.transport.jingle_ibb; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smackx.jingle.JingleTransportManager; -import org.jivesoftware.smackx.jingle.internal.Content; -import org.jivesoftware.smackx.jingle.internal.Transport; +import org.jivesoftware.smackx.jingle.internal.JingleContent; +import org.jivesoftware.smackx.jingle.internal.JingleTransport; /** * Created by vanitas on 21.07.17. @@ -23,12 +23,12 @@ public class JingleIBBTransportManager extends Manager implements JingleTranspor } @Override - public Transport createTransport(Content content) { + public JingleTransport createTransport(JingleContent content) { return new JingleIBBTransport(); } @Override - public Transport createTransport(Content content, Transport peersTransport) { + public JingleTransport createTransport(JingleContent content, JingleTransport peersTransport) { JingleIBBTransport other = (JingleIBBTransport) peersTransport; return new JingleIBBTransport(other.getSid(), (short) Math.min(other.getBlockSize(), MAX_BLOCKSIZE)); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java index 39a12f6dc..22366432c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java @@ -33,16 +33,16 @@ import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTran import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportInfoElement; import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement; -import org.jivesoftware.smackx.jingle.internal.Content; -import org.jivesoftware.smackx.jingle.internal.Transport; -import org.jivesoftware.smackx.jingle.internal.TransportCandidate; +import org.jivesoftware.smackx.jingle.internal.JingleContent; +import org.jivesoftware.smackx.jingle.internal.JingleTransport; +import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate; import org.jxmpp.jid.FullJid; /** * Jingle SOCKS5Bytestream transport component. */ -public class JingleS5BTransport extends Transport { +public class JingleS5BTransport extends JingleTransport { public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:s5b:1"; public static final String NAMESPACE = NAMESPACE_V1; @@ -62,22 +62,22 @@ public class JingleS5BTransport extends Transport { * @param initiator initiator. * @param responder responder. */ - public JingleS5BTransport(FullJid initiator, FullJid responder, String sid, List> candidates) { + public JingleS5BTransport(FullJid initiator, FullJid responder, String sid, List> candidates) { this(sid, Socks5Utils.createDigest(sid, initiator, responder), Bytestream.Mode.tcp, candidates); } - public JingleS5BTransport(Content content, JingleS5BTransport other, List> candidates) { + public JingleS5BTransport(JingleContent content, JingleS5BTransport other, List> candidates) { this(other.getSid(), Socks5Utils.createDigest(other.getSid(), content.getParent().getInitiator(), content.getParent().getResponder()), other.mode, candidates); } - public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List> candidates) { + public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List> candidates) { this.sid = sid; this.dstAddr = dstAddr; this.mode = mode; - for (TransportCandidate c : (candidates != null ? + for (JingleTransportCandidate c : (candidates != null ? candidates : Collections.emptySet())) { addCandidate(c); } @@ -90,7 +90,7 @@ public class JingleS5BTransport extends Transport { .setDestinationAddress(dstAddr) .setMode(mode); - for (TransportCandidate candidate : getCandidates()) { + for (JingleTransportCandidate candidate : getCandidates()) { builder.addTransportCandidate((JingleS5BTransportCandidateElement) candidate.getElement()); } @@ -132,7 +132,7 @@ public class JingleS5BTransport extends Transport { JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection); this.selectedCandidate = connectToCandidates(MAX_TIMEOUT); - if (selectedCandidate == null) { + if (selectedCandidate == CANDIDATE_FAILURE) { connection.createStanzaCollectorAndSend(transportManager.createCandidateError(this)); } @@ -140,7 +140,7 @@ public class JingleS5BTransport extends Transport { } public JingleS5BTransportCandidate connectToCandidates(int timeout) { - for (TransportCandidate c : getCandidates()) { + for (JingleTransportCandidate c : getCandidates()) { int _timeout = timeout / getCandidates().size(); //TODO: Wise? try { return ((JingleS5BTransportCandidate) c).connect(_timeout); @@ -150,7 +150,7 @@ public class JingleS5BTransport extends Transport { } // Failed to connect to any candidate. - return null; + return CANDIDATE_FAILURE; } @Override @@ -188,7 +188,7 @@ public class JingleS5BTransport extends Transport { return; } - Iterator> ourCandidates = getCandidates().iterator(); + Iterator> ourCandidates = getCandidates().iterator(); while (ourCandidates.hasNext()) { JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) ourCandidates.next(); if (candidate.getCandidateId().equals(candidateId)) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportCandidate.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportCandidate.java index 9281191ef..6ab0d56c8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportCandidate.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportCandidate.java @@ -26,13 +26,13 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client; import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement; -import org.jivesoftware.smackx.jingle.internal.Session; -import org.jivesoftware.smackx.jingle.internal.TransportCandidate; +import org.jivesoftware.smackx.jingle.internal.JingleSession; +import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate; /** * Jingle SOCKS5Bytestream transport candidate. */ -public class JingleS5BTransportCandidate extends TransportCandidate { +public class JingleS5BTransportCandidate extends JingleTransportCandidate { private final String candidateId; private final Bytestream.StreamHost streamHost; @@ -81,7 +81,7 @@ public class JingleS5BTransportCandidate extends TransportCandidate createTransport(Content content) { - Session session = content.getParent(); - List> candidates = collectCandidates(); + public JingleTransport createTransport(JingleContent content) { + JingleSession session = content.getParent(); + List> candidates = collectCandidates(); return new JingleS5BTransport(session.getInitiator(), session.getResponder(), StringUtils.randomString(24), candidates); } @Override - public Transport createTransport(Content content, Transport peersTransport) { + public JingleTransport createTransport(JingleContent content, JingleTransport peersTransport) { JingleS5BTransport transport = (JingleS5BTransport) peersTransport; - List> candidates = collectCandidates(); + List> candidates = collectCandidates(); return new JingleS5BTransport(content, transport, candidates); } - private List> collectCandidates() { - List> candidates = new ArrayList<>(); + private List> collectCandidates() { + List> candidates = new ArrayList<>(); //Local host if (JingleS5BTransportManager.isUseLocalCandidates()) { @@ -217,8 +217,8 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr } private JingleElement createTransportInfo(JingleS5BTransport transport, JingleS5BTransportInfoElement info) { - Content content = transport.getParent(); - Session session = content.getParent(); + JingleContent content = transport.getParent(); + JingleSession session = content.getParent(); JingleElement.Builder jb = JingleElement.getBuilder() .setSessionId(session.getSessionId()) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/legacy/JingleS5BTransportSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/legacy/JingleS5BTransportSession.java index e19faf05a..7e270124e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/legacy/JingleS5BTransportSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/legacy/JingleS5BTransportSession.java @@ -48,51 +48,7 @@ import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTran * Handler that handles Jingle Socks5Bytestream transports (XEP-0260). */ public class JingleS5BTransportSession extends JingleTransportSession { - private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportSession.class.getName()); - public JingleS5BTransportElement createTransport(String sid, Bytestream.Mode mode) { - JingleS5BTransportElement.Builder jb = JingleS5BTransportElement.getBuilder() - .setStreamId(sid).setMode(mode).setDestinationAddress( - Socks5Utils.createDigest(sid, jingleSession.getLocal(), jingleSession.getRemote())); - - //Local host - if (JingleS5BTransportManager.isUseLocalCandidates()) { - for (Bytestream.StreamHost host : transportManager().getLocalStreamHosts()) { - jb.addTransportCandidate(new JingleS5BTransportCandidateElement(host, 100, JingleS5BTransportCandidateElement.Type.direct)); - } - } - - List remoteHosts = Collections.emptyList(); - if (JingleS5BTransportManager.isUseExternalCandidates()) { - try { - remoteHosts = transportManager().getAvailableStreamHosts(); - } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { - LOGGER.log(Level.WARNING, "Could not determine available StreamHosts.", e); - } - } - - for (Bytestream.StreamHost host : remoteHosts) { - jb.addTransportCandidate(new JingleS5BTransportCandidateElement(host, 0, JingleS5BTransportCandidateElement.Type.proxy)); - } - - return jb.build(); - } - - public void setTheirTransport(JingleContentTransportElement transport) { - theirProposal = (JingleS5BTransportElement) transport; - } - - @Override - public void initiateOutgoingSession(JingleTransportInitiationCallback callback) { - this.callback = callback; - initiateSession(); - } - - @Override - public void initiateIncomingSession(JingleTransportInitiationCallback callback) { - this.callback = callback; - initiateSession(); - } private void initiateSession() { Socks5Proxy.getSocks5Proxy().addTransfer(createTransport().getDestinationAddress()); @@ -136,56 +92,6 @@ public class JingleS5BTransportSession extends JingleTransportSession contents) { - - JingleElement.Builder builder = JingleElement.getBuilder(); - builder.setAction(JingleAction.session_initiate) - .setSessionId(sessionId) - .setInitiator(connection.getUser()); - - for (JingleContentElement content : contents) { - builder.addJingleContent(content); - } - - JingleElement jingle = builder.build(); - jingle.setFrom(connection.getUser()); - jingle.setTo(recipient); - - return jingle; - } - - /** - * Accept a session. - * XEP-0166 Example 17. - * @param recipient recipient of the stanza. - * @param sessionId sessionId. - * @param content content - * @return session-accept stanza. - */ - public JingleElement createSessionAccept(FullJid recipient, - String sessionId, - JingleContentElement content) { - return createSessionAccept(recipient, sessionId, Collections.singletonList(content)); - } - - public JingleElement createSessionAccept(FullJid recipient, - String sessionId, - List contents) { - JingleElement.Builder jb = JingleElement.getBuilder(); - jb.setResponder(connection.getUser()) - .setAction(JingleAction.session_accept) - .setSessionId(sessionId); - - for (JingleContentElement content : contents) { - jb.addJingleContent(content); - } - - JingleElement jingle = jb.build(); - jingle.setTo(recipient); - jingle.setFrom(connection.getUser()); - - return jingle; - } - - /** - * Cancel a single contents transfer. - * XEP-0234 Example 10. - * @param recipient recipient of the stanza. - * @param sessionId sessionId. - * @param contentCreator creator of the content. - * @param contentName name of the content. - * @return session-terminate stanza. - */ - public JingleElement createSessionTerminateContentCancel(FullJid recipient, String sessionId, - JingleContentElement.Creator contentCreator, String contentName) { - JingleElement.Builder jb = JingleElement.getBuilder(); - jb.setAction(JingleAction.session_terminate) - .setSessionId(sessionId).setReason(JingleReasonElement.Reason.cancel); - - JingleContentElement.Builder cb = JingleContentElement.getBuilder(); - cb.setCreator(contentCreator).setName(contentName); - - JingleElement jingle = jb.addJingleContent(cb.build()).build(); - jingle.setFrom(connection.getUser()); - jingle.setTo(recipient); - - return jingle; - } - - /** - * Create a session ping stanza. - * XEP-0166 Example 32. - * @param recipient recipient of the stanza - * @param sessionId id of the session - * @return ping stanza - */ - public JingleElement createSessionPing(FullJid recipient, String sessionId) { - JingleElement.Builder jb = JingleElement.getBuilder(); - jb.setSessionId(sessionId) - .setAction(JingleAction.session_info); - - JingleElement jingle = jb.build(); - jingle.setFrom(connection.getUser()); - jingle.setTo(recipient); - - return jingle; - } - - /** - * Acknowledge the receipt of a stanza. - * XEP-0166 Example 5. - * @param jingle stanza that was received - * @return acknowledgement - */ - public IQ createAck(JingleElement jingle) { - return IQ.createResultIQ(jingle); - } - - /** - * Replace a transport with another one. - * XEP-0260 Example 15. - * @param recipient recipient of the stanza - * @param initiator initiator of the session - * @param sessionId sessionId - * @param contentCreator creator of the content - * @param contentName name of the content - * @param transport proposed transport - * @return transport-replace stanza - */ - public JingleElement createTransportReplace(FullJid recipient, FullJid initiator, String sessionId, - JingleContentElement.Creator contentCreator, String contentName, - JingleContentTransportElement transport) { - JingleElement.Builder jb = JingleElement.getBuilder(); - jb.setInitiator(initiator) - .setSessionId(sessionId) - .setAction(JingleAction.transport_replace); - - JingleContentElement.Builder cb = JingleContentElement.getBuilder(); - cb.setName(contentName).setCreator(contentCreator).setTransport(transport); - JingleElement jingle = jb.addJingleContent(cb.build()).build(); - - jingle.setTo(recipient); - jingle.setFrom(connection.getUser()); - - return jingle; - } - - /** - * Accept a transport. - * XEP-0260 Example 17. - * @param recipient recipient of the stanza - * @param initiator initiator of the session - * @param sessionId sessionId - * @param contentCreator creator of the content - * @param contentName name of the content - * @param transport transport to accept - * @return transport-accept stanza - */ - public JingleElement createTransportAccept(FullJid recipient, FullJid initiator, String sessionId, - JingleContentElement.Creator contentCreator, String contentName, - JingleContentTransportElement transport) { - JingleElement.Builder jb = JingleElement.getBuilder(); - jb.setAction(JingleAction.transport_accept) - .setInitiator(initiator) - .setSessionId(sessionId); - - JingleContentElement.Builder cb = JingleContentElement.getBuilder(); - cb.setCreator(contentCreator).setName(contentName).setTransport(transport); - - JingleElement jingle = jb.addJingleContent(cb.build()).build(); - jingle.setTo(recipient); - jingle.setFrom(connection.getUser()); - - return jingle; - } - - /** - * Reject a transport. - * XEP-0166 §7.2.14. - * @param recipient recipient of the stanza - * @param initiator initiator of the session - * @param sessionId sessionId - * @param contentCreator creator of the content - * @param contentName name of the content - * @param transport transport to reject - * @return transport-reject stanza - */ - public JingleElement createTransportReject(FullJid recipient, FullJid initiator, String sessionId, - JingleContentElement.Creator contentCreator, String contentName, - JingleContentTransportElement transport) { - JingleElement.Builder jb = JingleElement.getBuilder(); - jb.setAction(JingleAction.transport_reject) - .setInitiator(initiator) - .setSessionId(sessionId); - - JingleContentElement.Builder cb = JingleContentElement.getBuilder(); - cb.setCreator(contentCreator).setName(contentName).setTransport(transport); - - JingleElement jingle = jb.addJingleContent(cb.build()).build(); - jingle.setTo(recipient); - jingle.setFrom(connection.getUser()); - - return jingle; - } - - /* - * #################################################################################################### - */ - - /** - * Create an error response to a request with an unknown session id. - * XEP-0166 Example 29. - * @param request request with unknown sessionId. - * @return error stanza. - */ - public IQ createErrorUnknownSession(JingleElement request) { - XMPPError.Builder error = XMPPError.getBuilder(); - error.setCondition(XMPPError.Condition.item_not_found) - .addExtension(JingleErrorElement.UNKNOWN_SESSION); - return IQ.createErrorResponse(request, error); - } - - /** - * Create an error response to a request coming from a unknown initiator. - * XEP-0166 Example 12. - * @param request request from unknown initiator. - * @return error stanza. - */ - public IQ createErrorUnknownInitiator(JingleElement request) { - XMPPError.Builder b = XMPPError.getBuilder().setType(XMPPError.Type.CANCEL).setCondition(XMPPError.Condition.service_unavailable); - return IQ.createErrorResponse(request, b); - } - - /** - * Create an error response to a request with an unsupported info. - * XEP-0166 Example 31. - * @param request request with unsupported info. - * @return error stanza. - */ - public IQ createErrorUnsupportedInfo(JingleElement request) { - XMPPError.Builder error = XMPPError.getBuilder(); - error.setCondition(XMPPError.Condition.feature_not_implemented) - .addExtension(JingleErrorElement.UNSUPPORTED_INFO).setType(XMPPError.Type.MODIFY); - return IQ.createErrorResponse(request, error); - } - - /** - * Create an error response to a tie-breaking request. - * XEP-0166 Example 34. - * @param request tie-breaking request - * @return error stanza - */ - public IQ createErrorTieBreak(JingleElement request) { - XMPPError.Builder error = XMPPError.getBuilder(); - error.setCondition(XMPPError.Condition.conflict) - .addExtension(JingleErrorElement.TIE_BREAK); - return IQ.createErrorResponse(request, error); - } - - /** - * Create an error response to a request that was out of order. - * TODO: Find example. - * @param request request out of order. - * @return error stanza. - */ - public IQ createErrorOutOfOrder(JingleElement request) { - XMPPError.Builder error = XMPPError.getBuilder(); - error.setCondition(XMPPError.Condition.unexpected_request) - .addExtension(JingleErrorElement.OUT_OF_ORDER); - return IQ.createErrorResponse(request, error); - } - - /** - * Create an error response to a malformed request. - * XEP-0166 Ex. 16 - * @param request malformed request - * @return error stanza. - */ - public IQ createErrorMalformedRequest(JingleElement request) { - XMPPError.Builder error = XMPPError.getBuilder(); - error.setType(XMPPError.Type.CANCEL); - error.setCondition(XMPPError.Condition.bad_request); - return IQ.createErrorResponse(request, error); - } -} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java index 92eea2bf0..698a2cc85 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java @@ -21,9 +21,9 @@ import static junit.framework.TestCase.assertNull; import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager; -import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport; -import org.jivesoftware.smackx.jingle.transports.jingle_ibb.provider.JingleIBBTransportProvider; -import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement; +import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport; +import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider; +import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransport; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.provider.JingleS5BTransportProvider; import org.junit.Test; @@ -36,18 +36,18 @@ public class JingleContentProviderManagerTest extends SmackTestSuite { @Test public void transportProviderTest() { JingleContentProviderManager.removeJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1); - JingleContentProviderManager.removeJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1); + JingleContentProviderManager.removeJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1); assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1)); - assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1)); + assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1)); JingleIBBTransportProvider ibbProvider = new JingleIBBTransportProvider(); JingleContentProviderManager.addJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1, ibbProvider); assertEquals(ibbProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1)); - assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1)); + assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1)); JingleS5BTransportProvider s5bProvider = new JingleS5BTransportProvider(); - JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1, s5bProvider); - assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1)); + JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1, s5bProvider); + assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1)); } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleManagerTest.java deleted file mode 100644 index 63d1282bb..000000000 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleManagerTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - * 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.jingle; - -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertNotSame; -import static junit.framework.TestCase.assertNull; - -import org.jivesoftware.smack.DummyConnection; -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smack.test.util.SmackTestSuite; -import org.jivesoftware.smackx.jingle.element.JingleElement; - -import org.junit.Test; -import org.jxmpp.jid.FullJid; -import org.jxmpp.jid.impl.JidCreate; -import org.jxmpp.stringprep.XmppStringprepException; - -/** - * Created by vanitas on 03.07.17. - */ -public class JingleManagerTest extends SmackTestSuite { - - /** - * Might fail in *very* rare cases. - */ - @Test - public void randomTest() { - String r1 = JingleManager.randomId(); - String r2 = JingleManager.randomId(); - - assertNotSame(r1, r2); - assertEquals(24, r1.length()); - } - - @Test - public void threadPoolTest() { - assertNotNull(JingleManager.getThreadPool()); - } - - @Test - public void handlerRegistrationTest() throws XmppStringprepException { - final XMPPConnection connection = new DummyConnection(); - - FullJid remote = JidCreate.fullFrom("test@test.test/test"); - FullJid local = JidCreate.fullFrom("case@case.case/case"); - String sid = JingleManager.randomId(); - JingleSession s = new JingleSession(local, remote, Role.initiator, sid) { - @Override - public XMPPConnection getConnection() { - return connection; - } - - @Override - public void onTransportMethodFailed(String namespace) { - - } - }; - assertNull(JingleManager.getInstanceFor(connection).registerJingleSessionHandler(remote, sid, s)); - assertNotNull(JingleManager.getInstanceFor(connection).registerJingleSessionHandler(remote, sid, s)); - JingleManager.getInstanceFor(connection).unregisterJingleSessionHandler(remote, sid, s); - assertNull(JingleManager.getInstanceFor(connection).registerJingleSessionHandler(remote, sid, s)); - - String stubNamespace = "urn:xmpp:jingle:application:stub:0"; - JingleHandler stub = new JingleHandler() { - @Override - public IQ handleJingleRequest(JingleElement jingle) { - return null; - } - }; - - assertNull(JingleManager.getInstanceFor(connection).registerDescriptionHandler(stubNamespace, stub)); - assertNotNull(JingleManager.getInstanceFor(connection).registerDescriptionHandler(stubNamespace, stub)); - } -} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java deleted file mode 100644 index f0b2609e4..000000000 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/** - * - * 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.jingle; - -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertNotSame; -import static junit.framework.TestCase.assertNull; - -import java.util.List; - -import org.jivesoftware.smack.DummyConnection; -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smack.packet.TestIQ; -import org.jivesoftware.smackx.jingle.element.JingleContentElement; -import org.jivesoftware.smackx.jingle.element.JingleElement; -import org.jivesoftware.smackx.jingle.element.JingleAction; -import org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportSession; - -import org.junit.Test; -import org.jxmpp.jid.FullJid; -import org.jxmpp.jid.impl.JidCreate; -import org.jxmpp.stringprep.XmppStringprepException; - -public class JingleSessionTest { - - private static final XMPPConnection connection = new DummyConnection(); - - private static final IQ sessionInitiateResult = new TestIQ(); - private static final IQ sessionTerminateResult = new TestIQ(); - private static final IQ sessionInfoResult = new TestIQ(); - private static final IQ sessionAcceptResult = new TestIQ(); - - private static final IQ contentAddResult = new TestIQ(); - private static final IQ contentAcceptResult = new TestIQ(); - private static final IQ contentRejectResult = new TestIQ(); - private static final IQ contentModifyResult = new TestIQ(); - private static final IQ contentRemoveResult = new TestIQ(); - - private static final IQ descriptionInfoResult = new TestIQ(); - - private static final IQ securityInfoResult = new TestIQ(); - - private static final IQ transportAcceptResult = new TestIQ(); - private static final IQ transportReplaceResult = new TestIQ(); - private static final IQ transportRejectResult = new TestIQ(); - - @Test - public void jingleSessionTest() throws XmppStringprepException { - FullJid us5 = JidCreate.fullFrom("home@swe.et/home"); - FullJid u2 = JidCreate.fullFrom("place@far.far/away"); - String sessionId = "suchPopMuchWow"; - - JingleSession initiatedSimpleSession = new SimpleSession(us5, u2, Role.initiator, sessionId); - assertEquals(us5, initiatedSimpleSession.getInitiator()); - assertEquals(u2, initiatedSimpleSession.getResponder()); - assertEquals(us5, initiatedSimpleSession.getLocal()); - assertEquals(u2, initiatedSimpleSession.getRemote()); - assertEquals(sessionId, initiatedSimpleSession.getSessionId()); - assertNotNull(initiatedSimpleSession.getContents()); - - String sessionId2 = "popMusicSucks"; - JingleSession respondedSimpleSession = new SimpleSession(u2, us5, Role.responder, sessionId2); - assertEquals(us5, respondedSimpleSession.getLocal()); - assertEquals(us5, respondedSimpleSession.getResponder()); - assertEquals(u2, respondedSimpleSession.getInitiator()); - assertEquals(u2, respondedSimpleSession.getRemote()); - - assertEquals(new FullJidAndSessionId(u2, sessionId), initiatedSimpleSession.getFullJidAndSessionId()); - assertEquals(new FullJidAndSessionId(u2, sessionId2), respondedSimpleSession.getFullJidAndSessionId()); - - assertNull(initiatedSimpleSession.getTransportSession()); - initiatedSimpleSession.setTransportSession(new JingleIBBTransportSession(initiatedSimpleSession)); - assertNotNull(initiatedSimpleSession.getTransportSession()); - - assertNotSame(initiatedSimpleSession, respondedSimpleSession); - assertFalse(initiatedSimpleSession.equals(respondedSimpleSession)); - assertNotSame(initiatedSimpleSession.hashCode(), respondedSimpleSession.hashCode()); - assertFalse(initiatedSimpleSession.equals("Hallo Welt")); - } - - @Test - public void testHandleSessionRequest() { - JingleSession s = new SimpleSession(null, null, null, null); - - assertEquals(sessionAcceptResult, s.handleJingleSessionRequest(simpleAction(JingleAction.session_accept))); - assertEquals(sessionInfoResult, s.handleJingleSessionRequest(simpleAction(JingleAction.session_info))); - assertEquals(sessionInitiateResult, s.handleJingleSessionRequest(simpleAction(JingleAction.session_initiate))); - assertEquals(sessionTerminateResult, s.handleJingleSessionRequest(simpleAction(JingleAction.session_terminate))); - - assertEquals(contentAcceptResult, s.handleJingleSessionRequest(simpleAction(JingleAction.content_accept))); - assertEquals(contentAddResult, s.handleJingleSessionRequest(simpleAction(JingleAction.content_add))); - assertEquals(contentModifyResult, s.handleJingleSessionRequest(simpleAction(JingleAction.content_modify))); - assertEquals(contentRejectResult, s.handleJingleSessionRequest(simpleAction(JingleAction.content_reject))); - assertEquals(contentRemoveResult, s.handleJingleSessionRequest(simpleAction(JingleAction.content_remove))); - - assertEquals(descriptionInfoResult, s.handleJingleSessionRequest(simpleAction(JingleAction.description_info))); - - assertEquals(securityInfoResult, s.handleJingleSessionRequest(simpleAction(JingleAction.security_info))); - - assertEquals(transportAcceptResult, s.handleJingleSessionRequest(simpleAction(JingleAction.transport_accept))); - assertEquals(transportRejectResult, s.handleJingleSessionRequest(simpleAction(JingleAction.transport_reject))); - assertEquals(transportReplaceResult, s.handleJingleSessionRequest(simpleAction(JingleAction.transport_replace))); - } - - private static class SimpleSession extends JingleSession { - - public SimpleSession(FullJid initiator, FullJid responder, Role role, String sid) { - super(initiator, responder, role, sid); - } - - public SimpleSession(FullJid initiator, FullJid responder, Role role, String sid, List contents) { - super(initiator, responder, role, sid, contents); - } - - @Override - public XMPPConnection getConnection() { - return connection; - } - - @Override - public void onTransportMethodFailed(String namespace) { - - } - - @Override - public IQ handleSessionInitiate(JingleElement jingle) { - return sessionInitiateResult; - } - - @Override - public IQ handleSessionAccept(JingleElement jingle) { - return sessionAcceptResult; - } - - @Override - public IQ handleSessionTerminate(JingleElement jingle) { - return sessionTerminateResult; - } - - @Override - public IQ handleSessionInfo(JingleElement jingle) { - return sessionInfoResult; - } - - @Override - public IQ handleTransportAccept(JingleElement jingle) { - return transportAcceptResult; - } - - @Override - public IQ handleTransportReject(JingleElement jingle) { - return transportRejectResult; - } - - @Override - public IQ handleTransportReplace(JingleElement jingle) { - return transportReplaceResult; - } - - @Override - public IQ handleContentAdd(JingleElement jingle) { - return contentAddResult; - } - - @Override - public IQ handleContentAccept(JingleElement jingle) { - return contentAcceptResult; - } - - @Override - public IQ handleContentReject(JingleElement jingle) { - return contentRejectResult; - } - - @Override - public IQ handleContentRemove(JingleElement jingle) { - return contentRemoveResult; - } - - @Override - public IQ handleContentModify(JingleElement jingle) { - return contentModifyResult; - } - - @Override - public IQ handleDescriptionInfo(JingleElement jingle) { - return descriptionInfoResult; - } - - @Override - public IQ handleSecurityInfo(JingleElement jingle) { - return securityInfoResult; - } - } - - private JingleElement simpleAction(JingleAction action) { - return JingleElement.getBuilder().setAction(action).setSessionId("test").build(); - } -} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManagerTest.java deleted file mode 100644 index 96289b4a1..000000000 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManagerTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * - * 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.jingle; - -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertNull; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.jivesoftware.smack.DummyConnection; -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.test.util.SmackTestSuite; -import org.jivesoftware.smackx.jingle.element.JingleElement; -import org.jivesoftware.smackx.jingle.element.JingleAction; -import org.jivesoftware.smackx.jingle.element.JingleContentElement; -import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement; -import org.jivesoftware.smackx.jingle.transports.JingleTransportManager; -import org.jivesoftware.smackx.jingle.transports.JingleTransportSession; -import org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportManager; -import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport; -import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransportManager; -import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement; - -import org.junit.Test; -import org.jxmpp.jid.impl.JidCreate; -import org.jxmpp.stringprep.XmppStringprepException; - -public class JingleTransportMethodManagerTest extends SmackTestSuite { - - @Test - public void getTransportManagerTest() throws XmppStringprepException { - XMPPConnection connection = new DummyConnection(); - JingleTransportMethodManager jtmm = JingleTransportMethodManager.getInstanceFor(connection); - - assertNull(jtmm.getBestAvailableTransportManager()); - assertNull(jtmm.getTransportManager(JingleIBBTransport.NAMESPACE_V1)); - assertNull(jtmm.getTransportManager(JingleS5BTransportElement.NAMESPACE_V1)); - - jtmm.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection)); - assertNull(jtmm.getTransportManager(JingleS5BTransportElement.NAMESPACE_V1)); - assertNotNull(jtmm.getTransportManager(JingleIBBTransport.NAMESPACE_V1)); - assertEquals(JingleIBBTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager()); - - jtmm.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection)); - assertEquals(JingleS5BTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager()); - - jtmm.unregisterTransportManager(JingleS5BTransportManager.getInstanceFor(connection)); - assertNull(jtmm.getTransportManager(JingleS5BTransportElement.NAMESPACE_V1)); - jtmm.unregisterTransportManager(JingleIBBTransportManager.getInstanceFor(connection)); - - assertNull(jtmm.getBestAvailableTransportManager()); - - jtmm.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection)); - assertEquals(JingleS5BTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager()); - jtmm.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection)); - assertEquals(JingleS5BTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager()); - - assertEquals(JingleIBBTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager( - Collections.singleton(JingleS5BTransportElement.NAMESPACE_V1))); - - JingleStubTransportManager stub = new JingleStubTransportManager(connection); - jtmm.registerTransportManager(stub); - assertEquals(stub, JingleTransportMethodManager.getTransportManager(connection, JingleStubTransportManager.NAMESPACE)); - assertEquals(JingleS5BTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager()); - - JingleElement jingle = JingleElement.getBuilder().setSessionId("test").setAction(JingleAction.session_initiate) - .setInitiator(JidCreate.fullFrom("test@test.test/test")) - .addJingleContent( - JingleContentElement.getBuilder().setCreator(JingleContentElement.Creator.initiator).setName("content") - .setSenders(JingleContentElement.Senders.initiator).setTransport( - new JingleIBBTransport("transportId")).build()).build(); - assertEquals(JingleIBBTransportManager.getInstanceFor(connection), jtmm.getTransportManager(jingle)); - assertEquals(JingleIBBTransportManager.getInstanceFor(connection), - JingleTransportMethodManager.getTransportManager(connection, jingle)); - - Set except = new HashSet<>(); - except.add(JingleIBBTransport.NAMESPACE_V1); - except.add(JingleS5BTransportElement.NAMESPACE_V1); - assertEquals(stub, jtmm.getBestAvailableTransportManager(except)); - - jtmm.unregisterTransportManager(JingleS5BTransportManager.getInstanceFor(connection)); - jtmm.unregisterTransportManager(JingleIBBTransportManager.getInstanceFor(connection)); - assertEquals(stub, JingleTransportMethodManager.getBestAvailableTransportManager(connection)); - } - - private static class JingleStubTransportManager extends JingleTransportManager { - - public static final String NAMESPACE = "urn:xmpp:jingle:transports:stub:0"; - - public JingleStubTransportManager(XMPPConnection connection) { - super(connection); - } - - @Override - public String getNamespace() { - return NAMESPACE; - } - - @Override - public JingleTransportSession transportSession(JingleSession jingleSession) { - return null; - } - - @Override - public void authenticated(XMPPConnection connection, boolean resumed) { - - } - } -} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleUtilTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleUtilTest.java index 2729492c7..d37812da2 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleUtilTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleUtilTest.java @@ -18,7 +18,6 @@ package org.jivesoftware.smackx.jingle; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertTrue; import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; import java.io.IOException; @@ -28,13 +27,12 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.TestUtils; +import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleContentElement; import org.jivesoftware.smackx.jingle.element.JingleElement; -import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleReasonElement; import org.jivesoftware.smackx.jingle.provider.JingleProvider; -import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport; -import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil; +import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement; import org.junit.Before; import org.junit.Test; @@ -43,42 +41,29 @@ import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.stringprep.XmppStringprepException; import org.xml.sax.SAXException; - /** * Test the JingleUtil class. */ public class JingleUtilTest extends SmackTestSuite { - private XMPPConnection connection; - private JingleUtil jutil; - private FullJid romeo; private FullJid juliet; @Before public void setup() throws XmppStringprepException { - connection = new DummyConnection( + XMPPConnection connection = new DummyConnection( DummyConnection.getDummyConfigurationBuilder() .setUsernameAndPassword("romeo@montague.lit", "iluvJulibabe13").build()); JingleManager jm = JingleManager.getInstanceFor(connection); - jutil = new JingleUtil(connection); romeo = connection.getUser().asFullJidOrThrow(); juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony"); } - @Test - public void createAckTest() { - JingleElement jingle = JingleElement.getBuilder().setAction(JingleAction.session_initiate).setInitiator(romeo).setSessionId("test").build(); - IQ result = jutil.createAck(jingle); - assertEquals(jingle.getStanzaId(), result.getStanzaId()); - assertTrue(result.getType() == IQ.Type.result); - } - @Test public void createSessionTerminateDeclineTest() throws Exception { - JingleElement terminate = jutil.createSessionTerminateDecline(juliet, "thisismadness"); + JingleElement terminate = JingleElement.createSessionTerminate(juliet, "thisismadness", JingleReasonElement.Reason.decline); String jingleXML = "" + "" + "" + "" + ""; @@ -330,7 +315,7 @@ public class JingleUtilTest extends SmackTestSuite { @Test public void createTransportReplaceTest() throws IOException, SAXException { - JingleElement transportReplace = jutil.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransport("transid")); + JingleElement transportReplace = JingleElement.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE)); String jingleXML = "" + "" + "" + "" + ""; @@ -351,7 +336,7 @@ public class JingleUtilTest extends SmackTestSuite { @Test public void createErrorMalformedRequestTest() throws Exception { JingleElement j = defaultJingle(romeo, "error123"); - IQ error = jutil.createErrorMalformedRequest(j); + IQ error = JingleElement.createJingleErrorMalformedRequest(j); String xml = "