From f892ba136901f416aad6587bc2f806c7694944c4 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 26 Aug 2020 11:38:24 +0200 Subject: [PATCH] [core] Get stream-open-like element from transport When sending a stream-open-like element, it depends on the actual used transport which element is send. For example, RFC6120-style TCP uses , whereas the Websocket binding for XMPP uses . --- .../org/jivesoftware/smack/AbstractXMPPConnection.java | 9 +++++++-- .../smack/c2s/ModularXmppClientToServerConnection.java | 6 ++++++ .../java/org/jivesoftware/smack/packet/StreamOpen.java | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) 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 377d53c0c..a421d6cd1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -2229,7 +2229,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } } - protected void sendStreamOpen() throws NotConnectedException, InterruptedException { + protected final void sendStreamOpen() throws NotConnectedException, InterruptedException { // If possible, provide the receiving entity of the stream open tag, i.e. the server, as much information as // possible. The 'to' attribute is *always* available. The 'from' attribute if set by the user and no external // mechanism is used to determine the local entity (user). And the 'id' attribute is available after the first @@ -2241,12 +2241,17 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { from = XmppStringUtils.completeJidFrom(localpart, to); } String id = getStreamId(); + String lang = config.getXmlLang(); - StreamOpen streamOpen = new StreamOpen(to, from, id, config.getXmlLang(), StreamOpen.StreamContentNamespace.client); + AbstractStreamOpen streamOpen = getStreamOpen(to, from, id, lang); sendNonza(streamOpen); updateOutgoingStreamXmlEnvironmentOnStreamOpen(streamOpen); } + protected AbstractStreamOpen getStreamOpen(CharSequence to, CharSequence from, String id, String lang) { + return new StreamOpen(to, from, id, lang); + } + protected void updateOutgoingStreamXmlEnvironmentOnStreamOpen(AbstractStreamOpen streamOpen) { XmlEnvironment.Builder xmlEnvironmentBuilder = XmlEnvironment.builder(); xmlEnvironmentBuilder.with(streamOpen); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java index e404795db..191dd32e4 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/c2s/ModularXmppClientToServerConnection.java @@ -560,6 +560,12 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne waitForConditionOrThrowConnectionException(() -> featuresReceived, waitFor); } + @Override + protected AbstractStreamOpen getStreamOpen(CharSequence to, CharSequence from, String id, String lang) { + StreamOpenAndCloseFactory streamOpenAndCloseFactory = activeTransport.getStreamOpenAndCloseFactory(); + return streamOpenAndCloseFactory.createStreamOpen(to, from, id, lang); + } + protected void newStreamOpenWaitForFeaturesSequence(String waitFor) throws InterruptedException, SmackException, XMPPException { prepareToWaitForFeaturesReceived(); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamOpen.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamOpen.java index f4b59db4b..959adc1fa 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamOpen.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/StreamOpen.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014-2019 Florian Schmaus + * Copyright © 2014-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. @@ -33,6 +33,10 @@ public final class StreamOpen extends AbstractStreamOpen { this(to, from, id, "en", StreamContentNamespace.client); } + public StreamOpen(CharSequence to, CharSequence from, String id, String lang) { + super(to, from, id, lang); + } + public StreamOpen(CharSequence to, CharSequence from, String id, String lang, StreamContentNamespace ns) { super(to, from, id, lang, ns); }