gloox
1.0
|
00001 /* 00002 * Copyright (c) 2007-2009 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 #include <ctime> 00025 00026 namespace gloox 00027 { 00028 00064 class GLOOX_API ConnectionBOSH : public ConnectionBase, ConnectionDataHandler, TagHandler 00065 { 00066 public: 00082 ConnectionBOSH( ConnectionBase* connection, const LogSink& logInstance, const std::string& boshHost, 00083 const std::string& xmppServer, int xmppPort = 5222 ); 00084 00098 ConnectionBOSH( ConnectionDataHandler* cdh, ConnectionBase* connection, 00099 const LogSink& logInstance, const std::string& boshHost, 00100 const std::string& xmppServer, int xmppPort = 5222 ); 00101 00105 virtual ~ConnectionBOSH(); 00106 00110 enum ConnMode 00111 { 00112 ModeLegacyHTTP, 00113 ModePersistentHTTP, 00114 ModePipelining 00115 }; 00116 00122 void setServer( const std::string& xmppHost, unsigned short xmppPort = 5222 ) 00123 { m_server = xmppHost; m_port = xmppPort; } 00124 00130 void setPath( const std::string& path ) { m_path = path; } 00131 00139 void setMode( ConnMode mode ) { m_connMode = mode; } 00140 00141 // reimplemented from ConnectionBase 00142 virtual ConnectionError connect(); 00143 00144 // reimplemented from ConnectionBase 00145 virtual ConnectionError recv( int timeout = -1 ); 00146 00147 // reimplemented from ConnectionBase 00148 virtual bool send( const std::string& data ); 00149 00150 // reimplemented from ConnectionBase 00151 virtual ConnectionError receive(); 00152 00153 // reimplemented from ConnectionBase 00154 virtual void disconnect(); 00155 00156 // reimplemented from ConnectionBase 00157 virtual void cleanup(); 00158 00159 // reimplemented from ConnectionBase 00160 virtual void getStatistics( long int& totalIn, long int& totalOut ); 00161 00162 // reimplemented from ConnectionDataHandler 00163 virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data ); 00164 00165 // reimplemented from ConnectionDataHandler 00166 virtual void handleConnect( const ConnectionBase* connection ); 00167 00168 // reimplemented from ConnectionDataHandler 00169 virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason ); 00170 00171 // reimplemented from ConnectionDataHandler 00172 virtual ConnectionBase* newInstance() const; 00173 00174 // reimplemented from TagHandler 00175 virtual void handleTag( Tag* tag ); 00176 00177 private: 00178 ConnectionBOSH& operator=( const ConnectionBOSH& ); 00179 void initInstance( ConnectionBase* connection, const std::string& xmppServer, const int xmppPort ); 00180 bool sendRequest( const std::string& xml ); 00181 bool sendXML(); 00182 const std::string getHTTPField( const std::string& field ); 00183 ConnectionBase* getConnection(); 00184 ConnectionBase* activateConnection(); 00185 void putConnection(); 00186 00187 //ConnectionBase *m_connection; 00188 const LogSink& m_logInstance; 00189 00190 Parser m_parser; // Used for parsing XML section of responses 00191 std::string m_boshHost; // The hostname of the BOSH connection manager 00192 std::string m_boshedHost; // The hostname of the BOSH connection manager + : + port 00193 std::string m_path; // The path part of the URL that we need to request 00194 00195 // BOSH parameters 00196 unsigned long m_rid; 00197 std::string m_sid; 00198 00199 bool m_initialStreamSent; 00200 int m_openRequests; 00201 int m_maxOpenRequests; 00202 int m_wait; 00203 int m_hold; 00204 00205 bool m_streamRestart; // Set to true if we are waiting for an acknowledgement of a stream restart 00206 00207 time_t m_lastRequestTime; 00208 unsigned long m_minTimePerRequest; 00209 00210 std::string m_buffer; // Buffer of received data 00211 std::string m_bufferHeader; // HTTP header of data currently in buffer // FIXME doens't need to be member 00212 std::string::size_type m_bufferContentLength; // Length of the data in the current response 00213 00214 std::string m_sendBuffer; // Data waiting to be sent 00215 00216 typedef std::list<ConnectionBase*> ConnectionList; 00217 ConnectionList m_activeConnections; 00218 ConnectionList m_connectionPool; 00219 ConnMode m_connMode; 00220 00221 }; 00222 00223 } 00224 00225 #endif // CONNECTIONBOSH_H__