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.
virtual ~ConnectionHTTPProxy()
static HostMap resolve(const std::string &service, const std::string &proto, const std::string &domain, const LogSink &logInstance)
virtual ConnectionBase * newInstance() const
void setConnectionImpl(ConnectionBase *connection)
std::map< std::string, int > HostMap
virtual void getStatistics(long int &totalIn, long int &totalOut)
virtual void handleReceivedData(const ConnectionBase *connection, const std::string &data)=0
virtual void handleReceivedData(const ConnectionBase *connection, const std::string &data)
virtual void disconnect()=0
virtual ConnectionError connect()=0
This is an abstract base class to receive events from a ConnectionBase-derived object.
virtual ConnectionBase * newInstance() const =0
virtual void handleConnect(const ConnectionBase *connection)
virtual void handleDisconnect(const ConnectionBase *connection, ConnectionError reason)=0
The namespace for the gloox library.
const std::string encode64(const std::string &input)
const std::string & server() const
virtual bool send(const std::string &data)
virtual bool send(const std::string &data)=0
virtual void disconnect()
virtual void handleConnect(const ConnectionBase *connection)=0
ConnectionHTTPProxy(ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1)
const std::string GLOOX_VERSION
virtual ConnectionError receive()=0
void registerConnectionDataHandler(ConnectionDataHandler *cdh)
virtual ConnectionError recv(int timeout=-1)=0
virtual ConnectionError connect()
bool idna(const std::string &domain, std::string &out)
virtual void getStatistics(long int &totalIn, long int &totalOut)=0
void dbg(LogArea area, const std::string &message) const
ConnectionDataHandler * m_handler
virtual ConnectionError recv(int timeout=-1)
virtual void handleDisconnect(const ConnectionBase *connection, ConnectionError reason)
An implementation of log sink and source.
const std::string EmptyString
virtual ConnectionError receive()