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