1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 /*
21  * XSEC
22  *
23  * XKMSLocateRequestImpl := Implementation of LocateRequest Messages
24  *
25  * $Id: XKMSLocateRequestImpl.cpp 1833340 2018-06-11 15:40:13Z scantor $
26  *
27  */
28 
29 #include <xsec/framework/XSECDefs.hpp>
30 #include <xsec/framework/XSECError.hpp>
31 #include <xsec/framework/XSECEnv.hpp>
32 
33 #ifdef XSEC_XKMS_ENABLED
34 
35 #include "../../utils/XSECDOMUtils.hpp"
36 
37 #include "XKMSLocateRequestImpl.hpp"
38 
39 #include <xsec/xkms/XKMSConstants.hpp>
40 
41 #include <xercesc/dom/DOM.hpp>
42 
43 XERCES_CPP_NAMESPACE_USE
44 
45 // --------------------------------------------------------------------------------
46 //           Construct/Destruct
47 // --------------------------------------------------------------------------------
48 
XKMSLocateRequestImpl(const XSECEnv * env)49 XKMSLocateRequestImpl::XKMSLocateRequestImpl(
50 		const XSECEnv * env) :
51 m_request(env),
52 m_msg(m_request.m_msg),
53 mp_queryKeyBindingElement(NULL),
54 mp_queryKeyBinding(NULL) {
55 
56 }
57 
XKMSLocateRequestImpl(const XSECEnv * env,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * node)58 XKMSLocateRequestImpl::XKMSLocateRequestImpl(
59 		const XSECEnv * env,
60 		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * node) :
61 m_request(env, node),
62 m_msg(m_request.m_msg),
63 mp_queryKeyBinding(NULL) {
64 
65 }
66 
~XKMSLocateRequestImpl()67 XKMSLocateRequestImpl::~XKMSLocateRequestImpl() {
68 
69 	if (mp_queryKeyBinding != NULL)
70 		delete mp_queryKeyBinding;
71 
72 }
73 
74 
75 // --------------------------------------------------------------------------------
76 //           Load from DOM
77 // --------------------------------------------------------------------------------
78 
79 // Load elements
load()80 void XKMSLocateRequestImpl::load() {
81 
82 	if (m_msg.mp_messageAbstractTypeElement == NULL) {
83 
84 		// Attempt to load an empty element
85 		throw XSECException(XSECException::XKMSError,
86 			"XKMSLocateRequest::load - called on empty DOM");
87 
88 	}
89 
90 	if (!strEquals(getXKMSLocalName(m_msg.mp_messageAbstractTypeElement),
91 									XKMSConstants::s_tagLocateRequest)) {
92 
93 		throw XSECException(XSECException::XKMSError,
94 			"XKMSLocateRequest::load - called incorrect node");
95 
96 	}
97 
98 	// Load the base message
99 	m_request.load();
100 
101 	// Now check for any QueryKeyBinding elements
102 	DOMElement * tmpElt = findFirstElementChild(m_msg.mp_messageAbstractTypeElement);
103 	while (tmpElt != NULL &&
104 		!strEquals(getXKMSLocalName(tmpElt), XKMSConstants::s_tagQueryKeyBinding))
105 		tmpElt = findNextElementChild(tmpElt);
106 
107 	if (tmpElt != NULL) {
108 
109 		XSECnew(mp_queryKeyBinding, XKMSQueryKeyBindingImpl(m_msg.mp_env, tmpElt));
110 		mp_queryKeyBinding->load();
111 		mp_queryKeyBindingElement = tmpElt;
112 
113 	}
114 
115 }
116 
117 // --------------------------------------------------------------------------------
118 //           Create a blank one
119 // --------------------------------------------------------------------------------
createBlankLocateRequest(const XMLCh * service,const XMLCh * id)120 DOMElement * XKMSLocateRequestImpl::createBlankLocateRequest(
121 		const XMLCh * service,
122 		const XMLCh * id) {
123 
124 	return m_request.createBlankRequestAbstractType(
125 		XKMSConstants::s_tagLocateRequest, service, id);
126 //	return XKMSRequestAbstractTypeImpl::createBlankMessageAbstractType(
127 //		MAKE_UNICODE_STRING("ValidateRequest"), service, id);
128 
129 }
130 
131 // --------------------------------------------------------------------------------
132 //           Get interface methods
133 // --------------------------------------------------------------------------------
134 
getMessageType(void)135 XKMSMessageAbstractType::messageType XKMSLocateRequestImpl::getMessageType(void) {
136 
137 	return XKMSMessageAbstractTypeImpl::LocateRequest;
138 
139 }
140 
141 
getQueryKeyBinding(void)142 XKMSQueryKeyBinding * XKMSLocateRequestImpl::getQueryKeyBinding(void) {
143 
144 	return mp_queryKeyBinding;
145 
146 }
147 
148 // --------------------------------------------------------------------------------
149 //           Setter methods
150 // --------------------------------------------------------------------------------
151 
addQueryKeyBinding(void)152 XKMSQueryKeyBinding * XKMSLocateRequestImpl::addQueryKeyBinding(void) {
153 
154 	if (mp_queryKeyBinding != NULL)
155 		return mp_queryKeyBinding;
156 
157 
158 	// OK - Nothing exists, so we need to create from scratch
159 
160 	XSECnew(mp_queryKeyBinding, XKMSQueryKeyBindingImpl(m_msg.mp_env));
161 	mp_queryKeyBindingElement = mp_queryKeyBinding->createBlankQueryKeyBinding();
162 
163 	if (m_msg.mp_messageAbstractTypeElement->getFirstChild() == NULL) {
164 		m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
165 	}
166 	m_msg.mp_messageAbstractTypeElement->appendChild(mp_queryKeyBindingElement);
167 	m_msg.mp_env->doPrettyPrint(m_msg.mp_messageAbstractTypeElement);
168 
169 	return mp_queryKeyBinding;
170 
171 }
172 
173 #endif /* XSEC_XKMS_ENABLED */
174