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 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 XMLToolingConfig() : m_keyInfoResolver(NULL), m_replayCache(NULL), m_templateEngine(NULL), m_urlEncoder(NULL), clock_skew_secs(180) {}
65 /** Global KeyInfoResolver instance. */
66 KeyInfoResolver* m_keyInfoResolver;
68 /** Global ReplayCache instance. */
69 ReplayCache* m_replayCache;
71 /** Global TemplateEngine instance. */
72 TemplateEngine* m_templateEngine;
74 /** Global URLEncoder instance for use by URL-related functions. */
75 URLEncoder* m_urlEncoder;
78 virtual ~XMLToolingConfig() {}
81 * Returns the global configuration object for the library.
83 * @return reference to the global library configuration object
85 static XMLToolingConfig& getConfig();
90 * Each process using the library MUST call this function exactly once
91 * before using any library classes except for the LogConfig method.
93 * @return true iff initialization was successful
95 virtual bool init()=0;
100 * Each process using the library SHOULD call this function exactly once
101 * before terminating itself
103 virtual void term()=0;
106 * Loads a shared/dynamic library extension.
108 * Extension libraries are managed using a pair of "C" linkage functions:<br>
109 * extern "C" int xmltooling_extension_init(void* context);<br>
110 * extern "C" void xmltooling_extension_term();
112 * This method is internally synchronized.
114 * @param path pathname of shared library to load into process
115 * @param context arbitrary data to pass to library initialization hook
116 * @return true iff library was loaded successfully
118 virtual bool load_library(const char* path, void* context=NULL)=0;
121 * Configure logging system.
123 * May be called first, before initializing the library. Other calls to it
124 * must be externally synchronized.
126 * @param config either a logging configuration file, or a level from the set
127 * (DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG)
128 * @return true iff configuration was successful
130 virtual bool log_config(const char* config=NULL)=0;
133 * Obtains a non-validating parser pool.
134 * Library must be initialized first.
136 * @return reference to a non-validating parser pool.
138 virtual ParserPool& getParser() const=0;
141 * Obtains a validating parser pool.
142 * Library must be initialized first. Schema/catalog registration must be
143 * externally synchronized.
145 * @return reference to a validating parser pool.
147 virtual ParserPool& getValidatingParser() const=0;
150 * Sets the global KeyInfoResolver instance.
151 * This method must be externally synchronized with any code that uses the object.
152 * Any previously set object is destroyed.
154 * @param keyInfoResolver new KeyInfoResolver instance to store
156 void setKeyInfoResolver(KeyInfoResolver* keyInfoResolver);
159 * Returns the global KeyInfoResolver instance.
161 * @return global KeyInfoResolver or NULL
163 const KeyInfoResolver* getKeyInfoResolver() const {
164 return m_keyInfoResolver;
168 * Sets the global ReplayCache instance.
169 * This method must be externally synchronized with any code that uses the object.
170 * Any previously set object is destroyed.
172 * @param replayCache new ReplayCache instance to store
174 void setReplayCache(ReplayCache* replayCache);
177 * Returns the global ReplayCache instance.
179 * @return global ReplayCache or NULL
181 ReplayCache* getReplayCache() const {
182 return m_replayCache;
186 * Sets the global URLEncoder instance.
187 * This method must be externally synchronized with any code that uses the object.
188 * Any previously set object is destroyed.
190 * @param urlEncoder new URLEncoder instance to store
192 void setURLEncoder(URLEncoder* urlEncoder);
195 * Returns the global URLEncoder instance.
197 * @return global URLEncoder or NULL
199 const URLEncoder* getURLEncoder() const {
204 * Sets the global TemplateEngine instance.
205 * This method must be externally synchronized with any code that uses the object.
206 * Any previously set object is destroyed.
208 * @param templateEngine new TemplateEngine instance to store
210 void setTemplateEngine(TemplateEngine* templateEngine);
213 * Returns the global TemplateEngine instance.
215 * @return global TemplateEngine or NULL
217 TemplateEngine* getTemplateEngine() const {
218 return m_templateEngine;
222 * List of catalog files to load into validating parser pool at initialization time.
223 * Like other path settings, the separator depends on the platform
224 * (semicolon on Windows, colon otherwise).
226 std::string catalog_path;
229 * Adjusts any clock comparisons to be more liberal/permissive by the
230 * indicated number of seconds.
232 unsigned int clock_skew_secs;
234 #ifndef XMLTOOLING_NO_XMLSEC
236 * Returns an X.509 CRL implementation object.
238 virtual XSECCryptoX509CRL* X509CRL() const=0;
241 * Manages factories for KeyInfoResolver plugins.
243 PluginManager<KeyInfoResolver,const xercesc::DOMElement*> KeyInfoResolverManager;
246 * Manages factories for CredentialResolver plugins.
248 PluginManager<CredentialResolver,const xercesc::DOMElement*> CredentialResolverManager;
251 * Manages factories for TrustEngine plugins.
253 PluginManager<TrustEngine,const xercesc::DOMElement*> TrustEngineManager;
256 * Maps an XML Signature/Encryption algorithm identifier to a library-specific
257 * key algorithm and size for use in resolving credentials.
259 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
260 * @return a general key algorithm and key size (or 0 if the size is irrelevant)
262 virtual std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const=0;
265 * Registers an XML Signature/Encryption algorithm identifier against a library-specific
266 * key algorithm and size for use in resolving credentials.
268 * @param xmlAlgorithm XML Signature/Encryption algorithm identifier
269 * @param keyAlgorithm a key algorithm
270 * @param size a key size (or 0 if the size is irrelevant)
272 virtual void registerXMLAlgorithm(const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0)=0;
276 * Manages factories for SOAPTransport plugins.
278 * <p>The factory interface takes a peer name/endpoint pair.
280 PluginManager<SOAPTransport,std::pair<const char*,const char*> > SOAPTransportManager;
283 * Manages factories for StorageService plugins.
285 PluginManager<StorageService,const xercesc::DOMElement*> StorageServiceManager;
290 #if defined (_MSC_VER)
291 #pragma warning( pop )
294 #endif /* __xmltooling_config_h__ */