208035fdbf9b6df7d6095a1acd4a010f65725ece
[shibboleth/cpp-sp.git] / shibsp / MetadataExtImpl.cpp
1 /*
2  *  Copyright 2001-2006 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  * MetadataExtImpl.cpp
19  * 
20  * Implementation classes for Shibboleth metadata extensions schema
21  */
22
23 #include "internal.h"
24 #include "exceptions.h"
25 #include "MetadataExt.h"
26
27 #include <xmltooling/AbstractComplexElement.h>
28 #include <xmltooling/AbstractSimpleElement.h>
29 #include <xmltooling/impl/AnyElement.h>
30 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>
31 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
32 #include <xmltooling/util/XMLHelper.h>
33
34 using namespace shibsp;
35 using namespace xmlsignature;
36 using namespace xmltooling;
37 using namespace std;
38
39 using xmlconstants::XMLSIG_NS;
40 using xmlconstants::XML_BOOL_NULL;
41 using shibspconstants::SHIBMD_NS;
42
43 #if defined (_MSC_VER)
44     #pragma warning( push )
45     #pragma warning( disable : 4250 4251 )
46 #endif
47
48 namespace shibsp {
49
50     class SHIBSP_DLLLOCAL ScopeImpl : public virtual Scope,
51         public AbstractSimpleElement,
52         public AbstractDOMCachingXMLObject,
53         public AbstractXMLObjectMarshaller,
54         public AbstractXMLObjectUnmarshaller
55     {
56         void init() {
57             m_regexp=XML_BOOL_NULL;
58         }
59
60     public:
61
62         ScopeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
63                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
64             init();
65         }
66             
67         ScopeImpl(const ScopeImpl& src)
68                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src) {
69             init();
70             regexp(src.m_regexp);
71         }
72         
73         IMPL_XMLOBJECT_CLONE(Scope);
74         IMPL_BOOLEAN_ATTRIB(regexp);
75
76     protected:
77         void marshallAttributes(DOMElement* domElement) const {
78             MARSHALL_BOOLEAN_ATTRIB(regexp,REGEXP,NULL);
79         }
80
81         void processAttribute(const DOMAttr* attribute) {
82             PROC_BOOLEAN_ATTRIB(regexp,REGEXP,NULL);
83             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
84         }
85     };
86
87     class SHIBSP_DLLLOCAL KeyAuthorityImpl : public virtual KeyAuthority,
88             public AbstractComplexElement,
89             public AbstractAttributeExtensibleXMLObject,
90             public AbstractDOMCachingXMLObject,
91             public AbstractXMLObjectMarshaller,
92             public AbstractXMLObjectUnmarshaller
93     {
94         void init() {
95             m_VerifyDepth=NULL;
96         }
97     public:
98         virtual ~KeyAuthorityImpl() {
99             XMLString::release(&m_VerifyDepth);
100         }
101
102         KeyAuthorityImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
103                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
104             init();
105         }
106             
107         KeyAuthorityImpl(const KeyAuthorityImpl& src)
108                 : AbstractXMLObject(src), AbstractComplexElement(src),
109                     AbstractAttributeExtensibleXMLObject(src), AbstractDOMCachingXMLObject(src) {
110             init();
111             setVerifyDepth(src.m_VerifyDepth);
112             VectorOf(KeyInfo) v=getKeyInfos();
113             for (vector<KeyInfo*>::const_iterator i=src.m_KeyInfos.begin(); i!=src.m_KeyInfos.end(); ++i)
114                 v.push_back((*i)->cloneKeyInfo());
115         }
116         
117         IMPL_XMLOBJECT_CLONE(KeyAuthority);
118         IMPL_INTEGER_ATTRIB(VerifyDepth);
119         IMPL_TYPED_CHILDREN(KeyInfo,m_children.end());
120         
121     public:
122         void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false) {
123             if (!qualifiedName.hasNamespaceURI()) {
124                 if (XMLString::equals(qualifiedName.getLocalPart(),VERIFYDEPTH_ATTRIB_NAME)) {
125                     setVerifyDepth(value);
126                     return;
127                 }
128             }
129             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value, ID);
130         }
131
132     protected:
133         void marshallAttributes(DOMElement* domElement) const {
134             MARSHALL_INTEGER_ATTRIB(VerifyDepth,VERIFYDEPTH,NULL);
135             marshallExtensionAttributes(domElement);
136         }
137
138         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
139             PROC_TYPED_CHILDREN(KeyInfo,XMLSIG_NS,false);
140             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
141         }
142
143         void processAttribute(const DOMAttr* attribute) {
144             unmarshallExtensionAttribute(attribute);
145         }
146     };
147
148 };
149
150 #if defined (_MSC_VER)
151     #pragma warning( pop )
152 #endif
153
154 // Builder Implementations
155
156 IMPL_XMLOBJECTBUILDER(Scope);
157 IMPL_XMLOBJECTBUILDER(KeyAuthority);
158
159 const XMLCh Scope::LOCAL_NAME[] =                       UNICODE_LITERAL_5(S,c,o,p,e);
160 const XMLCh Scope::REGEXP_ATTRIB_NAME[] =               UNICODE_LITERAL_6(r,e,g,e,x,p);
161 const XMLCh KeyAuthority::LOCAL_NAME[] =                UNICODE_LITERAL_12(K,e,y,A,u,t,h,o,r,i,t,y);
162 const XMLCh KeyAuthority::VERIFYDEPTH_ATTRIB_NAME[] =   UNICODE_LITERAL_11(V,e,r,i,f,y,D,e,p,t,h);