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