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/FileTransfer
parentb1b3b8f88517ad8b14795cc8a6265962d2935be3 (diff)
downloadswift-contrib-8472194d716e0e3b95a66bf5be45c246ee79d0af.zip
swift-contrib-8472194d716e0e3b95a66bf5be45c246ee79d0af.tar.bz2
Propagate use of SafeByteArray down to the connection.
Diffstat (limited to 'Swiften/FileTransfer')
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp9
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerSession.h2
-rw-r--r--Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp18
3 files changed, 15 insertions, 14 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
index fadfd46..477af4b 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
@@ -10,6 +10,7 @@
#include <iostream>
#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
#include <Swiften/Base/Algorithm.h>
#include <Swiften/Base/Concat.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
@@ -36,7 +37,7 @@ void SOCKS5BytestreamServerSession::stop() {
finish(false);
}
-void SOCKS5BytestreamServerSession::handleDataRead(const ByteArray& data) {
+void SOCKS5BytestreamServerSession::handleDataRead(const SafeByteArray& data) {
append(unprocessedData, data);
process();
}
@@ -56,7 +57,7 @@ void SOCKS5BytestreamServerSession::process() {
std::cerr << "SOCKS5BytestreamServerSession: Junk after authentication mechanism";
}
unprocessedData.clear();
- connection->write(createByteArray("\x05\x00", 2));
+ connection->write(createSafeByteArray("\x05\x00", 2));
state = WaitingForRequest;
}
}
@@ -77,7 +78,7 @@ void SOCKS5BytestreamServerSession::process() {
std::cerr << "SOCKS5BytestreamServerSession: Junk after authentication mechanism";
}
bytestream = bytestreams->getBytestream(byteArrayToString(requestID));
- ByteArray result = createByteArray("\x05", 1);
+ SafeByteArray result = createSafeByteArray("\x05", 1);
result.push_back(bytestream ? 0x0 : 0x4);
append(result, createByteArray("\x00\x03", 2));
result.push_back(static_cast<char>(requestID.size()));
@@ -99,7 +100,7 @@ void SOCKS5BytestreamServerSession::process() {
void SOCKS5BytestreamServerSession::sendData() {
if (!bytestream->isFinished()) {
try {
- connection->write(bytestream->read(chunkSize));
+ connection->write(createSafeByteArray(bytestream->read(chunkSize)));
}
catch (const BytestreamException&) {
finish(true);
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h
index 80965fb..761a365 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h
@@ -40,7 +40,7 @@ namespace Swift {
private:
void finish(bool error);
void process();
- void handleDataRead(const ByteArray&);
+ void handleDataRead(const SafeByteArray&);
void sendData();
private:
diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp
index d4c31c5..06bc98f 100644
--- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp
@@ -48,7 +48,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {
boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());
StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get());
- receive(createByteArray("\x05\x02\x01\x02"));
+ receive(createSafeByteArray("\x05\x02\x01\x02"));
CPPUNIT_ASSERT(createByteArray("\x05\x00", 2) == receivedData);
}
@@ -57,10 +57,10 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {
boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession());
StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get());
- receive(createByteArray("\x05\x02\x01"));
+ receive(createSafeByteArray("\x05\x02\x01"));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedData.size()));
- receive(createByteArray("\x01"));
+ receive(createSafeByteArray("\x01"));
CPPUNIT_ASSERT(createByteArray("\x05\x00", 2) == receivedData);
}
@@ -71,7 +71,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {
authenticate();
ByteArray hostname(createByteArray("abcdef"));
- receive(concat(createByteArray("\x05\x01\x00\x03", 4), createByteArray(hostname.size()), hostname, createByteArray("\x00\x00", 2)));
+ receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2)));
CPPUNIT_ASSERT(createByteArray("\x05\x00\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == createByteArray(&receivedData[0], 13));
}
@@ -81,7 +81,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {
authenticate();
ByteArray hostname(createByteArray("abcdef"));
- receive(concat(createByteArray("\x05\x01\x00\x03", 4), createByteArray(hostname.size()), hostname, createByteArray("\x00\x00", 2)));
+ receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2)));
CPPUNIT_ASSERT(createByteArray("\x05\x04\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == receivedData);
}
@@ -113,19 +113,19 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {
}
private:
- void receive(const ByteArray& data) {
+ void receive(const SafeByteArray& data) {
connection->receive(data);
eventLoop->processEvents();
}
void authenticate() {
- receive(createByteArray("\x05\x02\x01\x02"));
+ receive(createSafeByteArray("\x05\x02\x01\x02"));
receivedData.clear();
receivedDataChunks = 0;
}
void request(const std::string& hostname) {
- receive(concat(createByteArray("\x05\x01\x00\x03", 4), createByteArray(hostname.size()), createByteArray(hostname), createByteArray("\x00\x00", 2)));
+ receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2)));
}
void skipHeader(const std::string& hostname) {
@@ -134,7 +134,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture {
}
- void handleDataWritten(const ByteArray& data) {
+ void handleDataWritten(const SafeByteArray& data) {
receivedData.insert(receivedData.end(), data.begin(), data.end());
receivedDataChunks++;
}