mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Reworking transports WIP
This commit is contained in:
parent
6818a52da7
commit
f4a910cfa5
44 changed files with 563 additions and 1148 deletions
|
@ -35,7 +35,6 @@ import org.jivesoftware.smack.Manager;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
|
|
|
@ -26,9 +26,6 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleReasonElement;
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
|
|
@ -29,8 +29,6 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleHandler;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
|
|
|
@ -19,9 +19,7 @@ package org.jivesoftware.smackx.jingle_filetransfer;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
|
|
|
@ -28,9 +28,6 @@ import org.jivesoftware.smack.XMPPException;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleReasonElement;
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.jivesoftware.smack.test.util.SmackTestSuite;
|
|||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.hashes.HashManager;
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtilTest;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
*
|
||||
* 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 org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
|
||||
public interface JingleHandler {
|
||||
|
||||
IQ handleJingleRequest(JingleElement jingle);
|
||||
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
*
|
||||
* 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 java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportManager;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.JingleS5BTransportManager;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
public final class JingleManager extends Manager {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName());
|
||||
|
||||
private static final Map<XMPPConnection, JingleManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private static final ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
|
||||
public static ExecutorService getThreadPool() {
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
public static synchronized JingleManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleManager jingleManager = INSTANCES.get(connection);
|
||||
if (jingleManager == null) {
|
||||
jingleManager = new JingleManager(connection);
|
||||
INSTANCES.put(connection, jingleManager);
|
||||
}
|
||||
return jingleManager;
|
||||
}
|
||||
|
||||
private final Map<String, JingleHandler> descriptionHandlers = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<FullJidAndSessionId, JingleSessionHandler> jingleSessionHandlers = new ConcurrentHashMap<>();
|
||||
|
||||
private final JingleUtil jutil;
|
||||
|
||||
private JingleManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
||||
jutil = new JingleUtil(connection);
|
||||
|
||||
connection.registerIQRequestHandler(
|
||||
new AbstractIqRequestHandler(JingleElement.ELEMENT, JingleElement.NAMESPACE, Type.set, Mode.async) {
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
final JingleElement jingle = (JingleElement) iqRequest;
|
||||
|
||||
FullJid fullFrom = jingle.getFrom().asFullJidOrThrow();
|
||||
String sid = jingle.getSid();
|
||||
FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(fullFrom, sid);
|
||||
|
||||
JingleSessionHandler sessionHandler = jingleSessionHandlers.get(fullJidAndSessionId);
|
||||
if (sessionHandler != null) {
|
||||
//Handle existing session
|
||||
return sessionHandler.handleJingleSessionRequest(jingle);
|
||||
}
|
||||
|
||||
if (jingle.getAction() == JingleAction.session_initiate) {
|
||||
|
||||
JingleContentElement content = jingle.getContents().get(0);
|
||||
JingleContentDescriptionElement description = content.getDescription();
|
||||
JingleHandler jingleDescriptionHandler = descriptionHandlers.get(
|
||||
description.getNamespace());
|
||||
|
||||
if (jingleDescriptionHandler == null) {
|
||||
//Unsupported Application
|
||||
LOGGER.log(Level.WARNING, "Unsupported Jingle application.");
|
||||
return jutil.createSessionTerminateUnsupportedApplications(fullFrom, sid);
|
||||
}
|
||||
return jingleDescriptionHandler.handleJingleRequest(jingle);
|
||||
}
|
||||
|
||||
//Unknown session
|
||||
LOGGER.log(Level.WARNING, "Unknown session.");
|
||||
return jutil.createErrorUnknownSession(jingle);
|
||||
}
|
||||
});
|
||||
//Register transports.
|
||||
JingleTransportMethodManager transportMethodManager = JingleTransportMethodManager.getInstanceFor(connection);
|
||||
transportMethodManager.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection));
|
||||
transportMethodManager.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
|
||||
}
|
||||
|
||||
public JingleHandler registerDescriptionHandler(String namespace, JingleHandler handler) {
|
||||
return descriptionHandlers.put(namespace, handler);
|
||||
}
|
||||
|
||||
public JingleSessionHandler registerJingleSessionHandler(FullJid otherJid, String sessionId, JingleSessionHandler sessionHandler) {
|
||||
FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(otherJid, sessionId);
|
||||
return jingleSessionHandlers.put(fullJidAndSessionId, sessionHandler);
|
||||
}
|
||||
|
||||
public JingleSessionHandler unregisterJingleSessionHandler(FullJid otherJid, String sessionId, JingleSessionHandler sessionHandler) {
|
||||
FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(otherJid, sessionId);
|
||||
return jingleSessionHandlers.remove(fullJidAndSessionId);
|
||||
}
|
||||
|
||||
public static String randomId() {
|
||||
return StringUtils.randomString(24);
|
||||
}
|
||||
}
|
|
@ -1,242 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
public abstract class JingleSession implements JingleSessionHandler {
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName());
|
||||
protected HashSet<String> failedTransportMethods = new HashSet<>();
|
||||
|
||||
protected final FullJid local;
|
||||
|
||||
protected final FullJid remote;
|
||||
|
||||
protected final Role role;
|
||||
|
||||
protected final String sid;
|
||||
|
||||
protected final List<JingleContentElement> contents = new ArrayList<>();
|
||||
|
||||
protected ArrayList<Future<?>> queued = new ArrayList<>();
|
||||
protected JingleTransportSession<?> transportSession;
|
||||
|
||||
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid) {
|
||||
this(initiator, responder, role, sid, null);
|
||||
}
|
||||
|
||||
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid, List<JingleContentElement> contents) {
|
||||
if (role == Role.initiator) {
|
||||
this.local = initiator;
|
||||
this.remote = responder;
|
||||
} else {
|
||||
this.local = responder;
|
||||
this.remote = initiator;
|
||||
}
|
||||
this.sid = sid;
|
||||
this.role = role;
|
||||
|
||||
if (contents != null) {
|
||||
this.contents.addAll(contents);
|
||||
}
|
||||
}
|
||||
|
||||
public FullJid getInitiator() {
|
||||
return isInitiator() ? local : remote;
|
||||
}
|
||||
|
||||
public boolean isInitiator() {
|
||||
return role == Role.initiator;
|
||||
}
|
||||
|
||||
public FullJid getResponder() {
|
||||
return isResponder() ? local : remote;
|
||||
}
|
||||
|
||||
public boolean isResponder() {
|
||||
return role == Role.responder;
|
||||
}
|
||||
|
||||
public FullJid getRemote() {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public FullJid getLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public FullJidAndSessionId getFullJidAndSessionId() {
|
||||
return new FullJidAndSessionId(remote, sid);
|
||||
}
|
||||
|
||||
public List<JingleContentElement> getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
public JingleTransportSession<?> getTransportSession() {
|
||||
return transportSession;
|
||||
}
|
||||
|
||||
protected void setTransportSession(JingleTransportSession<?> transportSession) {
|
||||
this.transportSession = transportSession;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 31 + getInitiator().hashCode();
|
||||
hashCode = 31 * hashCode + getResponder().hashCode();
|
||||
hashCode = 31 * hashCode + getSessionId().hashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof JingleSession)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JingleSession otherJingleSession = (JingleSession) other;
|
||||
return getInitiator().equals(otherJingleSession.getInitiator())
|
||||
&& getResponder().equals(otherJingleSession.getResponder())
|
||||
&& sid.equals(otherJingleSession.sid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleJingleSessionRequest(JingleElement jingle) {
|
||||
try {
|
||||
switch (jingle.getAction()) {
|
||||
case content_accept:
|
||||
return handleContentAccept(jingle);
|
||||
case content_add:
|
||||
return handleContentAdd(jingle);
|
||||
case content_modify:
|
||||
return handleContentModify(jingle);
|
||||
case content_reject:
|
||||
return handleContentReject(jingle);
|
||||
case content_remove:
|
||||
return handleContentRemove(jingle);
|
||||
case description_info:
|
||||
return handleDescriptionInfo(jingle);
|
||||
case session_info:
|
||||
return handleSessionInfo(jingle);
|
||||
case security_info:
|
||||
return handleSecurityInfo(jingle);
|
||||
case session_accept:
|
||||
return handleSessionAccept(jingle);
|
||||
case transport_accept:
|
||||
return handleTransportAccept(jingle);
|
||||
case transport_info:
|
||||
return transportSession.handleTransportInfo(jingle);
|
||||
case session_initiate:
|
||||
return handleSessionInitiate(jingle);
|
||||
case transport_reject:
|
||||
return handleTransportReject(jingle);
|
||||
case session_terminate:
|
||||
return handleSessionTerminate(jingle);
|
||||
case transport_replace:
|
||||
return handleTransportReplace(jingle);
|
||||
default:
|
||||
return IQ.createResultIQ(jingle);
|
||||
}
|
||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Caught an Exception: ", e);
|
||||
return null; //TODO: Handle better?
|
||||
}
|
||||
}
|
||||
|
||||
protected IQ handleSessionInitiate(JingleElement sessionInitiate) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
return IQ.createResultIQ(sessionInitiate);
|
||||
}
|
||||
|
||||
protected IQ handleSessionTerminate(JingleElement sessionTerminate) {
|
||||
return IQ.createResultIQ(sessionTerminate);
|
||||
}
|
||||
|
||||
protected IQ handleSessionInfo(JingleElement sessionInfo) {
|
||||
return IQ.createResultIQ(sessionInfo);
|
||||
}
|
||||
|
||||
protected IQ handleSessionAccept(JingleElement sessionAccept) throws SmackException.NotConnectedException, InterruptedException {
|
||||
return IQ.createResultIQ(sessionAccept);
|
||||
}
|
||||
|
||||
protected IQ handleContentAdd(JingleElement contentAdd) {
|
||||
return IQ.createResultIQ(contentAdd);
|
||||
}
|
||||
|
||||
protected IQ handleContentAccept(JingleElement contentAccept) {
|
||||
return IQ.createResultIQ(contentAccept);
|
||||
}
|
||||
|
||||
protected IQ handleContentModify(JingleElement contentModify) {
|
||||
return IQ.createResultIQ(contentModify);
|
||||
}
|
||||
|
||||
protected IQ handleContentReject(JingleElement contentReject) {
|
||||
return IQ.createResultIQ(contentReject);
|
||||
}
|
||||
|
||||
protected IQ handleContentRemove(JingleElement contentRemove) {
|
||||
return IQ.createResultIQ(contentRemove);
|
||||
}
|
||||
|
||||
protected IQ handleDescriptionInfo(JingleElement descriptionInfo) {
|
||||
return IQ.createResultIQ(descriptionInfo);
|
||||
}
|
||||
|
||||
protected IQ handleSecurityInfo(JingleElement securityInfo) {
|
||||
return IQ.createResultIQ(securityInfo);
|
||||
}
|
||||
|
||||
protected IQ handleTransportAccept(JingleElement transportAccept) throws SmackException.NotConnectedException, InterruptedException {
|
||||
return IQ.createResultIQ(transportAccept);
|
||||
}
|
||||
|
||||
protected IQ handleTransportReplace(JingleElement transportReplace)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
return IQ.createResultIQ(transportReplace);
|
||||
}
|
||||
|
||||
protected IQ handleTransportReject(JingleElement transportReject) {
|
||||
return IQ.createResultIQ(transportReject);
|
||||
}
|
||||
|
||||
public abstract XMPPConnection getConnection();
|
||||
|
||||
public abstract void onTransportMethodFailed(String namespace);
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
*
|
||||
* 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 org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
|
||||
public interface JingleSessionHandler {
|
||||
|
||||
IQ handleJingleSessionRequest(JingleElement jingle);
|
||||
|
||||
}
|
|
@ -1,35 +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;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 06.07.17.
|
||||
*/
|
||||
public final class JingleStreamRouter {
|
||||
private static JingleStreamRouter INSTANCE;
|
||||
|
||||
private JingleStreamRouter() {
|
||||
|
||||
}
|
||||
|
||||
public static JingleStreamRouter getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new JingleStreamRouter();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
|
@ -1,137 +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 java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
|
||||
/**
|
||||
* Manager where TransportMethods are registered.
|
||||
*/
|
||||
public final class JingleTransportMethodManager extends Manager {
|
||||
|
||||
private static final WeakHashMap<XMPPConnection, JingleTransportMethodManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private final HashMap<String, JingleTransportManager<?>> transportManagers = new HashMap<>();
|
||||
|
||||
private static final String[] transportPreference = new String[] {
|
||||
JingleS5BTransport.NAMESPACE_V1,
|
||||
JingleIBBTransport.NAMESPACE_V1
|
||||
};
|
||||
|
||||
private JingleTransportMethodManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
public static JingleTransportMethodManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleTransportMethodManager manager = INSTANCES.get(connection);
|
||||
if (manager == null) {
|
||||
manager = new JingleTransportMethodManager(connection);
|
||||
INSTANCES.put(connection, manager);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public void registerTransportManager(JingleTransportManager<?> manager) {
|
||||
transportManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public void unregisterTransportManager(JingleTransportManager<?> manager) {
|
||||
transportManagers.remove(manager.getNamespace());
|
||||
}
|
||||
|
||||
public static JingleTransportManager<?> getTransportManager(XMPPConnection connection, String namespace) {
|
||||
return getInstanceFor(connection).getTransportManager(namespace);
|
||||
}
|
||||
|
||||
public JingleTransportManager<?> getTransportManager(String namespace) {
|
||||
return transportManagers.get(namespace);
|
||||
}
|
||||
|
||||
public static JingleTransportManager<?> getTransportManager(XMPPConnection connection, JingleElement request) {
|
||||
return getInstanceFor(connection).getTransportManager(request);
|
||||
}
|
||||
public JingleTransportManager<?> getTransportManager(JingleElement request) {
|
||||
|
||||
JingleContentElement content = request.getContents().get(0);
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JingleContentTransportElement transport = content.getTransport();
|
||||
if (transport == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getTransportManager(transport.getNamespace());
|
||||
}
|
||||
|
||||
|
||||
public static JingleTransportManager<?> getBestAvailableTransportManager(XMPPConnection connection) {
|
||||
return getInstanceFor(connection).getBestAvailableTransportManager();
|
||||
}
|
||||
|
||||
public JingleTransportManager<?> getBestAvailableTransportManager() {
|
||||
JingleTransportManager<?> tm;
|
||||
for (String ns : transportPreference) {
|
||||
tm = getTransportManager(ns);
|
||||
if (tm != null) {
|
||||
return tm;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<String> it = transportManagers.keySet().iterator();
|
||||
if (it.hasNext()) {
|
||||
return getTransportManager(it.next());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public JingleTransportManager<?> getBestAvailableTransportManager(Set<String> except) {
|
||||
JingleTransportManager<?> tm;
|
||||
for (String ns : transportPreference) {
|
||||
tm = getTransportManager(ns);
|
||||
if (tm != null) {
|
||||
if (except.contains(tm.getNamespace())) {
|
||||
continue;
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
}
|
||||
|
||||
for (String ns : transportManagers.keySet()) {
|
||||
if (except.contains(ns)) {
|
||||
continue;
|
||||
}
|
||||
return getTransportManager(ns);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,23 +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;
|
||||
|
||||
public enum Role {
|
||||
initiator,
|
||||
responder,
|
||||
;
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle;
|
||||
package org.jivesoftware.smackx.jingle3;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
package org.jivesoftware.smackx.jingle3;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleDescriptionAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleSecurityAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleTransportAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentDescriptionProvider;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentSecurityProvider;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentTransportProvider;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 18.07.17.
|
||||
*/
|
||||
public final class JingleExtensionManager extends Manager {
|
||||
|
||||
private static final WeakHashMap<XMPPConnection, JingleExtensionManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private static final WeakHashMap<String, JingleContentDescriptionProvider<?>> descriptionProviders = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleContentTransportProvider<?>> transportProviders = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleContentSecurityProvider<?>> securityProviders = new WeakHashMap<>();
|
||||
|
||||
private static final WeakHashMap<String, JingleDescriptionAdapter<?>> descriptionAdapters = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleTransportAdapter<?>> transportAdapters = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleSecurityAdapter<?>> securityAdapters = new WeakHashMap<>();
|
||||
|
||||
public final WeakHashMap<String, JingleDescriptionManager> descriptionManagers = new WeakHashMap<>();
|
||||
public final WeakHashMap<String, JingleTransportManager> transportManagers = new WeakHashMap<>();
|
||||
public final WeakHashMap<String, JingleSecurityManager> securityManagers = new WeakHashMap<>();
|
||||
|
||||
private JingleExtensionManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
public static JingleExtensionManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleExtensionManager manager = INSTANCES.get(connection);
|
||||
|
||||
if (manager == null) {
|
||||
manager = new JingleExtensionManager(connection);
|
||||
INSTANCES.put(connection, manager);
|
||||
}
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static void registerDescriptionProvider(JingleContentDescriptionProvider<?> provider) {
|
||||
descriptionProviders.put(provider.getNamespace(), provider);
|
||||
}
|
||||
|
||||
public static JingleContentDescriptionProvider<?> getDescriptionProvider(String namespace) {
|
||||
return descriptionProviders.get(namespace);
|
||||
}
|
||||
|
||||
public static void registerTransportProvider(JingleContentTransportProvider<?> provider) {
|
||||
transportProviders.put(provider.getNamespace(), provider);
|
||||
}
|
||||
|
||||
public static JingleContentTransportProvider<?> getTransportProvider(String namespace) {
|
||||
return transportProviders.get(namespace);
|
||||
}
|
||||
|
||||
public static void registerSecurityProvider(JingleContentSecurityProvider<?> provider) {
|
||||
securityProviders.put(provider.getNamespace(), provider);
|
||||
}
|
||||
|
||||
public static JingleContentSecurityProvider<?> getSecurityProvider(String namespace) {
|
||||
return securityProviders.get(namespace);
|
||||
}
|
||||
|
||||
public static void addJingleDescriptionAdapter(JingleDescriptionAdapter<?> adapter) {
|
||||
descriptionAdapters.put(adapter.getNamespace(), adapter);
|
||||
}
|
||||
|
||||
public static void addJingleTransportAdapter(JingleTransportAdapter<?> adapter) {
|
||||
transportAdapters.put(adapter.getNamespace(), adapter);
|
||||
}
|
||||
|
||||
public static void addJingleSecurityAdapter(JingleSecurityAdapter<?> adapter) {
|
||||
securityAdapters.put(adapter.getNamespace(), adapter);
|
||||
}
|
||||
|
||||
public static JingleDescriptionAdapter<?> getJingleDescriptionAdapter(String namespace) {
|
||||
return descriptionAdapters.get(namespace);
|
||||
}
|
||||
|
||||
public static JingleTransportAdapter<?> getJingleTransportAdapter(String namespace) {
|
||||
return transportAdapters.get(namespace);
|
||||
}
|
||||
|
||||
public static JingleSecurityAdapter<?> getJingleSecurityAdapter(String namespace) {
|
||||
return securityAdapters.get(namespace);
|
||||
}
|
||||
|
||||
public void addJingleDescriptionManager(JingleDescriptionManager manager) {
|
||||
descriptionManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public JingleDescriptionManager getDescriptionManager(String namespace) {
|
||||
return descriptionManagers.get(namespace);
|
||||
}
|
||||
|
||||
public void addJingleTransportManager(JingleTransportManager manager) {
|
||||
transportManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public JingleTransportManager getTransportManager(String namespace) {
|
||||
return transportManagers.get(namespace);
|
||||
}
|
||||
|
||||
public void addJingleSecurityManager(JingleSecurityManager manager) {
|
||||
securityManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public JingleSecurityManager getSecurityManager(String namespace) {
|
||||
return securityManagers.get(namespace);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
package org.jivesoftware.smackx.jingle3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -8,7 +13,9 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle.FullJidAndSessionId;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleDescriptionAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleSecurityAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleTransportAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleReasonElement;
|
||||
|
@ -16,6 +23,9 @@ import org.jivesoftware.smackx.jingle3.exception.UnsupportedDescriptionException
|
|||
import org.jivesoftware.smackx.jingle3.exception.UnsupportedSecurityException;
|
||||
import org.jivesoftware.smackx.jingle3.exception.UnsupportedTransportException;
|
||||
import org.jivesoftware.smackx.jingle3.internal.Session;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentDescriptionProvider;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentSecurityProvider;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentTransportProvider;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
|
@ -25,6 +35,18 @@ import org.jxmpp.jid.FullJid;
|
|||
public class JingleManager extends Manager {
|
||||
private static final WeakHashMap<XMPPConnection, JingleManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private static final WeakHashMap<String, JingleContentDescriptionProvider<?>> descriptionProviders = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleContentTransportProvider<?>> transportProviders = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleContentSecurityProvider<?>> securityProviders = new WeakHashMap<>();
|
||||
|
||||
private static final WeakHashMap<String, JingleDescriptionAdapter<?>> descriptionAdapters = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleTransportAdapter<?>> transportAdapters = new WeakHashMap<>();
|
||||
private static final WeakHashMap<String, JingleSecurityAdapter<?>> securityAdapters = new WeakHashMap<>();
|
||||
|
||||
private final WeakHashMap<String, JingleDescriptionManager> descriptionManagers = new WeakHashMap<>();
|
||||
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 JingleManager(XMPPConnection connection) {
|
||||
|
@ -50,6 +72,7 @@ public class JingleManager extends Manager {
|
|||
//fresh. phew!
|
||||
try {
|
||||
session = Session.fromSessionInitiate(JingleManager.this, jingle);
|
||||
jingleSessions.put(fullJidAndSessionId, session);
|
||||
} catch (UnsupportedDescriptionException e) {
|
||||
return JingleElement.createSessionTerminate(jingle.getFrom().asFullJidOrThrow(),
|
||||
jingle.getSid(), JingleReasonElement.Reason.unsupported_applications);
|
||||
|
@ -58,6 +81,7 @@ public class JingleManager extends Manager {
|
|||
jingle.getSid(), JingleReasonElement.Reason.unsupported_transports);
|
||||
} catch (UnsupportedSecurityException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -82,6 +106,94 @@ public class JingleManager extends Manager {
|
|||
return manager;
|
||||
}
|
||||
|
||||
public static void registerDescriptionProvider(JingleContentDescriptionProvider<?> provider) {
|
||||
descriptionProviders.put(provider.getNamespace(), provider);
|
||||
}
|
||||
|
||||
public static JingleContentDescriptionProvider<?> getDescriptionProvider(String namespace) {
|
||||
return descriptionProviders.get(namespace);
|
||||
}
|
||||
|
||||
public static void registerTransportProvider(JingleContentTransportProvider<?> provider) {
|
||||
transportProviders.put(provider.getNamespace(), provider);
|
||||
}
|
||||
|
||||
public static JingleContentTransportProvider<?> getTransportProvider(String namespace) {
|
||||
return transportProviders.get(namespace);
|
||||
}
|
||||
|
||||
public static void registerSecurityProvider(JingleContentSecurityProvider<?> provider) {
|
||||
securityProviders.put(provider.getNamespace(), provider);
|
||||
}
|
||||
|
||||
public static JingleContentSecurityProvider<?> getSecurityProvider(String namespace) {
|
||||
return securityProviders.get(namespace);
|
||||
}
|
||||
|
||||
public static void addJingleDescriptionAdapter(JingleDescriptionAdapter<?> adapter) {
|
||||
descriptionAdapters.put(adapter.getNamespace(), adapter);
|
||||
}
|
||||
|
||||
public static void addJingleTransportAdapter(JingleTransportAdapter<?> adapter) {
|
||||
transportAdapters.put(adapter.getNamespace(), adapter);
|
||||
}
|
||||
|
||||
public static void addJingleSecurityAdapter(JingleSecurityAdapter<?> adapter) {
|
||||
securityAdapters.put(adapter.getNamespace(), adapter);
|
||||
}
|
||||
|
||||
public static JingleDescriptionAdapter<?> getJingleDescriptionAdapter(String namespace) {
|
||||
return descriptionAdapters.get(namespace);
|
||||
}
|
||||
|
||||
public static JingleTransportAdapter<?> getJingleTransportAdapter(String namespace) {
|
||||
return transportAdapters.get(namespace);
|
||||
}
|
||||
|
||||
public static JingleSecurityAdapter<?> getJingleSecurityAdapter(String namespace) {
|
||||
return securityAdapters.get(namespace);
|
||||
}
|
||||
|
||||
public void addJingleDescriptionManager(JingleDescriptionManager manager) {
|
||||
descriptionManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public JingleDescriptionManager getDescriptionManager(String namespace) {
|
||||
return descriptionManagers.get(namespace);
|
||||
}
|
||||
|
||||
public void addJingleTransportManager(JingleTransportManager manager) {
|
||||
transportManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public JingleTransportManager getTransportManager(String namespace) {
|
||||
return transportManagers.get(namespace);
|
||||
}
|
||||
|
||||
public void addJingleSecurityManager(JingleSecurityManager manager) {
|
||||
securityManagers.put(manager.getNamespace(), manager);
|
||||
}
|
||||
|
||||
public JingleSecurityManager getSecurityManager(String namespace) {
|
||||
return securityManagers.get(namespace);
|
||||
}
|
||||
|
||||
public List<JingleTransportManager> getAvailableTransportManagers() {
|
||||
return getAvailableTransportManagers(Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
private List<JingleTransportManager> getAvailableTransportManagers(Set<String> except) {
|
||||
Set<String> available = new HashSet<>(transportManagers.keySet());
|
||||
available.removeAll(except);
|
||||
List<JingleTransportManager> remaining = new ArrayList<>();
|
||||
|
||||
for (String namespace : available) {
|
||||
remaining.add(transportManagers.get(namespace));
|
||||
}
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
public XMPPConnection getConnection() {
|
||||
return connection();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.jivesoftware.smackx.jingle3;
|
||||
|
||||
import org.jivesoftware.smackx.jingle3.internal.Session;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 19.07.17.
|
||||
*/
|
||||
public interface JingleSessionInitiateListener {
|
||||
void onJingleSessionInitiate(Session session);
|
||||
}
|
|
@ -3,7 +3,7 @@ package org.jivesoftware.smackx.jingle3;
|
|||
/**
|
||||
* Created by vanitas on 19.07.17.
|
||||
*/
|
||||
public interface JingleTransportManager {
|
||||
public interface JingleTransportManager extends Comparable<JingleTransportManager> {
|
||||
|
||||
String getNamespace();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.jivesoftware.smackx.jingle3.internal.Transport;
|
|||
*/
|
||||
public interface JingleTransportAdapter<T extends Transport<?>> {
|
||||
|
||||
T transportFromElement(JingleContentTransportElement xml);
|
||||
T transportFromElement(JingleContentTransportElement element);
|
||||
|
||||
String getNamespace();
|
||||
}
|
|
@ -51,7 +51,6 @@ public abstract class JingleContentTransportElement implements ExtensionElement
|
|||
else {
|
||||
this.candidates = Collections.emptyList();
|
||||
}
|
||||
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Set;
|
|||
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.jingle3.Callback;
|
||||
import org.jivesoftware.smackx.jingle3.JingleExtensionManager;
|
||||
import org.jivesoftware.smackx.jingle3.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleDescriptionAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleSecurityAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleTransportAdapter;
|
||||
|
@ -51,7 +51,7 @@ public class Content {
|
|||
|
||||
JingleContentDescriptionElement descriptionElement = content.getDescription();
|
||||
if (descriptionElement != null) {
|
||||
JingleDescriptionAdapter<?> descriptionAdapter = JingleExtensionManager.getJingleDescriptionAdapter(content.getDescription().getNamespace());
|
||||
JingleDescriptionAdapter<?> descriptionAdapter = JingleManager.getJingleDescriptionAdapter(content.getDescription().getNamespace());
|
||||
if (descriptionAdapter != null) {
|
||||
description = descriptionAdapter.descriptionFromElement(descriptionElement);
|
||||
} else {
|
||||
|
@ -62,7 +62,7 @@ public class Content {
|
|||
|
||||
JingleContentTransportElement transportElement = content.getTransport();
|
||||
if (transportElement != null) {
|
||||
JingleTransportAdapter<?> transportAdapter = JingleExtensionManager.getJingleTransportAdapter(content.getTransport().getNamespace());
|
||||
JingleTransportAdapter<?> transportAdapter = JingleManager.getJingleTransportAdapter(content.getTransport().getNamespace());
|
||||
if (transportAdapter != null) {
|
||||
transport = transportAdapter.transportFromElement(transportElement);
|
||||
} else {
|
||||
|
@ -73,7 +73,7 @@ public class Content {
|
|||
|
||||
JingleContentSecurityElement securityElement = content.getSecurity();
|
||||
if (securityElement != null) {
|
||||
JingleSecurityAdapter<?> securityAdapter = JingleExtensionManager.getJingleSecurityAdapter(content.getSecurity().getNamespace());
|
||||
JingleSecurityAdapter<?> securityAdapter = JingleManager.getJingleSecurityAdapter(content.getSecurity().getNamespace());
|
||||
if (securityAdapter != null) {
|
||||
security = securityAdapter.securityFromElement(securityElement);
|
||||
} else {
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.jivesoftware.smack.SmackException;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle3.JingleDescriptionManager;
|
||||
import org.jivesoftware.smackx.jingle3.JingleExtensionManager;
|
||||
import org.jivesoftware.smackx.jingle3.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle3.Role;
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleTransportAdapter;
|
||||
|
@ -23,6 +22,7 @@ import org.jivesoftware.smackx.jingle3.element.JingleAction;
|
|||
import org.jivesoftware.smackx.jingle3.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle3.exception.UnsupportedDescriptionException;
|
||||
|
@ -135,7 +135,7 @@ public class Session {
|
|||
|
||||
}
|
||||
|
||||
JingleTransportAdapter<?> transportAdapter = JingleExtensionManager.getJingleTransportAdapter(
|
||||
JingleTransportAdapter<?> transportAdapter = JingleManager.getJingleTransportAdapter(
|
||||
newTransport.getNamespace());
|
||||
// This might be an unknown transport.
|
||||
if (transportAdapter == null) {
|
||||
|
@ -145,7 +145,7 @@ public class Session {
|
|||
}
|
||||
|
||||
//Otherwise, when all went well so far, accept the transport-replace
|
||||
content.setTransport(JingleExtensionManager.getJingleTransportAdapter(newTransport.getNamespace())
|
||||
content.setTransport(JingleManager.getJingleTransportAdapter(newTransport.getNamespace())
|
||||
.transportFromElement(newTransport));
|
||||
responses.add(JingleElement.createTransportAccept(getInitiator(), getPeer(), getSessionId(),
|
||||
content.getCreator(), content.getName(), newTransport));
|
||||
|
@ -165,9 +165,11 @@ public class Session {
|
|||
|
||||
private IQ handleSessionTerminate(JingleElement request) {
|
||||
JingleReasonElement reason = request.getReason();
|
||||
|
||||
if (reason == null) {
|
||||
throw new AssertionError("Reason MUST not be null! (I guess)...");
|
||||
}
|
||||
|
||||
switch (reason.asEnum()) {
|
||||
case alternative_session:
|
||||
case busy:
|
||||
|
@ -192,7 +194,7 @@ public class Session {
|
|||
case unsupported_transports:
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unknown reson enum: " + reason.asEnum().toString());
|
||||
throw new AssertionError("Unknown reason enum: " + reason.asEnum().toString());
|
||||
}
|
||||
return IQ.createResultIQ(request);
|
||||
}
|
||||
|
@ -209,18 +211,12 @@ public class Session {
|
|||
|
||||
private IQ handleTransportInfo(JingleElement request) {
|
||||
HashMap<JingleContentElement, Content> affectedContents = getAffectedContents(request);
|
||||
List<JingleElement> responses = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<JingleContentElement, Content> entry : affectedContents.entrySet()) {
|
||||
responses.add(entry.getValue().getTransport().handleTransportInfo(entry.getKey().getTransport().getInfo()));
|
||||
}
|
||||
|
||||
for (JingleElement response : responses) {
|
||||
try {
|
||||
getJingleManager().getConnection().createStanzaCollectorAndSend(response).nextResultOrThrow();
|
||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send response to transport-info: " + e, e);
|
||||
}
|
||||
Transport<?> transport = entry.getValue().getTransport();
|
||||
JingleContentTransportInfoElement info = entry.getKey().getTransport().getInfo();
|
||||
transport.handleTransportInfo(info);
|
||||
}
|
||||
|
||||
return IQ.createResultIQ(request);
|
||||
|
@ -307,7 +303,7 @@ public class Session {
|
|||
}
|
||||
|
||||
for (Map.Entry<String, List<Content>> descriptionCategory : contentsByDescription.entrySet()) {
|
||||
JingleDescriptionManager descriptionManager = JingleExtensionManager.getInstanceFor(getJingleManager().getConnection()).getDescriptionManager(descriptionCategory.getKey());
|
||||
JingleDescriptionManager descriptionManager = JingleManager.getInstanceFor(getJingleManager().getConnection()).getDescriptionManager(descriptionCategory.getKey());
|
||||
|
||||
if (descriptionManager == null) {
|
||||
//blabla
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package org.jivesoftware.smackx.jingle3.internal;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.BytestreamSessionEstablishedListener;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 18.07.17.
|
||||
*/
|
||||
|
@ -15,9 +16,17 @@ public abstract class Transport<D extends JingleContentTransportElement> {
|
|||
|
||||
public abstract String getNamespace();
|
||||
|
||||
public abstract BytestreamSession establishIncomingBytestreamSession(BytestreamSessionEstablishedListener listener);
|
||||
public abstract void establishIncomingBytestreamSession(FullJid peer,
|
||||
String transportSessionId,
|
||||
BytestreamSessionEstablishedListener listener,
|
||||
XMPPConnection connection);
|
||||
|
||||
public abstract BytestreamSession establishOutgoingBytestreamSession(BytestreamSessionEstablishedListener listener);
|
||||
public abstract void establishOutgoingBytestreamSession(FullJid peer,
|
||||
String transportSessionId,
|
||||
BytestreamSessionEstablishedListener listener,
|
||||
XMPPConnection connection);
|
||||
|
||||
public abstract JingleElement handleTransportInfo(JingleContentTransportInfoElement info);
|
||||
public abstract void setPeersProposal(Transport<?> peersProposal);
|
||||
|
||||
public abstract void handleTransportInfo(JingleContentTransportInfoElement info);
|
||||
}
|
||||
|
|
|
@ -1,25 +1,33 @@
|
|||
package org.jivesoftware.smackx.jingle3.transport.ibb;
|
||||
package org.jivesoftware.smackx.jingle3.transport.jingle_ibb;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
||||
import org.jivesoftware.smackx.jingle3.internal.Session;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle3.internal.Transport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.BytestreamSessionEstablishedListener;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 18.07.17.
|
||||
*/
|
||||
public class JingleIBBTransport extends Transport<JingleIBBTransportElement> {
|
||||
|
||||
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:ibb:1";
|
||||
public static final String NAMESPACE = NAMESPACE_V1;
|
||||
|
||||
private final String streamId;
|
||||
private final Short blockSize;
|
||||
|
||||
private JingleIBBTransport peersProposal;
|
||||
|
||||
public JingleIBBTransport(String streamId, Short blockSize) {
|
||||
this.streamId = streamId;
|
||||
this.blockSize = blockSize;
|
||||
|
@ -31,39 +39,55 @@ public class JingleIBBTransport extends Transport<JingleIBBTransportElement> {
|
|||
|
||||
@Override
|
||||
public JingleIBBTransportElement getElement() {
|
||||
return new JingleIBBTransportElement(blockSize, streamId);
|
||||
return new JingleIBBTransportElement(streamId, blockSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleIBBTransportElement.NAMESPACE_V1;
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytestreamSession establishIncomingBytestreamSession(final Session session) {
|
||||
|
||||
InBandBytestreamManager.getByteStreamManager(session.getJingleManager().getConnection())
|
||||
public void establishIncomingBytestreamSession(final FullJid peer, final String transportSessionId, final BytestreamSessionEstablishedListener listener, XMPPConnection connection) {
|
||||
InBandBytestreamManager.getByteStreamManager(connection)
|
||||
.addIncomingBytestreamListener(new BytestreamListener() {
|
||||
@Override
|
||||
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||
if (request.getFrom().asFullJidIfPossible().equals(session.getPeer())
|
||||
&& request.getSessionID().equals(theirProposal.getSessionId())) {
|
||||
if (request.getFrom().asFullJidIfPossible().equals(peer)
|
||||
&& request.getSessionID().equals(transportSessionId)) {
|
||||
BytestreamSession bytestreamSession;
|
||||
|
||||
try {
|
||||
bytestreamSession = request.accept();
|
||||
} catch (InterruptedException | SmackException | XMPPException.XMPPErrorException e) {
|
||||
.onException(e);
|
||||
listener.onBytestreamSessionFailed(e);
|
||||
return;
|
||||
}
|
||||
callback.onSessionInitiated(bytestreamSession);
|
||||
listener.onBytestreamSessionEstablished(bytestreamSession);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytestreamSession establishOutgoingBytestreamSession(BytestreamSessionEstablishedListener listener) {
|
||||
return null;
|
||||
public void establishOutgoingBytestreamSession(FullJid peer, String transportSessionId, BytestreamSessionEstablishedListener listener, XMPPConnection connection) {
|
||||
InBandBytestreamManager inBandBytestreamManager = InBandBytestreamManager.getByteStreamManager(connection);
|
||||
inBandBytestreamManager.setDefaultBlockSize(blockSize);
|
||||
try {
|
||||
BytestreamSession session = inBandBytestreamManager.establishSession(peer, transportSessionId);
|
||||
listener.onBytestreamSessionEstablished(session);
|
||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
|
||||
listener.onBytestreamSessionFailed(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPeersProposal(Transport<?> peersProposal) {
|
||||
this.peersProposal = (JingleIBBTransport) peersProposal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportInfo(JingleContentTransportInfoElement info) {
|
||||
// Nothing to do.
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.jivesoftware.smackx.jingle3.transport.ibb;
|
||||
package org.jivesoftware.smackx.jingle3.transport.jingle_ibb;
|
||||
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleTransportAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
|
@ -11,11 +11,11 @@ public class JingleIBBTransportAdapter implements JingleTransportAdapter<JingleI
|
|||
@Override
|
||||
public JingleIBBTransport transportFromElement(JingleContentTransportElement element) {
|
||||
JingleIBBTransportElement transport = (JingleIBBTransportElement) element;
|
||||
return new JingleIBBTransport(transport.getSessionId(), transport.getBlockSize());
|
||||
return new JingleIBBTransport(transport.getSid(), transport.getBlockSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleIBBTransportElement.NAMESPACE_V1;
|
||||
return JingleIBBTransport.NAMESPACE;
|
||||
}
|
||||
}
|
|
@ -1,64 +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.jingle3.transport.jingle_ibb;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.provider.JingleIBBTransportProvider;
|
||||
|
||||
/**
|
||||
* Manager for Jingle InBandBytestream transports (XEP-0261).
|
||||
*/
|
||||
public final class JingleIBBTransportManager extends JingleTransportManager<JingleIBBTransportElement> {
|
||||
|
||||
private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>();
|
||||
|
||||
private JingleIBBTransportManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleIBBTransportProvider());
|
||||
}
|
||||
|
||||
public static JingleIBBTransportManager getInstanceFor(XMPPConnection connection) {
|
||||
JingleIBBTransportManager manager = INSTANCES.get(connection);
|
||||
if (manager == null) {
|
||||
manager = new JingleIBBTransportManager(connection);
|
||||
INSTANCES.put(connection, manager);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleIBBTransportElement.NAMESPACE_V1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleTransportSession<JingleIBBTransportElement> transportSession(JingleSession jingleSession) {
|
||||
return new JingleIBBTransportSession(jingleSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
//Nothing to do.
|
||||
}
|
||||
}
|
|
@ -1,115 +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.jingle3.transport.jingle_ibb;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
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.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
|
||||
public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBTransportElement> {
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleIBBTransportSession.class.getName());
|
||||
|
||||
private final JingleIBBTransportManager transportManager;
|
||||
|
||||
public JingleIBBTransportSession(JingleSession session) {
|
||||
super(session);
|
||||
transportManager = JingleIBBTransportManager.getInstanceFor(session.getConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleIBBTransportElement createTransport() {
|
||||
|
||||
if (theirProposal == null) {
|
||||
return new JingleIBBTransportElement();
|
||||
} else {
|
||||
return new JingleIBBTransportElement(theirProposal.getBlockSize(), theirProposal.getSessionId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTheirProposal(JingleContentTransportElement transport) {
|
||||
theirProposal = (JingleIBBTransportElement) transport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiateOutgoingSession(JingleTransportInitiationCallback callback) {
|
||||
LOGGER.log(Level.INFO, "Initiate Jingle InBandBytestream session.");
|
||||
|
||||
BytestreamSession session;
|
||||
try {
|
||||
session = InBandBytestreamManager.getByteStreamManager(jingleSession.getConnection())
|
||||
.establishSession(jingleSession.getRemote(), theirProposal.getSessionId());
|
||||
callback.onSessionInitiated(session);
|
||||
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
callback.onException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiateIncomingSession(final JingleTransportInitiationCallback callback) {
|
||||
LOGGER.log(Level.INFO, "Await Jingle InBandBytestream session.");
|
||||
|
||||
InBandBytestreamManager.getByteStreamManager(jingleSession.getConnection()).addIncomingBytestreamListener(new BytestreamListener() {
|
||||
@Override
|
||||
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||
if (request.getFrom().asFullJidIfPossible().equals(jingleSession.getRemote())
|
||||
&& request.getSessionID().equals(theirProposal.getSessionId())) {
|
||||
BytestreamSession session;
|
||||
|
||||
try {
|
||||
session = request.accept();
|
||||
} catch (InterruptedException | SmackException | XMPPException.XMPPErrorException e) {
|
||||
callback.onException(e);
|
||||
return;
|
||||
}
|
||||
callback.onSessionInitiated(session);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return transportManager.getNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportInfo(JingleElement transportInfo) {
|
||||
return IQ.createResultIQ(transportInfo);
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleTransportManager<JingleIBBTransportElement> transportManager() {
|
||||
return JingleIBBTransportManager.getInstanceFor(jingleSession.getConnection());
|
||||
}
|
||||
}
|
|
@ -16,49 +16,36 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle3.transport.jingle_ibb.element;
|
||||
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.JingleIBBTransport;
|
||||
|
||||
/**
|
||||
* Transport Element for JingleInBandBytestream transports.
|
||||
*/
|
||||
public class JingleIBBTransportElement extends JingleContentTransportElement {
|
||||
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:ibb:1";
|
||||
public static final String ATTR_BLOCK_SIZE = "block-size";
|
||||
public static final String ATTR_SID = "sid";
|
||||
|
||||
public static final short DEFAULT_BLOCK_SIZE = 4096;
|
||||
|
||||
private final short blockSize;
|
||||
private final String sid;
|
||||
private final short blockSize;
|
||||
|
||||
public JingleIBBTransportElement() {
|
||||
this(DEFAULT_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
public JingleIBBTransportElement(String sid) {
|
||||
this(DEFAULT_BLOCK_SIZE, sid);
|
||||
}
|
||||
|
||||
public JingleIBBTransportElement(Short blockSize) {
|
||||
this(blockSize, StringUtils.randomString(24));
|
||||
}
|
||||
|
||||
public JingleIBBTransportElement(Short blockSize, String sid) {
|
||||
public JingleIBBTransportElement(String streamId, Short blockSize) {
|
||||
super(null);
|
||||
this.sid = streamId;
|
||||
this.blockSize = blockSize != null ? blockSize : DEFAULT_BLOCK_SIZE;
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public short getBlockSize() {
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addExtraAttributes(XmlStringBuilder xml) {
|
||||
xml.attribute(ATTR_BLOCK_SIZE, blockSize);
|
||||
|
@ -67,7 +54,7 @@ public class JingleIBBTransportElement extends JingleContentTransportElement {
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE_V1;
|
||||
return JingleIBBTransport.NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.jivesoftware.smackx.jingle3.transport.jingle_ibb.provider;
|
|||
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.JingleIBBTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -35,6 +36,6 @@ public class JingleIBBTransportProvider extends JingleContentTransportProvider
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleIBBTransportElement.NAMESPACE_V1;
|
||||
return JingleIBBTransport.NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
package org.jivesoftware.smackx.jingle3.transport.jingle_s5b;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle3.internal.Transport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.BytestreamSessionEstablishedListener;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfoElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 19.07.17.
|
||||
*/
|
||||
public class JingleS5BTransport extends Transport<JingleS5BTransportElement> {
|
||||
|
||||
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:s5b:1";
|
||||
public static final String NAMESPACE = NAMESPACE_V1;
|
||||
|
||||
private final String sid;
|
||||
|
||||
private String dstAddr;
|
||||
private Bytestream.Mode mode;
|
||||
private HashMap<String, JingleS5BTransportCandidate> candidates = new HashMap<>();
|
||||
|
||||
private String peerDstAddr;
|
||||
private Bytestream.Mode peerMode;
|
||||
private HashMap<String, JingleS5BTransportCandidate> peerCandidates;
|
||||
|
||||
private JingleS5BTransportCandidate ourChoice, theirChoice;
|
||||
private JingleS5BTransportCandidate nominee;
|
||||
|
||||
public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List<JingleS5BTransportCandidate> candidates) {
|
||||
this.sid = sid;
|
||||
this.dstAddr = dstAddr;
|
||||
this.mode = mode;
|
||||
|
||||
for (JingleS5BTransportCandidate c : (candidates != null ?
|
||||
candidates : Collections.<JingleS5BTransportCandidate>emptySet())) {
|
||||
this.candidates.put(c.getCandidateId(), c);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleS5BTransportElement getElement() {
|
||||
JingleS5BTransportElement.Builder builder = JingleS5BTransportElement.getBuilder()
|
||||
.setStreamId(sid)
|
||||
.setDestinationAddress(dstAddr)
|
||||
.setMode(mode);
|
||||
|
||||
for (JingleS5BTransportCandidate candidate : candidates.values()) {
|
||||
builder.addTransportCandidate(
|
||||
(JingleS5BTransportCandidateElement) candidate.getElement());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void establishIncomingBytestreamSession(FullJid peer, String transportSessionId, BytestreamSessionEstablishedListener listener, XMPPConnection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void establishOutgoingBytestreamSession(FullJid peer, String transportSessionId, BytestreamSessionEstablishedListener listener, XMPPConnection connection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPeersProposal(Transport<?> peersProposal) {
|
||||
JingleS5BTransport transport = (JingleS5BTransport) peersProposal;
|
||||
peerCandidates = transport.candidates;
|
||||
peerDstAddr = transport.dstAddr;
|
||||
peerMode = transport.mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTransportInfo(JingleContentTransportInfoElement info) {
|
||||
switch (info.getElementName()) {
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateUsed.ELEMENT:
|
||||
handleCandidateUsed((JingleS5BTransportInfoElement) info);
|
||||
return;
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateActivated.ELEMENT:
|
||||
handleCandidateActivate((JingleS5BTransportInfoElement) info);
|
||||
return;
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateError.ELEMENT:
|
||||
handleCandidateError((JingleS5BTransportInfoElement) info);
|
||||
return;
|
||||
|
||||
case JingleS5BTransportInfoElement.ProxyError.ELEMENT:
|
||||
handleProxyError((JingleS5BTransportInfoElement) info);
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new AssertionError("Unknown transport-info element: " + info.getElementName());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCandidateUsed(JingleS5BTransportInfoElement info) {
|
||||
String candidateId = ((JingleS5BTransportInfoElement.CandidateUsed) info).getCandidateId();
|
||||
theirChoice = candidates.get(candidateId);
|
||||
|
||||
if (theirChoice == null) {
|
||||
/*
|
||||
TODO: Booooooh illegal candidateId!! Go home!!!!11elf
|
||||
*/
|
||||
}
|
||||
|
||||
//connectIfReady();
|
||||
}
|
||||
|
||||
private void handleCandidateActivate(JingleS5BTransportInfoElement info) {
|
||||
//Socks5BytestreamSession bs = new Socks5BytestreamSession(ourChoice.socket,
|
||||
// ourChoice.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid()));
|
||||
//callback.onSessionInitiated(bs);
|
||||
}
|
||||
|
||||
private void handleCandidateError(JingleS5BTransportInfoElement info) {
|
||||
theirChoice = CANDIDATE_FAILURE;
|
||||
//connectIfReady();
|
||||
}
|
||||
|
||||
private void handleProxyError(JingleS5BTransportInfoElement info) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal dummy candidate used to represent failure.
|
||||
* Kinda depressing, isn't it?
|
||||
*/
|
||||
private final static JingleS5BTransportCandidate CANDIDATE_FAILURE = new JingleS5BTransportCandidate(null, null, -1, null);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.jivesoftware.smackx.jingle3.transport.jingle_s5b;
|
||||
|
||||
import org.jivesoftware.smackx.jingle3.adapter.JingleTransportAdapter;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 19.07.17.
|
||||
*/
|
||||
public class JingleS5BTransportAdapter implements JingleTransportAdapter<JingleS5BTransport> {
|
||||
|
||||
@Override
|
||||
public JingleS5BTransport transportFromElement(JingleContentTransportElement element) {
|
||||
JingleS5BTransport transport = new JingleS5BTransport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleS5BTransport.NAMESPACE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package org.jivesoftware.smackx.jingle3.transport.jingle_s5b;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 19.07.17.
|
||||
*/
|
||||
public class JingleS5BTransportCandidate {
|
||||
|
||||
private final String candidateId;
|
||||
private final Bytestream.StreamHost streamHost;
|
||||
private final int priority;
|
||||
private final JingleS5BTransportCandidateElement.Type type;
|
||||
|
||||
public JingleS5BTransportCandidate(String candidateId,
|
||||
Bytestream.StreamHost streamHost,
|
||||
int priority,
|
||||
JingleS5BTransportCandidateElement.Type type) {
|
||||
this.candidateId = candidateId;
|
||||
this.streamHost = streamHost;
|
||||
this.priority = priority;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getCandidateId() {
|
||||
return candidateId;
|
||||
}
|
||||
|
||||
public Bytestream.StreamHost getStreamHost() {
|
||||
return streamHost;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public JingleS5BTransportCandidateElement.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public JingleContentTransportCandidateElement getElement() {
|
||||
return new JingleS5BTransportCandidateElement(candidateId, streamHost.getAddress(), streamHost.getJID(), streamHost.getPort(), priority, type);
|
||||
}
|
||||
}
|
|
@ -31,9 +31,9 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
|||
/**
|
||||
* TransportCandidate for Jingle Socks5Bytestream transports.
|
||||
*/
|
||||
public final class JingleS5BTransportCandidate extends JingleContentTransportCandidateElement {
|
||||
public final class JingleS5BTransportCandidateElement extends JingleContentTransportCandidateElement {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportCandidate.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportCandidateElement.class.getName());
|
||||
|
||||
public static final String ATTR_CID = "cid";
|
||||
public static final String ATTR_HOST = "host";
|
||||
|
@ -49,7 +49,7 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
|
|||
private final int priority;
|
||||
private final Type type;
|
||||
|
||||
public JingleS5BTransportCandidate(String candidateId, String host, Jid jid, int port, int priority, Type type) {
|
||||
public JingleS5BTransportCandidateElement(String candidateId, String host, Jid jid, int port, int priority, Type type) {
|
||||
|
||||
Objects.requireNonNull(candidateId);
|
||||
Objects.requireNonNull(host);
|
||||
|
@ -70,7 +70,7 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public JingleS5BTransportCandidate(Bytestream.StreamHost streamHost, int priority, Type type) {
|
||||
public JingleS5BTransportCandidateElement(Bytestream.StreamHost streamHost, int priority, Type type) {
|
||||
this(StringUtils.randomString(24), streamHost.getAddress(), streamHost.getJID(), streamHost.getPort(), priority, type);
|
||||
}
|
||||
|
||||
|
@ -197,8 +197,8 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
|
|||
return this;
|
||||
}
|
||||
|
||||
public JingleS5BTransportCandidate build() {
|
||||
return new JingleS5BTransportCandidate(cid, host, jid, port, priority, type);
|
||||
public JingleS5BTransportCandidateElement build() {
|
||||
return new JingleS5BTransportCandidateElement(cid, host, jid, port, priority, type);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,26 +29,26 @@ import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement
|
|||
/**
|
||||
* Socks5Bytestream transport element.
|
||||
*/
|
||||
public class JingleS5BTransport extends JingleContentTransportElement {
|
||||
public class JingleS5BTransportElement extends JingleContentTransportElement {
|
||||
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:s5b:1";
|
||||
public static final String ATTR_DSTADDR = "dstaddr";
|
||||
public static final String ATTR_MODE = "mode";
|
||||
public static final String ATTR_SID = "sid";
|
||||
|
||||
private final String streamId;
|
||||
private final String sid;
|
||||
private final String dstAddr;
|
||||
private final Bytestream.Mode mode;
|
||||
|
||||
protected JingleS5BTransport(List<JingleContentTransportCandidateElement> candidates, JingleContentTransportInfoElement info, String streamId, String dstAddr, Bytestream.Mode mode) {
|
||||
protected JingleS5BTransportElement(String streamId, List<JingleContentTransportCandidateElement> candidates, JingleContentTransportInfoElement info, String dstAddr, Bytestream.Mode mode) {
|
||||
super(candidates, info);
|
||||
StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty.");
|
||||
this.streamId = streamId;
|
||||
this.sid = streamId;
|
||||
this.dstAddr = dstAddr;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public String getStreamId() {
|
||||
return streamId;
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public String getDestinationAddress() {
|
||||
|
@ -68,16 +68,16 @@ public class JingleS5BTransport extends JingleContentTransportElement {
|
|||
protected void addExtraAttributes(XmlStringBuilder xml) {
|
||||
xml.optAttribute(ATTR_DSTADDR, dstAddr);
|
||||
xml.optAttribute(ATTR_MODE, mode);
|
||||
xml.attribute(ATTR_SID, streamId);
|
||||
xml.attribute(ATTR_SID, sid);
|
||||
}
|
||||
|
||||
public boolean hasCandidate(String candidateId) {
|
||||
return getCandidate(candidateId) != null;
|
||||
}
|
||||
|
||||
public JingleS5BTransportCandidate getCandidate(String candidateId) {
|
||||
public JingleS5BTransportCandidateElement getCandidate(String candidateId) {
|
||||
for (JingleContentTransportCandidateElement c : candidates) {
|
||||
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) c;
|
||||
JingleS5BTransportCandidateElement candidate = (JingleS5BTransportCandidateElement) c;
|
||||
if (candidate.getCandidateId().equals(candidateId)) {
|
||||
return candidate;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class JingleS5BTransport extends JingleContentTransportElement {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder addTransportCandidate(JingleS5BTransportCandidate candidate) {
|
||||
public Builder addTransportCandidate(JingleS5BTransportCandidateElement candidate) {
|
||||
if (info != null) {
|
||||
throw new IllegalStateException("Builder has already an info set. " +
|
||||
"The transport can only have either an info or transport candidates, not both.");
|
||||
|
@ -133,23 +133,23 @@ public class JingleS5BTransport extends JingleContentTransportElement {
|
|||
}
|
||||
|
||||
public Builder setCandidateUsed(String candidateId) {
|
||||
return setTransportInfo(JingleS5BTransportInfo.CandidateUsed(candidateId));
|
||||
return setTransportInfo(JingleS5BTransportInfoElement.CandidateUsed(candidateId));
|
||||
}
|
||||
|
||||
public Builder setCandidateActivated(String candidateId) {
|
||||
return setTransportInfo(JingleS5BTransportInfo.CandidateActivated(candidateId));
|
||||
return setTransportInfo(JingleS5BTransportInfoElement.CandidateActivated(candidateId));
|
||||
}
|
||||
|
||||
public Builder setCandidateError() {
|
||||
return setTransportInfo(JingleS5BTransportInfo.CandidateError());
|
||||
return setTransportInfo(JingleS5BTransportInfoElement.CandidateError());
|
||||
}
|
||||
|
||||
public Builder setProxyError() {
|
||||
return setTransportInfo(JingleS5BTransportInfo.ProxyError());
|
||||
return setTransportInfo(JingleS5BTransportInfoElement.ProxyError());
|
||||
}
|
||||
|
||||
public JingleS5BTransport build() {
|
||||
return new JingleS5BTransport(candidates, info, streamId, dstAddr, mode);
|
||||
public JingleS5BTransportElement build() {
|
||||
return new JingleS5BTransportElement(streamId, candidates, info, dstAddr, mode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement
|
|||
/**
|
||||
* Class representing possible SOCKS5 TransportInfo elements.
|
||||
*/
|
||||
public abstract class JingleS5BTransportInfo extends JingleContentTransportInfoElement {
|
||||
public abstract class JingleS5BTransportInfoElement extends JingleContentTransportInfoElement {
|
||||
|
||||
private static CandidateError CEI;
|
||||
private static ProxyError PEI;
|
||||
|
@ -49,7 +49,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfoE
|
|||
return PEI;
|
||||
}
|
||||
|
||||
public static final class CandidateActivated extends JingleS5BTransportInfo {
|
||||
public static final class CandidateActivated extends JingleS5BTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-activated";
|
||||
public static final String ATTR_CID = "cid";
|
||||
|
||||
|
@ -89,7 +89,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfoE
|
|||
}
|
||||
}
|
||||
|
||||
public static final class CandidateUsed extends JingleS5BTransportInfo {
|
||||
public static final class CandidateUsed extends JingleS5BTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-used";
|
||||
public static final String ATTR_CID = "cid";
|
||||
|
||||
|
@ -129,7 +129,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfoE
|
|||
}
|
||||
}
|
||||
|
||||
public static final class CandidateError extends JingleS5BTransportInfo {
|
||||
public static final class CandidateError extends JingleS5BTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-error";
|
||||
|
||||
private CandidateError() {
|
||||
|
@ -160,7 +160,7 @@ public abstract class JingleS5BTransportInfo extends JingleContentTransportInfoE
|
|||
}
|
||||
}
|
||||
|
||||
public static final class ProxyError extends JingleS5BTransportInfo {
|
||||
public static final class ProxyError extends JingleS5BTransportInfoElement {
|
||||
public static final String ELEMENT = "proxy-error";
|
||||
|
||||
private ProxyError() {
|
|
@ -18,44 +18,44 @@ package org.jivesoftware.smackx.jingle3.transport.jingle_s5b.provider;
|
|||
|
||||
import static org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.Mode.tcp;
|
||||
import static org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.Mode.udp;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_CID;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_HOST;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_JID;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_PORT;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_PRIORITY;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate.ATTR_TYPE;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement.ATTR_CID;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement.ATTR_HOST;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement.ATTR_JID;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement.ATTR_PORT;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement.ATTR_PRIORITY;
|
||||
import static org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement.ATTR_TYPE;
|
||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfoElement;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Provider for JingleSocks5BytestreamTransport elements.
|
||||
*/
|
||||
public class JingleS5BTransportProvider extends JingleContentTransportProvider<JingleS5BTransport> {
|
||||
public class JingleS5BTransportProvider extends JingleContentTransportProvider<JingleS5BTransportElement> {
|
||||
|
||||
@Override
|
||||
public JingleS5BTransport parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
JingleS5BTransport.Builder builder = JingleS5BTransport.getBuilder();
|
||||
public JingleS5BTransportElement parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
JingleS5BTransportElement.Builder builder = JingleS5BTransportElement.getBuilder();
|
||||
|
||||
String streamId = parser.getAttributeValue(null, JingleS5BTransport.ATTR_SID);
|
||||
String streamId = parser.getAttributeValue(null, JingleS5BTransportElement.ATTR_SID);
|
||||
builder.setStreamId(streamId);
|
||||
|
||||
String dstAddr = parser.getAttributeValue(null, JingleS5BTransport.ATTR_DSTADDR);
|
||||
String dstAddr = parser.getAttributeValue(null, JingleS5BTransportElement.ATTR_DSTADDR);
|
||||
builder.setDestinationAddress(dstAddr);
|
||||
|
||||
String mode = parser.getAttributeValue(null, JingleS5BTransport.ATTR_MODE);
|
||||
String mode = parser.getAttributeValue(null, JingleS5BTransportElement.ATTR_MODE);
|
||||
if (mode != null) {
|
||||
builder.setMode(mode.equals(udp.toString()) ? udp : tcp);
|
||||
}
|
||||
|
||||
JingleS5BTransportCandidate.Builder cb;
|
||||
JingleS5BTransportCandidateElement.Builder cb;
|
||||
outerloop: while (true) {
|
||||
int tag = parser.nextTag();
|
||||
String name = parser.getName();
|
||||
|
@ -63,8 +63,8 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
|
|||
case START_TAG: {
|
||||
switch (name) {
|
||||
|
||||
case JingleS5BTransportCandidate.ELEMENT:
|
||||
cb = JingleS5BTransportCandidate.getBuilder();
|
||||
case JingleS5BTransportCandidateElement.ELEMENT:
|
||||
cb = JingleS5BTransportCandidateElement.getBuilder();
|
||||
cb.setCandidateId(parser.getAttributeValue(null, ATTR_CID));
|
||||
cb.setHost(parser.getAttributeValue(null, ATTR_HOST));
|
||||
cb.setJid(parser.getAttributeValue(null, ATTR_JID));
|
||||
|
@ -77,29 +77,29 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
|
|||
|
||||
String typeString = parser.getAttributeValue(null, ATTR_TYPE);
|
||||
if (typeString != null) {
|
||||
cb.setType(JingleS5BTransportCandidate.Type.fromString(typeString));
|
||||
cb.setType(JingleS5BTransportCandidateElement.Type.fromString(typeString));
|
||||
}
|
||||
builder.addTransportCandidate(cb.build());
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfo.CandidateActivated(
|
||||
case JingleS5BTransportInfoElement.CandidateActivated.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateActivated(
|
||||
parser.getAttributeValue(null,
|
||||
JingleS5BTransportInfo.CandidateActivated.ATTR_CID)));
|
||||
JingleS5BTransportInfoElement.CandidateActivated.ATTR_CID)));
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfo.CandidateUsed(
|
||||
case JingleS5BTransportInfoElement.CandidateUsed.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateUsed(
|
||||
parser.getAttributeValue(null,
|
||||
JingleS5BTransportInfo.CandidateUsed.ATTR_CID)));
|
||||
JingleS5BTransportInfoElement.CandidateUsed.ATTR_CID)));
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfo.CandidateError());
|
||||
case JingleS5BTransportInfoElement.CandidateError.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateError());
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfo.ProxyError());
|
||||
case JingleS5BTransportInfoElement.ProxyError.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.ProxyError());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.jingle3.transport.legacy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -30,14 +30,13 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
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.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle3.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
@ -46,7 +45,7 @@ import org.jxmpp.jid.Jid;
|
|||
/**
|
||||
* Manager for Jingle SOCKS5 Bytestream transports (XEP-0261).
|
||||
*/
|
||||
public final class JingleS5BTransportManager extends JingleTransportManager<JingleS5BTransport> {
|
||||
public final class JingleS5BTransportManager extends JingleTransportManager<JingleS5BTransportElement> {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportManager.class.getName());
|
||||
|
||||
|
@ -74,11 +73,11 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleS5BTransport.NAMESPACE_V1;
|
||||
return JingleS5BTransportElement.NAMESPACE_V1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleTransportSession<JingleS5BTransport> transportSession(JingleSession jingleSession) {
|
||||
public JingleTransportSession<JingleS5BTransportElement> transportSession(JingleSession jingleSession) {
|
||||
return new JingleS5BTransportSession(jingleSession);
|
||||
}
|
||||
|
||||
|
@ -153,7 +152,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
JingleContentElement.Builder cb = JingleContentElement.getBuilder();
|
||||
cb.setName(contentName).setCreator(contentCreator).setSenders(contentSenders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
JingleS5BTransportElement.Builder tb = JingleS5BTransportElement.getBuilder();
|
||||
tb.setCandidateUsed(candidateId).setStreamId(streamId);
|
||||
|
||||
JingleElement jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
|
@ -170,7 +169,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
JingleContentElement.Builder cb = JingleContentElement.getBuilder();
|
||||
cb.setName(name).setCreator(creator).setSenders(senders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
JingleS5BTransportElement.Builder tb = JingleS5BTransportElement.getBuilder();
|
||||
tb.setCandidateError().setStreamId(streamId);
|
||||
|
||||
JingleElement jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
|
@ -189,7 +188,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
JingleContentElement.Builder cb = JingleContentElement.getBuilder();
|
||||
cb.setSenders(senders).setCreator(creator).setName(name);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
JingleS5BTransportElement.Builder tb = JingleS5BTransportElement.getBuilder();
|
||||
tb.setStreamId(sessionId).setProxyError().setStreamId(streamId);
|
||||
|
||||
JingleElement jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
|
@ -207,7 +206,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
JingleContentElement.Builder cb = JingleContentElement.getBuilder();
|
||||
cb.setName(name).setCreator(creator).setSenders(senders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
JingleS5BTransportElement.Builder tb = JingleS5BTransportElement.getBuilder();
|
||||
tb.setStreamId(streamId).setCandidateActivated(candidateId);
|
||||
|
||||
JingleElement jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
|
@ -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.jingle3.transport.legacy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
@ -33,22 +33,21 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator;
|
|||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||
import org.jivesoftware.smackx.jingle3.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfoElement;
|
||||
|
||||
/**
|
||||
* Handler that handles Jingle Socks5Bytestream transports (XEP-0260).
|
||||
*/
|
||||
public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BTransport> {
|
||||
public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BTransportElement> {
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportSession.class.getName());
|
||||
|
||||
private JingleTransportInitiationCallback callback;
|
||||
|
@ -60,7 +59,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
private UsedCandidate ourChoice, theirChoice;
|
||||
|
||||
@Override
|
||||
public JingleS5BTransport createTransport() {
|
||||
public JingleS5BTransportElement createTransport() {
|
||||
if (ourProposal == null) {
|
||||
ourProposal = createTransport(JingleManager.randomId(), Bytestream.Mode.tcp);
|
||||
}
|
||||
|
@ -69,18 +68,18 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
@Override
|
||||
public void setTheirProposal(JingleContentTransportElement transport) {
|
||||
theirProposal = (JingleS5BTransport) transport;
|
||||
theirProposal = (JingleS5BTransportElement) transport;
|
||||
}
|
||||
|
||||
public JingleS5BTransport createTransport(String sid, Bytestream.Mode mode) {
|
||||
JingleS5BTransport.Builder jb = JingleS5BTransport.getBuilder()
|
||||
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 JingleS5BTransportCandidate(host, 100, JingleS5BTransportCandidate.Type.direct));
|
||||
jb.addTransportCandidate(new JingleS5BTransportCandidateElement(host, 100, JingleS5BTransportCandidateElement.Type.direct));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,14 +93,14 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
}
|
||||
|
||||
for (Bytestream.StreamHost host : remoteHosts) {
|
||||
jb.addTransportCandidate(new JingleS5BTransportCandidate(host, 0, JingleS5BTransportCandidate.Type.proxy));
|
||||
jb.addTransportCandidate(new JingleS5BTransportCandidateElement(host, 0, JingleS5BTransportCandidateElement.Type.proxy));
|
||||
}
|
||||
|
||||
return jb.build();
|
||||
}
|
||||
|
||||
public void setTheirTransport(JingleContentTransportElement transport) {
|
||||
theirProposal = (JingleS5BTransport) transport;
|
||||
theirProposal = (JingleS5BTransportElement) transport;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,9 +143,9 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
connectIfReady();
|
||||
}
|
||||
|
||||
private UsedCandidate chooseFromProposedCandidates(JingleS5BTransport proposal) {
|
||||
private UsedCandidate chooseFromProposedCandidates(JingleS5BTransportElement proposal) {
|
||||
for (JingleContentTransportCandidateElement c : proposal.getCandidates()) {
|
||||
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) c;
|
||||
JingleS5BTransportCandidateElement candidate = (JingleS5BTransportCandidateElement) c;
|
||||
|
||||
try {
|
||||
return connectToTheirCandidate(candidate);
|
||||
|
@ -158,7 +157,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
return null;
|
||||
}
|
||||
|
||||
private UsedCandidate connectToTheirCandidate(JingleS5BTransportCandidate candidate)
|
||||
private UsedCandidate connectToTheirCandidate(JingleS5BTransportCandidateElement candidate)
|
||||
throws InterruptedException, TimeoutException, SmackException, XMPPException, IOException {
|
||||
Bytestream.StreamHost streamHost = candidate.getStreamHost();
|
||||
String address = streamHost.getAddress();
|
||||
|
@ -169,7 +168,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
return new UsedCandidate(theirProposal, candidate, socket);
|
||||
}
|
||||
|
||||
private UsedCandidate connectToOurCandidate(JingleS5BTransportCandidate candidate)
|
||||
private UsedCandidate connectToOurCandidate(JingleS5BTransportCandidateElement candidate)
|
||||
throws InterruptedException, TimeoutException, SmackException, XMPPException, IOException {
|
||||
Bytestream.StreamHost streamHost = candidate.getStreamHost();
|
||||
String address = streamHost.getAddress();
|
||||
|
@ -184,24 +183,24 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleS5BTransport.NAMESPACE_V1;
|
||||
return JingleS5BTransportElement.NAMESPACE_V1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportInfo(JingleElement transportInfo) {
|
||||
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transportInfo.getContents().get(0).getTransport().getInfo();
|
||||
JingleS5BTransportInfoElement info = (JingleS5BTransportInfoElement) transportInfo.getContents().get(0).getTransport().getInfo();
|
||||
|
||||
switch (info.getElementName()) {
|
||||
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
||||
case JingleS5BTransportInfoElement.CandidateUsed.ELEMENT:
|
||||
return handleCandidateUsed(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
||||
case JingleS5BTransportInfoElement.CandidateActivated.ELEMENT:
|
||||
return handleCandidateActivate(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
||||
case JingleS5BTransportInfoElement.CandidateError.ELEMENT:
|
||||
return handleCandidateError(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||
case JingleS5BTransportInfoElement.ProxyError.ELEMENT:
|
||||
return handleProxyError(transportInfo);
|
||||
}
|
||||
//We should never go here, but lets be gracious...
|
||||
|
@ -209,8 +208,8 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
}
|
||||
|
||||
public IQ handleCandidateUsed(JingleElement jingle) {
|
||||
JingleS5BTransportInfo info = (JingleS5BTransportInfo) jingle.getContents().get(0).getTransport().getInfo();
|
||||
String candidateId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId();
|
||||
JingleS5BTransportInfoElement info = (JingleS5BTransportInfoElement) jingle.getContents().get(0).getTransport().getInfo();
|
||||
String candidateId = ((JingleS5BTransportInfoElement.CandidateUsed) info).getCandidateId();
|
||||
theirChoice = new UsedCandidate(ourProposal, ourProposal.getCandidate(candidateId), null);
|
||||
|
||||
if (theirChoice.candidate == null) {
|
||||
|
@ -283,7 +282,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
if (nominated == theirChoice) {
|
||||
LOGGER.log(Level.INFO, "Their choice, so our proposed candidate is used.");
|
||||
boolean isProxy = nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy;
|
||||
boolean isProxy = nominated.candidate.getType() == JingleS5BTransportCandidateElement.Type.proxy;
|
||||
try {
|
||||
nominated = connectToOurCandidate(nominated.candidate);
|
||||
} catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) {
|
||||
|
@ -329,7 +328,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
//Our choice
|
||||
else {
|
||||
LOGGER.log(Level.INFO, "Our choice, so their candidate was used.");
|
||||
boolean isProxy = nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy;
|
||||
boolean isProxy = nominated.candidate.getType() == JingleS5BTransportCandidateElement.Type.proxy;
|
||||
if (!isProxy) {
|
||||
LOGGER.log(Level.INFO, "Direct connection.");
|
||||
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, true);
|
||||
|
@ -347,10 +346,10 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
private static class UsedCandidate {
|
||||
private final Socket socket;
|
||||
private final JingleS5BTransport transport;
|
||||
private final JingleS5BTransportCandidate candidate;
|
||||
private final JingleS5BTransportElement transport;
|
||||
private final JingleS5BTransportCandidateElement candidate;
|
||||
|
||||
public UsedCandidate(JingleS5BTransport transport, JingleS5BTransportCandidate candidate, Socket socket) {
|
||||
public UsedCandidate(JingleS5BTransportElement transport, JingleS5BTransportCandidateElement candidate, Socket socket) {
|
||||
this.socket = socket;
|
||||
this.transport = transport;
|
||||
this.candidate = candidate;
|
|
@ -21,6 +21,7 @@ import static junit.framework.TestCase.assertNotSame;
|
|||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle3.FullJidAndSessionId;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.jivesoftware.smack.test.util.SmackTestSuite;
|
|||
import org.jivesoftware.smackx.jingle3.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.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.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(JingleS5BTransport.NAMESPACE_V1);
|
||||
JingleContentProviderManager.removeJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1);
|
||||
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1));
|
||||
|
||||
JingleIBBTransportProvider ibbProvider = new JingleIBBTransportProvider();
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1, ibbProvider);
|
||||
assertEquals(ibbProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
|
||||
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1));
|
||||
JingleS5BTransportProvider s5bProvider = new JingleS5BTransportProvider();
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1, s5bProvider);
|
||||
assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1, s5bProvider);
|
||||
assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransportElement.NAMESPACE_V1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ 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.jingle3.FullJidAndSessionId;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle3.element.JingleAction;
|
||||
|
|
|
@ -35,8 +35,8 @@ 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.jingle3.transport.jingle_s5b.JingleS5BTransportManager;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.legacy.JingleS5BTransportManager;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
@ -51,10 +51,10 @@ public class JingleTransportMethodManagerTest extends SmackTestSuite {
|
|||
|
||||
assertNull(jtmm.getBestAvailableTransportManager());
|
||||
assertNull(jtmm.getTransportManager(JingleIBBTransport.NAMESPACE_V1));
|
||||
assertNull(jtmm.getTransportManager(JingleS5BTransport.NAMESPACE_V1));
|
||||
assertNull(jtmm.getTransportManager(JingleS5BTransportElement.NAMESPACE_V1));
|
||||
|
||||
jtmm.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection));
|
||||
assertNull(jtmm.getTransportManager(JingleS5BTransport.NAMESPACE_V1));
|
||||
assertNull(jtmm.getTransportManager(JingleS5BTransportElement.NAMESPACE_V1));
|
||||
assertNotNull(jtmm.getTransportManager(JingleIBBTransport.NAMESPACE_V1));
|
||||
assertEquals(JingleIBBTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager());
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class JingleTransportMethodManagerTest extends SmackTestSuite {
|
|||
assertEquals(JingleS5BTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager());
|
||||
|
||||
jtmm.unregisterTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
|
||||
assertNull(jtmm.getTransportManager(JingleS5BTransport.NAMESPACE_V1));
|
||||
assertNull(jtmm.getTransportManager(JingleS5BTransportElement.NAMESPACE_V1));
|
||||
jtmm.unregisterTransportManager(JingleIBBTransportManager.getInstanceFor(connection));
|
||||
|
||||
assertNull(jtmm.getBestAvailableTransportManager());
|
||||
|
@ -73,7 +73,7 @@ public class JingleTransportMethodManagerTest extends SmackTestSuite {
|
|||
assertEquals(JingleS5BTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager());
|
||||
|
||||
assertEquals(JingleIBBTransportManager.getInstanceFor(connection), jtmm.getBestAvailableTransportManager(
|
||||
Collections.singleton(JingleS5BTransport.NAMESPACE_V1)));
|
||||
Collections.singleton(JingleS5BTransportElement.NAMESPACE_V1)));
|
||||
|
||||
JingleStubTransportManager stub = new JingleStubTransportManager(connection);
|
||||
jtmm.registerTransportManager(stub);
|
||||
|
@ -92,7 +92,7 @@ public class JingleTransportMethodManagerTest extends SmackTestSuite {
|
|||
|
||||
Set<String> except = new HashSet<>();
|
||||
except.add(JingleIBBTransport.NAMESPACE_V1);
|
||||
except.add(JingleS5BTransport.NAMESPACE_V1);
|
||||
except.add(JingleS5BTransportElement.NAMESPACE_V1);
|
||||
assertEquals(stub, jtmm.getBestAvailableTransportManager(except));
|
||||
|
||||
jtmm.unregisterTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
|
||||
|
|
|
@ -26,9 +26,9 @@ import org.jivesoftware.smack.test.util.SmackTestSuite;
|
|||
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportCandidateElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.elements.JingleS5BTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle3.transport.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -75,7 +75,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"type='proxy'/>" +
|
||||
|
||||
"</transport>";
|
||||
JingleS5BTransport transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
|
||||
JingleS5BTransportElement transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
|
||||
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
|
||||
assertEquals("vj3hs98y", transport.getStreamId());
|
||||
assertEquals(Bytestream.Mode.tcp, transport.getMode());
|
||||
|
@ -83,35 +83,35 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
|
||||
assertTrue(transport.hasCandidate("hft54dqy"));
|
||||
assertFalse(transport.hasCandidate("invalidId"));
|
||||
JingleS5BTransportCandidate candidate1 =
|
||||
(JingleS5BTransportCandidate) transport.getCandidates().get(0);
|
||||
JingleS5BTransportCandidateElement candidate1 =
|
||||
(JingleS5BTransportCandidateElement) transport.getCandidates().get(0);
|
||||
assertEquals(candidate1, transport.getCandidate("hft54dqy"));
|
||||
assertNotNull(candidate1.getStreamHost());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.direct.getWeight(), candidate1.getType().getWeight());
|
||||
assertEquals(JingleS5BTransportCandidateElement.Type.direct.getWeight(), candidate1.getType().getWeight());
|
||||
assertEquals("hft54dqy", candidate1.getCandidateId());
|
||||
assertEquals("192.168.4.1", candidate1.getHost());
|
||||
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
|
||||
assertEquals(5086, candidate1.getPort());
|
||||
assertEquals(8257636, candidate1.getPriority());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate1.getType());
|
||||
assertEquals(JingleS5BTransportCandidateElement.Type.direct, candidate1.getType());
|
||||
|
||||
JingleS5BTransportCandidate candidate2 =
|
||||
(JingleS5BTransportCandidate) transport.getCandidates().get(1);
|
||||
JingleS5BTransportCandidateElement candidate2 =
|
||||
(JingleS5BTransportCandidateElement) transport.getCandidates().get(1);
|
||||
assertEquals("hutr46fe", candidate2.getCandidateId());
|
||||
assertEquals("24.24.24.1", candidate2.getHost());
|
||||
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
|
||||
assertEquals(5087, candidate2.getPort());
|
||||
assertEquals(8258636, candidate2.getPriority());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate2.getType());
|
||||
assertEquals(JingleS5BTransportCandidateElement.Type.direct, candidate2.getType());
|
||||
|
||||
JingleS5BTransportCandidate candidate3 =
|
||||
(JingleS5BTransportCandidate) transport.getCandidates().get(2);
|
||||
JingleS5BTransportCandidateElement candidate3 =
|
||||
(JingleS5BTransportCandidateElement) transport.getCandidates().get(2);
|
||||
assertEquals("xmdh4b7i", candidate3.getCandidateId());
|
||||
assertEquals("123.456.7.8", candidate3.getHost());
|
||||
assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
|
||||
assertEquals(7625, candidate3.getPort());
|
||||
assertEquals(7878787, candidate3.getPriority());
|
||||
assertEquals(JingleS5BTransportCandidate.Type.proxy, candidate3.getType());
|
||||
assertEquals(JingleS5BTransportCandidateElement.Type.proxy, candidate3.getType());
|
||||
|
||||
assertEquals(xml, transport.toXML().toString());
|
||||
}
|
||||
|
@ -122,12 +122,12 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<candidate-error/>" +
|
||||
"</transport>";
|
||||
JingleS5BTransport candidateErrorTransport = new JingleS5BTransportProvider()
|
||||
JingleS5BTransportElement candidateErrorTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateError));
|
||||
assertNull(candidateErrorTransport.getDestinationAddress());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
||||
assertEquals(JingleS5BTransportInfo.CandidateError(),
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateError(),
|
||||
candidateErrorTransport.getInfo());
|
||||
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
||||
|
||||
|
@ -135,13 +135,13 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<proxy-error/>" +
|
||||
"</transport>";
|
||||
JingleS5BTransport proxyErrorTransport = new JingleS5BTransportProvider()
|
||||
JingleS5BTransportElement proxyErrorTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(proxyError));
|
||||
assertNull(proxyErrorTransport.getDestinationAddress());
|
||||
assertNotNull(proxyErrorTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
||||
assertEquals(JingleS5BTransportInfo.ProxyError(),
|
||||
assertEquals(JingleS5BTransportInfoElement.ProxyError(),
|
||||
proxyErrorTransport.getInfo());
|
||||
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
||||
|
||||
|
@ -149,13 +149,13 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<candidate-used cid='hr65dqyd'/>" +
|
||||
"</transport>";
|
||||
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
|
||||
JingleS5BTransportElement candidateUsedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateUsed));
|
||||
assertNotNull(candidateUsedTransport.getInfo());
|
||||
assertEquals(JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateUsed("hr65dqyd"),
|
||||
candidateUsedTransport.getInfo());
|
||||
assertEquals("hr65dqyd",
|
||||
((JingleS5BTransportInfo.CandidateUsed)
|
||||
((JingleS5BTransportInfoElement.CandidateUsed)
|
||||
candidateUsedTransport.getInfo()).getCandidateId());
|
||||
assertEquals(candidateUsed, candidateUsedTransport.toXML().toString());
|
||||
|
||||
|
@ -163,41 +163,41 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
|
||||
"<candidate-activated cid='hr65dqyd'/>" +
|
||||
"</transport>";
|
||||
JingleS5BTransport candidateActivatedTransport = new JingleS5BTransportProvider()
|
||||
JingleS5BTransportElement candidateActivatedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateActivated));
|
||||
assertNotNull(candidateActivatedTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
|
||||
assertEquals(JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateActivated("hr65dqyd"),
|
||||
candidateActivatedTransport.getInfo());
|
||||
assertEquals("hr65dqyd",
|
||||
((JingleS5BTransportInfo.CandidateActivated)
|
||||
((JingleS5BTransportInfoElement.CandidateActivated)
|
||||
candidateActivatedTransport.getInfo()).getCandidateId());
|
||||
assertEquals(candidateActivated, candidateActivatedTransport.toXML().toString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void candidateBuilderInvalidPortTest() {
|
||||
JingleS5BTransportCandidate.getBuilder().setPort(-5);
|
||||
JingleS5BTransportCandidateElement.getBuilder().setPort(-5);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void candidateBuilderInvalidPriorityTest() {
|
||||
JingleS5BTransportCandidate.getBuilder().setPriority(-1000);
|
||||
JingleS5BTransportCandidateElement.getBuilder().setPriority(-1000);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void transportCandidateIllegalPriorityTest() throws XmppStringprepException {
|
||||
FullJid jid = JidCreate.fullFrom("test@test.test/test");
|
||||
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(
|
||||
"cid", "host", jid, 5555, -30, JingleS5BTransportCandidate.Type.proxy);
|
||||
JingleS5BTransportCandidateElement candidate = new JingleS5BTransportCandidateElement(
|
||||
"cid", "host", jid, 5555, -30, JingleS5BTransportCandidateElement.Type.proxy);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void transportCandidateIllegalPortTest() throws XmppStringprepException {
|
||||
FullJid jid = JidCreate.fullFrom("test@test.test/test");
|
||||
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(
|
||||
"cid", "host", jid, -5555, 30, JingleS5BTransportCandidate.Type.proxy);
|
||||
JingleS5BTransportCandidateElement candidate = new JingleS5BTransportCandidateElement(
|
||||
"cid", "host", jid, -5555, 30, JingleS5BTransportCandidateElement.Type.proxy);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -207,7 +207,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
int port = 1234;
|
||||
Bytestream.StreamHost streamHost = new Bytestream.StreamHost(jid, host, port);
|
||||
|
||||
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(streamHost, 2000, JingleS5BTransportCandidate.Type.direct);
|
||||
JingleS5BTransportCandidateElement candidate = new JingleS5BTransportCandidateElement(streamHost, 2000, JingleS5BTransportCandidateElement.Type.direct);
|
||||
|
||||
assertEquals(2000, candidate.getPriority());
|
||||
assertEquals(jid, candidate.getJid());
|
||||
|
@ -219,6 +219,6 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void typeFromIllegalStringTest() {
|
||||
JingleS5BTransportCandidate.Type.fromString("illegal-type");
|
||||
JingleS5BTransportCandidateElement.Type.fromString("illegal-type");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue