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