2 * Copyright 2001-2010 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>
31 #include <xercesc/dom/DOM.hpp>
33 #if defined (_MSC_VER)
34 #pragma warning( push )
35 #pragma warning( disable : 4251 )
38 namespace xmltooling {
40 class XMLTOOL_API ParserPool;
41 class XMLTOOL_API PathResolver;
42 class XMLTOOL_API TemplateEngine;
43 class XMLTOOL_API URLEncoder;
44 #ifndef XMLTOOLING_LITE
45 class XMLTOOL_API ReplayCache;
46 class XMLTOOL_API StorageService;
48 #ifndef XMLTOOLING_NO_XMLSEC
49 class XMLTOOL_API CredentialResolver;
50 class XMLTOOL_API KeyInfoResolver;
51 class XMLTOOL_API TrustEngine;
52 class XMLTOOL_API XSECCryptoX509CRL;
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 virtual Lockable
64 MAKE_NONCOPYABLE(XMLToolingConfig);
68 #ifndef XMLTOOLING_NO_XMLSEC
69 /** Global KeyInfoResolver instance. */
70 KeyInfoResolver* m_keyInfoResolver;
72 /** Global ReplayCache instance. */
73 ReplayCache* m_replayCache;
76 /** Global PathResolver instance. */
77 PathResolver* m_pathResolver;
79 /** Global TemplateEngine instance. */
80 TemplateEngine* m_templateEngine;
82 /** Global URLEncoder instance for use by URL-related functions. */
83 URLEncoder* m_urlEncoder;
86 virtual ~XMLToolingConfig();
89 * Returns the global configuration object for the library.
91 * @return reference to the global library configuration object
93 static XMLToolingConfig& getConfig();
98 * Each process using the library MUST call this function exactly once
99 * before using any library classes except for the LogConfig method.
101 * @return true iff initialization was successful
103 virtual bool init()=0;
108 * Each process using the library SHOULD call this function exactly once
109 * before terminating itself
111 virtual void term()=0;
114 * Loads a shared/dynamic library extension.
116 * Extension libraries are managed using a pair of "C" linkage functions:<br>
117 * extern "C" int xmltooling_extension_init(void* context);<br>
118 * extern "C" void xmltooling_extension_term();
120 * This method is internally synchronized.
122 * @param path pathname of shared library to load into process
123 * @param context arbitrary data to pass to library initialization hook
124 * @return true iff library was loaded successfully
126 virtual bool load_library(const char* path, void* context=nullptr)=0;
129 * Configure logging system.
131 * May be called first, before initializing the library. Other calls to it
132 * must be externally synchronized.
134 * @param config either a logging configuration file, or a level from the set
135 * (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
136 * @return true iff configuration was successful
138 virtual bool log_config(const char* config=nullptr)=0;
141 * Obtains a non-validating parser pool.
142 * Library must be initialized first.
144 * @return reference to a non-validating parser pool.
146 virtual ParserPool& getParser() const=0;
149 * Obtains a validating parser pool.
150 * Library must be initialized first. Schema/catalog registration must be
151 * externally synchronized.
153 * @return reference to a validating parser pool.
155 virtual ParserPool& getValidatingParser() const=0;
157 #ifndef XMLTOOLING_NO_XMLSEC
159 * Returns the global KeyInfoResolver instance.
161 * @return global KeyInfoResolver or nullptr
163 const KeyInfoResolver* getKeyInfoResolver() const;
166 * Returns the global ReplayCache instance.
168 * @return global ReplayCache or nullptr
170 ReplayCache* getReplayCache() const;
173 * Sets the global KeyInfoResolver instance.
174 * This method must be externally synchronized with any code that uses the object.
175 * Any previously set object is destroyed.
177 * @param keyInfoResolver new KeyInfoResolver instance to store
179 void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
182 * Sets the global ReplayCache instance.
183 * This method must be externally synchronized with any code that uses the object.
184 * Any previously set object is destroyed.
186 * @param replayCache new ReplayCache instance to store
188 void setReplayCache(ReplayCache* replayCache);
192 * Returns the global PathResolver instance.
194 * @return global PathResolver or nullptr
196 PathResolver* getPathResolver() const;
199 * Returns the global TemplateEngine instance.
201 * @return global TemplateEngine or nullptr
203 TemplateEngine* getTemplateEngine() const;
206 * Returns the global URLEncoder instance.
208 * @return global URLEncoder or nullptr
210 const URLEncoder* getURLEncoder() const;
213 * Sets the global PathResolver instance.
214 * This method must be externally synchronized with any code that uses the object.
215 * Any previously set object is destroyed.
217 * @param pathResolver new PathResolver instance to store
219 void setPathResolver(PathResolver* pathResolver);
222 * Sets the global TemplateEngine instance.
223 * This method must be externally synchronized with any code that uses the object.
224 * Any previously set object is destroyed.
226 * @param templateEngine new TemplateEngine instance to store
228 void setTemplateEngine(TemplateEngine* templateEngine);
231 * Sets the global URLEncoder instance.
232 * This method must be externally synchronized with any code that uses the object.
233 * Any previously set object is destroyed.
235 * @param urlEncoder new URLEncoder instance to store
237 void setURLEncoder(URLEncoder* urlEncoder);
240 * List of catalog files to load into validating parser pool at initialization time.
241 * Like other path settings, the separator depends on the platform
242 * (semicolon on Windows, colon otherwise).
244 std::string catalog_path;
247 * Adjusts any clock comparisons to be more liberal/permissive by the
248 * indicated number of seconds.
250 unsigned int clock_skew_secs;
252 #ifndef XMLTOOLING_NO_XMLSEC
254 * Returns an X.509 CRL implementation object.
256 virtual XSECCryptoX509CRL* X509CRL() const=0;
259 * Manages factories for KeyInfoResolver plugins.
261 PluginManager<KeyInfoResolver,std::string,const xercesc::DOMElement*> KeyInfoResolverManager;
264 * Manages factories for CredentialResolver plugins.
266 PluginManager<CredentialResolver,std::string,const xercesc::DOMElement*> CredentialResolverManager;
269 * Manages factories for TrustEngine plugins.
271 PluginManager<TrustEngine,std::string,const xercesc::DOMElement*> TrustEngineManager;
274 * Manages factories for StorageService plugins.
276 PluginManager<StorageService,std::string,const xercesc::DOMElement*> StorageServiceManager;
279 * Maps an XML Signature/Encryption algorithm identifier to a library-specific
280 * key algorithm and size for use in resolving credentials.
282 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
283 * @return a general key algorithm and key size (or 0 if the size is irrelevant)
285 virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
288 * Registers an XML Signature/Encryption algorithm identifier against a library-specific
289 * key algorithm and size for use in resolving credentials.
291 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
292 * @param keyAlgorithm a key algorithm
293 * @param size a key size (or 0 if the size is irrelevant)
295 virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
299 * Manages factories for SOAPTransport plugins.
301 * <p>The factory interface takes a peer name/endpoint pair.
303 PluginManager<SOAPTransport,std::string,SOAPTransport::Address> SOAPTransportManager;
308 #if defined (_MSC_VER)
309 #pragma warning( pop )
312 #endif /* __xmltooling_config_h__ */