00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00144 virtual ConnectionError connect();
00145
00146
00147 virtual ConnectionError recv( int timeout = -1 );
00148
00149
00150 virtual bool send( const std::string& data );
00151
00152
00153 virtual ConnectionError receive();
00154
00155
00156 virtual void disconnect();
00157
00158
00159 virtual void cleanup();
00160
00161
00162 virtual void getStatistics( int& totalIn, int& totalOut );
00163
00164
00165 virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00166
00167
00168 virtual void handleConnect( const ConnectionBase* connection );
00169
00170
00171 virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00172
00173
00174 virtual ConnectionBase* newInstance() const;
00175
00176
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
00190 const LogSink& m_logInstance;
00191
00192 Parser m_parser;
00193 std::string m_boshHost;
00194 std::string m_boshedHost;
00195 std::string m_path;
00196
00197
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;
00208
00209 unsigned long m_lastRequestTime;
00210 unsigned long m_minTimePerRequest;
00211
00212 std::string m_buffer;
00213 std::string m_bufferHeader;
00214 std::string::size_type m_bufferContentLength;
00215
00216 std::string m_sendBuffer;
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__