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