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