summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StreamStack')
-rw-r--r--Swiften/StreamStack/CompressionLayer.h64
-rw-r--r--Swiften/StreamStack/ConnectionLayer.cpp6
-rw-r--r--Swiften/StreamStack/ConnectionLayer.h24
-rw-r--r--Swiften/StreamStack/DummyStreamLayer.h28
-rw-r--r--Swiften/StreamStack/HighLayer.cpp8
-rw-r--r--Swiften/StreamStack/HighLayer.h38
-rw-r--r--Swiften/StreamStack/LowLayer.cpp4
-rw-r--r--Swiften/StreamStack/LowLayer.h40
-rw-r--r--Swiften/StreamStack/StreamLayer.h8
-rw-r--r--Swiften/StreamStack/StreamStack.cpp18
-rw-r--r--Swiften/StreamStack/StreamStack.h60
-rw-r--r--Swiften/StreamStack/TLSLayer.cpp26
-rw-r--r--Swiften/StreamStack/TLSLayer.h44
-rw-r--r--Swiften/StreamStack/UnitTest/StreamStackTest.cpp302
-rw-r--r--Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp230
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.cpp32
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.h48
-rw-r--r--Swiften/StreamStack/XMPPLayer.cpp92
-rw-r--r--Swiften/StreamStack/XMPPLayer.h92
19 files changed, 582 insertions, 582 deletions
diff --git a/Swiften/StreamStack/CompressionLayer.h b/Swiften/StreamStack/CompressionLayer.h
index 1e694c9..32fad37 100644
--- a/Swiften/StreamStack/CompressionLayer.h
+++ b/Swiften/StreamStack/CompressionLayer.h
@@ -17,36 +17,36 @@
#include <Swiften/StreamStack/StreamLayer.h>
namespace Swift {
- class ZLibCompressor;
- class ZLibDecompressor;
-
- class SWIFTEN_API CompressionLayer : public StreamLayer, boost::noncopyable {
- public:
- CompressionLayer() {}
-
- virtual void writeData(const SafeByteArray& data) {
- try {
- writeDataToChildLayer(compressor_.process(data));
- }
- catch (const ZLibException&) {
- onError();
- }
- }
-
- virtual void handleDataRead(const SafeByteArray& data) {
- try {
- writeDataToParentLayer(decompressor_.process(data));
- }
- catch (const ZLibException&) {
- onError();
- }
- }
-
- public:
- boost::signal<void ()> onError;
-
- private:
- ZLibCompressor compressor_;
- ZLibDecompressor decompressor_;
- };
+ class ZLibCompressor;
+ class ZLibDecompressor;
+
+ class SWIFTEN_API CompressionLayer : public StreamLayer, boost::noncopyable {
+ public:
+ CompressionLayer() {}
+
+ virtual void writeData(const SafeByteArray& data) {
+ try {
+ writeDataToChildLayer(compressor_.process(data));
+ }
+ catch (const ZLibException&) {
+ onError();
+ }
+ }
+
+ virtual void handleDataRead(const SafeByteArray& data) {
+ try {
+ writeDataToParentLayer(decompressor_.process(data));
+ }
+ catch (const ZLibException&) {
+ onError();
+ }
+ }
+
+ public:
+ boost::signal<void ()> onError;
+
+ private:
+ ZLibCompressor compressor_;
+ ZLibDecompressor decompressor_;
+ };
}
diff --git a/Swiften/StreamStack/ConnectionLayer.cpp b/Swiften/StreamStack/ConnectionLayer.cpp
index 5bf07d0..09b6f87 100644
--- a/Swiften/StreamStack/ConnectionLayer.cpp
+++ b/Swiften/StreamStack/ConnectionLayer.cpp
@@ -11,15 +11,15 @@
namespace Swift {
ConnectionLayer::ConnectionLayer(boost::shared_ptr<Connection> connection) : connection(connection) {
- connection->onDataRead.connect(boost::bind(&ConnectionLayer::handleDataRead, this, _1));
+ connection->onDataRead.connect(boost::bind(&ConnectionLayer::handleDataRead, this, _1));
}
ConnectionLayer::~ConnectionLayer() {
- connection->onDataRead.disconnect(boost::bind(&ConnectionLayer::handleDataRead, this, _1));
+ connection->onDataRead.disconnect(boost::bind(&ConnectionLayer::handleDataRead, this, _1));
}
void ConnectionLayer::handleDataRead(boost::shared_ptr<SafeByteArray> data) {
- writeDataToParentLayer(*data);
+ writeDataToParentLayer(*data);
}
diff --git a/Swiften/StreamStack/ConnectionLayer.h b/Swiften/StreamStack/ConnectionLayer.h
index e89e24c..c2d0fde 100644
--- a/Swiften/StreamStack/ConnectionLayer.h
+++ b/Swiften/StreamStack/ConnectionLayer.h
@@ -13,19 +13,19 @@
#include <Swiften/StreamStack/LowLayer.h>
namespace Swift {
- class SWIFTEN_API ConnectionLayer : public LowLayer {
- public:
- ConnectionLayer(boost::shared_ptr<Connection> connection);
- virtual ~ConnectionLayer();
+ class SWIFTEN_API ConnectionLayer : public LowLayer {
+ public:
+ ConnectionLayer(boost::shared_ptr<Connection> connection);
+ virtual ~ConnectionLayer();
- void writeData(const SafeByteArray& data) {
- connection->write(data);
- }
+ void writeData(const SafeByteArray& data) {
+ connection->write(data);
+ }
- private:
- void handleDataRead(boost::shared_ptr<SafeByteArray>);
+ private:
+ void handleDataRead(boost::shared_ptr<SafeByteArray>);
- private:
- boost::shared_ptr<Connection> connection;
- };
+ private:
+ boost::shared_ptr<Connection> connection;
+ };
}
diff --git a/Swiften/StreamStack/DummyStreamLayer.h b/Swiften/StreamStack/DummyStreamLayer.h
index b06c8aa..5a93b7f 100644
--- a/Swiften/StreamStack/DummyStreamLayer.h
+++ b/Swiften/StreamStack/DummyStreamLayer.h
@@ -11,20 +11,20 @@
#include <Swiften/StreamStack/LowLayer.h>
namespace Swift {
- /**
- * The \ref DummyStreamLayer can be used to use a \ref LowLayer on its own, without a functioning parent layer.
- * The \ref DummyStreamLayer will serve as the parent layer to the \ref LowLayer and is called when the \ref LowLayer
- * wants to write data to its parent layer.
- */
- class SWIFTEN_API DummyStreamLayer : public HighLayer {
- public:
- DummyStreamLayer(LowLayer* lowLayer) {
- setChildLayer(lowLayer);
- lowLayer->setParentLayer(this);
- }
+ /**
+ * The \ref DummyStreamLayer can be used to use a \ref LowLayer on its own, without a functioning parent layer.
+ * The \ref DummyStreamLayer will serve as the parent layer to the \ref LowLayer and is called when the \ref LowLayer
+ * wants to write data to its parent layer.
+ */
+ class SWIFTEN_API DummyStreamLayer : public HighLayer {
+ public:
+ DummyStreamLayer(LowLayer* lowLayer) {
+ setChildLayer(lowLayer);
+ lowLayer->setParentLayer(this);
+ }
- virtual void handleDataRead(const SafeByteArray& /* data */) {
+ virtual void handleDataRead(const SafeByteArray& /* data */) {
- }
- };
+ }
+ };
}
diff --git a/Swiften/StreamStack/HighLayer.cpp b/Swiften/StreamStack/HighLayer.cpp
index b3e8ae8..fcfdacf 100644
--- a/Swiften/StreamStack/HighLayer.cpp
+++ b/Swiften/StreamStack/HighLayer.cpp
@@ -19,10 +19,10 @@ HighLayer::~HighLayer() {
}
void HighLayer::writeDataToChildLayer(const SafeByteArray& data) {
- //assert(childLayer);
- if (childLayer) {
- childLayer->writeData(data);
- }
+ //assert(childLayer);
+ if (childLayer) {
+ childLayer->writeData(data);
+ }
}
}
diff --git a/Swiften/StreamStack/HighLayer.h b/Swiften/StreamStack/HighLayer.h
index 178de70..a877d8d 100644
--- a/Swiften/StreamStack/HighLayer.h
+++ b/Swiften/StreamStack/HighLayer.h
@@ -10,29 +10,29 @@
#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
- class LowLayer;
+ class LowLayer;
- class SWIFTEN_API HighLayer {
- friend class StreamStack;
+ class SWIFTEN_API HighLayer {
+ friend class StreamStack;
- public:
- HighLayer();
- virtual ~HighLayer();
+ public:
+ HighLayer();
+ virtual ~HighLayer();
- virtual void handleDataRead(const SafeByteArray& data) = 0;
-
- protected:
- LowLayer* getChildLayer() {
- return childLayer;
- }
+ virtual void handleDataRead(const SafeByteArray& data) = 0;
- void setChildLayer(LowLayer* childLayer) {
- this->childLayer = childLayer;
- }
+ protected:
+ LowLayer* getChildLayer() {
+ return childLayer;
+ }
- void writeDataToChildLayer(const SafeByteArray& data);
+ void setChildLayer(LowLayer* childLayer) {
+ this->childLayer = childLayer;
+ }
- private:
- LowLayer* childLayer;
- };
+ void writeDataToChildLayer(const SafeByteArray& data);
+
+ private:
+ LowLayer* childLayer;
+ };
}
diff --git a/Swiften/StreamStack/LowLayer.cpp b/Swiften/StreamStack/LowLayer.cpp
index 4829bd1..07b0f43 100644
--- a/Swiften/StreamStack/LowLayer.cpp
+++ b/Swiften/StreamStack/LowLayer.cpp
@@ -19,8 +19,8 @@ LowLayer::~LowLayer() {
}
void LowLayer::writeDataToParentLayer(const SafeByteArray& data) {
- assert(parentLayer);
- parentLayer->handleDataRead(data);
+ assert(parentLayer);
+ parentLayer->handleDataRead(data);
}
}
diff --git a/Swiften/StreamStack/LowLayer.h b/Swiften/StreamStack/LowLayer.h
index b1bddec..83cc190 100644
--- a/Swiften/StreamStack/LowLayer.h
+++ b/Swiften/StreamStack/LowLayer.h
@@ -10,30 +10,30 @@
#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
- class HighLayer;
+ class HighLayer;
- class SWIFTEN_API LowLayer {
- friend class StreamStack;
- friend class DummyStreamLayer;
+ class SWIFTEN_API LowLayer {
+ friend class StreamStack;
+ friend class DummyStreamLayer;
- public:
- LowLayer();
- virtual ~LowLayer();
+ public:
+ LowLayer();
+ virtual ~LowLayer();
- virtual void writeData(const SafeByteArray& data) = 0;
-
- protected:
- HighLayer* getParentLayer() {
- return parentLayer;
- }
+ virtual void writeData(const SafeByteArray& data) = 0;
- void setParentLayer(HighLayer* parentLayer) {
- this->parentLayer = parentLayer;
- }
+ protected:
+ HighLayer* getParentLayer() {
+ return parentLayer;
+ }
- void writeDataToParentLayer(const SafeByteArray& data);
+ void setParentLayer(HighLayer* parentLayer) {
+ this->parentLayer = parentLayer;
+ }
- private:
- HighLayer* parentLayer;
- };
+ void writeDataToParentLayer(const SafeByteArray& data);
+
+ private:
+ HighLayer* parentLayer;
+ };
}
diff --git a/Swiften/StreamStack/StreamLayer.h b/Swiften/StreamStack/StreamLayer.h
index 2d3ea50..14a1ea6 100644
--- a/Swiften/StreamStack/StreamLayer.h
+++ b/Swiften/StreamStack/StreamLayer.h
@@ -11,8 +11,8 @@
#include <Swiften/StreamStack/LowLayer.h>
namespace Swift {
- class SWIFTEN_API StreamLayer : public LowLayer, public HighLayer {
- public:
- StreamLayer() {}
- };
+ class SWIFTEN_API StreamLayer : public LowLayer, public HighLayer {
+ public:
+ StreamLayer() {}
+ };
}
diff --git a/Swiften/StreamStack/StreamStack.cpp b/Swiften/StreamStack/StreamStack.cpp
index 99e2bcd..0bcd1b3 100644
--- a/Swiften/StreamStack/StreamStack.cpp
+++ b/Swiften/StreamStack/StreamStack.cpp
@@ -16,23 +16,23 @@
namespace Swift {
StreamStack::StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer) : xmppLayer_(xmppLayer), physicalLayer_(physicalLayer) {
- physicalLayer_->setParentLayer(xmppLayer_);
- xmppLayer_->setChildLayer(physicalLayer_);
+ physicalLayer_->setParentLayer(xmppLayer_);
+ xmppLayer_->setChildLayer(physicalLayer_);
}
StreamStack::~StreamStack() {
}
void StreamStack::addLayer(StreamLayer* newLayer) {
- LowLayer* lowLayer = layers_.empty() ? physicalLayer_ : *layers_.rbegin();
+ LowLayer* lowLayer = layers_.empty() ? physicalLayer_ : *layers_.rbegin();
- xmppLayer_->setChildLayer(newLayer);
- newLayer->setParentLayer(xmppLayer_);
-
- lowLayer->setParentLayer(newLayer);
- newLayer->setChildLayer(lowLayer);
+ xmppLayer_->setChildLayer(newLayer);
+ newLayer->setParentLayer(xmppLayer_);
- layers_.push_back(newLayer);
+ lowLayer->setParentLayer(newLayer);
+ newLayer->setChildLayer(lowLayer);
+
+ layers_.push_back(newLayer);
}
}
diff --git a/Swiften/StreamStack/StreamStack.h b/Swiften/StreamStack/StreamStack.h
index 8bf91b0..2a0b1f1 100644
--- a/Swiften/StreamStack/StreamStack.h
+++ b/Swiften/StreamStack/StreamStack.h
@@ -15,34 +15,34 @@
#include <Swiften/Elements/Stanza.h>
namespace Swift {
- class XMPPLayer;
- class LowLayer;
- class StreamLayer;
-
- class SWIFTEN_API StreamStack {
- public:
- StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer);
- ~StreamStack();
-
- void addLayer(StreamLayer*);
-
- XMPPLayer* getXMPPLayer() const {
- return xmppLayer_;
- }
-
- template<typename T> T* getLayer() {
- for (size_t i = 0; i < layers_.size(); ++i) {
- T* layer = dynamic_cast<T*>(layers_[i]);
- if (layer) {
- return layer;
- }
- }
- return NULL;
- }
-
- private:
- XMPPLayer* xmppLayer_;
- LowLayer* physicalLayer_;
- std::vector<StreamLayer*> layers_;
- };
+ class XMPPLayer;
+ class LowLayer;
+ class StreamLayer;
+
+ class SWIFTEN_API StreamStack {
+ public:
+ StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer);
+ ~StreamStack();
+
+ void addLayer(StreamLayer*);
+
+ XMPPLayer* getXMPPLayer() const {
+ return xmppLayer_;
+ }
+
+ template<typename T> T* getLayer() {
+ for (size_t i = 0; i < layers_.size(); ++i) {
+ T* layer = dynamic_cast<T*>(layers_[i]);
+ if (layer) {
+ return layer;
+ }
+ }
+ return NULL;
+ }
+
+ private:
+ XMPPLayer* xmppLayer_;
+ LowLayer* physicalLayer_;
+ std::vector<StreamLayer*> layers_;
+ };
}
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp
index bb0fe0f..3ab885a 100644
--- a/Swiften/StreamStack/TLSLayer.cpp
+++ b/Swiften/StreamStack/TLSLayer.cpp
@@ -14,43 +14,43 @@
namespace Swift {
TLSLayer::TLSLayer(TLSContextFactory* factory, const TLSOptions& tlsOptions) {
- context = factory->createTLSContext(tlsOptions);
- context->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
- context->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
- context->onConnected.connect(onConnected);
- context->onError.connect(onError);
+ context = factory->createTLSContext(tlsOptions);
+ context->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
+ context->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
+ context->onConnected.connect(onConnected);
+ context->onError.connect(onError);
}
TLSLayer::~TLSLayer() {
- delete context;
+ delete context;
}
void TLSLayer::connect() {
- context->connect();
+ context->connect();
}
void TLSLayer::writeData(const SafeByteArray& data) {
- context->handleDataFromApplication(data);
+ context->handleDataFromApplication(data);
}
void TLSLayer::handleDataRead(const SafeByteArray& data) {
- context->handleDataFromNetwork(data);
+ context->handleDataFromNetwork(data);
}
bool TLSLayer::setClientCertificate(CertificateWithKey::ref certificate) {
- return context->setClientCertificate(certificate);
+ return context->setClientCertificate(certificate);
}
Certificate::ref TLSLayer::getPeerCertificate() const {
- return context->getPeerCertificate();
+ return context->getPeerCertificate();
}
std::vector<Certificate::ref> TLSLayer::getPeerCertificateChain() const {
- return context->getPeerCertificateChain();
+ return context->getPeerCertificateChain();
}
boost::shared_ptr<CertificateVerificationError> TLSLayer::getPeerCertificateVerificationError() const {
- return context->getPeerCertificateVerificationError();
+ return context->getPeerCertificateVerificationError();
}
}
diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h
index 0ab35d5..b9072f3 100644
--- a/Swiften/StreamStack/TLSLayer.h
+++ b/Swiften/StreamStack/TLSLayer.h
@@ -17,33 +17,33 @@
#include <Swiften/TLS/TLSOptions.h>
namespace Swift {
- class TLSContext;
- class TLSContextFactory;
+ class TLSContext;
+ class TLSContextFactory;
- class SWIFTEN_API TLSLayer : public StreamLayer {
- public:
- TLSLayer(TLSContextFactory*, const TLSOptions&);
- virtual ~TLSLayer();
+ class SWIFTEN_API TLSLayer : public StreamLayer {
+ public:
+ TLSLayer(TLSContextFactory*, const TLSOptions&);
+ virtual ~TLSLayer();
- void connect();
- bool setClientCertificate(CertificateWithKey::ref cert);
+ void connect();
+ bool setClientCertificate(CertificateWithKey::ref cert);
- Certificate::ref getPeerCertificate() const;
- std::vector<Certificate::ref> getPeerCertificateChain() const;
- boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const;
+ Certificate::ref getPeerCertificate() const;
+ std::vector<Certificate::ref> getPeerCertificateChain() const;
+ boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const;
- void writeData(const SafeByteArray& data);
- void handleDataRead(const SafeByteArray& data);
+ void writeData(const SafeByteArray& data);
+ void handleDataRead(const SafeByteArray& data);
- TLSContext* getContext() const {
- return context;
- }
+ TLSContext* getContext() const {
+ return context;
+ }
- public:
- boost::signal<void (boost::shared_ptr<TLSError>)> onError;
- boost::signal<void ()> onConnected;
+ public:
+ boost::signal<void (boost::shared_ptr<TLSError>)> onError;
+ boost::signal<void ()> onConnected;
- private:
- TLSContext* context;
- };
+ private:
+ TLSContext* context;
+ };
}
diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
index 84a78fa..7044ad9 100644
--- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
+++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
@@ -27,157 +27,157 @@
using namespace Swift;
class StreamStackTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(StreamStackTest);
- CPPUNIT_TEST(testWriteData_NoIntermediateStreamStack);
- CPPUNIT_TEST(testWriteData_OneIntermediateStream);
- CPPUNIT_TEST(testWriteData_TwoIntermediateStreamStack);
- CPPUNIT_TEST(testReadData_NoIntermediateStreamStack);
- CPPUNIT_TEST(testReadData_OneIntermediateStream);
- CPPUNIT_TEST(testReadData_TwoIntermediateStreamStack);
- CPPUNIT_TEST(testAddLayer_ExistingOnWriteDataSlot);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- physicalStream_ = new TestLowLayer();
- xmppStream_ = new XMPPLayer(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType);
- elementsReceived_ = 0;
- dataWriteReceived_ = 0;
- }
-
- void tearDown() {
- delete physicalStream_;
- delete xmppStream_;
- }
-
- void testWriteData_NoIntermediateStreamStack() {
- StreamStack testling(xmppStream_, physicalStream_);
-
- xmppStream_->writeData("foo");
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
- CPPUNIT_ASSERT_EQUAL(createSafeByteArray("foo"), physicalStream_->data_[0]);
- }
-
- void testWriteData_OneIntermediateStream() {
- StreamStack testling(xmppStream_, physicalStream_);
- boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X"));
- testling.addLayer(xStream.get());
-
- xmppStream_->writeData("foo");
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
- CPPUNIT_ASSERT_EQUAL(createSafeByteArray("Xfoo"), physicalStream_->data_[0]);
- }
-
- void testWriteData_TwoIntermediateStreamStack() {
- StreamStack testling(xmppStream_, physicalStream_);
- boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X"));
- boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y"));
- testling.addLayer(xStream.get());
- testling.addLayer(yStream.get());
-
- xmppStream_->writeData("foo");
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
- CPPUNIT_ASSERT_EQUAL(createSafeByteArray("XYfoo"), physicalStream_->data_[0]);
- }
-
- void testReadData_NoIntermediateStreamStack() {
- StreamStack testling(xmppStream_, physicalStream_);
- xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1));
-
- physicalStream_->onDataRead(createSafeByteArray("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
-
- CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
- }
-
- void testReadData_OneIntermediateStream() {
- StreamStack testling(xmppStream_, physicalStream_);
- xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1));
- boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("<"));
- testling.addLayer(xStream.get());
-
- physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
-
- CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
- }
-
- void testReadData_TwoIntermediateStreamStack() {
- StreamStack testling(xmppStream_, physicalStream_);
- xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1));
- boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("s"));
- boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("<"));
- testling.addLayer(xStream.get());
- testling.addLayer(yStream.get());
-
- physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
-
- CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
- }
-
- void testAddLayer_ExistingOnWriteDataSlot() {
- StreamStack testling(xmppStream_, physicalStream_);
- xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1));
- boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X"));
- testling.addLayer(xStream.get());
-
- xmppStream_->writeData("foo");
-
- CPPUNIT_ASSERT_EQUAL(1, dataWriteReceived_);
- }
-
- void handleElement(boost::shared_ptr<ToplevelElement>) {
- ++elementsReceived_;
- }
-
- void handleWriteData(const SafeByteArray&) {
- ++dataWriteReceived_;
- }
-
- private:
- class MyStreamLayer : public StreamLayer {
- public:
- MyStreamLayer(const std::string& prepend) : prepend_(prepend) {
- }
-
- virtual void writeData(const SafeByteArray& data) {
- writeDataToChildLayer(concat(createSafeByteArray(prepend_), data));
- }
-
- virtual void handleDataRead(const SafeByteArray& data) {
- writeDataToParentLayer(concat(createSafeByteArray(prepend_), data));
- }
-
- private:
- std::string prepend_;
- };
-
- class TestLowLayer : public LowLayer {
- public:
- TestLowLayer() {
- }
-
- virtual void writeData(const SafeByteArray& data) {
- data_.push_back(data);
- }
-
- void onDataRead(const SafeByteArray& data) {
- writeDataToParentLayer(data);
- }
-
- std::vector<SafeByteArray> data_;
- };
-
-
- private:
- FullPayloadParserFactoryCollection parserFactories_;
- FullPayloadSerializerCollection serializers_;
- TestLowLayer* physicalStream_;
- PlatformXMLParserFactory xmlParserFactory_;
- XMPPLayer* xmppStream_;
- int elementsReceived_;
- int dataWriteReceived_;
+ CPPUNIT_TEST_SUITE(StreamStackTest);
+ CPPUNIT_TEST(testWriteData_NoIntermediateStreamStack);
+ CPPUNIT_TEST(testWriteData_OneIntermediateStream);
+ CPPUNIT_TEST(testWriteData_TwoIntermediateStreamStack);
+ CPPUNIT_TEST(testReadData_NoIntermediateStreamStack);
+ CPPUNIT_TEST(testReadData_OneIntermediateStream);
+ CPPUNIT_TEST(testReadData_TwoIntermediateStreamStack);
+ CPPUNIT_TEST(testAddLayer_ExistingOnWriteDataSlot);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ physicalStream_ = new TestLowLayer();
+ xmppStream_ = new XMPPLayer(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType);
+ elementsReceived_ = 0;
+ dataWriteReceived_ = 0;
+ }
+
+ void tearDown() {
+ delete physicalStream_;
+ delete xmppStream_;
+ }
+
+ void testWriteData_NoIntermediateStreamStack() {
+ StreamStack testling(xmppStream_, physicalStream_);
+
+ xmppStream_->writeData("foo");
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("foo"), physicalStream_->data_[0]);
+ }
+
+ void testWriteData_OneIntermediateStream() {
+ StreamStack testling(xmppStream_, physicalStream_);
+ boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X"));
+ testling.addLayer(xStream.get());
+
+ xmppStream_->writeData("foo");
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("Xfoo"), physicalStream_->data_[0]);
+ }
+
+ void testWriteData_TwoIntermediateStreamStack() {
+ StreamStack testling(xmppStream_, physicalStream_);
+ boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X"));
+ boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y"));
+ testling.addLayer(xStream.get());
+ testling.addLayer(yStream.get());
+
+ xmppStream_->writeData("foo");
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("XYfoo"), physicalStream_->data_[0]);
+ }
+
+ void testReadData_NoIntermediateStreamStack() {
+ StreamStack testling(xmppStream_, physicalStream_);
+ xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1));
+
+ physicalStream_->onDataRead(createSafeByteArray("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
+
+ CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
+ }
+
+ void testReadData_OneIntermediateStream() {
+ StreamStack testling(xmppStream_, physicalStream_);
+ xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1));
+ boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("<"));
+ testling.addLayer(xStream.get());
+
+ physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
+
+ CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
+ }
+
+ void testReadData_TwoIntermediateStreamStack() {
+ StreamStack testling(xmppStream_, physicalStream_);
+ xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1));
+ boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("s"));
+ boost::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("<"));
+ testling.addLayer(xStream.get());
+ testling.addLayer(yStream.get());
+
+ physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
+
+ CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
+ }
+
+ void testAddLayer_ExistingOnWriteDataSlot() {
+ StreamStack testling(xmppStream_, physicalStream_);
+ xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1));
+ boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X"));
+ testling.addLayer(xStream.get());
+
+ xmppStream_->writeData("foo");
+
+ CPPUNIT_ASSERT_EQUAL(1, dataWriteReceived_);
+ }
+
+ void handleElement(boost::shared_ptr<ToplevelElement>) {
+ ++elementsReceived_;
+ }
+
+ void handleWriteData(const SafeByteArray&) {
+ ++dataWriteReceived_;
+ }
+
+ private:
+ class MyStreamLayer : public StreamLayer {
+ public:
+ MyStreamLayer(const std::string& prepend) : prepend_(prepend) {
+ }
+
+ virtual void writeData(const SafeByteArray& data) {
+ writeDataToChildLayer(concat(createSafeByteArray(prepend_), data));
+ }
+
+ virtual void handleDataRead(const SafeByteArray& data) {
+ writeDataToParentLayer(concat(createSafeByteArray(prepend_), data));
+ }
+
+ private:
+ std::string prepend_;
+ };
+
+ class TestLowLayer : public LowLayer {
+ public:
+ TestLowLayer() {
+ }
+
+ virtual void writeData(const SafeByteArray& data) {
+ data_.push_back(data);
+ }
+
+ void onDataRead(const SafeByteArray& data) {
+ writeDataToParentLayer(data);
+ }
+
+ std::vector<SafeByteArray> data_;
+ };
+
+
+ private:
+ FullPayloadParserFactoryCollection parserFactories_;
+ FullPayloadSerializerCollection serializers_;
+ TestLowLayer* physicalStream_;
+ PlatformXMLParserFactory xmlParserFactory_;
+ XMPPLayer* xmppStream_;
+ int elementsReceived_;
+ int dataWriteReceived_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(StreamStackTest);
diff --git a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
index 0250666..86e02ba 100644
--- a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
+++ b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
@@ -23,121 +23,121 @@
using namespace Swift;
class XMPPLayerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(XMPPLayerTest);
- CPPUNIT_TEST(testParseData_Error);
- CPPUNIT_TEST(testResetParser);
- CPPUNIT_TEST(testResetParser_FromSlot);
- CPPUNIT_TEST(testWriteHeader);
- CPPUNIT_TEST(testWriteElement);
- CPPUNIT_TEST(testWriteFooter);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- lowLayer_ = new DummyLowLayer();
- testling_ = new XMPPLayerExposed(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType);
- testling_->setChildLayer(lowLayer_);
- elementsReceived_ = 0;
- errorReceived_ = 0;
- }
-
- void tearDown() {
- delete testling_;
- delete lowLayer_;
- }
-
- void testParseData_Error() {
- testling_->onError.connect(boost::bind(&XMPPLayerTest::handleError, this));
-
- testling_->handleDataRead(createSafeByteArray("<iq>"));
-
- CPPUNIT_ASSERT_EQUAL(1, errorReceived_);
- }
-
- void testResetParser() {
- testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElement, this, _1));
- testling_->onError.connect(boost::bind(&XMPPLayerTest::handleError, this));
-
- testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
- testling_->resetParser();
- testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
- testling_->handleDataRead(createSafeByteArray("<presence/>"));
-
- CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
- CPPUNIT_ASSERT_EQUAL(0, errorReceived_);
- }
-
- void testResetParser_FromSlot() {
- testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElementAndReset, this, _1));
- testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>"));
- testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>"));
-
- CPPUNIT_ASSERT_EQUAL(2, elementsReceived_);
- CPPUNIT_ASSERT_EQUAL(0, errorReceived_);
- }
-
- void testWriteHeader() {
- ProtocolHeader header;
- header.setTo("example.com");
- testling_->writeHeader(header);
-
- CPPUNIT_ASSERT_EQUAL(std::string("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"example.com\" version=\"1.0\">"), lowLayer_->writtenData);
- }
-
- void testWriteElement() {
- testling_->writeElement(boost::make_shared<Presence>());
-
- CPPUNIT_ASSERT_EQUAL(std::string("<presence/>"), lowLayer_->writtenData);
- }
-
- void testWriteFooter() {
- testling_->writeFooter();
-
- CPPUNIT_ASSERT_EQUAL(std::string("</stream:stream>"), lowLayer_->writtenData);
- }
-
- void handleElement(boost::shared_ptr<ToplevelElement>) {
- ++elementsReceived_;
- }
-
- void handleElementAndReset(boost::shared_ptr<ToplevelElement>) {
- ++elementsReceived_;
- testling_->resetParser();
- }
-
- void handleError() {
- ++errorReceived_;
- }
-
- private:
- class XMPPLayerExposed : public XMPPLayer {
- public:
- XMPPLayerExposed(
- PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers,
- XMLParserFactory* xmlParserFactory,
- StreamType streamType) : XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType) {}
-
- using XMPPLayer::handleDataRead;
- using HighLayer::setChildLayer;
- };
-
- class DummyLowLayer : public LowLayer {
- public:
- virtual void writeData(const SafeByteArray& data) {
- writtenData += byteArrayToString(ByteArray(data.begin(), data.end()));
- }
-
- std::string writtenData;
- };
-
- FullPayloadParserFactoryCollection parserFactories_;
- FullPayloadSerializerCollection serializers_;
- DummyLowLayer* lowLayer_;
- XMPPLayerExposed* testling_;
- PlatformXMLParserFactory xmlParserFactory_;
- int elementsReceived_;
- int errorReceived_;
+ CPPUNIT_TEST_SUITE(XMPPLayerTest);
+ CPPUNIT_TEST(testParseData_Error);
+ CPPUNIT_TEST(testResetParser);
+ CPPUNIT_TEST(testResetParser_FromSlot);
+ CPPUNIT_TEST(testWriteHeader);
+ CPPUNIT_TEST(testWriteElement);
+ CPPUNIT_TEST(testWriteFooter);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ lowLayer_ = new DummyLowLayer();
+ testling_ = new XMPPLayerExposed(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType);
+ testling_->setChildLayer(lowLayer_);
+ elementsReceived_ = 0;
+ errorReceived_ = 0;
+ }
+
+ void tearDown() {
+ delete testling_;
+ delete lowLayer_;
+ }
+
+ void testParseData_Error() {
+ testling_->onError.connect(boost::bind(&XMPPLayerTest::handleError, this));
+
+ testling_->handleDataRead(createSafeByteArray("<iq>"));
+
+ CPPUNIT_ASSERT_EQUAL(1, errorReceived_);
+ }
+
+ void testResetParser() {
+ testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElement, this, _1));
+ testling_->onError.connect(boost::bind(&XMPPLayerTest::handleError, this));
+
+ testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
+ testling_->resetParser();
+ testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
+ testling_->handleDataRead(createSafeByteArray("<presence/>"));
+
+ CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, errorReceived_);
+ }
+
+ void testResetParser_FromSlot() {
+ testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElementAndReset, this, _1));
+ testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>"));
+ testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>"));
+
+ CPPUNIT_ASSERT_EQUAL(2, elementsReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, errorReceived_);
+ }
+
+ void testWriteHeader() {
+ ProtocolHeader header;
+ header.setTo("example.com");
+ testling_->writeHeader(header);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<?xml version=\"1.0\"?><stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"example.com\" version=\"1.0\">"), lowLayer_->writtenData);
+ }
+
+ void testWriteElement() {
+ testling_->writeElement(boost::make_shared<Presence>());
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<presence/>"), lowLayer_->writtenData);
+ }
+
+ void testWriteFooter() {
+ testling_->writeFooter();
+
+ CPPUNIT_ASSERT_EQUAL(std::string("</stream:stream>"), lowLayer_->writtenData);
+ }
+
+ void handleElement(boost::shared_ptr<ToplevelElement>) {
+ ++elementsReceived_;
+ }
+
+ void handleElementAndReset(boost::shared_ptr<ToplevelElement>) {
+ ++elementsReceived_;
+ testling_->resetParser();
+ }
+
+ void handleError() {
+ ++errorReceived_;
+ }
+
+ private:
+ class XMPPLayerExposed : public XMPPLayer {
+ public:
+ XMPPLayerExposed(
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
+ StreamType streamType) : XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType) {}
+
+ using XMPPLayer::handleDataRead;
+ using HighLayer::setChildLayer;
+ };
+
+ class DummyLowLayer : public LowLayer {
+ public:
+ virtual void writeData(const SafeByteArray& data) {
+ writtenData += byteArrayToString(ByteArray(data.begin(), data.end()));
+ }
+
+ std::string writtenData;
+ };
+
+ FullPayloadParserFactoryCollection parserFactories_;
+ FullPayloadSerializerCollection serializers_;
+ DummyLowLayer* lowLayer_;
+ XMPPLayerExposed* testling_;
+ PlatformXMLParserFactory xmlParserFactory_;
+ int elementsReceived_;
+ int errorReceived_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(XMPPLayerTest);
diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp
index 5ea5423..9a473f3 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.cpp
+++ b/Swiften/StreamStack/WhitespacePingLayer.cpp
@@ -17,40 +17,40 @@ namespace Swift {
static const int TIMEOUT_MILLISECONDS = 60000;
WhitespacePingLayer::WhitespacePingLayer(TimerFactory* timerFactory) : isActive(false) {
- timer = timerFactory->createTimer(TIMEOUT_MILLISECONDS);
- timer->onTick.connect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
+ timer = timerFactory->createTimer(TIMEOUT_MILLISECONDS);
+ timer->onTick.connect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
}
WhitespacePingLayer::~WhitespacePingLayer() {
- SWIFT_LOG_ASSERT(!isActive, debug) << "WhitespacePingLayer still active at destruction." << std::endl;
- if (isActive) {
- timer->stop();
- }
- timer->onTick.disconnect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
+ SWIFT_LOG_ASSERT(!isActive, debug) << "WhitespacePingLayer still active at destruction." << std::endl;
+ if (isActive) {
+ timer->stop();
+ }
+ timer->onTick.disconnect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
}
void WhitespacePingLayer::writeData(const SafeByteArray& data) {
- writeDataToChildLayer(data);
+ writeDataToChildLayer(data);
}
void WhitespacePingLayer::handleDataRead(const SafeByteArray& data) {
- writeDataToParentLayer(data);
+ writeDataToParentLayer(data);
}
void WhitespacePingLayer::handleTimerTick() {
- timer->stop();
- writeDataToChildLayer(createSafeByteArray(" "));
- timer->start();
+ timer->stop();
+ writeDataToChildLayer(createSafeByteArray(" "));
+ timer->start();
}
void WhitespacePingLayer::setActive() {
- isActive = true;
- timer->start();
+ isActive = true;
+ timer->start();
}
void WhitespacePingLayer::setInactive() {
- timer->stop();
- isActive = false;
+ timer->stop();
+ isActive = false;
}
}
diff --git a/Swiften/StreamStack/WhitespacePingLayer.h b/Swiften/StreamStack/WhitespacePingLayer.h
index 7ed56ca..41189ba 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.h
+++ b/Swiften/StreamStack/WhitespacePingLayer.h
@@ -13,28 +13,28 @@
#include <Swiften/StreamStack/StreamLayer.h>
namespace Swift {
- class Timer;
- class TimerFactory;
-
- class SWIFTEN_API WhitespacePingLayer : public StreamLayer, boost::noncopyable {
- public:
- WhitespacePingLayer(TimerFactory* timerFactory);
- virtual ~WhitespacePingLayer();
-
- void setActive();
- void setInactive();
- void writeData(const SafeByteArray& data);
- void handleDataRead(const SafeByteArray& data);
-
- bool getIsActive() const {
- return isActive;
- }
-
- private:
- void handleTimerTick();
-
- private:
- bool isActive;
- boost::shared_ptr<Timer> timer;
- };
+ class Timer;
+ class TimerFactory;
+
+ class SWIFTEN_API WhitespacePingLayer : public StreamLayer, boost::noncopyable {
+ public:
+ WhitespacePingLayer(TimerFactory* timerFactory);
+ virtual ~WhitespacePingLayer();
+
+ void setActive();
+ void setInactive();
+ void writeData(const SafeByteArray& data);
+ void handleDataRead(const SafeByteArray& data);
+
+ bool getIsActive() const {
+ return isActive;
+ }
+
+ private:
+ void handleTimerTick();
+
+ private:
+ bool isActive;
+ boost::shared_ptr<Timer> timer;
+ };
}
diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp
index 2f7e578..e0d683c 100644
--- a/Swiften/StreamStack/XMPPLayer.cpp
+++ b/Swiften/StreamStack/XMPPLayer.cpp
@@ -13,88 +13,88 @@
namespace Swift {
XMPPLayer::XMPPLayer(
- PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers,
- XMLParserFactory* xmlParserFactory,
- StreamType streamType,
- bool setExplictNSonTopLevelElements) :
- payloadParserFactories_(payloadParserFactories),
- payloadSerializers_(payloadSerializers),
- xmlParserFactory_(xmlParserFactory),
- setExplictNSonTopLevelElements_(setExplictNSonTopLevelElements),
- resetParserAfterParse_(false),
- inParser_(false) {
- xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory);
- xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType, setExplictNSonTopLevelElements);
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
+ StreamType streamType,
+ bool setExplictNSonTopLevelElements) :
+ payloadParserFactories_(payloadParserFactories),
+ payloadSerializers_(payloadSerializers),
+ xmlParserFactory_(xmlParserFactory),
+ setExplictNSonTopLevelElements_(setExplictNSonTopLevelElements),
+ resetParserAfterParse_(false),
+ inParser_(false) {
+ xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory);
+ xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType, setExplictNSonTopLevelElements);
}
XMPPLayer::~XMPPLayer() {
- delete xmppSerializer_;
- delete xmppParser_;
+ delete xmppSerializer_;
+ delete xmppParser_;
}
void XMPPLayer::writeHeader(const ProtocolHeader& header) {
- writeDataInternal(createSafeByteArray(xmppSerializer_->serializeHeader(header)));
+ writeDataInternal(createSafeByteArray(xmppSerializer_->serializeHeader(header)));
}
void XMPPLayer::writeFooter() {
- writeDataInternal(createSafeByteArray(xmppSerializer_->serializeFooter()));
+ writeDataInternal(createSafeByteArray(xmppSerializer_->serializeFooter()));
}
void XMPPLayer::writeElement(boost::shared_ptr<ToplevelElement> element) {
- writeDataInternal(xmppSerializer_->serializeElement(element));
+ writeDataInternal(xmppSerializer_->serializeElement(element));
}
void XMPPLayer::writeData(const std::string& data) {
- writeDataInternal(createSafeByteArray(data));
+ writeDataInternal(createSafeByteArray(data));
}
void XMPPLayer::writeDataInternal(const SafeByteArray& data) {
- onWriteData(data);
- writeDataToChildLayer(data);
+ onWriteData(data);
+ writeDataToChildLayer(data);
}
void XMPPLayer::handleDataRead(const SafeByteArray& data) {
- onDataRead(data);
- inParser_ = true;
- // FIXME: Converting to unsafe string. Should be ok, since we don't take passwords
- // from the stream in clients. If servers start using this, and require safe storage,
- // we need to fix this.
- if (!xmppParser_->parse(byteArrayToString(ByteArray(data.begin(), data.end())))) {
- inParser_ = false;
- onError();
- return;
- }
- inParser_ = false;
- if (resetParserAfterParse_) {
- doResetParser();
- }
+ onDataRead(data);
+ inParser_ = true;
+ // FIXME: Converting to unsafe string. Should be ok, since we don't take passwords
+ // from the stream in clients. If servers start using this, and require safe storage,
+ // we need to fix this.
+ if (!xmppParser_->parse(byteArrayToString(ByteArray(data.begin(), data.end())))) {
+ inParser_ = false;
+ onError();
+ return;
+ }
+ inParser_ = false;
+ if (resetParserAfterParse_) {
+ doResetParser();
+ }
}
void XMPPLayer::doResetParser() {
- delete xmppParser_;
- xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory_);
- resetParserAfterParse_ = false;
+ delete xmppParser_;
+ xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory_);
+ resetParserAfterParse_ = false;
}
void XMPPLayer::handleStreamStart(const ProtocolHeader& header) {
- onStreamStart(header);
+ onStreamStart(header);
}
void XMPPLayer::handleElement(boost::shared_ptr<ToplevelElement> stanza) {
- onElement(stanza);
+ onElement(stanza);
}
void XMPPLayer::handleStreamEnd() {
}
void XMPPLayer::resetParser() {
- if (inParser_) {
- resetParserAfterParse_ = true;
- }
- else {
- doResetParser();
- }
+ if (inParser_) {
+ resetParserAfterParse_ = true;
+ }
+ else {
+ doResetParser();
+ }
}
}
diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h
index 1bf145d..25d48bf 100644
--- a/Swiften/StreamStack/XMPPLayer.h
+++ b/Swiften/StreamStack/XMPPLayer.h
@@ -18,58 +18,58 @@
#include <Swiften/StreamStack/HighLayer.h>
namespace Swift {
- class ProtocolHeader;
- class XMPPParser;
- class PayloadParserFactoryCollection;
- class XMPPSerializer;
- class PayloadSerializerCollection;
- class XMLParserFactory;
- class BOSHSessionStream;
+ class ProtocolHeader;
+ class XMPPParser;
+ class PayloadParserFactoryCollection;
+ class XMPPSerializer;
+ class PayloadSerializerCollection;
+ class XMLParserFactory;
+ class BOSHSessionStream;
- class SWIFTEN_API XMPPLayer : public XMPPParserClient, public HighLayer, boost::noncopyable {
- friend class BOSHSessionStream;
- public:
- XMPPLayer(
- PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers,
- XMLParserFactory* xmlParserFactory,
- StreamType streamType,
- bool setExplictNSonTopLevelElements = false);
- virtual ~XMPPLayer();
+ class SWIFTEN_API XMPPLayer : public XMPPParserClient, public HighLayer, boost::noncopyable {
+ friend class BOSHSessionStream;
+ public:
+ XMPPLayer(
+ PayloadParserFactoryCollection* payloadParserFactories,
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
+ StreamType streamType,
+ bool setExplictNSonTopLevelElements = false);
+ virtual ~XMPPLayer();
- void writeHeader(const ProtocolHeader& header);
- void writeFooter();
- void writeElement(boost::shared_ptr<ToplevelElement>);
- void writeData(const std::string& data);
+ void writeHeader(const ProtocolHeader& header);
+ void writeFooter();
+ void writeElement(boost::shared_ptr<ToplevelElement>);
+ void writeData(const std::string& data);
- void resetParser();
+ void resetParser();
- protected:
- void handleDataRead(const SafeByteArray& data);
- void writeDataInternal(const SafeByteArray& data);
+ protected:
+ void handleDataRead(const SafeByteArray& data);
+ void writeDataInternal(const SafeByteArray& data);
- public:
- boost::signal<void (const ProtocolHeader&)> onStreamStart;
- boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElement;
- boost::signal<void (const SafeByteArray&)> onWriteData;
- boost::signal<void (const SafeByteArray&)> onDataRead;
- boost::signal<void ()> onError;
+ public:
+ boost::signal<void (const ProtocolHeader&)> onStreamStart;
+ boost::signal<void (boost::shared_ptr<ToplevelElement>)> onElement;
+ boost::signal<void (const SafeByteArray&)> onWriteData;
+ boost::signal<void (const SafeByteArray&)> onDataRead;
+ boost::signal<void ()> onError;
- private:
- void handleStreamStart(const ProtocolHeader&);
- void handleElement(boost::shared_ptr<ToplevelElement>);
- void handleStreamEnd();
+ private:
+ void handleStreamStart(const ProtocolHeader&);
+ void handleElement(boost::shared_ptr<ToplevelElement>);
+ void handleStreamEnd();
- void doResetParser();
+ void doResetParser();
- private:
- PayloadParserFactoryCollection* payloadParserFactories_;
- XMPPParser* xmppParser_;
- PayloadSerializerCollection* payloadSerializers_;
- XMLParserFactory* xmlParserFactory_;
- XMPPSerializer* xmppSerializer_;
- bool setExplictNSonTopLevelElements_;
- bool resetParserAfterParse_;
- bool inParser_;
- };
+ private:
+ PayloadParserFactoryCollection* payloadParserFactories_;
+ XMPPParser* xmppParser_;
+ PayloadSerializerCollection* payloadSerializers_;
+ XMLParserFactory* xmlParserFactory_;
+ XMPPSerializer* xmppSerializer_;
+ bool setExplictNSonTopLevelElements_;
+ bool resetParserAfterParse_;
+ bool inParser_;
+ };
}