From 7a3925cb996b7d8b0b683557255880747851e9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 16 Apr 2011 20:07:13 +0200 Subject: Code style fixes. diff --git a/Swiften/Network/HTTPConnectProxiedConnection.cpp b/Swiften/Network/HTTPConnectProxiedConnection.cpp index 4e05f29..2e90b52 100644 --- a/Swiften/Network/HTTPConnectProxiedConnection.cpp +++ b/Swiften/Network/HTTPConnectProxiedConnection.cpp @@ -10,28 +10,26 @@ #include #include #include -#include #include "Swiften/Base/Log.h" #include "Swiften/Base/String.h" #include "Swiften/Base/ByteArray.h" #include "Swiften/Network/HostAddressPort.h" +#include -namespace Swift { +using namespace Swift; -HTTPConnectProxiedConnection::HTTPConnectProxiedConnection(ConnectionFactory* connectionFactory, HostAddressPort proxy) -: connectionFactory_(connectionFactory), proxy_(proxy), server_(HostAddressPort(HostAddress("0.0.0.0"), 0)) -{ +HTTPConnectProxiedConnection::HTTPConnectProxiedConnection(ConnectionFactory* connectionFactory, HostAddressPort proxy) : connectionFactory_(connectionFactory), proxy_(proxy), server_(HostAddressPort(HostAddress("0.0.0.0"), 0)) { connected_ = false; } HTTPConnectProxiedConnection::~HTTPConnectProxiedConnection() { - if(connection_) { + if (connection_) { connection_->onDataRead.disconnect(boost::bind(&HTTPConnectProxiedConnection::handleDataRead, shared_from_this(), _1)); connection_->onDisconnected.disconnect(boost::bind(&HTTPConnectProxiedConnection::handleDisconnected, shared_from_this(), _1)); } - if(connected_) { + if (connected_) { std::cerr << "Warning: Connection was still established." << std::endl; } } @@ -65,7 +63,7 @@ void HTTPConnectProxiedConnection::write(const ByteArray& data) { void HTTPConnectProxiedConnection::handleConnectionConnectFinished(bool error) { connection_->onConnectFinished.disconnect(boost::bind(&HTTPConnectProxiedConnection::handleConnectionConnectFinished, shared_from_this(), _1)); - if(!error) { + if (!error) { proxyState_ = ProxyConnecting; std::stringstream connect; connect << "CONNECT " << server_.getAddress().toString() << ":" << server_.getPort() << " HTTP/1.1\r\n\r\n"; @@ -106,6 +104,3 @@ void HTTPConnectProxiedConnection::handleDataRead(const ByteArray& data) { HostAddressPort HTTPConnectProxiedConnection::getLocalAddress() const { return connection_->getLocalAddress(); } - -//namespace -} diff --git a/Swiften/Network/HTTPConnectProxiedConnection.h b/Swiften/Network/HTTPConnectProxiedConnection.h index 88b4f66..232f4eb 100644 --- a/Swiften/Network/HTTPConnectProxiedConnection.h +++ b/Swiften/Network/HTTPConnectProxiedConnection.h @@ -8,7 +8,6 @@ #include -#include "Swiften/Network/ConnectionFactory.h" #include "Swiften/Network/Connection.h" #include "Swiften/Network/HostAddressPort.h" @@ -20,6 +19,8 @@ namespace boost { } namespace Swift { + class ConnectionFactory; + class HTTPConnectProxiedConnection : public Connection, public boost::enable_shared_from_this { public: typedef boost::shared_ptr ref; diff --git a/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp b/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp index 0212945..050b0c0 100644 --- a/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp +++ b/Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp @@ -5,14 +5,12 @@ */ #include "Swiften/Network/HTTPConnectProxiedConnectionFactory.h" + #include "Swiften/Network/HTTPConnectProxiedConnection.h" namespace Swift { -HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(ConnectionFactory* connectionFactory, HostAddressPort proxy) -: connectionFactory_(connectionFactory), proxy_(proxy) -{ - +HTTPConnectProxiedConnectionFactory::HTTPConnectProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) : connectionFactory_(connectionFactory), proxy_(proxy) { } boost::shared_ptr HTTPConnectProxiedConnectionFactory::createConnection() { diff --git a/Swiften/Network/HTTPConnectProxiedConnectionFactory.h b/Swiften/Network/HTTPConnectProxiedConnectionFactory.h index 7aeb337..2b0c8d5 100644 --- a/Swiften/Network/HTTPConnectProxiedConnectionFactory.h +++ b/Swiften/Network/HTTPConnectProxiedConnectionFactory.h @@ -7,15 +7,12 @@ #pragma once #include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/HTTPConnectProxiedConnection.h" #include "Swiften/Network/HostAddressPort.h" namespace Swift { - class HTTPConnectProxiedConnection; - class HTTPConnectProxiedConnectionFactory : public ConnectionFactory { public: - HTTPConnectProxiedConnectionFactory(ConnectionFactory* connectionFactory, HostAddressPort proxy); + HTTPConnectProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy); virtual boost::shared_ptr createConnection(); diff --git a/Swiften/Network/SOCKS5ProxiedConnection.cpp b/Swiften/Network/SOCKS5ProxiedConnection.cpp index d32a0f9..0232ede 100644 --- a/Swiften/Network/SOCKS5ProxiedConnection.cpp +++ b/Swiften/Network/SOCKS5ProxiedConnection.cpp @@ -9,28 +9,26 @@ #include #include #include -#include +#include #include "Swiften/Base/Log.h" #include "Swiften/Base/String.h" #include "Swiften/Base/ByteArray.h" #include "Swiften/Network/HostAddressPort.h" -namespace Swift { +using namespace Swift; -SOCKS5ProxiedConnection::SOCKS5ProxiedConnection(ConnectionFactory* connectionFactory, HostAddressPort proxy) -: connectionFactory_(connectionFactory), proxy_(proxy), server_(HostAddressPort(HostAddress("0.0.0.0"), 0)) -{ +SOCKS5ProxiedConnection::SOCKS5ProxiedConnection(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) : connectionFactory_(connectionFactory), proxy_(proxy), server_(HostAddressPort(HostAddress("0.0.0.0"), 0)) { connected_ = false; } SOCKS5ProxiedConnection::~SOCKS5ProxiedConnection() { - if(connection_) { + if (connection_) { connection_->onDataRead.disconnect(boost::bind(&SOCKS5ProxiedConnection::handleDataRead, shared_from_this(), _1)); connection_->onDisconnected.disconnect(boost::bind(&SOCKS5ProxiedConnection::handleDisconnected, shared_from_this(), _1)); } - if(connected_) { + if (connected_) { std::cerr << "Warning: Connection was still established." << std::endl; } } @@ -53,8 +51,9 @@ void SOCKS5ProxiedConnection::listen() { void SOCKS5ProxiedConnection::disconnect() { connected_ = false; - if(connection_) + if (connection_) { connection_->disconnect(); + } } void SOCKS5ProxiedConnection::handleDisconnected(const boost::optional& error) { @@ -62,13 +61,14 @@ void SOCKS5ProxiedConnection::handleDisconnected(const boost::optional& e } void SOCKS5ProxiedConnection::write(const ByteArray& data) { - if(connection_) + if (connection_) { connection_->write(data); + } } void SOCKS5ProxiedConnection::handleConnectionConnectFinished(bool error) { connection_->onConnectFinished.disconnect(boost::bind(&SOCKS5ProxiedConnection::handleConnectionConnectFinished, shared_from_this(), _1)); - if(!error) { + if (!error) { SWIFT_LOG(debug) << "Connection to proxy established, now connect to the server via it." << std::endl; proxyState_ = ProxyAuthenticating; @@ -109,13 +109,14 @@ void SOCKS5ProxiedConnection::handleDataRead(const ByteArray& data) { if(rawAddress.is_v4()) { uc = rawAddress.to_v4().to_bytes()[s]; // the address. } - else + else { uc = rawAddress.to_v6().to_bytes()[s]; // the address. + } socksConnect += static_cast (uc); } - socksConnect += static_cast (server_.getPort() >> 8); // highbyte of the port. - socksConnect += static_cast (server_.getPort()); // lowbyte of the port. + socksConnect += static_cast ((server_.getPort() >> 8) & 0xFF); // highbyte of the port. + socksConnect += static_cast (server_.getPort() & 0xFF); // lowbyte of the port. connection_->write(socksConnect); return; } @@ -171,6 +172,3 @@ void SOCKS5ProxiedConnection::handleDataRead(const ByteArray& data) { HostAddressPort SOCKS5ProxiedConnection::getLocalAddress() const { return connection_->getLocalAddress(); } - -//namespace -} diff --git a/Swiften/Network/SOCKS5ProxiedConnection.h b/Swiften/Network/SOCKS5ProxiedConnection.h index b222fd7..779bfa1 100644 --- a/Swiften/Network/SOCKS5ProxiedConnection.h +++ b/Swiften/Network/SOCKS5ProxiedConnection.h @@ -6,10 +6,8 @@ #pragma once -#include #include -#include "Swiften/Network/ConnectionFactory.h" #include "Swiften/Network/Connection.h" #include "Swiften/Network/HostAddressPort.h" @@ -21,13 +19,15 @@ namespace boost { } namespace Swift { + class ConnectionFactory; + class SOCKS5ProxiedConnection : public Connection, public boost::enable_shared_from_this { public: typedef boost::shared_ptr ref; ~SOCKS5ProxiedConnection(); - static ref create(ConnectionFactory* connectionFactory, HostAddressPort proxy) { + static ref create(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) { return ref(new SOCKS5ProxiedConnection(connectionFactory, proxy)); } @@ -37,19 +37,19 @@ namespace Swift { virtual void write(const ByteArray& data); virtual HostAddressPort getLocalAddress() const; - private: - enum { - ProxyAuthenticating = 0, - ProxyConnecting, - } proxyState_; - SOCKS5ProxiedConnection(ConnectionFactory* connectionFactory, HostAddressPort proxy); + private: + SOCKS5ProxiedConnection(ConnectionFactory* connectionFactory, const HostAddressPort& proxy); void handleConnectionConnectFinished(bool error); void handleDataRead(const ByteArray& data); void handleDisconnected(const boost::optional& error); private: + enum { + ProxyAuthenticating = 0, + ProxyConnecting, + } proxyState_; bool connected_; ConnectionFactory* connectionFactory_; HostAddressPort proxy_; diff --git a/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp b/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp index 0be0931..ab75644 100644 --- a/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp +++ b/Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp @@ -5,14 +5,12 @@ */ #include "Swiften/Network/SOCKS5ProxiedConnectionFactory.h" + #include "Swiften/Network/SOCKS5ProxiedConnection.h" namespace Swift { -SOCKS5ProxiedConnectionFactory::SOCKS5ProxiedConnectionFactory(ConnectionFactory* connectionFactory, HostAddressPort proxy) -: connectionFactory_(connectionFactory), proxy_(proxy) -{ - +SOCKS5ProxiedConnectionFactory::SOCKS5ProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy) : connectionFactory_(connectionFactory), proxy_(proxy) { } boost::shared_ptr SOCKS5ProxiedConnectionFactory::createConnection() { diff --git a/Swiften/Network/SOCKS5ProxiedConnectionFactory.h b/Swiften/Network/SOCKS5ProxiedConnectionFactory.h index a78a9e8..8f310c5 100644 --- a/Swiften/Network/SOCKS5ProxiedConnectionFactory.h +++ b/Swiften/Network/SOCKS5ProxiedConnectionFactory.h @@ -6,18 +6,13 @@ #pragma once -#include - #include "Swiften/Network/ConnectionFactory.h" -#include "Swiften/Network/SOCKS5ProxiedConnection.h" #include "Swiften/Network/HostAddressPort.h" namespace Swift { - class SOCKS5ProxiedConnection; - class SOCKS5ProxiedConnectionFactory : public ConnectionFactory { public: - SOCKS5ProxiedConnectionFactory(ConnectionFactory* connectionFactory, HostAddressPort proxy); + SOCKS5ProxiedConnectionFactory(ConnectionFactory* connectionFactory, const HostAddressPort& proxy); virtual boost::shared_ptr createConnection(); -- cgit v0.10.2-6-g49f6