diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java index 841be920d..d6abdd642 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java index 24cfe3f98..df7de850d 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java index 2ee1ec897..b701c1aef 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java @@ -17,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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java index 2e8fe81ac..d1d4116f4 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java index 7586d786a..27afb6886 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java @@ -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; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java index dc7e1da00..3c74f12da 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java @@ -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; diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleUtilFileTransferTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleUtilFileTransferTest.java index 16d88c0e6..fb877b5b7 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleUtilFileTransferTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleUtilFileTransferTest.java @@ -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; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleHandler.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleHandler.java deleted file mode 100644 index 39e889391..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleHandler.java +++ /dev/null @@ -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); - -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java deleted file mode 100644 index 4a745b74a..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java +++ /dev/null @@ -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 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 descriptionHandlers = new ConcurrentHashMap<>(); - - private final Map 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); - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java deleted file mode 100644 index 618f9dbce..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java +++ /dev/null @@ -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 failedTransportMethods = new HashSet<>(); - - protected final FullJid local; - - protected final FullJid remote; - - protected final Role role; - - protected final String sid; - - protected final List contents = new ArrayList<>(); - - protected ArrayList> 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 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 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); - -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSessionHandler.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSessionHandler.java deleted file mode 100644 index 8947bf59b..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSessionHandler.java +++ /dev/null @@ -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); - -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleStreamRouter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleStreamRouter.java deleted file mode 100644 index 0f66f1b09..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleStreamRouter.java +++ /dev/null @@ -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; - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java deleted file mode 100644 index a5f29e5b9..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleTransportMethodManager.java +++ /dev/null @@ -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 INSTANCES = new WeakHashMap<>(); - - private final HashMap> 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 it = transportManagers.keySet().iterator(); - if (it.hasNext()) { - return getTransportManager(it.next()); - } - - return null; - } - - public JingleTransportManager getBestAvailableTransportManager(Set 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; - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Role.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Role.java deleted file mode 100644 index 0473b0894..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/Role.java +++ /dev/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, - ; -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/FullJidAndSessionId.java similarity index 97% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/FullJidAndSessionId.java index 2bd3e7cde..014b650ca 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/FullJidAndSessionId.java @@ -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; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleExtensionManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleExtensionManager.java deleted file mode 100644 index 92ecb8e1d..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleExtensionManager.java +++ /dev/null @@ -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 INSTANCES = new WeakHashMap<>(); - - private static final WeakHashMap> descriptionProviders = new WeakHashMap<>(); - private static final WeakHashMap> transportProviders = new WeakHashMap<>(); - private static final WeakHashMap> securityProviders = new WeakHashMap<>(); - - private static final WeakHashMap> descriptionAdapters = new WeakHashMap<>(); - private static final WeakHashMap> transportAdapters = new WeakHashMap<>(); - private static final WeakHashMap> securityAdapters = new WeakHashMap<>(); - - public final WeakHashMap descriptionManagers = new WeakHashMap<>(); - public final WeakHashMap transportManagers = new WeakHashMap<>(); - public final WeakHashMap 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); - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleManager.java index ed18f50f8..60d50dc1e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleManager.java @@ -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 INSTANCES = new WeakHashMap<>(); + private static final WeakHashMap> descriptionProviders = new WeakHashMap<>(); + private static final WeakHashMap> transportProviders = new WeakHashMap<>(); + private static final WeakHashMap> securityProviders = new WeakHashMap<>(); + + private static final WeakHashMap> descriptionAdapters = new WeakHashMap<>(); + private static final WeakHashMap> transportAdapters = new WeakHashMap<>(); + private static final WeakHashMap> securityAdapters = new WeakHashMap<>(); + + private final WeakHashMap descriptionManagers = new WeakHashMap<>(); + private final WeakHashMap transportManagers = new WeakHashMap<>(); + private final WeakHashMap securityManagers = new WeakHashMap<>(); + private final ConcurrentHashMap 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 getAvailableTransportManagers() { + return getAvailableTransportManagers(Collections.emptySet()); + } + + private List getAvailableTransportManagers(Set except) { + Set available = new HashSet<>(transportManagers.keySet()); + available.removeAll(except); + List remaining = new ArrayList<>(); + + for (String namespace : available) { + remaining.add(transportManagers.get(namespace)); + } + + return remaining; + } + public XMPPConnection getConnection() { return connection(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleSessionInitiateListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleSessionInitiateListener.java new file mode 100644 index 000000000..cc63ea6f0 --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleSessionInitiateListener.java @@ -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); +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleTransportManager.java index 8a27ad81c..3e39ae1fb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/JingleTransportManager.java @@ -3,7 +3,7 @@ package org.jivesoftware.smackx.jingle3; /** * Created by vanitas on 19.07.17. */ -public interface JingleTransportManager { +public interface JingleTransportManager extends Comparable { String getNamespace(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/adapter/JingleTransportAdapter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/adapter/JingleTransportAdapter.java index 39a692fde..4f3a20fc6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/adapter/JingleTransportAdapter.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/adapter/JingleTransportAdapter.java @@ -8,7 +8,7 @@ import org.jivesoftware.smackx.jingle3.internal.Transport; */ public interface JingleTransportAdapter> { - T transportFromElement(JingleContentTransportElement xml); + T transportFromElement(JingleContentTransportElement element); String getNamespace(); } \ No newline at end of file diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/element/JingleContentTransportElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/element/JingleContentTransportElement.java index ff30e40d3..159682319 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/element/JingleContentTransportElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/element/JingleContentTransportElement.java @@ -51,7 +51,6 @@ public abstract class JingleContentTransportElement implements ExtensionElement else { this.candidates = Collections.emptyList(); } - this.info = info; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Content.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Content.java index f0aff9363..e0b341e8d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Content.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Content.java @@ -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 { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Session.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Session.java index dfb88aae7..3d85bb986 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Session.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Session.java @@ -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 affectedContents = getAffectedContents(request); - List responses = new ArrayList<>(); for (Map.Entry 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> 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 diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Transport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Transport.java index 2e108fd53..e24d68300 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Transport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/internal/Transport.java @@ -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 { 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); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/ibb/JingleIBBTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransport.java similarity index 50% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/ibb/JingleIBBTransport.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransport.java index fd2f9d2ab..f1676d4f5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/ibb/JingleIBBTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransport.java @@ -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 { + 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 { @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. } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/ibb/JingleIBBTransportAdapter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransportAdapter.java similarity index 76% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/ibb/JingleIBBTransportAdapter.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransportAdapter.java index f4ed7f78a..3e55cf433 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/ibb/JingleIBBTransportAdapter.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransportAdapter.java @@ -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 { - - private static final WeakHashMap 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 transportSession(JingleSession jingleSession) { - return new JingleIBBTransportSession(jingleSession); - } - - @Override - public void authenticated(XMPPConnection connection, boolean resumed) { - //Nothing to do. - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransportSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransportSession.java deleted file mode 100644 index 8d4b3ccaa..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/JingleIBBTransportSession.java +++ /dev/null @@ -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 { - 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 transportManager() { - return JingleIBBTransportManager.getInstanceFor(jingleSession.getConnection()); - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/element/JingleIBBTransportElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/element/JingleIBBTransportElement.java index 3823969d8..f0d909d4f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/element/JingleIBBTransportElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/element/JingleIBBTransportElement.java @@ -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 diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/provider/JingleIBBTransportProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/provider/JingleIBBTransportProvider.java index e2483cc4c..5563c2b40 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/provider/JingleIBBTransportProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_ibb/provider/JingleIBBTransportProvider.java @@ -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; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransport.java new file mode 100644 index 000000000..1db7f5428 --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransport.java @@ -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 { + + 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 candidates = new HashMap<>(); + + private String peerDstAddr; + private Bytestream.Mode peerMode; + private HashMap peerCandidates; + + private JingleS5BTransportCandidate ourChoice, theirChoice; + private JingleS5BTransportCandidate nominee; + + public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List candidates) { + this.sid = sid; + this.dstAddr = dstAddr; + this.mode = mode; + + for (JingleS5BTransportCandidate c : (candidates != null ? + candidates : Collections.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); +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportAdapter.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportAdapter.java new file mode 100644 index 000000000..5bd763c15 --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportAdapter.java @@ -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 { + + @Override + public JingleS5BTransport transportFromElement(JingleContentTransportElement element) { + JingleS5BTransport transport = new JingleS5BTransport(); + } + + @Override + public String getNamespace() { + return JingleS5BTransport.NAMESPACE; + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportCandidate.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportCandidate.java new file mode 100644 index 000000000..29e09688a --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportCandidate.java @@ -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); + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportCandidate.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportCandidateElement.java similarity index 90% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportCandidate.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportCandidateElement.java index 062214718..a72e68872 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportCandidate.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportCandidateElement.java @@ -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); } } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportElement.java similarity index 79% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransport.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportElement.java index 01e21b719..9fe6fea57 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportElement.java @@ -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 candidates, JingleContentTransportInfoElement info, String streamId, String dstAddr, Bytestream.Mode mode) { + protected JingleS5BTransportElement(String streamId, List 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); } } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportInfoElement.java similarity index 96% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportInfo.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportInfoElement.java index 2def8b986..d8074113a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportInfo.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/elements/JingleS5BTransportInfoElement.java @@ -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() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/provider/JingleS5BTransportProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/provider/JingleS5BTransportProvider.java index f98b4a080..2be2c95e6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/provider/JingleS5BTransportProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/provider/JingleS5BTransportProvider.java @@ -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 { +public class JingleS5BTransportProvider extends JingleContentTransportProvider { @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 { +public final class JingleS5BTransportManager extends JingleTransportManager { private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportManager.class.getName()); @@ -74,11 +73,11 @@ public final class JingleS5BTransportManager extends JingleTransportManager transportSession(JingleSession jingleSession) { + public JingleTransportSession transportSession(JingleSession jingleSession) { return new JingleS5BTransportSession(jingleSession); } @@ -153,7 +152,7 @@ public final class JingleS5BTransportManager extends JingleTransportManager { +public class JingleS5BTransportSession extends JingleTransportSession { private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportSession.class.getName()); private JingleTransportInitiationCallback callback; @@ -60,7 +59,7 @@ public class JingleS5BTransportSession extends JingleTransportSession 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)); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportTest.java index 3ab2a20c5..dae75dfba 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle3/transport/jingle_s5b/JingleS5BTransportTest.java @@ -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'/>" + ""; - 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 { "" + "" + ""; - 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 { "" + "" + ""; - 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 { "" + "" + ""; - 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 { "" + "" + ""; - 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"); } }