From 33221c57f9bf46484612f49ccbb1c375a4a13bf2 Mon Sep 17 00:00:00 2001 From: Mohsen Hariri Date: Mon, 2 Jul 2018 11:50:58 +0200 Subject: [PATCH 1/8] Fix missing body namespace in BOSH messages The body's "jabber:client" namespace was missing in BOSH messages. --- .../java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index 907d7be6f..756c2d885 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -39,7 +39,6 @@ import org.jivesoftware.smack.packet.Nonza; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.StanzaError; -import org.jivesoftware.smack.packet.StreamOpen; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Success; import org.jivesoftware.smack.util.PacketParserUtils; @@ -235,7 +234,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { private void sendElement(Element element) { try { - send(ComposableBody.builder().setPayloadXML(element.toXML(StreamOpen.CLIENT_NAMESPACE).toString()).build()); + send(ComposableBody.builder().setPayloadXML(element.toXML(BOSH_URI).toString()).build()); if (element instanceof Stanza) { firePacketSendingListeners((Stanza) element); } From 2347c2a0256c3aaac1b59de3387be3ed6167d3d4 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 4 Jul 2018 11:55:58 +0200 Subject: [PATCH 2/8] Avoid adding multiple processing hints to a message --- .../java/org/jivesoftware/smackx/hints/element/NoCopyHint.java | 2 +- .../jivesoftware/smackx/hints/element/NoPermanentStoreHint.java | 2 +- .../java/org/jivesoftware/smackx/hints/element/NoStoreHint.java | 2 +- .../java/org/jivesoftware/smackx/hints/element/StoreHint.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java index b07249ddd..a22a0f7b7 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoCopyHint.java @@ -56,6 +56,6 @@ public final class NoCopyHint extends MessageProcessingHint { } public static void set(Message message) { - message.addExtension(INSTANCE); + message.overrideExtension(INSTANCE); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java index bd3bac500..ff27c5bb1 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoPermanentStoreHint.java @@ -60,7 +60,7 @@ public final class NoPermanentStoreHint extends MessageProcessingHint { // No need to set the no-permanent-store hint when a no-store hint is already set. return; } - setExplicitly(message); + message.overrideExtension(INSTANCE); } public static void setExplicitly(Message message) { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java index 508812ec9..78e0f731a 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/NoStoreHint.java @@ -56,6 +56,6 @@ public final class NoStoreHint extends MessageProcessingHint { } public static void set(Message message) { - message.addExtension(INSTANCE); + message.overrideExtension(INSTANCE); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java index f468514b1..fdbed6cb3 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hints/element/StoreHint.java @@ -56,6 +56,6 @@ public final class StoreHint extends MessageProcessingHint { } public static void set(Message message) { - message.addExtension(INSTANCE); + message.overrideExtension(INSTANCE); } } From 9596ca894303fc887eb5a1d6f52e7ef783c99296 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 30 Jul 2018 11:51:20 +0200 Subject: [PATCH 3/8] Bump AnimalSniffer to 1.4.5 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7d628671a..0512bd8d9 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { } plugins { - id 'ru.vyarus.animalsniffer' version '1.4.3' + id 'ru.vyarus.animalsniffer' version '1.4.5' } apply plugin: 'org.kordamp.gradle.markdown' From a3fcbdbf5af531c6ead3b310b6b9d69e321269eb Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 1 Aug 2018 13:16:20 +0200 Subject: [PATCH 4/8] Make Stanza.appendErrorIfExists() aware of the enclosing XML namespace Originally discovered by Paul Schaub: Fixes an inconvenience, where an IQ with the implicit namespace `jabber:client` would append the namespace to an error child element like this: ``` ... /> `` --- .../java/org/jivesoftware/smack/packet/IQ.java | 16 ++++++++++++++-- .../org/jivesoftware/smack/packet/Message.java | 2 +- .../org/jivesoftware/smack/packet/Presence.java | 2 +- .../org/jivesoftware/smack/packet/Stanza.java | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java index 92ef0a964..09fa9178e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/IQ.java @@ -137,7 +137,7 @@ public abstract class IQ extends Stanza { buf.attribute("type", type.toString()); } buf.rightAngleBracket(); - buf.append(getChildElementXML()); + buf.append(getChildElementXML(enclosingNamespace)); buf.closeElement(IQ_ELEMENT); return buf; } @@ -149,10 +149,22 @@ public abstract class IQ extends Stanza { * @return the child element section of the IQ XML. */ public final XmlStringBuilder getChildElementXML() { + return getChildElementXML(null); + } + + /** + * Returns the sub-element XML section of the IQ packet, or the empty String if there + * isn't one. + * + * @param enclosingNamespace the enclosing XML namespace. + * @return the child element section of the IQ XML. + * @since 4.3.0 + */ + public final XmlStringBuilder getChildElementXML(String enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(); if (type == Type.error) { // Add the error sub-packet, if there is one. - appendErrorIfExists(xml); + appendErrorIfExists(xml, enclosingNamespace); } else if (childElementName != null) { // Add the query section if there is one. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java index cb87251c7..ee22034c5 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java @@ -501,7 +501,7 @@ public final class Message extends Stanza implements TypedCloneable { buf.optElement("thread", thread); // Append the error subpacket if the message type is an error. if (type == Type.error) { - appendErrorIfExists(buf); + appendErrorIfExists(buf, enclosingNamespace); } // Add extension elements, if any are defined. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index abf4e39c5..99a0b8ae1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -292,7 +292,7 @@ public final class Presence extends Stanza implements TypedCloneable { buf.append(getExtensions(), enclosingNamespace); // Add the error sub-packet, if there is one. - appendErrorIfExists(buf); + appendErrorIfExists(buf, enclosingNamespace); buf.closeElement(ELEMENT); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java index 2dff229ab..e9c9072fa 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java @@ -541,10 +541,10 @@ public abstract class Stanza implements TopLevelStreamElement { * * @param xml the XmlStringBuilder to append the error to. */ - protected void appendErrorIfExists(XmlStringBuilder xml) { + protected void appendErrorIfExists(XmlStringBuilder xml, String enclosingNamespace) { StanzaError error = getError(); if (error != null) { - xml.append(error.toXML()); + xml.append(error.toXML(enclosingNamespace)); } } } From 5bf0fd64ac8d692c983a846e42343844bd285866 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 2 Aug 2018 09:37:26 +0200 Subject: [PATCH 5/8] Add ExceptionThrowingCallbackWithHint and javadoc about parsing exceptions also providing rationale. --- .../smack/AbstractXMPPConnection.java | 32 ++++++++++++++ .../smack/SmackConfiguration.java | 4 +- .../ExceptionThrowingCallbackWithHint.java | 43 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallbackWithHint.java diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index ad576d00b..6ab848c50 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -97,6 +97,38 @@ import org.minidns.dnsname.DnsName; import org.xmlpull.v1.XmlPullParser; +/** + * This abstract class is commonly used as super class for XMPP connection mechanisms like TCP and BOSH. Hence it + * provides the methods for connection state management, like {@link #connect()}, {@link #login()} and + * {@link #disconnect()} (which are deliberately not provided by the {@link XMPPConnection} interface). + *

+ * Note: The default entry point to Smack's documentation is {@link XMPPConnection}. If you are getting started + * with Smack, then head over to {@link XMPPConnection} and the come back here. + *

+ *

Parsing Exceptions

+ *

+ * In case a Smack parser (Provider) throws those exceptions are handled over to the {@link ParsingExceptionCallback}. A + * common cause for a provider throwing is illegal input, for example a non-numeric String where only Integers are + * allowed. Smack's default behavior follows the "fail-hard per default" principle leading to a + * termination of the connection on parsing exceptions. This default was chosen to make users eventually aware that they + * should configure their own callback and handle those exceptions to prevent the disconnect. Handle a parsing exception + * could be as simple as using a non-throwing no-op callback, which would cause the faulty stream element to be taken + * out of the stream, i.e., Smack behaves like that element was never received. + *

+ *

+ * If the parsing exception is because Smack received illegal input, then please consider informing the authors of the + * originating entity about that. If it was thrown because of an bug in a Smack parser, then please consider filling a + * bug with Smack. + *

+ *

Managing the parsing exception callback

+ *

+ * The "fail-hard per default" behavior is achieved by using the + * {@link org.jivesoftware.smack.parsing.ExceptionThrowingCallbackWithHint} as default parsing exception callback. You + * can change the behavior using {@link #setParsingExceptionCallback(ParsingExceptionCallback)} to set a new callback. + * Use {@link org.jivesoftware.smack.SmackConfiguration#setDefaultParsingExceptionCallback(ParsingExceptionCallback)} to + * set the default callback. + *

+ */ public abstract class AbstractXMPPConnection implements XMPPConnection { private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName()); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java index 4b99bc20f..01f2995a4 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -29,7 +29,7 @@ import javax.net.ssl.HostnameVerifier; import org.jivesoftware.smack.compression.XMPPInputOutputStream; import org.jivesoftware.smack.debugger.ReflectionDebuggerFactory; import org.jivesoftware.smack.debugger.SmackDebuggerFactory; -import org.jivesoftware.smack.parsing.ExceptionThrowingCallback; +import org.jivesoftware.smack.parsing.ExceptionThrowingCallbackWithHint; import org.jivesoftware.smack.parsing.ParsingExceptionCallback; import org.jivesoftware.smack.util.Objects; @@ -80,7 +80,7 @@ public final class SmackConfiguration { * The default parsing exception callback is {@link ExceptionThrowingCallback} which will * throw an exception and therefore disconnect the active connection. */ - private static ParsingExceptionCallback defaultCallback = new ExceptionThrowingCallback(); + private static ParsingExceptionCallback defaultCallback = new ExceptionThrowingCallbackWithHint(); private static HostnameVerifier defaultHostnameVerififer; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallbackWithHint.java b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallbackWithHint.java new file mode 100644 index 000000000..299b21242 --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallbackWithHint.java @@ -0,0 +1,43 @@ +/** + * + * Copyright 2018 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.parsing; + +import java.util.logging.Logger; + +import org.jivesoftware.smack.UnparseableStanza; + +/** + * Like {@link ExceptionThrowingCallback} but additionally logs a warning message. + * + * @author Florian Schmaus + * + */ +public class ExceptionThrowingCallbackWithHint extends ExceptionThrowingCallback { + + private static final Logger LOGGER = Logger.getLogger(ExceptionThrowingCallbackWithHint.class.getName()); + + @Override + public void handleUnparsableStanza(UnparseableStanza packetData) throws Exception { + LOGGER.warning("Parsing exception encountered." + + " This exception will be re-thrown, leading to a disconnect." + + " You can change this behavior by setting a different ParsingExceptionCallback using setParsingExceptionCallback()." + + " More information an be found in AbstractXMPPConnection's javadoc."); + + super.handleUnparsableStanza(packetData); + } +} From 5a7e656898f2a32a57660ba15dec41dd50dd4921 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 2 Aug 2018 12:55:51 +0200 Subject: [PATCH 6/8] Bump JXMPP to 0.6.3 --- version.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.gradle b/version.gradle index f71298a5e..6ee5d1766 100644 --- a/version.gradle +++ b/version.gradle @@ -2,7 +2,7 @@ allprojects { ext { shortVersion = '4.3.0-rc2' isSnapshot = true - jxmppVersion = '0.6.2' + jxmppVersion = '0.6.3' miniDnsVersion = '0.3.0' smackMinAndroidSdk = 9 } From 4b5708603f8b1a425a16b2cd1e14295a082d0fcc Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 2 Aug 2018 12:56:32 +0200 Subject: [PATCH 7/8] Bump MiniDNS to 0.3.2 --- version.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.gradle b/version.gradle index 6ee5d1766..e7a7d2ba0 100644 --- a/version.gradle +++ b/version.gradle @@ -3,7 +3,7 @@ allprojects { shortVersion = '4.3.0-rc2' isSnapshot = true jxmppVersion = '0.6.3' - miniDnsVersion = '0.3.0' + miniDnsVersion = '0.3.2' smackMinAndroidSdk = 9 } } From 14f4f8eed97d60335b6c16d5e06eda8f8b7b7f75 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 2 Aug 2018 15:29:59 +0200 Subject: [PATCH 8/8] Smack 4.3.0 --- resources/releasedocs/changelog.html | 38 ++++++++++++++++++++++++++++ version.gradle | 4 +-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/resources/releasedocs/changelog.html b/resources/releasedocs/changelog.html index 5d87462d0..4d51e4594 100644 --- a/resources/releasedocs/changelog.html +++ b/resources/releasedocs/changelog.html @@ -141,6 +141,44 @@ hr {
+

4.3.0 -- 2018-08-02

+ +

Bug +

+
    +
  • [SMACK-759] - PubSubManager.getLeafNode() throws PubSubAssertionError.DiscoInfoNodeAssertionError if node exists but its not a PubSub Node +
  • +
  • [SMACK-814] - NPE when using Node.getAffiliationsAsOwner() +
  • +
  • [SMACK-815] - XEP-0184: DeliveryReceipt requires ID, although the XEP defines it as optional attribute +
  • +
  • [SMACK-818] - EntityCapsManager sends presences with multiple CapsExtension causing disco#info lookup to fail +
  • +
  • [SMACK-819] - ConcurrentModification Exception in MultiUserChatManager.java +
  • +
  • [SMACK-820] - DNSUtil.setDaneProvider() does not set the DANE provider +
  • +
+ +

Task +

+
    +
  • [SMACK-769] - Rename XMPPError to StanzaError +
  • +
  • [SMACK-776] - Remove deprecated reconnection callbacks in ConnectionListener +
  • +
+ +

Improvement +

+
    +
  • [SMACK-761] - Adopt ChatStateManager to new Chat API (chat2) +
  • +
  • [SMACK-812] - Enable ModifierOrder checkstyle check +
  • +
  • [SMACK-816] - SimplePayload should infer the XML element name and namespace +
  • +

4.2.4 -- 2018-04-15

diff --git a/version.gradle b/version.gradle index e7a7d2ba0..1cca66abe 100644 --- a/version.gradle +++ b/version.gradle @@ -1,7 +1,7 @@ allprojects { ext { - shortVersion = '4.3.0-rc2' - isSnapshot = true + shortVersion = '4.3.0' + isSnapshot = false jxmppVersion = '0.6.3' miniDnsVersion = '0.3.2' smackMinAndroidSdk = 9