connectionbosh.h
/*
* Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
* This file is part of the gloox library. http://camaya.net/gloox
*
* This software is distributed under a license. The full license
* agreement can be found in the file LICENSE in this distribution.
* This software may not be copied, modified, sold or distributed
* other than expressed in the named license agreement.
*
* This software is distributed without any warranty.
*/
#ifndef CONNECTIONBOSH_H__
#define CONNECTIONBOSH_H__
#include "gloox.h"
#include "connectionbase.h"
#include "logsink.h"
#include "taghandler.h"
#include "parser.h"
#include <string>
#include <list>
#include <ctime>
namespace gloox
{
class GLOOX_API ConnectionBOSH : public ConnectionBase, ConnectionDataHandler, TagHandler
{
public:
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();
enum ConnMode
{
ModeLegacyHTTP,
ModePersistentHTTP,
ModePipelining
};
void setServer( const std::string& xmppHost, unsigned short xmppPort = 5222 )
{ m_server = xmppHost; m_port = xmppPort; }
void setPath( const std::string& path ) { m_path = path; }
void setMode( ConnMode mode ) { m_connMode = mode; }
// reimplemented from ConnectionBase
virtual ConnectionError connect();
// reimplemented from ConnectionBase
virtual ConnectionError recv( int timeout = -1 );
// reimplemented from ConnectionBase
virtual bool send( const std::string& data );
// reimplemented from ConnectionBase
virtual ConnectionError receive();
// reimplemented from ConnectionBase
virtual void disconnect();
// reimplemented from ConnectionBase
virtual void cleanup();
// reimplemented from ConnectionBase
virtual void getStatistics( long int& totalIn, long int& totalOut );
// reimplemented from ConnectionDataHandler
virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
// reimplemented from ConnectionDataHandler
virtual void handleConnect( const ConnectionBase* connection );
// reimplemented from ConnectionDataHandler
virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
// reimplemented from ConnectionDataHandler
virtual ConnectionBase* newInstance() const;
// reimplemented from TagHandler
virtual void handleTag( Tag* tag );
private:
ConnectionBOSH& operator=( const ConnectionBOSH& );
void initInstance( ConnectionBase* connection, const std::string& xmppServer, const int xmppPort );
bool sendRequest( const std::string& xml );
bool sendXML();
const std::string getHTTPField( const std::string& field );
ConnectionBase* getConnection();
ConnectionBase* activateConnection();
void putConnection();
//ConnectionBase *m_connection;
const LogSink& m_logInstance;
Parser m_parser; // Used for parsing XML section of responses
std::string m_boshHost; // The hostname of the BOSH connection manager
std::string m_boshedHost; // The hostname of the BOSH connection manager + : + port
std::string m_path; // The path part of the URL that we need to request
// BOSH parameters
unsigned long m_rid;
std::string m_sid;
bool m_initialStreamSent;
int m_openRequests;
int m_maxOpenRequests;
int m_wait;
int m_hold;
bool m_streamRestart; // Set to true if we are waiting for an acknowledgement of a stream restart
time_t m_lastRequestTime;
unsigned long m_minTimePerRequest;
std::string m_buffer; // Buffer of received data
std::string m_bufferHeader; // HTTP header of data currently in buffer // FIXME doens't need to be member
std::string::size_type m_bufferContentLength; // Length of the data in the current response
std::string m_sendBuffer; // Data waiting to be sent
typedef std::list<ConnectionBase*> ConnectionList;
ConnectionList m_activeConnections;
ConnectionList m_connectionPool;
ConnMode m_connMode;
};
}
#endif // CONNECTIONBOSH_H__
gloox::ConnectionBOSH
This is an implementation of a BOSH (HTTP binding) connection.
Definition connectionbosh.h:65
gloox::ConnectionBOSH::ConnectionBOSH
ConnectionBOSH(ConnectionBase *connection, const LogSink &logInstance, const std::string &boshHost, const std::string &xmppServer, int xmppPort=5222)
Definition connectionbosh.cpp:31
gloox::ConnectionBOSH::setPath
void setPath(const std::string &path)
Definition connectionbosh.h:130
gloox::ConnectionBOSH::setMode
void setMode(ConnMode mode)
Definition connectionbosh.h:139
gloox::ConnectionBOSH::setServer
void setServer(const std::string &xmppHost, unsigned short xmppPort=5222)
Definition connectionbosh.h:122
gloox::ConnectionBOSH::ConnMode
ConnMode
Definition connectionbosh.h:111
gloox::ConnectionBOSH::ModePersistentHTTP
@ ModePersistentHTTP
Definition connectionbosh.h:113
gloox::ConnectionBOSH::ModePipelining
@ ModePipelining
Definition connectionbosh.h:114
gloox::ConnectionBOSH::ModeLegacyHTTP
@ ModeLegacyHTTP
Definition connectionbosh.h:112
gloox::ConnectionBase
An abstract base class for a connection.
Definition connectionbase.h:35
gloox::ConnectionBase::m_port
int m_port
Definition connectionbase.h:161
gloox::ConnectionBase::m_server
std::string m_server
Definition connectionbase.h:158
gloox::ConnectionBase::ConnectionBase
ConnectionBase(ConnectionDataHandler *cdh)
Definition connectionbase.h:42
gloox::ConnectionDataHandler
This is an abstract base class to receive events from a ConnectionBase-derived object.
Definition connectiondatahandler.h:36
gloox::LogSink
An implementation of log sink and source.
Definition logsink.h:39
gloox::Parser
This class implements an XML parser.
Definition parser.h:35
gloox::TagHandler
A virtual interface which can be reimplemented to receive non-XMPP Core stanzas.
Definition taghandler.h:33
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::ConnectionError
ConnectionError
Definition gloox.h:684