gloox 1.0
Public Member Functions

ConnectionHTTPProxy Class Reference

This is an implementation of a simple HTTP Proxying connection. More...

#include <connectionhttpproxy.h>

Inheritance diagram for ConnectionHTTPProxy:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ConnectionHTTPProxy (ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1)
 ConnectionHTTPProxy (ConnectionDataHandler *cdh, ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1)
virtual ~ConnectionHTTPProxy ()
virtual ConnectionError connect ()
virtual ConnectionError recv (int timeout=-1)
virtual bool send (const std::string &data)
virtual ConnectionError receive ()
virtual void disconnect ()
virtual void cleanup ()
virtual void getStatistics (long int &totalIn, long int &totalOut)
virtual void handleReceivedData (const ConnectionBase *connection, const std::string &data)
virtual void handleConnect (const ConnectionBase *connection)
virtual void handleDisconnect (const ConnectionBase *connection, ConnectionError reason)
virtual ConnectionBasenewInstance () const
void setServer (const std::string &host, int port=-1)
void setProxyAuth (const std::string &user, const std::string &password)
void setConnectionImpl (ConnectionBase *connection)
void setHTTP11 (bool http11)

Detailed Description

This is an implementation of a simple HTTP Proxying connection.

Usage:

 Client* c = new Client( ... );
 ConnectionTCPClient* conn0 = new ConnectionTCPClient( c->logInstance(),
                                                       proxyHost, proxyPort );
 ConnectionHTTPProxy* conn1 = new ConnectionHTTPProxy( c, conn0, c->logInstance(),
                                                       xmppHost, xmppPort );
 c->setConnectionImpl( conn1 );

Make sure to pass the proxy host/port to the transport connection (ConnectionTCPClient in this case), and the XMPP host/port to the proxy connection.

ConnectionHTTPProxy uses the CONNECT method to pass through the proxy. If your proxy does not allow this kind of connections, or if it kills connections after some time, you may want to use ConnectionBOSH instead or in addition.

The reason why ConnectionHTTPProxy doesn't manage its own ConnectionTCPClient is that it allows it to be used with other transports (like IPv6 or chained SOCKS5/HTTP proxies).

Author:
Jakob Schroeter <js@camaya.net>
Since:
0.9

Definition at line 53 of file connectionhttpproxy.h.


Constructor & Destructor Documentation

build buildd gloox src connectionhttpproxy cpp build buildd gloox src connectionhttpproxy cpp ConnectionHTTPProxy ( ConnectionBase connection,
const LogSink logInstance,
const std::string &  server,
int  port = -1 
)

Constructs a new ConnectionHTTPProxy object.

Parameters:
connectionA transport connection. It should be configured to connect to the proxy host and port, not to the XMPP host. ConnectionHTTPProxy will own the transport connection and delete it in its destructor.
logInstanceThe log target. Obtain it from ClientBase::logInstance().
serverA server to connect to. This is the XMPP server's address, not the proxy.
portThe port to connect to. This is the XMPP server's port, not the proxy's. The default of -1 means that SRV records will be used to find out about the actual host:port.
Note:
To properly use this object, you have to set a ConnectionDataHandler using registerConnectionDataHandler(). This is not necessary if this object is part of a 'connection chain', e.g. with ConnectionSOCKS5Proxy.

Definition at line 31 of file connectionhttpproxy.cpp.

ConnectionHTTPProxy ( ConnectionDataHandler cdh,
ConnectionBase connection,
const LogSink logInstance,
const std::string &  server,
int  port = -1 
)

Constructs a new ConnectionHTTPProxy object.

Parameters:
cdhAn ConnectionDataHandler-derived object that will handle incoming data.
connectionA transport connection. It should be configured to connect to the proxy host and port, not to the XMPP host. ConnectionHTTPProxy will own the transport connection and delete it in its destructor.
logInstanceThe log target. Obtain it from ClientBase::logInstance().
serverA server to connect to. This is the XMPP server's address, not the proxy.
portThe port to connect to. This is the XMPP server's port, not the proxy's. The default of -1 means that SRV records will be used to find out about the actual host:port.

Definition at line 45 of file connectionhttpproxy.cpp.

~ConnectionHTTPProxy ( ) [virtual]

Virtual destructor

Definition at line 60 of file connectionhttpproxy.cpp.


Member Function Documentation

void cleanup ( ) [virtual]

This function is called after a disconnect to clean up internal state. It is also called by ConnectionBase's destructor.

Reimplemented from ConnectionBase.

Definition at line 112 of file connectionhttpproxy.cpp.

ConnectionError connect ( ) [virtual]

Used to initiate the connection.

Returns:
Returns the connection state.

Implements ConnectionBase.

Definition at line 79 of file connectionhttpproxy.cpp.

void disconnect ( ) [virtual]

Disconnects an established connection. NOOP if no active connection exists.

Implements ConnectionBase.

Definition at line 90 of file connectionhttpproxy.cpp.

void getStatistics ( long int &  totalIn,
long int &  totalOut 
) [virtual]

Returns current connection statistics.

Parameters:
totalInThe total number of bytes received.
totalOutThe total number of bytes sent.

Implements ConnectionBase.

Definition at line 120 of file connectionhttpproxy.cpp.

void handleConnect ( const ConnectionBase connection) [virtual]

This function is called when e.g. the raw TCP connection was established.

Parameters:
connectionThe connection.

Implements ConnectionDataHandler.

Definition at line 163 of file connectionhttpproxy.cpp.

void handleDisconnect ( const ConnectionBase connection,
ConnectionError  reason 
) [virtual]

This connection is called when e.g. the raw TCP connection was closed.

Parameters:
connectionThe connection.
reasonThe reason for the disconnect.

Implements ConnectionDataHandler.

Definition at line 207 of file connectionhttpproxy.cpp.

void handleReceivedData ( const ConnectionBase connection,
const std::string &  data 
) [virtual]

This function is called for received from the underlying transport.

Parameters:
connectionThe connection that received the data.
dataThe data received.

Implements ConnectionDataHandler.

Definition at line 128 of file connectionhttpproxy.cpp.

ConnectionBase * newInstance ( ) const [virtual]

This function returns a new instance of the current ConnectionBase-derived object. The idea is to be able to 'clone' ConnectionBase-derived objects without knowing of what type they are exactly.

Returns:
A new Connection* instance.

Implements ConnectionBase.

Definition at line 65 of file connectionhttpproxy.cpp.

ConnectionError receive ( ) [virtual]

Use this function to put the connection into 'receive mode', i.e. this function returns only when the connection is terminated.

Returns:
Returns a value indicating the disconnection reason.

Implements ConnectionBase.

Definition at line 102 of file connectionhttpproxy.cpp.

ConnectionError recv ( int  timeout = -1) [virtual]

Use this periodically to receive data from the socket.

Parameters:
timeoutThe timeout to use for select in microseconds. Default of -1 means blocking.
Returns:
The state of the connection.

Implements ConnectionBase.

Definition at line 97 of file connectionhttpproxy.cpp.

bool send ( const std::string &  data) [virtual]

Use this function to send a string of data over the wire. The function returns only after all data has been sent.

Parameters:
dataThe data to send.
Returns:
True if the data has been sent (no guarantee of receipt), false in case of an error.

Implements ConnectionBase.

Definition at line 107 of file connectionhttpproxy.cpp.

void setConnectionImpl ( ConnectionBase connection)

Sets the underlying transport connection. A possibly existing connection will be deleted.

Parameters:
connectionThe ConnectionBase to replace the current connection, if any.

Definition at line 71 of file connectionhttpproxy.cpp.

void setHTTP11 ( bool  http11) [inline]

Switches usage of HTTP/1.1 on or off.

Parameters:
http11Set this to true to connect through a HTTP/1.1-only proxy, or false to use HTTP/1.0. Defaults to HTTP/1.0 which should work with 99.9% of proxies.

Definition at line 153 of file connectionhttpproxy.h.

void setProxyAuth ( const std::string &  user,
const std::string &  password 
) [inline]

Sets proxy authorization credentials.

Parameters:
userThe user name to use for proxy authorization.
passwordThe password to use for proxy authorization.

Definition at line 139 of file connectionhttpproxy.h.

void setServer ( const std::string &  host,
int  port = -1 
) [inline]

Sets the XMPP server to proxy to.

Parameters:
hostThe XMPP server hostname (IP address).
portThe XMPP server port. The default of -1 means that SRV records will be used to find out about the actual host:port.

Reimplemented from ConnectionBase.

Definition at line 131 of file connectionhttpproxy.h.


The documentation for this class was generated from the following files: