152 lines
4.5 KiB
C++
152 lines
4.5 KiB
C++
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (C) Intel Corporation, 2006 - 2007.
|
|
//
|
|
// File: TcpConsumer.h
|
|
//
|
|
// Contents: Handles outgoing TCP messages.
|
|
//
|
|
// Notes:
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
#ifndef _MPS_TCP_CONSUMER_H__
|
|
#define _MPS_TCP_CONSUMER_H__
|
|
|
|
|
|
//===================================================
|
|
// INCLUDES
|
|
//===================================================
|
|
#include <ace/Message_Block.h>
|
|
#include <ace/SOCK_Stream.h>
|
|
#include <ace/Message_Queue_T.h>
|
|
|
|
#include "TcpSvcHandler.h"
|
|
#include "SOCKSv5.h"
|
|
|
|
|
|
/***************************************************************************************
|
|
// Tcp_Consumer
|
|
//
|
|
/**************************************************************************************/
|
|
class Tcp_Consumer
|
|
{
|
|
|
|
public:
|
|
enum REP_STATUS{SUCCESS, FAILURE};
|
|
//===================================================
|
|
// CTOR / DTOR
|
|
//===================================================
|
|
Tcp_Consumer(Tcp_Svc_Handler* handler);
|
|
virtual ~Tcp_Consumer();
|
|
|
|
//===================================================
|
|
// PROTOTYPE:
|
|
//===================================================
|
|
|
|
//-----------------------------------------
|
|
// Get reference to socket stream
|
|
//-----------------------------------------
|
|
ACE_SOCK_Stream& getPeer(void) const;
|
|
|
|
//-----------------------------------------
|
|
// Finish sending event when flow control conditions abate.
|
|
//-----------------------------------------
|
|
STATUS handle_output (ACE_HANDLE h);
|
|
|
|
//-----------------------------------------
|
|
//
|
|
//-----------------------------------------
|
|
void handle_close();
|
|
void connectionClose();
|
|
|
|
//-----------------------------------------
|
|
// add message block to message queue, and
|
|
// register to write handler.
|
|
//-----------------------------------------
|
|
STATUS sendData(ACE_Message_Block* mb);
|
|
|
|
virtual STATUS sendVersionMsg(SOCKS_V5_METHOD support_method){return STATUS_FAILURE;}
|
|
|
|
// Put message in this tunnel handler queue
|
|
STATUS putq(ACE_Message_Block *mb, ACE_Time_Value *tv=0);
|
|
|
|
//-----------------------------------------
|
|
// Notify this consumer wether there is tunnelSupplier that uses its services.
|
|
// In case tcpSvcHandler released this tcpConsumer, (is_hold = false)
|
|
// there is no nned to use this instance- and thus we delete it.
|
|
//-----------------------------------------
|
|
//int setTunnelHold(bool is_hold);
|
|
virtual const char* identifier() { return _svc_handler->identifier();}
|
|
protected:
|
|
|
|
// ACE_Recursive_Thread_Mutex& socket_mutex() {return _svc_handler->_socket_mutex;};
|
|
//===================================================
|
|
// Data Member
|
|
//===================================================
|
|
Tcp_Svc_Handler* _svc_handler;
|
|
ACE_Recursive_Thread_Mutex _mutex;
|
|
ACE_UINT32 _msg_counter; //for DEBUG purpose only.
|
|
};
|
|
|
|
|
|
/***************************************************************************************
|
|
//
|
|
//
|
|
/**************************************************************************************/
|
|
class SocksConsumer: public Tcp_Consumer
|
|
{
|
|
|
|
public:
|
|
enum CHANNEL_REP_REASON
|
|
{
|
|
SUCCEEDED =0,
|
|
SERVER_FAILURE =1,
|
|
CONNECTION_NOT_ALLOWED =2,
|
|
NETWORK_UNREACHABLE =3,
|
|
HOST_UNREACHABLE =4,
|
|
CONNECTION_REFUESED =5,
|
|
TTL_EXPIRED =6,
|
|
COMMAND_NOT_SUPPORTED =7,
|
|
ADDRESS_TYPE_NOT_SUPPORTED =8
|
|
};
|
|
|
|
//===================================================
|
|
// CTOR / DTOR
|
|
//===================================================
|
|
SocksConsumer(Tcp_Svc_Handler* handler):Tcp_Consumer(handler){};
|
|
virtual ~SocksConsumer(){};
|
|
|
|
//===================================================
|
|
// PROTOTYPE:
|
|
//===================================================
|
|
|
|
//-----------------------------------------
|
|
// send Socks negotiation message according to
|
|
// openChannel reply
|
|
//-----------------------------------------
|
|
STATUS openRep(REP_STATUS status, CHANNEL_REP_REASON reason=CONNECTION_REFUESED);
|
|
|
|
//-----------------------------------------
|
|
// send Socks version message
|
|
//-----------------------------------------
|
|
virtual STATUS sendVersionMsg(SOCKS_V5_METHOD support_method);
|
|
|
|
//-----------------------------------------
|
|
// send Socks authentication message
|
|
//-----------------------------------------
|
|
STATUS sendAuthMsg(SOCKS_V5_REP status);
|
|
protected:
|
|
|
|
|
|
//===================================================
|
|
// Data Member
|
|
//===================================================
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif //_MPS_TCP_CONSUMER_H__
|