summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp')
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
index 0fd40bf..a4ab751 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2018 Isode Limited. 2 * Copyright (c) 2010-2019 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -33,13 +33,13 @@ SOCKS5BytestreamServerSession::SOCKS5BytestreamServerSession(
33 33
34SOCKS5BytestreamServerSession::~SOCKS5BytestreamServerSession() { 34SOCKS5BytestreamServerSession::~SOCKS5BytestreamServerSession() {
35 if (state != Finished && state != Initial) { 35 if (state != Finished && state != Initial) {
36 SWIFT_LOG(warning) << "SOCKS5BytestreamServerSession unfinished" << std::endl; 36 SWIFT_LOG(warning) << "SOCKS5BytestreamServerSession unfinished";
37 finish(); 37 finish();
38 } 38 }
39} 39}
40 40
41void SOCKS5BytestreamServerSession::start() { 41void SOCKS5BytestreamServerSession::start() {
42 SWIFT_LOG(debug) << std::endl; 42 SWIFT_LOG(debug);
43 dataReadConnection = connection->onDataRead.connect( 43 dataReadConnection = connection->onDataRead.connect(
44 boost::bind(&SOCKS5BytestreamServerSession::handleDataRead, this, _1)); 44 boost::bind(&SOCKS5BytestreamServerSession::handleDataRead, this, _1));
45 state = WaitingForAuthentication; 45 state = WaitingForAuthentication;
@@ -50,7 +50,7 @@ void SOCKS5BytestreamServerSession::stop() {
50} 50}
51 51
52void SOCKS5BytestreamServerSession::startSending(std::shared_ptr<ReadBytestream> stream) { 52void SOCKS5BytestreamServerSession::startSending(std::shared_ptr<ReadBytestream> stream) {
53 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!" << std::endl; return; } 53 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!"; return; }
54 54
55 readBytestream = stream; 55 readBytestream = stream;
56 state = WritingData; 56 state = WritingData;
@@ -62,7 +62,7 @@ void SOCKS5BytestreamServerSession::startSending(std::shared_ptr<ReadBytestream>
62} 62}
63 63
64void SOCKS5BytestreamServerSession::startReceiving(std::shared_ptr<WriteBytestream> stream) { 64void SOCKS5BytestreamServerSession::startReceiving(std::shared_ptr<WriteBytestream> stream) {
65 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!" << std::endl; return; } 65 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!"; return; }
66 66
67 writeBytestream = stream; 67 writeBytestream = stream;
68 state = ReadingData; 68 state = ReadingData;
@@ -93,7 +93,7 @@ void SOCKS5BytestreamServerSession::handleDataAvailable() {
93} 93}
94 94
95void SOCKS5BytestreamServerSession::handleDisconnected(const boost::optional<Connection::Error>& error) { 95void SOCKS5BytestreamServerSession::handleDisconnected(const boost::optional<Connection::Error>& error) {
96 SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error") << std::endl; 96 SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error");
97 finish(error ? boost::optional<FileTransferError>(FileTransferError::PeerError) : boost::optional<FileTransferError>()); 97 finish(error ? boost::optional<FileTransferError>(FileTransferError::PeerError) : boost::optional<FileTransferError>());
98} 98}
99 99
@@ -109,7 +109,7 @@ void SOCKS5BytestreamServerSession::process() {
109 if (i == 2 + authCount) { 109 if (i == 2 + authCount) {
110 // Authentication message is complete 110 // Authentication message is complete
111 if (i != unprocessedData.size()) { 111 if (i != unprocessedData.size()) {
112 SWIFT_LOG(debug) << "Junk after authentication mechanism" << std::endl; 112 SWIFT_LOG(debug) << "Junk after authentication mechanism";
113 } 113 }
114 unprocessedData.clear(); 114 unprocessedData.clear();
115 connection->write(createSafeByteArray("\x05\x00", 2)); 115 connection->write(createSafeByteArray("\x05\x00", 2));
@@ -130,7 +130,7 @@ void SOCKS5BytestreamServerSession::process() {
130 i += 2; 130 i += 2;
131 if (i <= unprocessedData.size()) { 131 if (i <= unprocessedData.size()) {
132 if (i != unprocessedData.size()) { 132 if (i != unprocessedData.size()) {
133 SWIFT_LOG(debug) << "Junk after authentication mechanism" << std::endl; 133 SWIFT_LOG(debug) << "Junk after authentication mechanism";
134 } 134 }
135 unprocessedData.clear(); 135 unprocessedData.clear();
136 streamID = byteArrayToString(requestID); 136 streamID = byteArrayToString(requestID);
@@ -142,18 +142,18 @@ void SOCKS5BytestreamServerSession::process() {
142 result.push_back(boost::numeric_cast<unsigned char>(requestID.size())); 142 result.push_back(boost::numeric_cast<unsigned char>(requestID.size()));
143 } 143 }
144 catch (const boost::numeric::bad_numeric_cast& e) { 144 catch (const boost::numeric::bad_numeric_cast& e) {
145 SWIFT_LOG(warning) << "SOCKS5 request ID is too long (" << requestID.size() << "): " << e.what() << std::endl; 145 SWIFT_LOG(warning) << "SOCKS5 request ID is too long (" << requestID.size() << "): " << e.what();
146 finish(); 146 finish();
147 return; 147 return;
148 } 148 }
149 append(result, concat(requestID, createByteArray("\x00\x00", 2))); 149 append(result, concat(requestID, createByteArray("\x00\x00", 2)));
150 if (!hasBytestream) { 150 if (!hasBytestream) {
151 SWIFT_LOG(debug) << "Readstream or Wrtiestream with ID " << streamID << " not found!" << std::endl; 151 SWIFT_LOG(debug) << "Readstream or Wrtiestream with ID " << streamID << " not found!";
152 connection->write(result); 152 connection->write(result);
153 finish(boost::optional<FileTransferError>(FileTransferError::PeerError)); 153 finish(boost::optional<FileTransferError>(FileTransferError::PeerError));
154 } 154 }
155 else { 155 else {
156 SWIFT_LOG(debug) << "Found stream. Sent OK." << std::endl; 156 SWIFT_LOG(debug) << "Found stream. Sent OK.";
157 connection->write(result); 157 connection->write(result);
158 state = ReadyForTransfer; 158 state = ReadyForTransfer;
159 } 159 }
@@ -185,7 +185,7 @@ void SOCKS5BytestreamServerSession::sendData() {
185} 185}
186 186
187void SOCKS5BytestreamServerSession::finish(const boost::optional<FileTransferError>& error) { 187void SOCKS5BytestreamServerSession::finish(const boost::optional<FileTransferError>& error) {
188 SWIFT_LOG(debug) << "state: " << state << std::endl; 188 SWIFT_LOG(debug) << "state: " << state;
189 if (state == Finished) { 189 if (state == Finished) {
190 return; 190 return;
191 } 191 }