From e81c4814ed154dfdcbedbbb331997a6b18856198 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 6 Jan 2020 18:41:30 +0100 Subject: [PATCH 01/17] Make use of XmlStringBuilder in AttentionElement --- .../smackx/attention/packet/AttentionExtension.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/attention/packet/AttentionExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/attention/packet/AttentionExtension.java index cdc47d2cc..c107fe5c3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/attention/packet/AttentionExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/attention/packet/AttentionExtension.java @@ -19,6 +19,7 @@ package org.jivesoftware.smackx.attention.packet; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.XmlEnvironment; import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.xml.XmlPullParser; /** @@ -69,11 +70,8 @@ public class AttentionExtension implements ExtensionElement { * @see org.jivesoftware.smack.packet.PacketExtension#toXML() */ @Override - public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { - final StringBuilder sb = new StringBuilder(); - sb.append('<').append(getElementName()).append(" xmlns=\"").append( - getNamespace()).append("\"/>"); - return sb.toString(); + public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { + return new XmlStringBuilder(this).closeEmptyElement(); } /** From ffbd97ff102703cf9665511e1ef7ec4685142081 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 8 Apr 2020 22:09:13 +0200 Subject: [PATCH 02/17] Add AttentionElementTest --- .../attention/AttentionElementTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/attention/AttentionElementTest.java diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/attention/AttentionElementTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/attention/AttentionElementTest.java new file mode 100644 index 000000000..52be8b713 --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/attention/AttentionElementTest.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2020 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.attention; + +import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar; + +import org.jivesoftware.smackx.attention.packet.AttentionExtension; + +import org.junit.Test; + +public class AttentionElementTest { + + /** + * Serialized Attention element. + * @see XEP-0224: Attention - Example 2 + */ + private static final String XML = ""; + + @Test + public void serializationTest() { + AttentionExtension extension = new AttentionExtension(); + assertXmlSimilar(XML, extension.toXML()); + } +} From b5caf13c8a1b1c0e60e3344d9b398611a827c65b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 8 Apr 2020 22:15:29 +0200 Subject: [PATCH 03/17] Add Nick JUnit test --- .../jivesoftware/smackx/nick/NickTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/nick/NickTest.java diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/nick/NickTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/nick/NickTest.java new file mode 100644 index 000000000..9819642f0 --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/nick/NickTest.java @@ -0,0 +1,83 @@ +/** + * + * Copyright 2020 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.nick; + +import static org.jivesoftware.smack.test.util.XmlUnitUtils.assertXmlSimilar; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; + +import java.io.IOException; + +import org.jivesoftware.smack.parsing.SmackParsingException; +import org.jivesoftware.smack.test.util.SmackTestUtil; +import org.jivesoftware.smack.xml.XmlPullParserException; +import org.jivesoftware.smackx.nick.packet.Nick; +import org.jivesoftware.smackx.nick.provider.NickProvider; + +import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +public class NickTest { + /** + * see XEP-0172: User Nickname - Example 3 + */ + private static final String XML = "Ishmael"; + + @Test + public void disallowEmptyNickTest() { + assertThrows("Empty String as argument MUST cause IllegalArgumentException.", + IllegalArgumentException.class, () -> new Nick("")); + } + + @Test + public void disallowNullNickTest() { + assertThrows("Null argument MUST cause IllegalArgumentException.", + IllegalArgumentException.class, () -> new Nick(null)); + } + + + @Test + public void serializationTest() { + Nick nick = new Nick("Ishmael"); + + assertXmlSimilar(XML, nick.toXML()); + } + + @ParameterizedTest + @EnumSource(SmackTestUtil.XmlPullParserKind.class) + public void deserializationTest(SmackTestUtil.XmlPullParserKind parserKind) + throws XmlPullParserException, IOException, SmackParsingException { + Nick nick = SmackTestUtil.parse(XML, NickProvider.class, parserKind); + + assertNotNull(nick); + assertEquals("Ishmael", nick.getName()); + } + + @Test + public void nicksAreEscapedTest() { + String name = "\"'&"; + + Nick nick = new Nick(name); + + assertXmlSimilar("" + + "</nick>"'&" + + "", nick.toXML()); + assertEquals(name, nick.getName()); + } +} From 4991c952e756ca2439d1f1ebd00a7193376f10f4 Mon Sep 17 00:00:00 2001 From: adiaholic Date: Sun, 20 Oct 2019 17:42:53 +0530 Subject: [PATCH 04/17] Correct code example inside `UserTuneElement`. --- .../smackx/usertune/element/UserTuneElement.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java index 3208557bb..36daa66af 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/element/UserTuneElement.java @@ -161,11 +161,16 @@ public final class UserTuneElement implements ExtensionElement { /** * This class defines a Builder class for {@link UserTuneElement}.
- * {@link UserTuneElement} instance can be obtained using the {@link #build()} method as follows.
- * UserTuneElement.Builder builder = new UserTuneElement.Builder(); - * builder.setSource("Yessongs"); builder.setTitle("Heart of the Sunrise"); - * UserTuneElement userTuneElement = builder.build();
- * Values such as title, source, artist, length, source, track and uri can be set using their respective setters through {@link Builder} + * {@link UserTuneElement} instance can be obtained using the {@link #build()} method as follows.

+ *
+     * {@code
+     * UserTuneElement.Builder builder = UserTuneElement.getBuilder();
+     * builder.setSource("Yessongs");
+     * builder.setTitle("Heart of the Sunrise");
+     * UserTuneElement userTuneElement = builder.build();
+     * }
+     * 
+ * Values such as title, source, artist, length, source, track and uri can be set using their respective setters through {@link Builder}. */ public static final class Builder { private String artist; From 5579567572cf8ec93abe219c613b7a5d668f124a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 8 Apr 2020 20:54:05 +0200 Subject: [PATCH 05/17] core: use addCompressionHandler() instead directly adding to the list --- .../main/java/org/jivesoftware/smack/SmackInitialization.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java index 22bf89490..2a5b79c6a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java @@ -107,7 +107,7 @@ public final class SmackInitialization { } // Add the Java7 compression handler first, since it's preferred - SmackConfiguration.compressionHandlers.add(new Java7ZlibInputOutputStream()); + SmackConfiguration.addCompressionHandler(new Java7ZlibInputOutputStream()); XmppCompressionManager.registerXmppCompressionFactory(ZlibXmppCompressionFactory.INSTANCE); From 57d7ac4d5d3af51627dc01502313795a760c2ce8 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 8 Apr 2020 20:57:02 +0200 Subject: [PATCH 06/17] Remove smack-compression-jzlib The smack-compression-jzlib subproject is obsolete since Java 7 de- and inflate support was added with SMACK-389. Now it is time to remove it. Fixes SMACK-840. --- build.gradle | 1 - settings.gradle | 1 - smack-compression-jzlib/build.gradle | 8 --- .../jzlib/JzlibInputOutputStream.java | 67 ------------------- .../smack/compression/jzlib/package-info.java | 21 ------ .../smack/compression/package-info.java | 1 - 6 files changed, 99 deletions(-) delete mode 100644 smack-compression-jzlib/build.gradle delete mode 100644 smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java delete mode 100644 smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/package-info.java delete mode 120000 smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/package-info.java diff --git a/build.gradle b/build.gradle index 502245fd0..6eeea45c5 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,6 @@ allprojects { ':smack-android', ':smack-android-extensions', ':smack-bosh', - ':smack-compression-jzlib', ':smack-debug', ':smack-debug-slf4j', ':smack-java7', diff --git a/settings.gradle b/settings.gradle index 0f84a8753..37bbbb004 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,7 +16,6 @@ include 'smack-core', 'smack-resolver-javax', 'smack-sasl-javax', 'smack-sasl-provided', - 'smack-compression-jzlib', 'smack-legacy', 'smack-jingle-old', 'smack-bosh', diff --git a/smack-compression-jzlib/build.gradle b/smack-compression-jzlib/build.gradle deleted file mode 100644 index b9aeb8b84..000000000 --- a/smack-compression-jzlib/build.gradle +++ /dev/null @@ -1,8 +0,0 @@ -description = """\ -Compression with jzlib -Allow to compress the XMPP stream with help of jzlib.""" - -dependencies { - compile project(':smack-core') - compile 'com.jcraft:jzlib:[1.1,1.2)' -} diff --git a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java b/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java deleted file mode 100644 index ae231d5f5..000000000 --- a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * Copyright 2013-2014 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.smack.compression.jzlib; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.jivesoftware.smack.SmackConfiguration; -import org.jivesoftware.smack.compression.XMPPInputOutputStream; - -import com.jcraft.jzlib.DeflaterOutputStream; -import com.jcraft.jzlib.InflaterInputStream; - -/** - * This class provides XMPP "zlib" compression with the help of JZLib. - * - * @author Florian Schmaus - * @see JZLib - * - */ -public class JzlibInputOutputStream extends XMPPInputOutputStream { - - static { - SmackConfiguration.addCompressionHandler(new JzlibInputOutputStream()); - } - - public JzlibInputOutputStream() { - super("zlib"); - } - - @Override - public boolean isSupported() { - return true; - } - - @Override - public InputStream getInputStream(InputStream inputStream) throws IOException { - final InflaterInputStream is = new InflaterInputStream(inputStream); - - return is; - } - - @Override - public OutputStream getOutputStream(OutputStream outputStream) throws IOException { - final DeflaterOutputStream os = new DeflaterOutputStream(outputStream); - if (flushMethod == FlushMethod.SYNC_FLUSH) { - os.setSyncFlush(true); - } - - return os; - } -} diff --git a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/package-info.java b/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/package-info.java deleted file mode 100644 index b598d0ddd..000000000 --- a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * - * Copyright 2015 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. - */ - -/** - * Support for XMPP stream compression (XEP-138) via JZlib. - */ -package org.jivesoftware.smack.compression.jzlib; diff --git a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/package-info.java b/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/package-info.java deleted file mode 120000 index c88ae8f0b..000000000 --- a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/package-info.java +++ /dev/null @@ -1 +0,0 @@ -../../../../../../../../smack-core/src/main/java/org/jivesoftware/smack/compression/package-info.java \ No newline at end of file From f329b447f23c5d8882786029d2b0e12556918025 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 8 Apr 2020 21:17:59 +0200 Subject: [PATCH 07/17] Delete some outdated code from the old integration-test dir The code in the integration-test/ directories should either be migrated to sinttest (or unit tests), or get deleted. This is a first small step towards this goal. --- .../jivesoftware/smack/util/CacheTest.java | 43 ---- .../smack/util/ConnectionUtils.java | 29 --- .../smack/util/XMPPErrorTest.java | 203 ------------------ 3 files changed, 275 deletions(-) delete mode 100644 smack-core/src/integration-test/java/org/jivesoftware/smack/util/CacheTest.java delete mode 100644 smack-core/src/integration-test/java/org/jivesoftware/smack/util/ConnectionUtils.java delete mode 100644 smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/CacheTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/CacheTest.java deleted file mode 100644 index 0243ca330..000000000 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/CacheTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - * Copyright 2005 Jive Software. - * - * 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.smack.util; - -import junit.framework.TestCase; - -/** - * A test case for the Cache class. - */ -public class CacheTest extends TestCase { - - public void testMaxSize() { - Cache cache = new Cache(100, -1); - for (int i=0; i < 1000; i++) { - cache.put(i, "value"); - assertTrue("Cache size must never be larger than 100.", cache.size() <= 100); - } - } - - public void testLRU() { - Cache cache = new Cache(100, -1); - for (int i=0; i < 1000; i++) { - cache.put(i, "value"); - assertTrue("LRU algorithm for cache key of '0' failed.", - cache.get(new Integer(0)) != null); - } - } -} diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/ConnectionUtils.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/ConnectionUtils.java deleted file mode 100644 index e02b72c84..000000000 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/ConnectionUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.jivesoftware.smack.util; - -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.Roster; -import org.jivesoftware.smack.XMPPException; - -public class ConnectionUtils { - - private ConnectionUtils() {} - - public static void becomeFriends(XMPPConnection con0, XMPPConnection con1) throws XMPPException { - Roster r0 = con0.getRoster(); - Roster r1 = con1.getRoster(); - r0.setSubscriptionMode(Roster.SubscriptionMode.accept_all); - r1.setSubscriptionMode(Roster.SubscriptionMode.accept_all); - r0.createEntry(con1.getUser(), "u2", null); - r1.createEntry(con0.getUser(), "u1", null); - } - - public static void letsAllBeFriends(XMPPConnection[] connections) throws XMPPException { - for (XMPPConnection c1 : connections) { - for (XMPPConnection c2 : connections) { - if (c1 == c2) - continue; - becomeFriends(c1, c2); - } - } - } -} diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java deleted file mode 100644 index 8d2a0df4f..000000000 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/** - * - * Copyright 2006 Jive Software. - * - * 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.smack.util; - -import java.io.StringReader; - -import org.jivesoftware.smack.packet.XMPPError; -import org.jivesoftware.smack.test.SmackTestCase; -import org.jivesoftware.smack.xml.XmlPullParserFactory; -import org.jivesoftware.smack.xml.XmlPullParser; -import org.jivesoftware.smack.xml.XmlPullParserException; - -public class XMPPErrorTest extends SmackTestCase { - - public XMPPErrorTest(String arg0) { - super(arg0); - } - - /** - * Check the creation of a new xmppError locally. - */ - public void testLocalErrorCreation() { - XMPPError error = new XMPPError(XMPPError.Condition.item_not_found); - error.toXML(); - - assertEquals(error.getCondition(), "item-not-found"); - assertEquals(error.getCode(), 404); - assertEquals(error.getType(), XMPPError.Type.CANCEL); - assertNull(error.getMessage()); - } - - /** - * Check the creation of a new xmppError locally. - */ - public void testLocalErrorWithCommentCreation() { - String message = "Error Message"; - XMPPError error = new XMPPError(XMPPError.Condition.item_not_found, message); - error.toXML(); - - assertEquals(error.getCondition(), "item-not-found"); - assertEquals(error.getCode(), 404); - assertEquals(error.getType(), XMPPError.Type.CANCEL); - assertEquals(error.getMessage(), message); - } - - /** - * Check the creation of a new xmppError locally where there is not a default defined. - */ - public void testUserDefinedErrorWithCommentCreation() { - String message = "Error Message"; - XMPPError error = new XMPPError(new XMPPError.Condition("my_own_error"), message); - error.toXML(); - - assertEquals(error.getCondition(), "my_own_error"); - assertEquals(error.getCode(), 0); - assertNull(error.getType()); - assertEquals(error.getMessage(), message); - } - - /** - * Check the parser with an xml with the 404 error. - */ - public void test404() { - // Make the XML to test - String xml = "" + - "" + - ""; - try { - // Create the xml parser - XmlPullParser parser = getParserFromXML(xml); - // Create a packet from the xml - XMPPError packet = parseError(parser); - - assertNotNull(packet); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - /** - * Check the parser with an xml with the 404 error. - */ - public void testCancel() { - // Make the XML to test - String xml = "" + - "" + - ""; - try { - // Create the xml parser - XmlPullParser parser = getParserFromXML(xml); - // Create a packet from the xml - XMPPError error = parseError(parser); - - assertNotNull(error); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - public void testMessageAndApplicationDefinedError() { - String xml = "" + - "" + - "" + - "Some special application diagnostic information..." + - "" + - "" + - ""; - try { - // Create the xml parser - XmlPullParser parser = getParserFromXML(xml); - // Create a packet from the xml - XMPPError error = parseError(parser); - - String sendingXML = error.toXML(); - - assertNotNull(error); - assertNotNull(sendingXML); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - /** - * Check the parser with an xml with the 404 error. - */ - public void testCancelWithMessage() { - // Make the XML to test - String xml = "" + - "" + - "" + - "Some special application diagnostic information!" + - "" + - ""; - try { - // Create the xml parser - XmlPullParser parser = getParserFromXML(xml); - // Create a packet from the xml - XMPPError error = parseError(parser); - - assertNotNull(error); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - /** - * Check the parser with an xml with the 404 error. - */ - public void testCancelWithMessageAndApplicationError() { - // Make the XML to test - String xml = "" + - "" + - "" + - "Some special application diagnostic information!" + - "" + - "" + - ""; - try { - // Create the xml parser - XmlPullParser parser = getParserFromXML(xml); - // Create a packet from the xml - XMPPError error = parseError(parser); - - assertNotNull(error); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - private XMPPError parseError(XmlPullParser parser) throws Exception { - parser.next(); - return PacketParserUtils.parseError(parser); - } - - private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException { - XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(new StringReader(xml)); - return parser; - } - - protected int getMaxConnections() { - return 0; - } -} From f1dd925844a9f98c485081491b5003c7a43dac67 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 8 Apr 2020 21:19:25 +0200 Subject: [PATCH 08/17] Mark code from the old integration-test dir as migration candidates --- .../integration-test/java/org/jivesoftware/smack/FloodTest.java | 1 + .../src/integration-test/java/org/jivesoftware/smack/IQTest.java | 1 + .../java/org/jivesoftware/smack/MessageTest.java | 1 + .../java/org/jivesoftware/smack/util/DNSUtilTest.java | 1 + 4 files changed, 4 insertions(+) diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/FloodTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/FloodTest.java index d6234b53d..57253f19c 100644 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/FloodTest.java +++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/FloodTest.java @@ -25,6 +25,7 @@ import org.jivesoftware.smack.filter.ThreadFilter; * * @author Gaston Dombiak */ +// sinttest candidate public class FloodTest extends SmackTestCase { public FloodTest(String arg0) { diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/IQTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/IQTest.java index 1463c0fd4..5b8cfd87f 100644 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/IQTest.java +++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/IQTest.java @@ -30,6 +30,7 @@ import org.jivesoftware.smackx.packet.Version; * * @author Gaston Dombiak */ +// sinttest candidate public class IQTest extends SmackTestCase { public IQTest(String arg0) { diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/MessageTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/MessageTest.java index b483f9ef7..75b4f6915 100644 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/MessageTest.java +++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/MessageTest.java @@ -27,6 +27,7 @@ import org.jivesoftware.smack.test.SmackTestCase; * * @author Gaston Dombiak */ +// sinttest candidate public class MessageTest extends SmackTestCase { public MessageTest(String arg0) { diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/DNSUtilTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/DNSUtilTest.java index b1bbc89c0..bed03d075 100644 --- a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/DNSUtilTest.java +++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/DNSUtilTest.java @@ -16,6 +16,7 @@ import org.jivesoftware.smack.util.dns.JavaxResolver; import org.jivesoftware.smack.util.dns.SRVRecord; import org.junit.Test; +// minidns candidate? public class DNSUtilTest { private static final String igniterealtimeDomain = "igniterealtime.org"; private static final String igniterealtimeXMPPServer = "xmpp." + igniterealtimeDomain; From bf92712f4c2dce4b57fb6955ce446d3308945b13 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 8 Apr 2020 21:44:45 +0200 Subject: [PATCH 09/17] legacy: merge workgroup.providers into legacy.providers Previously the workgroup providers where not automatically loaded by Smack. Fixes SMACK-729. --- .../legacy.providers | 210 +++++++++++++++++ .../workgroup.providers | 215 ------------------ 2 files changed, 210 insertions(+), 215 deletions(-) delete mode 100644 smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/workgroup.providers diff --git a/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/legacy.providers b/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/legacy.providers index 76b426839..5c8fe3104 100644 --- a/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/legacy.providers +++ b/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/legacy.providers @@ -16,4 +16,214 @@ org.jivesoftware.smackx.xroster.provider.RosterExchangeProvider + + + offer + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.OfferRequestProvider + + + + offer-revoke + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.OfferRevokeProvider + + + + agent-status-request + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.AgentStatusRequest$Provider + + + + transcripts + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.TranscriptsProvider + + + + transcript + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.TranscriptProvider + + + + workgroups + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups$Provider + + + + agent-info + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.AgentInfo$Provider + + + + transcript-search + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.TranscriptSearch$Provider + + + + occupants-info + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.OccupantsInfo$Provider + + + + chat-settings + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.settings.ChatSettings$InternalProvider + + + + chat-notes + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.ext.notes.ChatNotes$Provider + + + + chat-sessions + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.ext.history.AgentChatHistory$InternalProvider + + + + offline-settings + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.settings.OfflineSettings$InternalProvider + + + + sound-settings + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.settings.SoundSettings$InternalProvider + + + + workgroup-properties + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.settings.WorkgroupProperties$InternalProvider + + + + + search-settings + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.settings.SearchSettings$InternalProvider + + + + workgroup-form + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm$InternalProvider + + + + macros + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.ext.macros.Macros$InternalProvider + + + + chat-metadata + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.ext.history.ChatMetadata$Provider + + + + generic-metadata + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.settings.GenericSettings$InternalProvider + + + + monitor + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.MonitorPacket$InternalProvider + + + + + queue-status + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.QueueUpdate$Provider + + + + workgroup + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.WorkgroupInformation$Provider + + + + metadata + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.MetaDataProvider + + + + session + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.SessionID$Provider + + + + user + http://jivesoftware.com/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.UserID$Provider + + + + agent-status + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.AgentStatus$Provider + + + + notify-queue-details + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.QueueDetails$Provider + + + + notify-queue + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.QueueOverview$Provider + + + + invite + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.RoomInvitation$Provider + + + + transfer + http://jabber.org/protocol/workgroup + org.jivesoftware.smackx.workgroup.packet.RoomTransfer$Provider + + diff --git a/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/workgroup.providers b/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/workgroup.providers deleted file mode 100644 index 2c7025210..000000000 --- a/smack-legacy/src/main/resources/org.jivesoftware.smack.legacy/workgroup.providers +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - offer - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.OfferRequestProvider - - - - offer-revoke - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.OfferRevokeProvider - - - - agent-status-request - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.AgentStatusRequest$Provider - - - - transcripts - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.TranscriptsProvider - - - - transcript - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.TranscriptProvider - - - - workgroups - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups$Provider - - - - agent-info - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.AgentInfo$Provider - - - - transcript-search - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.TranscriptSearch$Provider - - - - occupants-info - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.OccupantsInfo$Provider - - - - chat-settings - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.settings.ChatSettings$InternalProvider - - - - chat-notes - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.ext.notes.ChatNotes$Provider - - - - chat-sessions - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.ext.history.AgentChatHistory$InternalProvider - - - - offline-settings - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.settings.OfflineSettings$InternalProvider - - - - sound-settings - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.settings.SoundSettings$InternalProvider - - - - workgroup-properties - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.settings.WorkgroupProperties$InternalProvider - - - - - search-settings - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.settings.SearchSettings$InternalProvider - - - - workgroup-form - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm$InternalProvider - - - - macros - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.ext.macros.Macros$InternalProvider - - - - chat-metadata - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.ext.history.ChatMetadata$Provider - - - - generic-metadata - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.settings.GenericSettings$InternalProvider - - - - monitor - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.MonitorPacket$InternalProvider - - - - - queue-status - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.QueueUpdate$Provider - - - - workgroup - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.WorkgroupInformation$Provider - - - - metadata - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.MetaDataProvider - - - - session - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.SessionID$Provider - - - - user - http://jivesoftware.com/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.UserID$Provider - - - - agent-status - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.AgentStatus$Provider - - - - notify-queue-details - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.QueueDetails$Provider - - - - notify-queue - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.QueueOverview$Provider - - - - invite - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.RoomInvitation$Provider - - - - transfer - http://jabber.org/protocol/workgroup - org.jivesoftware.smackx.workgroup.packet.RoomTransfer$Provider - - - From 353e43407f8ccc4b610ea187793472b58a49da3a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 15:15:27 +0200 Subject: [PATCH 10/17] mam: support of advanced configuration Fixes SMACK-822. Co-authored-by: Jagmeet Singh --- .../jivesoftware/smackx/mam/MamManager.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index e95048665..3b7b3ef75 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2017-2019 Florian Schmaus, 2016-2017 Fernando Ramirez + * Copyright © 2017-2020 Florian Schmaus, 2016-2017 Fernando Ramirez * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,14 @@ import java.util.WeakHashMap; import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotLoggedInException; import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnectionRegistry; +import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.IQReplyFilter; import org.jivesoftware.smack.packet.IQ; @@ -41,10 +43,11 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.StringUtils; - +import org.jivesoftware.smackx.commands.AdHocCommandManager; +import org.jivesoftware.smackx.commands.RemoteCommand; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; +import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.forward.packet.Forwarded; -import org.jivesoftware.smackx.mam.MamManager.MamQueryArgs; import org.jivesoftware.smackx.mam.element.MamElements; import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension; import org.jivesoftware.smackx.mam.element.MamFinIQ; @@ -172,6 +175,8 @@ public final class MamManager extends Manager { private static final Map> INSTANCES = new WeakHashMap<>(); + private static final String ADVANCED_CONFIG_NODE = "urn:xmpp:mam#configure"; + /** * Get a MamManager for the MAM archive of the local entity (the "user") of the given connection. * @@ -216,10 +221,13 @@ public final class MamManager extends Manager { private final ServiceDiscoveryManager serviceDiscoveryManager; + private final AdHocCommandManager adHocCommandManager; + private MamManager(XMPPConnection connection, Jid archiveAddress) { super(connection); this.archiveAddress = archiveAddress; serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); + adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection); } /** @@ -714,6 +722,25 @@ public final class MamManager extends Manager { return serviceDiscoveryManager.supportsFeature(archiveAddress, MamElements.NAMESPACE); } + public boolean isAdvancedConfigurationSupported() throws InterruptedException, XMPPException, SmackException { + DiscoverItems discoverItems = adHocCommandManager.discoverCommands(archiveAddress); + for (DiscoverItems.Item item : discoverItems.getItems()) { + if (item.getNode().equals(ADVANCED_CONFIG_NODE)) { + return true; + } + } + return false; + } + + public RemoteCommand getAdvancedConfigurationCommand() throws InterruptedException, XMPPException, SmackException { + DiscoverItems discoverItems = adHocCommandManager.discoverCommands(archiveAddress); + for (DiscoverItems.Item item : discoverItems.getItems()) { + if (item.getNode().equals(ADVANCED_CONFIG_NODE)) + return adHocCommandManager.getRemoteCommand(archiveAddress, item.getNode()); + } + throw new SmackException.FeatureNotSupportedException(ADVANCED_CONFIG_NODE, archiveAddress); + } + private static DataForm getNewMamForm() { FormField field = FormField.hiddenFormType(MamElements.NAMESPACE); DataForm form = new DataForm(DataForm.Type.submit); From 1e5ea1fdbef5714228a888ab7d3e7ff97f5b3a3a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 15:20:00 +0200 Subject: [PATCH 11/17] mam: remove dead code in MamManager --- .../jivesoftware/smackx/mam/MamManager.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index 3b7b3ef75..efa584708 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -561,30 +561,6 @@ public final class MamManager extends Manager { return new MamQueryPage(cancelledResultCollector, mamFinIQ); } - /** - * MAM query result class. - * - */ - @Deprecated - @SuppressWarnings("UnusedVariable") - public static final class MamQueryResult { - public final List forwardedMessages; - public final MamFinIQ mamFin; - private final String node; - private final DataForm form; - - private MamQueryResult(MamQuery mamQuery) { - this(mamQuery.mamQueryPage.forwardedMessages, mamQuery.mamQueryPage.mamFin, mamQuery.node, mamQuery.form); - } - - private MamQueryResult(List forwardedMessages, MamFinIQ mamFin, String node, DataForm form) { - this.forwardedMessages = forwardedMessages; - this.mamFin = mamFin; - this.node = node; - this.form = form; - } - } - public final class MamQuery { private final String node; private final DataForm form; From b8b084970ec28db634e255d6f04d1c5b29909603 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 15:21:50 +0200 Subject: [PATCH 12/17] mam: remove deprecated method in MamManager --- .../jivesoftware/smackx/mam/MamManager.java | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index efa584708..721407dfd 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -766,34 +766,6 @@ public final class MamManager extends Manager { return queryMamPrefs(mamPrefIQ); } - /** - * Update the preferences in the server. - * - * @param alwaysJids TODO javadoc me please - * is the list of JIDs that should always have messages to/from - * archived in the user's store - * @param neverJids TODO javadoc me please - * is the list of JIDs that should never have messages to/from - * archived in the user's store - * @param defaultBehavior TODO javadoc me please - * can be "roster", "always", "never" (see XEP-0313) - * @return the MAM preferences result - * @throws NoResponseException if there was no response from the remote entity. - * @throws XMPPErrorException if there was an XMPP error returned. - * @throws NotConnectedException if the XMPP connection is not connected. - * @throws InterruptedException if the calling thread was interrupted. - * @throws NotLoggedInException if the XMPP connection is not authenticated. - * @deprecated use {@link #updateArchivingPreferences(MamPrefs)} instead. - */ - @Deprecated - public MamPrefsResult updateArchivingPreferences(List alwaysJids, List neverJids, DefaultBehavior defaultBehavior) - throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, - NotLoggedInException { - Objects.requireNonNull(defaultBehavior, "Default behavior must be set"); - MamPrefsIQ mamPrefIQ = new MamPrefsIQ(alwaysJids, neverJids, defaultBehavior); - return queryMamPrefs(mamPrefIQ); - } - /** * Update the preferences in the server. * From 390f7823e1e39399d783f7b10a52be28d6ba5b3c Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 15:22:33 +0200 Subject: [PATCH 13/17] mam: add javadoc for parameter --- .../src/main/java/org/jivesoftware/smackx/mam/MamManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index 721407dfd..f3477bdd4 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -769,7 +769,7 @@ public final class MamManager extends Manager { /** * Update the preferences in the server. * - * @param mamPrefs TODO javadoc me please + * @param mamPrefs the MAM preferences to set the archive to * @return the currently active preferences after the operation. * @throws NoResponseException if there was no response from the remote entity. * @throws XMPPErrorException if there was an XMPP error returned. From 85af4a022d3b81834a44e0b74c2e5b17783903ac Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 20:54:36 +0200 Subject: [PATCH 14/17] compression: remove Android SDK level < 19 compatiblity Since we now require Android SDK 19 or higher, we can use the method directly. --- .../Java7ZlibInputOutputStream.java | 54 ++++++------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/compression/Java7ZlibInputOutputStream.java b/smack-core/src/main/java/org/jivesoftware/smack/compression/Java7ZlibInputOutputStream.java index fd71d90ef..3d830445c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/compression/Java7ZlibInputOutputStream.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/compression/Java7ZlibInputOutputStream.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013-2018 Florian Schmaus + * Copyright 2013-2020 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ package org.jivesoftware.smack.compression; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; import java.util.zip.Inflater; @@ -41,31 +39,15 @@ import java.util.zip.InflaterInputStream; * @author Florian Schmaus */ public class Java7ZlibInputOutputStream extends XMPPInputOutputStream { - private static final Method method; - private static final boolean supported; private static final int compressionLevel = Deflater.DEFAULT_COMPRESSION; - private static final int SYNC_FLUSH_INT = 2; - private static final int FULL_FLUSH_INT = 3; - - static { - Method m = null; - try { - m = Deflater.class.getMethod("deflate", byte[].class, int.class, int.class, int.class); - } catch (SecurityException e) { - } catch (NoSuchMethodException e) { - } - method = m; - supported = method != null; - } - public Java7ZlibInputOutputStream() { super("zlib"); } @Override public boolean isSupported() { - return supported; + return true; } @Override @@ -101,29 +83,23 @@ public class Java7ZlibInputOutputStream extends XMPPInputOutputStream { @Override public OutputStream getOutputStream(OutputStream outputStream) { final int flushMethodInt; - if (flushMethod == FlushMethod.SYNC_FLUSH) { - flushMethodInt = SYNC_FLUSH_INT; - } else { - flushMethodInt = FULL_FLUSH_INT; + switch (flushMethod) { + case SYNC_FLUSH: + flushMethodInt = Deflater.SYNC_FLUSH; + break; + case FULL_FLUSH: + flushMethodInt = Deflater.FULL_FLUSH; + break; + default: + throw new AssertionError(); } + return new DeflaterOutputStream(outputStream, new Deflater(compressionLevel)) { @Override public void flush() throws IOException { - if (!supported) { - super.flush(); - return; - } - try { - int count; - while ((count = (Integer) method.invoke(def, buf, 0, buf.length, flushMethodInt)) != 0) { - out.write(buf, 0, count); - } - } catch (IllegalArgumentException e) { - throw new IOException("Can't flush"); - } catch (IllegalAccessException e) { - throw new IOException("Can't flush"); - } catch (InvocationTargetException e) { - throw new IOException("Can't flush"); + int count; + while ((count = def.deflate(buf, 0, buf.length, flushMethodInt)) > 0) { + out.write(buf, 0, count); } super.flush(); } From e68b89d266ac63d912ab8da5ce4226e1e02744d0 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 21:07:41 +0200 Subject: [PATCH 15/17] sinttest: rename and move ModularXmppClientToServerConnection test Rename and move the test in the correct package. --- ...ppClientToServerConnectionLowLevelIntegrationTest.java} | 7 +++---- .../main/java/org/jivesoftware/smack/c2s/package-info.java | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) rename smack-integration-test/src/main/java/org/jivesoftware/smack/{tcp/XmppNioTcpConnectionLowLevelIntegrationTest.java => c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java} (80%) create mode 120000 smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/package-info.java diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/tcp/XmppNioTcpConnectionLowLevelIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java similarity index 80% rename from smack-integration-test/src/main/java/org/jivesoftware/smack/tcp/XmppNioTcpConnectionLowLevelIntegrationTest.java rename to smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java index 5971ceda6..541b057be 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smack/tcp/XmppNioTcpConnectionLowLevelIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.tcp; +package org.jivesoftware.smack.c2s; import java.io.IOException; import java.security.KeyManagementException; @@ -22,15 +22,14 @@ import java.security.NoSuchAlgorithmException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection; import org.igniterealtime.smack.inttest.AbstractSmackSpecificLowLevelIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; -public class XmppNioTcpConnectionLowLevelIntegrationTest extends AbstractSmackSpecificLowLevelIntegrationTest { +public class ModularXmppClientToServerConnectionLowLevelIntegrationTest extends AbstractSmackSpecificLowLevelIntegrationTest { - public XmppNioTcpConnectionLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) { + public ModularXmppClientToServerConnectionLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) { super(environment, ModularXmppClientToServerConnection.class); } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/package-info.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/package-info.java new file mode 120000 index 000000000..b79177a68 --- /dev/null +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/package-info.java @@ -0,0 +1 @@ +../../../../../../../../smack-core/src/main/java/org/jivesoftware/smack/c2s/package-info.java \ No newline at end of file From 79b9c7b9346e9945b46cf59d785d204309a94803 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 21:09:42 +0200 Subject: [PATCH 16/17] sinttest: add testDisconnectedNeverConnected for modular connection --- ...lientToServerConnectionLowLevelIntegrationTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java index 541b057be..c5a1564c6 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnectionLowLevelIntegrationTest.java @@ -21,7 +21,10 @@ import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.SmackException.NoResponseException; +import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.igniterealtime.smack.inttest.AbstractSmackSpecificLowLevelIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTest; @@ -43,4 +46,11 @@ public class ModularXmppClientToServerConnectionLowLevelIntegrationTest extends connection.disconnect(); } + @SmackIntegrationTest + public void testDisconnectNeverConnected() + throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + ModularXmppClientToServerConnection connection = getSpecificUnconnectedConnection(); + + connection.disconnect(); + } } From 993bed07ef3a000b252c49a43b44171022fd4d94 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 10 Apr 2020 19:52:43 +0200 Subject: [PATCH 17/17] readme: replace IRC badge with XMPP MUC badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dcb526f47..7ae8508f4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Smack ===== -[![Build Status](https://travis-ci.org/igniterealtime/Smack.svg?branch=master)](https://travis-ci.org/igniterealtime/Smack) [![Coverage Status](https://coveralls.io/repos/igniterealtime/Smack/badge.svg)](https://coveralls.io/r/igniterealtime/Smack) [![Project Stats](https://www.openhub.net/p/smack/widgets/project_thin_badge.gif)](https://www.openhub.net/p/smack) [![Visit our IRC channel](https://kiwiirc.com/buttons/irc.freenode.net/smack.png)](https://kiwiirc.com/client/irc.freenode.net/smack) +[![Build Status](https://travis-ci.org/igniterealtime/Smack.svg?branch=master)](https://travis-ci.org/igniterealtime/Smack) [![Coverage Status](https://coveralls.io/repos/igniterealtime/Smack/badge.svg)](https://coveralls.io/r/igniterealtime/Smack) [![Project Stats](https://www.openhub.net/p/smack/widgets/project_thin_badge.gif)](https://www.openhub.net/p/smack) [![Link to XMPP chat smack@conference.igniterealtime.org](https://inverse.chat/badge.svg?room=smack@conference.igniterealtime.org)](https://inverse.chat/#converse/room?jid=smack@conference.igniterealtime.org) About -----