From e0bd1d168c6937201f4076db0db8b9a6b436c204 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 4 Sep 2022 09:28:00 +0200 Subject: [PATCH] do not attempt resume when already in smacks session --- .../siacs/conversations/utils/XmlHelper.java | 47 ++++++++++--------- .../conversations/xmpp/XmppConnection.java | 14 +++--- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/XmlHelper.java b/src/main/java/eu/siacs/conversations/utils/XmlHelper.java index 4964bd5ef..7287297e3 100644 --- a/src/main/java/eu/siacs/conversations/utils/XmlHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/XmlHelper.java @@ -1,30 +1,31 @@ package eu.siacs.conversations.utils; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + +import java.util.Collections; +import java.util.List; + import eu.siacs.conversations.xml.Element; public class XmlHelper { - public static String encodeEntities(String content) { - content = content.replace("&", "&"); - content = content.replace("<", "<"); - content = content.replace(">", ">"); - content = content.replace("\"", """); - content = content.replace("'", "'"); - content = content.replaceAll("[\\p{Cntrl}&&[^\n\t\r]]", ""); - return content; - } + public static String encodeEntities(String content) { + content = content.replace("&", "&"); + content = content.replace("<", "<"); + content = content.replace(">", ">"); + content = content.replace("\"", """); + content = content.replace("'", "'"); + content = content.replaceAll("[\\p{Cntrl}&&[^\n\t\r]]", ""); + return content; + } - public static String printElementNames(final Element element) { - final StringBuilder builder = new StringBuilder(); - builder.append('['); - if (element != null) { - for (Element child : element.getChildren()) { - if (builder.length() != 1) { - builder.append(','); - } - builder.append(child.getName()); - } - } - builder.append(']'); - return builder.toString(); - } + public static String printElementNames(final Element element) { + final List features = + element == null + ? Collections.emptyList() + : Lists.transform( + element.getChildren(), + child -> child != null ? child.getName() : null); + return Joiner.on(", ").join(features); + } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 525151d62..64ffa4e12 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -817,7 +817,7 @@ public class XmppConnection implements Runnable { this.stanzasReceived = 0; this.inSmacksSession = true; final RequestPacket r = new RequestPacket(); - // tagWriter.writeStanzaAsync(r); + tagWriter.writeStanzaAsync(r); } private void processResumed(final Element resumed) throws StateChangingException { @@ -1180,7 +1180,8 @@ public class XmppConnection implements Runnable { && isSecure) { authenticate(SaslMechanism.Version.SASL); } else if (this.streamFeatures.hasChild("sm", Namespace.STREAM_MANAGEMENT) - && streamId != null) { + && streamId != null + && !inSmacksSession) { if (Config.EXTENDED_SM_LOGGING) { Log.d( Config.LOGTAG, @@ -1208,7 +1209,7 @@ public class XmppConnection implements Runnable { Config.LOGTAG, account.getJid().asBareJid() + ": received NOP stream features " - + this.streamFeatures); + + XmlHelper.printElementNames(this.streamFeatures)); } } @@ -1295,7 +1296,6 @@ public class XmppConnection implements Runnable { + "/" + saslMechanism.getMechanism()); authenticate.setAttribute("mechanism", saslMechanism.getMechanism()); - Log.d(Config.LOGTAG, "authenticate " + authenticate); tagWriter.writeElement(authenticate); } @@ -1310,7 +1310,7 @@ public class XmppConnection implements Runnable { features.addChild("enable", Namespace.CARBONS); } if (bindFeatures.contains(Namespace.STREAM_MANAGEMENT)) { - features.addChild("enable", Namespace.STREAM_MANAGEMENT); + features.addChild(new EnablePacket()); } return bind; } @@ -2365,8 +2365,8 @@ public class XmppConnection implements Runnable { private boolean hasDiscoFeature(final Jid server, final String feature) { synchronized (XmppConnection.this.disco) { - return connection.disco.containsKey(server) - && connection.disco.get(server).getFeatures().contains(feature); + final ServiceDiscoveryResult sdr = connection.disco.get(server); + return sdr != null && sdr.getFeatures().contains(feature); } }