connectiontls.h
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
00108 void setClientCert( const std::string& clientKey, const std::string& clientCerts )
00109 {
00110 m_clientKey = clientKey;
00111 m_clientCerts = clientCerts;
00112 }
00113
00118 void setConnectionImpl( ConnectionBase* connection );
00119
00128 void registerTLSHandler( TLSHandler* th ) { m_tlsHandler = th; }
00129
00130
00131 virtual ConnectionError connect();
00132
00133
00134 virtual ConnectionError recv( int timeout = -1 );
00135
00136
00137 virtual bool send( const std::string& data );
00138
00139
00140 virtual ConnectionError receive();
00141
00142
00143 virtual void disconnect();
00144
00145
00146 virtual void cleanup();
00147
00148
00149 virtual void getStatistics( long int& totalIn, long int& totalOut );
00150
00151
00152 virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00153
00154
00155 virtual void handleConnect( const ConnectionBase* connection );
00156
00157
00158 virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00159
00160
00161 virtual ConnectionBase* newInstance() const;
00162
00163
00164 virtual void handleEncryptedData( const TLSBase*, const std::string& data );
00165
00166
00167 virtual void handleDecryptedData( const TLSBase*, const std::string& data );
00168
00169
00170 virtual void handleHandshakeResult( const TLSBase* base, bool success, CertInfo& certinfo );
00171
00172 protected:
00178 virtual TLSBase* getTLSBase( TLSHandler* th, const std::string server )
00179 {
00180 return new TLSDefault( th, server, TLSDefault::VerifyingClient );
00181 }
00182
00183 ConnectionBase* m_connection;
00184 TLSBase* m_tls;
00185 TLSHandler* m_tlsHandler;
00186 CertInfo m_certInfo;
00187 const LogSink& m_log;
00188 StringList m_cacerts;
00189 std::string m_clientCerts;
00190 std::string m_clientKey;
00191
00192 private:
00193 ConnectionTLS& operator=( const ConnectionTLS& );
00194
00195 };
00196
00197 }
00198
00199 #endif // CONNECTIONTLS_H__