gloox  0.9.9.12
tlsgnutlsbase.h
1 /*
2  Copyright (c) 2007-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #ifndef TLSGNUTLSBASE_H__
16 #define TLSGNUTLSBASE_H__
17 
18 #include "tlsbase.h"
19 
20 #ifdef _WIN32
21 # include "../config.h.win"
22 #elif defined( _WIN32_WCE )
23 # include "../config.h.win"
24 #else
25 # include "config.h"
26 #endif
27 
28 #ifdef HAVE_GNUTLS
29 
30 #include <gnutls/gnutls.h>
31 #include <gnutls/x509.h>
32 
33 namespace gloox
34 {
35 
44  class GnuTLSBase : public TLSBase
45  {
46  public:
52  GnuTLSBase( TLSHandler *th, const std::string& server = "" );
53 
57  virtual ~GnuTLSBase();
58 
59  // reimplemented from TLSBase
60  virtual bool encrypt( const std::string& data );
61 
62  // reimplemented from TLSBase
63  virtual int decrypt( const std::string& data );
64 
65  // reimplemented from TLSBase
66  virtual void cleanup();
67 
68  // reimplemented from TLSBase
69  virtual bool handshake();
70 
71  // reimplemented from TLSBase
72  virtual void setCACerts( const StringList& /*cacerts*/ ) {}
73 
74  // reimplemented from TLSBase
75  virtual void setClientCert( const std::string& /*clientKey*/, const std::string& /*clientCerts*/ ) {}
76 
77  protected:
78  virtual void init() = 0;
79  virtual void getCertInfo() {}
80 
81  gnutls_session_t* m_session;
82 
83  std::string m_recvBuffer;
84  char *m_buf;
85  const int m_bufsize;
86 
87  ssize_t pullFunc( void *data, size_t len );
88  static ssize_t pullFunc( gnutls_transport_ptr_t ptr, void *data, size_t len );
89 
90  ssize_t pushFunc( const void *data, size_t len );
91  static ssize_t pushFunc( gnutls_transport_ptr_t ptr, const void *data, size_t len );
92 
93  };
94 
95 }
96 
97 #endif // HAVE_GNUTLS
98 
99 #endif // TLSGNUTLSBASE_H__