socks5bytestreamserver.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 SOCKS5BYTESTREAMSERVER_H__
#define SOCKS5BYTESTREAMSERVER_H__
#include "macros.h"
#include "connectionhandler.h"
#include "connectiontcpserver.h"
#include "logsink.h"
#include "mutex.h"
namespace gloox
{
class GLOOX_API SOCKS5BytestreamServer : public ConnectionHandler, public ConnectionDataHandler
{
friend class SOCKS5BytestreamManager;
public:
SOCKS5BytestreamServer( const LogSink& logInstance, int port, const std::string& ip = EmptyString );
~SOCKS5BytestreamServer();
ConnectionError listen();
ConnectionError recv( int timeout );
void stop();
int localPort() const;
const std::string localInterface() const;
int serverSocket() const { return m_tcpServer->socket(); }
// reimplemented from ConnectionHandler
virtual void handleIncomingConnection( ConnectionBase* server, ConnectionBase* connection );
// 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 );
private:
SOCKS5BytestreamServer& operator=( const SOCKS5BytestreamServer& );
void registerHash( const std::string& hash );
void removeHash( const std::string& hash );
ConnectionBase* getConnection( const std::string& hash );
enum NegotiationState
{
StateDisconnected,
StateUnnegotiated,
StateAuthmethodAccepted,
StateAuthAccepted,
StateDestinationAccepted,
StateActive
};
struct ConnectionInfo
{
NegotiationState state;
std::string hash;
};
typedef std::map<ConnectionBase*, ConnectionInfo> ConnectionMap;
ConnectionMap m_connections;
typedef std::list<const ConnectionBase*> ConnectionList;
ConnectionList m_oldConnections;
typedef std::list<std::string> HashMap;
HashMap m_hashes;
ConnectionTCPServer* m_tcpServer;
util::Mutex m_mutex;
const LogSink& m_logInstance;
std::string m_ip;
int m_port;
};
}
#endif // SOCKS5BYTESTREAMSERVER_H__
gloox::ConnectionBase
An abstract base class for a connection.
Definition connectionbase.h:35
gloox::ConnectionDataHandler
This is an abstract base class to receive events from a ConnectionBase-derived object.
Definition connectiondatahandler.h:36
gloox::ConnectionHandler
This is an abstract base class to receive incoming connection attempts. Do not confuse this with Conn...
Definition connectionhandler.h:34
gloox::LogSink
An implementation of log sink and source.
Definition logsink.h:39
gloox::SOCKS5BytestreamServer
A server listening for SOCKS5 bytestreams.
Definition socks5bytestreamserver.h:37
gloox::SOCKS5BytestreamServer::localInterface
const std::string localInterface() const
Definition socks5bytestreamserver.cpp:100
gloox::SOCKS5BytestreamServer::listen
ConnectionError listen()
Definition socks5bytestreamserver.cpp:43
gloox::SOCKS5BytestreamServer::stop
void stop()
Definition socks5bytestreamserver.cpp:83
gloox::SOCKS5BytestreamServer::serverSocket
int serverSocket() const
Definition socks5bytestreamserver.h:93
gloox::SOCKS5BytestreamServer::localPort
int localPort() const
Definition socks5bytestreamserver.cpp:92
gloox::SOCKS5BytestreamServer::recv
ConnectionError recv(int timeout)
Definition socks5bytestreamserver.cpp:51
gloox::SOCKS5BytestreamServer::SOCKS5BytestreamServer
SOCKS5BytestreamServer(const LogSink &logInstance, int port, const std::string &ip=EmptyString)
Definition socks5bytestreamserver.cpp:21
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ConnectionError
ConnectionError
Definition gloox.h:684
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::StateDisconnected
@ StateDisconnected
Definition gloox.h:642