glooxd  0.3-svn
featurestarttls.h
1 /*
2  Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the glooxd library. http://camaya.net/glooxd
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 #ifndef FEATURESTARTTLS_H__
15 #define FEATURESTARTTLS_H__
16 
17 #include "glooxd.h"
18 #include "streamfeature.h"
19 
20 #include <gloox/tlshandler.h>
21 
22 namespace gloox
23 {
24  class Tag;
25  class ConnectionTLSServer;
26 }
27 
28 namespace glooxd
29 {
30 
31  class CertificateProvider;
32 
39  class GLOOXD_API FeatureSTARTTLS : public StreamFeature, public gloox::TLSHandler
40  {
41  public:
48  FeatureSTARTTLS( bool required,
49  CertificateProvider* cp );
50 
54  virtual ~FeatureSTARTTLS();
55 
56  // reimplemented from StreamFeature
57  virtual const std::string& filterString() const;
58 
59  // reimplemented from StreamFeature
60  virtual gloox::Tag* tag( int state, const std::string& domain );
61 
62  // reimplemented from StreamFeature
63  virtual StreamFeature* newInstance() const
64  {
65  return new FeatureSTARTTLS( m_required, m_cp );
66  }
67 
68  // reimplemented from StreamFeature
69  virtual void handleTag( gloox::Tag* tag );
70 
71  // reimplemented from gloox::TLSHandler
72  virtual void handleEncryptedData( const gloox::TLSBase* /*base*/, const std::string& /*data*/ ) {}
73 
74  // reimplemented from gloox::TLSHandler
75  virtual void handleDecryptedData( const gloox::TLSBase* /*base*/, const std::string& /*data*/ ) {}
76 
77  // reimplemented from gloox::TLSHandler
78  virtual void handleHandshakeResult( const gloox::TLSBase* base, bool success, gloox::CertInfo &certinfo );
79 
80  private:
81  enum State
82  {
83  TLSOffered,
84  TLSHandshake,
85  TLSEnabled,
86  TLSCanceled
87  };
88 
89  std::string m_key;
90  std::string m_cert;
91  State m_state;
92  CertificateProvider* m_cp;
93  gloox::ConnectionTLSServer* m_encryption;
94  bool m_required;
95 
96  };
97 
98 }
99 
100 #endif // FEATURESTARTTLS_H__