|
1 /* |
|
2 * Copyright (c) 2002 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: Status response buffering |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "NSmlResponseController.h" |
|
23 #include "nsmlcliagconstants.h" |
|
24 |
|
25 |
|
26 // --------------------------------------------------------- |
|
27 // CNSmlResponseController::CNSmlResponseController() |
|
28 // Constructor, nothing special in here. |
|
29 // --------------------------------------------------------- |
|
30 // |
|
31 CNSmlResponseController::CNSmlResponseController() |
|
32 { |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------- |
|
36 // CNSmlResponseController::ConstructL() |
|
37 // Two-way construction. Constructor may leave in EPOC. |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 void CNSmlResponseController::ConstructL() |
|
41 { |
|
42 iResponse = new ( ELeave ) CArrayFixFlat<TResponseData>(1); |
|
43 iEntryID = 0; |
|
44 } |
|
45 // --------------------------------------------------------- |
|
46 // CNSmlResponseController::~CNSmlResponseController() |
|
47 // |
|
48 // --------------------------------------------------------- |
|
49 CNSmlResponseController::~CNSmlResponseController() |
|
50 { |
|
51 if ( iResponse ) |
|
52 { |
|
53 for ( TInt i = 0; i < iResponse->Count(); i++) |
|
54 { |
|
55 FreeResources( i ); |
|
56 } |
|
57 delete iResponse; |
|
58 } |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CNSmlResponseController::NewL() |
|
63 // Creates new instance of CNSmlResponseController. |
|
64 // Does not leave instance pointer to CleanupStack. |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 CNSmlResponseController* CNSmlResponseController::NewL() |
|
68 { |
|
69 CNSmlResponseController* self = CNSmlResponseController::NewLC(); |
|
70 CleanupStack::Pop(); |
|
71 return( self ); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CNSmlResponseController::NewLC() |
|
76 // Creates new instance of CNSmlResponseController |
|
77 // Leaves instance pointer to CleanupStack. |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 CNSmlResponseController* CNSmlResponseController::NewLC() |
|
81 { |
|
82 CNSmlResponseController* self = new (ELeave) CNSmlResponseController(); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 return( self ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CNSmlResponseController::CreateNewResponseItemL() |
|
90 // Creates new response item to the array |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 TInt CNSmlResponseController::CreateNewResponseItemL() |
|
94 { |
|
95 TResponseData responseData; |
|
96 responseData.responseMsgID = 0; |
|
97 responseData.responseCmd = NULL; |
|
98 responseData.responseCmdID = 0; |
|
99 responseData.responseLUID = NULL; |
|
100 responseData.responseAppIndex = -1; |
|
101 responseData.responseStatusCode = 0; |
|
102 responseData.responseStatusReceived = EFalse; |
|
103 responseData.responseChal = NULL; |
|
104 responseData.responseDetail = EResponseNoDetail; |
|
105 responseData.responseMoreData = EFalse; |
|
106 iResponse->AppendL( responseData ); |
|
107 return iResponse->Count(); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // CNSmlResponseController::RemoveResponseItem |
|
112 // Removes Response item |
|
113 // --------------------------------------------------------- |
|
114 void CNSmlResponseController::RemoveResponseItem( TInt aMsgID, TInt aCmdID ) |
|
115 { |
|
116 for ( TInt i = 0; i < iResponse->Count(); i++) |
|
117 { |
|
118 if ( (*iResponse)[i].responseMsgID == aMsgID && |
|
119 (*iResponse)[i].responseCmdID == aCmdID ) |
|
120 { |
|
121 FreeResources( i ); |
|
122 iResponse->Delete( i ); |
|
123 break; |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CNSmlResponseController::SetMsgID() |
|
130 // Sets Message ID |
|
131 // --------------------------------------------------------- |
|
132 void CNSmlResponseController::SetMsgID( TInt aEntryID, TInt aMsgID ) |
|
133 { |
|
134 (*iResponse)[aEntryID-1].responseMsgID = aMsgID; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------- |
|
138 // CNSmlResponseController::SetCmdL() |
|
139 // Sets SyncML command |
|
140 // --------------------------------------------------------- |
|
141 void CNSmlResponseController::SetCmdL( TInt aEntryID, const TDesC8& aCmd ) |
|
142 { |
|
143 (*iResponse)[aEntryID-1].responseCmd = HBufC8::NewL( aCmd.Length() ); |
|
144 *(*iResponse)[aEntryID-1].responseCmd = aCmd; |
|
145 } |
|
146 // --------------------------------------------------------- |
|
147 // CNSmlResponseController::SetCmdID() |
|
148 // Sets Command ID |
|
149 // --------------------------------------------------------- |
|
150 void CNSmlResponseController::SetCmdID( TInt aEntryID, TInt aCmdID ) |
|
151 { |
|
152 (*iResponse)[aEntryID-1].responseCmdID = aCmdID; |
|
153 } |
|
154 // --------------------------------------------------------- |
|
155 // CNSmlResponseController::SetLUIDL() |
|
156 // Sets LUID |
|
157 // --------------------------------------------------------- |
|
158 EXPORT_C void CNSmlResponseController::SetLUIDL( TInt aEntryID, const TDesC8& aLUID ) |
|
159 { |
|
160 (*iResponse)[aEntryID-1].responseLUID = HBufC8::NewL( aLUID.Length() ); |
|
161 *(*iResponse)[aEntryID-1].responseLUID = aLUID; |
|
162 } |
|
163 // --------------------------------------------------------- |
|
164 // CNSmlResponseController::SetAppIndex() |
|
165 // Set Index of application in Sync |
|
166 // --------------------------------------------------------- |
|
167 EXPORT_C void CNSmlResponseController::SetAppIndex( TInt aEntryID, TInt aAppIndex ) |
|
168 { |
|
169 (*iResponse)[aEntryID-1].responseAppIndex = aAppIndex; |
|
170 } |
|
171 // --------------------------------------------------------- |
|
172 // CNSmlResponseController::SetChalTypeL() |
|
173 // Sets Challenge Type |
|
174 // --------------------------------------------------------- |
|
175 void CNSmlResponseController::SetChalTypeL( TInt aEntryID, const TDesC8& aType ) |
|
176 { |
|
177 if ( !(*iResponse)[aEntryID-1].responseChal ) |
|
178 { |
|
179 CreateResponseChalL( aEntryID-1 ); |
|
180 } |
|
181 if ( (*iResponse)[aEntryID-1].responseChal->chalType ) |
|
182 { |
|
183 delete (*iResponse)[aEntryID-1].responseChal->chalType; |
|
184 (*iResponse)[aEntryID-1].responseChal->chalType = NULL; |
|
185 } |
|
186 (*iResponse)[aEntryID-1].responseChal->chalType = HBufC8::NewL( aType.Length() ); |
|
187 *(*iResponse)[aEntryID-1].responseChal->chalType = aType; |
|
188 } |
|
189 // --------------------------------------------------------- |
|
190 // CNSmlResponseController::SetChalFormatL() |
|
191 // Sets Challenge Format |
|
192 // --------------------------------------------------------- |
|
193 void CNSmlResponseController::SetChalFormatL( TInt aEntryID, const TDesC8& aFormat ) |
|
194 { |
|
195 if ( !(*iResponse)[aEntryID-1].responseChal ) |
|
196 { |
|
197 CreateResponseChalL( aEntryID-1 ); |
|
198 } |
|
199 if ( (*iResponse)[aEntryID-1].responseChal->chalFormat ) |
|
200 { |
|
201 delete (*iResponse)[aEntryID-1].responseChal->chalFormat; |
|
202 (*iResponse)[aEntryID-1].responseChal->chalFormat = NULL; |
|
203 } |
|
204 (*iResponse)[aEntryID-1].responseChal->chalFormat = HBufC8::NewL( aFormat.Length() ); |
|
205 *(*iResponse)[aEntryID-1].responseChal->chalFormat = aFormat; |
|
206 } |
|
207 // --------------------------------------------------------- |
|
208 // CNSmlResponseController::SetChalNextNonceL() |
|
209 // Sets Challenge Format |
|
210 // --------------------------------------------------------- |
|
211 void CNSmlResponseController::SetChalNextNonceL( TInt aEntryID, const TDesC8& aNextNonce ) |
|
212 { |
|
213 if ( !(*iResponse)[aEntryID-1].responseChal ) |
|
214 { |
|
215 CreateResponseChalL( aEntryID-1 ); |
|
216 } |
|
217 if ( (*iResponse)[aEntryID-1].responseChal->chalNextNonce ) |
|
218 { |
|
219 delete (*iResponse)[aEntryID-1].responseChal->chalNextNonce; |
|
220 (*iResponse)[aEntryID-1].responseChal->chalNextNonce = NULL; |
|
221 } |
|
222 (*iResponse)[aEntryID-1].responseChal->chalNextNonce = HBufC8::NewL( aNextNonce.Length() ); |
|
223 *(*iResponse)[aEntryID-1].responseChal->chalNextNonce = aNextNonce; |
|
224 } |
|
225 // --------------------------------------------------------- |
|
226 // CNSmlResponseController::SetResponseDetail() |
|
227 // |
|
228 // --------------------------------------------------------- |
|
229 EXPORT_C void CNSmlResponseController::SetResponseDetail( TInt aEntryID, TResponseDetail aResponseDetail ) |
|
230 { |
|
231 (*iResponse)[aEntryID-1].responseDetail= aResponseDetail; |
|
232 } |
|
233 // --------------------------------------------------------- |
|
234 // CNSmlResponseController::SetMoreData() |
|
235 // |
|
236 // --------------------------------------------------------- |
|
237 EXPORT_C void CNSmlResponseController::SetMoreData( TInt aEntryID ) |
|
238 { |
|
239 (*iResponse)[aEntryID-1].responseMoreData = ETrue; |
|
240 } |
|
241 // --------------------------------------------------------- |
|
242 // CNSmlResponseController::RemoveAllReceivedOnes() |
|
243 // All items which Status is received are deleted |
|
244 // --------------------------------------------------------- |
|
245 void CNSmlResponseController::RemoveAllReceivedOnes() |
|
246 { |
|
247 for ( TInt i = iResponse->Count() - 1; i >= 0; i--) |
|
248 { |
|
249 if ( (*iResponse)[i].responseStatusReceived ) |
|
250 { |
|
251 FreeResources( i ); |
|
252 iResponse->Delete( i ); |
|
253 } |
|
254 } |
|
255 iResponse->Compress(); |
|
256 iEntryID = 0; |
|
257 } |
|
258 // --------------------------------------------------------- |
|
259 // CNSmlResponseController::ResetL() |
|
260 // |
|
261 // --------------------------------------------------------- |
|
262 EXPORT_C void CNSmlResponseController::ResetL() |
|
263 { |
|
264 for ( TInt i = 0; i < iResponse->Count(); i++) |
|
265 { |
|
266 FreeResources( i ); |
|
267 } |
|
268 delete iResponse; |
|
269 iResponse = NULL; |
|
270 ConstructL(); |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // CNSmlResponseController::MatchStatusElement |
|
275 // Searches matching Response data and updates status code and status-received flag |
|
276 // --------------------------------------------------------- |
|
277 TBool CNSmlResponseController::MatchStatusElement( const TDesC8& aMsgID, const TDesC8& aCmdID, TInt aStatusCode, TInt& aEntryID ) |
|
278 { |
|
279 TLex8 lexicalStatusMsgID( aMsgID ); |
|
280 TInt numericMsgID; |
|
281 if ( lexicalStatusMsgID.Val (numericMsgID ) != KErrNone ) |
|
282 { |
|
283 return EFalse; |
|
284 } |
|
285 TLex8 lexicalStatusCmdID( aCmdID ); |
|
286 TInt numericCmdID; |
|
287 if ( lexicalStatusCmdID.Val (numericCmdID ) != KErrNone ) |
|
288 { |
|
289 return EFalse; |
|
290 } |
|
291 for ( TInt i = 0; i < iResponse->Count(); i++) |
|
292 { |
|
293 if ( numericMsgID == (*iResponse)[i].responseMsgID && numericCmdID == (*iResponse)[i].responseCmdID ) |
|
294 { |
|
295 (*iResponse)[i].responseStatusReceived = ETrue; |
|
296 (*iResponse)[i].responseStatusCode = aStatusCode; |
|
297 aEntryID = ++i; |
|
298 return ETrue; |
|
299 } |
|
300 } |
|
301 return EFalse; |
|
302 } |
|
303 // --------------------------------------------------------- |
|
304 // CNSmlResponseController::Begin() |
|
305 // |
|
306 // --------------------------------------------------------- |
|
307 void CNSmlResponseController::Begin() |
|
308 { |
|
309 iEntryID = 0; |
|
310 } |
|
311 // --------------------------------------------------------- |
|
312 // CNSmlResponseController::NextResponseInfo() |
|
313 // Gives entry ID for the next response info item |
|
314 // --------------------------------------------------------- |
|
315 TBool CNSmlResponseController::NextResponseInfo( TInt& aEntryID ) |
|
316 { |
|
317 if ( iResponse->Count() <= iEntryID ) |
|
318 { |
|
319 return EFalse; |
|
320 } |
|
321 iEntryID++; |
|
322 aEntryID = iEntryID; |
|
323 return ETrue; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // CNSmlResponseController::ItemResponseInfo() |
|
328 // Gives entry ID for the response info of the item |
|
329 // --------------------------------------------------------- |
|
330 TBool CNSmlResponseController::ItemResponseInfo( const TDesC8& aLUID, TInt& aEntryID ) const |
|
331 { |
|
332 TBool itemFound = EFalse; |
|
333 for ( TInt i = 0; i < iResponse->Count(); i++) |
|
334 { |
|
335 if ( (*iResponse)[i].responseLUID ) |
|
336 { |
|
337 if ( *(*iResponse)[i].responseLUID == aLUID ) |
|
338 { |
|
339 itemFound = ETrue; |
|
340 aEntryID = ++i; |
|
341 break; |
|
342 } |
|
343 } |
|
344 } |
|
345 return itemFound; |
|
346 } |
|
347 // --------------------------------------------------------- |
|
348 // CNSmlResponseController::Cmd() |
|
349 // Gives name of the SyncML command |
|
350 // --------------------------------------------------------- |
|
351 EXPORT_C TDesC8& CNSmlResponseController::Cmd( TInt aEntryID ) const |
|
352 { |
|
353 return *(*iResponse)[aEntryID-1].responseCmd; |
|
354 } |
|
355 // --------------------------------------------------------- |
|
356 // CNSmlResponseController::LUID() |
|
357 // Gives name of the SyncML command |
|
358 // --------------------------------------------------------- |
|
359 EXPORT_C TPtrC8 CNSmlResponseController::LUID( TInt aEntryID ) const |
|
360 { |
|
361 TPtrC8 empty; |
|
362 if ( (*iResponse)[aEntryID-1].responseLUID ) |
|
363 { |
|
364 return *(*iResponse)[aEntryID-1].responseLUID; |
|
365 } |
|
366 else |
|
367 { |
|
368 return empty; |
|
369 } |
|
370 } |
|
371 // --------------------------------------------------------- |
|
372 // CNSmlResponseController::ChalType() |
|
373 // Gives name of the authentication type |
|
374 // --------------------------------------------------------- |
|
375 EXPORT_C TPtrC8 CNSmlResponseController::ChalType( TInt aEntryID ) const |
|
376 { |
|
377 TPtrC8 type; |
|
378 if ( (*iResponse)[aEntryID-1].responseChal ) |
|
379 { |
|
380 if ( (*iResponse)[aEntryID-1].responseChal->chalType ) |
|
381 { |
|
382 type.Set( *(*iResponse)[aEntryID-1].responseChal->chalType ); |
|
383 } |
|
384 } |
|
385 return type; |
|
386 } |
|
387 // --------------------------------------------------------- |
|
388 // CNSmlResponseController::ChalFormat() |
|
389 // Gives Format of NextNonce |
|
390 // --------------------------------------------------------- |
|
391 TPtrC8 CNSmlResponseController::ChalFormat( TInt aEntryID ) const |
|
392 { |
|
393 TPtrC8 format; |
|
394 if ( (*iResponse)[aEntryID-1].responseChal ) |
|
395 { |
|
396 if ( (*iResponse)[aEntryID-1].responseChal->chalFormat ) |
|
397 { |
|
398 format.Set( *(*iResponse)[aEntryID-1].responseChal->chalFormat ); |
|
399 } |
|
400 } |
|
401 return format; |
|
402 } |
|
403 // --------------------------------------------------------- |
|
404 // CNSmlResponseController::ChalNextNonce() |
|
405 // Gives NextNonce |
|
406 // --------------------------------------------------------- |
|
407 TPtrC8 CNSmlResponseController::ChalNextNonce( TInt aEntryID ) const |
|
408 { |
|
409 TPtrC8 nextNonce; |
|
410 if ( (*iResponse)[aEntryID-1].responseChal ) |
|
411 { |
|
412 if ( (*iResponse)[aEntryID-1].responseChal->chalNextNonce ) |
|
413 { |
|
414 nextNonce.Set( *(*iResponse)[aEntryID-1].responseChal->chalNextNonce ); |
|
415 } |
|
416 } |
|
417 return nextNonce; |
|
418 } |
|
419 // --------------------------------------------------------- |
|
420 // CNSmlResponseController::ResponseDetail |
|
421 // |
|
422 // --------------------------------------------------------- |
|
423 EXPORT_C CNSmlResponseController::TResponseDetail CNSmlResponseController::ResponseDetail( TInt aEntryID ) const |
|
424 { |
|
425 return (*iResponse)[aEntryID-1].responseDetail; |
|
426 } |
|
427 // --------------------------------------------------------- |
|
428 // CNSmlResponseController::BusyStatus() |
|
429 // Returns True if 101 statuscode in SyncHdr in given message |
|
430 // --------------------------------------------------------- |
|
431 TBool CNSmlResponseController::BusyStatus( TInt aMsgID ) const |
|
432 { |
|
433 TBool busyStatus = EFalse; |
|
434 for ( TInt i = 0; i < iResponse->Count(); i++) |
|
435 { |
|
436 if ( ( (*iResponse)[i].responseMsgID == aMsgID ) && ( (*iResponse)[i].responseCmd ) ) |
|
437 { |
|
438 if ( *(*iResponse)[i].responseCmd == KNSmlAgentSyncHdr ) |
|
439 { |
|
440 if ( (*iResponse)[i].responseStatusCode == 101 ) |
|
441 { |
|
442 busyStatus = ETrue; |
|
443 } |
|
444 break; |
|
445 } |
|
446 } |
|
447 } |
|
448 return busyStatus; |
|
449 } |
|
450 |
|
451 // --------------------------------------------------------- |
|
452 // CNSmlResponseController::MoreData() |
|
453 // |
|
454 // --------------------------------------------------------- |
|
455 EXPORT_C TBool CNSmlResponseController::MoreData( TInt aEntryID ) const |
|
456 { |
|
457 return (*iResponse)[aEntryID-1].responseMoreData; |
|
458 } |
|
459 // --------------------------------------------------------- |
|
460 // CNSmlResponseController::AppIndex() |
|
461 // Gives index of the application |
|
462 // --------------------------------------------------------- |
|
463 EXPORT_C TInt CNSmlResponseController::AppIndex( TInt aEntryID ) const |
|
464 { |
|
465 return (*iResponse)[aEntryID-1].responseAppIndex; |
|
466 } |
|
467 // --------------------------------------------------------- |
|
468 // CNSmlResponseController::StatusCode() |
|
469 // Gives status code |
|
470 // --------------------------------------------------------- |
|
471 EXPORT_C TInt CNSmlResponseController::StatusCode( TInt aEntryID ) const |
|
472 { |
|
473 return (*iResponse)[aEntryID-1].responseStatusCode; |
|
474 } |
|
475 |
|
476 // --------------------------------------------------------- |
|
477 // CNSmlResponseController::EntryID() |
|
478 // Returns EntryID by Cmd ID and Msg ID |
|
479 // --------------------------------------------------------- |
|
480 EXPORT_C TInt CNSmlResponseController::EntryID( TInt aCmdID, TInt aMsgID) const |
|
481 { |
|
482 TInt count = iResponse->Count(); |
|
483 for( TInt i = 0; i < count; i++ ) |
|
484 { |
|
485 // aCmdID and aMsgID have been retrieved from the received |
|
486 // status command for deletion. |
|
487 if( iResponse->At( i ).responseCmdID == aCmdID && |
|
488 iResponse->At( i ).responseMsgID == aMsgID ) |
|
489 { |
|
490 // Entry ID of the current item. |
|
491 return i+1; |
|
492 } |
|
493 } |
|
494 // Entry ID not found |
|
495 return 0; |
|
496 } |
|
497 |
|
498 // --------------------------------------------------------- |
|
499 // CNSmlResponseController::StatusReceived() |
|
500 // Returns True, if the has returned Status for the command |
|
501 // --------------------------------------------------------- |
|
502 TBool CNSmlResponseController::StatusReceived( TInt aEntryID ) const |
|
503 { |
|
504 return (*iResponse)[aEntryID-1].responseStatusReceived; |
|
505 } |
|
506 // --------------------------------------------------------- |
|
507 // CNSmlResponseController::CreateResponseChalL |
|
508 // Creates and initiates responseChal structure |
|
509 // --------------------------------------------------------- |
|
510 void CNSmlResponseController::CreateResponseChalL( TInt aIndex) |
|
511 { |
|
512 (*iResponse)[aIndex].responseChal = new( ELeave ) TChal; |
|
513 (*iResponse)[aIndex].responseChal->chalType = NULL; |
|
514 (*iResponse)[aIndex].responseChal->chalFormat = NULL; |
|
515 (*iResponse)[aIndex].responseChal->chalNextNonce = NULL; |
|
516 } |
|
517 // --------------------------------------------------------- |
|
518 // CNSmlResponseController::FreeResources |
|
519 // Frees resources of an item |
|
520 // --------------------------------------------------------- |
|
521 void CNSmlResponseController::FreeResources( TInt aI ) |
|
522 { |
|
523 delete ( (*iResponse)[aI].responseCmd ); |
|
524 delete ( (*iResponse)[aI].responseLUID ); |
|
525 if ( (*iResponse)[aI].responseChal ) |
|
526 { |
|
527 delete (*iResponse)[aI].responseChal->chalType; |
|
528 delete (*iResponse)[aI].responseChal->chalFormat; |
|
529 delete (*iResponse)[aI].responseChal->chalNextNonce; |
|
530 delete (*iResponse)[aI].responseChal; |
|
531 } |
|
532 } |