Add boost support, and header fix
[shibboleth/cpp-sp.git] / shibsp / metadata / MetadataExtImpl.cpp
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * MetadataExtImpl.cpp
23  * 
24  * Implementation classes for Shibboleth metadata extensions schema.
25  */
26
27 #include "internal.h"
28 #include "exceptions.h"
29 #include "metadata/MetadataExt.h"
30
31 #include <boost/lexical_cast.hpp>
32 #include <xmltooling/AbstractComplexElement.h>
33 #include <xmltooling/AbstractSimpleElement.h>
34 #include <xmltooling/impl/AnyElement.h>
35 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>
36 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
37 #include <xmltooling/signature/KeyInfo.h>
38 #include <xmltooling/util/XMLHelper.h>
39
40 using namespace shibsp;
41 using namespace xmlsignature;
42 using namespace xmltooling;
43 using namespace std;
44
45 using xmlconstants::XMLSIG_NS;
46 using xmlconstants::XML_BOOL_NULL;
47 using shibspconstants::SHIBMD_NS;
48
49 #if defined (_MSC_VER)
50     #pragma warning( push )
51     #pragma warning( disable : 4250 4251 )
52 #endif
53
54 namespace shibsp {
55
56     class SHIBSP_DLLLOCAL ScopeImpl : public virtual Scope,
57         public AbstractSimpleElement,
58         public AbstractDOMCachingXMLObject,
59         public AbstractXMLObjectMarshaller,
60         public AbstractXMLObjectUnmarshaller
61     {
62         void init() {
63             m_Regexp=XML_BOOL_NULL;
64         }
65
66     public:
67
68         ScopeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
69                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
70             init();
71         }
72             
73         ScopeImpl(const ScopeImpl& src)
74                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src) {
75             init();
76             Regexp(src.m_Regexp);
77         }
78         
79         IMPL_XMLOBJECT_CLONE(Scope);
80         IMPL_BOOLEAN_ATTRIB(Regexp);
81
82     protected:
83         void marshallAttributes(DOMElement* domElement) const {
84             MARSHALL_BOOLEAN_ATTRIB(Regexp,REGEXP,nullptr);
85         }
86
87         void processAttribute(const DOMAttr* attribute) {
88             PROC_BOOLEAN_ATTRIB(Regexp,REGEXP,nullptr);
89             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
90         }
91     };
92
93     class SHIBSP_DLLLOCAL KeyAuthorityImpl : public virtual KeyAuthority,
94             public AbstractComplexElement,
95             public AbstractAttributeExtensibleXMLObject,
96             public AbstractDOMCachingXMLObject,
97             public AbstractXMLObjectMarshaller,
98             public AbstractXMLObjectUnmarshaller
99     {
100         void init() {
101             m_VerifyDepth=nullptr;
102         }
103     public:
104         virtual ~KeyAuthorityImpl() {
105             XMLString::release(&m_VerifyDepth);
106         }
107
108         KeyAuthorityImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
109                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
110             init();
111         }
112             
113         KeyAuthorityImpl(const KeyAuthorityImpl& src)
114                 : AbstractXMLObject(src), AbstractComplexElement(src),
115                     AbstractAttributeExtensibleXMLObject(src), AbstractDOMCachingXMLObject(src) {
116             init();
117             setVerifyDepth(src.m_VerifyDepth);
118             VectorOf(KeyInfo) v=getKeyInfos();
119             for (vector<KeyInfo*>::const_iterator i=src.m_KeyInfos.begin(); i!=src.m_KeyInfos.end(); ++i)
120                 v.push_back((*i)->cloneKeyInfo());
121         }
122         
123         IMPL_XMLOBJECT_CLONE(KeyAuthority);
124         IMPL_INTEGER_ATTRIB(VerifyDepth);
125         IMPL_TYPED_CHILDREN(KeyInfo,m_children.end());
126         
127     public:
128         void setAttribute(const xmltooling::QName& qualifiedName, const XMLCh* value, bool ID=false) {
129             if (!qualifiedName.hasNamespaceURI()) {
130                 if (XMLString::equals(qualifiedName.getLocalPart(),VERIFYDEPTH_ATTRIB_NAME)) {
131                     setVerifyDepth(value);
132                     return;
133                 }
134             }
135             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value, ID);
136         }
137
138     protected:
139         void marshallAttributes(DOMElement* domElement) const {
140             MARSHALL_INTEGER_ATTRIB(VerifyDepth,VERIFYDEPTH,nullptr);
141             marshallExtensionAttributes(domElement);
142         }
143
144         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
145             PROC_TYPED_CHILDREN(KeyInfo,XMLSIG_NS,false);
146             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
147         }
148
149         void processAttribute(const DOMAttr* attribute) {
150             unmarshallExtensionAttribute(attribute);
151         }
152     };
153
154 };
155
156 #if defined (_MSC_VER)
157     #pragma warning( pop )
158 #endif
159
160 // Builder Implementations
161
162 IMPL_XMLOBJECTBUILDER(Scope);
163 IMPL_XMLOBJECTBUILDER(KeyAuthority);
164
165 const XMLCh Scope::LOCAL_NAME[] =                       UNICODE_LITERAL_5(S,c,o,p,e);
166 const XMLCh Scope::REGEXP_ATTRIB_NAME[] =               UNICODE_LITERAL_6(r,e,g,e,x,p);
167 const XMLCh KeyAuthority::LOCAL_NAME[] =                UNICODE_LITERAL_12(K,e,y,A,u,t,h,o,r,i,t,y);
168 const XMLCh KeyAuthority::VERIFYDEPTH_ATTRIB_NAME[] =   UNICODE_LITERAL_11(V,e,r,i,f,y,D,e,p,t,h);