https://issues.shibboleth.net/jira/browse/CPPOST-70
[shibboleth/cpp-opensaml.git] / saml / saml1 / core / impl / ProtocolsImpl.cpp
index 33d3b5d..9911c18 100644 (file)
@@ -117,7 +117,7 @@ namespace opensaml {
 
             QueryImpl(const QueryImpl& src) : AbstractXMLObject(src), AnyElementImpl(src) {}
 
-            IMPL_XMLOBJECT_CLONE(Query);
+            IMPL_XMLOBJECT_CLONE_EX(Query);
         };
 
         class SAML_DLLLOCAL SubjectQueryImpl : public virtual SubjectQuery,
@@ -131,10 +131,12 @@ namespace opensaml {
                 m_children.push_back(nullptr);
                 m_pos_Subject=m_children.begin();
             }
+
         protected:
             SubjectQueryImpl() {
                 init();
             }
+
         public:
             virtual ~SubjectQueryImpl() {}
 
@@ -146,10 +148,21 @@ namespace opensaml {
             SubjectQueryImpl(const SubjectQueryImpl& src)
                     : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
                 init();
+            }
+
+            void _clone(const SubjectQueryImpl& src) {
                 if (src.getSubject())
                     setSubject(src.getSubject()->cloneSubject());
             }
 
+            SubjectQuery* cloneSubjectQuery() const {
+                return dynamic_cast<SubjectQuery*>(clone());
+            }
+
+            Query* cloneQuery() const {
+                return dynamic_cast<Query*>(clone());
+            }
+
             IMPL_TYPED_CHILD(Subject);
 
         protected:
@@ -164,28 +177,27 @@ namespace opensaml {
             void init() {
                 m_AuthenticationMethod=nullptr;
             }
+
         public:
             virtual ~AuthenticationQueryImpl() {
                 XMLString::release(&m_AuthenticationMethod);
             }
 
             AuthenticationQueryImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
-                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+                    : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
                 init();
             }
 
             AuthenticationQueryImpl(const AuthenticationQueryImpl& src) : AbstractXMLObject(src), SubjectQueryImpl(src) {
                 init();
-                setAuthenticationMethod(src.getAuthenticationMethod());
             }
 
-            IMPL_XMLOBJECT_CLONE(AuthenticationQuery);
-            SubjectQuery* cloneSubjectQuery() const {
-                return cloneAuthenticationQuery();
-            }
-            Query* cloneQuery() const {
-                return cloneAuthenticationQuery();
+            void _clone(const AuthenticationQueryImpl& src) {
+                SubjectQueryImpl::_clone(src);
+                setAuthenticationMethod(src.getAuthenticationMethod());
             }
+
+            IMPL_XMLOBJECT_CLONE_EX(AuthenticationQuery);
             IMPL_STRING_ATTRIB(AuthenticationMethod);
 
         protected:
@@ -205,18 +217,23 @@ namespace opensaml {
             void init() {
                 m_Resource=nullptr;
             }
+
         public:
             virtual ~AttributeQueryImpl() {
                 XMLString::release(&m_Resource);
             }
 
             AttributeQueryImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
-                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+                    : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
                 init();
             }
 
             AttributeQueryImpl(const AttributeQueryImpl& src) : AbstractXMLObject(src), SubjectQueryImpl(src) {
                 init();
+            }
+
+            void _clone(const AttributeQueryImpl& src) {
+                SubjectQueryImpl::_clone(src);
                 setResource(src.getResource());
                 VectorOf(AttributeDesignator) v=getAttributeDesignators();
                 for (vector<AttributeDesignator*>::const_iterator i=src.m_AttributeDesignators.begin(); i!=src.m_AttributeDesignators.end(); i++) {
@@ -226,13 +243,7 @@ namespace opensaml {
                 }
             }
 
-            IMPL_XMLOBJECT_CLONE(AttributeQuery);
-            SubjectQuery* cloneSubjectQuery() const {
-                return cloneAttributeQuery();
-            }
-            Query* cloneQuery() const {
-                return cloneAttributeQuery();
-            }
+            IMPL_XMLOBJECT_CLONE_EX(AttributeQuery);
             IMPL_STRING_ATTRIB(Resource);
             IMPL_TYPED_CHILDREN(AttributeDesignator,m_children.end());
 
@@ -262,18 +273,23 @@ namespace opensaml {
                 m_pos_Evidence=m_pos_Subject;
                 ++m_pos_Evidence;
             }
+
         public:
             virtual ~AuthorizationDecisionQueryImpl() {
                 XMLString::release(&m_Resource);
             }
 
             AuthorizationDecisionQueryImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
-                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+                    : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
                 init();
             }
 
             AuthorizationDecisionQueryImpl(const AuthorizationDecisionQueryImpl& src) : AbstractXMLObject(src), SubjectQueryImpl(src) {
                 init();
+            }
+
+            void _clone(const AuthorizationDecisionQueryImpl& src) {
+                SubjectQueryImpl::_clone(src);
                 setResource(src.getResource());
                 if (src.getEvidence())
                     setEvidence(src.getEvidence()->cloneEvidence());
@@ -285,13 +301,7 @@ namespace opensaml {
                 }
             }
 
-            IMPL_XMLOBJECT_CLONE(AuthorizationDecisionQuery);
-            SubjectQuery* cloneSubjectQuery() const {
-                return cloneAuthorizationDecisionQuery();
-            }
-            Query* cloneQuery() const {
-                return cloneAuthorizationDecisionQuery();
-            }
+            IMPL_XMLOBJECT_CLONE_EX(AuthorizationDecisionQuery);
             IMPL_STRING_ATTRIB(Resource);
             IMPL_TYPED_CHILD(Evidence);
             IMPL_TYPED_CHILDREN(Action, m_pos_Evidence);
@@ -328,6 +338,7 @@ namespace opensaml {
                 m_Signature=nullptr;
                 m_pos_Signature=m_children.begin();
             }
+
         protected:
             RequestAbstractTypeImpl() {
                 init();
@@ -347,6 +358,13 @@ namespace opensaml {
             RequestAbstractTypeImpl(const RequestAbstractTypeImpl& src)
                     : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
                 init();
+            }
+
+            //IMPL_TYPED_CHILD(Signature);
+            // Need customized setter.
+
+        protected:
+            void _clone(const RequestAbstractTypeImpl& src) {
                 setMinorVersion(src.m_MinorVersion);
                 setRequestID(src.getRequestID());
                 setIssueInstant(src.getIssueInstant());
@@ -360,11 +378,9 @@ namespace opensaml {
                 }
             }
 
-            //IMPL_TYPED_CHILD(Signature);
-            // Need customized setter.
-        protected:
             Signature* m_Signature;
             list<XMLObject*>::iterator m_pos_Signature;
+
         public:
             Signature* getSignature() const {
                 return m_Signature;
@@ -378,6 +394,10 @@ namespace opensaml {
                     m_Signature->setContentReference(new opensaml::ContentReference(*this));
             }
 
+            RequestAbstractType* cloneRequestAbstractType() const {
+                return dynamic_cast<RequestAbstractType*>(clone());
+            }
+
             IMPL_INTEGER_ATTRIB(MinorVersion);
             IMPL_STRING_ATTRIB(RequestID);    // have to special-case getXMLID
             const XMLCh* getXMLID() const {
@@ -462,6 +482,7 @@ namespace opensaml {
                 m_pos_Query=m_pos_Signature;
                 ++m_pos_Query;
             }
+
         public:
             virtual ~RequestImpl() {}
 
@@ -472,6 +493,10 @@ namespace opensaml {
 
             RequestImpl(const RequestImpl& src) : AbstractXMLObject(src), RequestAbstractTypeImpl(src) {
                 init();
+            }
+
+            void _clone(const RequestImpl& src) {
+                RequestAbstractTypeImpl::_clone(src);
                 if (src.getQuery())
                     setQuery(src.getQuery()->cloneQuery());
                 VectorOf(AssertionIDReference) v=getAssertionIDReferences();
@@ -488,10 +513,7 @@ namespace opensaml {
                 }
             }
 
-            IMPL_XMLOBJECT_CLONE(Request);
-            RequestAbstractType* cloneRequestAbstractType() const {
-                return cloneRequest();
-            }
+            IMPL_XMLOBJECT_CLONE_EX(Request);
             IMPL_TYPED_CHILD(Query);
 
             SubjectQuery* getSubjectQuery() const {
@@ -678,10 +700,12 @@ namespace opensaml {
                 m_Signature=nullptr;
                 m_pos_Signature=m_children.begin();
             }
+
         protected:
             ResponseAbstractTypeImpl() {
                 init();
             }
+
         public:
             virtual ~ResponseAbstractTypeImpl() {
                 XMLString::release(&m_MinorVersion);
@@ -692,13 +716,19 @@ namespace opensaml {
             }
 
             ResponseAbstractTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
-                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+                    : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
                 init();
             }
 
             ResponseAbstractTypeImpl(const ResponseAbstractTypeImpl& src)
                     : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
                 init();
+            }
+
+            //IMPL_TYPED_CHILD(Signature);
+            // Need customized setter.
+        protected:
+            void _clone(const ResponseAbstractTypeImpl& src) {
                 setMinorVersion(src.m_MinorVersion);
                 setResponseID(src.getResponseID());
                 setInResponseTo(src.getInResponseTo());
@@ -708,9 +738,6 @@ namespace opensaml {
                     setSignature(src.getSignature()->cloneSignature());
             }
 
-            //IMPL_TYPED_CHILD(Signature);
-            // Need customized setter.
-        protected:
             Signature* m_Signature;
             list<XMLObject*>::iterator m_pos_Signature;
         public:
@@ -726,6 +753,10 @@ namespace opensaml {
                     m_Signature->setContentReference(new opensaml::ContentReference(*this));
             }
 
+            ResponseAbstractType* cloneResponseAbstractType() const {
+                return dynamic_cast<ResponseAbstractType*>(clone());
+            }
+
             IMPL_INTEGER_ATTRIB(MinorVersion);
             IMPL_STRING_ATTRIB(ResponseID);    // have to special-case getXMLID
             const XMLCh* getXMLID() const {
@@ -814,16 +845,21 @@ namespace opensaml {
                 m_pos_Status=m_pos_Signature;
                 ++m_pos_Status;
             }
+
         public:
             virtual ~ResponseImpl() {}
 
             ResponseImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
-                : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+                    : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
                 init();
             }
 
             ResponseImpl(const ResponseImpl& src) : AbstractXMLObject(src), ResponseAbstractTypeImpl(src) {
                 init();
+            }
+
+            void _clone(const ResponseImpl& src) {
+                ResponseAbstractTypeImpl::_clone(src);
                 if (src.getStatus())
                     setStatus(src.getStatus()->cloneStatus());
                 VectorOf(saml1::Assertion) v=getAssertions();
@@ -834,10 +870,7 @@ namespace opensaml {
                 }
             }
 
-            IMPL_XMLOBJECT_CLONE(Response);
-            ResponseAbstractType* cloneResponseAbstractType() const {
-                return cloneResponse();
-            }
+            IMPL_XMLOBJECT_CLONE_EX(Response);
             IMPL_TYPED_CHILD(Status);
             IMPL_TYPED_FOREIGN_CHILDREN(Assertion,saml1,m_children.end());