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