diff options
author | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
commit | cfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch) | |
tree | 18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/Session | |
parent | 1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff) | |
download | swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2 |
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines
in the process.
Changed CheckTabs.py tool to disallow hard tabs in source
files.
Test-Information:
Manually checked 30 random files that the conversion worked
as expected.
Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/Session')
-rw-r--r-- | Swiften/Session/BOSHSessionStream.cpp | 192 | ||||
-rw-r--r-- | Swiften/Session/BOSHSessionStream.h | 140 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 210 | ||||
-rw-r--r-- | Swiften/Session/BasicSessionStream.h | 126 | ||||
-rw-r--r-- | Swiften/Session/Session.cpp | 130 | ||||
-rw-r--r-- | Swiften/Session/Session.h | 186 | ||||
-rw-r--r-- | Swiften/Session/SessionStream.h | 136 | ||||
-rw-r--r-- | Swiften/Session/SessionTracer.cpp | 16 | ||||
-rw-r--r-- | Swiften/Session/SessionTracer.h | 14 |
9 files changed, 575 insertions, 575 deletions
diff --git a/Swiften/Session/BOSHSessionStream.cpp b/Swiften/Session/BOSHSessionStream.cpp index 7fb8b31..3794ae3 100644 --- a/Swiften/Session/BOSHSessionStream.cpp +++ b/Swiften/Session/BOSHSessionStream.cpp @@ -27,123 +27,123 @@ namespace Swift { BOSHSessionStream::BOSHSessionStream(const URL& boshURL, - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - ConnectionFactory* connectionFactory, - TLSContextFactory* tlsContextFactory, - TimerFactory* timerFactory, - XMLParserFactory* xmlParserFactory, - EventLoop* eventLoop, - DomainNameResolver* resolver, - const std::string& to, - const URL& boshHTTPConnectProxyURL, - const SafeString& boshHTTPConnectProxyAuthID, - const SafeString& boshHTTPConnectProxyAuthPassword, - const TLSOptions& tlsOptions, - boost::shared_ptr<HTTPTrafficFilter> trafficFilter) : - available(false), - eventLoop(eventLoop), - firstHeader(true) { - - boost::mt19937 random; - boost::uniform_int<unsigned long long> dist(0, (1LL<<53) - 1); - random.seed(static_cast<unsigned int>(time(NULL))); - unsigned long long initialRID = boost::variate_generator<boost::mt19937&, boost::uniform_int<unsigned long long> >(random, dist)(); - - connectionPool = new BOSHConnectionPool(boshURL, resolver, connectionFactory, xmlParserFactory, tlsContextFactory, timerFactory, eventLoop, to, initialRID, boshHTTPConnectProxyURL, boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword, tlsOptions, trafficFilter); - connectionPool->onSessionTerminated.connect(boost::bind(&BOSHSessionStream::handlePoolSessionTerminated, this, _1)); - connectionPool->onSessionStarted.connect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); - connectionPool->onXMPPDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); - connectionPool->onBOSHDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); - connectionPool->onBOSHDataWritten.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); - - xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType, true); - xmppLayer->onStreamStart.connect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); - xmppLayer->onElement.connect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); - xmppLayer->onError.connect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); - xmppLayer->onWriteData.connect(boost::bind(&BOSHSessionStream::handleXMPPLayerDataWritten, this, _1)); - - available = true; + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + ConnectionFactory* connectionFactory, + TLSContextFactory* tlsContextFactory, + TimerFactory* timerFactory, + XMLParserFactory* xmlParserFactory, + EventLoop* eventLoop, + DomainNameResolver* resolver, + const std::string& to, + const URL& boshHTTPConnectProxyURL, + const SafeString& boshHTTPConnectProxyAuthID, + const SafeString& boshHTTPConnectProxyAuthPassword, + const TLSOptions& tlsOptions, + boost::shared_ptr<HTTPTrafficFilter> trafficFilter) : + available(false), + eventLoop(eventLoop), + firstHeader(true) { + + boost::mt19937 random; + boost::uniform_int<unsigned long long> dist(0, (1LL<<53) - 1); + random.seed(static_cast<unsigned int>(time(NULL))); + unsigned long long initialRID = boost::variate_generator<boost::mt19937&, boost::uniform_int<unsigned long long> >(random, dist)(); + + connectionPool = new BOSHConnectionPool(boshURL, resolver, connectionFactory, xmlParserFactory, tlsContextFactory, timerFactory, eventLoop, to, initialRID, boshHTTPConnectProxyURL, boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword, tlsOptions, trafficFilter); + connectionPool->onSessionTerminated.connect(boost::bind(&BOSHSessionStream::handlePoolSessionTerminated, this, _1)); + connectionPool->onSessionStarted.connect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); + connectionPool->onXMPPDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); + connectionPool->onBOSHDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); + connectionPool->onBOSHDataWritten.connect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); + + xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType, true); + xmppLayer->onStreamStart.connect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); + xmppLayer->onElement.connect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); + xmppLayer->onError.connect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); + xmppLayer->onWriteData.connect(boost::bind(&BOSHSessionStream::handleXMPPLayerDataWritten, this, _1)); + + available = true; } BOSHSessionStream::~BOSHSessionStream() { - BOSHSessionStream::close(); - connectionPool->onSessionTerminated.disconnect(boost::bind(&BOSHSessionStream::handlePoolSessionTerminated, this, _1)); - connectionPool->onSessionStarted.disconnect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); - connectionPool->onXMPPDataRead.disconnect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); - connectionPool->onBOSHDataRead.disconnect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); - connectionPool->onBOSHDataWritten.disconnect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); - delete connectionPool; - connectionPool = NULL; - xmppLayer->onStreamStart.disconnect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); - xmppLayer->onElement.disconnect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); - xmppLayer->onError.disconnect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); - xmppLayer->onWriteData.disconnect(boost::bind(&BOSHSessionStream::handleXMPPLayerDataWritten, this, _1)); - delete xmppLayer; - xmppLayer = NULL; + BOSHSessionStream::close(); + connectionPool->onSessionTerminated.disconnect(boost::bind(&BOSHSessionStream::handlePoolSessionTerminated, this, _1)); + connectionPool->onSessionStarted.disconnect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); + connectionPool->onXMPPDataRead.disconnect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); + connectionPool->onBOSHDataRead.disconnect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataRead, this, _1)); + connectionPool->onBOSHDataWritten.disconnect(boost::bind(&BOSHSessionStream::handlePoolBOSHDataWritten, this, _1)); + delete connectionPool; + connectionPool = NULL; + xmppLayer->onStreamStart.disconnect(boost::bind(&BOSHSessionStream::handleStreamStartReceived, this, _1)); + xmppLayer->onElement.disconnect(boost::bind(&BOSHSessionStream::handleElementReceived, this, _1)); + xmppLayer->onError.disconnect(boost::bind(&BOSHSessionStream::handleXMPPError, this)); + xmppLayer->onWriteData.disconnect(boost::bind(&BOSHSessionStream::handleXMPPLayerDataWritten, this, _1)); + delete xmppLayer; + xmppLayer = NULL; } void BOSHSessionStream::open() { - connectionPool->setTLSCertificate(getTLSCertificate()); - connectionPool->open(); + connectionPool->setTLSCertificate(getTLSCertificate()); + connectionPool->open(); } void BOSHSessionStream::handlePoolXMPPDataRead(const SafeByteArray& data) { - xmppLayer->handleDataRead(data); + xmppLayer->handleDataRead(data); } void BOSHSessionStream::writeElement(boost::shared_ptr<ToplevelElement> element) { - assert(available); - xmppLayer->writeElement(element); + assert(available); + xmppLayer->writeElement(element); } void BOSHSessionStream::writeFooter() { - connectionPool->writeFooter(); + connectionPool->writeFooter(); } void BOSHSessionStream::writeData(const std::string& data) { - assert(available); - xmppLayer->writeData(data); + assert(available); + xmppLayer->writeData(data); } void BOSHSessionStream::close() { - connectionPool->close(); + connectionPool->close(); } bool BOSHSessionStream::isOpen() { - return available; + return available; } bool BOSHSessionStream::supportsTLSEncryption() { - return false; + return false; } void BOSHSessionStream::addTLSEncryption() { - assert(available); + assert(available); } bool BOSHSessionStream::isTLSEncrypted() { - return connectionPool->isTLSEncrypted(); + return connectionPool->isTLSEncrypted(); } Certificate::ref BOSHSessionStream::getPeerCertificate() const { - return connectionPool->getPeerCertificate(); + return connectionPool->getPeerCertificate(); } std::vector<Certificate::ref> BOSHSessionStream::getPeerCertificateChain() const { - return connectionPool->getPeerCertificateChain(); + return connectionPool->getPeerCertificateChain(); } boost::shared_ptr<CertificateVerificationError> BOSHSessionStream::getPeerCertificateVerificationError() const { - return connectionPool->getPeerCertificateVerificationError(); + return connectionPool->getPeerCertificateVerificationError(); } ByteArray BOSHSessionStream::getTLSFinishMessage() const { - return ByteArray(); + return ByteArray(); } bool BOSHSessionStream::supportsZLibCompression() { - return false; + return false; } void BOSHSessionStream::addZLibCompression() { @@ -151,71 +151,71 @@ void BOSHSessionStream::addZLibCompression() { } void BOSHSessionStream::setWhitespacePingEnabled(bool /*enabled*/) { - return; + return; } void BOSHSessionStream::resetXMPPParser() { - xmppLayer->resetParser(); + xmppLayer->resetParser(); } void BOSHSessionStream::handleStreamStartReceived(const ProtocolHeader& header) { - onStreamStartReceived(header); + onStreamStartReceived(header); } void BOSHSessionStream::handleElementReceived(boost::shared_ptr<ToplevelElement> element) { - onElementReceived(element); + onElementReceived(element); } void BOSHSessionStream::handleXMPPError() { - available = false; - onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError)); + available = false; + onClosed(boost::make_shared<SessionStreamError>(SessionStreamError::ParseError)); } void BOSHSessionStream::handlePoolSessionStarted() { - fakeStreamHeaderReceipt(); + fakeStreamHeaderReceipt(); } void BOSHSessionStream::handlePoolSessionTerminated(BOSHError::ref error) { - eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamFooterReceipt, this, error), shared_from_this()); + eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamFooterReceipt, this, error), shared_from_this()); } void BOSHSessionStream::writeHeader(const ProtocolHeader& header) { - streamHeader = header; - /*First time we're told to do this, don't (the sending of the initial header is handled on connect) - On subsequent requests we should restart the stream the BOSH way. - */ - if (!firstHeader) { - eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamHeaderReceipt, this), shared_from_this()); - eventLoop->postEvent(boost::bind(&BOSHConnectionPool::restartStream, connectionPool), shared_from_this()); - } - firstHeader = false; + streamHeader = header; + /*First time we're told to do this, don't (the sending of the initial header is handled on connect) + On subsequent requests we should restart the stream the BOSH way. + */ + if (!firstHeader) { + eventLoop->postEvent(boost::bind(&BOSHSessionStream::fakeStreamHeaderReceipt, this), shared_from_this()); + eventLoop->postEvent(boost::bind(&BOSHConnectionPool::restartStream, connectionPool), shared_from_this()); + } + firstHeader = false; } void BOSHSessionStream::fakeStreamHeaderReceipt() { - std::stringstream header; - header << "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='"; - header << streamHeader.getTo() << "' id='dummy' version='1.0'>"; + std::stringstream header; + header << "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='"; + header << streamHeader.getTo() << "' id='dummy' version='1.0'>"; - xmppLayer->handleDataRead(createSafeByteArray(header.str())); + xmppLayer->handleDataRead(createSafeByteArray(header.str())); } void BOSHSessionStream::fakeStreamFooterReceipt(BOSHError::ref error) { - std::string footer("</stream:stream>"); - xmppLayer->handleDataRead(createSafeByteArray(footer)); - onClosed(error); + std::string footer("</stream:stream>"); + xmppLayer->handleDataRead(createSafeByteArray(footer)); + onClosed(error); } void BOSHSessionStream::handleXMPPLayerDataWritten(const SafeByteArray& data) { - eventLoop->postEvent(boost::bind(&BOSHConnectionPool::write, connectionPool, data), shared_from_this()); + eventLoop->postEvent(boost::bind(&BOSHConnectionPool::write, connectionPool, data), shared_from_this()); } void BOSHSessionStream::handlePoolBOSHDataRead(const SafeByteArray& data) { - onDataRead(data); + onDataRead(data); } void BOSHSessionStream::handlePoolBOSHDataWritten(const SafeByteArray& data) { - onDataWritten(data); + onDataWritten(data); } } diff --git a/Swiften/Session/BOSHSessionStream.h b/Swiften/Session/BOSHSessionStream.h index 66e41ea..17292f4 100644 --- a/Swiften/Session/BOSHSessionStream.h +++ b/Swiften/Session/BOSHSessionStream.h @@ -18,85 +18,85 @@ #include <Swiften/TLS/TLSOptions.h> namespace Swift { - class CompressionLayer; - class ConnectionLayer; - class EventLoop; - class HTTPTrafficFilter; - class PayloadParserFactoryCollection; - class PayloadSerializerCollection; - class StreamStack; - class TLSContextFactory; - class TimerFactory; - class XMLParserFactory; - class XMPPLayer; + class CompressionLayer; + class ConnectionLayer; + class EventLoop; + class HTTPTrafficFilter; + class PayloadParserFactoryCollection; + class PayloadSerializerCollection; + class StreamStack; + class TLSContextFactory; + class TimerFactory; + class XMLParserFactory; + class XMPPLayer; - class SWIFTEN_API BOSHSessionStream : public SessionStream, public EventOwner, public boost::enable_shared_from_this<BOSHSessionStream> { - public: - BOSHSessionStream( - const URL& boshURL, - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - ConnectionFactory* connectionFactory, - TLSContextFactory* tlsContextFactory, - TimerFactory* whitespacePingLayerFactory, - XMLParserFactory* xmlParserFactory, - EventLoop* eventLoop, - DomainNameResolver* resolver, - const std::string& to, - const URL& boshHTTPConnectProxyURL, - const SafeString& boshHTTPConnectProxyAuthID, - const SafeString& boshHTTPConnectProxyAuthPassword, - const TLSOptions& tlsOptions, - boost::shared_ptr<HTTPTrafficFilter> trafficFilter - ); - virtual ~BOSHSessionStream(); + class SWIFTEN_API BOSHSessionStream : public SessionStream, public EventOwner, public boost::enable_shared_from_this<BOSHSessionStream> { + public: + BOSHSessionStream( + const URL& boshURL, + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + ConnectionFactory* connectionFactory, + TLSContextFactory* tlsContextFactory, + TimerFactory* whitespacePingLayerFactory, + XMLParserFactory* xmlParserFactory, + EventLoop* eventLoop, + DomainNameResolver* resolver, + const std::string& to, + const URL& boshHTTPConnectProxyURL, + const SafeString& boshHTTPConnectProxyAuthID, + const SafeString& boshHTTPConnectProxyAuthPassword, + const TLSOptions& tlsOptions, + boost::shared_ptr<HTTPTrafficFilter> trafficFilter + ); + virtual ~BOSHSessionStream(); - void open(); - virtual void close(); - virtual bool isOpen(); + void open(); + virtual void close(); + virtual bool isOpen(); - virtual void writeHeader(const ProtocolHeader& header); - virtual void writeElement(boost::shared_ptr<ToplevelElement>); - virtual void writeFooter(); - virtual void writeData(const std::string& data); + virtual void writeHeader(const ProtocolHeader& header); + virtual void writeElement(boost::shared_ptr<ToplevelElement>); + virtual void writeFooter(); + virtual void writeData(const std::string& data); - virtual bool supportsZLibCompression(); - virtual void addZLibCompression(); + virtual bool supportsZLibCompression(); + virtual void addZLibCompression(); - virtual bool supportsTLSEncryption(); - virtual void addTLSEncryption(); - virtual bool isTLSEncrypted(); - virtual Certificate::ref getPeerCertificate() const; - virtual std::vector<Certificate::ref> getPeerCertificateChain() const; - virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; - virtual ByteArray getTLSFinishMessage() const; + virtual bool supportsTLSEncryption(); + virtual void addTLSEncryption(); + virtual bool isTLSEncrypted(); + virtual Certificate::ref getPeerCertificate() const; + virtual std::vector<Certificate::ref> getPeerCertificateChain() const; + virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; + virtual ByteArray getTLSFinishMessage() const; - virtual void setWhitespacePingEnabled(bool); + virtual void setWhitespacePingEnabled(bool); - virtual void resetXMPPParser(); + virtual void resetXMPPParser(); - private: - void handleXMPPError(); - void handleStreamStartReceived(const ProtocolHeader&); - void handleElementReceived(boost::shared_ptr<ToplevelElement>); - void handlePoolXMPPDataRead(const SafeByteArray& data); - void handleXMPPLayerDataWritten(const SafeByteArray& data); - void handlePoolSessionStarted(); - void handlePoolBOSHDataRead(const SafeByteArray& data); - void handlePoolBOSHDataWritten(const SafeByteArray& data); - void handlePoolSessionTerminated(BOSHError::ref condition); + private: + void handleXMPPError(); + void handleStreamStartReceived(const ProtocolHeader&); + void handleElementReceived(boost::shared_ptr<ToplevelElement>); + void handlePoolXMPPDataRead(const SafeByteArray& data); + void handleXMPPLayerDataWritten(const SafeByteArray& data); + void handlePoolSessionStarted(); + void handlePoolBOSHDataRead(const SafeByteArray& data); + void handlePoolBOSHDataWritten(const SafeByteArray& data); + void handlePoolSessionTerminated(BOSHError::ref condition); - private: - void fakeStreamHeaderReceipt(); - void fakeStreamFooterReceipt(BOSHError::ref error); + private: + void fakeStreamHeaderReceipt(); + void fakeStreamFooterReceipt(BOSHError::ref error); - private: - BOSHConnectionPool* connectionPool; - bool available; - XMPPLayer* xmppLayer; - ProtocolHeader streamHeader; - EventLoop* eventLoop; - bool firstHeader; - }; + private: + BOSHConnectionPool* connectionPool; + bool available; + XMPPLayer* xmppLayer; + ProtocolHeader streamHeader; + EventLoop* eventLoop; + bool firstHeader; + }; } 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); } } diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index 2298351..db4a7e0 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h @@ -17,78 +17,78 @@ #include <Swiften/TLS/TLSOptions.h> namespace Swift { - class TLSContextFactory; - class TLSLayer; - class TimerFactory; - class WhitespacePingLayer; - class PayloadParserFactoryCollection; - class PayloadSerializerCollection; - class StreamStack; - class XMPPLayer; - class ConnectionLayer; - class CompressionLayer; - class XMLParserFactory; + class TLSContextFactory; + class TLSLayer; + class TimerFactory; + class WhitespacePingLayer; + class PayloadParserFactoryCollection; + class PayloadSerializerCollection; + class StreamStack; + class XMPPLayer; + class ConnectionLayer; + class CompressionLayer; + class XMLParserFactory; - class SWIFTEN_API BasicSessionStream : public SessionStream { - public: - BasicSessionStream( - StreamType streamType, - boost::shared_ptr<Connection> connection, - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - TLSContextFactory* tlsContextFactory, - TimerFactory* whitespacePingLayerFactory, - XMLParserFactory* xmlParserFactory, - const TLSOptions& tlsOptions - ); - virtual ~BasicSessionStream(); + class SWIFTEN_API BasicSessionStream : public SessionStream { + public: + BasicSessionStream( + StreamType streamType, + boost::shared_ptr<Connection> connection, + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + TLSContextFactory* tlsContextFactory, + TimerFactory* whitespacePingLayerFactory, + XMLParserFactory* xmlParserFactory, + const TLSOptions& tlsOptions + ); + virtual ~BasicSessionStream(); - virtual void close(); - virtual bool isOpen(); + virtual void close(); + virtual bool isOpen(); - virtual void writeHeader(const ProtocolHeader& header); - virtual void writeElement(boost::shared_ptr<ToplevelElement>); - virtual void writeFooter(); - virtual void writeData(const std::string& data); + virtual void writeHeader(const ProtocolHeader& header); + virtual void writeElement(boost::shared_ptr<ToplevelElement>); + virtual void writeFooter(); + virtual void writeData(const std::string& data); - virtual bool supportsZLibCompression(); - virtual void addZLibCompression(); + virtual bool supportsZLibCompression(); + virtual void addZLibCompression(); - virtual bool supportsTLSEncryption(); - virtual void addTLSEncryption(); - virtual bool isTLSEncrypted(); - virtual Certificate::ref getPeerCertificate() const; - virtual std::vector<Certificate::ref> getPeerCertificateChain() const; + virtual bool supportsTLSEncryption(); + virtual void addTLSEncryption(); + virtual bool isTLSEncrypted(); + virtual Certificate::ref getPeerCertificate() const; + virtual std::vector<Certificate::ref> getPeerCertificateChain() const; - virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; - virtual ByteArray getTLSFinishMessage() const; + virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; + virtual ByteArray getTLSFinishMessage() const; - virtual void setWhitespacePingEnabled(bool); + virtual void setWhitespacePingEnabled(bool); - virtual void resetXMPPParser(); + virtual void resetXMPPParser(); - private: - void handleConnectionFinished(const boost::optional<Connection::Error>& error); - void handleXMPPError(); - void handleTLSConnected(); - void handleTLSError(boost::shared_ptr<TLSError>); - void handleStreamStartReceived(const ProtocolHeader&); - void handleElementReceived(boost::shared_ptr<ToplevelElement>); - void handleDataRead(const SafeByteArray& data); - void handleDataWritten(const SafeByteArray& data); + private: + void handleConnectionFinished(const boost::optional<Connection::Error>& error); + void handleXMPPError(); + void handleTLSConnected(); + void handleTLSError(boost::shared_ptr<TLSError>); + void handleStreamStartReceived(const ProtocolHeader&); + void handleElementReceived(boost::shared_ptr<ToplevelElement>); + void handleDataRead(const SafeByteArray& data); + void handleDataWritten(const SafeByteArray& data); - private: - bool available; - boost::shared_ptr<Connection> connection; - TLSContextFactory* tlsContextFactory; - TimerFactory* timerFactory; - XMPPLayer* xmppLayer; - ConnectionLayer* connectionLayer; - CompressionLayer* compressionLayer; - TLSLayer* tlsLayer; - WhitespacePingLayer* whitespacePingLayer; - StreamStack* streamStack; - TLSOptions tlsOptions_; - }; + private: + bool available; + boost::shared_ptr<Connection> connection; + TLSContextFactory* tlsContextFactory; + TimerFactory* timerFactory; + XMPPLayer* xmppLayer; + ConnectionLayer* connectionLayer; + CompressionLayer* compressionLayer; + TLSLayer* tlsLayer; + WhitespacePingLayer* whitespacePingLayer; + StreamStack* streamStack; + TLSOptions tlsOptions_; + }; } diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp index 95d7227..7f13cd7 100644 --- a/Swiften/Session/Session.cpp +++ b/Swiften/Session/Session.cpp @@ -14,92 +14,92 @@ namespace Swift { Session::Session( - boost::shared_ptr<Connection> connection, - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - XMLParserFactory* xmlParserFactory) : - connection(connection), - payloadParserFactories(payloadParserFactories), - payloadSerializers(payloadSerializers), - xmlParserFactory(xmlParserFactory), - xmppLayer(NULL), - connectionLayer(NULL), - streamStack(0), - finishing(false) { + boost::shared_ptr<Connection> connection, + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + XMLParserFactory* xmlParserFactory) : + connection(connection), + payloadParserFactories(payloadParserFactories), + payloadSerializers(payloadSerializers), + xmlParserFactory(xmlParserFactory), + xmppLayer(NULL), + connectionLayer(NULL), + streamStack(0), + finishing(false) { } Session::~Session() { - delete streamStack; - delete connectionLayer; - delete xmppLayer; + delete streamStack; + delete connectionLayer; + delete xmppLayer; } void Session::startSession() { - initializeStreamStack(); - handleSessionStarted(); + initializeStreamStack(); + handleSessionStarted(); } void Session::finishSession() { - if (finishing) { - return; - } - finishing = true; - if (xmppLayer) { - xmppLayer->writeFooter(); - } - connection->disconnect(); + if (finishing) { + return; + } + finishing = true; + if (xmppLayer) { + xmppLayer->writeFooter(); + } + connection->disconnect(); } void Session::finishSession(const SessionError& /*error*/) { - if (finishing) { - return; - } - finishing = true; - if (xmppLayer) { - xmppLayer->writeFooter(); - } - connection->disconnect(); + if (finishing) { + return; + } + finishing = true; + if (xmppLayer) { + xmppLayer->writeFooter(); + } + connection->disconnect(); } void Session::initializeStreamStack() { - xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); - xmppLayer->onStreamStart.connect( - boost::bind(&Session::handleStreamStart, this, _1)); - xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); - xmppLayer->onError.connect( - boost::bind(&Session::finishSession, this, XMLError)); - xmppLayer->onDataRead.connect(boost::bind(boost::ref(onDataRead), _1)); - xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); - connection->onDisconnected.connect( - boost::bind(&Session::handleDisconnected, this, _1)); - connectionLayer = new ConnectionLayer(connection); - streamStack = new StreamStack(xmppLayer, connectionLayer); + xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); + xmppLayer->onStreamStart.connect( + boost::bind(&Session::handleStreamStart, this, _1)); + xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); + xmppLayer->onError.connect( + boost::bind(&Session::finishSession, this, XMLError)); + xmppLayer->onDataRead.connect(boost::bind(boost::ref(onDataRead), _1)); + xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); + connection->onDisconnected.connect( + boost::bind(&Session::handleDisconnected, this, _1)); + connectionLayer = new ConnectionLayer(connection); + streamStack = new StreamStack(xmppLayer, connectionLayer); } void Session::sendElement(boost::shared_ptr<ToplevelElement> stanza) { - xmppLayer->writeElement(stanza); + xmppLayer->writeElement(stanza); } void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { - connection->onDisconnected.disconnect( - boost::bind(&Session::handleDisconnected, this, _1)); - if (connectionError) { - switch (*connectionError) { - case Connection::ReadError: - handleSessionFinished(ConnectionReadError); - onSessionFinished(ConnectionReadError); - break; - case Connection::WriteError: - handleSessionFinished(ConnectionWriteError); - onSessionFinished(ConnectionWriteError); - break; - } - } - else { - boost::optional<SessionError> error; - handleSessionFinished(error); - onSessionFinished(error); - } + connection->onDisconnected.disconnect( + boost::bind(&Session::handleDisconnected, this, _1)); + if (connectionError) { + switch (*connectionError) { + case Connection::ReadError: + handleSessionFinished(ConnectionReadError); + onSessionFinished(ConnectionReadError); + break; + case Connection::WriteError: + handleSessionFinished(ConnectionWriteError); + onSessionFinished(ConnectionWriteError); + break; + } + } + else { + boost::optional<SessionError> error; + handleSessionFinished(error); + onSessionFinished(error); + } } } diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h index a6dae80..d01833d 100644 --- a/Swiften/Session/Session.h +++ b/Swiften/Session/Session.h @@ -19,97 +19,97 @@ #include <Swiften/StreamStack/ConnectionLayer.h> namespace Swift { - class ProtocolHeader; - class StreamStack; - class JID; - class Element; - class PayloadParserFactoryCollection; - class PayloadSerializerCollection; - class XMPPLayer; - class XMLParserFactory; - - class SWIFTEN_API Session : public boost::enable_shared_from_this<Session> { - public: - enum SessionError { - ConnectionReadError, - ConnectionWriteError, - XMLError, - AuthenticationFailedError, - NoSupportedAuthMechanismsError, - UnexpectedElementError, - ResourceBindError, - SessionStartError, - TLSError, - ClientCertificateLoadError, - ClientCertificateError - }; - - Session( - boost::shared_ptr<Connection> connection, - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - XMLParserFactory* xmlParserFactory); - virtual ~Session(); - - void startSession(); - void finishSession(); - - void sendElement(boost::shared_ptr<ToplevelElement>); - - const JID& getLocalJID() const { - return localJID; - } - - const JID& getRemoteJID() const { - return remoteJID; - } - - boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElementReceived; - boost::signal<void (const boost::optional<SessionError>&)> onSessionFinished; - boost::signal<void (const SafeByteArray&)> onDataWritten; - boost::signal<void (const SafeByteArray&)> onDataRead; - - protected: - void setRemoteJID(const JID& j) { - remoteJID = j; - } - - void setLocalJID(const JID& j) { - localJID = j; - } - - void finishSession(const SessionError&); - - virtual void handleSessionStarted() {} - virtual void handleSessionFinished(const boost::optional<SessionError>&) {} - virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; - virtual void handleStreamStart(const ProtocolHeader&) = 0; - - void initializeStreamStack(); - - XMPPLayer* getXMPPLayer() const { - return xmppLayer; - } - - StreamStack* getStreamStack() const { - return streamStack; - } - - void setFinished(); - - private: - void handleDisconnected(const boost::optional<Connection::Error>& error); - - private: - JID localJID; - JID remoteJID; - boost::shared_ptr<Connection> connection; - PayloadParserFactoryCollection* payloadParserFactories; - PayloadSerializerCollection* payloadSerializers; - XMLParserFactory* xmlParserFactory; - XMPPLayer* xmppLayer; - ConnectionLayer* connectionLayer; - StreamStack* streamStack; - bool finishing; - }; + class ProtocolHeader; + class StreamStack; + class JID; + class Element; + class PayloadParserFactoryCollection; + class PayloadSerializerCollection; + class XMPPLayer; + class XMLParserFactory; + + class SWIFTEN_API Session : public boost::enable_shared_from_this<Session> { + public: + enum SessionError { + ConnectionReadError, + ConnectionWriteError, + XMLError, + AuthenticationFailedError, + NoSupportedAuthMechanismsError, + UnexpectedElementError, + ResourceBindError, + SessionStartError, + TLSError, + ClientCertificateLoadError, + ClientCertificateError + }; + + Session( + boost::shared_ptr<Connection> connection, + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + XMLParserFactory* xmlParserFactory); + virtual ~Session(); + + void startSession(); + void finishSession(); + + void sendElement(boost::shared_ptr<ToplevelElement>); + + const JID& getLocalJID() const { + return localJID; + } + + const JID& getRemoteJID() const { + return remoteJID; + } + + boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElementReceived; + boost::signal<void (const boost::optional<SessionError>&)> onSessionFinished; + boost::signal<void (const SafeByteArray&)> onDataWritten; + boost::signal<void (const SafeByteArray&)> onDataRead; + + protected: + void setRemoteJID(const JID& j) { + remoteJID = j; + } + + void setLocalJID(const JID& j) { + localJID = j; + } + + void finishSession(const SessionError&); + + virtual void handleSessionStarted() {} + virtual void handleSessionFinished(const boost::optional<SessionError>&) {} + virtual void handleElement(boost::shared_ptr<ToplevelElement>) = 0; + virtual void handleStreamStart(const ProtocolHeader&) = 0; + + void initializeStreamStack(); + + XMPPLayer* getXMPPLayer() const { + return xmppLayer; + } + + StreamStack* getStreamStack() const { + return streamStack; + } + + void setFinished(); + + private: + void handleDisconnected(const boost::optional<Connection::Error>& error); + + private: + JID localJID; + JID remoteJID; + boost::shared_ptr<Connection> connection; + PayloadParserFactoryCollection* payloadParserFactories; + PayloadSerializerCollection* payloadSerializers; + XMLParserFactory* xmlParserFactory; + XMPPLayer* xmppLayer; + ConnectionLayer* connectionLayer; + StreamStack* streamStack; + bool finishing; + }; } diff --git a/Swiften/Session/SessionStream.h b/Swiften/Session/SessionStream.h index 9dcec71..18404c6 100644 --- a/Swiften/Session/SessionStream.h +++ b/Swiften/Session/SessionStream.h @@ -20,72 +20,72 @@ #include <Swiften/TLS/CertificateWithKey.h> namespace Swift { - class SWIFTEN_API SessionStream { - public: - class SWIFTEN_API SessionStreamError : public Swift::Error { - public: - enum Type { - ParseError, - TLSError, - InvalidTLSCertificateError, - ConnectionReadError, - ConnectionWriteError - }; - - SessionStreamError(Type type) : type(type) {} - - Type type; - }; - - SessionStream(): certificate() {} - - virtual ~SessionStream(); - - virtual void close() = 0; - virtual bool isOpen() = 0; - - virtual void writeHeader(const ProtocolHeader& header) = 0; - virtual void writeFooter() = 0; - virtual void writeElement(boost::shared_ptr<ToplevelElement>) = 0; - virtual void writeData(const std::string& data) = 0; - - virtual bool supportsZLibCompression() = 0; - virtual void addZLibCompression() = 0; - - virtual bool supportsTLSEncryption() = 0; - virtual void addTLSEncryption() = 0; - virtual bool isTLSEncrypted() = 0; - virtual void setWhitespacePingEnabled(bool enabled) = 0; - - virtual void resetXMPPParser() = 0; - - void setTLSCertificate(CertificateWithKey::ref cert) { - certificate = cert; - } - - virtual bool hasTLSCertificate() { - return certificate && !certificate->isNull(); - } - - virtual Certificate::ref getPeerCertificate() const = 0; - virtual std::vector<Certificate::ref> getPeerCertificateChain() const = 0; - virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const = 0; - - virtual ByteArray getTLSFinishMessage() const = 0; - - boost::signal<void (const ProtocolHeader&)> onStreamStartReceived; - boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElementReceived; - boost::signal<void (boost::shared_ptr<Error>)> onClosed; - boost::signal<void ()> onTLSEncrypted; - boost::signal<void (const SafeByteArray&)> onDataRead; - boost::signal<void (const SafeByteArray&)> onDataWritten; - - protected: - CertificateWithKey::ref getTLSCertificate() const { - return certificate; - } - - private: - CertificateWithKey::ref certificate; - }; + class SWIFTEN_API SessionStream { + public: + class SWIFTEN_API SessionStreamError : public Swift::Error { + public: + enum Type { + ParseError, + TLSError, + InvalidTLSCertificateError, + ConnectionReadError, + ConnectionWriteError + }; + + SessionStreamError(Type type) : type(type) {} + + Type type; + }; + + SessionStream(): certificate() {} + + virtual ~SessionStream(); + + virtual void close() = 0; + virtual bool isOpen() = 0; + + virtual void writeHeader(const ProtocolHeader& header) = 0; + virtual void writeFooter() = 0; + virtual void writeElement(boost::shared_ptr<ToplevelElement>) = 0; + virtual void writeData(const std::string& data) = 0; + + virtual bool supportsZLibCompression() = 0; + virtual void addZLibCompression() = 0; + + virtual bool supportsTLSEncryption() = 0; + virtual void addTLSEncryption() = 0; + virtual bool isTLSEncrypted() = 0; + virtual void setWhitespacePingEnabled(bool enabled) = 0; + + virtual void resetXMPPParser() = 0; + + void setTLSCertificate(CertificateWithKey::ref cert) { + certificate = cert; + } + + virtual bool hasTLSCertificate() { + return certificate && !certificate->isNull(); + } + + virtual Certificate::ref getPeerCertificate() const = 0; + virtual std::vector<Certificate::ref> getPeerCertificateChain() const = 0; + virtual boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const = 0; + + virtual ByteArray getTLSFinishMessage() const = 0; + + boost::signal<void (const ProtocolHeader&)> onStreamStartReceived; + boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElementReceived; + boost::signal<void (boost::shared_ptr<Error>)> onClosed; + boost::signal<void ()> onTLSEncrypted; + boost::signal<void (const SafeByteArray&)> onDataRead; + boost::signal<void (const SafeByteArray&)> onDataWritten; + + protected: + CertificateWithKey::ref getTLSCertificate() const { + return certificate; + } + + private: + CertificateWithKey::ref certificate; + }; } diff --git a/Swiften/Session/SessionTracer.cpp b/Swiften/Session/SessionTracer.cpp index 61e8cc7..aa44b9c 100644 --- a/Swiften/Session/SessionTracer.cpp +++ b/Swiften/Session/SessionTracer.cpp @@ -13,17 +13,17 @@ namespace Swift { SessionTracer::SessionTracer(boost::shared_ptr<Session> session) : session(session) { - session->onDataRead.connect(boost::bind(&SessionTracer::printData, this, '<', _1)); - session->onDataWritten.connect(boost::bind(&SessionTracer::printData, this, '>', _1)); + session->onDataRead.connect(boost::bind(&SessionTracer::printData, this, '<', _1)); + session->onDataWritten.connect(boost::bind(&SessionTracer::printData, this, '>', _1)); } void SessionTracer::printData(char direction, const SafeByteArray& data) { - std::cerr << direction << direction << " " << session->getLocalJID() << " "; - for (unsigned int i = 0; i < 72 - session->getLocalJID().toString().size() - session->getRemoteJID().toString().size(); ++i) { - std::cerr << direction; - } - std::cerr << " " << session->getRemoteJID()<< " " << direction << direction << std::endl; - std::cerr << byteArrayToString(ByteArray(data.begin(), data.end())) << std::endl; + std::cerr << direction << direction << " " << session->getLocalJID() << " "; + for (unsigned int i = 0; i < 72 - session->getLocalJID().toString().size() - session->getRemoteJID().toString().size(); ++i) { + std::cerr << direction; + } + std::cerr << " " << session->getRemoteJID()<< " " << direction << direction << std::endl; + std::cerr << byteArrayToString(ByteArray(data.begin(), data.end())) << std::endl; } } diff --git a/Swiften/Session/SessionTracer.h b/Swiften/Session/SessionTracer.h index adc72b0..3993a87 100644 --- a/Swiften/Session/SessionTracer.h +++ b/Swiften/Session/SessionTracer.h @@ -13,13 +13,13 @@ #include <Swiften/Session/Session.h> namespace Swift { - class SWIFTEN_API SessionTracer { - public: - SessionTracer(boost::shared_ptr<Session> session); + class SWIFTEN_API SessionTracer { + public: + SessionTracer(boost::shared_ptr<Session> session); - private: - void printData(char direction, const SafeByteArray& data); + private: + void printData(char direction, const SafeByteArray& data); - boost::shared_ptr<Session> session; - }; + boost::shared_ptr<Session> session; + }; } |