mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-25 03:57:58 +01:00
Complete JingleElement and fix jingle tests
This commit is contained in:
parent
639c951fd6
commit
e28bfa1a64
29 changed files with 358 additions and 1045 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<String, JingleTransportManager> transportManagers = new WeakHashMap<>();
|
||||
private final WeakHashMap<String, JingleSecurityManager> securityManagers = new WeakHashMap<>();
|
||||
|
||||
private final ConcurrentHashMap<FullJidAndSessionId, Session> jingleSessions = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<FullJidAndSessionId, JingleSession> 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(),
|
||||
|
|
|
@ -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<JingleTransportManage
|
|||
|
||||
String getNamespace();
|
||||
|
||||
Transport<?> createTransport(Content content);
|
||||
JingleTransport<?> createTransport(JingleContent content);
|
||||
|
||||
Transport<?> createTransport(Content content, Transport<?> peersTransport);
|
||||
JingleTransport<?> createTransport(JingleContent content, JingleTransport<?> peersTransport);
|
||||
}
|
||||
|
|
|
@ -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<D extends Description<?>> {
|
||||
public interface JingleDescriptionAdapter<D extends JingleDescription<?>> {
|
||||
|
||||
D descriptionFromElement(JingleContentDescriptionElement element);
|
||||
|
||||
|
|
|
@ -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<S extends Security<?>> {
|
||||
public interface JingleSecurityAdapter<S extends JingleSecurity<?>> {
|
||||
|
||||
S securityFromElement(JingleContentSecurityElement element);
|
||||
|
||||
|
|
|
@ -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<T extends Transport<?>> {
|
||||
public interface JingleTransportAdapter<T extends JingleTransport<?>> {
|
||||
|
||||
T transportFromElement(JingleContentTransportElement element);
|
||||
|
||||
|
|
|
@ -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<JingleContentElement> 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<JingleContentElement> 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.
|
||||
|
|
|
@ -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<Callback> callbacks = Collections.synchronizedList(new ArrayList<Callback>());
|
||||
private final Set<String> transportBlacklist = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
||||
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);
|
|
@ -21,19 +21,19 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
|||
/**
|
||||
* Class that represents a contents description component.
|
||||
*/
|
||||
public abstract class Description<D extends JingleContentDescriptionElement> {
|
||||
public abstract class JingleDescription<D extends JingleContentDescriptionElement> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -23,21 +23,21 @@ import org.jivesoftware.smackx.jingle.element.JingleContentSecurityInfoElement;
|
|||
/**
|
||||
* Class that represents a contents security component.
|
||||
*/
|
||||
public abstract class Security<D extends JingleContentSecurityElement> {
|
||||
public abstract class JingleSecurity<D extends JingleContentSecurityElement> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<String, Content> contents = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, JingleContent> contents = new ConcurrentHashMap<>();
|
||||
private final JingleManager jingleManager;
|
||||
|
||||
private final FullJid initiator, responder;
|
||||
private final Role role;
|
||||
private final String sessionId;
|
||||
|
||||
private final Map<Content, PendingJingleAction> pendingJingleActions =
|
||||
Collections.synchronizedMap(new HashMap<Content, PendingJingleAction>());
|
||||
private final Map<JingleContent, PendingJingleAction> pendingJingleActions =
|
||||
Collections.synchronizedMap(new HashMap<JingleContent, PendingJingleAction>());
|
||||
|
||||
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<JingleContentElement> initiateContents = initiate.getContents();
|
||||
|
||||
for (JingleContentElement content : initiateContents) {
|
||||
|
@ -139,7 +139,7 @@ public class Session {
|
|||
List<JingleElement> responses = new ArrayList<>();
|
||||
|
||||
for (JingleContentElement affected : affectedContents) {
|
||||
Content content = contents.get(affected.getName());
|
||||
JingleContent content = contents.get(affected.getName());
|
||||
JingleContentTransportElement newTransport = affected.getTransport();
|
||||
Set<String> blacklist = content.getTransportBlacklist();
|
||||
|
||||
|
@ -216,7 +216,7 @@ public class Session {
|
|||
}
|
||||
|
||||
private IQ handleTransportReject(JingleElement request) {
|
||||
HashMap<JingleContentElement, Content> affectedContents = getAffectedContents(request);
|
||||
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -226,11 +226,11 @@ public class Session {
|
|||
}
|
||||
|
||||
private IQ handleTransportInfo(JingleElement request) {
|
||||
HashMap<JingleContentElement, Content> affectedContents = getAffectedContents(request);
|
||||
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
|
||||
|
||||
for (Map.Entry<JingleContentElement, Content> entry : affectedContents.entrySet()) {
|
||||
for (Map.Entry<JingleContentElement, JingleContent> 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<JingleContentElement, Content> affectedContents = getAffectedContents(request);
|
||||
for (Map.Entry<JingleContentElement, Content> entry : affectedContents.entrySet()) {
|
||||
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
|
||||
for (Map.Entry<JingleContentElement, JingleContent> 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<JingleContentElement, Content> affectedContents = getAffectedContents(request);
|
||||
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
|
||||
List<JingleElement> responses = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<JingleContentElement, Content> entry : affectedContents.entrySet()) {
|
||||
for (Map.Entry<JingleContentElement, JingleContent> entry : affectedContents.entrySet()) {
|
||||
responses.add(entry.getValue().getSecurity().handleSecurityInfo(entry.getKey().getSecurity().getSecurityInfo()));
|
||||
}
|
||||
|
||||
|
@ -306,19 +306,19 @@ public class Session {
|
|||
final List<JingleContentElement> proposedContents = request.getContents();
|
||||
final List<JingleContentElement> acceptedContents = new ArrayList<>();
|
||||
|
||||
final HashMap<String, List<Content>> contentsByDescription = new HashMap<>();
|
||||
final HashMap<String, List<JingleContent>> contentsByDescription = new HashMap<>();
|
||||
|
||||
for (JingleContentElement p : proposedContents) {
|
||||
JingleContentDescriptionElement description = p.getDescription();
|
||||
List<Content> list = contentsByDescription.get(description.getNamespace());
|
||||
List<JingleContent> 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<String, List<Content>> descriptionCategory : contentsByDescription.entrySet()) {
|
||||
for (Map.Entry<String, List<JingleContent>> 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<JingleContentElement, Content> getAffectedContents(JingleElement request) {
|
||||
HashMap<JingleContentElement, Content> map = new HashMap<>();
|
||||
private HashMap<JingleContentElement, JingleContent> getAffectedContents(JingleElement request) {
|
||||
HashMap<JingleContentElement, JingleContent> 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());
|
||||
}
|
|
@ -28,17 +28,17 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
|||
/**
|
||||
* Class that represents a contents transport component.
|
||||
*/
|
||||
public abstract class Transport<D extends JingleContentTransportElement> {
|
||||
public abstract class JingleTransport<D extends JingleContentTransportElement> {
|
||||
|
||||
private Content parent;
|
||||
private final ArrayList<TransportCandidate<?>> candidates = new ArrayList<>();
|
||||
private JingleContent parent;
|
||||
private final ArrayList<JingleTransportCandidate<?>> 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<D extends JingleContentTransportElement> {
|
|||
|
||||
// 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<D extends JingleContentTransportElement> {
|
|||
}
|
||||
}
|
||||
|
||||
public List<TransportCandidate<?>> getCandidates() {
|
||||
public List<JingleTransportCandidate<?>> getCandidates() {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public abstract class Transport<D extends JingleContentTransportElement> {
|
|||
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<D extends JingleContentTransportElement> {
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -21,18 +21,18 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidateEle
|
|||
/**
|
||||
* Class that represents a transports candidate component.
|
||||
*/
|
||||
public abstract class TransportCandidate<E extends JingleContentTransportCandidateElement> {
|
||||
public abstract class JingleTransportCandidate<E extends JingleContentTransportCandidateElement> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<JingleIBBTransportElement> {
|
||||
public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElement> {
|
||||
|
||||
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<JingleIBBTransportElement> {
|
|||
|
||||
@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<JingleIBBTransportElement> {
|
|||
|
||||
@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<JingleIBBTransportElement> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addCandidate(TransportCandidate<?> candidate) {
|
||||
public void addCandidate(JingleTransportCandidate<?> candidate) {
|
||||
// Sorry, we don't want any candidates.
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<JingleS5BTransportElement> {
|
||||
public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElement> {
|
||||
|
||||
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<JingleS5BTransportElement> {
|
|||
* @param initiator initiator.
|
||||
* @param responder responder.
|
||||
*/
|
||||
public JingleS5BTransport(FullJid initiator, FullJid responder, String sid, List<TransportCandidate<?>> candidates) {
|
||||
public JingleS5BTransport(FullJid initiator, FullJid responder, String sid, List<JingleTransportCandidate<?>> candidates) {
|
||||
this(sid, Socks5Utils.createDigest(sid, initiator, responder), Bytestream.Mode.tcp, candidates);
|
||||
}
|
||||
|
||||
public JingleS5BTransport(Content content, JingleS5BTransport other, List<TransportCandidate<?>> candidates) {
|
||||
public JingleS5BTransport(JingleContent content, JingleS5BTransport other, List<JingleTransportCandidate<?>> 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<TransportCandidate<?>> candidates) {
|
||||
public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List<JingleTransportCandidate<?>> candidates) {
|
||||
this.sid = sid;
|
||||
this.dstAddr = dstAddr;
|
||||
this.mode = mode;
|
||||
|
||||
for (TransportCandidate<?> c : (candidates != null ?
|
||||
for (JingleTransportCandidate<?> c : (candidates != null ?
|
||||
candidates : Collections.<JingleS5BTransportCandidate>emptySet())) {
|
||||
addCandidate(c);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class JingleS5BTransport extends Transport<JingleS5BTransportElement> {
|
|||
.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<JingleS5BTransportElement> {
|
|||
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<JingleS5BTransportElement> {
|
|||
}
|
||||
|
||||
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<JingleS5BTransportElement> {
|
|||
}
|
||||
|
||||
// Failed to connect to any candidate.
|
||||
return null;
|
||||
return CANDIDATE_FAILURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -188,7 +188,7 @@ public class JingleS5BTransport extends Transport<JingleS5BTransportElement> {
|
|||
return;
|
||||
}
|
||||
|
||||
Iterator<TransportCandidate<?>> ourCandidates = getCandidates().iterator();
|
||||
Iterator<JingleTransportCandidate<?>> ourCandidates = getCandidates().iterator();
|
||||
while (ourCandidates.hasNext()) {
|
||||
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) ourCandidates.next();
|
||||
if (candidate.getCandidateId().equals(candidateId)) {
|
||||
|
|
|
@ -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<JingleS5BTransportCandidateElement> {
|
||||
public class JingleS5BTransportCandidate extends JingleTransportCandidate<JingleS5BTransportCandidateElement> {
|
||||
|
||||
private final String candidateId;
|
||||
private final Bytestream.StreamHost streamHost;
|
||||
|
@ -81,7 +81,7 @@ public class JingleS5BTransportCandidate extends TransportCandidate<JingleS5BTra
|
|||
client = new Socks5Client(getStreamHost(), ((JingleS5BTransport) getParent()).getDstAddr());
|
||||
}
|
||||
else {
|
||||
Session session = getParent().getParent().getParent();
|
||||
JingleSession session = getParent().getParent().getParent();
|
||||
client = new Socks5ClientForInitiator(getStreamHost(), ((JingleS5BTransport) getParent()).getDstAddr(),
|
||||
session.getJingleManager().getConnection(), session.getSessionId(), session.getPeer());
|
||||
}
|
||||
|
|
|
@ -35,10 +35,10 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
|||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.internal.Content;
|
||||
import org.jivesoftware.smackx.jingle.internal.Session;
|
||||
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.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
|
||||
import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement;
|
||||
|
@ -132,21 +132,21 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
|||
}
|
||||
|
||||
@Override
|
||||
public Transport<?> createTransport(Content content) {
|
||||
Session session = content.getParent();
|
||||
List<TransportCandidate<?>> candidates = collectCandidates();
|
||||
public JingleTransport<?> createTransport(JingleContent content) {
|
||||
JingleSession session = content.getParent();
|
||||
List<JingleTransportCandidate<?>> 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<TransportCandidate<?>> candidates = collectCandidates();
|
||||
List<JingleTransportCandidate<?>> candidates = collectCandidates();
|
||||
return new JingleS5BTransport(content, transport, candidates);
|
||||
}
|
||||
|
||||
private List<TransportCandidate<?>> collectCandidates() {
|
||||
List<TransportCandidate<?>> candidates = new ArrayList<>();
|
||||
private List<JingleTransportCandidate<?>> collectCandidates() {
|
||||
List<JingleTransportCandidate<?>> 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())
|
||||
|
|
|
@ -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<JingleS5BTransportElement> {
|
||||
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<Bytestream.StreamHost> 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<JingleS5BT
|
|||
return null;
|
||||
}
|
||||
|
||||
private UsedCandidate connectToTheirCandidate(JingleS5BTransportCandidateElement candidate)
|
||||
throws InterruptedException, TimeoutException, SmackException, XMPPException, IOException {
|
||||
Bytestream.StreamHost streamHost = candidate.getStreamHost();
|
||||
String address = streamHost.getAddress();
|
||||
Socks5Client socks5Client = new Socks5Client(streamHost, theirProposal.getDestinationAddress());
|
||||
Socket socket = socks5Client.getSocket(10 * 1000);
|
||||
LOGGER.log(Level.INFO, "Connected to their StreamHost " + address + " using dstAddr "
|
||||
+ theirProposal.getDestinationAddress());
|
||||
return new UsedCandidate(theirProposal, candidate, socket);
|
||||
}
|
||||
|
||||
private UsedCandidate connectToOurCandidate(JingleS5BTransportCandidateElement candidate)
|
||||
throws InterruptedException, TimeoutException, SmackException, XMPPException, IOException {
|
||||
Bytestream.StreamHost streamHost = candidate.getStreamHost();
|
||||
String address = streamHost.getAddress();
|
||||
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(
|
||||
streamHost, ourProposal.getDestinationAddress(), jingleSession.getConnection(),
|
||||
ourProposal.getStreamId(), jingleSession.getRemote());
|
||||
Socket socket = socks5Client.getSocket(10 * 1000);
|
||||
LOGGER.log(Level.INFO, "Connected to our StreamHost " + address + " using dstAddr "
|
||||
+ ourProposal.getDestinationAddress());
|
||||
return new UsedCandidate(ourProposal, candidate, socket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleS5BTransportElement.NAMESPACE_V1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportInfo(JingleElement transportInfo) {
|
||||
JingleS5BTransportInfoElement info = (JingleS5BTransportInfoElement) transportInfo.getContents().get(0).getTransport().getInfo();
|
||||
|
||||
switch (info.getElementName()) {
|
||||
case JingleS5BTransportInfoElement.CandidateUsed.ELEMENT:
|
||||
return handleCandidateUsed(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateActivated.ELEMENT:
|
||||
return handleCandidateActivate(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateError.ELEMENT:
|
||||
return handleCandidateError(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfoElement.ProxyError.ELEMENT:
|
||||
return handleProxyError(transportInfo);
|
||||
}
|
||||
//We should never go here, but lets be gracious...
|
||||
return IQ.createResultIQ(transportInfo);
|
||||
}
|
||||
|
||||
public IQ handleCandidateUsed(JingleElement jingle) {
|
||||
JingleS5BTransportInfoElement info = (JingleS5BTransportInfoElement) jingle.getContents().get(0).getTransport().getInfo();
|
||||
String candidateId = ((JingleS5BTransportInfoElement.CandidateUsed) info).getCandidateId();
|
||||
|
|
|
@ -1,332 +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.transport.legacy;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleErrorElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Util to quickly create and send jingle stanzas.
|
||||
*/
|
||||
public class JingleUtil {
|
||||
|
||||
private final XMPPConnection connection;
|
||||
|
||||
public JingleUtil(XMPPConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a Jingle session.
|
||||
* XEP-0166 Example 10.
|
||||
* @param recipient recipient of the stanza.
|
||||
* @param sessionId sessionId
|
||||
* @param content content
|
||||
* @return session-initiate stanza.
|
||||
*/
|
||||
public JingleElement createSessionInitiate(FullJid recipient,
|
||||
String sessionId,
|
||||
JingleContentElement content) {
|
||||
return createSessionInitiate(recipient, sessionId, Collections.singletonList(content));
|
||||
}
|
||||
|
||||
public JingleElement createSessionInitiate(FullJid recipient,
|
||||
String sessionId,
|
||||
List<JingleContentElement> 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<JingleContentElement> 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);
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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<JingleContentElement> 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();
|
||||
}
|
||||
}
|
|
@ -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<String> 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<JingleContentTransportElement> {
|
||||
|
||||
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<JingleContentTransportElement> transportSession(JingleSession jingleSession) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -97,7 +82,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateSuccessTest() throws Exception {
|
||||
JingleElement success = jutil.createSessionTerminateSuccess(juliet, "thisissparta");
|
||||
JingleElement success = JingleElement.createSessionTerminate(juliet, "thisissparta", JingleReasonElement.Reason.success);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -116,7 +101,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateBusyTest() throws Exception {
|
||||
JingleElement busy = jutil.createSessionTerminateBusy(juliet, "thisispatrick");
|
||||
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisispatrick", JingleReasonElement.Reason.busy);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -135,7 +120,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateAlternativeSessionTest() throws Exception {
|
||||
JingleElement busy = jutil.createSessionTerminateAlternativeSession(juliet, "thisistherhythm", "ofthenight");
|
||||
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisistherhythm", JingleReasonElement.AlternativeSession("ofthenight"));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -158,7 +143,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateCancelTest() throws Exception {
|
||||
JingleElement cancel = jutil.createSessionTerminateCancel(juliet, "thisistheend");
|
||||
JingleElement cancel = JingleElement.createSessionTerminate(juliet, "thisistheend", JingleReasonElement.Reason.cancel);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -177,7 +162,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateUnsupportedTransportsTest() throws Exception {
|
||||
JingleElement unsupportedTransports = jutil.createSessionTerminateUnsupportedTransports(juliet, "thisisus");
|
||||
JingleElement unsupportedTransports = JingleElement.createSessionTerminate(juliet, "thisisus", JingleReasonElement.Reason.unsupported_transports);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -196,7 +181,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateUnsupportedApplicationsTest() throws Exception {
|
||||
JingleElement unsupportedApplications = jutil.createSessionTerminateUnsupportedApplications(juliet, "thisiswar");
|
||||
JingleElement unsupportedApplications = JingleElement.createSessionTerminate(juliet, "thisiswar", JingleReasonElement.Reason.unsupported_applications);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -215,7 +200,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateFailedTransportTest() throws IOException, SAXException {
|
||||
JingleElement failedTransport = jutil.createSessionTerminateFailedTransport(juliet, "derailed");
|
||||
JingleElement failedTransport = JingleElement.createSessionTerminate(juliet, "derailed", JingleReasonElement.Reason.failed_transport);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -232,7 +217,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateFailedApplicationTest() throws IOException, SAXException {
|
||||
JingleElement failedApplication = jutil.createSessionTerminateFailedApplication(juliet, "crashed");
|
||||
JingleElement failedApplication = JingleElement.createSessionTerminate(juliet, "crashed", JingleReasonElement.Reason.failed_application);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -249,7 +234,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionPingTest() throws Exception {
|
||||
JingleElement ping = jutil.createSessionPing(juliet, "thisisit");
|
||||
JingleElement ping = JingleElement.createSessionPing(juliet, "thisisit");
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-info' " +
|
||||
|
@ -263,7 +248,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateContentCancelTest() throws Exception {
|
||||
JingleElement cancel = jutil.createSessionTerminateContentCancel(juliet, "thisismumbo#5", JingleContentElement.Creator.initiator, "content123");
|
||||
JingleElement cancel = JingleElement.createSessionTerminateContentCancel(juliet, "thisismumbo#5", JingleContentElement.Creator.initiator, "content123");
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -288,7 +273,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createSessionTerminateIncompatibleParameters() throws IOException, SAXException {
|
||||
JingleElement terminate = jutil.createSessionTerminateIncompatibleParameters(juliet, "incompatibleSID");
|
||||
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "incompatibleSID", JingleReasonElement.Reason.incompatible_parameters);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
|
@ -305,7 +290,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void createTransportAcceptTest() throws IOException, SAXException {
|
||||
JingleElement transportAccept = jutil.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransport("transid"));
|
||||
JingleElement transportAccept = JingleElement.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='transport-accept' " +
|
||||
|
@ -313,7 +298,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
"sid='transAcc'>" +
|
||||
"<content creator='initiator' name='cname'>" +
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='" + JingleIBBTransport.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"sid='transid'/>" +
|
||||
"</content>" +
|
||||
"</jingle>";
|
||||
|
@ -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 =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='transport-replace' " +
|
||||
|
@ -338,7 +323,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
"sid='transAcc'>" +
|
||||
"<content creator='initiator' name='cname'>" +
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='" + JingleIBBTransport.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"sid='transid'/>" +
|
||||
"</content>" +
|
||||
"</jingle>";
|
||||
|
@ -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 =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
|
@ -368,7 +353,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void createErrorTieBreakTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "thisistie");
|
||||
IQ error = jutil.createErrorTieBreak(j);
|
||||
IQ error = JingleElement.createJingleErrorTieBreak(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
|
@ -386,7 +371,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void createErrorUnknownSessionTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "youknownothingjohnsnow");
|
||||
IQ error = jutil.createErrorUnknownSession(j);
|
||||
IQ error = JingleElement.createJingleErrorUnknownSession(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
|
@ -404,7 +389,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void createErrorUnknownInitiatorTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "iamyourfather");
|
||||
IQ error = jutil.createErrorUnknownInitiator(j);
|
||||
IQ error = JingleElement.createJingleErrorUnknownInitiator(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
|
@ -421,7 +406,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void createErrorOutOfOrderTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "yourfatheriam");
|
||||
IQ error = jutil.createErrorOutOfOrder(j);
|
||||
IQ error = JingleElement.createJingleErrorOutOfOrder(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
|
@ -440,7 +425,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void createErrorUnsupportedInfoTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "thisstatementiswrong");
|
||||
IQ error = jutil.createErrorUnsupportedInfo(j);
|
||||
IQ error = JingleElement.createJingleErrorUnsupportedInfo(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
|
@ -462,6 +447,6 @@ public class JingleUtilTest extends SmackTestSuite {
|
|||
}
|
||||
|
||||
private JingleElement defaultJingle(FullJid recipient, String sessionId) {
|
||||
return jutil.createSessionPing(recipient, sessionId);
|
||||
return JingleElement.createSessionPing(recipient, sessionId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle.transports.jingle_ibb;
|
||||
package org.jivesoftware.smackx.jingle.transport.jingle_ibb;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle3.transport.jingle_s5b;
|
||||
package org.jivesoftware.smackx.jingle.transport.jingle_s5b;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
Loading…
Reference in a new issue