summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-05-03 20:39:27 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-05-05 19:43:14 (GMT)
commit772b2ec0243d7b55d91e4027d828881d18093ed0 (patch)
tree83a58b2b97f3992165ee20c05e0630452eb50457 /Swiften/Network
parent0b3db8fd68abee7269d5a38aabd8a816e099eae5 (diff)
downloadswift-772b2ec0243d7b55d91e4027d828881d18093ed0.zip
swift-772b2ec0243d7b55d91e4027d828881d18093ed0.tar.bz2
Replace ByteArray by typedef.
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BoostConnection.cpp9
-rw-r--r--Swiften/Network/HTTPConnectProxiedConnection.cpp8
-rw-r--r--Swiften/Network/PlatformDomainNameServiceQuery.cpp10
-rw-r--r--Swiften/Network/SOCKS5ProxiedConnection.cpp20
-rw-r--r--Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp30
-rw-r--r--Swiften/Network/WindowsProxyProvider.cpp8
6 files changed, 44 insertions, 41 deletions
diff --git a/Swiften/Network/BoostConnection.cpp b/Swiften/Network/BoostConnection.cpp
index 2fdb468..b56ad38 100644
--- a/Swiften/Network/BoostConnection.cpp
+++ b/Swiften/Network/BoostConnection.cpp
@@ -7,14 +7,15 @@
#include <Swiften/Network/BoostConnection.h>
#include <iostream>
+#include <string>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/asio/write.hpp>
#include <Swiften/Base/Log.h>
+#include <Swiften/Base/Algorithm.h>
#include <Swiften/EventLoop/EventLoop.h>
-#include <string>
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Network/HostAddressPort.h>
#include <Swiften/Base/sleep.h>
@@ -84,7 +85,7 @@ void BoostConnection::write(const ByteArray& data) {
doWrite(data);
}
else {
- writeQueue_ += data;
+ append(writeQueue_, data);
}
}
@@ -113,7 +114,7 @@ void BoostConnection::doRead() {
void BoostConnection::handleSocketRead(const boost::system::error_code& error, size_t bytesTransferred) {
SWIFT_LOG(debug) << "Socket read " << error << std::endl;
if (!error) {
- eventLoop->postEvent(boost::bind(boost::ref(onDataRead), ByteArray(&readBuffer_[0], bytesTransferred)), shared_from_this());
+ eventLoop->postEvent(boost::bind(boost::ref(onDataRead), createByteArray(&readBuffer_[0], bytesTransferred)), shared_from_this());
doRead();
}
else if (/*error == boost::asio::error::eof ||*/ error == boost::asio::error::operation_aborted) {
@@ -137,7 +138,7 @@ void BoostConnection::handleDataWritten(const boost::system::error_code& error)
}
{
boost::lock_guard<boost::mutex> lock(writeMutex_);
- if (writeQueue_.isEmpty()) {
+ if (writeQueue_.empty()) {
writing_ = false;
}
else {
diff --git a/Swiften/Network/HTTPConnectProxiedConnection.cpp b/Swiften/Network/HTTPConnectProxiedConnection.cpp
index dca08df..61fe597 100644
--- a/Swiften/Network/HTTPConnectProxiedConnection.cpp
+++ b/Swiften/Network/HTTPConnectProxiedConnection.cpp
@@ -66,7 +66,7 @@ void HTTPConnectProxiedConnection::handleConnectionConnectFinished(bool error) {
if (!error) {
std::stringstream connect;
connect << "CONNECT " << server_.getAddress().toString() << ":" << server_.getPort() << " HTTP/1.1\r\n\r\n";
- connection_->write(ByteArray(connect.str()));
+ connection_->write(createByteArray(connect.str()));
}
else {
onConnectFinished(true);
@@ -75,8 +75,8 @@ void HTTPConnectProxiedConnection::handleConnectionConnectFinished(bool error) {
void HTTPConnectProxiedConnection::handleDataRead(const ByteArray& data) {
if (!connected_) {
- SWIFT_LOG(debug) << data.toString() << std::endl;
- std::vector<std::string> tmp = String::split(data.toString(), ' ');
+ SWIFT_LOG(debug) << byteArrayToString(data) << std::endl;
+ std::vector<std::string> tmp = String::split(byteArrayToString(data), ' ');
if(tmp.size() > 1) {
int status = boost::lexical_cast<int> (tmp[1].c_str());
SWIFT_LOG(debug) << "Proxy Status: " << status << std::endl;
@@ -85,7 +85,7 @@ void HTTPConnectProxiedConnection::handleDataRead(const ByteArray& data) {
onConnectFinished(false);
return;
}
- SWIFT_LOG(debug) << "HTTP Proxy returned an error: " << data.toString() << std::endl;
+ SWIFT_LOG(debug) << "HTTP Proxy returned an error: " << byteArrayToString(data) << std::endl;
}
disconnect();
onConnectFinished(true);
diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
index 56c9748..5d076ac 100644
--- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp
+++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
@@ -81,7 +81,7 @@ void PlatformDomainNameServiceQuery::runBlocking() {
ByteArray response;
response.resize(NS_PACKETSZ);
- int responseLength = res_query(const_cast<char*>(service.c_str()), ns_c_in, ns_t_srv, reinterpret_cast<u_char*>(response.getData()), response.getSize());
+ int responseLength = res_query(const_cast<char*>(service.c_str()), ns_c_in, ns_t_srv, reinterpret_cast<u_char*>(vecptr(response)), response.size());
if (responseLength == -1) {
SWIFT_LOG(debug) << "Error" << std::endl;
emitError();
@@ -89,8 +89,8 @@ void PlatformDomainNameServiceQuery::runBlocking() {
}
// Parse header
- HEADER* header = reinterpret_cast<HEADER*>(response.getData());
- unsigned char* messageStart = reinterpret_cast<unsigned char*>(response.getData());
+ HEADER* header = reinterpret_cast<HEADER*>(vecptr(response));
+ unsigned char* messageStart = vecptr(response);
unsigned char* messageEnd = messageStart + responseLength;
unsigned char* currentEntry = messageStart + NS_HFIXEDSZ;
@@ -146,12 +146,12 @@ void PlatformDomainNameServiceQuery::runBlocking() {
}
ByteArray entry;
entry.resize(NS_MAXDNAME);
- entryLength = dn_expand(messageStart, messageEnd, currentEntry, reinterpret_cast<char*>(entry.getData()), entry.getSize());
+ entryLength = dn_expand(messageStart, messageEnd, currentEntry, reinterpret_cast<char*>(vecptr(entry)), entry.size());
if (entryLength < 0) {
emitError();
return;
}
- record.hostname = std::string(reinterpret_cast<const char*>(entry.getData()));
+ record.hostname = std::string(reinterpret_cast<const char*>(vecptr(entry)));
records.push_back(record);
currentEntry += entryLength;
answersCount--;
diff --git a/Swiften/Network/SOCKS5ProxiedConnection.cpp b/Swiften/Network/SOCKS5ProxiedConnection.cpp
index 52e56a9..cf531e5 100644
--- a/Swiften/Network/SOCKS5ProxiedConnection.cpp
+++ b/Swiften/Network/SOCKS5ProxiedConnection.cpp
@@ -73,9 +73,9 @@ void SOCKS5ProxiedConnection::handleConnectionConnectFinished(bool error) {
proxyState_ = ProxyAuthenticating;
ByteArray socksConnect;
- socksConnect += 0x05; // VER = SOCKS5 = 0x05
- socksConnect += 0x01; // Number of authentication methods after this byte.
- socksConnect += 0x00; // 0x00 == no authentication
+ socksConnect.push_back(0x05); // VER = SOCKS5 = 0x05
+ socksConnect.push_back(0x01); // Number of authentication methods after this byte.
+ socksConnect.push_back(0x00); // 0x00 == no authentication
// buffer.push_back(0x01); // 0x01 == GSSAPI
// buffer.push_back(0x02); // 0x02 == Username/Password
// rest see RFC 1928 (http://tools.ietf.org/html/rfc1928)
@@ -99,10 +99,10 @@ void SOCKS5ProxiedConnection::handleDataRead(const ByteArray& data) {
case 0x00:
try {
proxyState_ = ProxyConnecting;
- socksConnect += 0x05; // VER = SOCKS5 = 0x05
- socksConnect += 0x01; // Construct a TCP connection. (CMD)
- socksConnect += 0x00; // reserved.
- socksConnect += rawAddress.is_v4() ? 0x01 : 0x04; // IPv4 == 0x01, Hostname == 0x02, IPv6 == 0x04. (ATYP)
+ socksConnect.push_back(0x05); // VER = SOCKS5 = 0x05
+ socksConnect.push_back(0x01); // Construct a TCP connection. (CMD)
+ socksConnect.push_back(0x00); // reserved.
+ socksConnect.push_back(rawAddress.is_v4() ? 0x01 : 0x04); // IPv4 == 0x01, Hostname == 0x02, IPv6 == 0x04. (ATYP)
size_t size = rawAddress.is_v4() ? rawAddress.to_v4().to_bytes().size() : rawAddress.to_v6().to_bytes().size();
for (size_t s = 0; s < size; s++) {
unsigned char uc;
@@ -112,11 +112,11 @@ void SOCKS5ProxiedConnection::handleDataRead(const ByteArray& data) {
else {
uc = rawAddress.to_v6().to_bytes()[s]; // the address.
}
- socksConnect += static_cast<char> (uc);
+ socksConnect.push_back(static_cast<char>(uc));
}
- socksConnect += static_cast<unsigned char> ((server_.getPort() >> 8) & 0xFF); // highbyte of the port.
- socksConnect += static_cast<unsigned char> (server_.getPort() & 0xFF); // lowbyte of the port.
+ socksConnect.push_back(static_cast<unsigned char> ((server_.getPort() >> 8) & 0xFF)); // highbyte of the port.
+ socksConnect.push_back(static_cast<unsigned char> (server_.getPort() & 0xFF)); // lowbyte of the port.
connection_->write(socksConnect);
return;
}
diff --git a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
index 6c4c89c..d33c988 100644
--- a/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
+++ b/Swiften/Network/UnitTest/HTTPConnectProxiedConnectionTest.cpp
@@ -12,6 +12,8 @@
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/shared_ptr.hpp>
+#include <QA/Checker/IO.h>
+#include <Swiften/Base/Algorithm.h>
#include <Swiften/Network/Connection.h>
#include <Swiften/Network/ConnectionFactory.h>
#include <Swiften/Network/HTTPConnectProxiedConnection.h>
@@ -66,7 +68,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- CPPUNIT_ASSERT_EQUAL(ByteArray("CONNECT 2.2.2.2:2345 HTTP/1.1\r\n\r\n"), connectionFactory->connections[0]->dataWritten);
+ CPPUNIT_ASSERT_EQUAL(createByteArray("CONNECT 2.2.2.2:2345 HTTP/1.1\r\n\r\n"), connectionFactory->connections[0]->dataWritten);
}
void testConnect_ReceiveConnectResponse() {
@@ -74,12 +76,12 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
eventLoop->processEvents();
CPPUNIT_ASSERT(connectFinished);
CPPUNIT_ASSERT(!connectFinishedWithError);
- CPPUNIT_ASSERT(dataRead.isEmpty());
+ CPPUNIT_ASSERT(dataRead.empty());
}
void testConnect_ReceiveMalformedConnectResponse() {
@@ -87,7 +89,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("FLOOP"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("FLOOP"));
eventLoop->processEvents();
CPPUNIT_ASSERT(connectFinished);
@@ -100,7 +102,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 401 Unauthorized\r\n\r\n"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("HTTP/1.0 401 Unauthorized\r\n\r\n"));
eventLoop->processEvents();
CPPUNIT_ASSERT(connectFinished);
@@ -112,25 +114,25 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
HTTPConnectProxiedConnection::ref testling(createTestling());
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("abcdef"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("abcdef"));
- CPPUNIT_ASSERT_EQUAL(ByteArray("abcdef"), dataRead);
+ CPPUNIT_ASSERT_EQUAL(createByteArray("abcdef"), dataRead);
}
void testWrite_AfterConnect() {
HTTPConnectProxiedConnection::ref testling(createTestling());
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
eventLoop->processEvents();
connectionFactory->connections[0]->dataWritten.clear();
- testling->write(ByteArray("abcdef"));
+ testling->write(createByteArray("abcdef"));
- CPPUNIT_ASSERT_EQUAL(ByteArray("abcdef"), connectionFactory->connections[0]->dataWritten);
+ CPPUNIT_ASSERT_EQUAL(createByteArray("abcdef"), connectionFactory->connections[0]->dataWritten);
}
void testDisconnect_AfterConnectRequest() {
@@ -149,7 +151,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
HTTPConnectProxiedConnection::ref testling(createTestling());
testling->connect(HostAddressPort(HostAddress("2.2.2.2"), 2345));
eventLoop->processEvents();
- connectionFactory->connections[0]->onDataRead(ByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
+ connectionFactory->connections[0]->onDataRead(createByteArray("HTTP/1.0 200 Connection established\r\n\r\n"));
eventLoop->processEvents();
testling->disconnect();
@@ -179,7 +181,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
}
void handleDataRead(const ByteArray& d) {
- dataRead += d;
+ append(dataRead, d);
}
struct MockConnection : public Connection {
@@ -203,7 +205,7 @@ class HTTPConnectProxiedConnectionTest : public CppUnit::TestFixture {
}
void write(const ByteArray& d) {
- dataWritten += d;
+ append(dataWritten, d);
}
EventLoop* eventLoop;
diff --git a/Swiften/Network/WindowsProxyProvider.cpp b/Swiften/Network/WindowsProxyProvider.cpp
index 5fb3c3a..3ae43e0 100644
--- a/Swiften/Network/WindowsProxyProvider.cpp
+++ b/Swiften/Network/WindowsProxyProvider.cpp
@@ -36,9 +36,9 @@ WindowsProxyProvider::WindowsProxyProvider()
return;
}
dataBuffer.resize(dataSize);
- result = RegQueryValueEx(hKey, "ProxyServer", NULL, &dataType, reinterpret_cast<BYTE*>(dataBuffer.getData()), &dataSize);
+ result = RegQueryValueEx(hKey, "ProxyServer", NULL, &dataType, reinterpret_cast<BYTE*>(vecptr(dataBuffer)), &dataSize);
if(result == ERROR_SUCCESS) {
- std::vector<std::string> proxies = String::split(dataBuffer.toString(), ';');
+ std::vector<std::string> proxies = String::split(byteArrayToString(dataBuffer), ';');
std::pair<std::string, std::string> protocolAndProxy;
foreach(std::string proxy, proxies) {
if(proxy.find('=') != std::string::npos) {
@@ -100,11 +100,11 @@ bool WindowsProxyProvider::proxyEnabled(HKEY hKey) const {
return ret;
dataBuffer.resize(dataSize);
- result = RegQueryValueEx(hKey, "ProxyEnable", NULL, &dataType, reinterpret_cast<BYTE*>(dataBuffer.getData()), &dataSize);
+ result = RegQueryValueEx(hKey, "ProxyEnable", NULL, &dataType, reinterpret_cast<BYTE*>(vecptr(dataBuffer)), &dataSize);
if(result != ERROR_SUCCESS)
return ret;
- for(size_t t = 0; t < dataBuffer.getSize(); t++) {
+ for(size_t t = 0; t < dataBuffer.size(); t++) {
data += static_cast<int> (dataBuffer[t]) * pow(256, static_cast<double>(t));
}
return (data == 1);