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:
parent
002d060584
commit
bd4b91fc26
5 changed files with 20 additions and 12 deletions
|
@ -235,6 +235,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
|
||||
private XmlEnvironment incomingStreamXmlEnvironment;
|
||||
|
||||
protected XmlEnvironment outgoingStreamXmlEnvironment;
|
||||
|
||||
final Map<QName, NonzaCallback> nonzaCallbacks = new HashMap<>();
|
||||
|
||||
protected final Lock connectionLock = new ReentrantLock();
|
||||
|
@ -2017,7 +2019,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
from = XmppStringUtils.completeJidFrom(localpart, to);
|
||||
}
|
||||
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 {
|
||||
|
|
|
@ -163,6 +163,12 @@ public class XmlEnvironment {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder with(StreamOpen streamOpen) {
|
||||
withNamespace(streamOpen.getNamespace());
|
||||
withLanguage(streamOpen.getLanguage());
|
||||
return this;
|
||||
}
|
||||
|
||||
public XmlEnvironment build() {
|
||||
return new XmlEnvironment(this);
|
||||
}
|
||||
|
|
|
@ -624,14 +624,10 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
|||
* XmlStringBuilder contents.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public void write(Writer writer, String enclosingNamespace) throws IOException {
|
||||
XmlEnvironment enclosingXmlEnvironment = XmlEnvironment.builder()
|
||||
.withNamespace(enclosingNamespace)
|
||||
.build();
|
||||
appendXmlTo(writer, enclosingXmlEnvironment);
|
||||
public void write(Writer writer, XmlEnvironment enclosingXmlEnvironment) throws IOException {
|
||||
try {
|
||||
appendXmlTo(csq -> {
|
||||
try {
|
||||
|
|
|
@ -87,7 +87,6 @@ import org.jivesoftware.smack.packet.Presence;
|
|||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.StartTls;
|
||||
import org.jivesoftware.smack.packet.StreamError;
|
||||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Challenge;
|
||||
|
@ -1347,9 +1346,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
|||
}
|
||||
maybeAddToUnacknowledgedStanzas(packet);
|
||||
|
||||
CharSequence elementXml = element.toXML(StreamOpen.CLIENT_NAMESPACE);
|
||||
CharSequence elementXml = element.toXML(outgoingStreamXmlEnvironment);
|
||||
if (elementXml instanceof XmlStringBuilder) {
|
||||
((XmlStringBuilder) elementXml).write(writer, StreamOpen.CLIENT_NAMESPACE);
|
||||
((XmlStringBuilder) elementXml).write(writer, outgoingStreamXmlEnvironment);
|
||||
}
|
||||
else {
|
||||
writer.write(elementXml.toString());
|
||||
|
|
|
@ -82,7 +82,6 @@ import org.jivesoftware.smack.packet.StreamOpen;
|
|||
import org.jivesoftware.smack.packet.TlsFailure;
|
||||
import org.jivesoftware.smack.packet.TlsProceed;
|
||||
import org.jivesoftware.smack.packet.TopLevelStreamElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.sasl.SASLErrorException;
|
||||
import org.jivesoftware.smack.util.ArrayBlockingQueueWithShutdown;
|
||||
import org.jivesoftware.smack.util.Async;
|
||||
|
@ -510,7 +509,7 @@ public class XmppNioTcpConnection extends AbstractXmppNioConnection {
|
|||
CharSequence nextCharSequence = currentlyOutgonigTopLevelStreamElement.toXML(StreamOpen.CLIENT_NAMESPACE);
|
||||
if (nextCharSequence instanceof XmlStringBuilder) {
|
||||
XmlStringBuilder xmlStringBuilder = (XmlStringBuilder) nextCharSequence;
|
||||
outgoingCharSequenceIterator = xmlStringBuilder.toList(XmlEnvironment.EMPTY).iterator();
|
||||
outgoingCharSequenceIterator = xmlStringBuilder.toList(outgoingStreamXmlEnvironment).iterator();
|
||||
} else {
|
||||
outgoingCharSequenceIterator = Collections.singletonList(nextCharSequence).iterator();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue