connectionsocks5proxy.h
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef CONNECTIONSOCKS5PROXY_H__
#define CONNECTIONSOCKS5PROXY_H__
#include "gloox.h"
#include "connectionbase.h"
#include "logsink.h"
#include <string>
namespace gloox
{
class GLOOX_API ConnectionSOCKS5Proxy : public ConnectionBase, public ConnectionDataHandler
{
public:
ConnectionSOCKS5Proxy( ConnectionBase* connection, const LogSink& logInstance,
const std::string& server, int port = -1, bool ip = false );
ConnectionSOCKS5Proxy( ConnectionDataHandler* cdh, ConnectionBase* connection,
const LogSink& logInstance,
const std::string& server, int port = -1, bool ip = false );
virtual ~ConnectionSOCKS5Proxy();
// reimplemented from ConnectionBase
virtual ConnectionError connect();
// reimplemented from ConnectionBase
virtual ConnectionError recv( int timeout = -1 );
// reimplemented from ConnectionBase
virtual bool send( const std::string& data );
// reimplemented from ConnectionBase
virtual ConnectionError receive();
// reimplemented from ConnectionBase
virtual void disconnect();
// reimplemented from ConnectionBase
virtual void cleanup();
// reimplemented from ConnectionBase
virtual void getStatistics( long int &totalIn, long int &totalOut );
// reimplemented from ConnectionDataHandler
virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
// reimplemented from ConnectionDataHandler
virtual void handleConnect( const ConnectionBase* connection );
// reimplemented from ConnectionDataHandler
virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
// reimplemented from ConnectionDataHandler
virtual ConnectionBase* newInstance() const;
void setServer( const std::string& host, int port = -1, bool ip = false )
{ m_server = host; m_port = port; m_ip = ip; }
void setProxyAuth( const std::string& user, const std::string& password )
{ m_proxyUser = user; m_proxyPwd = password; }
void setConnectionImpl( ConnectionBase* connection );
private:
enum Socks5State
{
S5StateDisconnected,
S5StateConnecting,
S5StateNegotiating,
S5StateAuthenticating,
S5StateConnected
};
ConnectionSOCKS5Proxy &operator=( const ConnectionSOCKS5Proxy& );
void negotiate();
ConnectionBase* m_connection;
const LogSink& m_logInstance;
Socks5State m_s5state;
std::string m_proxyUser;
std::string m_proxyPwd;
std::string m_proxyHandshakeBuffer;
bool m_ip;
};
}
#endif // CONNECTIONSOCKS5PROXY_H__
gloox::ConnectionBase
An abstract base class for a connection.
Definition connectionbase.h:35
gloox::ConnectionBase::port
int port() const
Definition connectionbase.h:121
gloox::ConnectionBase::server
const std::string & server() const
Definition connectionbase.h:115
gloox::ConnectionBase::m_port
int m_port
Definition connectionbase.h:161
gloox::ConnectionBase::m_server
std::string m_server
Definition connectionbase.h:158
gloox::ConnectionBase::ConnectionBase
ConnectionBase(ConnectionDataHandler *cdh)
Definition connectionbase.h:42
gloox::ConnectionDataHandler
This is an abstract base class to receive events from a ConnectionBase-derived object.
Definition connectiondatahandler.h:36
gloox::ConnectionSOCKS5Proxy::ConnectionSOCKS5Proxy
ConnectionSOCKS5Proxy(ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1, bool ip=false)
Definition connectionsocks5proxy.cpp:44
gloox::ConnectionSOCKS5Proxy::setServer
void setServer(const std::string &host, int port=-1, bool ip=false)
Definition connectionsocks5proxy.h:134
gloox::ConnectionSOCKS5Proxy::handleDisconnect
virtual void handleDisconnect(const ConnectionBase *connection, ConnectionError reason)
Definition connectionsocks5proxy.cpp:376
gloox::ConnectionSOCKS5Proxy::recv
virtual ConnectionError recv(int timeout=-1)
Definition connectionsocks5proxy.cpp:122
gloox::ConnectionSOCKS5Proxy::cleanup
virtual void cleanup()
Definition connectionsocks5proxy.cpp:155
gloox::ConnectionSOCKS5Proxy::handleConnect
virtual void handleConnect(const ConnectionBase *connection)
Definition connectionsocks5proxy.cpp:339
gloox::ConnectionSOCKS5Proxy::handleReceivedData
virtual void handleReceivedData(const ConnectionBase *connection, const std::string &data)
Definition connectionsocks5proxy.cpp:175
gloox::ConnectionSOCKS5Proxy::disconnect
virtual void disconnect()
Definition connectionsocks5proxy.cpp:115
gloox::ConnectionSOCKS5Proxy::newInstance
virtual ConnectionBase * newInstance() const
Definition connectionsocks5proxy.cpp:81
gloox::ConnectionSOCKS5Proxy::connect
virtual ConnectionError connect()
Definition connectionsocks5proxy.cpp:95
gloox::ConnectionSOCKS5Proxy::send
virtual bool send(const std::string &data)
Definition connectionsocks5proxy.cpp:138
gloox::ConnectionSOCKS5Proxy::setProxyAuth
void setProxyAuth(const std::string &user, const std::string &password)
Definition connectionsocks5proxy.h:142
gloox::ConnectionSOCKS5Proxy::receive
virtual ConnectionError receive()
Definition connectionsocks5proxy.cpp:130
gloox::ConnectionSOCKS5Proxy::getStatistics
virtual void getStatistics(long int &totalIn, long int &totalOut)
Definition connectionsocks5proxy.cpp:164
gloox::LogSink
An implementation of log sink and source.
Definition logsink.h:39
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ConnectionError
ConnectionError
Definition gloox.h:684