Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

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 
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       // reimplemented from ConnectionBase
00144       virtual ConnectionError connect();
00145 
00146       // reimplemented from ConnectionBase
00147       virtual ConnectionError recv( int timeout = -1 );
00148 
00149       // reimplemented from ConnectionBase
00150       virtual bool send( const std::string& data );
00151 
00152       // reimplemented from ConnectionBase
00153       virtual ConnectionError receive();
00154 
00155       // reimplemented from ConnectionBase
00156       virtual void disconnect();
00157 
00158       // reimplemented from ConnectionBase
00159       virtual void cleanup();
00160 
00161       // reimplemented from ConnectionBase
00162       virtual void getStatistics( long int& totalIn, long int& totalOut );
00163 
00164       // reimplemented from ConnectionDataHandler
00165       virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00166 
00167       // reimplemented from ConnectionDataHandler
00168       virtual void handleConnect( const ConnectionBase* connection );
00169 
00170       // reimplemented from ConnectionDataHandler
00171       virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00172 
00173       // reimplemented from ConnectionDataHandler
00174       virtual ConnectionBase* newInstance() const;
00175 
00176       // reimplemented from TLSHandler
00177       virtual void handleEncryptedData( const TLSBase*, const std::string& data );
00178 
00179       // reimplemented from TLSHandler
00180       virtual void handleDecryptedData( const TLSBase*, const std::string& data );
00181 
00182       // reimplemented from TLSHandler
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__

Generated on Tue May 4 16:35:12 2010 for gloox by  doxygen 1.4.1