206 lines
5.9 KiB
C++

//----------------------------------------------------------------------------
//
// Copyright (C) Intel Corporation, 2006 - 2007.
//
// File: TcpSupplier.h
//
// Contents: Handles incoming data on TCP connection.
//
// Notes:
//----------------------------------------------------------------------------
#ifndef _MPS_SUPPLIER_H__
#define _MPS_SUPPLIER_H__
//===================================================
// INCLUDES
//===================================================
#include <ace/Recursive_Thread_Mutex.h>
#include <ace/OS_NS_stdio.h>
#include <ace/OS_NS_string.h>
#include <ace/OS_NS_unistd.h>
#include <ace/Log_Priority.h>
#include <ace/Log_Msg.h>
#include "SocksSvcHandler.h"
#include "SOCKSv5.h"
// FW declaration
class Tcp_Consumer;
class Channel_Consumer;
/***************************************************************************************
//
//
/**************************************************************************************/
class Tcp_Supplier
{
public:
//===================================================
// CTOR / DTOR
//===================================================
Tcp_Supplier(Tcp_Svc_Handler* handler)
:_svc_handler(handler),_channel_consummer(NULL) {};
virtual ~Tcp_Supplier();
//===================================================
// PROTOTYPE:
//===================================================
//-----------------------------------------
//
//-----------------------------------------
virtual STATUS handle_input (ACE_HANDLE h);
//-----------------------------------------
// Get reference to socket stream
//-----------------------------------------
ACE_SOCK_Stream& getPeer(void) const;
//-----------------------------------------
//
//-----------------------------------------
STATUS tunnelData(void);
//-----------------------------------------
// close supplier - this method is called from
// the reactor (handle_close in the svc_handler)
//-----------------------------------------
void handle_close();
//void closeSupplier();
void unRegisterHandler(ACE_Reactor_Mask reactor_flag);
void registerHandler(ACE_Reactor_Mask reactor_flag);
//-----------------------------------------
// Create Channel consumer, and through it
// channel open Reply (according to is_connected).
//-----------------------------------------
STATUS channelOpenRep(ACE_INET_Addr amt_addr,
bool is_connected,
ACE_UINT32 tunnel_handler,
ACE_UINT32 win_size,
AMT_Tunnel_Consumer* tunnel_consumer);
protected:
//ACE_Recursive_Thread_Mutex& socket_mutex() {return _svc_handler->_socket_mutex;};
//-----------------------------------------
// This function can't be called!!!
// It used for derived class (SOCKS)
//-----------------------------------------
virtual STATUS startNegotiate()
{
ACE_ERROR_RETURN ((MY_DEBUG "Negotiation called for TCP session\n"),STATUS_FAILURE);
}
virtual const char* identifier() { return _svc_handler->identifier();}
Tcp_Consumer* consumer();
//===================================================
// Data Member
//===================================================
Tcp_Svc_Handler* _svc_handler;
//Tcp_Consumer* _consumer;
Channel_Consumer* _channel_consummer;
ACE_Recursive_Thread_Mutex _mutex;
};
/***************************************************************************************
//
//
/**************************************************************************************/
class SocksSupplier: public Tcp_Supplier
{
protected:
public:
//===================================================
// CTOR / DTOR
//===================================================
SocksSupplier(Tcp_Svc_Handler* handler)
:Tcp_Supplier(handler){}
virtual ~SocksSupplier(){};
//===================================================
// PROTOTYPE:
//===================================================
//-----------------------------------------
//
//-----------------------------------------
virtual STATUS handle_input (ACE_HANDLE h);
//-----------------------------------------
//
//-----------------------------------------
protected:
//-----------------------------------------
// return true when SOCKS negotiaition needed.
// (true on INIT, Authentication and NEGOTIATION)
//-----------------------------------------
bool isNegotiationNeeded();
//-----------------------------------------
// handle SOCKS negotiation
//-----------------------------------------
virtual STATUS startNegotiate();
private:
//-----------------------------------------
// handle SOCKS first negotiation message
// (read version, send supported authentication)
//-----------------------------------------
STATUS startConnection(void);
//-----------------------------------------
// handle SOCKS second negotiation message
// (create connection)
//-----------------------------------------
STATUS negotiate(void);
//-----------------------------------------
// Handle SOCKS Authentication.
//
// NOTE:
// Enter here only when MPS configured to support SOCKS authenication.
//-----------------------------------------
STATUS authenticate();
Socks_Svc_Handler::SOCKS_STATE socks_state();
//-----------------------------------------
// returns true if MPS supports one of the methods client asked
// in 'version' message. (for more details see rfc 1929)
//
// NOTE:
// this depands on wether MPS support client Authenticationion
// (defined in config file)
//-----------------------------------------
bool MPSSupportSocksMethod(SOCKSv5_ClientVersion& version);
//-----------------------------------------
// returns true if client's SOCKS 'version' message
// support in 'method'
//-----------------------------------------
bool ClientSupportMethod(SOCKSv5_ClientVersion& version, SOCKS_V5_METHOD method);
//===================================================
// Data Member
//===================================================
};
#endif //_MPS_SUPPLIER_H__