Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

connectionbosh.h

00001 /*
00002  * Copyright (c) 2007-2008 by Jakob Schroeter <js@camaya.net>
00003  * This file is part of the gloox library. http://camaya.net/gloox
00004  *
00005  * This software is distributed under a license. The full license
00006  * agreement can be found in the file LICENSE in this distribution.
00007  * This software may not be copied, modified, sold or distributed
00008  * other than expressed in the named license agreement.
00009  *
00010  * This software is distributed without any warranty.
00011  */
00012 
00013 #ifndef CONNECTIONBOSH_H__
00014 #define CONNECTIONBOSH_H__
00015 
00016 #include "gloox.h"
00017 #include "connectionbase.h"
00018 #include "logsink.h"
00019 #include "taghandler.h"
00020 #include "parser.h"
00021 
00022 #include <string>
00023 #include <list>
00024 
00025 namespace gloox
00026 {
00027 
00066   class GLOOX_API ConnectionBOSH : public ConnectionBase, ConnectionDataHandler, TagHandler
00067   {
00068     public:
00084       ConnectionBOSH( ConnectionBase* connection, const LogSink& logInstance, const std::string& boshHost,
00085                       const std::string& xmppServer, int xmppPort = 5222 );
00086 
00100       ConnectionBOSH( ConnectionDataHandler* cdh, ConnectionBase* connection,
00101                       const LogSink& logInstance, const std::string& boshHost,
00102                       const std::string& xmppServer, int xmppPort = 5222 );
00103 
00107       virtual ~ConnectionBOSH();
00108 
00112       enum ConnMode
00113       {
00114         ModeLegacyHTTP,             
00115         ModePersistentHTTP,         
00116         ModePipelining              
00117       };
00118 
00124       void setServer( const std::string& xmppHost, unsigned short xmppPort = 5222 )
00125         { m_server = xmppHost; m_port = xmppPort; }
00126 
00132       void setPath( const std::string& path ) { m_path = path; }
00133 
00141       void setMode( ConnMode mode ) { m_connMode = mode; }
00142 
00143       // reimplemented from ConnectionBase
00144       virtual ConnectionError connect();
00145 
00146       // reimplemented from ConnectionBase
00147       virtual ConnectionError recv( int timeout = -1 );
00148 
00149       // reimplemented from ConnectionBase
00150       virtual bool send( const std::string& data );
00151 
00152       // reimplemented from ConnectionBase
00153       virtual ConnectionError receive();
00154 
00155       // reimplemented from ConnectionBase
00156       virtual void disconnect();
00157 
00158       // reimplemented from ConnectionBase
00159       virtual void cleanup();
00160 
00161       // reimplemented from ConnectionBase
00162       virtual void getStatistics( int& totalIn, int& totalOut );
00163 
00164       // reimplemented from ConnectionDataHandler
00165       virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00166 
00167       // reimplemented from ConnectionDataHandler
00168       virtual void handleConnect( const ConnectionBase* connection );
00169 
00170       // reimplemented from ConnectionDataHandler
00171       virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00172 
00173       // reimplemented from ConnectionDataHandler
00174       virtual ConnectionBase* newInstance() const;
00175 
00176       // reimplemented from TagHandler
00177       virtual void handleTag( Tag* tag );
00178 
00179     private:
00180       ConnectionBOSH& operator=( const ConnectionBOSH& );
00181       void initInstance( ConnectionBase* connection, const std::string& xmppServer, const int xmppPort );
00182       bool sendRequest( const std::string& xml );
00183       bool sendXML();
00184       const std::string getHTTPField( const std::string& field );
00185       ConnectionBase* getConnection();
00186       ConnectionBase* activateConnection();
00187       void putConnection();
00188 
00189       //ConnectionBase *m_connection;
00190       const LogSink& m_logInstance;
00191 
00192       Parser m_parser;   // Used for parsing XML section of responses
00193       std::string m_boshHost;   // The hostname of the BOSH connection manager
00194       std::string m_boshedHost;   // The hostname of the BOSH connection manager + : + port
00195       std::string m_path;   // The path part of the URL that we need to request
00196 
00197       // BOSH parameters
00198       unsigned long m_rid;
00199       std::string m_sid;
00200 
00201       bool m_initialStreamSent;
00202       int m_openRequests;
00203       int m_maxOpenRequests;
00204       int m_wait;
00205       int m_hold;
00206 
00207       bool m_streamRestart;   // Set to true if we are waiting for an acknowledgement of a stream restart
00208 
00209       unsigned long m_lastRequestTime;
00210       unsigned long m_minTimePerRequest;
00211 
00212       std::string m_buffer;   // Buffer of received data
00213       std::string m_bufferHeader;   // HTTP header of data currently in buffer // FIXME doens't need to be member
00214       std::string::size_type m_bufferContentLength;   // Length of the data in the current response
00215 
00216       std::string m_sendBuffer;   // Data waiting to be sent
00217 
00218       typedef std::list<ConnectionBase*> ConnectionList;
00219       ConnectionList m_activeConnections;
00220       ConnectionList m_connectionPool;
00221       ConnMode m_connMode;
00222 
00223   };
00224 
00225 }
00226 
00227 #endif // CONNECTIONBOSH_H__

Generated on Mon Sep 1 09:25:09 2008 for gloox by  doxygen 1.4.1