diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java index 9d25b5c4d..0eabe3128 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java @@ -253,4 +253,8 @@ public final class JingleManager extends Manager { jingleSessions.put(new FullJidAndSessionId(peer, session.getSessionId()), session); return session; } + + public void removeSession(JingleSession session) { + jingleSessions.remove(new FullJidAndSessionId(session.getPeer(), session.getSessionId())); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleDescription.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleDescription.java index e017d6fd6..07bbc20e3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleDescription.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleDescription.java @@ -18,6 +18,8 @@ package org.jivesoftware.smackx.jingle.components; import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement; +import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement; +import org.jivesoftware.smackx.jingle.element.JingleElement; /** * Class that represents a contents description component. @@ -34,6 +36,8 @@ public abstract class JingleDescription affectedContents = request.getContents(); - List responses = new ArrayList<>(); + private IQ handleTransportReplace(final JingleElement request) { + Async.go(new Runnable() { + @Override + public void run() { + List affectedContents = request.getContents(); + List responses = new ArrayList<>(); - for (JingleContentElement affected : affectedContents) { - JingleContent content = contents.get(affected.getName()); - JingleContentTransportElement newTransport = affected.getTransport(); - Set blacklist = content.getTransportBlacklist(); + for (JingleContentElement affected : affectedContents) { + JingleContent content = contents.get(affected.getName()); + JingleContentTransportElement newTransport = affected.getTransport(); + Set blacklist = content.getTransportBlacklist(); - // Proposed transport method might already be on the blacklist (eg. because of previous failures) - if (blacklist.contains(newTransport.getNamespace())) { - responses.add(JingleElement.createTransportReject(getInitiator(), getPeer(), getSessionId(), - content.getCreator(), content.getName(), newTransport)); - continue; + // Proposed transport method might already be on the blacklist (eg. because of previous failures) + if (blacklist.contains(newTransport.getNamespace())) { + responses.add(JingleElement.createTransportReject(getInitiator(), getPeer(), getSessionId(), + content.getCreator(), content.getName(), newTransport)); + continue; + } + + JingleTransportAdapter transportAdapter = JingleManager.getJingleTransportAdapter( + newTransport.getNamespace()); + // This might be an unknown transport. + if (transportAdapter == null) { + responses.add(JingleElement.createTransportReject(getInitiator(), getPeer(), getSessionId(), + content.getCreator(), content.getName(), newTransport)); + continue; + } + + //Otherwise, when all went well so far, accept the transport-replace + content.setTransport(JingleManager.getJingleTransportAdapter(newTransport.getNamespace()) + .transportFromElement(newTransport)); + responses.add(JingleElement.createTransportAccept(getInitiator(), getPeer(), getSessionId(), + content.getCreator(), content.getName(), newTransport)); + } + + for (JingleElement response : responses) { + try { + jingleManager.getConnection().createStanzaCollectorAndSend(response).nextResultOrThrow(); + } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) { + LOGGER.log(Level.SEVERE, "Could not send response to transport-replace: " + e, e); + } + } } - - JingleTransportAdapter transportAdapter = JingleManager.getJingleTransportAdapter( - newTransport.getNamespace()); - // This might be an unknown transport. - if (transportAdapter == null) { - responses.add(JingleElement.createTransportReject(getInitiator(), getPeer(), getSessionId(), - content.getCreator(), content.getName(), newTransport)); - continue; - } - - //Otherwise, when all went well so far, accept the transport-replace - content.setTransport(JingleManager.getJingleTransportAdapter(newTransport.getNamespace()) - .transportFromElement(newTransport)); - responses.add(JingleElement.createTransportAccept(getInitiator(), getPeer(), getSessionId(), - content.getCreator(), content.getName(), newTransport)); - } - - //TODO: Put in Thread? - for (JingleElement response : responses) { - try { - jingleManager.getConnection().createStanzaCollectorAndSend(response).nextResultOrThrow(); - } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) { - LOGGER.log(Level.SEVERE, "Could not send response to transport-replace: " + e, e); - } - } + }); return IQ.createResultIQ(request); } @@ -217,32 +222,10 @@ public class JingleSession { throw new AssertionError("Reason MUST not be null! (I guess)..."); } - switch (reason.asEnum()) { - case alternative_session: - case busy: - case cancel: - case connectivity_error: - case decline: - // :( - case expired: - case failed_application: - case failed_transport: - case general_error: - // well... shit. - case gone: - case incompatible_parameters: - case media_error: - case security_error: - case success: - // Weeeeeh - break; - case timeout: - case unsupported_applications: - case unsupported_transports: - break; - default: - throw new AssertionError("Unknown reason enum: " + reason.asEnum().toString()); - } + //TODO: Inform client. + + jingleManager.removeSession(this); + return IQ.createResultIQ(request); } @@ -270,7 +253,6 @@ public class JingleSession { HashMap affectedContents = getAffectedContents(request); for (Map.Entry entry : affectedContents.entrySet()) { - JingleTransport transport = entry.getValue().getTransport(); JingleContentTransportInfoElement info = entry.getKey().getTransport().getInfo(); transport.handleTransportInfo(info, request); @@ -328,7 +310,22 @@ public class JingleSession { } private IQ handleDescriptionInfo(JingleElement request) { - return null; + HashMap affectedContents = getAffectedContents(request); + List responses = new ArrayList<>(); + + for (Map.Entry entry : affectedContents.entrySet()) { + responses.add(entry.getValue().getDescription().handleDescriptionInfo(entry.getKey().getDescription().getDescriptionInfo())); + } + + for (JingleElement response : responses) { + try { + getJingleManager().getConnection().createStanzaCollectorAndSend(response).nextResultOrThrow(); + } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) { + LOGGER.log(Level.SEVERE, "Could not send response to description-info: " + e, e); + } + } + + return IQ.createResultIQ(request); } private IQ handleContentRemove(JingleElement request) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionElement.java index dd69abd8d..780ad4a18 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionElement.java @@ -57,6 +57,10 @@ public abstract class JingleContentDescriptionElement implements ExtensionElemen return payloads; } + public JingleContentDescriptionInfoElement getDescriptionInfo() { + return null; //TODO + } + protected void addExtraAttributes(XmlStringBuilder xml) { } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionInfoElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionInfoElement.java new file mode 100644 index 000000000..af1785dbe --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleContentDescriptionInfoElement.java @@ -0,0 +1,10 @@ +package org.jivesoftware.smackx.jingle.element; + +import org.jivesoftware.smack.packet.NamedElement; + +/** + * Created by vanitas on 28.07.17. + */ +public abstract class JingleContentDescriptionInfoElement implements NamedElement { + +}