1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-10-31 17:25:58 +01:00

Introduce AbstractXMPPConnection.outgoingStreamXmlEnvironment

This commit is contained in:
Florian Schmaus 2019-09-21 23:00:17 +02:00
parent 002d060584
commit bd4b91fc26
5 changed files with 20 additions and 12 deletions

View file

@ -235,6 +235,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
private XmlEnvironment incomingStreamXmlEnvironment; private XmlEnvironment incomingStreamXmlEnvironment;
protected XmlEnvironment outgoingStreamXmlEnvironment;
final Map<QName, NonzaCallback> nonzaCallbacks = new HashMap<>(); final Map<QName, NonzaCallback> nonzaCallbacks = new HashMap<>();
protected final Lock connectionLock = new ReentrantLock(); protected final Lock connectionLock = new ReentrantLock();
@ -2017,7 +2019,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
from = XmppStringUtils.completeJidFrom(localpart, to); from = XmppStringUtils.completeJidFrom(localpart, to);
} }
String id = getStreamId(); String id = getStreamId();
sendNonza(new StreamOpen(to, from, id, config.getXmlLang(), StreamOpen.StreamContentNamespace.client));
StreamOpen streamOpen = new StreamOpen(to, from, id, config.getXmlLang(), StreamOpen.StreamContentNamespace.client);
sendNonza(streamOpen);
XmlEnvironment.Builder xmlEnvironmentBuilder = XmlEnvironment.builder();
xmlEnvironmentBuilder.with(streamOpen);
outgoingStreamXmlEnvironment = xmlEnvironmentBuilder.build();
} }
public static final class SmackTlsContext { public static final class SmackTlsContext {

View file

@ -163,6 +163,12 @@ public class XmlEnvironment {
return this; return this;
} }
public Builder with(StreamOpen streamOpen) {
withNamespace(streamOpen.getNamespace());
withLanguage(streamOpen.getLanguage());
return this;
}
public XmlEnvironment build() { public XmlEnvironment build() {
return new XmlEnvironment(this); return new XmlEnvironment(this);
} }

View file

@ -624,14 +624,10 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
* XmlStringBuilder contents. * XmlStringBuilder contents.
* *
* @param writer TODO javadoc me please * @param writer TODO javadoc me please
* @param enclosingNamespace the enclosing XML namespace. * @param enclosingXmlEnvironment the enclosing XML environment.
* @throws IOException if an I/O error occured. * @throws IOException if an I/O error occured.
*/ */
public void write(Writer writer, String enclosingNamespace) throws IOException { public void write(Writer writer, XmlEnvironment enclosingXmlEnvironment) throws IOException {
XmlEnvironment enclosingXmlEnvironment = XmlEnvironment.builder()
.withNamespace(enclosingNamespace)
.build();
appendXmlTo(writer, enclosingXmlEnvironment);
try { try {
appendXmlTo(csq -> { appendXmlTo(csq -> {
try { try {

View file

@ -87,7 +87,6 @@ import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StartTls; import org.jivesoftware.smack.packet.StartTls;
import org.jivesoftware.smack.packet.StreamError; import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.proxy.ProxyInfo; import org.jivesoftware.smack.proxy.ProxyInfo;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements; import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Challenge; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Challenge;
@ -1347,9 +1346,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
} }
maybeAddToUnacknowledgedStanzas(packet); maybeAddToUnacknowledgedStanzas(packet);
CharSequence elementXml = element.toXML(StreamOpen.CLIENT_NAMESPACE); CharSequence elementXml = element.toXML(outgoingStreamXmlEnvironment);
if (elementXml instanceof XmlStringBuilder) { if (elementXml instanceof XmlStringBuilder) {
((XmlStringBuilder) elementXml).write(writer, StreamOpen.CLIENT_NAMESPACE); ((XmlStringBuilder) elementXml).write(writer, outgoingStreamXmlEnvironment);
} }
else { else {
writer.write(elementXml.toString()); writer.write(elementXml.toString());

View file

@ -82,7 +82,6 @@ import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.packet.TlsFailure; import org.jivesoftware.smack.packet.TlsFailure;
import org.jivesoftware.smack.packet.TlsProceed; import org.jivesoftware.smack.packet.TlsProceed;
import org.jivesoftware.smack.packet.TopLevelStreamElement; import org.jivesoftware.smack.packet.TopLevelStreamElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.sasl.SASLErrorException; import org.jivesoftware.smack.sasl.SASLErrorException;
import org.jivesoftware.smack.util.ArrayBlockingQueueWithShutdown; import org.jivesoftware.smack.util.ArrayBlockingQueueWithShutdown;
import org.jivesoftware.smack.util.Async; import org.jivesoftware.smack.util.Async;
@ -510,7 +509,7 @@ public class XmppNioTcpConnection extends AbstractXmppNioConnection {
CharSequence nextCharSequence = currentlyOutgonigTopLevelStreamElement.toXML(StreamOpen.CLIENT_NAMESPACE); CharSequence nextCharSequence = currentlyOutgonigTopLevelStreamElement.toXML(StreamOpen.CLIENT_NAMESPACE);
if (nextCharSequence instanceof XmlStringBuilder) { if (nextCharSequence instanceof XmlStringBuilder) {
XmlStringBuilder xmlStringBuilder = (XmlStringBuilder) nextCharSequence; XmlStringBuilder xmlStringBuilder = (XmlStringBuilder) nextCharSequence;
outgoingCharSequenceIterator = xmlStringBuilder.toList(XmlEnvironment.EMPTY).iterator(); outgoingCharSequenceIterator = xmlStringBuilder.toList(outgoingStreamXmlEnvironment).iterator();
} else { } else {
outgoingCharSequenceIterator = Collections.singletonList(nextCharSequence).iterator(); outgoingCharSequenceIterator = Collections.singletonList(nextCharSequence).iterator();
} }