gloox  1.0
tlsgnutlsbase.h
1 /*
2  Copyright (c) 2007-2009 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 #include "config.h"
21 
22 #ifdef HAVE_GNUTLS
23 
24 #include <gnutls/gnutls.h>
25 #include <gnutls/x509.h>
26 
27 namespace gloox
28 {
29 
38  class GnuTLSBase : public TLSBase
39  {
40  public:
46  GnuTLSBase( TLSHandler* th, const std::string& server = EmptyString );
47 
51  virtual ~GnuTLSBase();
52 
53  // reimplemented from TLSBase
54  virtual bool encrypt( const std::string& data );
55 
56  // reimplemented from TLSBase
57  virtual int decrypt( const std::string& data );
58 
59  // reimplemented from TLSBase
60  virtual void cleanup();
61 
62  // reimplemented from TLSBase
63  virtual bool handshake();
64 
65  // reimplemented from TLSBase
66  virtual void setCACerts( const StringList& /*cacerts*/ ) {}
67 
68  // reimplemented from TLSBase
69  virtual void setClientCert( const std::string& /*clientKey*/, const std::string& /*clientCerts*/ ) {}
70 
71  protected:
72  virtual void getCertInfo() {}
73 
74  gnutls_session_t* m_session;
75 
76  std::string m_recvBuffer;
77  char* m_buf;
78  const int m_bufsize;
79 
80  ssize_t pullFunc( void* data, size_t len );
81  static ssize_t pullFunc( gnutls_transport_ptr_t ptr, void* data, size_t len );
82 
83  ssize_t pushFunc( const void* data, size_t len );
84  static ssize_t pushFunc( gnutls_transport_ptr_t ptr, const void* data, size_t len );
85 
86  };
87 
88 }
89 
90 #endif // HAVE_GNUTLS
91 
92 #endif // TLSGNUTLSBASE_H__