00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef CONNECTIONTLS_H__
00014 #define CONNECTIONTLS_H__
00015
00016 #include "gloox.h"
00017 #include "logsink.h"
00018 #include "connectionbase.h"
00019 #include "tlsdefault.h"
00020 #include "connectiondatahandler.h"
00021
00022 #include <string>
00023
00024 namespace gloox
00025 {
00026
00051 class GLOOX_API ConnectionTLS : public TLSHandler, public ConnectionBase, public ConnectionDataHandler
00052 {
00053 public:
00062 ConnectionTLS( ConnectionDataHandler* cdh, ConnectionBase* conn, const LogSink& log );
00063
00071 ConnectionTLS( ConnectionBase* conn, const LogSink& log );
00072
00076 virtual ~ConnectionTLS();
00077
00084 void setCACerts( const StringList& cacerts )
00085 {
00086 m_cacerts = cacerts;
00087 }
00088
00094 const CertInfo& fetchTLSInfo() const { return m_certInfo; }
00095
00107 void setClientCert( const std::string& clientKey, const std::string& clientCerts )
00108 {
00109 m_clientKey = clientKey;
00110 m_clientCerts = clientCerts;
00111 }
00112
00125 virtual void setSubject( const std::string& subject ) { m_subject = subject; }
00126
00131 void setConnectionImpl( ConnectionBase* connection );
00132
00141 void registerTLSHandler( TLSHandler* th ) { m_tlsHandler = th; }
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( long int& totalIn, long 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 handleEncryptedData( const TLSBase*, const std::string& data );
00178
00179
00180 virtual void handleDecryptedData( const TLSBase*, const std::string& data );
00181
00182
00183 virtual void handleHandshakeResult( const TLSBase* base, bool success, CertInfo& certinfo );
00184
00185 protected:
00191 virtual TLSBase* getTLSBase( TLSHandler* th, const std::string server )
00192 {
00193 return new TLSDefault( th, server, TLSDefault::VerifyingClient );
00194 }
00195
00196 ConnectionBase* m_connection;
00197 TLSBase* m_tls;
00198 TLSHandler* m_tlsHandler;
00199 CertInfo m_certInfo;
00200 const LogSink& m_log;
00201 StringList m_cacerts;
00202 std::string m_clientCerts;
00203 std::string m_clientKey;
00204 std::string m_subject;
00205
00206 private:
00207 ConnectionTLS& operator=( const ConnectionTLS& );
00208
00209 };
00210
00211 }
00212
00213 #endif // CONNECTIONTLS_H__