f29f7067a4dc140b10f0eafa41a5660bc77bf89d
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLToolingConfig.h
1 /*
2  *  Copyright 2001-2006 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 StorageService;
46     class XMLTOOL_API TrustEngine;
47     class XMLTOOL_API XSECCryptoX509CRL;
48
49     /**
50      * Singleton object that manages library startup/shutdown.configuration.
51      * 
52      * A locking interface is supplied as a convenience for code that wants to
53      * obtain a global system lock, but the actual configuration itself is not
54      * synchronized.
55      */
56     class XMLTOOL_API XMLToolingConfig : public Lockable
57     {
58         MAKE_NONCOPYABLE(XMLToolingConfig);
59     protected:
60         XMLToolingConfig() : m_replayCache(NULL), clock_skew_secs(180) {}
61         
62         /** Global ReplayCache instance. */
63         ReplayCache* m_replayCache;
64     public:
65         virtual ~XMLToolingConfig() {}
66
67         /**
68          * Returns the global configuration object for the library.
69          * 
70          * @return reference to the global library configuration object
71          */
72         static XMLToolingConfig& getConfig();
73         
74         /**
75          * Initializes library
76          * 
77          * Each process using the library MUST call this function exactly once
78          * before using any library classes except for the LogConfig method.
79          * 
80          * @return true iff initialization was successful 
81          */
82         virtual bool init()=0;
83         
84         /**
85          * Shuts down library
86          * 
87          * Each process using the library SHOULD call this function exactly once
88          * before terminating itself
89          */
90         virtual void term()=0;
91
92         /**
93          * Loads a shared/dynamic library extension.
94          * 
95          * Extension libraries are managed using a pair of "C" linkage functions:<br>
96          *      extern "C" int xmltooling_extension_init(void* context);<br>
97          *      extern "C" void xmltooling_extension_term();
98          * 
99          * This method is internally synchronized.
100          * 
101          * @param path      pathname of shared library to load into process
102          * @param context   arbitrary data to pass to library initialization hook
103          * @return true iff library was loaded successfully
104          */
105         virtual bool load_library(const char* path, void* context=NULL)=0;
106         
107         /**
108          * Configure logging system.
109          * 
110          * May be called first, before initializing the library. Other calls to it
111          * must be externally synchronized. 
112          * 
113          * @param config    either a logging configuration file, or a level from the set
114          *                  (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
115          * @return true iff configuration was successful
116          */
117         virtual bool log_config(const char* config=NULL)=0;
118
119         /**
120          * Obtains a non-validating parser pool.
121          * Library must be initialized first.
122          *
123          * @return reference to a non-validating parser pool.
124          */
125         virtual ParserPool& getParser() const=0;
126
127         /**
128          * Obtains a validating parser pool.
129          * Library must be initialized first. Schema/catalog registration must be
130          * externally synchronized.
131          *
132          * @return reference to a validating parser pool.
133          */
134         virtual ParserPool& getValidatingParser() const=0;
135
136         /**
137          * Sets the global ReplayCache instance.
138          * This method must be externally synchronized with any code that uses the object.
139          * Any previously set object is destroyed.
140          * 
141          * @param replayCache   new ReplayCache instance to store
142          */
143         void setReplayCache(ReplayCache* replayCache);
144
145         /**
146          * Returns the global ReplayCache instance.
147          * 
148          * @return  global ReplayCache or NULL
149          */
150         ReplayCache* getReplayCache() const {
151             return m_replayCache;
152         }
153                 
154         /**
155          * List of catalog files to load into validating parser pool at initialization time.
156          * Like other path settings, the separator depends on the platform
157          * (semicolon on Windows, colon otherwise). 
158          */
159         std::string catalog_path;
160         
161         /**
162          * Adjusts any clock comparisons to be more liberal/permissive by the
163          * indicated number of seconds.
164          */
165         unsigned int clock_skew_secs;
166
167 #ifndef XMLTOOLING_NO_XMLSEC
168         /**
169          * Returns an X.509 CRL implementation object.
170          */
171         virtual XSECCryptoX509CRL* X509CRL() const=0;
172
173         /**
174          * Manages factories for KeyResolver plugins.
175          */
176         PluginManager<xmlsignature::KeyResolver,const DOMElement*> KeyResolverManager;
177
178         /**
179          * Manages factories for CredentialResolver plugins.
180          */
181         PluginManager<xmlsignature::CredentialResolver,const DOMElement*> CredentialResolverManager;
182
183         /**
184          * Manages factories for TrustEngine plugins.
185          */
186         PluginManager<TrustEngine,const DOMElement*> TrustEngineManager;
187 #endif
188
189         /**
190          * Manages factories for StorageService plugins.
191          */
192         PluginManager<StorageService,const DOMElement*> StorageServiceManager;
193     };
194
195 };
196
197 #if defined (_MSC_VER)
198     #pragma warning( pop )
199 #endif
200
201 #endif /* __xmltooling_config_h__ */