From a137944e5010acb67050b58a9a92c831420464a7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 22 May 2020 15:38:16 +0200 Subject: [PATCH] [disco/caps] Fix DiscoverInfo.asBuilder() The method would not copy the extensions elements, which would lead to a false calculation of the caps hash by EntityCapsManager. --- .../org/jivesoftware/smack/packet/AbstractIqBuilder.java | 6 +++++- .../main/java/org/jivesoftware/smack/packet/IqBuilder.java | 6 +++++- .../org/jivesoftware/smackx/caps/EntityCapsManager.java | 2 +- .../org/jivesoftware/smackx/disco/packet/DiscoverInfo.java | 4 ++-- .../smackx/disco/packet/DiscoverInfoBuilder.java | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractIqBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractIqBuilder.java index d975db0ef..5eac12435 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractIqBuilder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractIqBuilder.java @@ -1,6 +1,6 @@ /** * - * Copyright 2019 Florian Schmaus + * Copyright 2019-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. @@ -23,6 +23,10 @@ public abstract class AbstractIqBuilder> extend protected IQ.Type type = IQ.Type.get; + AbstractIqBuilder(IQ other, String stanzaId) { + super(other, stanzaId); + } + AbstractIqBuilder(AbstractIqBuilder other) { super(other); type = other.type; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/IqBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/IqBuilder.java index 2e24f53b2..644f077ea 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/IqBuilder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/IqBuilder.java @@ -1,6 +1,6 @@ /** * - * Copyright 2019 Florian Schmaus + * Copyright 2019-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. @@ -22,6 +22,10 @@ import org.jivesoftware.smack.util.Objects; public abstract class IqBuilder, I extends IQ> extends AbstractIqBuilder { + protected IqBuilder(IQ other, String stanzaId) { + super(other, stanzaId); + } + protected IqBuilder(AbstractIqBuilder other) { super(other); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index 5352c85cc..a83c24875 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -496,7 +496,7 @@ public final class EntityCapsManager extends Manager { private void updateLocalEntityCaps(DiscoverInfo synthesizedDiscoveryInfo) { XMPPConnection connection = connection(); - DiscoverInfoBuilder discoverInfoBuilder = synthesizedDiscoveryInfo.asBuilder(); + DiscoverInfoBuilder discoverInfoBuilder = synthesizedDiscoveryInfo.asBuilder("synthesized-disco-info-result"); // getLocalNodeVer() will return a result only after currentCapsVersion is set. Therefore // set it first and then call getLocalNodeVer() currentCapsVersion = generateVerificationString(discoverInfoBuilder); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java index 796e51857..7de48f1be 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java @@ -299,8 +299,8 @@ public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable return containsDuplicateFeatures; } - public DiscoverInfoBuilder asBuilder() { - return new DiscoverInfoBuilder(this); + public DiscoverInfoBuilder asBuilder(String stanzaId) { + return new DiscoverInfoBuilder(this, stanzaId); } // TODO: Deprecate in favor of asBuilder(). diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfoBuilder.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfoBuilder.java index 66f965de4..b8e179c70 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfoBuilder.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfoBuilder.java @@ -1,6 +1,6 @@ /** * - * Copyright 2019 Florian Schmaus + * Copyright 2019-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. @@ -48,8 +48,8 @@ public class DiscoverInfoBuilder extends IqBuilder