Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / SAMLConfig.h
1 /*
2  *  Copyright 2001-2009 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 saml/SAMLConfig.h
19  * 
20  * Library configuration.
21  */
22
23 #ifndef __saml_config_h__
24 #define __saml_config_h__
25
26 #include <saml/base.h>
27
28 #include <string>
29 #include <xercesc/dom/DOM.hpp>
30 #include <xmltooling/PluginManager.h>
31
32 /**
33  * @namespace opensaml
34  * Common classes for OpenSAML library
35  */
36 namespace opensaml {
37
38     class SAML_API ArtifactMap;
39     class SAML_API MessageEncoder;
40     class SAML_API MessageDecoder;
41     class SAML_API SAMLArtifact;
42     class SAML_API SecurityPolicyRule;
43
44     namespace saml2md {
45         class SAML_API MetadataProvider;
46         class SAML_API MetadataFilter;
47     };
48
49 #if defined (_MSC_VER)
50     #pragma warning( push )
51     #pragma warning( disable : 4250 4251 )
52 #endif
53
54     /**
55      * Singleton object that manages library startup/shutdown.configuration.
56      */
57     class SAML_API SAMLConfig
58     {
59     MAKE_NONCOPYABLE(SAMLConfig);
60     public:
61         virtual ~SAMLConfig() {}
62
63         /**
64          * Returns the global configuration object for the library.
65          * 
66          * @return reference to the global library configuration object
67          */
68         static SAMLConfig& getConfig();
69         
70         /**
71          * Initializes library
72          * 
73          * Each process using the library MUST call this function exactly once
74          * before using any library classes. The flag controls whether this is the
75          * "dominant" library or not and can allow the SAML library to be loaded
76          * as an extension of XMLTooling rather than subsuming it.
77          * 
78          * @param initXMLTooling true iff this method should initialize the XMLTooling layer
79          * @return true iff initialization was successful 
80          */
81         virtual bool init(bool initXMLTooling=true)=0;
82         
83         /**
84          * Shuts down library
85          * 
86          * Each process using the library SHOULD call this function exactly once
87          * before terminating itself. The flag controls whether this is the
88          * "dominant" library or not and can allow the SAML library to be loaded
89          * as an extension of XMLTooling rather than subsuming it.
90          * 
91          * @param termXMLTooling true iff this method should shutdown the XMLTooling layer
92          */
93         virtual void term(bool termXMLTooling=true)=0;
94         
95         /**
96          * Sets the global ArtifactMap instance.
97          * This method must be externally synchronized with any code that uses the object.
98          * Any previously set object is destroyed.
99          * 
100          * @param artifactMap   new ArtifactMap instance to store
101          */
102         void setArtifactMap(ArtifactMap* artifactMap);
103         
104         /**
105          * Returns the global ArtifactMap instance.
106          * 
107          * @return  global ArtifactMap or NULL
108          */
109         ArtifactMap* getArtifactMap() const {
110             return m_artifactMap;
111         }
112
113         /**
114          * Generate random information using the underlying security library
115          * 
116          * @param buf   buffer for the information
117          * @param len   number of bytes to write into buffer
118          */
119         virtual void generateRandomBytes(void* buf, unsigned int len)=0;
120
121         /**
122          * Generate random information using the underlying security library
123          * 
124          * @param buf   string buffer for the information
125          * @param len   number of bytes to write into buffer
126          */
127         virtual void generateRandomBytes(std::string& buf, unsigned int len)=0;
128
129         /**
130          * Generate a valid XML identifier of the form _X{32} where X is a
131          * random hex character. The caller is responsible for freeing the result.
132          * 
133          * @return a valid null-terminated XML ID
134          */
135         virtual XMLCh* generateIdentifier()=0;
136         
137         /**
138          * Generate the SHA-1 hash of a string
139          * 
140          * @param s     NULL-terminated string to hash
141          * @param toHex true iff the result should be encoded in hexadecimal form or left as raw bytes
142          *  
143          * @return  SHA-1 hash of the data
144          */
145         virtual std::string hashSHA1(const char* s, bool toHex=false)=0;
146
147         /** Manages factories for MessageDecoder plugins. */
148         xmltooling::PluginManager< MessageDecoder,std::string,std::pair<const xercesc::DOMElement*,const XMLCh*> > MessageDecoderManager;
149
150         /** Manages factories for MessageEncoder plugins. */
151         xmltooling::PluginManager< MessageEncoder,std::string,std::pair<const xercesc::DOMElement*,const XMLCh*> > MessageEncoderManager;
152
153         /** Manages factories for SAMLArtifact plugins. */
154         xmltooling::PluginManager<SAMLArtifact,std::string,const char*> SAMLArtifactManager;
155
156         /** Manages factories for SecurityPolicyRule plugins. */
157         xmltooling::PluginManager<SecurityPolicyRule,std::string,const xercesc::DOMElement*> SecurityPolicyRuleManager;
158
159         /** Manages factories for MetadataProvider plugins. */
160         xmltooling::PluginManager<saml2md::MetadataProvider,std::string,const xercesc::DOMElement*> MetadataProviderManager;
161         
162         /** Manages factories for MetadataFilter plugins. */
163         xmltooling::PluginManager<saml2md::MetadataFilter,std::string,const xercesc::DOMElement*> MetadataFilterManager;
164
165     protected:
166         SAMLConfig() : m_artifactMap(NULL) {}
167         
168         /** Global ArtifactMap instance for use by artifact-related functions. */
169         ArtifactMap* m_artifactMap;
170     };
171
172 #if defined (_MSC_VER)
173     #pragma warning( pop )
174 #endif
175     
176 };
177
178 #endif /* __saml_config_h__ */