From f783ecab4b24a90409799404609eacbb4defe37e Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sat, 17 Jun 2017 00:17:21 +0200 Subject: [PATCH] Move ft to experimental, more jingleUtil stuff --- .../JingleFileTransferManager.java | 43 +++++++++++ .../jingle_filetransfer/package-info.java | 21 ++++++ .../smackx/jingle/JingleUtil.java | 72 +++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/package-info.java 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 new file mode 100644 index 000000000..7b96cdbd4 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java @@ -0,0 +1,43 @@ +/** + * + * 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_filetransfer; + +import java.util.WeakHashMap; + +import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.XMPPConnection; + +/** + * Manager for JingleFileTransfer (XEP-0234). + */ +public final class JingleFileTransferManager extends Manager { + + private static final WeakHashMap INSTANCES = new WeakHashMap<>(); + + private JingleFileTransferManager(XMPPConnection connection) { + super(connection); + } + + public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) { + JingleFileTransferManager manager = INSTANCES.get(connection); + if (manager == null) { + manager = new JingleFileTransferManager(connection); + INSTANCES.put(connection, manager); + } + return manager; + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/package-info.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/package-info.java new file mode 100644 index 000000000..86fb45ecc --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/package-info.java @@ -0,0 +1,21 @@ +/** + * + * 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. + */ + +/** + * Smack's API for XEP-0234: Jingle File Transfer. + */ +package org.jivesoftware.smackx.jingle_filetransfer; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java index 65ec0ba84..3a00f7f44 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java @@ -4,11 +4,13 @@ import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.jingle.element.Jingle; import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleContent; import org.jivesoftware.smackx.jingle.element.JingleContentDescription; import org.jivesoftware.smackx.jingle.element.JingleContentTransport; +import org.jivesoftware.smackx.jingle.element.JingleError; import org.jivesoftware.smackx.jingle.element.JingleReason; import org.jxmpp.jid.FullJid; @@ -160,4 +162,74 @@ public class JingleUtil { return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); } + + public IQ sendSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId) + throws InterruptedException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, SmackException.NoResponseException { + return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_transports); + } + + public IQ sendSessionTerminateFailedTransport(FullJid recipient, String sessionId) + throws InterruptedException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, SmackException.NoResponseException { + return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_transport); + } + + public IQ sendSessionTerminateUnsupportedApplications(FullJid recipient, String sessionId) + throws InterruptedException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, SmackException.NoResponseException { + return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_applications); + } + + public IQ sendSessionTerminateFailedApplication(FullJid recipient, String sessionId) + throws InterruptedException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, SmackException.NoResponseException { + return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_application); + } + + public IQ sendSessionTerminateIncompatibleParameters(FullJid recipient, String sessionId) + throws InterruptedException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, SmackException.NoResponseException { + return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.incompatible_parameters); + } + + public IQ sendSessionPing(FullJid recipient, String sessionId) + throws SmackException.NotConnectedException, InterruptedException, + XMPPException.XMPPErrorException, SmackException.NoResponseException { + + Jingle.Builder jb = Jingle.getBuilder(); + jb.setSessionId(sessionId) + .setAction(JingleAction.session_info); + + Jingle jingle = jb.build(); + jingle.setFrom(connection.getUser()); + jingle.setTo(recipient); + + return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); + } + + public void sendErrorUnknownSession(Jingle request) + throws SmackException.NotConnectedException, InterruptedException { + + XMPPError.Builder error = XMPPError.getBuilder(); + error.setCondition(XMPPError.Condition.item_not_found) + .addExtension(JingleError.UNKNOWN_SESSION); + + connection.sendStanza(IQ.createErrorResponse(request, error)); + } + + public void sendErrorUnknownInitiator(Jingle request) + throws SmackException.NotConnectedException, InterruptedException { + connection.sendStanza(IQ.createErrorResponse(request, XMPPError.Condition.service_unavailable)); + } + + public void sendErrorUnsupportedInfo(Jingle request) + throws SmackException.NotConnectedException, InterruptedException { + + XMPPError.Builder error = XMPPError.getBuilder(); + error.setCondition(XMPPError.Condition.feature_not_implemented) + .addExtension(JingleError.UNSUPPORTED_INFO); + + connection.sendStanza(IQ.createErrorResponse(request, error)); + } }