From 6739b74ff939544141620f955192796996928d78 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 22 Nov 2015 22:44:57 +0100 Subject: [PATCH 1/8] Smack 4.1.6-SNAPSHOT --- version.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.gradle b/version.gradle index dfb8ec0b5..853ef0f98 100644 --- a/version.gradle +++ b/version.gradle @@ -1,7 +1,7 @@ allprojects { ext { - shortVersion = '4.1.5' - isSnapshot = false + shortVersion = '4.1.6' + isSnapshot = true jxmppVersion = '0.4.2' smackMinAndroidSdk = 8 } From 3c74ef2fd2d279ab061e2b760de7006a528dc997 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 3 Dec 2015 08:17:19 +0100 Subject: [PATCH 2/8] Fix PubSub Affiliation getElementName() must return 'affiliation', not 'subscription'. Fixes SMACK-705. --- .../main/java/org/jivesoftware/smackx/pubsub/Affiliation.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java index 8686dab6d..818bfe92b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java @@ -31,6 +31,8 @@ import org.jivesoftware.smack.packet.ExtensionElement; */ public class Affiliation implements ExtensionElement { + public static final String ELEMENT = "affiliation"; + protected String node; protected Type type; @@ -63,7 +65,7 @@ public class Affiliation implements ExtensionElement public String getElementName() { - return "subscription"; + return ELEMENT; } public String getNamespace() From 352e4225628eb895d1ec8f3d12b1e5124c03d7a5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 3 Dec 2015 13:30:44 +0100 Subject: [PATCH 3/8] Drop SM state *before* binding the resource as otherwise and may be duplicated on reconnect. Fixes SMACK-706. --- .../org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index cd4e320c6..20d9e4495 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -399,8 +399,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { LOGGER.fine("Stream resumption failed, continuing with normal stream establishment process"); } - bindResourceAndEstablishSession(resource); - List previouslyUnackedStanzas = new LinkedList(); if (unacknowledgedStanzas != null) { // There was a previous connection with SM enabled but that was either not resumable or @@ -413,6 +411,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // after the 'enable' stream element has been sent. dropSmState(); } + + // Now bind the resource. It is important to do this *after* we dropped an eventually + // existing Stream Management state. As otherwise and may end up in + // unacknowledgedStanzas and become duplicated on reconnect. See SMACK-706. + bindResourceAndEstablishSession(resource); + if (isSmAvailable() && useSm) { // Remove what is maybe left from previously stream managed sessions serverHandledStanzasCount = 0; From f34f37a20c0ca80c03367bf0551d04f019ab330e Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 10 Dec 2015 17:10:49 +0100 Subject: [PATCH 4/8] Check for 'null' to avoid NPE in Socks5Proxy Check if serverSocket is null before calling isClosed(), as otherwise the resulting NPE will cause an endless loop. Thanks to Michael Grafl for reporting. Fixes SMACK-707. --- .../org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java index 152922300..370c1c0cf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java @@ -387,7 +387,7 @@ public class Socks5Proxy { try { - if (Socks5Proxy.this.serverSocket.isClosed() + if (Socks5Proxy.this.serverSocket == null || Socks5Proxy.this.serverSocket.isClosed() || Thread.currentThread().isInterrupted()) { return; } From 09364e571cb660d42a37ffd60f4c07a0be1018ed Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 13 Dec 2015 22:41:58 +0100 Subject: [PATCH 5/8] Ensure that delivery receipts/requests have ID set Fixes SMACK-708. --- .../smackx/receipts/DeliveryReceipt.java | 5 +++-- .../receipts/DeliveryReceiptManager.java | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java index 87169dbe0..4b8dee7f2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceipt.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013-2014 the original author or authors + * Copyright 2013-2015 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import java.util.Map; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.provider.EmbeddedExtensionProvider; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.XmlStringBuilder; /** @@ -42,7 +43,7 @@ public class DeliveryReceipt implements ExtensionElement public DeliveryReceipt(String id) { - this.id = id; + this.id = StringUtils.requireNotNullOrEmpty(id, "id must not be null"); } public String getId() diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index ceafde1ed..82dbd490f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -20,6 +20,7 @@ import java.util.Map; import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArraySet; +import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NotConnectedException; @@ -38,6 +39,7 @@ import org.jivesoftware.smack.filter.StanzaTypeFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.roster.Roster; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; /** @@ -73,6 +75,8 @@ public class DeliveryReceiptManager extends Manager { private static final StanzaFilter MESSAGES_WITH_DELIVERY_RECEIPT = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE)); + private static final Logger LOGGER = Logger.getLogger(DeliveryReceiptManager.class.getName()); + private static Map instances = new WeakHashMap(); static { @@ -159,6 +163,11 @@ public class DeliveryReceiptManager extends Manager { final Message messageWithReceiptRequest = (Message) packet; Message ack = receiptMessageFor(messageWithReceiptRequest); + if (ack == null) { + LOGGER.warning("Received message stanza with receipt request from '" + from + + "' without a stanza ID set. Message: " + messageWithReceiptRequest); + return; + } connection.sendStanza(ack); } }, MESSAGES_WITH_DEVLIERY_RECEIPT_REQUEST); @@ -300,14 +309,21 @@ public class DeliveryReceiptManager extends Manager { /** * Create and return a new message including a delivery receipt extension for the given message. + *

+ * If {@code messageWithReceiptRequest} does not have a Stanza ID set, then {@code null} will be returned. + *

* * @param messageWithReceiptRequest the given message with a receipt request extension. - * @return a new message with a receipt. + * @return a new message with a receipt or null. * @since 4.1 */ public static Message receiptMessageFor(Message messageWithReceiptRequest) { + String stanzaId = messageWithReceiptRequest.getStanzaId(); + if (StringUtils.isNullOrEmpty(stanzaId)) { + return null; + } Message message = new Message(messageWithReceiptRequest.getFrom(), messageWithReceiptRequest.getType()); - message.addExtension(new DeliveryReceipt(messageWithReceiptRequest.getStanzaId())); + message.addExtension(new DeliveryReceipt(stanzaId)); return message; } } From 72c7137ff15374a5307fcb0ae89b2be85474aef8 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 14 Dec 2015 11:34:18 +0100 Subject: [PATCH 6/8] Don't request receipts for messages without a body SMACK-709 --- .../smackx/receipts/DeliveryReceiptManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index 82dbd490f..67888eb7b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -32,6 +32,7 @@ import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.MessageTypeFilter; +import org.jivesoftware.smack.filter.MessageWithBodiesFilter; import org.jivesoftware.smack.filter.NotFilter; import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.filter.StanzaExtensionFilter; @@ -244,13 +245,17 @@ public class DeliveryReceiptManager extends Manager { /** * A filter for stanzas to request delivery receipts for. Notably those are message stanzas of type normal, chat or - * headline, which do notcontain a delivery receipt, i.e. are ack messages. + * headline, which do notcontain a delivery receipt, i.e. are ack messages, and have a body extension. * * @see XEP-184 § 5.4 Ack Messages */ private static final StanzaFilter MESSAGES_TO_REQUEST_RECEIPTS_FOR = new AndFilter( - MessageTypeFilter.NORMAL_OR_CHAT_OR_HEADLINE, new NotFilter(new StanzaExtensionFilter( - DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE))); + // @formatter:off + MessageTypeFilter.NORMAL_OR_CHAT_OR_HEADLINE, + new NotFilter(new StanzaExtensionFilter(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE)), + MessageWithBodiesFilter.INSTANCE + ); + // @formatter:on private static final StanzaListener AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER = new StanzaListener() { @Override @@ -261,7 +266,9 @@ public class DeliveryReceiptManager extends Manager { }; /** - * Enables automatic requests of delivery receipts for outgoing messages of type 'normal', 'chat' or 'headline. + * Enables automatic requests of delivery receipts for outgoing messages of + * {@link Message.Type#normal}, {@link Message.Type#chat} or {@link Message.Type#headline}, and + * with a {@link Message.Body} extension. * * @since 4.1 * @see #dontAutoAddDeliveryReceiptRequests() From 8650a07228991c8c7f8baa25cc71311fbdfe58a0 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 19 Dec 2015 20:15:23 +0100 Subject: [PATCH 7/8] Quote backslash in provided DIGEST-MD5 implementation Fixes SMACK-710. --- .../sasl/provided/SASLDigestMD5Mechanism.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java b/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java index 1c0a8370a..4f5e43837 100644 --- a/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java +++ b/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Mechanism.java @@ -141,7 +141,7 @@ public class SASLDigestMD5Mechanism extends SASLMechanism { String responseValue = calcResponse(DigestType.ClientResponse); // @formatter:off // See RFC 2831 2.1.2 digest-response - String saslString = "username=\"" + authenticationId + '"' + String saslString = "username=\"" + quoteBackslash(authenticationId) + '"' + ",realm=\"" + serviceName + '"' + ",nonce=\"" + nonce + '"' + ",cnonce=\"" + cnonce + '"' @@ -216,4 +216,18 @@ public class SASLDigestMD5Mechanism extends SASLMechanism { return responseValue; } + /** + * Quote the backslash in the given String. Replaces all occurrences of "\" with "\\". + *

+ * According to RFC 2831 § 7.2 a quoted-string consists either of qdtext or quoted-pair. And since quoted-pair is a + * backslash followed by a char, every backslash in qdtext must be quoted, since it otherwise would be treated as + * qdtext. + *

+ * + * @param string the input string. + * @return the input string where the every backslash is quoted. + */ + public static String quoteBackslash(String string) { + return string.replace("\\", "\\\\"); + } } From 73c531f8414a6fa65e650ab0159d937ae52f0840 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 23 Jan 2016 12:12:38 +0100 Subject: [PATCH 8/8] Smack 4.1.6 --- resources/releasedocs/changelog.html | 19 +++++++++++++++++++ version.gradle | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/resources/releasedocs/changelog.html b/resources/releasedocs/changelog.html index 7ffbe2f85..7e189a858 100644 --- a/resources/releasedocs/changelog.html +++ b/resources/releasedocs/changelog.html @@ -141,6 +141,25 @@ hr {
+

4.1.6 -- 2016-01-23

+ +

Bug +

+
    +
  • [SMACK-705] - PubSub's Affiliation.getElementName() returns wrong name +
  • +
  • [SMACK-706] - Smack may sends <bind/> and <session/> twice if Stream Management is used and a previous SM state exists +
  • +
  • [SMACK-707] - Infinite loop of NullPointerExceptions in Socks5Proxy +
  • +
  • [SMACK-708] - DeliveryReceipt(Manager) should ensure that receipts (and requests) have an ID set +
  • +
  • [SMACK-709] - Don't request delivery receipts for messages without a body +
  • +
  • [SMACK-710] - SASL DIGEST-MD5 backslash must be quoted +
  • +
+

4.1.5 -- 2015-11-22

Bug diff --git a/version.gradle b/version.gradle index 853ef0f98..96c20e1b8 100644 --- a/version.gradle +++ b/version.gradle @@ -1,7 +1,7 @@ allprojects { ext { shortVersion = '4.1.6' - isSnapshot = true + isSnapshot = false jxmppVersion = '0.4.2' smackMinAndroidSdk = 8 }