2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/XMLToolingConfig.h
20 * Library configuration
23 #ifndef __xmltooling_config_h__
24 #define __xmltooling_config_h__
26 #include <xmltooling/Lockable.h>
27 #include <xmltooling/PluginManager.h>
28 #include <xmltooling/soap/SOAPTransport.h>
29 #include <xmltooling/util/ParserPool.h>
31 #ifndef XMLTOOLING_NO_XMLSEC
32 namespace xmltooling {
33 class XMLTOOL_API CredentialResolver;
34 class XMLTOOL_API KeyInfoResolver;
35 class XMLTOOL_API TrustEngine;
36 class XMLTOOL_API XSECCryptoX509CRL;
40 #if defined (_MSC_VER)
41 #pragma warning( push )
42 #pragma warning( disable : 4251 )
45 namespace xmltooling {
47 class XMLTOOL_API PathResolver;
48 class XMLTOOL_API TemplateEngine;
49 class XMLTOOL_API URLEncoder;
50 #ifndef XMLTOOLING_LITE
51 class XMLTOOL_API ReplayCache;
52 class XMLTOOL_API StorageService;
56 * Singleton object that manages library startup/shutdown.configuration.
58 * A locking interface is supplied as a convenience for code that wants to
59 * obtain a global system lock, but the actual configuration itself is not
62 class XMLTOOL_API XMLToolingConfig : public Lockable
64 MAKE_NONCOPYABLE(XMLToolingConfig);
66 #ifndef XMLTOOLING_NO_XMLSEC
67 XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL),
68 m_pathResolver(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
70 /** Global KeyInfoResolver instance. */
71 KeyInfoResolver* m_keyInfoResolver;
73 /** Global ReplayCache instance. */
74 ReplayCache* m_replayCache;
76 XMLToolingConfig() : m_pathResolver(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
79 /** Global PathResolver instance. */
80 PathResolver* m_pathResolver;
82 /** Global TemplateEngine instance. */
83 TemplateEngine* m_templateEngine;
85 /** Global URLEncoder instance for use by URL-related functions. */
86 URLEncoder* m_urlEncoder;
89 virtual ~XMLToolingConfig() {}
92 * Returns the global configuration object for the library.
94 * @return reference to the global library configuration object
96 static XMLToolingConfig& getConfig();
101 * Each process using the library MUST call this function exactly once
102 * before using any library classes except for the LogConfig method.
104 * @return true iff initialization was successful
106 virtual bool init()=0;
111 * Each process using the library SHOULD call this function exactly once
112 * before terminating itself
114 virtual void term()=0;
117 * Loads a shared/dynamic library extension.
119 * Extension libraries are managed using a pair of "C" linkage functions:<br>
120 * extern "C" int xmltooling_extension_init(void* context);<br>
121 * extern "C" void xmltooling_extension_term();
123 * This method is internally synchronized.
125 * @param path pathname of shared library to load into process
126 * @param context arbitrary data to pass to library initialization hook
127 * @return true iff library was loaded successfully
129 virtual bool load_library(const char* path, void* context=NULL)=0;
132 * Configure logging system.
134 * May be called first, before initializing the library. Other calls to it
135 * must be externally synchronized.
137 * @param config either a logging configuration file, or a level from the set
138 * (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
139 * @return true iff configuration was successful
141 virtual bool log_config(const char* config=NULL)=0;
144 * Obtains a non-validating parser pool.
145 * Library must be initialized first.
147 * @return reference to a non-validating parser pool.
149 virtual ParserPool& getParser() const=0;
152 * Obtains a validating parser pool.
153 * Library must be initialized first. Schema/catalog registration must be
154 * externally synchronized.
156 * @return reference to a validating parser pool.
158 virtual ParserPool& getValidatingParser() const=0;
160 #ifndef XMLTOOLING_NO_XMLSEC
162 * Sets the global KeyInfoResolver instance.
163 * This method must be externally synchronized with any code that uses the object.
164 * Any previously set object is destroyed.
166 * @param keyInfoResolver new KeyInfoResolver instance to store
168 void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
171 * Returns the global KeyInfoResolver instance.
173 * @return global KeyInfoResolver or NULL
175 const KeyInfoResolver* getKeyInfoResolver() const {
176 return m_keyInfoResolver;
180 * Sets the global ReplayCache instance.
181 * This method must be externally synchronized with any code that uses the object.
182 * Any previously set object is destroyed.
184 * @param replayCache new ReplayCache instance to store
186 void setReplayCache(ReplayCache* replayCache);
189 * Returns the global ReplayCache instance.
191 * @return global ReplayCache or NULL
193 ReplayCache* getReplayCache() const {
194 return m_replayCache;
199 * Sets the global URLEncoder instance.
200 * This method must be externally synchronized with any code that uses the object.
201 * Any previously set object is destroyed.
203 * @param urlEncoder new URLEncoder instance to store
205 void setURLEncoder(URLEncoder* urlEncoder);
208 * Returns the global URLEncoder instance.
210 * @return global URLEncoder or NULL
212 const URLEncoder* getURLEncoder() const {
217 * Sets the global TemplateEngine instance.
218 * This method must be externally synchronized with any code that uses the object.
219 * Any previously set object is destroyed.
221 * @param templateEngine new TemplateEngine instance to store
223 void setTemplateEngine(TemplateEngine* templateEngine);
226 * Returns the global TemplateEngine instance.
228 * @return global TemplateEngine or NULL
230 TemplateEngine* getTemplateEngine() const {
231 return m_templateEngine;
235 * Sets the global PathResolver instance.
236 * This method must be externally synchronized with any code that uses the object.
237 * Any previously set object is destroyed.
239 * @param pathResolver new PathResolver instance to store
241 void setPathResolver(PathResolver* pathResolver);
244 * Returns the global PathResolver instance.
246 * @return global PathResolver or NULL
248 PathResolver* getPathResolver() const {
249 return m_pathResolver;
253 * List of catalog files to load into validating parser pool at initialization time.
254 * Like other path settings, the separator depends on the platform
255 * (semicolon on Windows, colon otherwise).
257 std::string catalog_path;
260 * Adjusts any clock comparisons to be more liberal/permissive by the
261 * indicated number of seconds.
263 unsigned int clock_skew_secs;
265 #ifndef XMLTOOLING_NO_XMLSEC
267 * Returns an X.509 CRL implementation object.
269 virtual XSECCryptoX509CRL* X509CRL() const=0;
272 * Manages factories for KeyInfoResolver plugins.
274 PluginManager<KeyInfoResolver,std::string,const xercesc::DOMElement*> KeyInfoResolverManager;
277 * Manages factories for CredentialResolver plugins.
279 PluginManager<CredentialResolver,std::string,const xercesc::DOMElement*> CredentialResolverManager;
282 * Manages factories for TrustEngine plugins.
284 PluginManager<TrustEngine,std::string,const xercesc::DOMElement*> TrustEngineManager;
287 * Manages factories for StorageService plugins.
289 PluginManager<StorageService,std::string,const xercesc::DOMElement*> StorageServiceManager;
292 * Maps an XML Signature/Encryption algorithm identifier to a library-specific
293 * key algorithm and size for use in resolving credentials.
295 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
296 * @return a general key algorithm and key size (or 0 if the size is irrelevant)
298 virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
301 * Registers an XML Signature/Encryption algorithm identifier against a library-specific
302 * key algorithm and size for use in resolving credentials.
304 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
305 * @param keyAlgorithm a key algorithm
306 * @param size a key size (or 0 if the size is irrelevant)
308 virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
312 * Manages factories for SOAPTransport plugins.
314 * <p>The factory interface takes a peer name/endpoint pair.
316 PluginManager<SOAPTransport,std::string,SOAPTransport::Address> SOAPTransportManager;
321 #if defined (_MSC_VER)
322 #pragma warning( pop )
325 #endif /* __xmltooling_config_h__ */