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