1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 01:59:38 +02:00

Split JingleFileTransferSession in incoming and outgoing

This commit is contained in:
vanitasvitae 2017-06-19 17:55:04 +02:00
parent 73f9af474e
commit 2bac6297ee
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
9 changed files with 179 additions and 92 deletions

View file

@ -1,6 +1,23 @@
/**
*
* 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.WeakHashMap;
import org.jivesoftware.smack.Manager;
@ -9,15 +26,22 @@ import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
/**
* Created by vanitas on 19.06.17.
* Manager where TransportMethods are registered.
*/
public final class JingleTransportMethodManager extends Manager {
private static final WeakHashMap<XMPPConnection, JingleTransportMethodManager> INSTANCES = new WeakHashMap<>();
private final HashMap<String, JingleTransportManager<?>> transportManagers = new HashMap<>();
private static final String[] transportPreference = new String[] {
JingleS5BTransport.NAMESPACE_V1,
JingleIBBTransport.NAMESPACE_V1
};
private JingleTransportMethodManager(XMPPConnection connection) {
super(connection);
}
@ -44,4 +68,25 @@ public final class JingleTransportMethodManager extends Manager {
JingleContentTransport transport = content.getJingleTransports().get(0);
return getTransportManager(transport.getNamespace());
}
/**
* TODO: Find better solution.
* @return
*/
public JingleTransportManager<?> getBestAvailableTransportManager() {
JingleTransportManager<?> tm;
for (String ns : transportPreference) {
tm = getTransportManager(ns);
if (tm != null) {
return tm;
}
}
Iterator<String> it = transportManagers.keySet().iterator();
if (it.hasNext()) {
return getTransportManager(it.next());
}
return null;
}
}

View file

@ -1,10 +1,27 @@
/**
*
* 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.transports;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
/**
* Created by vanitas on 19.06.17.
* Manager for a JingleTransport method.
* @param <D> JingleContentTransport.
*/
public abstract class JingleTransportManager<D extends JingleContentTransport> {

View file

@ -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 <a href="https://xmpp.org/extensions/xep-0261.html">XEP-0261: Jingle In-Band Bytestreams</a>.
*/
package org.jivesoftware.smackx.jingle.transports;

View file

@ -1,54 +0,0 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotSame;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.StringUtils;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test JingleSession class.
*/
public class JingleSessionTest extends SmackTestSuite {
@Test
public void sessionTest() throws XmppStringprepException {
FullJid romeo = JidCreate.fullFrom("romeo@montague.lit/r");
FullJid juliet = JidCreate.fullFrom("juliet@capulet.lit/j");
String sid = StringUtils.randomString(24);
JingleSession s1 = new JingleSession(romeo, juliet, Role.initiator, sid);
JingleSession s2 = new JingleSession(juliet, romeo, Role.responder, sid);
JingleSession s3 = new JingleSession(romeo, juliet, Role.responder, StringUtils.randomString(23));
JingleSession s4 = new JingleSession(juliet, romeo, Role.responder, sid);
JingleSession s5 = new JingleSession(juliet, romeo, Role.initiator, sid);
assertNotSame(s1, s2);
assertNotSame(s1, s3);
assertNotSame(s2, s3);
assertNotSame(s4, s5);
assertEquals(s2, s4);
assertEquals(s2.hashCode(), s4.hashCode());
}
}