gloox 1.0

connectiontls.h

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 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       // reimplemented from ConnectionBase
00131       virtual ConnectionError connect();
00132 
00133       // reimplemented from ConnectionBase
00134       virtual ConnectionError recv( int timeout = -1 );
00135 
00136       // reimplemented from ConnectionBase
00137       virtual bool send( const std::string& data );
00138 
00139       // reimplemented from ConnectionBase
00140       virtual ConnectionError receive();
00141 
00142       // reimplemented from ConnectionBase
00143       virtual void disconnect();
00144 
00145       // reimplemented from ConnectionBase
00146       virtual void cleanup();
00147 
00148       // reimplemented from ConnectionBase
00149       virtual void getStatistics( long int& totalIn, long int& totalOut );
00150 
00151       // reimplemented from ConnectionDataHandler
00152       virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00153 
00154       // reimplemented from ConnectionDataHandler
00155       virtual void handleConnect( const ConnectionBase* connection );
00156 
00157       // reimplemented from ConnectionDataHandler
00158       virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00159 
00160       // reimplemented from ConnectionDataHandler
00161       virtual ConnectionBase* newInstance() const;
00162 
00163       // reimplemented from TLSHandler
00164       virtual void handleEncryptedData( const TLSBase*, const std::string& data );
00165 
00166       // reimplemented from TLSHandler
00167       virtual void handleDecryptedData( const TLSBase*, const std::string& data );
00168 
00169       // reimplemented from TLSHandler
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__