summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Session/BasicSessionStream.cpp')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp210
1 files changed, 105 insertions, 105 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index c2d8515..697115a 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -21,192 +21,192 @@
namespace Swift {
BasicSessionStream::BasicSessionStream(
- StreamType streamType,
- boost::shared_ptr<Connection> connection,
- PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers,
- TLSContextFactory* tlsContextFactory,
- TimerFactory* timerFactory,
- XMLParserFactory* xmlParserFactory,
- const TLSOptions& tlsOptions) :
- available(false),
- connection(connection),
- tlsContextFactory(tlsContextFactory),
- timerFactory(timerFactory),
- compressionLayer(NULL),
- tlsLayer(NULL),
- whitespacePingLayer(NULL),
- tlsOptions_(tlsOptions) {
- xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType);
- xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
- xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
- xmppLayer->onError.connect(boost::bind(&BasicSessionStream::handleXMPPError, this));
- xmppLayer->onDataRead.connect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
- xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
-
- connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1));
- connectionLayer = new ConnectionLayer(connection);
-
- streamStack = new StreamStack(xmppLayer, connectionLayer);
-
- available = true;
+ StreamType streamType,
+ boost::shared_ptr<Connection> connection,
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers,
+ TLSContextFactory* tlsContextFactory,
+ TimerFactory* timerFactory,
+ XMLParserFactory* xmlParserFactory,
+ const TLSOptions& tlsOptions) :
+ available(false),
+ connection(connection),
+ tlsContextFactory(tlsContextFactory),
+ timerFactory(timerFactory),
+ compressionLayer(NULL),
+ tlsLayer(NULL),
+ whitespacePingLayer(NULL),
+ tlsOptions_(tlsOptions) {
+ xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType);
+ xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
+ xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
+ xmppLayer->onError.connect(boost::bind(&BasicSessionStream::handleXMPPError, this));
+ xmppLayer->onDataRead.connect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
+ xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
+
+ connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1));
+ connectionLayer = new ConnectionLayer(connection);
+
+ streamStack = new StreamStack(xmppLayer, connectionLayer);
+
+ available = true;
}
BasicSessionStream::~BasicSessionStream() {
- delete compressionLayer;
+ delete compressionLayer;
- if (tlsLayer) {
- tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
- tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
- delete tlsLayer;
- }
- delete whitespacePingLayer;
- delete streamStack;
+ if (tlsLayer) {
+ tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
+ tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
+ delete tlsLayer;
+ }
+ delete whitespacePingLayer;
+ delete streamStack;
- connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1));
- delete connectionLayer;
+ connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1));
+ delete connectionLayer;
- xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
- xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
- xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this));
- xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
- xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
- delete xmppLayer;
+ xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
+ xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
+ xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this));
+ xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
+ xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
+ delete xmppLayer;
}
void BasicSessionStream::writeHeader(const ProtocolHeader& header) {
- assert(available);
- xmppLayer->writeHeader(header);
+ assert(available);
+ xmppLayer->writeHeader(header);
}
void BasicSessionStream::writeElement(boost::shared_ptr<ToplevelElement> element) {
- assert(available);
- xmppLayer->writeElement(element);
+ assert(available);
+ xmppLayer->writeElement(element);
}
void BasicSessionStream::writeFooter() {
- assert(available);
- xmppLayer->writeFooter();
+ assert(available);
+ xmppLayer->writeFooter();
}
void BasicSessionStream::writeData(const std::string& data) {
- assert(available);
- xmppLayer->writeData(data);
+ assert(available);
+ xmppLayer->writeData(data);
}
void BasicSessionStream::close() {
- connection->disconnect();
+ connection->disconnect();
}
bool BasicSessionStream::isOpen() {
- return available;
+ return available;
}
bool BasicSessionStream::supportsTLSEncryption() {
- return tlsContextFactory && tlsContextFactory->canCreate();
+ return tlsContextFactory && tlsContextFactory->canCreate();
}
void BasicSessionStream::addTLSEncryption() {
- assert(available);
- tlsLayer = new TLSLayer(tlsContextFactory, tlsOptions_);
- if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) {
- onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::InvalidTLSCertificateError));
- }
- else {
- streamStack->addLayer(tlsLayer);
- tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
- tlsLayer->onConnected.connect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
- tlsLayer->connect();
- }
+ assert(available);
+ tlsLayer = new TLSLayer(tlsContextFactory, tlsOptions_);
+ if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) {
+ onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::InvalidTLSCertificateError));
+ }
+ else {
+ streamStack->addLayer(tlsLayer);
+ tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
+ tlsLayer->onConnected.connect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
+ tlsLayer->connect();
+ }
}
bool BasicSessionStream::isTLSEncrypted() {
- return tlsLayer;
+ return tlsLayer;
}
Certificate::ref BasicSessionStream::getPeerCertificate() const {
- return tlsLayer->getPeerCertificate();
+ return tlsLayer->getPeerCertificate();
}
std::vector<Certificate::ref> BasicSessionStream::getPeerCertificateChain() const {
- return tlsLayer->getPeerCertificateChain();
+ return tlsLayer->getPeerCertificateChain();
}
boost::shared_ptr<CertificateVerificationError> BasicSessionStream::getPeerCertificateVerificationError() const {
- return tlsLayer->getPeerCertificateVerificationError();
+ return tlsLayer->getPeerCertificateVerificationError();
}
ByteArray BasicSessionStream::getTLSFinishMessage() const {
- return tlsLayer->getContext()->getFinishMessage();
+ return tlsLayer->getContext()->getFinishMessage();
}
bool BasicSessionStream::supportsZLibCompression() {
- return true;
+ return true;
}
void BasicSessionStream::addZLibCompression() {
- compressionLayer = new CompressionLayer();
- streamStack->addLayer(compressionLayer);
+ compressionLayer = new CompressionLayer();
+ streamStack->addLayer(compressionLayer);
}
void BasicSessionStream::setWhitespacePingEnabled(bool enabled) {
- if (enabled) {
- if (!whitespacePingLayer) {
- whitespacePingLayer = new WhitespacePingLayer(timerFactory);
- streamStack->addLayer(whitespacePingLayer);
- }
- whitespacePingLayer->setActive();
- }
- else if (whitespacePingLayer) {
- whitespacePingLayer->setInactive();
- }
+ if (enabled) {
+ if (!whitespacePingLayer) {
+ whitespacePingLayer = new WhitespacePingLayer(timerFactory);
+ streamStack->addLayer(whitespacePingLayer);
+ }
+ whitespacePingLayer->setActive();
+ }
+ else if (whitespacePingLayer) {
+ whitespacePingLayer->setInactive();
+ }
}
void BasicSessionStream::resetXMPPParser() {
- xmppLayer->resetParser();
+ xmppLayer->resetParser();
}
void BasicSessionStream::handleStreamStartReceived(const ProtocolHeader& header) {
- onStreamStartReceived(header);
+ onStreamStartReceived(header);
}
void BasicSessionStream::handleElementReceived(boost::shared_ptr<ToplevelElement> element) {
- onElementReceived(element);
+ onElementReceived(element);
}
void BasicSessionStream::handleXMPPError() {
- available = false;
- onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError));
+ available = false;
+ onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError));
}
void BasicSessionStream::handleTLSConnected() {
- onTLSEncrypted();
+ onTLSEncrypted();
}
void BasicSessionStream::handleTLSError(boost::shared_ptr<TLSError> error) {
- available = false;
- onClosed(error);
+ available = false;
+ onClosed(error);
}
void BasicSessionStream::handleConnectionFinished(const boost::optional<Connection::Error>& error) {
- available = false;
- if (error == Connection::ReadError) {
- onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionReadError));
- }
- else if (error) {
- onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionWriteError));
- }
- else {
- onClosed(boost::shared_ptr<SessionStreamError>());
- }
+ available = false;
+ if (error == Connection::ReadError) {
+ onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionReadError));
+ }
+ else if (error) {
+ onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ConnectionWriteError));
+ }
+ else {
+ onClosed(boost::shared_ptr<SessionStreamError>());
+ }
}
void BasicSessionStream::handleDataRead(const SafeByteArray& data) {
- onDataRead(data);
+ onDataRead(data);
}
void BasicSessionStream::handleDataWritten(const SafeByteArray& data) {
- onDataWritten(data);
+ onDataWritten(data);
}
}