17 #include "connectionhttpproxy.h"
31 const std::string& server,
int port )
33 m_logInstance( logInstance ), m_http11( false )
46 const std::string& server,
int port )
48 m_logInstance( logInstance )
74 m_connection = connection;
107 return m_connection && m_connection->
send( data );
123 totalIn = totalOut = 0;
127 const std::string& data )
134 m_proxyHandshakeBuffer += data;
135 if( ( !m_proxyHandshakeBuffer.compare( 0, 12,
"HTTP/1.0 200" )
136 || !m_proxyHandshakeBuffer.compare( 0, 12,
"HTTP/1.1 200" ) )
137 && !m_proxyHandshakeBuffer.compare( m_proxyHandshakeBuffer.length() - 4, 4,
"\r\n\r\n" ) )
142 "HTTP proxy connection established" );
145 else if( !m_proxyHandshakeBuffer.compare( 9, 3,
"407" ) )
150 else if( !m_proxyHandshakeBuffer.compare( 9, 3,
"403" )
151 || !m_proxyHandshakeBuffer.compare( 9, 3,
"404" ) )
170 if( !servers.empty() )
172 const std::pair< std::string, int >& host = *servers.begin();
177 std::string message =
"Requesting HTTP proxy connection to " +
server +
":"
178 + util::int2string(
port );
181 std::string os =
"CONNECT " +
server +
":" + util::int2string(
port ) +
" HTTP/1."
182 + util::int2string( m_http11 ? 1 : 0 ) +
"\r\n"
183 "Host: " +
server +
"\r\n"
184 "Content-Length: 0\r\n"
185 "Proxy-Connection: Keep-Alive\r\n"
186 "Pragma: no-cache\r\n"
189 if( !m_proxyUser.empty() && !m_proxyPwd.empty() )
191 os +=
"Proxy-Authorization: Basic " +
Base64::encode64( m_proxyUser +
":" + m_proxyPwd )
196 if( !m_connection->
send( os ) )
An abstract base class for a connection.
const std::string & server() const
virtual ConnectionError recv(int timeout=-1)=0
virtual bool send(const std::string &data)=0
ConnectionDataHandler * m_handler
virtual ConnectionError connect()=0
virtual ConnectionError receive()=0
virtual void getStatistics(long int &totalIn, long int &totalOut)=0
virtual void disconnect()=0
virtual ConnectionBase * newInstance() const =0
void registerConnectionDataHandler(ConnectionDataHandler *cdh)
This is an abstract base class to receive events from a ConnectionBase-derived object.
virtual void handleReceivedData(const ConnectionBase *connection, const std::string &data)=0
virtual void handleDisconnect(const ConnectionBase *connection, ConnectionError reason)=0
virtual void handleConnect(const ConnectionBase *connection)=0
virtual ~ConnectionHTTPProxy()
virtual void handleDisconnect(const ConnectionBase *connection, ConnectionError reason)
virtual ConnectionError recv(int timeout=-1)
virtual void handleConnect(const ConnectionBase *connection)
virtual void handleReceivedData(const ConnectionBase *connection, const std::string &data)
virtual void disconnect()
virtual ConnectionBase * newInstance() const
virtual ConnectionError connect()
void setConnectionImpl(ConnectionBase *connection)
virtual bool send(const std::string &data)
ConnectionHTTPProxy(ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1)
virtual ConnectionError receive()
virtual void getStatistics(long int &totalIn, long int &totalOut)
static HostMap resolve(const std::string &service, const std::string &proto, const std::string &domain, const LogSink &logInstance)
std::map< std::string, int > HostMap
An implementation of log sink and source.
void dbg(LogArea area, const std::string &message) const
const std::string encode64(const std::string &input)
bool idna(const std::string &domain, std::string &out)
The namespace for the gloox library.
const std::string GLOOX_VERSION
@ LogAreaClassConnectionHTTPProxy
const std::string EmptyString