Reducing header overuse, non-inlining selected methods (CPPOST-35).
[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 #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          * Returns the global KeyInfoResolver instance.
163          * 
164          * @return  global KeyInfoResolver or NULL
165          */
166         const KeyInfoResolver* getKeyInfoResolver() const;
167
168         /**
169          * Returns the global ReplayCache instance.
170          * 
171          * @return  global ReplayCache or NULL
172          */
173         ReplayCache* getReplayCache() const;
174
175         /**
176          * Sets the global KeyInfoResolver instance.
177          * This method must be externally synchronized with any code that uses the object.
178          * Any previously set object is destroyed.
179          * 
180          * @param keyInfoResolver   new KeyInfoResolver instance to store
181          */
182         void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
183
184         /**
185          * Sets the global ReplayCache instance.
186          * This method must be externally synchronized with any code that uses the object.
187          * Any previously set object is destroyed.
188          * 
189          * @param replayCache   new ReplayCache instance to store
190          */
191         void setReplayCache(ReplayCache* replayCache);
192 #endif
193
194         /**
195          * Returns the global PathResolver instance.
196          * 
197          * @return  global PathResolver or NULL
198          */
199         PathResolver* getPathResolver() const;
200         
201         /**
202          * Returns the global TemplateEngine instance.
203          * 
204          * @return  global TemplateEngine or NULL
205          */
206         TemplateEngine* getTemplateEngine() const;
207
208         /**
209          * Returns the global URLEncoder instance.
210          * 
211          * @return  global URLEncoder or NULL
212          */
213         const URLEncoder* getURLEncoder() const;
214
215         /**
216          * Sets the global PathResolver instance.
217          * This method must be externally synchronized with any code that uses the object.
218          * Any previously set object is destroyed.
219          * 
220          * @param pathResolver   new PathResolver instance to store
221          */
222         void setPathResolver(PathResolver* pathResolver);
223         
224         /**
225          * Sets the global TemplateEngine instance.
226          * This method must be externally synchronized with any code that uses the object.
227          * Any previously set object is destroyed.
228          * 
229          * @param templateEngine   new TemplateEngine instance to store
230          */
231         void setTemplateEngine(TemplateEngine* templateEngine);
232
233         /**
234          * Sets the global URLEncoder instance.
235          * This method must be externally synchronized with any code that uses the object.
236          * Any previously set object is destroyed.
237          * 
238          * @param urlEncoder   new URLEncoder instance to store
239          */
240         void setURLEncoder(URLEncoder* urlEncoder);
241         
242         /**
243          * List of catalog files to load into validating parser pool at initialization time.
244          * Like other path settings, the separator depends on the platform
245          * (semicolon on Windows, colon otherwise). 
246          */
247         std::string catalog_path;
248         
249         /**
250          * Adjusts any clock comparisons to be more liberal/permissive by the
251          * indicated number of seconds.
252          */
253         unsigned int clock_skew_secs;
254
255 #ifndef XMLTOOLING_NO_XMLSEC
256         /**
257          * Returns an X.509 CRL implementation object.
258          */
259         virtual XSECCryptoX509CRL* X509CRL() const=0;
260
261         /**
262          * Manages factories for KeyInfoResolver plugins.
263          */
264         PluginManager<KeyInfoResolver,std::string,const xercesc::DOMElement*> KeyInfoResolverManager;
265
266         /**
267          * Manages factories for CredentialResolver plugins.
268          */
269         PluginManager<CredentialResolver,std::string,const xercesc::DOMElement*> CredentialResolverManager;
270
271         /**
272          * Manages factories for TrustEngine plugins.
273          */
274         PluginManager<TrustEngine,std::string,const xercesc::DOMElement*> TrustEngineManager;
275
276         /**
277          * Manages factories for StorageService plugins.
278          */
279         PluginManager<StorageService,std::string,const xercesc::DOMElement*> StorageServiceManager;
280
281         /**
282          * Maps an XML Signature/Encryption algorithm identifier to a library-specific
283          * key algorithm and size for use in resolving credentials.
284          *
285          * @param xmlAlgorithm  XML Signature/Encryption algorithm identifier
286          * @return  a general key algorithm and key size (or 0 if the size is irrelevant)
287          */
288         virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
289
290         /**
291          * Registers an XML Signature/Encryption algorithm identifier against a library-specific
292          * key algorithm and size for use in resolving credentials.
293          *
294          * @param xmlAlgorithm  XML Signature/Encryption algorithm identifier
295          * @param keyAlgorithm  a key algorithm
296          * @param size          a key size (or 0 if the size is irrelevant)
297          */
298         virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
299 #endif
300
301         /**
302          * Manages factories for SOAPTransport plugins.
303          * 
304          * <p>The factory interface takes a peer name/endpoint pair.
305          */
306         PluginManager<SOAPTransport,std::string,SOAPTransport::Address> SOAPTransportManager;
307     };
308
309 };
310
311 #if defined (_MSC_VER)
312     #pragma warning( pop )
313 #endif
314
315 #endif /* __xmltooling_config_h__ */