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