summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-05-18 16:22:06 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-05-18 16:50:18 (GMT)
commit8472194d716e0e3b95a66bf5be45c246ee79d0af (patch)
treeb9f473e0e606b012ee5013e85d2cf5e7523b7029 /Swiften/StreamStack
parentb1b3b8f88517ad8b14795cc8a6265962d2935be3 (diff)
downloadswift-contrib-8472194d716e0e3b95a66bf5be45c246ee79d0af.zip
swift-contrib-8472194d716e0e3b95a66bf5be45c246ee79d0af.tar.bz2
Propagate use of SafeByteArray down to the connection.
Diffstat (limited to 'Swiften/StreamStack')
-rw-r--r--Swiften/StreamStack/CompressionLayer.h6
-rw-r--r--Swiften/StreamStack/ConnectionLayer.h2
-rw-r--r--Swiften/StreamStack/HighLayer.cpp2
-rw-r--r--Swiften/StreamStack/HighLayer.h6
-rw-r--r--Swiften/StreamStack/LowLayer.cpp2
-rw-r--r--Swiften/StreamStack/LowLayer.h6
-rw-r--r--Swiften/StreamStack/TLSLayer.cpp4
-rw-r--r--Swiften/StreamStack/TLSLayer.h6
-rw-r--r--Swiften/StreamStack/UnitTest/StreamStackTest.cpp28
-rw-r--r--Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp16
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.cpp6
-rw-r--r--Swiften/StreamStack/WhitespacePingLayer.h4
-rw-r--r--Swiften/StreamStack/XMPPLayer.cpp17
-rw-r--r--Swiften/StreamStack/XMPPLayer.h10
14 files changed, 59 insertions, 56 deletions
diff --git a/Swiften/StreamStack/CompressionLayer.h b/Swiften/StreamStack/CompressionLayer.h
index b10ee52..783cfca 100644
--- a/Swiften/StreamStack/CompressionLayer.h
+++ b/Swiften/StreamStack/CompressionLayer.h
@@ -9,7 +9,7 @@
#include <boost/noncopyable.hpp>
#include <Swiften/Base/boost_bsignals.h>
-#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
#include <Swiften/StreamStack/StreamLayer.h>
#include <Swiften/Compress/ZLibException.h>
#include <Swiften/Compress/ZLibCompressor.h>
@@ -23,7 +23,7 @@ namespace Swift {
public:
CompressionLayer() {}
- virtual void writeData(const ByteArray& data) {
+ virtual void writeData(const SafeByteArray& data) {
try {
writeDataToChildLayer(compressor_.process(data));
}
@@ -32,7 +32,7 @@ namespace Swift {
}
}
- virtual void handleDataRead(const ByteArray& data) {
+ virtual void handleDataRead(const SafeByteArray& data) {
try {
writeDataToParentLayer(decompressor_.process(data));
}
diff --git a/Swiften/StreamStack/ConnectionLayer.h b/Swiften/StreamStack/ConnectionLayer.h
index fc33e48..8ccd33c 100644
--- a/Swiften/StreamStack/ConnectionLayer.h
+++ b/Swiften/StreamStack/ConnectionLayer.h
@@ -17,7 +17,7 @@ namespace Swift {
ConnectionLayer(boost::shared_ptr<Connection> connection);
~ConnectionLayer();
- void writeData(const ByteArray& data) {
+ void writeData(const SafeByteArray& data) {
connection->write(data);
}
diff --git a/Swiften/StreamStack/HighLayer.cpp b/Swiften/StreamStack/HighLayer.cpp
index 7203b7f..dc17c2a 100644
--- a/Swiften/StreamStack/HighLayer.cpp
+++ b/Swiften/StreamStack/HighLayer.cpp
@@ -18,7 +18,7 @@ HighLayer::HighLayer() : childLayer(NULL) {
HighLayer::~HighLayer() {
}
-void HighLayer::writeDataToChildLayer(const ByteArray& data) {
+void HighLayer::writeDataToChildLayer(const SafeByteArray& data) {
assert(childLayer);
childLayer->writeData(data);
}
diff --git a/Swiften/StreamStack/HighLayer.h b/Swiften/StreamStack/HighLayer.h
index b96458f..06b1d25 100644
--- a/Swiften/StreamStack/HighLayer.h
+++ b/Swiften/StreamStack/HighLayer.h
@@ -6,7 +6,7 @@
#pragma once
-#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
class LowLayer;
@@ -18,7 +18,7 @@ namespace Swift {
HighLayer();
virtual ~HighLayer();
- virtual void handleDataRead(const ByteArray& data) = 0;
+ virtual void handleDataRead(const SafeByteArray& data) = 0;
protected:
LowLayer* getChildLayer() {
@@ -29,7 +29,7 @@ namespace Swift {
this->childLayer = childLayer;
}
- void writeDataToChildLayer(const ByteArray& data);
+ void writeDataToChildLayer(const SafeByteArray& data);
private:
LowLayer* childLayer;
diff --git a/Swiften/StreamStack/LowLayer.cpp b/Swiften/StreamStack/LowLayer.cpp
index ed93cd2..ff4ca17 100644
--- a/Swiften/StreamStack/LowLayer.cpp
+++ b/Swiften/StreamStack/LowLayer.cpp
@@ -18,7 +18,7 @@ LowLayer::LowLayer() : parentLayer(NULL) {
LowLayer::~LowLayer() {
}
-void LowLayer::writeDataToParentLayer(const ByteArray& data) {
+void LowLayer::writeDataToParentLayer(const SafeByteArray& data) {
assert(parentLayer);
parentLayer->handleDataRead(data);
}
diff --git a/Swiften/StreamStack/LowLayer.h b/Swiften/StreamStack/LowLayer.h
index 87eb3de..00960ea 100644
--- a/Swiften/StreamStack/LowLayer.h
+++ b/Swiften/StreamStack/LowLayer.h
@@ -6,7 +6,7 @@
#pragma once
-#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
class HighLayer;
@@ -18,7 +18,7 @@ namespace Swift {
LowLayer();
virtual ~LowLayer();
- virtual void writeData(const ByteArray& data) = 0;
+ virtual void writeData(const SafeByteArray& data) = 0;
protected:
HighLayer* getParentLayer() {
@@ -29,7 +29,7 @@ namespace Swift {
this->parentLayer = parentLayer;
}
- void writeDataToParentLayer(const ByteArray& data);
+ void writeDataToParentLayer(const SafeByteArray& data);
private:
HighLayer* parentLayer;
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp
index 707b700..6f2223d 100644
--- a/Swiften/StreamStack/TLSLayer.cpp
+++ b/Swiften/StreamStack/TLSLayer.cpp
@@ -29,11 +29,11 @@ void TLSLayer::connect() {
context->connect();
}
-void TLSLayer::writeData(const ByteArray& data) {
+void TLSLayer::writeData(const SafeByteArray& data) {
context->handleDataFromApplication(data);
}
-void TLSLayer::handleDataRead(const ByteArray& data) {
+void TLSLayer::handleDataRead(const SafeByteArray& data) {
context->handleDataFromNetwork(data);
}
diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h
index bec63ee..a8693d5 100644
--- a/Swiften/StreamStack/TLSLayer.h
+++ b/Swiften/StreamStack/TLSLayer.h
@@ -6,7 +6,7 @@
#include <Swiften/Base/boost_bsignals.h>
-#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
#include <Swiften/StreamStack/StreamLayer.h>
#include <Swiften/TLS/Certificate.h>
#include <Swiften/TLS/CertificateVerificationError.h>
@@ -27,8 +27,8 @@ namespace Swift {
Certificate::ref getPeerCertificate() const;
boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const;
- void writeData(const ByteArray& data);
- void handleDataRead(const ByteArray& data);
+ void writeData(const SafeByteArray& data);
+ void handleDataRead(const SafeByteArray& data);
TLSContext* getContext() const {
return context;
diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
index 19dd37c..cf6b035 100644
--- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
+++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
@@ -54,7 +54,7 @@ class StreamStackTest : public CppUnit::TestFixture {
xmppStream_->writeData("foo");
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
- CPPUNIT_ASSERT_EQUAL(createByteArray("foo"), physicalStream_->data_[0]);
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("foo"), physicalStream_->data_[0]);
}
void testWriteData_OneIntermediateStream() {
@@ -65,7 +65,7 @@ class StreamStackTest : public CppUnit::TestFixture {
xmppStream_->writeData("foo");
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
- CPPUNIT_ASSERT_EQUAL(createByteArray("Xfoo"), physicalStream_->data_[0]);
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("Xfoo"), physicalStream_->data_[0]);
}
void testWriteData_TwoIntermediateStreamStack() {
@@ -78,14 +78,14 @@ class StreamStackTest : public CppUnit::TestFixture {
xmppStream_->writeData("foo");
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), physicalStream_->data_.size());
- CPPUNIT_ASSERT_EQUAL(createByteArray("XYfoo"), physicalStream_->data_[0]);
+ 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(createByteArray("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
+ physicalStream_->onDataRead(createSafeByteArray("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
}
@@ -96,7 +96,7 @@ class StreamStackTest : public CppUnit::TestFixture {
boost::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("<"));
testling.addLayer(xStream.get());
- physicalStream_->onDataRead(createByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
+ physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
}
@@ -109,7 +109,7 @@ class StreamStackTest : public CppUnit::TestFixture {
testling.addLayer(xStream.get());
testling.addLayer(yStream.get());
- physicalStream_->onDataRead(createByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
+ physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>"));
CPPUNIT_ASSERT_EQUAL(1, elementsReceived_);
}
@@ -129,7 +129,7 @@ class StreamStackTest : public CppUnit::TestFixture {
++elementsReceived_;
}
- void handleWriteData(ByteArray) {
+ void handleWriteData(const SafeByteArray&) {
++dataWriteReceived_;
}
@@ -139,12 +139,12 @@ class StreamStackTest : public CppUnit::TestFixture {
MyStreamLayer(const std::string& prepend) : prepend_(prepend) {
}
- virtual void writeData(const ByteArray& data) {
- writeDataToChildLayer(concat(createByteArray(prepend_), data));
+ virtual void writeData(const SafeByteArray& data) {
+ writeDataToChildLayer(concat(createSafeByteArray(prepend_), data));
}
- virtual void handleDataRead(const ByteArray& data) {
- writeDataToParentLayer(concat(createByteArray(prepend_), data));
+ virtual void handleDataRead(const SafeByteArray& data) {
+ writeDataToParentLayer(concat(createSafeByteArray(prepend_), data));
}
private:
@@ -156,15 +156,15 @@ class StreamStackTest : public CppUnit::TestFixture {
TestLowLayer() {
}
- virtual void writeData(const ByteArray& data) {
+ virtual void writeData(const SafeByteArray& data) {
data_.push_back(data);
}
- void onDataRead(const ByteArray& data) {
+ void onDataRead(const SafeByteArray& data) {
writeDataToParentLayer(data);
}
- std::vector<ByteArray> data_;
+ std::vector<SafeByteArray> data_;
};
diff --git a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
index 602699d..bb0ce61 100644
--- a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
+++ b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
@@ -46,7 +46,7 @@ class XMPPLayerTest : public CppUnit::TestFixture {
void testParseData_Error() {
testling_->onError.connect(boost::bind(&XMPPLayerTest::handleError, this));
- testling_->handleDataRead(createByteArray("<iq>"));
+ testling_->handleDataRead(createSafeByteArray("<iq>"));
CPPUNIT_ASSERT_EQUAL(1, errorReceived_);
}
@@ -55,10 +55,10 @@ class XMPPLayerTest : public CppUnit::TestFixture {
testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElement, this, _1));
testling_->onError.connect(boost::bind(&XMPPLayerTest::handleError, this));
- testling_->handleDataRead(createByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
+ testling_->handleDataRead(createSafeByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
testling_->resetParser();
- testling_->handleDataRead(createByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" >"));
- testling_->handleDataRead(createByteArray("<presence/>"));
+ 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_);
@@ -66,8 +66,8 @@ class XMPPLayerTest : public CppUnit::TestFixture {
void testResetParser_FromSlot() {
testling_->onElement.connect(boost::bind(&XMPPLayerTest::handleElementAndReset, this, _1));
- testling_->handleDataRead(createByteArray("<stream:stream to=\"example.com\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" ><presence/>"));
- testling_->handleDataRead(createByteArray("<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/>"));
+ 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_);
@@ -120,8 +120,8 @@ class XMPPLayerTest : public CppUnit::TestFixture {
class DummyLowLayer : public LowLayer {
public:
- virtual void writeData(const ByteArray& data) {
- writtenData += byteArrayToString(data);
+ virtual void writeData(const SafeByteArray& data) {
+ writtenData += byteArrayToString(ByteArray(data.begin(), data.end()));
}
std::string writtenData;
diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp
index 6a95899..b14f3a2 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.cpp
+++ b/Swiften/StreamStack/WhitespacePingLayer.cpp
@@ -20,17 +20,17 @@ WhitespacePingLayer::WhitespacePingLayer(TimerFactory* timerFactory) : isActive(
timer->onTick.connect(boost::bind(&WhitespacePingLayer::handleTimerTick, this));
}
-void WhitespacePingLayer::writeData(const ByteArray& data) {
+void WhitespacePingLayer::writeData(const SafeByteArray& data) {
writeDataToChildLayer(data);
}
-void WhitespacePingLayer::handleDataRead(const ByteArray& data) {
+void WhitespacePingLayer::handleDataRead(const SafeByteArray& data) {
writeDataToParentLayer(data);
}
void WhitespacePingLayer::handleTimerTick() {
timer->stop();
- writeDataToChildLayer(createByteArray(" "));
+ writeDataToChildLayer(createSafeByteArray(" "));
timer->start();
}
diff --git a/Swiften/StreamStack/WhitespacePingLayer.h b/Swiften/StreamStack/WhitespacePingLayer.h
index 7c42c29..1435842 100644
--- a/Swiften/StreamStack/WhitespacePingLayer.h
+++ b/Swiften/StreamStack/WhitespacePingLayer.h
@@ -21,8 +21,8 @@ namespace Swift {
void setActive();
void setInactive();
- void writeData(const ByteArray& data);
- void handleDataRead(const ByteArray& data);
+ void writeData(const SafeByteArray& data);
+ void handleDataRead(const SafeByteArray& data);
bool getIsActive() const {
return isActive;
diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp
index 37cda65..1de3a2a 100644
--- a/Swiften/StreamStack/XMPPLayer.cpp
+++ b/Swiften/StreamStack/XMPPLayer.cpp
@@ -29,30 +29,33 @@ XMPPLayer::~XMPPLayer() {
}
void XMPPLayer::writeHeader(const ProtocolHeader& header) {
- writeDataInternal(createByteArray(xmppSerializer_->serializeHeader(header)));
+ writeDataInternal(createSafeByteArray(xmppSerializer_->serializeHeader(header)));
}
void XMPPLayer::writeFooter() {
- writeDataInternal(createByteArray(xmppSerializer_->serializeFooter()));
+ writeDataInternal(createSafeByteArray(xmppSerializer_->serializeFooter()));
}
void XMPPLayer::writeElement(boost::shared_ptr<Element> element) {
- writeDataInternal(createByteArray(xmppSerializer_->serializeElement(element)));
+ writeDataInternal(createSafeByteArray(xmppSerializer_->serializeElement(element)));
}
void XMPPLayer::writeData(const std::string& data) {
- writeDataInternal(createByteArray(data));
+ writeDataInternal(createSafeByteArray(data));
}
-void XMPPLayer::writeDataInternal(const ByteArray& data) {
+void XMPPLayer::writeDataInternal(const SafeByteArray& data) {
onWriteData(data);
writeDataToChildLayer(data);
}
-void XMPPLayer::handleDataRead(const ByteArray& data) {
+void XMPPLayer::handleDataRead(const SafeByteArray& data) {
onDataRead(data);
inParser_ = true;
- if (!xmppParser_->parse(byteArrayToString(data))) {
+ // 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;
diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h
index 72d0e7e..54bdd42 100644
--- a/Swiften/StreamStack/XMPPLayer.h
+++ b/Swiften/StreamStack/XMPPLayer.h
@@ -11,7 +11,7 @@
#include <boost/noncopyable.hpp>
#include <Swiften/StreamStack/HighLayer.h>
-#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
#include <Swiften/Elements/Element.h>
#include <Swiften/Elements/StreamType.h>
#include <Swiften/Parser/XMPPParserClient.h>
@@ -39,14 +39,14 @@ namespace Swift {
void resetParser();
protected:
- void handleDataRead(const ByteArray& data);
- void writeDataInternal(const ByteArray& data);
+ void handleDataRead(const SafeByteArray& data);
+ void writeDataInternal(const SafeByteArray& data);
public:
boost::signal<void (const ProtocolHeader&)> onStreamStart;
boost::signal<void (boost::shared_ptr<Element>)> onElement;
- boost::signal<void (const ByteArray&)> onWriteData;
- boost::signal<void (const ByteArray&)> onDataRead;
+ boost::signal<void (const SafeByteArray&)> onWriteData;
+ boost::signal<void (const SafeByteArray&)> onDataRead;
boost::signal<void ()> onError;
private: