comparison 3rdparty/vmime/src/vmime/security/sasl/SASLMechanismFactory.hpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library. Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23
24 #ifndef VMIME_SECURITY_SASL_SASLMECHANISMFACTORY_HPP_INCLUDED
25 #define VMIME_SECURITY_SASL_SASLMECHANISMFACTORY_HPP_INCLUDED
26
27
28 #include "vmime/config.hpp"
29
30
31 #if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_SASL_SUPPORT
32
33
34 #include "vmime/types.hpp"
35 #include "vmime/base.hpp"
36
37 #include "vmime/security/sasl/SASLMechanism.hpp"
38
39 #include <map>
40
41
42 namespace vmime {
43 namespace security {
44 namespace sasl {
45
46
47 class SASLContext;
48
49
50 /** Constructs SASL mechanism objects.
51 */
52 class VMIME_EXPORT SASLMechanismFactory : public object
53 {
54 private:
55
56 SASLMechanismFactory();
57 ~SASLMechanismFactory();
58
59
60 class registeredMechanism : public object
61 {
62 public:
63
64 virtual shared_ptr <SASLMechanism> create
65 (shared_ptr <SASLContext> ctx, const string& name) = 0;
66 };
67
68 template <typename T>
69 class registeredMechanismImpl : public registeredMechanism
70 {
71 public:
72
73 shared_ptr <SASLMechanism> create(shared_ptr <SASLContext> ctx, const string& name)
74 {
75 return vmime::make_shared <T>(ctx, name);
76 }
77 };
78
79 typedef std::map <string, shared_ptr <registeredMechanism> > MapType;
80 MapType m_mechs;
81
82 public:
83
84 static SASLMechanismFactory* getInstance();
85
86 /** Register a mechanism into this factory, so that subsequent
87 * calls to create return a valid object for this mechanism.
88 *
89 * @param name mechanism name
90 */
91 template <typename MECH_CLASS>
92 void registerMechanism(const string& name)
93 {
94 m_mechs.insert(MapType::value_type(name,
95 vmime::make_shared <registeredMechanismImpl <MECH_CLASS> >()));
96 }
97
98 /** Create a mechanism object given its name.
99 *
100 * @param ctx SASL context
101 * @param name mechanism name
102 * @return a new mechanism object
103 * @throw exceptions::no_such_mechanism if no mechanism is
104 * registered for the specified name
105 */
106 shared_ptr <SASLMechanism> create(shared_ptr <SASLContext> ctx, const string& name);
107
108 /** Return a list of supported mechanisms. This includes mechanisms
109 * registered using registerMechanism() as well as the ones that
110 * are built-in.
111 *
112 * @return list of supported mechanisms
113 */
114 const std::vector <string> getSupportedMechanisms() const;
115
116 /** Test whether an authentication mechanism is supported.
117 *
118 * @param name mechanism name
119 * @return true if the specified mechanism is supported,
120 * false otherwise
121 */
122 bool isMechanismSupported(const string& name) const;
123
124 /** Test whether an authentication mechanism is directly supported
125 * by the underlying SASL library.
126 *
127 * @param name mechanism name
128 * @return true if the specified mechanism is built-in,
129 * or false otherwise
130 */
131 bool isBuiltinMechanism(const string& name) const;
132
133 private:
134
135 #ifdef GSASL_VERSION
136 Gsasl* m_gsaslContext;
137 #else
138 void* m_gsaslContext;
139 #endif // GSASL_VERSION
140
141 };
142
143
144 } // sasl
145 } // security
146 } // vmime
147
148
149 #endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_SASL_SUPPORT
150
151 #endif // VMIME_SECURITY_SASL_SASLMECHANISMFACTORY_HPP_INCLUDED
152