diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-04-16 18:07:13 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-04-18 19:11:46 (GMT) |
commit | 7a3925cb996b7d8b0b683557255880747851e9ae (patch) | |
tree | 9eb65fb931168a29c78a19bb4cb8006b1f733043 /Swiften | |
parent | 7d2db3b25effc93aa111664d0745a5365f4b7f05 (diff) | |
download | swift-contrib-7a3925cb996b7d8b0b683557255880747851e9ae.zip swift-contrib-7a3925cb996b7d8b0b683557255880747851e9ae.tar.bz2 |
Code style fixes.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Network/HTTPConnectProxiedConnection.cpp | 17 | ||||
-rw-r--r-- | Swiften/Network/HTTPConnectProxiedConnection.h | 3 | ||||
-rw-r--r-- | Swiften/Network/HTTPConnectProxiedConnectionFactory.cpp | 6 | ||||
-rw-r--r-- | Swiften/Network/HTTPConnectProxiedConnectionFactory.h | 5 | ||||
-rw-r--r-- | Swiften/Network/SOCKS5ProxiedConnection.cpp | 30 | ||||
-rw-r--r-- | Swiften/Network/SOCKS5ProxiedConnection.h | 18 | ||||
-rw-r--r-- | Swiften/Network/SOCKS5ProxiedConnectionFactory.cpp | 6 | ||||
-rw-r--r-- | Swiften/Network/SOCKS5ProxiedConnectionFactory.h | 7 |
8 files changed, 37 insertions, 55 deletions
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 <boost/bind.hpp> #include <boost/thread.hpp> #include <boost/lexical_cast.hpp> -#include <math.h> #include "Swiften/Base/Log.h" #include "Swiften/Base/String.h" #include "Swiften/Base/ByteArray.h" #include "Swiften/Network/HostAddressPort.h" +#include <Swiften/Network/ConnectionFactory.h> -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 <boost/enable_shared_from_this.hpp> -#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<HTTPConnectProxiedConnection> { public: typedef boost::shared_ptr<HTTPConnectProxiedConnection> 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<Connection> 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<Connection> 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 <iostream> #include <boost/bind.hpp> #include <boost/thread.hpp> -#include <math.h> +#include <Swiften/Network/ConnectionFactory.h> #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>& error) { @@ -62,13 +61,14 @@ void SOCKS5ProxiedConnection::handleDisconnected(const boost::optional<Error>& 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<char> (uc); } - socksConnect += static_cast<unsigned char> (server_.getPort() >> 8); // highbyte of the port. - socksConnect += static_cast<unsigned char> (server_.getPort()); // lowbyte of the port. + 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. 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 <boost/asio.hpp> #include <boost/enable_shared_from_this.hpp> -#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<SOCKS5ProxiedConnection> { public: typedef boost::shared_ptr<SOCKS5ProxiedConnection> 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>& 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<Connection> 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 <boost/asio.hpp> - #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<Connection> createConnection(); |