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

tlsdefault.cpp

00001 /*
00002  * Copyright (c) 2007-2008 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 #include "tlsdefault.h"
00014 
00015 #include "tlshandler.h"
00016 
00017 #ifdef _WIN32
00018 # include "../config.h.win"
00019 #elif defined( _WIN32_WCE )
00020 # include "../config.h.win"
00021 #else
00022 # include "config.h"
00023 #endif
00024 
00025 #if defined( HAVE_OPENSSL )
00026 # define HAVE_TLS
00027 # include "tlsopenssl.h"
00028 #elif defined( HAVE_GNUTLS )
00029 # define HAVE_TLS
00030 # include "tlsgnutlsclient.h"
00031 # include "tlsgnutlsclientanon.h"
00032 # include "tlsgnutlsserveranon.h"
00033 #elif defined( HAVE_WINTLS )
00034 # define HAVE_TLS
00035 # include "tlsschannel.h"
00036 #endif
00037 
00038 namespace gloox
00039 {
00040 
00041   TLSDefault::TLSDefault( TLSHandler* th, const std::string server, Type type )
00042     : TLSBase( th, server ), m_impl( 0 )
00043   {
00044     switch( type )
00045     {
00046       case VerifyingClient:
00047 #ifdef HAVE_GNUTLS
00048         m_impl = new GnuTLSClient( th, server );
00049 #elif defined( HAVE_OPENSSL )
00050         m_impl = new OpenSSL( th, server );
00051 #elif defined( HAVE_WINTLS )
00052         m_impl = new SChannel( th, server );
00053 #endif
00054         break;
00055       case AnonymousClient:
00056 #ifdef HAVE_GNUTLS
00057         m_impl = new GnuTLSClientAnon( th );
00058 #endif
00059         break;
00060       case AnonymousServer:
00061 #ifdef HAVE_GNUTLS
00062         m_impl = new GnuTLSServerAnon( th );
00063 #endif
00064         break;
00065       case VerifyingServer:
00066         break;
00067       default:
00068         break;
00069     }
00070   }
00071 
00072   TLSDefault::~TLSDefault()
00073   {
00074     delete m_impl;
00075   }
00076 
00077   bool TLSDefault::init()
00078   {
00079     return m_impl ? m_impl->init() : false;
00080   }
00081 
00082   int TLSDefault::types()
00083   {
00084     int types = 0;
00085 #ifdef HAVE_GNUTLS
00086     types |= VerifyingClient;
00087     types |= AnonymousClient;
00088     types |= AnonymousServer;
00089 #elif defined( HAVE_OPENSSL )
00090     types |= VerifyingClient;
00091 #elif defined( HAVE_WINTLS )
00092     types |= VerifyingClient;
00093 #endif
00094     return types;
00095   }
00096 
00097   bool TLSDefault::encrypt( const std::string& data )
00098   {
00099     return m_impl ? m_impl->encrypt( data ) : false;
00100   }
00101 
00102   int TLSDefault::decrypt( const std::string& data )
00103   {
00104     return m_impl ? m_impl->decrypt( data ) : 0;
00105   }
00106 
00107   void TLSDefault::cleanup()
00108   {
00109     if( m_impl )
00110       m_impl->cleanup();
00111   }
00112 
00113   bool TLSDefault::handshake()
00114   {
00115     return m_impl ? m_impl->handshake() : false;
00116   }
00117 
00118   bool TLSDefault::isSecure() const
00119   {
00120     return m_impl ? m_impl->isSecure() : false;
00121   }
00122 
00123   void TLSDefault::setCACerts( const StringList& cacerts )
00124   {
00125     if( m_impl )
00126       m_impl->setCACerts( cacerts );
00127   }
00128 
00129   const CertInfo& TLSDefault::fetchTLSInfo() const
00130   {
00131     return m_impl ? m_impl->fetchTLSInfo() : m_certInfo;
00132   }
00133 
00134   void TLSDefault::setClientCert( const std::string& clientKey, const std::string& clientCerts )
00135   {
00136     if( m_impl )
00137       m_impl->setClientCert( clientKey, clientCerts );
00138   }
00139 
00140 }

Generated on Sun Dec 28 22:10:18 2008 for gloox by  doxygen 1.4.1