diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-11-25 19:19:28 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-11-25 19:20:53 (GMT) |
commit | db00adc9810377500e6ab27900b29496a0d05afe (patch) | |
tree | 0f13d821883e0e99e9b6e7f15c84e3371375cd96 /Swiften | |
parent | c198064db0a6444a24220eee65cbf747eb7fbfb0 (diff) | |
download | swift-db00adc9810377500e6ab27900b29496a0d05afe.zip swift-db00adc9810377500e6ab27900b29496a0d05afe.tar.bz2 |
Enabled stream compression again.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Client/Client.cpp | 3 | ||||
-rw-r--r-- | Swiften/Client/ClientError.h | 1 | ||||
-rw-r--r-- | Swiften/Client/ClientSession.cpp | 17 | ||||
-rw-r--r-- | Swiften/Client/ClientSession.h | 1 | ||||
-rw-r--r-- | Swiften/Client/UnitTest/ClientSessionTest.cpp | 7 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 6 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.h | 4 | ||||
-rw-r--r-- | Swiften/Session/SessionStream.h | 2 |
8 files changed, 40 insertions, 1 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index 3962281..19f7ee5 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp @@ -145,6 +145,9 @@ void Client::handleSessionFinished(boost::shared_ptr<Error> error) { case ClientSession::Error::AuthenticationFailedError: clientError = ClientError(ClientError::AuthenticationFailedError); break; + case ClientSession::Error::CompressionFailedError: + clientError = ClientError(ClientError::CompressionFailedError); + break; case ClientSession::Error::ServerVerificationFailedError: clientError = ClientError(ClientError::ServerVerificationFailedError); break; diff --git a/Swiften/Client/ClientError.h b/Swiften/Client/ClientError.h index 55c57fc..a0557d4 100644 --- a/Swiften/Client/ClientError.h +++ b/Swiften/Client/ClientError.h @@ -11,6 +11,7 @@ namespace Swift { ConnectionWriteError, XMLError, AuthenticationFailedError, + CompressionFailedError, ServerVerificationFailedError, NoSupportedAuthMechanismsError, UnexpectedElementError, diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp index 61ce8ef..8427d27 100644 --- a/Swiften/Client/ClientSession.cpp +++ b/Swiften/Client/ClientSession.cpp @@ -12,6 +12,9 @@ #include "Swiften/Elements/AuthFailure.h" #include "Swiften/Elements/AuthChallenge.h" #include "Swiften/Elements/AuthResponse.h" +#include "Swiften/Elements/Compressed.h" +#include "Swiften/Elements/CompressFailure.h" +#include "Swiften/Elements/CompressRequest.h" #include "Swiften/Elements/StartSession.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/ResourceBind.h" @@ -70,6 +73,10 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) { state = WaitingForEncrypt; stream->writeElement(boost::shared_ptr<StartTLSRequest>(new StartTLSRequest())); } + else if (streamFeatures->hasCompressionMethod("zlib")) { + state = Compressing; + stream->writeElement(boost::shared_ptr<CompressRequest>(new CompressRequest("zlib"))); + } else if (streamFeatures->hasAuthenticationMechanisms()) { if (stream->hasTLSCertificate()) { if (streamFeatures->hasAuthenticationMechanism("EXTERNAL")) { @@ -120,6 +127,16 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) { } } } + else if (boost::dynamic_pointer_cast<Compressed>(element)) { + checkState(Compressing); + state = WaitingForStreamStart; + stream->addZLibCompression(); + stream->resetXMPPParser(); + sendStreamHeader(); + } + else if (boost::dynamic_pointer_cast<CompressFailure>(element)) { + finishSession(Error::CompressionFailedError); + } else if (AuthChallenge* challenge = dynamic_cast<AuthChallenge*>(element.get())) { checkState(Authenticating); assert(authenticator); diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h index 5e5acbc..ef4d747 100644 --- a/Swiften/Client/ClientSession.h +++ b/Swiften/Client/ClientSession.h @@ -34,6 +34,7 @@ namespace Swift { struct Error : public Swift::Error { enum Type { AuthenticationFailedError, + CompressionFailedError, ServerVerificationFailedError, NoSupportedAuthMechanismsError, UnexpectedElementError, diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp index 9fe2a3d..e035ba3 100644 --- a/Swiften/Client/UnitTest/ClientSessionTest.cpp +++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp @@ -173,7 +173,7 @@ class ClientSessionTest : public CppUnit::TestFixture { bool footer; }; - MockSessionStream() : available(true), canTLSEncrypt(true), tlsEncrypted(false), whitespacePingEnabled(false), resetCount(0) { + MockSessionStream() : available(true), canTLSEncrypt(true), tlsEncrypted(false), compressed(false), whitespacePingEnabled(false), resetCount(0) { } virtual bool isAvailable() { @@ -200,6 +200,10 @@ class ClientSessionTest : public CppUnit::TestFixture { tlsEncrypted = true; } + virtual void addZLibCompression() { + compressed = true; + } + virtual void setWhitespacePingEnabled(bool enabled) { whitespacePingEnabled = enabled; } @@ -286,6 +290,7 @@ class ClientSessionTest : public CppUnit::TestFixture { bool available; bool canTLSEncrypt; bool tlsEncrypted; + bool compressed; bool whitespacePingEnabled; int resetCount; std::deque<Event> receivedEvents; diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index 0d0f49f..ed7f1eb 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -6,6 +6,7 @@ #include "Swiften/StreamStack/StreamStack.h" #include "Swiften/StreamStack/ConnectionLayer.h" #include "Swiften/StreamStack/WhitespacePingLayer.h" +#include "Swiften/StreamStack/CompressionLayer.h" #include "Swiften/StreamStack/TLSLayer.h" #include "Swiften/StreamStack/TLSLayerFactory.h" @@ -74,6 +75,11 @@ void BasicSessionStream::addTLSEncryption() { } } +void BasicSessionStream::addZLibCompression() { + boost::shared_ptr<CompressionLayer> compressionLayer(new CompressionLayer()); + streamStack->addLayer(compressionLayer); +} + void BasicSessionStream::setWhitespacePingEnabled(bool enabled) { if (enabled) { if (!whitespacePingLayer) { diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index f36df83..8618458 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h @@ -16,6 +16,7 @@ namespace Swift { class StreamStack; class XMPPLayer; class ConnectionLayer; + class CompressionLayer; class BasicSessionStream : public SessionStream, @@ -38,6 +39,8 @@ namespace Swift { virtual void writeElement(boost::shared_ptr<Element>); virtual void writeFooter(); + virtual void addZLibCompression(); + virtual bool supportsTLSEncryption(); virtual void addTLSEncryption(); @@ -65,6 +68,7 @@ namespace Swift { boost::shared_ptr<XMPPLayer> xmppLayer; boost::shared_ptr<ConnectionLayer> connectionLayer; StreamStack* streamStack; + boost::shared_ptr<CompressionLayer> compressionLayer; boost::shared_ptr<TLSLayer> tlsLayer; boost::shared_ptr<WhitespacePingLayer> whitespacePingLayer; }; diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 1252c5a..8c64ccf 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -34,6 +34,8 @@ namespace Swift { virtual void writeFooter() = 0; virtual void writeElement(boost::shared_ptr<Element>) = 0; + virtual void addZLibCompression() = 0; + virtual bool supportsTLSEncryption() = 0; virtual void addTLSEncryption() = 0; virtual void setWhitespacePingEnabled(bool enabled) = 0; |