ConnectionBOSH Class Reference

This is an implementation of a BOSH (HTTP binding) connection. More...

#include <connectionbosh.h>

Inherits gloox::ConnectionBase, gloox::ConnectionDataHandler, and gloox::TagHandler.

List of all members.

Public Types

enum  ConnMode { ModeLegacyHTTP, ModePersistentHTTP, ModePipelining }

Public Member Functions

 ConnectionBOSH (ConnectionBase *connection, const LogSink &logInstance, const std::string &boshHost, const std::string &xmppServer, int xmppPort=5222)
 ConnectionBOSH (ConnectionDataHandler *cdh, ConnectionBase *connection, const LogSink &logInstance, const std::string &boshHost, const std::string &xmppServer, int xmppPort=5222)
virtual ~ConnectionBOSH ()
void setServer (const std::string &xmppHost, unsigned short xmppPort=5222)
void setPath (const std::string &path)
void setMode (ConnMode mode)
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
virtual void handleTag (Tag *tag)

Detailed Description

This is an implementation of a BOSH (HTTP binding) connection.

Usage:

 Client *c = new Client( ... );
 c->setConnectionImpl( new ConnectionBOSH( c,
                                new ConnectionTCPClient( c->logInstance(), httpServer, httpPort ),
                                c->logInstance(), boshHost, xmpphost, xmppPort ) );

Make sure to pass the BOSH connection manager's host/port to the transport connection (ConnectionTCPClient in this case), and the XMPP server's host and port to the BOSH connection. You must also pass to BOSH the address of the BOSH server you are dealing with, this is used in the HTTP Host header.

In the case of using ConnectionBOSH through a HTTP proxy, supply httpServer and httpPort as those of the proxy. In all cases, boshHost should be set to the hostname (not IP address) of the server running the BOSH connection manager.

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

Note:
To avoid problems, you should disable TLS in gloox by calling ClientBase::setTls( TLSDisabled ).

Sample configurations for different servers can be found in the bosh_example.cpp file included with gloox in the src/examples/ directory.

Author:
Matthew Wild <mwild1@gmail.com>
Jakob Schroeter <js@camaya.net>
Since:
1.0

Definition at line 64 of file connectionbosh.h.


Member Enumeration Documentation

enum ConnMode

The supported connection modes. Usually auto-detected.

Enumerator:
ModeLegacyHTTP 

HTTP 1.0 connections, closed after receiving a response

ModePersistentHTTP 

HTTP 1.1 connections, re-used after receiving a response

ModePipelining 

HTTP Pipelining (implies HTTP 1.1) a single connection is used

Definition at line 110 of file connectionbosh.h.


Constructor & Destructor Documentation

ConnectionBOSH ( ConnectionBase connection,
const LogSink logInstance,
const std::string &  boshHost,
const std::string &  xmppServer,
int  xmppPort = 5222 
)

Constructs a new ConnectionBOSH object.

Parameters:
connection A transport connection. It should be configured to connect to the BOSH connection manager's (or a HTTP proxy's) host and port, not to the XMPP host. ConnectionBOSH will own the transport connection and delete it in its destructor.
logInstance The log target. Obtain it from ClientBase::logInstance().
boshHost The hostname of the BOSH connection manager
xmppServer A server to connect to. This is the XMPP server's address, not the connection manager's.
xmppPort The port to connect to. This is the XMPP server's port, not the connection manager's.
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 20 of file connectionbosh.cpp.

ConnectionBOSH ( ConnectionDataHandler cdh,
ConnectionBase connection,
const LogSink logInstance,
const std::string &  boshHost,
const std::string &  xmppServer,
int  xmppPort = 5222 
)

Constructs a new ConnectionBOSH object.

Parameters:
cdh An ConnectionDataHandler-derived object that will handle incoming data.
connection A transport connection. It should be configured to connect to the connection manager's (or proxy's) host and port, not to the XMPP host. ConnectionBOSH will own the transport connection and delete it in its destructor.
logInstance The log target. Obtain it from ClientBase::logInstance().
boshHost The hostname of the BOSH connection manager (not any intermediate proxy)
xmppServer A server to connect to. This is the XMPP server's address, not the connection manager's.
xmppPort The port to connect to. This is the XMPP server's port, not the connection manager's.

Definition at line 33 of file connectionbosh.cpp.

~ConnectionBOSH (  )  [virtual]

Virtual destructor

Definition at line 65 of file connectionbosh.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 332 of file connectionbosh.cpp.

ConnectionError connect (  )  [virtual]

Used to initiate the connection.

Returns:
Returns the connection state.

Implements ConnectionBase.

Definition at line 92 of file connectionbosh.cpp.

void disconnect (  )  [virtual]

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

Implements ConnectionBase.

Definition at line 110 of file connectionbosh.cpp.

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

Returns current connection statistics.

Parameters:
totalIn The total number of bytes received.
totalOut The total number of bytes sent.

Implements ConnectionBase.

Definition at line 340 of file connectionbosh.cpp.

void handleConnect ( const ConnectionBase connection  )  [virtual]

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

Parameters:
connection The connection.

Implements ConnectionDataHandler.

Definition at line 395 of file connectionbosh.cpp.

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

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

Parameters:
connection The connection.
reason The reason for the disconnect.

Implements ConnectionDataHandler.

Definition at line 422 of file connectionbosh.cpp.

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

This function is called for received from the underlying transport.

Parameters:
connection The connection that received the data.
data The data received.

Implements ConnectionDataHandler.

Definition at line 346 of file connectionbosh.cpp.

void handleTag ( Tag tag  )  [virtual]

This function is called when a registered XML element arrives. As with every handler in gloox, the Tag is going to be deleted after this function returned. If you need a copy afterwards, create it using Tag::clone().

Parameters:
tag The complete Tag.

Implements TagHandler.

Definition at line 447 of file connectionbosh.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 71 of file connectionbosh.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 324 of file connectionbosh.cpp.

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

Use this periodically to receive data from the socket.

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

Implements ConnectionBase.

Definition at line 150 of file connectionbosh.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:
data The 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 172 of file connectionbosh.cpp.

void setMode ( ConnMode  mode  )  [inline]

Sets the connection mode

Parameters:
mode The connection mode,
See also:
ConnMode
Note:
In the case that a mode is selected that the connection manager or proxy does not support, gloox will fall back to using HTTP/1.0 connections, which should work with any server.

Definition at line 139 of file connectionbosh.h.

void setPath ( const std::string &  path  )  [inline]

Sets the path on the connection manager to request

Parameters:
path The path, the default is "/http-bind/", which is the default for many connection managers.

Definition at line 130 of file connectionbosh.h.

void setServer ( const std::string &  xmppHost,
unsigned short  xmppPort = 5222 
) [inline]

Sets the XMPP server to proxy to.

Parameters:
xmppHost The XMPP server hostname (IP address).
xmppPort The XMPP server port.

Definition at line 122 of file connectionbosh.h.


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

Generated by  doxygen 1.6.2