|
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: SyncML DM command handling |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 // |
|
22 #include <f32file.h> |
|
23 #include <utf.h> |
|
24 // FOTA |
|
25 #include <DevManInternalCRKeys.h> |
|
26 #include <featmgr.h> |
|
27 // FOTA end |
|
28 #include <SyncMLNotifierParams.h> |
|
29 |
|
30 #include <nsmlconstants.h> |
|
31 #include <nsmldebug.h> |
|
32 #include <nsmlphoneinfo.h> |
|
33 #include <nsmlunicodeconverter.h> |
|
34 // DM specific includes |
|
35 #include <nsmldmconst.h> |
|
36 #include <nsmldmmodule.h> |
|
37 //For P&S keys |
|
38 #include <e32property.h> |
|
39 #include <e32math.h> |
|
40 #include "nsmldminternalpskeys.h" |
|
41 // common includes with DS |
|
42 #include "nsmlcliagconstants.h" |
|
43 #include "NSmlCmdsBase.h" |
|
44 #include "NSmlAgentBase.h" |
|
45 #include "NSmlStatusContainer.h" |
|
46 #include "NSmlResponseController.h" |
|
47 #include "NSmlResultsContainer.h" |
|
48 #include "NSmlAuth.h" |
|
49 #include "NSmlURI.h" |
|
50 #include "WBXMLSyncMLGenerator.h" |
|
51 #include "WBXMLSyncMLParser.h" |
|
52 #include "WBXMLGeneratorError.h" |
|
53 #include "WBXMLParser.h" |
|
54 #include "smldtd.h" |
|
55 #include "smldef.h" |
|
56 #include "nsmlagenttestdefines.h" |
|
57 // DM specific includes |
|
58 #include "nsmldmagconstants.h" |
|
59 #include "NSmlDMCmds.h" |
|
60 #include "nsmldmerror.h" |
|
61 #ifdef __TEST_TREEMODULE |
|
62 #include "nsmldmtestmodule.h" |
|
63 #else |
|
64 #include <nsmldmmodule.h> |
|
65 #endif |
|
66 |
|
67 |
|
68 #ifndef __WINS__ |
|
69 // This lowers the unnecessary compiler warning (armv5) to remark. |
|
70 // "Warning: #174-D: expression has no effect..." is caused by |
|
71 // DBG_ARGS8 macro in no-debug builds. |
|
72 #pragma diag_remark 174 |
|
73 #endif |
|
74 |
|
75 |
|
76 const TUid KNSmlSyncDialogUid = { 0x101F876A }; |
|
77 // FOTA |
|
78 const TInt KNSmlDmNoRequest = -1; |
|
79 // FOTA end |
|
80 const TInt KNSmlDmChoiceChunkMinSize = 32; |
|
81 const TInt KNSmlDmChoiceChunkMaxSize = 10000; |
|
82 |
|
83 _LIT8 ( KNSmlDMMetaTypeUserRequest, "org.openmobilealliance.dm.firmwareupdate.userrequest" ); |
|
84 _LIT8 ( KNSmlDMMetaFormatUserRequest, "chr" ); |
|
85 _LIT(KChunkName,"AlertItems"); |
|
86 |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CNSmlDMCmds::NewL() |
|
90 // Creates new instance of CNSmlDMCmds |
|
91 // Does not leave instance pointer to CleanupStack. |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 CNSmlDMCmds* CNSmlDMCmds::NewL( CNSmlAgentBase* aAgent, const TDesC8& aSessionID, const TDesC8& aVerProto, const HBufC& aSyncMLUserName, CNSmlURI* aSyncServer, const TDesC& aDMServerId, MSyncMLProgressObserver* aDMObserver ) |
|
95 { |
|
96 CNSmlDMCmds* self = new (ELeave) CNSmlDMCmds(); |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( aAgent, aSessionID, aVerProto, aSyncMLUserName, aSyncServer, aDMServerId, aDMObserver ); |
|
99 CleanupStack::Pop(); //self |
|
100 return self; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CNSmlDMCmds::~CNSmlDMCmds() |
|
105 // Destructor |
|
106 // --------------------------------------------------------- |
|
107 // |
|
108 CNSmlDMCmds::~CNSmlDMCmds() |
|
109 { |
|
110 delete iDMServerId; |
|
111 delete iDMModule; |
|
112 if ( iDMDevInfo ) |
|
113 { |
|
114 delete iDMDevInfo->iFormat; |
|
115 delete iDMDevInfo->iType; |
|
116 delete iDMDevInfo->iObject; |
|
117 delete iDMDevInfo; |
|
118 } |
|
119 delete iLargeObjectUri; |
|
120 |
|
121 if(iChunk.Handle()) |
|
122 { |
|
123 iChunk.Close(); |
|
124 } |
|
125 // FOTA |
|
126 // uninitialize feature manager |
|
127 FeatureManager::UnInitializeLib(); |
|
128 delete iRepository; |
|
129 |
|
130 //P&S key deletion,even fine if the key is not there |
|
131 RProperty::Delete( KPSUidNSmlDMSyncAgent,KNSmlDMCmdAddOnExistingNodeorLeafKey); |
|
132 // FOTA end |
|
133 } |
|
134 |
|
135 |
|
136 // --------------------------------------------------------- |
|
137 // CNSmlDMCmds::CNSmlDMCmds() |
|
138 // Constructor |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 CNSmlDMCmds::CNSmlDMCmds() |
|
142 { |
|
143 } |
|
144 // --------------------------------------------------------- |
|
145 // CNSmlDMCmds::ConstructL() |
|
146 // |
|
147 // --------------------------------------------------------- |
|
148 void CNSmlDMCmds::ConstructL( CNSmlAgentBase* aAgent, const TDesC8& aSessionID, const TDesC8& aVerProto, const HBufC& aSyncMLUserName, CNSmlURI* aSyncServer, const TDesC& aDMServerId, MSyncMLProgressObserver* aDMObserver ) |
|
149 { |
|
150 if(!FeatureManager::FeatureSupported( KFeatureIdSyncMlDm112 )) |
|
151 { |
|
152 CNSmlCmdsBase::ConstructL( aAgent, aSessionID, aVerProto,KNSmlSyncMLPublicId12 , aSyncMLUserName, aSyncServer, EFalse ); |
|
153 } |
|
154 else |
|
155 { |
|
156 CNSmlCmdsBase::ConstructL( aAgent, aSessionID, aVerProto,KNSmlSyncMLPublicId , aSyncMLUserName, aSyncServer, EFalse ); |
|
157 } |
|
158 iDMServerId = aDMServerId.AllocL(); |
|
159 iDMObserver = aDMObserver; |
|
160 #ifdef __TEST_TREEMODULE |
|
161 iDMModule = CNSmlDmTestModule::NewL( this ); |
|
162 #else |
|
163 iDMModule = CNSmlDmModule::NewL( this ); |
|
164 #endif |
|
165 HBufC8* serverId = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aDMServerId); |
|
166 CleanupStack::PushL(serverId); |
|
167 iDMModule->SetServerL( *serverId ); |
|
168 CleanupStack::PopAndDestroy(); //serverId |
|
169 |
|
170 // FOTA |
|
171 // init feature manager |
|
172 FeatureManager::InitializeLibL(); |
|
173 if ( FeatureManager::FeatureSupported ( KFeatureIdSyncMlDmFota ) ) |
|
174 { |
|
175 TRAPD ( error, iRepository = CRepository::NewL ( KCRUidDeviceManagementInternalKeys ) ); |
|
176 if ( error != KErrNone ) |
|
177 { |
|
178 iRepository = NULL; |
|
179 } |
|
180 } |
|
181 // FOTA end |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CNSmlDMCmds::DoDevInfoItemsL() |
|
186 // Function which is called recursive when writing DevInfo items |
|
187 // --------------------------------------------------------- |
|
188 void CNSmlDMCmds::DoDevInfoItemsL( const TDesC8& aURI ) |
|
189 { |
|
190 iDMModule->FetchObjectL( aURI, KNullDesC8, 0, 0, ETrue ); |
|
191 if ( !iDMDevInfo->iResults ) |
|
192 { |
|
193 return; |
|
194 } |
|
195 iDMDevInfo->iResults = EFalse; |
|
196 if ( *iDMDevInfo->iFormat == _L8("node") ) |
|
197 { |
|
198 HBufC8* childList = iDMDevInfo->iObject->AllocLC(); |
|
199 TPtrC8 childListPtr( *childList ); |
|
200 TInt pos = 0; |
|
201 TBool moreData = ETrue; |
|
202 do |
|
203 { |
|
204 pos = childListPtr.Locate('/'); |
|
205 if ( pos == KErrNotFound ) |
|
206 { |
|
207 moreData = EFalse; |
|
208 pos = childListPtr.Length(); |
|
209 } |
|
210 User::LeaveIfError( pos ); |
|
211 HBufC8* childURI = HBufC8::NewLC( aURI.Length() + 1 + pos ); |
|
212 *childURI = aURI; |
|
213 TPtr8 childURIPtr = childURI->Des(); |
|
214 childURIPtr += _L8("/"); |
|
215 HBufC8* segment = HBufC8::NewLC( pos ); |
|
216 segment->Des().Copy( childListPtr.Left( pos ) ); |
|
217 childURIPtr += *segment; |
|
218 DoDevInfoItemsL( *childURI ); |
|
219 if ( moreData ) |
|
220 { |
|
221 childListPtr.Set( childListPtr.Right( childListPtr.Length() - ( segment->Length() +1 ) )); |
|
222 } |
|
223 CleanupStack::PopAndDestroy( 2 ); // segment, childURI |
|
224 } while ( moreData ); |
|
225 CleanupStack::PopAndDestroy(); // childList |
|
226 } |
|
227 else |
|
228 { |
|
229 if ( iDMDevInfo->iFirst ) |
|
230 { |
|
231 iDMDevInfo->iFirst = EFalse; |
|
232 } |
|
233 else |
|
234 { |
|
235 (*iDMDevInfo->iItemListPtr)->next = new( ELeave ) SmlItemList_t; |
|
236 iDMDevInfo->iItemListPtr = &(*iDMDevInfo->iItemListPtr)->next; |
|
237 (*iDMDevInfo->iItemListPtr)->item = new( ELeave ) SmlItem_t; |
|
238 } |
|
239 DoSourceL( (*iDMDevInfo->iItemListPtr)->item->source, aURI ); |
|
240 SmlMetInfMetInf_t* metInf; |
|
241 DoMetInfLC( metInf ); |
|
242 PcdataNewL( metInf->format, *iDMDevInfo->iFormat ); |
|
243 PcdataNewL( metInf->type, _L8("text/plain") ); |
|
244 DoMetaL( (*iDMDevInfo->iItemListPtr)->item->meta, metInf ); |
|
245 CleanupStack::Pop(); //metInf , only Pop because ownership has been changed |
|
246 PcdataNewL( (*iDMDevInfo->iItemListPtr)->item->data, *iDMDevInfo->iObject ); |
|
247 } |
|
248 } |
|
249 // --------------------------------------------------------- |
|
250 // CNSmlDMCmds::FreeDMDevinfo() |
|
251 // |
|
252 // --------------------------------------------------------- |
|
253 void CNSmlDMCmds::FreeDMDevinfo() |
|
254 { |
|
255 if ( iDMDevInfo ) |
|
256 { |
|
257 delete iDMDevInfo->iFormat; |
|
258 delete iDMDevInfo->iType; |
|
259 delete iDMDevInfo->iObject; |
|
260 delete iDMDevInfo; |
|
261 iDMDevInfo = NULL; |
|
262 } |
|
263 } |
|
264 // --------------------------------------------------------- |
|
265 // CNSmlDMCmds::AlertParameter() |
|
266 // |
|
267 // --------------------------------------------------------- |
|
268 TInt CNSmlDMCmds::AlertParameter( const SmlPcdata_t* aData, const TDesC8& aParamID ) const |
|
269 { |
|
270 TInt valueNum = 0; |
|
271 if ( aData ) |
|
272 { |
|
273 if ( aData->content ) |
|
274 { |
|
275 TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length ); |
|
276 TrimRightSpaceAndNull( parameters ); |
|
277 TInt startPos = parameters.Find( aParamID ); |
|
278 if ( startPos >= 0 ) |
|
279 { |
|
280 if ( parameters.Length() > startPos + aParamID.Length() ) |
|
281 { |
|
282 TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) ); |
|
283 TInt length = 0; |
|
284 while ( length < strPart.Length() ) |
|
285 { |
|
286 TChar character = strPart[length]; |
|
287 if ( character.IsDigit() ) |
|
288 { |
|
289 ++length; |
|
290 } |
|
291 else |
|
292 { |
|
293 break; |
|
294 } |
|
295 } |
|
296 TPtrC8 valueStr = strPart.Left( length ); |
|
297 TLex8 lexicalValue( valueStr ); |
|
298 if ( lexicalValue.Val( valueNum ) != KErrNone ) |
|
299 { |
|
300 valueNum = 0; |
|
301 } |
|
302 } |
|
303 } |
|
304 } |
|
305 } |
|
306 return valueNum; |
|
307 } |
|
308 |
|
309 //#ifdef RD_DM_TEXT_INPUT_ALERT |
|
310 // --------------------------------------------------------- |
|
311 // CNSmlDMCmds::AlertInputTypeParameter() |
|
312 // For 1102-User Input server alert |
|
313 // For Input Type optional parameter |
|
314 // --------------------------------------------------------- |
|
315 TInt CNSmlDMCmds::AlertInputTypeParameter( const SmlPcdata_t* aData, const TDesC8& aParamID ) const |
|
316 { |
|
317 _DBG_FILE("CNSmlDMCmds::AlertInputTypeParameter: begin"); |
|
318 TInt valueNum = 0;//alphanumeric by default |
|
319 if ( aData ) |
|
320 { |
|
321 if ( aData->content ) |
|
322 { |
|
323 TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length ); |
|
324 TrimRightSpaceAndNull( parameters ); |
|
325 TInt startPos = parameters.Find( aParamID ); |
|
326 if ( startPos >= 0 ) |
|
327 { |
|
328 if ( parameters.Length() > startPos + aParamID.Length() ) |
|
329 { |
|
330 TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) ); |
|
331 TInt length = 0; |
|
332 TChar character = strPart[length]; |
|
333 |
|
334 switch( character ) |
|
335 { |
|
336 case 'A': //Alphanumeric |
|
337 valueNum = ESyncMLInputTypeAlphaNumeric; |
|
338 break; |
|
339 case 'N': //Numeric |
|
340 valueNum = ESyncMLInputTypeNumeric; |
|
341 break; |
|
342 case 'D': //Date |
|
343 valueNum = ESyncMLInputTypeDate; |
|
344 break; |
|
345 case 'T': //Time |
|
346 valueNum = ESyncMLInputTypeTime; |
|
347 break; |
|
348 case 'P': //Phone number |
|
349 valueNum = ESyncMLInputTypePhoneNumber; |
|
350 break; |
|
351 case 'I': //Ip address |
|
352 valueNum = ESyncMLInputTypeIPAddress; |
|
353 break; |
|
354 } |
|
355 } |
|
356 } |
|
357 } |
|
358 } |
|
359 _DBG_FILE("CNSmlDMCmds::AlertInputTypeParameter: end"); |
|
360 return valueNum; |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------- |
|
364 // CNSmlDMCmds::AlertEchoTypeParameter() |
|
365 // For 1102-User Input server alert |
|
366 // For Echo Type optional parameter |
|
367 // --------------------------------------------------------- |
|
368 TInt CNSmlDMCmds::AlertEchoTypeParameter( const SmlPcdata_t* aData, const TDesC8& aParamID ) const |
|
369 { |
|
370 _DBG_FILE("CNSmlDMCmds::AlertEchoTypeParameter: begin"); |
|
371 TInt valueNum = 0;//Text by default |
|
372 if ( aData ) |
|
373 { |
|
374 if ( aData->content ) |
|
375 { |
|
376 TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length ); |
|
377 TrimRightSpaceAndNull( parameters ); |
|
378 TInt startPos = parameters.Find( aParamID ); |
|
379 if ( startPos >= 0 ) |
|
380 { |
|
381 if ( parameters.Length() > startPos + aParamID.Length() ) |
|
382 { |
|
383 TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) ); |
|
384 TInt length = 0; |
|
385 TChar character = strPart[length]; |
|
386 switch( character ) |
|
387 { |
|
388 |
|
389 case 'T': valueNum = ESyncMLEchoTypeText; |
|
390 break; |
|
391 case 'P': valueNum = ESyncMLEchoTypePassword; |
|
392 break; |
|
393 default: |
|
394 break; |
|
395 } |
|
396 } |
|
397 } |
|
398 } |
|
399 } |
|
400 _DBG_FILE("CNSmlDMCmds::AlertEchoTypeParameter: end"); |
|
401 return valueNum; |
|
402 } |
|
403 // --------------------------------------------------------- |
|
404 // CNSmlDMCmds::CheckDRPresence() |
|
405 // For 1102-User Input server alert |
|
406 // For Default Response item existence verification |
|
407 // --------------------------------------------------------- |
|
408 TBool CNSmlDMCmds::CheckDRPresence( const SmlPcdata_t* aData, const TDesC8& aParamID ) const |
|
409 { |
|
410 if ( aData ) |
|
411 { |
|
412 if ( aData->content ) |
|
413 { |
|
414 TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length ); |
|
415 TrimRightSpaceAndNull( parameters ); |
|
416 TInt startPos = parameters.Find( aParamID ); |
|
417 if ( startPos >= 0 ) |
|
418 { |
|
419 return ETrue; |
|
420 } |
|
421 } |
|
422 } |
|
423 return EFalse; |
|
424 } |
|
425 |
|
426 // --------------------------------------------------------- |
|
427 // CNSmlDMCmds::AlertDefaultResponseParam() |
|
428 // For 1102-User Input server alert |
|
429 // For Default Response optional parameter |
|
430 // --------------------------------------------------------- |
|
431 TPtrC8 CNSmlDMCmds::AlertDefaultResponseParam( const SmlPcdata_t* aData, const TDesC8& aParamID ) const |
|
432 { |
|
433 _DBG_FILE("CNSmlDMCmds::AlertDefaultResponseParam: begin"); |
|
434 TLex8 value; |
|
435 if ( aData ) |
|
436 { |
|
437 if ( aData->content ) |
|
438 { |
|
439 TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length ); |
|
440 TrimRightSpaceAndNull( parameters ); |
|
441 TInt startPos = parameters.Find( aParamID ); |
|
442 if ( startPos >= 0 ) |
|
443 { |
|
444 if ( parameters.Length() > startPos + aParamID.Length() ) |
|
445 { |
|
446 TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) ); |
|
447 TInt length = 0; |
|
448 while ( length < strPart.Length() ) |
|
449 { |
|
450 TChar character = strPart[length]; |
|
451 if ( character != '&' ) |
|
452 { |
|
453 ++length; |
|
454 } |
|
455 else |
|
456 { |
|
457 break; |
|
458 } |
|
459 } |
|
460 TPtrC8 valueStr = strPart.Left( length ); |
|
461 value.Assign( valueStr ); |
|
462 |
|
463 } |
|
464 } |
|
465 } |
|
466 } |
|
467 _DBG_FILE("CNSmlDMCmds::AlertDefaultResponseParam: end"); |
|
468 return value.Remainder(); |
|
469 } |
|
470 //#endif |
|
471 |
|
472 // --------------------------------------------------------- |
|
473 // CNSmlDMCmds::AlertDataLC() |
|
474 // |
|
475 // --------------------------------------------------------- |
|
476 HBufC8* CNSmlDMCmds::AlertDataLC( const SmlItemList_t* aItemList ) const |
|
477 { |
|
478 HBufC8* unicodeData = NULL; |
|
479 _DBG_FILE("CNSmlDMCmds::AlertDataLC: Begin"); |
|
480 if ( aItemList ) |
|
481 { |
|
482 if ( aItemList->next ) |
|
483 { |
|
484 if ( aItemList->next->item ) |
|
485 { |
|
486 if ( aItemList->next->item->data ) |
|
487 { |
|
488 if ( aItemList->next->item->data->content ) |
|
489 { |
|
490 TPtr8 data( (TUint8*) aItemList->next->item->data->content, aItemList->next->item->data->length, aItemList->next->item->data->length ); |
|
491 TrimRightSpaceAndNull( data ); |
|
492 unicodeData = data.AllocLC(); |
|
493 data.Zero(); |
|
494 } |
|
495 } |
|
496 } |
|
497 } |
|
498 } |
|
499 |
|
500 if ( unicodeData == NULL ) |
|
501 { |
|
502 unicodeData = HBufC8::NewLC( 0 ); |
|
503 } |
|
504 _DBG_FILE("CNSmlDMCmds::AlertDataLC: end"); |
|
505 return unicodeData; |
|
506 } |
|
507 // --------------------------------------------------------- |
|
508 // CNSmlDMCmds::InitStatusToAtomicOrSequenceL() |
|
509 // |
|
510 // --------------------------------------------------------- |
|
511 TInt CNSmlDMCmds::InitStatusToAtomicOrSequenceL( const TDesC8& aCmd, const SmlAtomic_t* aAtomic ) const |
|
512 { |
|
513 TInt statusID( 0 ); |
|
514 statusID = iStatusToServer->CreateNewStatusElementL(); |
|
515 iStatusToServer->SetCmdRefL( statusID, aAtomic->cmdID ); |
|
516 iStatusToServer->SetCmdL( statusID, aCmd ); |
|
517 if ( iStatusToServerNoResponse || IsFlagSet( aAtomic->flags, SmlNoResp_f ) ) |
|
518 { |
|
519 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
520 } |
|
521 else |
|
522 { |
|
523 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
524 } |
|
525 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
526 return statusID; |
|
527 } |
|
528 |
|
529 // --------------------------------------------------------- |
|
530 // CNSmlDMCmds::DoAlertL() |
|
531 // Makes Alert element and calls parser to generate xml |
|
532 // --------------------------------------------------------- |
|
533 void CNSmlDMCmds::DoAlertL( const TDesC8& aAlertCode, TTime* /*aLastSyncAnchor*/, TTime* /*aNextSyncAnchor*/ ) |
|
534 { |
|
535 //initialise Alert |
|
536 SmlAlert_t* alert = new( ELeave ) SmlAlert_t; |
|
537 CleanupStack::PushL( alert ); |
|
538 //element type |
|
539 alert->elementType = SML_PE_ALERT; |
|
540 //CmdID element |
|
541 DoCmdIdL( alert->cmdID ); |
|
542 //Alert code to Data element |
|
543 PcdataNewL ( alert->data, aAlertCode ); |
|
544 TInt ret = iGenerator->smlAlertCmd( alert); |
|
545 if ( ret != KWBXMLGeneratorOk ) |
|
546 { |
|
547 User::Leave( ret ); |
|
548 } |
|
549 CleanupStack::PopAndDestroy(); //alert |
|
550 //save Status response information for response status controlling |
|
551 CreateAndInitResponseItemL( KNSmlAgentAlert ); |
|
552 } |
|
553 |
|
554 // FOTA |
|
555 // --------------------------------------------------------- |
|
556 // CNSmlDMCmds::DoGenericAlertL() |
|
557 // Makes a generic alert element (or possible many of them) |
|
558 // and calls WBXML generator. |
|
559 // @param aFwMgmtUri. The uri which has been used in the exe command whose final result is |
|
560 // about to be reported. |
|
561 // @param aMetaType. Meta/Type that should be used in the alert. |
|
562 // @param aMetaFormat. Meta/Format that should be used in the alert. |
|
563 // @param aFinalResult. The final result value which is reported to remote server. |
|
564 // @param aCorrelator. Correlator value used in the original exec command. |
|
565 // --------------------------------------------------------- |
|
566 // |
|
567 void CNSmlDMCmds::DoGenericAlertL ( const TDesC8& aFwMgmtUri, const TDesC8& aMetaType, const TDesC8& aMetaFormat, |
|
568 TInt aFinalResult, const TDesC8& aFwCorrelator ) |
|
569 { |
|
570 SmlAlert_t* alert = new (ELeave) SmlAlert_t; |
|
571 CleanupStack::PushL ( alert ); |
|
572 alert->elementType = SML_PE_ALERT; |
|
573 DoCmdIdL ( alert->cmdID ); |
|
574 PcdataNewL ( alert->data, KNSmlDMAgentGenericAlert ); |
|
575 |
|
576 if ( aFwCorrelator != KNullDesC8 ) |
|
577 { |
|
578 PcdataNewL ( alert->correlator, aFwCorrelator ); |
|
579 } |
|
580 |
|
581 alert->itemList = new ( ELeave ) SmlItemList_t; |
|
582 alert->itemList->item = new ( ELeave ) SmlItem_t; |
|
583 // URI comes without ./ from the adapter - add it now |
|
584 TPtr8 uri = HBufC8::NewLC ( aFwMgmtUri.Length() + KNSmlAgentRelativeURIPrefix().Length() )->Des(); |
|
585 uri.Append ( KNSmlAgentRelativeURIPrefix ); |
|
586 uri.Append ( aFwMgmtUri ); |
|
587 |
|
588 DoSourceL ( alert->itemList->item->source, uri ); |
|
589 CleanupStack::PopAndDestroy(); // uri |
|
590 |
|
591 SmlMetInfMetInf_t* metInf; |
|
592 DoMetInfLC ( metInf ); |
|
593 |
|
594 PcdataNewL ( metInf->type, aMetaType ); |
|
595 PcdataNewL ( metInf->format, aMetaFormat ); |
|
596 DoMetaL ( alert->itemList->item->meta, metInf ); |
|
597 CleanupStack::Pop(); // metInf |
|
598 TBuf8<KNSmlMaxInt32Length> result; |
|
599 result.Num ( aFinalResult ); |
|
600 PcdataNewL ( alert->itemList->item->data, result ); |
|
601 |
|
602 TInt ret = iGenerator->smlAlertCmd ( alert ); |
|
603 if ( ret != KWBXMLGeneratorOk ) |
|
604 { |
|
605 User::Leave( ret ); |
|
606 } |
|
607 CleanupStack::PopAndDestroy(); //alert |
|
608 //response item is not created, because client is not |
|
609 //interested what server responds to generic alert. |
|
610 // ... |
|
611 } |
|
612 |
|
613 // @param aMetaType. Meta/Type that should be used in the alert. |
|
614 // @param aMetaFormat. Meta/Format that should be used in the alert. |
|
615 // @param aFinalResult. The final result value which is reported to remote server. |
|
616 // @param aCorrelator. Correlator value used in the original exec command. |
|
617 // --------------------------------------------------------- |
|
618 // |
|
619 void CNSmlDMCmds::DoGenericAlertL ( const TDesC8& aCorrelator, const RArray<CNSmlDMAlertItem>& aItemList ) |
|
620 { |
|
621 SmlAlert_t* alert = new (ELeave) SmlAlert_t; |
|
622 CleanupStack::PushL ( alert ); |
|
623 alert->elementType = SML_PE_ALERT; |
|
624 DoCmdIdL ( alert->cmdID ); |
|
625 PcdataNewL ( alert->data, KNSmlDMAgentGenericAlert ); |
|
626 |
|
627 if ( aCorrelator != KNullDesC8 ) |
|
628 { |
|
629 PcdataNewL ( alert->correlator, aCorrelator ); |
|
630 } |
|
631 |
|
632 SmlItemList_t* itemPtr = NULL; |
|
633 TInt count = 1; |
|
634 if(&aItemList) |
|
635 count = aItemList.Count(); |
|
636 for(TInt i = 0; i<count; i++) |
|
637 { |
|
638 if( itemPtr == NULL) |
|
639 { |
|
640 alert->itemList = new ( ELeave ) SmlItemList_t; |
|
641 itemPtr = alert->itemList; |
|
642 } |
|
643 else |
|
644 { |
|
645 itemPtr->next = new ( ELeave ) SmlItemList_t; |
|
646 itemPtr = itemPtr->next; |
|
647 } |
|
648 itemPtr->item = new ( ELeave ) SmlItem_t; |
|
649 // URI comes without ./ from the adapter - add it now |
|
650 TPtr8 uri = HBufC8::NewLC ((*aItemList[i].iSource).Length() + KNSmlAgentRelativeURIPrefix().Length())->Des(); |
|
651 uri.Append ( KNSmlAgentRelativeURIPrefix ); |
|
652 uri.Append ( *aItemList[i].iSource ); |
|
653 |
|
654 DoSourceL ( itemPtr->item->source, uri ); |
|
655 CleanupStack::PopAndDestroy(); // uri |
|
656 |
|
657 TPtr8 targeturi = HBufC8::NewLC ( (*aItemList[i].iTarget).Length())->Des(); |
|
658 targeturi.Append ( *aItemList[i].iTarget); |
|
659 DoTargetL ( itemPtr->item->target, targeturi ); |
|
660 CleanupStack::PopAndDestroy(); // targeturi |
|
661 |
|
662 SmlMetInfMetInf_t* metInf; |
|
663 DoMetInfLC ( metInf ); |
|
664 |
|
665 PcdataNewL ( metInf->type, *aItemList[i].iMetaType ); |
|
666 PcdataNewL ( metInf->format, *aItemList[i].iMetaFormat ); |
|
667 PcdataNewL ( metInf->mark, *aItemList[i].iMetaMark ); |
|
668 |
|
669 DoMetaL ( itemPtr->item->meta, metInf ); |
|
670 CleanupStack::Pop(); // metInf |
|
671 |
|
672 PcdataNewL ( itemPtr->item->data, *aItemList[i].iData ); |
|
673 |
|
674 } |
|
675 TInt ret = iGenerator->smlAlertCmd ( alert ); |
|
676 if ( ret != KWBXMLGeneratorOk ) |
|
677 { |
|
678 User::Leave( ret ); |
|
679 } |
|
680 CleanupStack::PopAndDestroy(); //alert |
|
681 //response item is not created, because client is not |
|
682 //interested what server responds to generic alert. |
|
683 // ... |
|
684 } |
|
685 |
|
686 // --------------------------------------------------------- |
|
687 // CNSmlDMCmds::DoGenericUserAlertL() |
|
688 // Makes a generic user alert element, if the update request is set to the |
|
689 // central repository by the FOTA UI. |
|
690 // @param aProfileId. The profile id of the current dm session. |
|
691 // @return TBool. ETrue if the alert was generated, otherwise EFalse. |
|
692 // --------------------------------------------------------- |
|
693 // |
|
694 TBool CNSmlDMCmds::DoGenericUserAlertL ( TInt aProfileId ) |
|
695 { |
|
696 // Check from the central repository if firmware update |
|
697 // is requested by the user |
|
698 TBool needsReset(EFalse); |
|
699 |
|
700 // Getting a value |
|
701 TInt readProfId ( KNSmlDmNoRequest ); |
|
702 if ( iRepository ) |
|
703 { |
|
704 iRepository->Get ( KDevManClientInitiatedFwUpdateId, readProfId ); |
|
705 } |
|
706 |
|
707 if ( readProfId != KNSmlDmNoRequest && readProfId == aProfileId ) |
|
708 { |
|
709 SmlAlert_t* alert = new (ELeave) SmlAlert_t; |
|
710 CleanupStack::PushL ( alert ); |
|
711 alert->elementType = SML_PE_ALERT; |
|
712 DoCmdIdL ( alert->cmdID ); |
|
713 PcdataNewL ( alert->data, KNSmlDMAgentGenericAlert ); |
|
714 |
|
715 alert->itemList = new ( ELeave ) SmlItemList_t; |
|
716 alert->itemList->item = new ( ELeave ) SmlItem_t; |
|
717 |
|
718 SmlMetInfMetInf_t* metInf; |
|
719 DoMetInfLC ( metInf ); |
|
720 |
|
721 PcdataNewL ( metInf->type, KNSmlDMMetaTypeUserRequest ); |
|
722 PcdataNewL ( metInf->format, KNSmlDMMetaFormatUserRequest ); |
|
723 DoMetaL ( alert->itemList->item->meta, metInf ); |
|
724 CleanupStack::Pop(); // metInf |
|
725 |
|
726 PcdataNewL ( alert->itemList->item->data, KNullDesC8 ); |
|
727 |
|
728 TInt ret = iGenerator->smlAlertCmd ( alert ); |
|
729 if ( ret != KWBXMLGeneratorOk ) |
|
730 { |
|
731 User::Leave( ret ); |
|
732 } |
|
733 CleanupStack::PopAndDestroy(); //alert |
|
734 needsReset = ETrue; |
|
735 } |
|
736 return needsReset; |
|
737 } |
|
738 |
|
739 // --------------------------------------------------------- |
|
740 // CNSmlDMCmds::ResetGenericUserAlertL() |
|
741 // Resets the update request in the central repository by |
|
742 // writing '-1' value. |
|
743 // --------------------------------------------------------- |
|
744 // |
|
745 void CNSmlDMCmds::ResetGenericUserAlertL() |
|
746 { |
|
747 // Reset the value in the Central Repository |
|
748 if ( iRepository ) |
|
749 { |
|
750 iRepository->Set ( KDevManClientInitiatedFwUpdateId, KNSmlDmNoRequest ); |
|
751 } |
|
752 } |
|
753 |
|
754 // --------------------------------------------------------- |
|
755 // CNSmlDMCmds::MarkGenAlertsSentL() |
|
756 // When the generic alerts are successfully sent to the remote |
|
757 // server, the FOTA adapter needs to be informed about this. |
|
758 // This command is chained through the DM engine. |
|
759 // --------------------------------------------------------- |
|
760 // |
|
761 void CNSmlDMCmds::MarkGenAlertsSentL() |
|
762 { |
|
763 iDMModule->MarkGenAlertsSentL(); |
|
764 } |
|
765 |
|
766 |
|
767 // --------------------------------------------------------- |
|
768 // CNSmlDMCmds::MarkGenAlertsSentL() |
|
769 // When the generic alerts are successfully sent to the remote |
|
770 // server, the FOTA adapter needs to be informed about this. |
|
771 // This command is chained through the DM engine. |
|
772 // --------------------------------------------------------- |
|
773 // |
|
774 void CNSmlDMCmds::MarkGenAlertsSentL(const TDesC8& aURI) |
|
775 { |
|
776 iDMModule->MarkGenAlertsSentL(aURI); |
|
777 } |
|
778 // --------------------------------------------------------- |
|
779 // CNSmlDMCmds::DisconnectFromOtherServers() |
|
780 // Closes the connections to callback server and host servers. |
|
781 // Separate function is needed, since the disconnecting cannot |
|
782 // be made after the active scheduler of the thread is stopped. |
|
783 // --------------------------------------------------------- |
|
784 // |
|
785 void CNSmlDMCmds::DisconnectFromOtherServers() |
|
786 { |
|
787 iDMModule->DisconnectFromOtherServers(); |
|
788 } |
|
789 |
|
790 |
|
791 // FOTA end |
|
792 |
|
793 // --------------------------------------------------------- |
|
794 // CNSmlDMCmds::DoPutL() |
|
795 // Empty function In DM |
|
796 // --------------------------------------------------------- |
|
797 void CNSmlDMCmds::DoPutL() |
|
798 { |
|
799 } |
|
800 |
|
801 // --------------------------------------------------------- |
|
802 // CNSmlDMCmds::DoResultsL() |
|
803 // |
|
804 // --------------------------------------------------------- |
|
805 CNSmlCmdsBase::TReturnValue CNSmlDMCmds::DoResultsL() |
|
806 { |
|
807 TBool found( ETrue ); |
|
808 CNSmlCmdsBase::TReturnValue returnValue = CNSmlCmdsBase::EReturnOK; |
|
809 if ( iResultsToServer ) |
|
810 { |
|
811 iResultsToServer->Begin(); |
|
812 while( found ) |
|
813 { |
|
814 SmlResults_t* results; |
|
815 found = iResultsToServer->NextResultsElement( results ); |
|
816 if ( found ) |
|
817 { |
|
818 SmlPcdata_t* cmdID; |
|
819 DoCmdIdL( cmdID ); |
|
820 CleanupStack::PushL( cmdID ); |
|
821 iResultsToServer->SetCmdIDL( iResultsToServer->CurrentEntryID(), cmdID ); |
|
822 CleanupStack::PopAndDestroy(); //cmdID; |
|
823 |
|
824 TInt dataBufferSize(0); |
|
825 |
|
826 while ( results->itemList->item->data->length < KNSmlDefaultWorkspaceSize && iBytesSent+dataBufferSize<iLargeObjectTotalSize) |
|
827 { |
|
828 //loop until the whole item is got from the dm module, but stop if item size is over the workspace size. |
|
829 //the while condition is false if not large object (iLargeObjectTotalSize =0) |
|
830 CBufBase *data= CBufFlat::NewL(64); |
|
831 CleanupStack::PushL(data); |
|
832 data->InsertL(0,results->itemList->item->data->content,results->itemList->item->data->length); |
|
833 TInt len = data->Size(); |
|
834 DBG_ARGS8(_S8("CNSmlDMCmds::DoResultsL 1,dataLen= %d,totalSize= %d,bytesSent= %d"), len,iLargeObjectTotalSize,iBytesSent ); |
|
835 iDMModule->MoreDataL(data); |
|
836 if(data->Size()==len) |
|
837 { |
|
838 CleanupStack::PopAndDestroy(); //data |
|
839 break; |
|
840 } |
|
841 delete results->itemList->item->data; |
|
842 PcdataNewL( results->itemList->item->data, data->Ptr( 0 ) ); |
|
843 dataBufferSize = data->Size(); |
|
844 DBG_ARGS8(_S8("CNSmlDMCmds::DoResultsL 2,dataBufferSize= %d"), dataBufferSize ); |
|
845 CleanupStack::PopAndDestroy(); //data |
|
846 } |
|
847 |
|
848 if ( results->itemList->item->data->length >= KNSmlLargeObjectMinSize ) |
|
849 { |
|
850 iGenerator->SetTruncate( ETrue ); |
|
851 iGenerator->SetContentLength( results->itemList->item->data->length ); |
|
852 } |
|
853 TInt ret = iGenerator->smlResultsCmd( results ); |
|
854 switch ( ret ) |
|
855 { |
|
856 case KWBXMLGeneratorOk: |
|
857 if ( iGenerator->WasTruncated() ) |
|
858 { |
|
859 DBG_ARGS8(_S8("CNSmlDMCmds::DoResultsL before subtract, length=%d"), results->itemList->item->data->length); |
|
860 SubtractConsumedFromPcData( results->itemList->item, iGenerator->DataConsumed() ); |
|
861 DBG_ARGS8(_S8("CNSmlDMCmds::DoResultsL after subtract, length=%d, dataConsumed=%d"), results->itemList->item->data->length, iGenerator->DataConsumed()); |
|
862 DBG_ARGS8(_S8("CNSmlDMCmds::DoResultsL DataConsumed, BytesSent= %d, length=%d"), iBytesSent, iGenerator->DataConsumed() ); |
|
863 iBytesSent += iGenerator->DataConsumed(); |
|
864 |
|
865 returnValue = CNSmlCmdsBase::EReturnBufferFull; |
|
866 found = EFalse; |
|
867 } |
|
868 else |
|
869 { |
|
870 iLargeObjectTotalSize = 0; |
|
871 iBytesSent = 0; |
|
872 iResultsToServer->RemoveWritten( iResultsToServer->CurrentEntryID() ); |
|
873 } |
|
874 CreateAndInitResponseItemL( KNSmlAgentResults ); |
|
875 break; |
|
876 case KWBXMLGeneratorBufferFull: |
|
877 returnValue = CNSmlCmdsBase::EReturnBufferFull; |
|
878 found = EFalse; |
|
879 break; |
|
880 default: |
|
881 User::Leave( ret ); |
|
882 break; |
|
883 } |
|
884 DBG_ARGS8(_S8("CNSmlDMCmds::DoResultsL 3,BytesSent= %d"), iBytesSent ); |
|
885 iGenerator->SetTruncate( EFalse ); |
|
886 } |
|
887 else |
|
888 { |
|
889 iLargeObjectTotalSize = 0; |
|
890 iBytesSent = 0; |
|
891 } |
|
892 } |
|
893 } |
|
894 return returnValue; |
|
895 } |
|
896 // --------------------------------------------------------- |
|
897 // CNSmlDMCmds::DoGetL() |
|
898 // Empty function In DM |
|
899 // --------------------------------------------------------- |
|
900 void CNSmlDMCmds::DoGetL() |
|
901 { |
|
902 } |
|
903 // --------------------------------------------------------- |
|
904 // CNSmlCmdsBase::DoStartSyncL |
|
905 // Empty function In DM |
|
906 // --------------------------------------------------------- |
|
907 CNSmlCmdsBase::TReturnValue CNSmlDMCmds::DoStartSyncL() |
|
908 { |
|
909 return CNSmlCmdsBase::EReturnOK; |
|
910 } |
|
911 // --------------------------------------------------------- |
|
912 // CNSmlDMCmds::DoEndSyncL |
|
913 // Empty function In DM |
|
914 // --------------------------------------------------------- |
|
915 void CNSmlDMCmds::DoEndSyncL() |
|
916 { |
|
917 } |
|
918 // --------------------------------------------------------- |
|
919 // CNSmlDMCmds::DoAddOrReplaceOrDeleteL |
|
920 // Generate Replace element, which contains DevInf |
|
921 // and calls parser to generate xml |
|
922 // --------------------------------------------------------- |
|
923 CNSmlCmdsBase::TReturnValue CNSmlDMCmds::DoAddOrReplaceOrDeleteL() |
|
924 { |
|
925 //initialise Add, Update or Delete element |
|
926 SmlGenericCmd_t* genericCmd = new( ELeave ) SmlGenericCmd_t; |
|
927 CleanupStack::PushL( genericCmd ); |
|
928 //CmdID element |
|
929 DoCmdIdL( genericCmd->cmdID ); |
|
930 |
|
931 genericCmd->itemList = new( ELeave ) SmlItemList_t; |
|
932 |
|
933 iDMDevInfo = new(ELeave) TDMDevInfo; |
|
934 iDMDevInfo->iFormat = NULL; |
|
935 iDMDevInfo->iType = NULL; |
|
936 iDMDevInfo->iObject= NULL; |
|
937 iDMDevInfo->iItemListPtr = &genericCmd->itemList; |
|
938 (*iDMDevInfo->iItemListPtr)->item = new( ELeave ) SmlItem_t; |
|
939 iDMDevInfo->iFirst = ETrue; |
|
940 iDMDevInfo->iResults = EFalse; |
|
941 iDMDevInfoResults = ETrue; |
|
942 DoDevInfoItemsL( _L8("./DevInfo") ); |
|
943 FreeDMDevinfo(); |
|
944 iDMDevInfoResults = EFalse; |
|
945 |
|
946 genericCmd->elementType = SML_PE_REPLACE; |
|
947 TInt ret = iGenerator->smlReplaceCmd( genericCmd ); |
|
948 CNSmlCmdsBase::TReturnValue returnValue = CNSmlCmdsBase::EReturnOK; |
|
949 switch ( ret ) |
|
950 { |
|
951 case KWBXMLGeneratorOk: |
|
952 break; |
|
953 default: |
|
954 User::Leave( ret ); |
|
955 break; |
|
956 } |
|
957 if ( ret == KWBXMLGeneratorOk ) |
|
958 { |
|
959 CreateAndInitResponseItemL( KNSmlAgentReplace ); |
|
960 } |
|
961 CleanupStack::PopAndDestroy(); //genericCmd |
|
962 return returnValue; |
|
963 } |
|
964 |
|
965 |
|
966 // --------------------------------------------------------- |
|
967 // CNSmlDMCmds::DoMapL |
|
968 // Empty function In DM |
|
969 // --------------------------------------------------------- |
|
970 CNSmlDMCmds::TReturnValue CNSmlDMCmds::DoMapL() |
|
971 { |
|
972 return EReturnOK; |
|
973 } |
|
974 // --------------------------------------------------------- |
|
975 // CNSmlDMCmds::ProcessResultsCmdL |
|
976 // Empty function In DM |
|
977 // --------------------------------------------------------- |
|
978 void CNSmlDMCmds::ProcessResultsCmdL( SmlResults_t* /*aResults*/ ) |
|
979 { |
|
980 } |
|
981 // --------------------------------------------------------- |
|
982 // CNSmlDMCmds::ProcessPutCmd |
|
983 // Empty function In DM |
|
984 // --------------------------------------------------------- |
|
985 void CNSmlDMCmds::ProcessPutCmdL( SmlPut_t* /*aPut*/ ) |
|
986 { |
|
987 } |
|
988 // --------------------------------------------------------- |
|
989 // CNSmlDMCmds::ProcessGetCmdL |
|
990 // Handle object request from the server in Get command |
|
991 // --------------------------------------------------------- |
|
992 void CNSmlDMCmds::ProcessGetCmdL( SmlGet_t* aGet ) |
|
993 { |
|
994 // cmdID |
|
995 if ( aGet->cmdID->length == 0 ) |
|
996 { |
|
997 StatusDataToGetCommandL( aGet, NULL, TNSmlError::ESmlStatusIncompleteCommand ); |
|
998 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
999 return; |
|
1000 } |
|
1001 TPtrC8 cmdID( (TUint8*) aGet->cmdID->content, aGet->cmdID->length ); |
|
1002 DBG_ARGS8(_S8("CNSmlDMCmds::ProcessGetCmdL, CmdId = %S"), &cmdID ); |
|
1003 |
|
1004 SmlItemList_t* itemList; |
|
1005 HBufC8* uri; |
|
1006 itemList = aGet->itemList; |
|
1007 TInt statusID; |
|
1008 TInt resultsID; |
|
1009 while ( itemList ) |
|
1010 { |
|
1011 if ( iAgent->Interrupted() ) |
|
1012 { |
|
1013 StatusDataToGetCommandL( aGet, itemList->item, TNSmlError::ESmlStatusCommandFailed ); |
|
1014 itemList = itemList->next; |
|
1015 continue; |
|
1016 } |
|
1017 if ( iServerAuth->Challenged() ) |
|
1018 { |
|
1019 StatusDataToGetCommandL( aGet, itemList->item, TNSmlError::ESmlStatusClientAuthenticationRequired ); |
|
1020 itemList = itemList->next; |
|
1021 continue; |
|
1022 } |
|
1023 if ( iDMNotExecuted ) |
|
1024 { |
|
1025 StatusDataToGetCommandL( aGet, itemList->item, TNSmlError::ESmlStatusNotExecuted ); |
|
1026 itemList = itemList->next; |
|
1027 continue; |
|
1028 } |
|
1029 // target |
|
1030 if ( !TargetIsUnderItem( itemList ) ) |
|
1031 { |
|
1032 StatusDataToGetCommandL( aGet, itemList->item, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1033 itemList = itemList->next; |
|
1034 continue; |
|
1035 } |
|
1036 statusID = StatusDataToGetCommandL( aGet, itemList->item, TNSmlError::ESmlStatusOK ); |
|
1037 resultsID = iResultsToServer->CreateNewResultsL( *iCurrServerMsgID, cmdID, itemList->item->target, itemList->item->source ); |
|
1038 iResultsToServer->SetStatusID( resultsID, statusID ); |
|
1039 |
|
1040 TPtr8 pcdata( (TUint8*) itemList->item->target->locURI->content, itemList->item->target->locURI->length, itemList->item->target->locURI->length ); |
|
1041 TrimRightSpaceAndNull( pcdata ); |
|
1042 uri = pcdata.AllocLC(); |
|
1043 |
|
1044 iDMModule->FetchObjectL( *uri, *MetaTypeInUtf8LC( itemList->item->meta ), resultsID, statusID, EFalse ); |
|
1045 if ( iDMAtomic ) |
|
1046 { |
|
1047 iStatusToServer->SetAtomicOrSequenceId( statusID, iDMAtomicID ); |
|
1048 } |
|
1049 CleanupStack::PopAndDestroy( 2 ); // *MetaTypeLC(), uri |
|
1050 itemList = itemList->next; |
|
1051 } |
|
1052 } |
|
1053 |
|
1054 // --------------------------------------------------------- |
|
1055 // CNSmlDMCmds::ProcessAlertCmdL |
|
1056 // Handles Alert command from a server. |
|
1057 // --------------------------------------------------------- |
|
1058 void CNSmlDMCmds::ProcessAlertCmdL( SmlAlert_t* aAlert, TBool /*aNextAlert*/, TBool /*aServerAlert*/, TBool /*aDisplayAlert*/ ) |
|
1059 { |
|
1060 TInt statusID( 0 ); |
|
1061 statusID = iStatusToServer->CreateNewStatusElementL(); |
|
1062 iStatusToServer->SetCmdRefL( statusID, aAlert->cmdID ); |
|
1063 iStatusToServer->SetCmdL( statusID, KNSmlAgentAlert ); |
|
1064 if ( iStatusToServerNoResponse || IsFlagSet( aAlert->flags, SmlNoResp_f ) ) |
|
1065 { |
|
1066 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
1067 } |
|
1068 else |
|
1069 { |
|
1070 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
1071 } |
|
1072 |
|
1073 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1074 |
|
1075 // Alert Code in Data element |
|
1076 TPtr8 alertCode = AlertCode( aAlert ); |
|
1077 if ( alertCode.Length() == 0 ) |
|
1078 { |
|
1079 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1080 iAgent->Interrupt( TNSmlError::ESmlAlertCodeMissing, EFalse, EFalse ); |
|
1081 return; |
|
1082 } |
|
1083 if ( alertCode == KNSmlDMAgentSessionAbortAlert ) |
|
1084 { |
|
1085 iAgent->Interrupt( TNSmlDMError::ESmlServerSessionAbort, ETrue, EFalse ); |
|
1086 return; |
|
1087 } |
|
1088 if ( iAgent->Interrupted() ) |
|
1089 { |
|
1090 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1091 return; |
|
1092 } |
|
1093 // cmdID |
|
1094 if ( aAlert->cmdID->length == 0 ) |
|
1095 { |
|
1096 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1097 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1098 return; |
|
1099 } |
|
1100 if ( iServerAuth->Challenged() ) |
|
1101 { |
|
1102 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusClientAuthenticationRequired ); |
|
1103 return; |
|
1104 } |
|
1105 |
|
1106 if ( iDMNotExecuted ) |
|
1107 { |
|
1108 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusNotExecuted ); |
|
1109 return; |
|
1110 } |
|
1111 |
|
1112 |
|
1113 if ( alertCode == KNSmlDMAgentDisplayAlert || |
|
1114 alertCode == KNSmlDMAgentContinueOrAbortAlert || |
|
1115 alertCode == KNSmlDMAgentNextMessage || |
|
1116 alertCode == KNSmlDMAgentSessionAbortAlert || |
|
1117 alertCode == KNSmlDMAgentServerInitAlert || |
|
1118 alertCode == KNSmlDMAgentClientInitAlert |
|
1119 || alertCode == KNSmlDMAgentUserInputAlert |
|
1120 || alertCode == KNSmlDMAgentSingleChoiceAlert |
|
1121 || alertCode == KNSmlDMAgentMultipleChoiceAlert) |
|
1122 { |
|
1123 HandleAlertsL(aAlert,statusID); |
|
1124 } |
|
1125 else |
|
1126 { |
|
1127 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOptFeatureNotSupported ); |
|
1128 return; |
|
1129 } |
|
1130 |
|
1131 } |
|
1132 |
|
1133 // --------------------------------------------------------- |
|
1134 // CNSmlDMCmds::HandleAlertErrorL |
|
1135 // Handles Error while processing Alert command from a server. |
|
1136 // --------------------------------------------------------- |
|
1137 void CNSmlDMCmds::HandleAlertErrorL() |
|
1138 { |
|
1139 if ( iDMAtomic || iDMSequence ) |
|
1140 { |
|
1141 iDMNotExecuted = ETrue; |
|
1142 if (iDMAtomic ) |
|
1143 { |
|
1144 iDMModule->RollBackL(); |
|
1145 iStatusToServer->SetStatusCodesInAtomicL( iDMAtomicID, TNSmlError::ESmlStatusRollBackOK, EFalse ); |
|
1146 iStatusToServer->SetStatusCodeToAtomicOrSequenceCmdL( iDMAtomicID, TNSmlError::ESmlStatusNotExecuted, KNSmlAgentAtomic ); |
|
1147 } |
|
1148 if ( iDMSequence ) |
|
1149 { |
|
1150 iStatusToServer->SetStatusCodeToAtomicOrSequenceCmdL( iDMSequenceID, TNSmlError::ESmlStatusNotExecuted, KNSmlAgentSequence ); |
|
1151 } |
|
1152 } |
|
1153 } |
|
1154 |
|
1155 // --------------------------------------------------------- |
|
1156 // CNSmlDMCmds::HandleAlertsL |
|
1157 // Handles Alert commands from a server. |
|
1158 // --------------------------------------------------------- |
|
1159 void CNSmlDMCmds::HandleAlertsL( SmlAlert_t* aAlert, TInt& aStatusId) |
|
1160 { |
|
1161 TPtr8 alertCode = AlertCode( aAlert ); |
|
1162 if ( alertCode == KNSmlDMAgentDisplayAlert || alertCode == KNSmlDMAgentContinueOrAbortAlert |
|
1163 || alertCode == KNSmlDMAgentUserInputAlert |
|
1164 || alertCode == KNSmlDMAgentSingleChoiceAlert |
|
1165 || alertCode == KNSmlDMAgentMultipleChoiceAlert ) |
|
1166 { |
|
1167 if ( !aAlert->itemList ) |
|
1168 { |
|
1169 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1170 iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse ); |
|
1171 return; |
|
1172 } |
|
1173 if ( !aAlert->itemList->item ) |
|
1174 { |
|
1175 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1176 iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse ); |
|
1177 return; |
|
1178 } |
|
1179 |
|
1180 if ( alertCode == KNSmlDMAgentDisplayAlert ) |
|
1181 { |
|
1182 HandleDisplayAlertL(aAlert,aStatusId); |
|
1183 } |
|
1184 else if(alertCode == KNSmlDMAgentContinueOrAbortAlert) |
|
1185 { |
|
1186 HandleConfirmationAlertL(aAlert,aStatusId); |
|
1187 } |
|
1188 else if(alertCode == KNSmlDMAgentUserInputAlert) |
|
1189 { |
|
1190 HandleUserInputalertL(aAlert,aStatusId); |
|
1191 } |
|
1192 else if(alertCode == KNSmlDMAgentSingleChoiceAlert |
|
1193 || alertCode == KNSmlDMAgentMultipleChoiceAlert) |
|
1194 { |
|
1195 HandleChoiceAlertsL(aAlert,aStatusId); |
|
1196 } |
|
1197 else // |
|
1198 { |
|
1199 |
|
1200 } |
|
1201 } |
|
1202 } |
|
1203 |
|
1204 // --------------------------------------------------------- |
|
1205 // CNSmlDMCmds::HandleChoiceAlertsL |
|
1206 // Handles Choice Alert commands from a server. |
|
1207 // --------------------------------------------------------- |
|
1208 void CNSmlDMCmds::HandleChoiceAlertsL( SmlAlert_t* aAlert, TInt& aStatusId) |
|
1209 { |
|
1210 const TChar KDRSeparator('-'); |
|
1211 const TChar KChoiceItemSeparator(','); |
|
1212 TPtr8 alertCode = AlertCode( aAlert ); |
|
1213 // MINDT |
|
1214 TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMINDT ); |
|
1215 // MAXDT |
|
1216 TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXDT ); |
|
1217 if ( mindt > maxdt ) |
|
1218 { |
|
1219 maxdt = mindt; |
|
1220 } |
|
1221 TSyncMLDlgNotifParams notifyParams; |
|
1222 TInt maxlen = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXLEN ); |
|
1223 |
|
1224 //check if iDR, Default response parameter is there or not |
|
1225 //DRPresent is used for destroying how many items in the pop up stack |
|
1226 TBool DRPresent = CheckDRPresence( aAlert->itemList->item->data, KNSmlDMAgentDR ); |
|
1227 if( DRPresent ) |
|
1228 { |
|
1229 TPtrC8 DrPtr = AlertDefaultResponseParam( aAlert->itemList->item->data, KNSmlDMAgentDR ); |
|
1230 HBufC8* hptr = HBufC8::NewLC( DrPtr.Length()+ 4 ); //cs 1dr |
|
1231 TPtr8 DrBuf(hptr->Des()); |
|
1232 if(alertCode == KNSmlDMAgentMultipleChoiceAlert) |
|
1233 { |
|
1234 _DBG_FILE("drbuf multichoice"); |
|
1235 DrBuf.Append(KDRSeparator); |
|
1236 DrBuf.Append(DrPtr); |
|
1237 DrBuf.Append(KDRSeparator); |
|
1238 } |
|
1239 else |
|
1240 { |
|
1241 DrBuf.Append(DrPtr); |
|
1242 } |
|
1243 HBufC* DrBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( DrBuf ); |
|
1244 CleanupStack::PushL( DrBuf16 ); //cs 2dr |
|
1245 notifyParams.iDR = *DrBuf16; |
|
1246 } |
|
1247 HBufC8* alertData = AlertDataLC( aAlert->itemList ); //cs 1 |
|
1248 if ( alertData->Length() == 0) |
|
1249 { |
|
1250 if( DRPresent ) |
|
1251 { |
|
1252 CleanupStack::PopAndDestroy(2);//alertData,hptr,DrBuf16 |
|
1253 } |
|
1254 CleanupStack::PopAndDestroy();//alertData |
|
1255 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1256 HandleAlertErrorL(); |
|
1257 return; |
|
1258 } |
|
1259 |
|
1260 HBufC8* alertDataWithMDT = HBufC8::NewLC(alertData->Length()+KNSmlDMAgentMINDT().Length()+KNSmlDMAgentMAXDT().Length()+6); //cs 2 |
|
1261 TPtr8 dataBuf = alertDataWithMDT->Des(); |
|
1262 dataBuf.Append(*alertData); |
|
1263 HBufC* dataBuf16 = NULL; |
|
1264 TRAPD(errC, dataBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(dataBuf)); |
|
1265 if( errC == KErrCorrupt ) |
|
1266 { |
|
1267 if( DRPresent ) |
|
1268 { |
|
1269 CleanupStack::PopAndDestroy(2); //alertData hptr,DrBuf16,alertDataWithMDT |
|
1270 } |
|
1271 CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT |
|
1272 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed ); |
|
1273 return; |
|
1274 } |
|
1275 CleanupStack::PushL(dataBuf16); //cs 3 |
|
1276 //RNotifier notifier; |
|
1277 //User::LeaveIfError( notifier.Connect() ); |
|
1278 //CleanupClosePushL(notifier); //cs |
|
1279 TPckgBuf<TBool> resBuf; |
|
1280 /* |
|
1281 //TO reduce cyclomatic complexity |
|
1282 if( dataBuf16->Length() > KSyncMLMaxServerMsgLength ) |
|
1283 { |
|
1284 notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ; |
|
1285 } |
|
1286 else |
|
1287 { |
|
1288 notifyParams.iServerMsg = *dataBuf16; |
|
1289 } */ |
|
1290 TInt datalength = FindMaxLength(dataBuf16->Length(),KSyncMLMaxServerMsgLength); |
|
1291 notifyParams.iServerMsg = (*dataBuf16).Left(datalength); |
|
1292 notifyParams.iMaxTime = maxdt; |
|
1293 notifyParams.iMaxLength = maxlen; |
|
1294 TRequestStatus status; |
|
1295 _DBG_FILE("starting of choice alerts"); |
|
1296 //Retrieve items list |
|
1297 HBufC8* lengthbuf = HBufC8::NewLC(100); //cs 4 |
|
1298 TInt NumItems = 0 ; |
|
1299 HBufC8* listitems = AlertChoiceItemsLC(aAlert->itemList,lengthbuf,NumItems); //cs 5 |
|
1300 if(!NumItems) |
|
1301 { |
|
1302 if( DRPresent ) |
|
1303 { |
|
1304 CleanupStack::PopAndDestroy(2); |
|
1305 } |
|
1306 CleanupStack::PopAndDestroy(5); |
|
1307 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1308 return; |
|
1309 } |
|
1310 notifyParams.iNumberOfItems = NumItems; |
|
1311 HBufC* choiceitemslength = NULL; |
|
1312 TRAPD(errL, choiceitemslength = CnvUtfConverter::ConvertToUnicodeFromUtf8L(lengthbuf->Des())); |
|
1313 if( errL/* == KErrCorrupt*/ )//useful for low memory and other cases |
|
1314 { |
|
1315 if( DRPresent ) |
|
1316 { |
|
1317 CleanupStack::PopAndDestroy(2); |
|
1318 } |
|
1319 CleanupStack::PopAndDestroy(5); |
|
1320 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed ); |
|
1321 return; |
|
1322 } |
|
1323 CleanupStack::PushL(choiceitemslength); //cs 6 |
|
1324 |
|
1325 /* if( choiceitemslength->Length() > KSyncMLChoiceItemsLengthBuffer ) |
|
1326 { |
|
1327 notifyParams.iItemLength = (*choiceitemslength).Left(KSyncMLChoiceItemsLengthBuffer) ; |
|
1328 } |
|
1329 else |
|
1330 { |
|
1331 notifyParams.iItemLength = *choiceitemslength; |
|
1332 } */ |
|
1333 datalength = FindMaxLength(choiceitemslength->Length(),KSyncMLChoiceItemsLengthBuffer); |
|
1334 notifyParams.iItemLength = (*choiceitemslength).Left(datalength); |
|
1335 if( alertCode == KNSmlDMAgentMultipleChoiceAlert) |
|
1336 { |
|
1337 _DBG_FILE("multiple choice alerts"); |
|
1338 notifyParams.iNoteType = ESyncMLMultiChoiceQuery; |
|
1339 } |
|
1340 else |
|
1341 { |
|
1342 _DBG_FILE("single choice alerts"); |
|
1343 notifyParams.iNoteType = ESyncMLSingleChoiceQuery; |
|
1344 } |
|
1345 if(iChunk.Handle()) |
|
1346 iChunk.Close(); |
|
1347 else |
|
1348 { |
|
1349 TTime now; |
|
1350 now.HomeTime(); |
|
1351 TInt64 rand = now.Int64(); |
|
1352 // Use timestamp to get a unique seed |
|
1353 TInt randnum = Math::Rand( rand ); |
|
1354 TBuf<KSyncMLMaxProfileNameLength> chunkname; |
|
1355 chunkname.AppendNum(randnum); |
|
1356 chunkname.Append(KChunkName); |
|
1357 notifyParams.iChunkName = chunkname; |
|
1358 TInt err1 = iChunk.CreateGlobal( chunkname, |
|
1359 KNSmlDmChoiceChunkMinSize, KNSmlDmChoiceChunkMaxSize ); |
|
1360 DBG_FILE_CODE(err1,_S8("chunk creating error is ")); |
|
1361 if( err1 < 0 && err1 != KErrAlreadyExists ) |
|
1362 User::LeaveIfError(err1); |
|
1363 if( err1 == KErrAlreadyExists ) |
|
1364 { err1 = iChunk.OpenGlobal(chunkname,EFalse); |
|
1365 DBG_FILE_CODE(err1,_S8("chunk opening error is ")); |
|
1366 User::LeaveIfError(err1); |
|
1367 } |
|
1368 } |
|
1369 TInt size1 = iChunk.Size(); |
|
1370 DBG_FILE_CODE(size1,_S8("chunk size is ")); |
|
1371 |
|
1372 RMemWriteStream chunkStream ( iChunk.Base(), iChunk.Size() ); |
|
1373 CleanupClosePushL ( chunkStream ); //cs |
|
1374 chunkStream.WriteL ( listitems->Des() ); |
|
1375 CleanupStack::PopAndDestroy(1);//chunkstream |
|
1376 TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams ); |
|
1377 TSyncMLDlgNotifReturnParams emptybuf; |
|
1378 TSyncMLDlgNotifReturnParamsPckg resultBuf( emptybuf ); |
|
1379 RNotifier notifier; |
|
1380 User::LeaveIfError( notifier.Connect() ); |
|
1381 CleanupClosePushL(notifier); //cs 7 |
|
1382 _DBG_FILE("starting choice notifier"); |
|
1383 notifier.StartNotifierAndGetResponse( status, KNSmlSyncDialogUid, pkgBuf, resultBuf ); |
|
1384 _DBG_FILE("notifier returned"); |
|
1385 User::WaitForRequest( status ); |
|
1386 CleanupStack::PopAndDestroy(4);//notifier,lengthbuf,listitems,choiceitemslength |
|
1387 iChunk.Close(); |
|
1388 TBuf8<KSyncMLMaxAlertResultLength> rettext; |
|
1389 rettext.Copy( resultBuf().irettext.Left( KSyncMLMaxAlertResultLength ) ); |
|
1390 if ( status != KErrNone ) |
|
1391 { |
|
1392 TInt error = TNSmlError::ESmlStatusOperationCancelled ; |
|
1393 iStatusToServer->SetStatusCodeL( aStatusId, error ); |
|
1394 HandleAlertErrorL(); |
|
1395 } |
|
1396 else |
|
1397 { |
|
1398 //For sending data to server |
|
1399 if( alertCode == KNSmlDMAgentMultipleChoiceAlert) |
|
1400 { |
|
1401 SendMultiChoiceDataToServerL(rettext,aStatusId); |
|
1402 } |
|
1403 else |
|
1404 { |
|
1405 SmlPcdata_t* data = NULL; |
|
1406 PcdataNewL( data, rettext); |
|
1407 CleanupStack::PushL( data ); |
|
1408 iStatusToServer->AddItemDataL( aStatusId, data ); |
|
1409 CleanupStack::PopAndDestroy(); //data |
|
1410 } |
|
1411 } |
|
1412 if( DRPresent ) |
|
1413 CleanupStack::PopAndDestroy(2); //hptr,DrBuf16 |
|
1414 |
|
1415 CleanupStack::PopAndDestroy(3); //notifier,alertData,alertDataWithMDT,dataBuf16 |
|
1416 } |
|
1417 |
|
1418 // --------------------------------------------------------- |
|
1419 // CNSmlDMCmds::SendMultiChoiceDataToServerL |
|
1420 // Sends Multiple Choice Alert status to server. |
|
1421 // --------------------------------------------------------- |
|
1422 void CNSmlDMCmds::SendMultiChoiceDataToServerL(TDes8& aData,TInt& aStatusId) |
|
1423 { |
|
1424 const TChar KDRSeparator('-'); |
|
1425 TPtrC8 temp1,temp2; |
|
1426 TInt prevcommapos = 0; |
|
1427 SmlPcdata_t* data = NULL; |
|
1428 for(TInt i=0;i<aData.Length();i++) |
|
1429 { |
|
1430 //find a slash |
|
1431 |
|
1432 if(aData[i]== KDRSeparator) |
|
1433 { |
|
1434 if(prevcommapos) |
|
1435 { |
|
1436 |
|
1437 temp1.Set(aData.Left(i)); |
|
1438 temp2.Set(temp1.Right(i-(prevcommapos+1))); |
|
1439 prevcommapos= i; |
|
1440 } |
|
1441 else //firsttime finding comma |
|
1442 { |
|
1443 prevcommapos= i; |
|
1444 temp1.Set(aData.Left(i)); |
|
1445 temp2.Set(temp1.Right(i)); |
|
1446 } |
|
1447 //convert temp2 to number |
|
1448 PcdataNewL( data, temp2); |
|
1449 CleanupStack::PushL( data ); |
|
1450 iStatusToServer->AddItemDataL( aStatusId, data ); |
|
1451 CleanupStack::PopAndDestroy(); //data |
|
1452 data = NULL; |
|
1453 |
|
1454 } |
|
1455 } |
|
1456 |
|
1457 } |
|
1458 |
|
1459 // --------------------------------------------------------- |
|
1460 // CNSmlDMCmds::HandleConfirmationAlertL |
|
1461 // Handles Confirmation Alert command from a server. |
|
1462 // --------------------------------------------------------- |
|
1463 void CNSmlDMCmds::HandleConfirmationAlertL( SmlAlert_t* aAlert, TInt& aStatusId) |
|
1464 { |
|
1465 // MINDT |
|
1466 TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMINDT ); |
|
1467 // MAXDT |
|
1468 TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXDT ); |
|
1469 if ( mindt > maxdt ) |
|
1470 { |
|
1471 maxdt = mindt; |
|
1472 } |
|
1473 TSyncMLDlgNotifParams notifyParams; |
|
1474 TInt maxlen = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXLEN ); |
|
1475 HBufC8* alertData = AlertDataLC( aAlert->itemList ); |
|
1476 if ( alertData->Length() == 0) |
|
1477 { |
|
1478 CleanupStack::PopAndDestroy();//alertData |
|
1479 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1480 HandleAlertErrorL(); |
|
1481 return; |
|
1482 } |
|
1483 HBufC8* alertDataWithMDT = HBufC8::NewLC(alertData->Length()+KNSmlDMAgentMINDT().Length()+KNSmlDMAgentMAXDT().Length()+6); |
|
1484 TPtr8 dataBuf = alertDataWithMDT->Des(); |
|
1485 dataBuf.Append(*alertData); |
|
1486 HBufC* dataBuf16 = NULL; |
|
1487 TRAPD(errC, dataBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(dataBuf)); |
|
1488 if( errC == KErrCorrupt ) |
|
1489 { |
|
1490 CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT |
|
1491 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed ); |
|
1492 return; |
|
1493 } |
|
1494 CleanupStack::PushL(dataBuf16); |
|
1495 RNotifier notifier; |
|
1496 User::LeaveIfError( notifier.Connect() ); |
|
1497 CleanupClosePushL(notifier); |
|
1498 TPckgBuf<TBool> resBuf; |
|
1499 if( dataBuf16->Length() > KSyncMLMaxServerMsgLength ) |
|
1500 { |
|
1501 notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ; |
|
1502 } |
|
1503 else |
|
1504 { |
|
1505 notifyParams.iServerMsg = *dataBuf16; |
|
1506 } |
|
1507 notifyParams.iMaxTime = maxdt; |
|
1508 notifyParams.iMaxLength = maxlen; |
|
1509 TRequestStatus status; |
|
1510 //Note type to Query note |
|
1511 notifyParams.iNoteType = ESyncMLYesNoQuery; |
|
1512 TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams ); |
|
1513 notifier.StartNotifierAndGetResponse(status,KNSmlSyncDialogUid,pkgBuf,resBuf); |
|
1514 User::WaitForRequest(status); |
|
1515 TBool ret = resBuf(); |
|
1516 if ( status == KErrCancel || status == KErrTimedOut ) |
|
1517 { |
|
1518 TInt error = status == KErrCancel ? TNSmlError::ESmlStatusNotModified : TNSmlError::ESmlStatusRequestTimeout; |
|
1519 iStatusToServer->SetStatusCodeL( aStatusId, error ); |
|
1520 HandleAlertErrorL(); |
|
1521 } |
|
1522 CleanupStack::PopAndDestroy(4); //alertData alertDataWithMDT,databuf16,notifier |
|
1523 } |
|
1524 |
|
1525 // --------------------------------------------------------- |
|
1526 // CNSmlDMCmds::HandleUserInputalertL |
|
1527 // Handles user Text Input Alert command from a server. |
|
1528 // --------------------------------------------------------- |
|
1529 void CNSmlDMCmds::HandleUserInputalertL( SmlAlert_t* aAlert, TInt& aStatusId) |
|
1530 { |
|
1531 // MINDT |
|
1532 TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMINDT ); |
|
1533 // MAXDT |
|
1534 TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXDT ); |
|
1535 if ( mindt > maxdt ) |
|
1536 { |
|
1537 maxdt = mindt; |
|
1538 } |
|
1539 TSyncMLDlgNotifParams notifyParams; |
|
1540 TInt maxlen = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXLEN ); |
|
1541 TInt InputType = AlertInputTypeParameter( aAlert->itemList->item->data, KNSmlDMAgentIT ); |
|
1542 TInt EchoType = AlertEchoTypeParameter( aAlert->itemList->item->data, KNSmlDMAgentET ); |
|
1543 //check if iDR, Default response parameter is there or not |
|
1544 //DRPresent is used for destroying how many items in the pop up stack |
|
1545 TBool DRPresent = CheckDRPresence( aAlert->itemList->item->data, KNSmlDMAgentDR ); |
|
1546 if( DRPresent ) |
|
1547 { |
|
1548 TPtrC8 DrPtr = AlertDefaultResponseParam( aAlert->itemList->item->data, KNSmlDMAgentDR ); |
|
1549 HBufC8* hptr = HBufC8::NewLC( DrPtr.Length()+ 4 ); //cs |
|
1550 TPtr8 DrBuf(hptr->Des()); |
|
1551 |
|
1552 DrBuf.Append(DrPtr); |
|
1553 |
|
1554 HBufC* DrBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( DrBuf ); |
|
1555 CleanupStack::PushL( DrBuf16 );//cs |
|
1556 notifyParams.iDR = *DrBuf16; |
|
1557 } |
|
1558 HBufC8* alertData = AlertDataLC( aAlert->itemList );//cs |
|
1559 if ( alertData->Length() == 0) |
|
1560 { |
|
1561 if( DRPresent ) |
|
1562 { |
|
1563 CleanupStack::PopAndDestroy(3);//alertData,hptr,DrBuf16 |
|
1564 } |
|
1565 else |
|
1566 { |
|
1567 CleanupStack::PopAndDestroy();//alertData |
|
1568 } |
|
1569 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1570 HandleAlertErrorL(); |
|
1571 return; |
|
1572 } |
|
1573 HBufC8* alertDataWithMDT = HBufC8::NewLC(alertData->Length()+KNSmlDMAgentMINDT().Length()+KNSmlDMAgentMAXDT().Length()+6);//cs |
|
1574 TPtr8 dataBuf = alertDataWithMDT->Des(); |
|
1575 dataBuf.Append(*alertData); |
|
1576 HBufC* dataBuf16 = NULL; |
|
1577 TRAPD(errC, dataBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(dataBuf)); |
|
1578 if( errC == KErrCorrupt ) |
|
1579 { |
|
1580 if( DRPresent ) |
|
1581 { |
|
1582 CleanupStack::PopAndDestroy(4); //alertData hptr,DrBuf16,alertDataWithMDT |
|
1583 } |
|
1584 else |
|
1585 { |
|
1586 CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT |
|
1587 } |
|
1588 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed ); |
|
1589 return; |
|
1590 } |
|
1591 CleanupStack::PushL(dataBuf16); //cs |
|
1592 RNotifier notifier; |
|
1593 User::LeaveIfError( notifier.Connect() ); |
|
1594 CleanupClosePushL(notifier); //cs |
|
1595 TPckgBuf<TBool> resBuf; |
|
1596 if( dataBuf16->Length() > KSyncMLMaxServerMsgLength ) |
|
1597 { |
|
1598 notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ; |
|
1599 } |
|
1600 else |
|
1601 { |
|
1602 notifyParams.iServerMsg = *dataBuf16; |
|
1603 } |
|
1604 notifyParams.iMaxTime = maxdt; |
|
1605 notifyParams.iMaxLength = maxlen; |
|
1606 notifyParams.iET = EchoType; |
|
1607 notifyParams.iIT = InputType; |
|
1608 TRequestStatus status; |
|
1609 //Note type to Text input note |
|
1610 notifyParams.iNoteType = ESyncMLInputQuery; |
|
1611 TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams ); |
|
1612 TSyncMLDlgNotifReturnParams emptybuf; |
|
1613 TSyncMLDlgNotifReturnParamsPckg resultBuf( emptybuf ); |
|
1614 notifier.StartNotifierAndGetResponse( status, KNSmlSyncDialogUid, pkgBuf, resultBuf ); |
|
1615 User::WaitForRequest( status ); |
|
1616 TBuf8<KSyncMLMaxDefaultResponseMsgLength> rettext; |
|
1617 rettext.Copy( resultBuf().irettext.Left( KSyncMLMaxDefaultResponseMsgLength ) ); |
|
1618 if ( status == KErrCancel || status == KErrTimedOut || status == KErrAbort ) |
|
1619 { |
|
1620 TInt error = TNSmlError::ESmlStatusOperationCancelled ; |
|
1621 iStatusToServer->SetStatusCodeL( aStatusId, error ); |
|
1622 HandleAlertErrorL(); |
|
1623 } |
|
1624 //For sending data to server |
|
1625 SmlPcdata_t* data = NULL; |
|
1626 PcdataNewL( data, rettext); |
|
1627 CleanupStack::PushL( data ); |
|
1628 iStatusToServer->AddItemDataL( aStatusId, data ); |
|
1629 CleanupStack::PopAndDestroy(); //data |
|
1630 if( DRPresent ) |
|
1631 CleanupStack::PopAndDestroy(6); //notifier,alertData,alertDataWithMDT,dataBuf16,hptr,DrBuf16 |
|
1632 else |
|
1633 //#endif |
|
1634 CleanupStack::PopAndDestroy(4); //notifier,alertData,alertDataWithMDT,dataBuf16 |
|
1635 } |
|
1636 |
|
1637 // --------------------------------------------------------- |
|
1638 // CNSmlDMCmds::HandleDisplayAlertL |
|
1639 // Handles Display Alert command from a server. |
|
1640 // --------------------------------------------------------- |
|
1641 void CNSmlDMCmds::HandleDisplayAlertL( SmlAlert_t* aAlert, TInt& aStatusId) |
|
1642 { |
|
1643 // MINDT |
|
1644 TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMINDT ); |
|
1645 // MAXDT |
|
1646 TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXDT ); |
|
1647 if ( mindt > maxdt ) |
|
1648 { |
|
1649 maxdt = mindt; |
|
1650 } |
|
1651 TSyncMLDlgNotifParams notifyParams; |
|
1652 TInt maxlen = AlertParameter( aAlert->itemList->item->data, KNSmlDMAgentMAXLEN ); |
|
1653 HBufC8* alertData = AlertDataLC( aAlert->itemList ); |
|
1654 if ( alertData->Length() == 0) |
|
1655 { |
|
1656 CleanupStack::PopAndDestroy();//alertData |
|
1657 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1658 HandleAlertErrorL(); |
|
1659 return; |
|
1660 } |
|
1661 HBufC8* alertDataWithMDT = HBufC8::NewLC(alertData->Length()+KNSmlDMAgentMINDT().Length()+KNSmlDMAgentMAXDT().Length()+6); |
|
1662 TPtr8 dataBuf = alertDataWithMDT->Des(); |
|
1663 dataBuf.Append(*alertData); |
|
1664 HBufC* dataBuf16 = NULL; |
|
1665 TRAPD(errC, dataBuf16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(dataBuf)); |
|
1666 if( errC == KErrCorrupt ) |
|
1667 { |
|
1668 CleanupStack::PopAndDestroy(2); //alertData alertDataWithMDT |
|
1669 iStatusToServer->SetStatusCodeL( aStatusId, TNSmlError::ESmlStatusCommandFailed ); |
|
1670 return; |
|
1671 } |
|
1672 CleanupStack::PushL(dataBuf16); |
|
1673 RNotifier notifier; |
|
1674 User::LeaveIfError( notifier.Connect() ); |
|
1675 CleanupClosePushL(notifier); |
|
1676 TPckgBuf<TBool> resBuf; |
|
1677 if( dataBuf16->Length() > KSyncMLMaxServerMsgLength ) |
|
1678 { |
|
1679 notifyParams.iServerMsg = (*dataBuf16).Left(KSyncMLMaxServerMsgLength) ; |
|
1680 } |
|
1681 else |
|
1682 { |
|
1683 notifyParams.iServerMsg = *dataBuf16; |
|
1684 } |
|
1685 notifyParams.iMaxTime = maxdt; |
|
1686 notifyParams.iMaxLength = maxlen; |
|
1687 TRequestStatus status; |
|
1688 notifyParams.iNoteType = ESyncMLInfoNote; |
|
1689 TPckgBuf<TSyncMLDlgNotifParams> pkgBuf( notifyParams ); |
|
1690 notifier.StartNotifierAndGetResponse(status,KNSmlSyncDialogUid,pkgBuf,resBuf); |
|
1691 User::WaitForRequest(status); |
|
1692 CleanupStack::PopAndDestroy(4); //alertData alertDataWithMDT,databuf16,notifier |
|
1693 } |
|
1694 |
|
1695 // --------------------------------------------------------- |
|
1696 // CNSmlDMCmds::ProcessSyncL() |
|
1697 // Process received Add, Replace and Delete commands |
|
1698 // --------------------------------------------------------- |
|
1699 void CNSmlDMCmds::ProcessSyncL( SmlSync_t* /*aSync*/ ) |
|
1700 { |
|
1701 } |
|
1702 |
|
1703 // --------------------------------------------------------- |
|
1704 // CNSmlDMCmds::ProcessUpdatesL() |
|
1705 // Process received Add, Replace and Delete commands |
|
1706 // --------------------------------------------------------- |
|
1707 void CNSmlDMCmds::ProcessUpdatesL( const TDesC8& aCmd, SmlGenericCmd_t* aContent ) |
|
1708 { |
|
1709 TInt statusID( 0 ); |
|
1710 // cmdID |
|
1711 if ( aContent->cmdID->length == 0 ) |
|
1712 { |
|
1713 StatusDataToGenericCommandL( aCmd, aContent, NULL, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1714 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1715 return; |
|
1716 } |
|
1717 SmlItemList_t* itemList=0; |
|
1718 SmlItem_t* item=0; |
|
1719 HBufC8* uri; |
|
1720 // FOTA |
|
1721 /* |
|
1722 if(aCmd==KNSmlAgentExec()) |
|
1723 { |
|
1724 item = ((SmlExecPtr_t)aContent)->item; |
|
1725 } |
|
1726 else |
|
1727 { |
|
1728 */ |
|
1729 itemList = aContent->itemList; |
|
1730 item = itemList->item; |
|
1731 // } |
|
1732 // FOTA end |
|
1733 |
|
1734 while ( item ) |
|
1735 { |
|
1736 TNSmlError::TNSmlSyncMLStatusCode statusCode=TNSmlError::ESmlStatusOK; |
|
1737 UpdateErrorStatusCode(item,statusCode); |
|
1738 |
|
1739 if(statusCode!=TNSmlError::ESmlStatusOK) |
|
1740 { |
|
1741 StatusDataToGenericCommandL( aCmd, aContent, item, statusCode ); |
|
1742 if(itemList) |
|
1743 { |
|
1744 itemList = itemList->next; |
|
1745 if(itemList) |
|
1746 { |
|
1747 item=itemList->item; |
|
1748 } |
|
1749 else |
|
1750 { |
|
1751 item=0; |
|
1752 } |
|
1753 } |
|
1754 else |
|
1755 { |
|
1756 item = 0; |
|
1757 } |
|
1758 continue; |
|
1759 } |
|
1760 |
|
1761 TPtr8 pcdata( (TUint8*) item->target->locURI->content, item->target->locURI->length, item->target->locURI->length ); |
|
1762 TrimRightSpaceAndNull( pcdata ); |
|
1763 uri = pcdata.AllocLC(); |
|
1764 CBufBase* dataBuffer = NULL; |
|
1765 |
|
1766 //Get the data chunk from the servers message. The data is set to dataBuffer. |
|
1767 TInt totSizeOfLarge(0); |
|
1768 statusCode = GetChunkL( *uri, item, aContent->meta, dataBuffer, totSizeOfLarge ); |
|
1769 // FOTA |
|
1770 // if ( dataBuffer ) |
|
1771 // { |
|
1772 CleanupStack::PushL( dataBuffer ); |
|
1773 // } |
|
1774 if ( !(statusCode == TNSmlError::ESmlStatusOK||statusCode == TNSmlError::ESmlStatusItemAccepted )) |
|
1775 { |
|
1776 statusID = StatusDataToGenericCommandL( aCmd, aContent, item, statusCode ); |
|
1777 |
|
1778 // If this was the last chunk and there was a size mismatch, send anyway |
|
1779 // a null chunk package to HostServer, so that largeObject handling session ends |
|
1780 // properly. |
|
1781 if ( statusCode == TNSmlError::ESmlStatusSizeMismatch ) |
|
1782 { |
|
1783 iDMModule->UpdateObjectL ( *uri, KNullDesC8, KNullDesC8, statusID, iMoreData ); |
|
1784 } |
|
1785 } |
|
1786 // FOTA end |
|
1787 |
|
1788 else |
|
1789 { |
|
1790 if ( dataBuffer ) |
|
1791 { |
|
1792 TPtr8 objectData( dataBuffer->Ptr(0) ); |
|
1793 |
|
1794 HBufC8* metaType = MetaTypeInUtf8LC( item->meta ); |
|
1795 if ( metaType->Length() == 0 ) |
|
1796 { |
|
1797 CleanupStack::PopAndDestroy(); // metaType |
|
1798 metaType = MetaTypeInUtf8LC( aContent->meta ); |
|
1799 } |
|
1800 if ( aCmd == KNSmlAgentAdd ) |
|
1801 { |
|
1802 statusID = StatusDataToGenericCommandL( aCmd, aContent, item, statusCode ); |
|
1803 //Set p& S key to EAddCmd |
|
1804 RProperty::Define(KPSUidNSmlDMSyncAgent, |
|
1805 KNSmlDMCmdAddOnExistingNodeorLeafKey, RProperty::EInt, |
|
1806 KReadPolicy, KWritePolicy ); |
|
1807 RProperty::Set(KPSUidNSmlDMSyncAgent, |
|
1808 KNSmlDMCmdAddOnExistingNodeorLeafKey, EAddCmd ); |
|
1809 iDMModule->AddObjectL( *uri, objectData, *metaType, statusID,iMoreData ); |
|
1810 } |
|
1811 else if ( aCmd == KNSmlAgentReplace ) |
|
1812 { |
|
1813 statusID = StatusDataToGenericCommandL( aCmd, aContent, item, statusCode); |
|
1814 // FOTA |
|
1815 if ( totSizeOfLarge ) |
|
1816 { |
|
1817 // The total size of the large object is forwarded only for FOTA adapter. |
|
1818 iDMModule->UpdateObjectL( *uri, objectData, *metaType, statusID, iMoreData, totSizeOfLarge ); |
|
1819 } |
|
1820 else |
|
1821 { |
|
1822 iDMModule->UpdateObjectL( *uri, objectData, *metaType, statusID, iMoreData ); |
|
1823 } |
|
1824 // FOTA end |
|
1825 } |
|
1826 else if ( aCmd == KNSmlAgentDelete ) |
|
1827 { |
|
1828 statusID = StatusDataToGenericCommandL( aCmd, aContent, item, statusCode); |
|
1829 iDMModule->DeleteObjectL( *uri, statusID ); |
|
1830 } |
|
1831 // FOTA |
|
1832 /* |
|
1833 if ( aCmd == KNSmlAgentExec ) |
|
1834 { |
|
1835 statusID = StatusDataToGenericCommandL( aCmd, aContent, item, statusCode); |
|
1836 iDMModule->ExecuteObjectL( *uri, objectData, *metaType, statusID,iMoreData ); |
|
1837 } |
|
1838 */ |
|
1839 // FOTA end |
|
1840 else if ( aCmd == KNSmlAgentCopy ) |
|
1841 { |
|
1842 statusID = StatusDataToGenericCommandL( aCmd, aContent, item, statusCode); |
|
1843 TPtr8 pcdataSourceUri( (TUint8*) item->source->locURI->content, item->source->locURI->length, item->source->locURI->length ); |
|
1844 TrimRightSpaceAndNull( pcdataSourceUri ); |
|
1845 |
|
1846 iDMModule->CopyObjectL( *uri, pcdataSourceUri, *metaType, statusID ); |
|
1847 } |
|
1848 // FOTA : Pop and destroy for databuffer moved forward |
|
1849 CleanupStack::PopAndDestroy(); // metaType |
|
1850 // FOTA end |
|
1851 if ( iDMAtomic ) |
|
1852 { |
|
1853 iStatusToServer->SetAtomicOrSequenceId( statusID, iDMAtomicID ); |
|
1854 } |
|
1855 } |
|
1856 } |
|
1857 // FOTA : Pop and destroy for databuffer added |
|
1858 CleanupStack::PopAndDestroy(2); // databuffer, uri |
|
1859 // FOTA end |
|
1860 if(itemList) |
|
1861 { |
|
1862 itemList = itemList->next; |
|
1863 if(itemList) |
|
1864 { |
|
1865 item=itemList->item; |
|
1866 } |
|
1867 else |
|
1868 { |
|
1869 item=0; |
|
1870 } |
|
1871 } |
|
1872 else |
|
1873 { |
|
1874 item = 0; |
|
1875 } |
|
1876 } |
|
1877 } |
|
1878 |
|
1879 // FOTA |
|
1880 // --------------------------------------------------------- |
|
1881 // CNSmlDMCmds::ProcessExecCmdL() |
|
1882 // Process the exec structure sent by the remote server. |
|
1883 // @param aExec. The exec command structure, accordant with the dtd. |
|
1884 // --------------------------------------------------------- |
|
1885 // |
|
1886 void CNSmlDMCmds::ProcessExecCmdL ( SmlExec_t* aExec ) |
|
1887 { |
|
1888 if ( aExec->cmdID->length == 0 ) |
|
1889 { |
|
1890 StatusDataToCommandL ( KNSmlAgentExec, aExec->cmdID, aExec->flags, NULL, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1891 iAgent->Interrupt ( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1892 return; |
|
1893 } |
|
1894 TNSmlError::TNSmlSyncMLStatusCode statusCode ( TNSmlError::ESmlStatusOK ); |
|
1895 |
|
1896 if ( iAgent->Interrupted() ) |
|
1897 { |
|
1898 statusCode = TNSmlError::ESmlStatusCommandFailed; |
|
1899 } |
|
1900 else if ( iServerAuth->Challenged() ) |
|
1901 { |
|
1902 statusCode = TNSmlError::ESmlStatusClientAuthenticationRequired; |
|
1903 } |
|
1904 else if ( iDMNotExecuted ) |
|
1905 { |
|
1906 statusCode = TNSmlError::ESmlStatusNotExecuted; |
|
1907 } |
|
1908 else if ( !aExec->item->target || !aExec->item->target->locURI ) |
|
1909 { |
|
1910 statusCode = TNSmlError::ESmlStatusIncompleteCommand; |
|
1911 } |
|
1912 |
|
1913 if ( statusCode != TNSmlError::ESmlStatusOK ) |
|
1914 { |
|
1915 StatusDataToCommandL ( KNSmlAgentExec, aExec->cmdID, aExec->flags, aExec->item, statusCode ); |
|
1916 return; |
|
1917 } |
|
1918 |
|
1919 TPtr8 pcdata ( (TUint8*) aExec->item->target->locURI->content, aExec->item->target->locURI->length, aExec->item->target->locURI->length ); |
|
1920 TrimRightSpaceAndNull ( pcdata ); |
|
1921 HBufC8* uri = pcdata.AllocLC(); |
|
1922 CBufBase* dataBuffer = NULL; |
|
1923 |
|
1924 //Get the data chunk from the servers message. The data is set to dataBuffer. |
|
1925 TInt dummy(0); |
|
1926 statusCode = GetChunkL ( *uri, aExec->item, aExec->meta, dataBuffer, dummy ); |
|
1927 CleanupStack::PushL( dataBuffer ); |
|
1928 |
|
1929 if ( !( statusCode == TNSmlError::ESmlStatusOK || statusCode == TNSmlError::ESmlStatusItemAccepted ) ) |
|
1930 { |
|
1931 StatusDataToCommandL ( KNSmlAgentExec, aExec->cmdID, aExec->flags, aExec->item, statusCode ); |
|
1932 } |
|
1933 else |
|
1934 { |
|
1935 if ( dataBuffer ) |
|
1936 { |
|
1937 HBufC8* metaType = MetaTypeInUtf8LC( aExec->item->meta ); |
|
1938 if ( metaType->Length() == 0 ) |
|
1939 { |
|
1940 CleanupStack::PopAndDestroy(); // metaType |
|
1941 metaType = MetaTypeInUtf8LC ( aExec->meta ); |
|
1942 } |
|
1943 TInt statusID ( 0 ); |
|
1944 statusID = StatusDataToCommandL ( KNSmlAgentExec, aExec->cmdID, aExec->flags, aExec->item, statusCode ); |
|
1945 if ( aExec->correlator ) |
|
1946 { |
|
1947 TPtr8 correlator ( (TUint8*) aExec->correlator->content, aExec->correlator->length, aExec->correlator->length ); |
|
1948 TrimRightSpaceAndNull ( correlator ); |
|
1949 HBufC8* execCorrelator = correlator.AllocLC(); |
|
1950 iDMModule->ExecuteObjectL ( *uri, dataBuffer->Ptr(0), *metaType, statusID, *execCorrelator, iMoreData ); |
|
1951 CleanupStack::PopAndDestroy(); // execCorrelator |
|
1952 } |
|
1953 else |
|
1954 { |
|
1955 iDMModule->ExecuteObjectL ( *uri, dataBuffer->Ptr(0), *metaType, statusID, KNullDesC8(), iMoreData ); |
|
1956 } |
|
1957 CleanupStack::PopAndDestroy(); // metaType |
|
1958 if ( iDMAtomic ) |
|
1959 { |
|
1960 iStatusToServer->SetAtomicOrSequenceId ( statusID, iDMAtomicID ); |
|
1961 } |
|
1962 } |
|
1963 } |
|
1964 CleanupStack::PopAndDestroy(2); // databuffer, uri |
|
1965 } |
|
1966 |
|
1967 // FOTA end |
|
1968 // --------------------------------------------------------- |
|
1969 // CNSmlDMCmds::ProcessAtomicL() |
|
1970 // |
|
1971 // --------------------------------------------------------- |
|
1972 void CNSmlDMCmds::ProcessAtomicL( SmlAtomic_t* aAtomic ) |
|
1973 { |
|
1974 TInt statusID = InitStatusToAtomicOrSequenceL( KNSmlAgentAtomic, aAtomic ); |
|
1975 if ( iAgent->Interrupted() ) |
|
1976 { |
|
1977 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1978 return; |
|
1979 } |
|
1980 if ( iServerAuth->Challenged() ) |
|
1981 { |
|
1982 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusClientAuthenticationRequired ); |
|
1983 return; |
|
1984 } |
|
1985 iDMAtomicID++; |
|
1986 iStatusToServer->SetAtomicOrSequenceId( statusID, iDMAtomicID ); |
|
1987 iDMModule->StartTransactionL(); |
|
1988 iDMAtomic = ETrue; |
|
1989 } |
|
1990 // --------------------------------------------------------- |
|
1991 // CNSmlDMCmds::ProcessEndAtomicL() |
|
1992 // |
|
1993 // --------------------------------------------------------- |
|
1994 void CNSmlDMCmds::ProcessEndAtomicL() |
|
1995 { |
|
1996 if ( (!iAgent->Interrupted()) && ( !iServerAuth->Challenged() ) ) |
|
1997 { |
|
1998 iDMModule->CommitTransactionL(); |
|
1999 } |
|
2000 iDMAtomic = EFalse; |
|
2001 if ( !iDMSequence ) |
|
2002 { |
|
2003 iDMNotExecuted = EFalse; |
|
2004 } |
|
2005 } |
|
2006 |
|
2007 // --------------------------------------------------------- |
|
2008 // CNSmlDMCmds::ProcessSequenceL() |
|
2009 // |
|
2010 // --------------------------------------------------------- |
|
2011 void CNSmlDMCmds::ProcessSequenceL( SmlSequence_t* aSequence ) |
|
2012 { |
|
2013 TInt statusID = InitStatusToAtomicOrSequenceL( KNSmlAgentSequence, aSequence ); |
|
2014 if ( iAgent->Interrupted() ) |
|
2015 { |
|
2016 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
2017 return; |
|
2018 } |
|
2019 if ( iServerAuth->Challenged() ) |
|
2020 { |
|
2021 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusClientAuthenticationRequired ); |
|
2022 return; |
|
2023 } |
|
2024 if ( iDMNotExecuted ) |
|
2025 { |
|
2026 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusNotExecuted ); |
|
2027 return; |
|
2028 } |
|
2029 iDMSequenceID++; |
|
2030 iStatusToServer->SetAtomicOrSequenceId( statusID, iDMSequenceID ); |
|
2031 iDMSequence = ETrue; |
|
2032 } |
|
2033 // --------------------------------------------------------- |
|
2034 // CNSmlDMCmds::ProcessEndSequence() |
|
2035 // |
|
2036 // --------------------------------------------------------- |
|
2037 void CNSmlDMCmds::ProcessEndSequence() |
|
2038 { |
|
2039 iDMSequence = EFalse; |
|
2040 if ( !iDMAtomic ) |
|
2041 { |
|
2042 iDMNotExecuted = EFalse; |
|
2043 } |
|
2044 } |
|
2045 |
|
2046 // --------------------------------------------------------- |
|
2047 // CNSmlDMCmds::ProcessEndSync() |
|
2048 // |
|
2049 // --------------------------------------------------------- |
|
2050 void CNSmlDMCmds::ProcessEndSyncL() |
|
2051 { |
|
2052 } |
|
2053 |
|
2054 // --------------------------------------------------------- |
|
2055 // CNSmlDMCmds::DoEndMessageL |
|
2056 // Generates end tag of SyncML element and possble final flag in SyncBody |
|
2057 // and calls Ref.Toolkit parser to generate xml |
|
2058 // --------------------------------------------------------- |
|
2059 void CNSmlDMCmds::DoEndMessageL( TBool aFinal ) |
|
2060 { |
|
2061 TInt ret; |
|
2062 if ( aFinal ) |
|
2063 { |
|
2064 ret = iGenerator->smlEndMessage( ETrue ); |
|
2065 } |
|
2066 else |
|
2067 { |
|
2068 ret = iGenerator->smlEndMessage( EFalse ); |
|
2069 } |
|
2070 if ( ret != KWBXMLGeneratorOk ) |
|
2071 { |
|
2072 User::Leave( ret ); |
|
2073 } |
|
2074 } |
|
2075 |
|
2076 // --------------------------------------------------------- |
|
2077 // CNSmlDMCmds::EndOfServerMessageL() |
|
2078 // |
|
2079 // --------------------------------------------------------- |
|
2080 void CNSmlDMCmds::EndOfServerMessageL() const |
|
2081 { |
|
2082 iDMModule->EndMessageL(); |
|
2083 } |
|
2084 |
|
2085 |
|
2086 |
|
2087 // --------------------------------------------------------- |
|
2088 // CNSmlDMCmds::SetResultsL() |
|
2089 // |
|
2090 // --------------------------------------------------------- |
|
2091 void CNSmlDMCmds::SetResultsL( const TInt aResultsRef, const CBufBase& aObject, const TDesC8& aType, const TDesC8& aFormat,TInt aTotalSize ) |
|
2092 { |
|
2093 if ( !iDMDevInfoResults ) |
|
2094 { |
|
2095 if ( iServerMaxObjectSize > 0 && aObject.Size() > iServerMaxObjectSize ) |
|
2096 { |
|
2097 iLargeObjectTotalSize = 0; |
|
2098 iBytesSent=0; |
|
2099 iStatusToServer->SetStatusCodeL( iResultsToServer->StatusID( aResultsRef ), TNSmlError::TNSmlSyncMLStatusCode( TNSmlError::ESmlStatusEntityTooLarge ), ETrue ); |
|
2100 } |
|
2101 else |
|
2102 { |
|
2103 iBytesSent=0; |
|
2104 iLargeObjectTotalSize = aTotalSize; |
|
2105 iResultsToServer->AddItemL( aResultsRef, aObject, aType, aFormat ); |
|
2106 } |
|
2107 } |
|
2108 else |
|
2109 { |
|
2110 iDMDevInfo->iResults = ETrue; |
|
2111 delete iDMDevInfo->iFormat; |
|
2112 iDMDevInfo->iFormat = NULL; |
|
2113 delete iDMDevInfo->iType; |
|
2114 iDMDevInfo->iType = NULL; |
|
2115 delete iDMDevInfo->iObject; |
|
2116 iDMDevInfo->iObject = NULL; |
|
2117 iDMDevInfo->iFormat = aFormat.AllocL(); |
|
2118 iDMDevInfo->iType = aType.AllocL(); |
|
2119 iDMDevInfo->iObject = CONST_CAST( CBufBase&, aObject ).Ptr(0).AllocL(); |
|
2120 } |
|
2121 } |
|
2122 |
|
2123 // --------------------------------------------------------- |
|
2124 // CNSmlDMCmds::SetStatusL() |
|
2125 // |
|
2126 // --------------------------------------------------------- |
|
2127 void CNSmlDMCmds::SetStatusL( TInt aStatusRef, TInt aStatusCode ) |
|
2128 { |
|
2129 if ( !iDMDevInfoResults ) |
|
2130 { |
|
2131 iStatusToServer->SetStatusCodeL( aStatusRef, aStatusCode ); |
|
2132 /*if ( iDMSequence ) |
|
2133 { |
|
2134 if ( aStatusCode >= 300 || aStatusCode < 200 ) |
|
2135 { |
|
2136 iDMNotExecuted = ETrue; |
|
2137 } |
|
2138 }*/ |
|
2139 if ( iDMAtomic ) |
|
2140 { |
|
2141 if ( aStatusCode >= 300 || aStatusCode < 200 ) |
|
2142 { |
|
2143 iStatusToServer->SetStatusCodeToAtomicOrSequenceCmdL( iDMAtomicID, TNSmlError::ESmlStatusAtomicFailed, KNSmlAgentAtomic ); |
|
2144 } |
|
2145 } |
|
2146 } |
|
2147 if ( ( aStatusCode == TNSmlError::TNSmlSyncMLStatusCode( TNSmlError::ESmlStatusDeviceFull ) ) && |
|
2148 (!iDMDeviceFullWritten ) ) |
|
2149 { |
|
2150 iAgent->WriteWarningL( -1, TNSmlError::ESmlStatusDeviceFull ); |
|
2151 iDMDeviceFullWritten = ETrue; |
|
2152 } |
|
2153 } |
|
2154 |
|
2155 // ----------------------------------------------------------------------------- |
|
2156 // CNSmlDMCmds::GetChunkL |
|
2157 // Buffer the received item and handles large objects. |
|
2158 // ----------------------------------------------------------------------------- |
|
2159 // |
|
2160 TNSmlError::TNSmlSyncMLStatusCode CNSmlDMCmds::GetChunkL(TDesC8& aLargeUri, |
|
2161 const SmlItem_t* aCurrentItem, |
|
2162 const SmlPcdata_t* aMetaInCommand, |
|
2163 CBufBase*& aBuffer, |
|
2164 // FOTA |
|
2165 TInt& aTotSizeOfLarge |
|
2166 // FOTA end |
|
2167 ) |
|
2168 { |
|
2169 iItemSizeInStream = 0; |
|
2170 TNSmlError::TNSmlSyncMLStatusCode status( TNSmlError::ESmlStatusOK ); |
|
2171 iMoreData = IsFlagSet( aCurrentItem->flags, SmlMoreData_f ); |
|
2172 |
|
2173 // check that the previously received chunk belongs to the same item |
|
2174 if ( iAmountReceived != 0 ) |
|
2175 { |
|
2176 if (iLargeObjectUri&&iLargeObjectUri->Compare(aLargeUri) ) |
|
2177 { |
|
2178 iAgent->SetEndOfDataAlertRequest(); |
|
2179 delete iRecBuf; |
|
2180 iRecBuf = NULL; |
|
2181 delete iLargeObjectUri; |
|
2182 iLargeObjectUri=NULL; |
|
2183 iServerLargeObjectSize = 0; |
|
2184 } |
|
2185 } |
|
2186 |
|
2187 if ( iMoreData && ( iAmountReceived == 0 ) ) |
|
2188 { |
|
2189 iServerLargeObjectSize = ServerObjectSize( aCurrentItem->meta ); |
|
2190 |
|
2191 if ( iServerLargeObjectSize == 0 ) |
|
2192 { |
|
2193 iServerLargeObjectSize = ServerObjectSize( aMetaInCommand ); |
|
2194 } |
|
2195 // FOTA |
|
2196 if ( iServerLargeObjectSize == 0 ) |
|
2197 { |
|
2198 status = TNSmlError::ESmlStatusSizeRequired; |
|
2199 } |
|
2200 // FOTA end |
|
2201 iItemSizeInStream = iServerLargeObjectSize; |
|
2202 // FOTA |
|
2203 aTotSizeOfLarge = iServerLargeObjectSize; |
|
2204 // FOTA end |
|
2205 delete iLargeObjectUri; |
|
2206 iLargeObjectUri=NULL; |
|
2207 iLargeObjectUri = aLargeUri.AllocL(); |
|
2208 } |
|
2209 |
|
2210 iRecBuf = CBufFlat::NewL( 1 ); |
|
2211 |
|
2212 // buffer data |
|
2213 if ( aCurrentItem->data ) |
|
2214 { |
|
2215 if ( iItemSizeInStream == 0 ) |
|
2216 { |
|
2217 iItemSizeInStream = aCurrentItem->data->length; |
|
2218 } |
|
2219 |
|
2220 if ( aCurrentItem->data->content ) |
|
2221 { |
|
2222 TPtr8 data( static_cast<TUint8*>( aCurrentItem->data->content ), aCurrentItem->data->length, aCurrentItem->data->length ); |
|
2223 iRecBuf->InsertL( iRecBuf->Size(), data ); |
|
2224 } |
|
2225 } |
|
2226 else |
|
2227 { |
|
2228 aBuffer = iRecBuf; |
|
2229 iRecBuf = NULL; |
|
2230 return status; |
|
2231 } |
|
2232 |
|
2233 // last / only chunk |
|
2234 if ( !iMoreData ) |
|
2235 { |
|
2236 TBool notFirst( iAmountReceived != 0 ); |
|
2237 iAmountReceived += aCurrentItem->data->length; |
|
2238 |
|
2239 if ( notFirst && ( iAmountReceived != iServerLargeObjectSize ) ) |
|
2240 { |
|
2241 status = TNSmlError::ESmlStatusSizeMismatch; |
|
2242 delete iRecBuf; |
|
2243 iRecBuf = NULL; |
|
2244 } |
|
2245 |
|
2246 iAmountReceived = 0; |
|
2247 } |
|
2248 // middle chunk |
|
2249 else |
|
2250 { |
|
2251 iAmountReceived += aCurrentItem->data->length; |
|
2252 // FOTA |
|
2253 if ( status == TNSmlError::ESmlStatusOK ) |
|
2254 { |
|
2255 status = TNSmlError::ESmlStatusItemAccepted; |
|
2256 } |
|
2257 // FOTA end |
|
2258 } |
|
2259 |
|
2260 aBuffer = iRecBuf; |
|
2261 iRecBuf = NULL; |
|
2262 |
|
2263 return status; |
|
2264 } |
|
2265 |
|
2266 // --------------------------------------------------------- |
|
2267 // CNSmlDMCmds::UpdateErrorStatusCode() |
|
2268 // Updates the status code with proper error |
|
2269 // --------------------------------------------------------------------------------------------------------------- |
|
2270 void CNSmlDMCmds::UpdateErrorStatusCode(SmlItem_t* aItem, |
|
2271 TNSmlError::TNSmlSyncMLStatusCode& aStatusCode ) |
|
2272 { |
|
2273 if ( iAgent->Interrupted() ) |
|
2274 { |
|
2275 aStatusCode = TNSmlError::ESmlStatusCommandFailed; |
|
2276 } |
|
2277 if ( iServerAuth->Challenged() ) |
|
2278 { |
|
2279 aStatusCode = TNSmlError::ESmlStatusClientAuthenticationRequired; |
|
2280 } |
|
2281 if ( iDMNotExecuted ) |
|
2282 { |
|
2283 aStatusCode = TNSmlError::ESmlStatusNotExecuted; |
|
2284 } |
|
2285 // target |
|
2286 if ( !aItem->target||!aItem->target->locURI ) |
|
2287 { |
|
2288 aStatusCode = TNSmlError::ESmlStatusIncompleteCommand; |
|
2289 } |
|
2290 } |
|
2291 |
|
2292 // --------------------------------------------------------------------------------------------------------------- |
|
2293 // CNSmlDMCmds::AlertChoiceItemsLC() |
|
2294 // Retrieves the choice alerts information |
|
2295 // --------------------------------------------------------------------------------------------------------------- |
|
2296 HBufC8* CNSmlDMCmds::AlertChoiceItemsLC(SmlItemList_t* aItemList,HBufC8*& aLengthBuf ,TInt& aNumItems ) const |
|
2297 { |
|
2298 /*cleanupstack contains |
|
2299 * top : tempdata |
|
2300 * : unicodeData |
|
2301 * bottom: aLengthBuf |
|
2302 */ |
|
2303 const TChar KDRSeparator('-'); |
|
2304 const TChar KChoiceItemSeparator(','); |
|
2305 HBufC8* unicodeData = HBufC8::NewLC(200); |
|
2306 HBufC8* tempdata = NULL; |
|
2307 HBufC8* lengthbuf = aLengthBuf; |
|
2308 TBuf<20> lennum; |
|
2309 SmlItemList_t* temp; |
|
2310 if ( aItemList )//Not null |
|
2311 { |
|
2312 if(aItemList->next)//removing header of dialog |
|
2313 { |
|
2314 temp = aItemList->next; |
|
2315 while(temp->next) |
|
2316 { |
|
2317 if ( temp->next->item ) |
|
2318 { |
|
2319 if ( temp->next->item->data ) |
|
2320 { |
|
2321 if ( temp->next->item->data->content ) |
|
2322 { |
|
2323 TPtr8 data( (TUint8*) temp->next->item->data->content, temp->next->item->data->length, temp->next->item->data->length ); |
|
2324 TrimRightSpaceAndNull( data ); |
|
2325 tempdata = data.AllocLC(); |
|
2326 TInt length = data.Length();//item length |
|
2327 //add length to buffer and add comma |
|
2328 if(lengthbuf->Des().MaxLength() > (lengthbuf->Des().Length() + 5/*bytes*/) ) |
|
2329 { |
|
2330 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200 |
|
2331 { |
|
2332 lennum.Num(KSyncMLMaxChoiceItemLength); |
|
2333 lengthbuf->Des().Append(lennum); |
|
2334 lengthbuf->Des().Append(KChoiceItemSeparator); |
|
2335 } |
|
2336 else |
|
2337 { |
|
2338 lennum.Num(length); |
|
2339 lengthbuf->Des().Append(lennum); |
|
2340 lengthbuf->Des().Append(KChoiceItemSeparator); |
|
2341 } |
|
2342 } |
|
2343 else |
|
2344 { |
|
2345 //Pop the aLengthBuf from cleanupstack and realloc |
|
2346 CleanupStack::Pop(3); //tempdata,unicodeData,aLengthBuf |
|
2347 lengthbuf = lengthbuf->ReAllocL(lengthbuf->Des().Length() + 100); |
|
2348 CleanupStack::PushL(lengthbuf); |
|
2349 CleanupStack::PushL(unicodeData); |
|
2350 CleanupStack::PushL(tempdata); |
|
2351 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200 |
|
2352 { |
|
2353 lengthbuf->Des().AppendNum(KSyncMLMaxChoiceItemLength); |
|
2354 lengthbuf->Des().Append(KChoiceItemSeparator); |
|
2355 } |
|
2356 else |
|
2357 { |
|
2358 lengthbuf->Des().AppendNum(length); //Append(length); |
|
2359 lengthbuf->Des().Append(KChoiceItemSeparator); |
|
2360 } |
|
2361 } |
|
2362 if(unicodeData->Des().MaxLength()> (unicodeData->Des().Length() + length)) |
|
2363 { |
|
2364 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200 |
|
2365 { |
|
2366 unicodeData->Des().Append(tempdata->Des().Left(KSyncMLMaxChoiceItemLength)); |
|
2367 } |
|
2368 else |
|
2369 { |
|
2370 unicodeData->Des().Append(tempdata->Des()); |
|
2371 } |
|
2372 } |
|
2373 else |
|
2374 { |
|
2375 CleanupStack::Pop(2);//tempdata,unicodeData |
|
2376 unicodeData = unicodeData->ReAllocL(unicodeData->Des().Length() + length + 200); |
|
2377 CleanupStack::PushL(unicodeData); |
|
2378 CleanupStack::PushL(tempdata); |
|
2379 if(length > KSyncMLMaxChoiceItemLength ) // choice item length restricting to 200 |
|
2380 { |
|
2381 unicodeData->Des().Append(tempdata->Des().Left(KSyncMLMaxChoiceItemLength)); |
|
2382 } |
|
2383 else |
|
2384 { |
|
2385 unicodeData->Des().Append(tempdata->Des()); |
|
2386 } |
|
2387 } |
|
2388 CleanupStack::PopAndDestroy(tempdata); |
|
2389 aNumItems++; |
|
2390 data.Zero(); |
|
2391 } |
|
2392 } |
|
2393 } |
|
2394 temp = temp->next; |
|
2395 } |
|
2396 } |
|
2397 } |
|
2398 _DBG_FILE("CNSmlDMCmds::AlertDataLC: end"); |
|
2399 aLengthBuf = lengthbuf; |
|
2400 return unicodeData; |
|
2401 } |
|
2402 |
|
2403 // --------------------------------------------------------------------------------------------------------------- |
|
2404 // CNSmlDMCmds::FindMaxLength() |
|
2405 // --------------------------------------------------------------------------------------------------------------- |
|
2406 TInt CNSmlDMCmds::FindMaxLength(TInt aSourceLength, TInt aDestLength) |
|
2407 { |
|
2408 TInt length = 0; |
|
2409 if(aSourceLength > aDestLength ) |
|
2410 { |
|
2411 length = aDestLength; |
|
2412 } |
|
2413 else |
|
2414 { |
|
2415 length = aSourceLength; |
|
2416 } |
|
2417 return length; |
|
2418 } |