Move ReplayCache and StorageService APIs to full build only.
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLToolingConfig.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/XMLToolingConfig.h
19  * 
20  * Library configuration 
21  */
22
23 #ifndef __xmltooling_config_h__
24 #define __xmltooling_config_h__
25
26 #include <xmltooling/Lockable.h>
27 #include <xmltooling/PluginManager.h>
28 #include <xmltooling/util/ParserPool.h>
29
30 #ifndef XMLTOOLING_NO_XMLSEC
31 namespace xmltooling {
32     class XMLTOOL_API CredentialResolver;
33     class XMLTOOL_API KeyInfoResolver;
34     class XMLTOOL_API TrustEngine;
35     class XMLTOOL_API XSECCryptoX509CRL;
36 };
37 #endif
38
39 #if defined (_MSC_VER)
40     #pragma warning( push )
41     #pragma warning( disable : 4251 )
42 #endif
43
44 namespace xmltooling {
45     
46     class XMLTOOL_API SOAPTransport;
47     class XMLTOOL_API TemplateEngine;
48     class XMLTOOL_API URLEncoder;
49 #ifndef XMLTOOLING_LITE
50     class XMLTOOL_API ReplayCache;
51     class XMLTOOL_API StorageService;
52 #endif
53
54     /**
55      * Singleton object that manages library startup/shutdown.configuration.
56      * 
57      * A locking interface is supplied as a convenience for code that wants to
58      * obtain a global system lock, but the actual configuration itself is not
59      * synchronized.
60      */
61     class XMLTOOL_API XMLToolingConfig : public Lockable
62     {
63         MAKE_NONCOPYABLE(XMLToolingConfig);
64     protected:
65 #ifndef XMLTOOLING_NO_XMLSEC
66         XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
67
68         /** Global KeyInfoResolver instance. */
69         KeyInfoResolver* m_keyInfoResolver;
70
71         /** Global ReplayCache instance. */
72         ReplayCache* m_replayCache;
73 #else
74         XMLToolingConfig() : m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
75 #endif
76
77         /** Global TemplateEngine instance. */
78         TemplateEngine* m_templateEngine;
79
80         /** Global URLEncoder instance for use by URL-related functions. */
81         URLEncoder* m_urlEncoder;
82
83     public:
84         virtual ~XMLToolingConfig() {}
85
86         /**
87          * Returns the global configuration object for the library.
88          * 
89          * @return reference to the global library configuration object
90          */
91         static XMLToolingConfig& getConfig();
92         
93         /**
94          * Initializes library
95          * 
96          * Each process using the library MUST call this function exactly once
97          * before using any library classes except for the LogConfig method.
98          * 
99          * @return true iff initialization was successful 
100          */
101         virtual bool init()=0;
102         
103         /**
104          * Shuts down library
105          * 
106          * Each process using the library SHOULD call this function exactly once
107          * before terminating itself
108          */
109         virtual void term()=0;
110
111         /**
112          * Loads a shared/dynamic library extension.
113          * 
114          * Extension libraries are managed using a pair of "C" linkage functions:<br>
115          *      extern "C" int xmltooling_extension_init(void* context);<br>
116          *      extern "C" void xmltooling_extension_term();
117          * 
118          * This method is internally synchronized.
119          * 
120          * @param path      pathname of shared library to load into process
121          * @param context   arbitrary data to pass to library initialization hook
122          * @return true iff library was loaded successfully
123          */
124         virtual bool load_library(const char* path, void* context=NULL)=0;
125         
126         /**
127          * Configure logging system.
128          * 
129          * May be called first, before initializing the library. Other calls to it
130          * must be externally synchronized. 
131          * 
132          * @param config    either a logging configuration file, or a level from the set
133          *                  (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
134          * @return true iff configuration was successful
135          */
136         virtual bool log_config(const char* config=NULL)=0;
137
138         /**
139          * Obtains a non-validating parser pool.
140          * Library must be initialized first.
141          *
142          * @return reference to a non-validating parser pool.
143          */
144         virtual ParserPool& getParser() const=0;
145
146         /**
147          * Obtains a validating parser pool.
148          * Library must be initialized first. Schema/catalog registration must be
149          * externally synchronized.
150          *
151          * @return reference to a validating parser pool.
152          */
153         virtual ParserPool& getValidatingParser() const=0;
154
155 #ifndef XMLTOOLING_NO_XMLSEC
156         /**
157          * Sets the global KeyInfoResolver instance.
158          * This method must be externally synchronized with any code that uses the object.
159          * Any previously set object is destroyed.
160          * 
161          * @param keyInfoResolver   new KeyInfoResolver instance to store
162          */
163         void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
164
165         /**
166          * Returns the global KeyInfoResolver instance.
167          * 
168          * @return  global KeyInfoResolver or NULL
169          */
170         const KeyInfoResolver* getKeyInfoResolver() const {
171             return m_keyInfoResolver;
172         }
173
174         /**
175          * Sets the global ReplayCache instance.
176          * This method must be externally synchronized with any code that uses the object.
177          * Any previously set object is destroyed.
178          * 
179          * @param replayCache   new ReplayCache instance to store
180          */
181         void setReplayCache(ReplayCache* replayCache);
182
183         /**
184          * Returns the global ReplayCache instance.
185          * 
186          * @return  global ReplayCache or NULL
187          */
188         ReplayCache* getReplayCache() const {
189             return m_replayCache;
190         }
191 #endif
192
193         /**
194          * Sets the global URLEncoder instance.
195          * This method must be externally synchronized with any code that uses the object.
196          * Any previously set object is destroyed.
197          * 
198          * @param urlEncoder   new URLEncoder instance to store
199          */
200         void setURLEncoder(URLEncoder* urlEncoder);
201         
202         /**
203          * Returns the global URLEncoder instance.
204          * 
205          * @return  global URLEncoder or NULL
206          */
207         const URLEncoder* getURLEncoder() const {
208             return m_urlEncoder;
209         }
210         
211         /**
212          * Sets the global TemplateEngine instance.
213          * This method must be externally synchronized with any code that uses the object.
214          * Any previously set object is destroyed.
215          * 
216          * @param templateEngine   new TemplateEngine instance to store
217          */
218         void setTemplateEngine(TemplateEngine* templateEngine);
219
220         /**
221          * Returns the global TemplateEngine instance.
222          * 
223          * @return  global TemplateEngine or NULL
224          */
225         TemplateEngine* getTemplateEngine() const {
226             return m_templateEngine;
227         }
228                 
229         /**
230          * List of catalog files to load into validating parser pool at initialization time.
231          * Like other path settings, the separator depends on the platform
232          * (semicolon on Windows, colon otherwise). 
233          */
234         std::string catalog_path;
235         
236         /**
237          * Adjusts any clock comparisons to be more liberal/permissive by the
238          * indicated number of seconds.
239          */
240         unsigned int clock_skew_secs;
241
242 #ifndef XMLTOOLING_NO_XMLSEC
243         /**
244          * Returns an X.509 CRL implementation object.
245          */
246         virtual XSECCryptoX509CRL* X509CRL() const=0;
247
248         /**
249          * Manages factories for KeyInfoResolver plugins.
250          */
251         PluginManager<KeyInfoResolver,std::string,const xercesc::DOMElement*> KeyInfoResolverManager;
252
253         /**
254          * Manages factories for CredentialResolver plugins.
255          */
256         PluginManager<CredentialResolver,std::string,const xercesc::DOMElement*> CredentialResolverManager;
257
258         /**
259          * Manages factories for TrustEngine plugins.
260          */
261         PluginManager<TrustEngine,std::string,const xercesc::DOMElement*> TrustEngineManager;
262
263         /**
264          * Manages factories for StorageService plugins.
265          */
266         PluginManager<StorageService,std::string,const xercesc::DOMElement*> StorageServiceManager;
267
268         /**
269          * Maps an XML Signature/Encryption algorithm identifier to a library-specific
270          * key algorithm and size for use in resolving credentials.
271          *
272          * @param xmlAlgorithm  XML Signature/Encryption algorithm identifier
273          * @return  a general key algorithm and key size (or 0 if the size is irrelevant)
274          */
275         virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
276
277         /**
278          * Registers an XML Signature/Encryption algorithm identifier against a library-specific
279          * key algorithm and size for use in resolving credentials.
280          *
281          * @param xmlAlgorithm  XML Signature/Encryption algorithm identifier
282          * @param keyAlgorithm  a key algorithm
283          * @param size          a key size (or 0 if the size is irrelevant)
284          */
285         virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
286 #endif
287
288         /**
289          * Manages factories for SOAPTransport plugins.
290          * 
291          * <p>The factory interface takes a peer name/endpoint pair.
292          */
293         PluginManager<SOAPTransport,std::string,std::pair<const char*,const char*> > SOAPTransportManager;
294     };
295
296 };
297
298 #if defined (_MSC_VER)
299     #pragma warning( pop )
300 #endif
301
302 #endif /* __xmltooling_config_h__ */