gloox  1.1-svn
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  protected:
66  virtual void getCertInfo() {}
67 
68  gnutls_session_t* m_session;
69 
70  std::string m_recvBuffer;
71  char* m_buf;
72  const int m_bufsize;
73 
74  ssize_t pullFunc( void* data, size_t len );
75  static ssize_t pullFunc( gnutls_transport_ptr_t ptr, void* data, size_t len );
76 
77  ssize_t pushFunc( const void* data, size_t len );
78  static ssize_t pushFunc( gnutls_transport_ptr_t ptr, const void* data, size_t len );
79 
80  };
81 
82 }
83 
84 #endif // HAVE_GNUTLS
85 
86 #endif // TLSGNUTLSBASE_H__