14 #include "socks5bytestream.h"
15 #include "bytestreamdatahandler.h"
16 #include "clientbase.h"
17 #include "connectionbase.h"
18 #include "connectionsocks5proxy.h"
25 SOCKS5Bytestream::SOCKS5Bytestream( SOCKS5BytestreamManager* manager, ConnectionBase* connection,
26 LogSink& logInstance,
const JID& initiator,
const JID& target,
27 const std::string& sid )
28 : Bytestream( Bytestream::S5B, logInstance, initiator, target, sid ),
29 m_manager( manager ), m_connection( 0 ), m_socks5( 0 ), m_connected( false )
31 if( connection && connection->state() == StateConnected )
34 setConnectionImpl( connection );
37 SOCKS5Bytestream::~SOCKS5Bytestream()
51 m_connection = connection;
55 sha.
feed( m_initiator.full() );
56 sha.
feed( m_target.full() );
60 bool SOCKS5Bytestream::connect()
62 if( !m_connection || !m_socks5 || !m_manager )
68 StreamHostList::const_iterator it = m_hosts.begin();
69 for( ; it != m_hosts.end(); ++it )
71 if( ++it == m_hosts.end() )
74 m_connection->setServer( (*it).host, (*it).port );
87 bool SOCKS5Bytestream::send(
const std::string& data )
89 if( !m_open || !m_connection || !m_socks5 || !m_manager )
92 return m_socks5->send( data );
97 if( !m_connection || !m_socks5 || !m_manager )
100 return m_socks5->recv( timeout );
103 void SOCKS5Bytestream::activate()
107 m_handler->handleBytestreamOpen(
this );
110 void SOCKS5Bytestream::close()
112 if( m_open && m_handler )
116 m_socks5->disconnect();
117 m_handler->handleBytestreamClose(
this );
121 void SOCKS5Bytestream::handleReceivedData(
const ConnectionBase* ,
const std::string& data )
129 m_handler->handleBytestreamOpen(
this );
141 m_handler->handleBytestreamData(
this, data );
146 m_manager->acknowledgeStreamHost(
true, m_proxy, m_sid );
151 m_handler->handleBytestreamOpen(
this );
An abstract base class for a connection.
This is an implementation of a simple SOCKS5 Proxying connection (RFC 1928 + RFC 1929).
An implementation of SHA1.
void feed(const unsigned char *data, unsigned length)
The namespace for the gloox library.
const std::string EmptyString