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