|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Authorization out transaction handler. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngAuthorizationTransactionOut.h" |
|
20 |
|
21 #include "CPEngAuthorizationResponse.h" |
|
22 #include "MPEngAuthorizationEngine.h" |
|
23 |
|
24 #include "MPEngXMLSerializer.h" |
|
25 #include "MPEngXMLParser.h" |
|
26 |
|
27 #include "MPEngPresenceAttrManager.h" |
|
28 #include "PEngAttrLibFactory.h" |
|
29 |
|
30 #include "CPEngTransactionStatus.h" |
|
31 #include "PEngWVPresenceErrors2.h" |
|
32 #include "PresenceDebugPrint.h" |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CPEngAuthorizationTransactionOut::CPEngAuthorizationTransactionOut() |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPEngAuthorizationTransactionOut::CPEngAuthorizationTransactionOut( |
|
42 MPEngAuthorizationEngine& aAuthEngine, |
|
43 MPEngPresenceAttrManager& aAttrManager, |
|
44 MPEngXMLParser& aXMLParser, |
|
45 TPEngWVCspVersion& aCSPVersion, |
|
46 TInt aOperationId ) |
|
47 : iAuthEngine( aAuthEngine ), |
|
48 iAttributeManager( aAttrManager ), |
|
49 iXMLParser( aXMLParser ), |
|
50 iCSPVersion( aCSPVersion ), |
|
51 iTransCompleted( EFalse ), |
|
52 iOperationId( aOperationId ) |
|
53 { |
|
54 PENG_DP( D_PENG_LIT( "CPEngAuthorizationTransactionOut::CPEngAuthorizationTransactionOut()" ) ); |
|
55 iAuthEngine.LockForNetworkPublishing(); |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CPEngAuthorizationTransactionOut::ConstructL() |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CPEngAuthorizationTransactionOut::ConstructL() |
|
64 { |
|
65 iTransactionStatus = CPEngTransactionStatus::NewL(); |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CPEngAuthorizationTransactionOut::NewLC() |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CPEngAuthorizationTransactionOut* CPEngAuthorizationTransactionOut::NewLC( |
|
74 MPEngAuthorizationEngine& aAuthEngine, |
|
75 MPEngPresenceAttrManager& aAttrManager, |
|
76 MPEngXMLParser& aXMLParser, |
|
77 TPEngWVCspVersion& aCSPVersion, |
|
78 TInt aOperationId ) |
|
79 { |
|
80 CPEngAuthorizationTransactionOut* self = |
|
81 new ( ELeave ) CPEngAuthorizationTransactionOut( |
|
82 aAuthEngine, |
|
83 aAttrManager, |
|
84 aXMLParser, |
|
85 aCSPVersion, |
|
86 aOperationId ); |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL( ); |
|
89 |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 // Destructor |
|
95 CPEngAuthorizationTransactionOut::~CPEngAuthorizationTransactionOut() |
|
96 { |
|
97 iAuthEngine.UnLockForNetworkPublishing(); |
|
98 delete iResponse; |
|
99 delete iTransactionStatus; |
|
100 } |
|
101 |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CPEngAuthorizationTransactionOut::RequestL() |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CPEngAuthorizationTransactionOut::RequestL( TDes8& aSendBuffer ) |
|
108 { |
|
109 aSendBuffer.Zero(); |
|
110 MPEngXMLSerializer* xmlSerializer = CreateXmlSerializerL( aSendBuffer ); |
|
111 CleanupClosePushL( *xmlSerializer ); |
|
112 |
|
113 |
|
114 // <TransactionContent xmlns="http://www.wireless -village.org/TRC1.1"> |
|
115 if ( iCSPVersion == EWVCspV11 ) |
|
116 { |
|
117 xmlSerializer->StartTagL( KTransactionContent ); |
|
118 xmlSerializer->AttributeL( KXmlXmlns, KTransactionContentNS ); |
|
119 } |
|
120 else |
|
121 { |
|
122 xmlSerializer->StartTagL( KTransactionContent ); |
|
123 xmlSerializer->AttributeL( KXmlXmlns, KTransactionContentNS_CSP12 ); |
|
124 } |
|
125 |
|
126 |
|
127 switch ( iResponse->AuthorizationStatus() ) |
|
128 { |
|
129 case MPEngAuthorizationRequest::EPEngAuthAccepted: // fall through |
|
130 case MPEngAuthorizationRequest::EPEngAuthDenied: |
|
131 { |
|
132 AppendXMLPresenceAuthUserL( *xmlSerializer ); |
|
133 break; |
|
134 } |
|
135 |
|
136 case MPEngAuthorizationRequest::EPEngAuthCanceled: |
|
137 { |
|
138 AppendXMLCancelAuthorizationL( *xmlSerializer ); |
|
139 } |
|
140 |
|
141 default: |
|
142 { |
|
143 User::Leave( KErrNotSupported ); |
|
144 break; |
|
145 } |
|
146 } |
|
147 |
|
148 |
|
149 // end of transaction |
|
150 // </TransactionContent> |
|
151 xmlSerializer->EndTagL( KTransactionContent ); |
|
152 CleanupStack::PopAndDestroy( ); // xmlSerializer |
|
153 } |
|
154 |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CPEngAuthorizationTransactionOut::LastRunningTransactionHandler() |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CPEngAuthorizationTransactionOut::LastRunningTransactionHandler() |
|
161 { |
|
162 } |
|
163 |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CPEngAuthorizationTransactionOut::ProcessResponseL() |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CPEngAuthorizationTransactionOut::ProcessResponseL( |
|
170 const TDesC8& aResponse, |
|
171 TRequestStatus& /* aStatus */ ) |
|
172 { |
|
173 PENG_DP( D_PENG_LIT( "CPEngAuthorizationTransactionOut::ProcessResponseL()" ) ); |
|
174 |
|
175 |
|
176 // check if we have some answer from the server |
|
177 TInt err ( iXMLParser.ParseResultL( aResponse, |
|
178 iOperationId, |
|
179 *iTransactionStatus ) ); |
|
180 // how did transaction go |
|
181 switch ( err ) |
|
182 { |
|
183 case KErrNone: // transaction OK |
|
184 { |
|
185 // Authorization response went fine, store it |
|
186 iAuthEngine.UpdateAuthorizationStateL( *iResponse, |
|
187 ( iCSPVersion == EWVCspV12 ) ); |
|
188 break; |
|
189 } |
|
190 |
|
191 case KPEngNwErrUnrespondedPresenceRequest: |
|
192 case KPEngNwErrUnknownUser: |
|
193 case KPEngNwErrBadParameter: |
|
194 { |
|
195 // unknown user id,or bad param, remove Authorization request |
|
196 iAuthEngine.RemoveAuthorizationRequestL( *iResponse ); |
|
197 break; |
|
198 } |
|
199 |
|
200 default: |
|
201 { |
|
202 } |
|
203 } |
|
204 |
|
205 iTransCompleted = ETrue; |
|
206 } |
|
207 |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CPEngAuthorizationTransactionOut::CancelProcessing() |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CPEngAuthorizationTransactionOut::CancelProcessing( ) |
|
214 { |
|
215 } |
|
216 |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CPEngAuthorizationTransactionOut::NewTransactionHandlersL() |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CPEngAuthorizationTransactionOut::NewTransactionHandlersL( |
|
223 RPointerArray<MPEngOutgoingTransactionHandler>& /* aTransactionsArray*/ ) |
|
224 { |
|
225 } |
|
226 |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CPEngAuthorizationTransactionOut::TransactionCompleted() |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TBool CPEngAuthorizationTransactionOut::TransactionCompleted() |
|
233 { |
|
234 return iTransCompleted; |
|
235 } |
|
236 |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CPEngAuthorizationTransactionOut::TransactionResult() |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 CPEngTransactionStatus* CPEngAuthorizationTransactionOut::TransactionResult() |
|
243 { |
|
244 CPEngTransactionStatus* temp = iTransactionStatus; |
|
245 iTransactionStatus = NULL; |
|
246 return temp; |
|
247 } |
|
248 |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CPEngAuthorizationTransactionOut::ReleaseHandler() |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CPEngAuthorizationTransactionOut::ReleaseHandler() |
|
255 { |
|
256 iTransCompleted = ETrue; |
|
257 } |
|
258 |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CPEngAuthorizationTransactionOut::SetAuthResponse() |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CPEngAuthorizationTransactionOut::SetAuthResponse( |
|
265 CPEngAuthorizationResponse* aResponse ) |
|
266 { |
|
267 delete iResponse; |
|
268 iResponse = aResponse; |
|
269 } |
|
270 |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CPEngAuthorizationTransactionOut::AppendXMLPresenceAuthUserL() |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CPEngAuthorizationTransactionOut::AppendXMLPresenceAuthUserL( |
|
277 MPEngXMLSerializer& aXmlSerializer ) |
|
278 { |
|
279 // <PresenceAuth-User> |
|
280 aXmlSerializer.StartTagL( KPresenceAuthUser ); |
|
281 AppendXMLUserIdL( aXmlSerializer ); |
|
282 |
|
283 // <Acceptance> |
|
284 aXmlSerializer.StartTagL( KAcceptance ); |
|
285 |
|
286 |
|
287 if ( iResponse->AuthorizationStatus() == MPEngAuthorizationRequest::EPEngAuthAccepted ) |
|
288 { |
|
289 aXmlSerializer.RawValueL( KXMLValueTrue ); |
|
290 } |
|
291 else |
|
292 { |
|
293 aXmlSerializer.RawValueL( KXMLValueFalse ); |
|
294 } |
|
295 // </Acceptance> |
|
296 aXmlSerializer.EndTagL( KAcceptance ); |
|
297 |
|
298 |
|
299 // if CSP 1.2 we also append list of attributes to accept |
|
300 if ( iCSPVersion == EWVCspV12 ) |
|
301 { |
|
302 const RArray<TUint32>& attributes = iResponse->AuthorizedAttributes(); |
|
303 TInt count( attributes.Count() ); |
|
304 // xmlns="Name space" |
|
305 // append attribute's namespace according to attributes on the list |
|
306 // Append Attribute name space |
|
307 TPtrC8 attributeName; |
|
308 TPtrC8 attributeNameSpace; |
|
309 User::LeaveIfError( |
|
310 iAttributeManager.GetAttributeXmlNameAndNameSpace( attributes[0], |
|
311 attributeName, |
|
312 attributeNameSpace ) ); |
|
313 |
|
314 // <PresenceSubList> |
|
315 aXmlSerializer.StartTagL( KPresenceSubList ); |
|
316 aXmlSerializer.AttributeL( KXmlXmlns, attributeNameSpace ); |
|
317 |
|
318 // Append attributes one by one |
|
319 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
320 { |
|
321 User::LeaveIfError( |
|
322 iAttributeManager.GetAttributeXmlNameAndNameSpace( attributes[ x ], |
|
323 attributeName, |
|
324 attributeNameSpace ) ); |
|
325 |
|
326 aXmlSerializer.StartTagL( attributeName |
|
327 ).EndTagL( attributeName ); |
|
328 } |
|
329 |
|
330 // </PresenceSubList> |
|
331 aXmlSerializer.EndTagL( KPresenceSubList ); |
|
332 } |
|
333 |
|
334 // </PresenceAuth-User> |
|
335 aXmlSerializer.EndTagL( KPresenceAuthUser ); |
|
336 } |
|
337 |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CPEngAuthorizationTransactionOut::AppendXMLCancelAuthorizationL() |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 void CPEngAuthorizationTransactionOut::AppendXMLCancelAuthorizationL( |
|
344 MPEngXMLSerializer& aXmlSerializer ) |
|
345 { |
|
346 // <CancelAuth-Request> |
|
347 aXmlSerializer.StartTagL( KCancelAuthRequest ); |
|
348 |
|
349 AppendXMLUserIdL( aXmlSerializer ); |
|
350 |
|
351 // </CancelAuth-Request> |
|
352 aXmlSerializer.EndTagL( KCancelAuthRequest ); |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CPEngAuthorizationTransactionOut::AppendXMLUserIdL() |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CPEngAuthorizationTransactionOut::AppendXMLUserIdL( |
|
360 MPEngXMLSerializer& aXmlSerializer ) |
|
361 { |
|
362 aXmlSerializer.StartTagL( KUserIDXMLTag |
|
363 ).WvAddressL( iResponse->Id() |
|
364 ).EndTagL( KUserIDXMLTag ); |
|
365 } |
|
366 |
|
367 // End of File |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |