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/util/ParserPool.h>
30 #ifndef XMLTOOLING_NO_XMLSEC
31 namespace xmltooling {
32 class XMLTOOL_API CredentialResolver;
33 class XMLTOOL_API KeyInfoResolver;
34 class XMLTOOL_API TrustEngine;
35 class XMLTOOL_API XSECCryptoX509CRL;
39 #if defined (_MSC_VER)
40 #pragma warning( push )
41 #pragma warning( disable : 4251 )
44 namespace xmltooling {
46 class XMLTOOL_API ReplayCache;
47 class XMLTOOL_API SOAPTransport;
48 class XMLTOOL_API StorageService;
49 class XMLTOOL_API TemplateEngine;
50 class XMLTOOL_API URLEncoder;
53 * Singleton object that manages library startup/shutdown.configuration.
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
59 class XMLTOOL_API XMLToolingConfig : public Lockable
61 MAKE_NONCOPYABLE(XMLToolingConfig);
63 #ifndef XMLTOOLING_NO_XMLSEC
64 XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
66 /** Global KeyInfoResolver instance. */
67 KeyInfoResolver* m_keyInfoResolver;
69 XMLToolingConfig() : m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
72 /** Global ReplayCache instance. */
73 ReplayCache* m_replayCache;
75 /** Global TemplateEngine instance. */
76 TemplateEngine* m_templateEngine;
78 /** Global URLEncoder instance for use by URL-related functions. */
79 URLEncoder* m_urlEncoder;
82 virtual ~XMLToolingConfig() {}
85 * Returns the global configuration object for the library.
87 * @return reference to the global library configuration object
89 static XMLToolingConfig& getConfig();
94 * Each process using the library MUST call this function exactly once
95 * before using any library classes except for the LogConfig method.
97 * @return true iff initialization was successful
99 virtual bool init()=0;
104 * Each process using the library SHOULD call this function exactly once
105 * before terminating itself
107 virtual void term()=0;
110 * Loads a shared/dynamic library extension.
112 * Extension libraries are managed using a pair of "C" linkage functions:<br>
113 * extern "C" int xmltooling_extension_init(void* context);<br>
114 * extern "C" void xmltooling_extension_term();
116 * This method is internally synchronized.
118 * @param path pathname of shared library to load into process
119 * @param context arbitrary data to pass to library initialization hook
120 * @return true iff library was loaded successfully
122 virtual bool load_library(const char* path, void* context=NULL)=0;
125 * Configure logging system.
127 * May be called first, before initializing the library. Other calls to it
128 * must be externally synchronized.
130 * @param config either a logging configuration file, or a level from the set
131 * (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
132 * @return true iff configuration was successful
134 virtual bool log_config(const char* config=NULL)=0;
137 * Obtains a non-validating parser pool.
138 * Library must be initialized first.
140 * @return reference to a non-validating parser pool.
142 virtual ParserPool& getParser() const=0;
145 * Obtains a validating parser pool.
146 * Library must be initialized first. Schema/catalog registration must be
147 * externally synchronized.
149 * @return reference to a validating parser pool.
151 virtual ParserPool& getValidatingParser() const=0;
153 #ifndef XMLTOOLING_NO_XMLSEC
155 * Sets the global KeyInfoResolver instance.
156 * This method must be externally synchronized with any code that uses the object.
157 * Any previously set object is destroyed.
159 * @param keyInfoResolver new KeyInfoResolver instance to store
161 void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
164 * Returns the global KeyInfoResolver instance.
166 * @return global KeyInfoResolver or NULL
168 const KeyInfoResolver* getKeyInfoResolver() const {
169 return m_keyInfoResolver;
174 * Sets the global ReplayCache instance.
175 * This method must be externally synchronized with any code that uses the object.
176 * Any previously set object is destroyed.
178 * @param replayCache new ReplayCache instance to store
180 void setReplayCache(ReplayCache* replayCache);
183 * Returns the global ReplayCache instance.
185 * @return global ReplayCache or NULL
187 ReplayCache* getReplayCache() const {
188 return m_replayCache;
192 * Sets the global URLEncoder instance.
193 * This method must be externally synchronized with any code that uses the object.
194 * Any previously set object is destroyed.
196 * @param urlEncoder new URLEncoder instance to store
198 void setURLEncoder(URLEncoder* urlEncoder);
201 * Returns the global URLEncoder instance.
203 * @return global URLEncoder or NULL
205 const URLEncoder* getURLEncoder() const {
210 * Sets the global TemplateEngine instance.
211 * This method must be externally synchronized with any code that uses the object.
212 * Any previously set object is destroyed.
214 * @param templateEngine new TemplateEngine instance to store
216 void setTemplateEngine(TemplateEngine* templateEngine);
219 * Returns the global TemplateEngine instance.
221 * @return global TemplateEngine or NULL
223 TemplateEngine* getTemplateEngine() const {
224 return m_templateEngine;
228 * List of catalog files to load into validating parser pool at initialization time.
229 * Like other path settings, the separator depends on the platform
230 * (semicolon on Windows, colon otherwise).
232 std::string catalog_path;
235 * Adjusts any clock comparisons to be more liberal/permissive by the
236 * indicated number of seconds.
238 unsigned int clock_skew_secs;
240 #ifndef XMLTOOLING_NO_XMLSEC
242 * Returns an X.509 CRL implementation object.
244 virtual XSECCryptoX509CRL* X509CRL() const=0;
247 * Manages factories for KeyInfoResolver plugins.
249 PluginManager<KeyInfoResolver,std::string,const xercesc::DOMElement*> KeyInfoResolverManager;
252 * Manages factories for CredentialResolver plugins.
254 PluginManager<CredentialResolver,std::string,const xercesc::DOMElement*> CredentialResolverManager;
257 * Manages factories for TrustEngine plugins.
259 PluginManager<TrustEngine,std::string,const xercesc::DOMElement*> TrustEngineManager;
262 * Maps an XML Signature/Encryption algorithm identifier to a library-specific
263 * key algorithm and size for use in resolving credentials.
265 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
266 * @return a general key algorithm and key size (or 0 if the size is irrelevant)
268 virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
271 * Registers an XML Signature/Encryption algorithm identifier against a library-specific
272 * key algorithm and size for use in resolving credentials.
274 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
275 * @param keyAlgorithm a key algorithm
276 * @param size a key size (or 0 if the size is irrelevant)
278 virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
282 * Manages factories for SOAPTransport plugins.
284 * <p>The factory interface takes a peer name/endpoint pair.
286 PluginManager<SOAPTransport,std::string,std::pair<const char*,const char*> > SOAPTransportManager;
289 * Manages factories for StorageService plugins.
291 PluginManager<StorageService,std::string,const xercesc::DOMElement*> StorageServiceManager;
296 #if defined (_MSC_VER)
297 #pragma warning( pop )
300 #endif /* __xmltooling_config_h__ */