e68ed96e179ada024823167f762e023201c81592
[shibboleth/cpp-sp.git] / shib-target / internal.h
1 /*
2  *  Copyright 2001-2005 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 /* internal.h - internally visible declarations
18
19    Scott Cantor
20    6/29/03
21
22    $History:$
23 */
24
25 #ifndef __shibtarget_internal_h__
26 #define __shibtarget_internal_h__
27
28 #ifdef WIN32
29 # define SHIBTARGET_EXPORTS __declspec(dllexport)
30 #endif
31
32 // eventually we might be able to support autoconf via cygwin...
33 #if defined (_MSC_VER) || defined(__BORLANDC__)
34 # include "config_win32.h"
35 #else
36 # include "config.h"
37 #endif
38
39 #include "shib-target.h"
40 #include "hresult.h"
41
42 #include <xmltooling/util/Threads.h>
43
44 #include <log4cpp/Category.hh>
45 #include <log4cpp/FixedContextCategory.hh>
46
47 #define SHIBT_L(s) shibtarget::XML::Literals::s
48 #define SHIBT_L_QNAME(p,s) shibtarget::XML::Literals::p##_##s
49 #define SHIBT_LOGCAT "shibtarget"
50 #define SHIBTRAN_LOGCAT "Shibboleth-TRANSACTION"
51
52 namespace shibtarget {
53     // Generic class, which handles the IPropertySet configuration interface.
54     // Most of the basic configuration details are exposed via this interface.
55     // This implementation extracts the XML tree structure and caches it in a map
56     // with the attributes stored in the various possible formats they might be fetched.
57     // Elements are treated as nested IPropertySets.
58     // The "trick" to this is to pass in an "exclude list" using a DOMNodeFilter. Nested
59     // property sets are extracted by running a TreeWalker againt the filter for the
60     // immediate children. The filter should skip any excluded elements that will be
61     // processed separately.
62     class XMLPropertySet : public virtual IPropertySet
63     {
64     public:
65         XMLPropertySet() {}
66         ~XMLPropertySet();
67
68         std::pair<bool,bool> getBool(const char* name, const char* ns=NULL) const;
69         std::pair<bool,const char*> getString(const char* name, const char* ns=NULL) const;
70         std::pair<bool,const XMLCh*> getXMLString(const char* name, const char* ns=NULL) const;
71         std::pair<bool,unsigned int> getUnsignedInt(const char* name, const char* ns=NULL) const;
72         std::pair<bool,int> getInt(const char* name, const char* ns=NULL) const;
73         const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const;
74         const DOMElement* getElement() const {return m_root;}
75     
76         void load(
77             const DOMElement* e,    // root element of property set
78             log4cpp::Category& log, // log object for tracing
79             DOMNodeFilter* filter,  // control what subelements to include
80             const std::map<std::string,std::string>* remapper=NULL   // on the fly property renaming for legacy support
81             );
82
83     private:
84         const DOMElement* m_root;
85         std::map<std::string,std::pair<char*,const XMLCh*> > m_map;
86         std::map<std::string,IPropertySet*> m_nested;
87     };
88
89     // ST-aware class that maps SAML artifacts to appropriate binding information
90     class STArtifactMapper : public virtual saml::SAMLBrowserProfile::ArtifactMapper
91     {
92     public:
93         STArtifactMapper(const IApplication* application) : m_app(application) {}
94         virtual ~STArtifactMapper() {}
95         saml::SAMLResponse* resolve(saml::SAMLRequest* request);
96     
97     private:
98         const IApplication* m_app;
99     };
100
101     class STConfig : public ShibTargetConfig
102     {
103     public:
104         STConfig() : m_tranLog(NULL), m_tranLogLock(NULL) {}
105         ~STConfig() {}
106         
107         bool init(const char* schemadir);
108         bool load(const char* config);
109         void shutdown();
110
111         log4cpp::Category& getTransactionLog() { m_tranLogLock->lock(); return *m_tranLog; }
112         void releaseTransactionLog() { m_tranLogLock->unlock();}
113     private:
114         log4cpp::FixedContextCategory* m_tranLog;
115         xmltooling::Mutex* m_tranLogLock;
116         static IConfig* ShibTargetConfigFactory(const DOMElement* e);
117     };
118 }
119
120 #endif