summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-25 19:19:28 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-25 19:20:53 (GMT)
commitdb00adc9810377500e6ab27900b29496a0d05afe (patch)
tree0f13d821883e0e99e9b6e7f15c84e3371375cd96 /Swiften
parentc198064db0a6444a24220eee65cbf747eb7fbfb0 (diff)
downloadswift-db00adc9810377500e6ab27900b29496a0d05afe.zip
swift-db00adc9810377500e6ab27900b29496a0d05afe.tar.bz2
Enabled stream compression again.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Client/Client.cpp3
-rw-r--r--Swiften/Client/ClientError.h1
-rw-r--r--Swiften/Client/ClientSession.cpp17
-rw-r--r--Swiften/Client/ClientSession.h1
-rw-r--r--Swiften/Client/UnitTest/ClientSessionTest.cpp7
-rw-r--r--Swiften/Session/BasicSessionStream.cpp6
-rw-r--r--Swiften/Session/BasicSessionStream.h4
-rw-r--r--Swiften/Session/SessionStream.h2
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
@@ -142,12 +142,15 @@ void Client::handleSessionFinished(boost::shared_ptr<Error> error) {
ClientError clientError;
if (boost::shared_ptr<ClientSession::Error> actualError = boost::dynamic_pointer_cast<ClientSession::Error>(error)) {
switch(actualError->type) {
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;
case ClientSession::Error::NoSupportedAuthMechanismsError:
clientError = ClientError(ClientError::NoSupportedAuthMechanismsError);
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
@@ -8,12 +8,13 @@ namespace Swift {
DomainNameResolveError,
ConnectionError,
ConnectionReadError,
ConnectionWriteError,
XMLError,
AuthenticationFailedError,
+ CompressionFailedError,
ServerVerificationFailedError,
NoSupportedAuthMechanismsError,
UnexpectedElementError,
ResourceBindError,
SessionStartError,
TLSError,
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
@@ -9,12 +9,15 @@
#include "Swiften/Elements/TLSProceed.h"
#include "Swiften/Elements/AuthRequest.h"
#include "Swiften/Elements/AuthSuccess.h"
#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"
#include "Swiften/SASL/PLAINClientAuthenticator.h"
#include "Swiften/SASL/SCRAMSHA1ClientAuthenticator.h"
#include "Swiften/Session/SessionStream.h"
@@ -67,12 +70,16 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
}
if (streamFeatures->hasStartTLS() && stream->supportsTLSEncryption()) {
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")) {
state = Authenticating;
stream->writeElement(boost::shared_ptr<Element>(new AuthRequest("EXTERNAL", "")));
}
@@ -117,12 +124,22 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
else {
state = Initialized;
onInitialized();
}
}
}
+ 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);
if (authenticator->setChallenge(challenge->getValue())) {
stream->writeElement(boost::shared_ptr<AuthResponse>(new AuthResponse(authenticator->getResponse())));
}
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
@@ -31,12 +31,13 @@ namespace Swift {
Finished
};
struct Error : public Swift::Error {
enum Type {
AuthenticationFailedError,
+ CompressionFailedError,
ServerVerificationFailedError,
NoSupportedAuthMechanismsError,
UnexpectedElementError,
ResourceBindError,
SessionStartError,
TLSClientCertificateError,
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
@@ -170,13 +170,13 @@ class ClientSessionTest : public CppUnit::TestFixture {
boost::shared_ptr<Element> element;
boost::optional<ProtocolHeader> header;
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() {
return available;
}
@@ -197,12 +197,16 @@ class ClientSessionTest : public CppUnit::TestFixture {
}
virtual void addTLSEncryption() {
tlsEncrypted = true;
}
+ virtual void addZLibCompression() {
+ compressed = true;
+ }
+
virtual void setWhitespacePingEnabled(bool enabled) {
whitespacePingEnabled = enabled;
}
virtual void resetXMPPParser() {
resetCount++;
@@ -283,12 +287,13 @@ class ClientSessionTest : public CppUnit::TestFixture {
return event;
}
bool available;
bool canTLSEncrypt;
bool tlsEncrypted;
+ bool compressed;
bool whitespacePingEnabled;
int resetCount;
std::deque<Event> receivedEvents;
};
boost::shared_ptr<MockSessionStream> server;
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
@@ -3,12 +3,13 @@
#include <boost/bind.hpp>
#include "Swiften/StreamStack/XMPPLayer.h"
#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"
namespace Swift {
BasicSessionStream::BasicSessionStream(boost::shared_ptr<Connection> connection, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, TLSLayerFactory* tlsLayerFactory, TimerFactory* timerFactory) : available(false), connection(connection), payloadParserFactories(payloadParserFactories), payloadSerializers(payloadSerializers), tlsLayerFactory(tlsLayerFactory), timerFactory(timerFactory) {
@@ -71,12 +72,17 @@ void BasicSessionStream::addTLSEncryption() {
tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, shared_from_this()));
tlsLayer->onConnected.connect(boost::bind(&BasicSessionStream::handleTLSConnected, shared_from_this()));
tlsLayer->connect();
}
}
+void BasicSessionStream::addZLibCompression() {
+ boost::shared_ptr<CompressionLayer> compressionLayer(new CompressionLayer());
+ streamStack->addLayer(compressionLayer);
+}
+
void BasicSessionStream::setWhitespacePingEnabled(bool enabled) {
if (enabled) {
if (!whitespacePingLayer) {
whitespacePingLayer = boost::shared_ptr<WhitespacePingLayer>(new WhitespacePingLayer(timerFactory));
streamStack->addLayer(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
@@ -13,12 +13,13 @@ namespace Swift {
class WhitespacePingLayer;
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
class StreamStack;
class XMPPLayer;
class ConnectionLayer;
+ class CompressionLayer;
class BasicSessionStream :
public SessionStream,
public boost::enable_shared_from_this<BasicSessionStream> {
public:
BasicSessionStream(
@@ -35,12 +36,14 @@ namespace Swift {
virtual bool isAvailable();
virtual void writeHeader(const ProtocolHeader& header);
virtual void writeElement(boost::shared_ptr<Element>);
virtual void writeFooter();
+ virtual void addZLibCompression();
+
virtual bool supportsTLSEncryption();
virtual void addTLSEncryption();
virtual void setWhitespacePingEnabled(bool);
virtual void resetXMPPParser();
@@ -62,10 +65,11 @@ namespace Swift {
PayloadSerializerCollection* payloadSerializers;
TLSLayerFactory* tlsLayerFactory;
TimerFactory* timerFactory;
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
@@ -31,12 +31,14 @@ namespace Swift {
virtual bool isAvailable() = 0;
virtual void writeHeader(const ProtocolHeader& header) = 0;
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;
virtual void resetXMPPParser() = 0;