From 475fed8c515d4e3ad34efd601d800eacbe1604bb Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 23 Apr 2015 21:31:09 +0200 Subject: [PATCH 1/8] Fix DeliveryReceiptsManager.autoAddDeliveryReceiptRequests Must use interceptors instead of sending listeners, as those are invoked *after* the stanza has been put on the wire. Also use the correct filter, which excludes ack messages. Fixes SMACK-656. --- .../smackx/receipts/DeliveryReceiptManager.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 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 6c062b9aa..ceafde1ed 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 @@ -31,6 +31,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.NotFilter; import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.filter.StanzaExtensionFilter; import org.jivesoftware.smack.filter.StanzaTypeFilter; @@ -232,6 +233,16 @@ public class DeliveryReceiptManager extends Manager { receiptReceivedListeners.remove(listener); } + /** + * 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. + * + * @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))); + private static final StanzaListener AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER = new StanzaListener() { @Override public void processPacket(Stanza packet) throws NotConnectedException { @@ -247,8 +258,8 @@ public class DeliveryReceiptManager extends Manager { * @see #dontAutoAddDeliveryReceiptRequests() */ public void autoAddDeliveryReceiptRequests() { - connection().addPacketSendingListener(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER, - MessageTypeFilter.NORMAL_OR_CHAT_OR_HEADLINE); + connection().addPacketInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER, + MESSAGES_TO_REQUEST_RECEIPTS_FOR); } /** @@ -258,7 +269,7 @@ public class DeliveryReceiptManager extends Manager { * @see #autoAddDeliveryReceiptRequests() */ public void dontAutoAddDeliveryReceiptRequests() { - connection().removePacketSendingListener(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER); + connection().removePacketInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER); } /** From f579fb2c778220c6832f1be54c8ec80e568a0fc9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 25 Apr 2015 22:53:46 +0200 Subject: [PATCH 2/8] Throw exception if smack-java7 is loaded on Android --- .../jivesoftware/smack/util/SystemUtil.java | 28 +++++++++++++++++++ .../smack/java7/Java7SmackInitializer.java | 11 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/util/SystemUtil.java diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/SystemUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/SystemUtil.java new file mode 100644 index 000000000..a3cf17b12 --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/SystemUtil.java @@ -0,0 +1,28 @@ +/** + * + * 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. + */ +package org.jivesoftware.smack.util; + +public class SystemUtil { + + public static final String PROPERTY_JAVA_VENDOR = "java.vendor"; + + public static boolean onAndroid() { + String vendor = System.getProperty(PROPERTY_JAVA_VENDOR); + return vendor.contains("Android"); + } + +} diff --git a/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java b/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java index 482213219..60e1958e4 100644 --- a/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java +++ b/smack-java7/src/main/java/org/jivesoftware/smack/java7/Java7SmackInitializer.java @@ -1,6 +1,6 @@ /** * - * Copyright 2014 the original author or authors + * Copyright 2014-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. @@ -22,6 +22,7 @@ import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.initializer.SmackInitializer; import org.jivesoftware.smack.util.DNSUtil; import org.jivesoftware.smack.util.StringTransformer; +import org.jivesoftware.smack.util.SystemUtil; import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smack.util.stringencoder.Base64UrlSafeEncoder; import org.jivesoftware.smack.util.stringencoder.java7.Java7Base64Encoder; @@ -31,6 +32,14 @@ public class Java7SmackInitializer implements SmackInitializer { @Override public List initialize() { + if (SystemUtil.onAndroid()) { + // @formatter:off + throw new RuntimeException( + "You need to remove the smack-java7 dependency/jar from your build, " + + "as it does not run on Android. " + + "Use smack-android instead."); + // @formatter:on + } SmackConfiguration.setDefaultHostnameVerifier(new Java7HostnameVerifier()); Base64.setEncoder(Java7Base64Encoder.getInstance()); Base64UrlSafeEncoder.setEncoder(Java7Base64UrlSafeEncoder.getInstance()); From e0bc1ccaf201daf2322ba8654764cca81f26c612 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Apr 2015 07:27:38 +0200 Subject: [PATCH 3/8] Fix memory leak in RosterEntry Roster's INSTANCE map has a weak reference to XMPPConnection, which has a field of RosterEntry(ies), and RosterEntry has a strong reference to XMPPConnection resulting in a cycle which is preventing XMPPConnection from getting gc'ed. SMACK-659. --- .../java/org/jivesoftware/smack/roster/RosterEntry.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java index f9ff82a97..2a387f13b 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.SmackException.NotConnectedException; @@ -36,7 +37,7 @@ import org.jivesoftware.smack.roster.packet.RosterPacket; * * @author Matt Tucker */ -public class RosterEntry { +public final class RosterEntry extends Manager { /** * The JID of the entity/user. @@ -47,7 +48,6 @@ public class RosterEntry { private RosterPacket.ItemType type; private RosterPacket.ItemStatus status; final private Roster roster; - final private XMPPConnection connection; /** * Creates a new roster entry. @@ -60,12 +60,12 @@ public class RosterEntry { */ RosterEntry(String user, String name, RosterPacket.ItemType type, RosterPacket.ItemStatus status, Roster roster, XMPPConnection connection) { + super(connection); this.user = user; this.name = name; this.type = type; this.status = status; this.roster = roster; - this.connection = connection; } /** @@ -103,7 +103,7 @@ public class RosterEntry { RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.set); packet.addRosterItem(toRosterItem(this)); - connection.createPacketCollectorAndSend(packet).nextResultOrThrow(); + connection().createPacketCollectorAndSend(packet).nextResultOrThrow(); // We have received a result response to the IQ set, the name was successfully changed this.name = name; From a4be67ff5d4960e185ac98bec81591a733f5b47c Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Apr 2015 17:32:20 +0200 Subject: [PATCH 4/8] Fix ReconnectionManager RANDOM_INCREASING_DELAY policy which was using the same value. Fixes SMACK-660. --- .../java/org/jivesoftware/smack/ReconnectionManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java index da478fd5a..a38cd1715 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java @@ -186,10 +186,12 @@ public class ReconnectionManager { if (attempts > 13) { delay = randomBase * 6 * 5; // between 2.5 and 7.5 minutes (~5 minutes) } - if (attempts > 7) { + else if (attempts > 7) { delay = randomBase * 6; // between 30 and 90 seconds (~1 minutes) } - delay = randomBase; // 10 seconds + else { + delay = randomBase; // 10 seconds + } break; default: throw new AssertionError("Unknown reconnection policy " + reconnectionPolicy); From 4eb322608ee15c7c04aa9fb591098c3ce9fd5a44 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Apr 2015 17:51:18 +0200 Subject: [PATCH 5/8] Add ConnectionConfiguration.setProxyInfo(ProxyInfo) Fixes SMACK-661. --- .../jivesoftware/smack/ConnectionConfiguration.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index 125c691ed..94157271f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -614,6 +614,17 @@ public abstract class ConnectionConfiguration { return getThis(); } + /** + * Set the information about the Proxy used for the connection. + * + * @param proxyInfo the Proxy information. + * @return a reference to this builder. + */ + public B setProxyInfo(ProxyInfo proxyInfo) { + this.proxy = proxyInfo; + return getThis(); + } + /** * Allow null or the empty String as username. * From 65dd6c9777fa56eff7c983d2860b2ed6f2dfb8d9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 30 Apr 2015 11:43:54 +0200 Subject: [PATCH 6/8] Fix RosterEntry.setNames(String) also mark the method synchornized, to prevent race conditions with the name. Fixes SMACK-662. --- .../org/jivesoftware/smack/roster/RosterEntry.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java index 2a387f13b..e73fdad8d 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java @@ -94,7 +94,7 @@ public final class RosterEntry extends Manager { * @throws XMPPErrorException * @throws NoResponseException */ - public void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException { + public synchronized void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException { // Do nothing if the name hasn't changed. if (name != null && name.equals(this.name)) { return; @@ -102,7 +102,10 @@ public final class RosterEntry extends Manager { RosterPacket packet = new RosterPacket(); packet.setType(IQ.Type.set); - packet.addRosterItem(toRosterItem(this)); + + // Create a new roster item with the current RosterEntry and the *new* name. Note that we can't set the name of + // RosterEntry right away, as otherwise the updated event wont get fired, because equalsDeep would return true. + packet.addRosterItem(toRosterItem(this, name)); connection().createPacketCollectorAndSend(packet).nextResultOrThrow(); // We have received a result response to the IQ set, the name was successfully changed @@ -246,7 +249,11 @@ public final class RosterEntry extends Manager { } static RosterPacket.Item toRosterItem(RosterEntry entry) { - RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName()); + return toRosterItem(entry, entry.getName()); + } + + private static RosterPacket.Item toRosterItem(RosterEntry entry, String name) { + RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), name); item.setItemType(entry.getType()); item.setItemStatus(entry.getStatus()); // Set the correct group names for the item. From 236dfb009d21f2d37f2556443154f26d0ce82ae5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 7 May 2015 22:40:38 +0200 Subject: [PATCH 7/8] Improve logging of parsing errors --- .../java/org/jivesoftware/smack/util/PacketParserUtils.java | 4 +++- .../smackx/caps/provider/CapsExtensionProvider.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java index 6a7e8d9ab..ac5ea11b8 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java @@ -576,7 +576,9 @@ public class PacketParserUtils { try { PacketParserUtils.addExtensionElement(presence, parser, elementName, namespace); } catch (Exception e) { - LOGGER.log(Level.WARNING, "Failed to parse extension packet in Presence packet.", e); + LOGGER.log(Level.WARNING, + "Failed to parse extension packet in Presence packet. Attributes: from=" + + presence.getFrom() + " id=" + presence.getStanzaId(), e); } break; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProvider.java index 0eba8f4e2..e7efd791a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/provider/CapsExtensionProvider.java @@ -51,7 +51,8 @@ public class CapsExtensionProvider extends ExtensionElementProvider + +

4.1.1 -- 2015-05-09

+ +

Bug +

+
    +
  • [SMACK-649] - DIGEST-MD5 challenge/response parsing must handle linear white spaces after the comma +
  • +
  • [SMACK-652] - SynchronizationPoint should use signalAll +
  • +
  • [SMACK-653] - Integer overflow if both client and server don't specify a max resumption time +
  • +
  • [SMACK-654] - isSmResumptionPossible() returns wrong values +
  • +
  • [SMACK-656] - DeliveryReceipts auto add should use packet interceptors and should not be requested for messages with ACKs. +
  • +
  • [SMACK-659] - Memory leak caused by RosterEntry declaring a strong reference to XMPPConnection +
  • +
  • [SMACK-660] - ReconnectionManager's RANDOM_INCREASING_DELAY is erroneously using a fixed value. +
  • +
  • [SMACK-661] - Add method to set ProxyInfo in ConnectionConfiguration.Builder +
  • +
  • [SMACK-662] - RosterEntry.setName() does not change the name +
  • +
+

4.1.0 -- 2015-03-29

Sub-task diff --git a/version.gradle b/version.gradle index e880afb5f..7e83af347 100644 --- a/version.gradle +++ b/version.gradle @@ -1,7 +1,7 @@ allprojects { ext { shortVersion = '4.1.1' - isSnapshot = true + isSnapshot = false jxmppVersion = '0.4.2-beta1' smackMinAndroidSdk = 8 }