|
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: DS Sync flow |
|
15 * |
|
16 */ |
|
17 |
|
18 #define SYNCML_V3 |
|
19 // INCLUDE FILES |
|
20 #include <SyncMLObservers.h> |
|
21 #include <SyncMLNotifierParams.h> |
|
22 #include <SyncMLNotifier.h> |
|
23 #include <nsmlconstants.h> |
|
24 #include <nsmldebug.h> |
|
25 #include <nsmlphoneinfo.h> |
|
26 #include <nsmlunicodeconverter.h> |
|
27 // common includes with DM |
|
28 #include "nsmlcliagconstants.h" |
|
29 #include "NSmlCmdsBase.h" |
|
30 #include "NSmlAgentBase.h" |
|
31 #include "NSmlStatusContainer.h" |
|
32 #include "NSmlResponseController.h" |
|
33 #include "NSmlURI.h" |
|
34 #include "WBXMLSyncMLGenerator.h" |
|
35 #include "WBXMLSyncMLParser.h" |
|
36 #include "WBXMLDevInfGenerator.h" |
|
37 #include "WBXMLDevInfParser.h" |
|
38 #include "WBXMLGeneratorError.h" |
|
39 #include "WBXMLParser.h" |
|
40 #include "WBXMLParserError.h" |
|
41 #include "smldtd.h" |
|
42 #include "smldef.h" |
|
43 // DS specific includes |
|
44 #include "nsmldsagconstants.h" |
|
45 #include "NSmlDSCmds.h" |
|
46 #include "nsmldscontent.h" |
|
47 #include "NSmlDSAgent.h" |
|
48 #include "nsmldserror.h" |
|
49 #include "nsmlfilter.h" |
|
50 #include "nsmldssettings.h" |
|
51 #include "nsmldsbatchbuffer.h" |
|
52 #include "nsmldshostclient.h" |
|
53 |
|
54 |
|
55 #ifndef __WINS__ |
|
56 // This lowers the unnecessary compiler warning (armv5) to remark. |
|
57 // "Warning: #174-D: expression has no effect..." is caused by |
|
58 // DBG_ARGS8 macro in no-debug builds. |
|
59 #pragma diag_remark 174 |
|
60 #endif |
|
61 |
|
62 |
|
63 // CONSTANTS |
|
64 _LIT8( KNSmlRoot, "/" ); |
|
65 |
|
66 // ============================ MEMBER FUNCTIONS =============================== |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CNSmlDSCmds::CNSmlDSCmds() |
|
70 // C++ default constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CNSmlDSCmds::CNSmlDSCmds( CNSmlDSContent& aDSContent, MSyncMLProgressObserver& aDSObserver ) : iDSContent( aDSContent ), iDSObserver( aDSObserver ) |
|
74 { |
|
75 iAtomicModeOn = EFalse; |
|
76 iAtomicId = 0; |
|
77 iAtomicHasFailed = EFalse; |
|
78 iItemOpened = EFalse; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CNSmlDSCmds::ConstructL |
|
83 // Symbian 2nd phase constructor. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CNSmlDSCmds::ConstructL( CNSmlAgentBase* aAgent, const TDesC8& aSessionID, const TDesC8& aVerProto, const TInt aPublicId, const HBufC& aSyncMLUserName, CNSmlURI* aSyncServer, TBool aVersionCheck ) |
|
87 { |
|
88 CNSmlCmdsBase::ConstructL( aAgent, aSessionID, aVerProto, aPublicId, aSyncMLUserName, aSyncServer, aVersionCheck ); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CNSmlDSCmds::NewL |
|
93 // Two-phased constructor. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CNSmlDSCmds* CNSmlDSCmds::NewL( CNSmlAgentBase* aAgent, const TDesC8& aSessionID, const TDesC8& aVerProto, const TInt aPublicId, const HBufC& aSyncMLUserName, CNSmlURI* aSyncServer, CNSmlDSContent& aDSContent, MSyncMLProgressObserver& aDSObserver, TBool aVersionCheck ) |
|
97 { |
|
98 CNSmlDSCmds* self = new ( ELeave ) CNSmlDSCmds( aDSContent, aDSObserver ); |
|
99 CleanupStack::PushL( self ); |
|
100 self->ConstructL( aAgent, aSessionID, aVerProto, aPublicId, aSyncMLUserName, aSyncServer, aVersionCheck ); |
|
101 CleanupStack::Pop(); // self |
|
102 return self; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CNSmlDSCmds::~CNSmlDSCmds |
|
107 // Destructor. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CNSmlDSCmds::~CNSmlDSCmds() |
|
111 { |
|
112 delete iBatchBuffer; |
|
113 delete iDSGetCmdId; |
|
114 delete iDSGetMsgId; |
|
115 delete iDSLargeObjectCmdName; |
|
116 delete iDSDevGenerator; |
|
117 delete iDSPreviousSyncTargetURI; |
|
118 delete iDataBuffer; |
|
119 delete iLargeUid; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CNSmlDSCmds::CommitBatchL |
|
124 // Commits the batched commands and sets their statuses. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CNSmlDSCmds::CommitBatchL() |
|
128 { |
|
129 _DBG_FILE(_S8("CNSmlDSCmds::CommitBatchL : Begin")); |
|
130 if ( !iDSContent.BatchModeOn() ) |
|
131 { |
|
132 return; |
|
133 } |
|
134 |
|
135 RArray<TInt> commitResults; |
|
136 TInt resultCode; |
|
137 |
|
138 iDSContent.CommitBatchL( commitResults, resultCode ); |
|
139 |
|
140 // if the atomic mode is on and committing the batch fails then everyting will be rolled back |
|
141 if ( iAtomicModeOn && resultCode != KErrNone ) |
|
142 { |
|
143 iAtomicHasFailed = ETrue; |
|
144 commitResults.Close(); |
|
145 iBatchModeOn = EFalse; |
|
146 delete iBatchBuffer; |
|
147 iBatchBuffer = NULL; |
|
148 return; |
|
149 } |
|
150 |
|
151 TInt commitIndex( 0 ); |
|
152 |
|
153 for ( TInt batchIndex = 0; batchIndex < iBatchBuffer->Count(); batchIndex++ ) |
|
154 { |
|
155 if ( resultCode != KErrNone ) |
|
156 { |
|
157 iDSContent.IncreaseServerItemsFailed(); |
|
158 |
|
159 iStatusToServer->SetStatusCodeL( iBatchBuffer->StatusEntryId( batchIndex ), TNSmlError::ESmlStatusCommandFailed ); |
|
160 continue; |
|
161 } |
|
162 |
|
163 TInt statusId( KErrNone ); |
|
164 |
|
165 for ( TInt i = 0; i < iBatchBuffer->NumberOfResults( batchIndex ); i++ ) |
|
166 { |
|
167 if ( commitResults[commitIndex] != KErrNone ) |
|
168 { |
|
169 statusId = commitResults[commitIndex]; |
|
170 } |
|
171 |
|
172 ++commitIndex; |
|
173 } |
|
174 |
|
175 // map the status code & set the command's status |
|
176 MapStatusCodeL( batchIndex, statusId ); |
|
177 |
|
178 if ( statusId != KErrNone ) |
|
179 { |
|
180 iStatusToServer->SetStatusCodeL( iBatchBuffer->StatusEntryId( batchIndex ), iBatchBuffer->Status( batchIndex ) ); |
|
181 } |
|
182 } |
|
183 |
|
184 iBatchModeOn = EFalse; |
|
185 delete iBatchBuffer; |
|
186 iBatchBuffer = NULL; |
|
187 _DBG_FILE(_S8("CNSmlDSCmds::CommitBatchL : End")); |
|
188 commitResults.Close(); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CNSmlDSCmds::MapStatusCode |
|
193 // Performs mapping between datastore operation return values and SyncML error |
|
194 // codes. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CNSmlDSCmds::MapStatusCodeL( const TInt aIndex, const TInt aStatus ) |
|
198 { |
|
199 TBool commandOk( EFalse ); |
|
200 |
|
201 if ( iBatchBuffer->Command( aIndex ) == KNSmlAgentAdd ) |
|
202 { |
|
203 switch ( aStatus ) |
|
204 { |
|
205 case KErrNone: |
|
206 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusItemAdded ); |
|
207 iDSContent.IncreaseServerItemsAdded(); |
|
208 commandOk = ETrue; |
|
209 |
|
210 if ( !iAtomicModeOn ) |
|
211 { |
|
212 iDSContent.CreateNewMapItemL( iBatchBuffer->Uid( aIndex ), iBatchBuffer->GUid( aIndex ), 0 ); |
|
213 } |
|
214 else |
|
215 { |
|
216 iDSContent.CreateNewMapItemL( iBatchBuffer->Uid( aIndex ), iBatchBuffer->GUid( aIndex ), iAtomicId ); |
|
217 } |
|
218 break; |
|
219 |
|
220 case KErrDiskFull: |
|
221 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusDeviceFull ); |
|
222 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
223 break; |
|
224 |
|
225 case KErrNotSupported: |
|
226 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
227 break; |
|
228 |
|
229 default: |
|
230 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusCommandFailed ); |
|
231 break; |
|
232 } |
|
233 } |
|
234 else if ( iBatchBuffer->Command( aIndex ) == KNSmlAgentReplace ) |
|
235 { |
|
236 switch ( aStatus ) |
|
237 { |
|
238 case KErrNone: |
|
239 iDSContent.IncreaseServerItemsChanged(); |
|
240 commandOk = ETrue; |
|
241 break; |
|
242 |
|
243 case KErrNotFound: |
|
244 { |
|
245 TSmlDbItemUid newLUid; |
|
246 |
|
247 TInt retval = iDSContent.CreateItemL( newLUid, |
|
248 iBatchBuffer->ItemData( aIndex ).Size(), |
|
249 iBatchBuffer->MimeType( aIndex ), |
|
250 iBatchBuffer->MimeVersion( aIndex ), |
|
251 iBatchBuffer->Parent( aIndex ) ); |
|
252 |
|
253 if ( retval == KErrNone ) |
|
254 { |
|
255 TRAP( retval, iDSContent.WriteItemL( iBatchBuffer->ItemData( aIndex ) ) ); |
|
256 } |
|
257 |
|
258 if ( retval == KErrNone ) |
|
259 { |
|
260 retval = iDSContent.CommitItemL(); |
|
261 } |
|
262 |
|
263 switch( retval ) |
|
264 { |
|
265 case KErrNone: |
|
266 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusItemAdded ); |
|
267 |
|
268 iDSContent.IncreaseServerItemsAdded(); |
|
269 commandOk = ETrue; |
|
270 |
|
271 if ( !iAtomicModeOn ) |
|
272 { |
|
273 iDSContent.CreateNewMapItemL( newLUid, iBatchBuffer->GUid( aIndex ), 0 ); |
|
274 } |
|
275 else |
|
276 { |
|
277 iDSContent.CreateNewMapItemL( newLUid, iBatchBuffer->GUid( aIndex ), iAtomicId ); |
|
278 } |
|
279 break; |
|
280 |
|
281 case KErrDiskFull: |
|
282 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusDeviceFull ); |
|
283 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
284 break; |
|
285 |
|
286 case KErrNotSupported: |
|
287 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
288 break; |
|
289 |
|
290 default: |
|
291 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusCommandFailed ); |
|
292 break; |
|
293 } |
|
294 } |
|
295 break; |
|
296 |
|
297 case KErrDiskFull: |
|
298 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusDeviceFull ); |
|
299 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
300 break; |
|
301 |
|
302 case KErrNotSupported: |
|
303 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
304 break; |
|
305 |
|
306 default: |
|
307 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusCommandFailed ); |
|
308 break; |
|
309 } |
|
310 } |
|
311 else if ( iBatchBuffer->Command( aIndex ) == KNSmlAgentDelete ) |
|
312 { |
|
313 switch ( aStatus ) |
|
314 { |
|
315 case KErrNone: |
|
316 iDSContent.IncreaseServerItemsDeleted(); |
|
317 commandOk = ETrue; |
|
318 break; |
|
319 |
|
320 case KErrNotFound: |
|
321 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusItemIsNotDeleted ); |
|
322 break; |
|
323 |
|
324 case KErrDiskFull: |
|
325 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusDeviceFull ); |
|
326 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
327 break; |
|
328 |
|
329 case KErrNotSupported: |
|
330 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
331 break; |
|
332 |
|
333 default: |
|
334 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusCommandFailed ); |
|
335 break; |
|
336 } |
|
337 } |
|
338 else if ( iBatchBuffer->Command( aIndex ) == KNSmlAgentMove ) |
|
339 { |
|
340 switch ( aStatus ) |
|
341 { |
|
342 case KErrNone: |
|
343 iDSContent.IncreaseServerItemsMoved(); |
|
344 commandOk = ETrue; |
|
345 break; |
|
346 |
|
347 case KErrDiskFull: |
|
348 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusDeviceFull ); |
|
349 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
350 break; |
|
351 |
|
352 case KErrNotSupported: |
|
353 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
354 break; |
|
355 |
|
356 default: |
|
357 iBatchBuffer->SetStatus( aIndex, TNSmlError::ESmlStatusMoveFailed ); |
|
358 break; |
|
359 } |
|
360 } |
|
361 |
|
362 if ( !commandOk ) |
|
363 { |
|
364 iDSContent.IncreaseServerItemsFailed(); |
|
365 } |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CNSmlDSCmds::DoAlertL |
|
370 // Makes an Alert element and calls the parser to generate XML. |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 void CNSmlDSCmds::DoAlertL( const TDesC8& aAlertCode, TTime* aLastSyncAnchor, TTime* aNextSyncAnchor ) |
|
374 { |
|
375 SmlAlert_t* alert = new ( ELeave ) SmlAlert_t; |
|
376 CleanupStack::PushL( alert ); |
|
377 |
|
378 // element type |
|
379 alert->elementType = SML_PE_ALERT; |
|
380 |
|
381 // CmdID element |
|
382 DoCmdIdL( alert->cmdID ); |
|
383 |
|
384 // Alert code to Data element |
|
385 PcdataNewL ( alert->data, aAlertCode ); |
|
386 alert->itemList = new ( ELeave ) SmlItemList_t; |
|
387 alert->itemList->item = new ( ELeave ) SmlItem_t; |
|
388 |
|
389 // Target and Source elements |
|
390 if ( aAlertCode == KNSmlDSAgentResultAlert || aAlertCode == KNSmlDSAgentNextMessage || aAlertCode == KNSmlDSAgentNoEndOfData ) |
|
391 { |
|
392 DoTargetL( alert->itemList->item->target, iSentSyncHdrTarget->HostName() ); |
|
393 DoSourceL( alert->itemList->item->source, iSentSyncHdrSource->HostName() ); |
|
394 } |
|
395 else |
|
396 { |
|
397 DoTargetWithFilterL( alert->itemList->item->target, iDSContent.RemoteDatabase()->Database() ); |
|
398 DoSourceL( alert->itemList->item->source, iDSContent.LocalDatabase()->Database() ); |
|
399 } |
|
400 |
|
401 // Anchor/Last and Anchor/Next in the Meta Element |
|
402 if ( aLastSyncAnchor && aNextSyncAnchor ) |
|
403 { |
|
404 HBufC8* lastAnchor = HBufC8::NewLC( KNSmlDSAgentAnchorDateFormat.iTypeLength ); |
|
405 HBufC8* nextAnchor = HBufC8::NewLC( KNSmlDSAgentAnchorDateFormat.iTypeLength ); |
|
406 |
|
407 if ( *aLastSyncAnchor != TTime( 0 ) ) |
|
408 { |
|
409 lastAnchor->Des().Format( KNSmlDSAgentAnchorDateFormat, |
|
410 aLastSyncAnchor->DateTime().Year(), |
|
411 aLastSyncAnchor->DateTime().Month() + 1, |
|
412 aLastSyncAnchor->DateTime().Day() + 1, |
|
413 aLastSyncAnchor->DateTime().Hour(), |
|
414 aLastSyncAnchor->DateTime().Minute(), |
|
415 aLastSyncAnchor->DateTime().Second() ); |
|
416 } |
|
417 |
|
418 if ( *aNextSyncAnchor != TTime( 0 ) ) |
|
419 { |
|
420 nextAnchor->Des().Format( KNSmlDSAgentAnchorDateFormat, |
|
421 aNextSyncAnchor->DateTime().Year(), |
|
422 aNextSyncAnchor->DateTime().Month() + 1, |
|
423 aNextSyncAnchor->DateTime().Day() + 1, |
|
424 aNextSyncAnchor->DateTime().Hour(), |
|
425 aNextSyncAnchor->DateTime().Minute(), |
|
426 aNextSyncAnchor->DateTime().Second() ); |
|
427 } |
|
428 |
|
429 if ( ( *aLastSyncAnchor != TTime( 0 ) ) || ( *aNextSyncAnchor != TTime( 0 ) ) ) |
|
430 { |
|
431 SmlMetInfMetInf_t* metInf; |
|
432 DoMetInfLC( metInf ); |
|
433 DoAnchorsL( *metInf, lastAnchor, nextAnchor ); |
|
434 DoMetaL( alert->itemList->item->meta, metInf ); |
|
435 CleanupStack::Pop(); // metInf |
|
436 } |
|
437 |
|
438 CleanupStack::PopAndDestroy( 2 ); // lastAnchor, nextAnchor |
|
439 } |
|
440 |
|
441 TInt ret( iGenerator->smlAlertCmd( alert) ); |
|
442 |
|
443 if ( ret != KWBXMLGeneratorOk ) |
|
444 { |
|
445 User::Leave( ret ); |
|
446 } |
|
447 |
|
448 CleanupStack::PopAndDestroy(); // alert |
|
449 |
|
450 // save Status response information for response status controlling |
|
451 TInt respID( CreateAndInitResponseItemL( KNSmlAgentAlert ) ); |
|
452 |
|
453 iResponseController->SetAppIndex( respID, iDSContent.CurrentIndex() ); |
|
454 |
|
455 if ( aAlertCode >= KNSmlDSTwoWay && aAlertCode <= KNSmlDSRefreshFromServerByServer ) |
|
456 { |
|
457 iResponseController->SetResponseDetail( respID, CNSmlResponseController::EResponseInitAlert ); |
|
458 } |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // CNSmlDSCmds::DoPutL |
|
463 // Inserts DevInfo into Put element and calls the WBXML generator. |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 void CNSmlDSCmds::DoPutL() |
|
467 { |
|
468 SmlPut_t* put = new ( ELeave )SmlPut_t; |
|
469 CleanupStack::PushL( put ); |
|
470 put->elementType = SML_PE_PUT; |
|
471 |
|
472 // CmdID element |
|
473 DoCmdIdL( put->cmdID ); |
|
474 |
|
475 // Type element in Meta |
|
476 SmlMetInfMetInf_t* metInf; |
|
477 DoMetInfLC( metInf ); |
|
478 PcdataNewL( metInf->type, KNSmlDSAgentDeviceInfoContentType ); |
|
479 DoMetaL( put->meta, metInf ); |
|
480 CleanupStack::Pop(); // metinf |
|
481 |
|
482 // Item element |
|
483 put->itemList = new ( ELeave )SmlItemList_t; |
|
484 put->itemList->item = new ( ELeave )SmlItem_t; |
|
485 |
|
486 // Item/Source element |
|
487 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
488 { |
|
489 DoSourceL( put->itemList->item->source, KNSmlDSAgentDeviceInfo11URI ); |
|
490 PcdataNewL( put->itemList->item->data, DoDeviceInfoL( ETrue ) ); |
|
491 } |
|
492 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
493 { |
|
494 DoSourceL( put->itemList->item->source, KNSmlDSAgentDeviceInfo12URI ); |
|
495 PcdataNewL( put->itemList->item->data, DoDeviceInfoL() ); |
|
496 } |
|
497 |
|
498 // Device Info |
|
499 FreeDeviceInfo(); |
|
500 |
|
501 TInt ret( iGenerator->smlPutCmd( put ) ); |
|
502 |
|
503 if ( ret != KWBXMLGeneratorOk ) |
|
504 { |
|
505 User::Leave( ret ); |
|
506 } |
|
507 |
|
508 CleanupStack::PopAndDestroy(); // put |
|
509 |
|
510 //save Status response information for response status controlling |
|
511 CreateAndInitResponseItemL( KNSmlAgentPut ); |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CNSmlDSCmds::DoResultsL |
|
516 // Generate Device Info to Results element and calls the WBXML generator. |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoResultsL() |
|
520 { |
|
521 SmlResults_t* results = new ( ELeave ) SmlResults_t; |
|
522 CleanupStack::PushL( results ); |
|
523 results->elementType = SML_PE_RESULTS; |
|
524 |
|
525 // CmdID element |
|
526 DoCmdIdL( results->cmdID ); |
|
527 |
|
528 // MsgRef element |
|
529 if ( iDSGetMsgId ) |
|
530 { |
|
531 PcdataNewL ( results->msgRef, *iDSGetMsgId ); |
|
532 } |
|
533 |
|
534 // CmdRef element |
|
535 if ( iDSGetCmdId ) |
|
536 { |
|
537 PcdataNewL ( results->cmdRef, *iDSGetCmdId ); |
|
538 } |
|
539 |
|
540 // Type element in Meta |
|
541 SmlMetInfMetInf_t* metInf; |
|
542 DoMetInfLC( metInf ); |
|
543 PcdataNewL( metInf->type, KNSmlDSAgentDeviceInfoContentType ); |
|
544 DoMetaL( results->meta, metInf ); |
|
545 CleanupStack::Pop(); // metinf |
|
546 |
|
547 // Item element |
|
548 results->itemList = new( ELeave ) SmlItemList_t; |
|
549 results->itemList->item = new( ELeave ) SmlItem_t; |
|
550 |
|
551 // Item/source element |
|
552 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
553 { |
|
554 DoSourceL( results->itemList->item->source, KNSmlDSAgentDeviceInfo11URI ); |
|
555 PcdataNewL( results->itemList->item->data, DoDeviceInfoL(ETrue) ); |
|
556 } |
|
557 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
558 { |
|
559 DoSourceL( results->itemList->item->source, KNSmlDSAgentDeviceInfo12URI ); |
|
560 PcdataNewL( results->itemList->item->data, DoDeviceInfoL() ); |
|
561 } |
|
562 |
|
563 // Device Info |
|
564 results->itemList->next = NULL; |
|
565 TInt ret( iGenerator->smlResultsCmd( results ) ); |
|
566 FreeDeviceInfo(); |
|
567 |
|
568 if ( ret != KWBXMLGeneratorOk ) |
|
569 { |
|
570 User::Leave( ret ); |
|
571 } |
|
572 |
|
573 CleanupStack::PopAndDestroy(); // results |
|
574 |
|
575 CreateAndInitResponseItemL( KNSmlAgentResults ); |
|
576 |
|
577 return CNSmlCmdsBase::EReturnOK; |
|
578 } |
|
579 |
|
580 // ----------------------------------------------------------------------------- |
|
581 // CNSmlDSCmds::DoGetL |
|
582 // Generates the Get element used to ask DevInfo from the server. |
|
583 // ----------------------------------------------------------------------------- |
|
584 // |
|
585 void CNSmlDSCmds::DoGetL() |
|
586 { |
|
587 SmlGet_t* get = new( ELeave ) SmlGet_t; |
|
588 CleanupStack::PushL( get ); |
|
589 get->elementType = SML_PE_GET; |
|
590 |
|
591 // CmdID element |
|
592 DoCmdIdL( get->cmdID ); |
|
593 |
|
594 // Type element in Meta |
|
595 SmlMetInfMetInf_t* metInf; |
|
596 DoMetInfLC( metInf ); |
|
597 PcdataNewL( metInf->type, KNSmlDSAgentDeviceInfoContentType ); |
|
598 DoMetaL( get->meta, metInf ); |
|
599 CleanupStack::Pop(); // metinf |
|
600 |
|
601 // Item element |
|
602 get->itemList = new( ELeave ) SmlItemList_t; |
|
603 get->itemList->item = new( ELeave ) SmlItem_t; |
|
604 |
|
605 // Item/Target element |
|
606 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
607 { |
|
608 DoTargetL( get->itemList->item->target, KNSmlDSAgentDeviceInfo11URI ); |
|
609 } |
|
610 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
611 { |
|
612 DoTargetL( get->itemList->item->target, KNSmlDSAgentDeviceInfo12URI ); |
|
613 } |
|
614 |
|
615 TInt ret( iGenerator->smlGetCmd( get ) ); |
|
616 |
|
617 if ( ret != KWBXMLGeneratorOk ) |
|
618 { |
|
619 User::Leave( ret ); |
|
620 } |
|
621 |
|
622 CleanupStack::PopAndDestroy(); // get |
|
623 |
|
624 //save Status response information for response status controlling |
|
625 CreateAndInitResponseItemL( KNSmlAgentGet ); |
|
626 } |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CNSmlCmdsBase::DoStartSyncL |
|
630 // Generates the Sync element. |
|
631 // ----------------------------------------------------------------------------- |
|
632 // |
|
633 CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoStartSyncL() |
|
634 { |
|
635 // initialise SyncHdr |
|
636 SmlSync_t* sync = new( ELeave ) SmlSync_t; |
|
637 CleanupStack::PushL( sync ); |
|
638 |
|
639 // element type |
|
640 sync->elementType = SML_PE_SYNC_START; |
|
641 |
|
642 // CmdID element |
|
643 DoCmdIdL( sync->cmdID ); |
|
644 |
|
645 // Target element |
|
646 DoTargetL( sync->target, iDSContent.RemoteDatabase()->Database() ); |
|
647 |
|
648 // Source element |
|
649 DoSourceL( sync->source, iDSContent.LocalDatabase()->Database() ); |
|
650 |
|
651 // free memory and max object size in the Meta element |
|
652 SmlMetInfMetInf_t* metInf; |
|
653 DoMetInfLC( metInf ); |
|
654 DoMaxObjSizeL( *metInf, iDSContent.MaxObjSizeL() ); |
|
655 DoMetaL( sync->meta, metInf ); |
|
656 CleanupStack::Pop(); // metInf |
|
657 |
|
658 // NumberOfChanges element |
|
659 DoNumberOfChangesL( sync->noc ); |
|
660 |
|
661 TInt ret( iGenerator->smlStartSync( sync ) ); |
|
662 CNSmlCmdsBase::TReturnValue returnValue( CNSmlCmdsBase::EReturnOK ); |
|
663 |
|
664 switch ( ret ) |
|
665 { |
|
666 case KWBXMLGeneratorOk: |
|
667 break; |
|
668 |
|
669 case KWBXMLGeneratorBufferFull: |
|
670 returnValue = CNSmlCmdsBase::EReturnBufferFull; |
|
671 break; |
|
672 |
|
673 default: |
|
674 User::Leave( ret ); |
|
675 } |
|
676 |
|
677 CleanupStack::PopAndDestroy(); // sync |
|
678 |
|
679 // save Status response information for response status controlling |
|
680 TInt respID( CreateAndInitResponseItemL( KNSmlAgentSync ) ); |
|
681 |
|
682 iResponseController->SetAppIndex( respID, iDSContent.CurrentIndex() ); |
|
683 |
|
684 return returnValue; |
|
685 } |
|
686 |
|
687 // ----------------------------------------------------------------------------- |
|
688 // CNSmlDSCmds::DoEndSyncL |
|
689 // Generates the end tag of the Sync element and calls the WBXML generator. |
|
690 // ----------------------------------------------------------------------------- |
|
691 // |
|
692 void CNSmlDSCmds::DoEndSyncL() |
|
693 { |
|
694 TInt ret( iGenerator->smlEndSync() ); |
|
695 |
|
696 if ( ret != KWBXMLGeneratorOk ) |
|
697 { |
|
698 User::Leave( ret ); |
|
699 } |
|
700 } |
|
701 |
|
702 // ----------------------------------------------------------------------------- |
|
703 // CNSmlDSCmds::DoAddOrReplaceOrDeleteL |
|
704 // Generates Add, Replace, Delete and Move elements and calls the parser to |
|
705 // generate xml. |
|
706 // ----------------------------------------------------------------------------- |
|
707 // |
|
708 CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoAddOrReplaceOrDeleteL() |
|
709 { |
|
710 DBG_FILE(_S8("CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoAddOrReplaceOrDeleteL() begins")); |
|
711 TInt ret( KErrNone ); |
|
712 TSmlDbItemUid localUid; |
|
713 TSmlDbItemUid parentUid( KNullDataItemId ); |
|
714 TBuf8<KNSmlMaxCmdNameLength> cmdName; |
|
715 CNSmlDbMeta* meta( NULL ); |
|
716 MSyncMLProgressObserver::TSyncMLDataSyncModifications clientModifications = { 0, 0, 0, 0, 0 }; |
|
717 MSyncMLProgressObserver::TSyncMLDataSyncModifications serverModifications = { 0, 0, 0, 0, 0 }; |
|
718 |
|
719 if ( iLargeData ) |
|
720 { |
|
721 DBG_FILE(_S8("CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoAddOrReplaceOrDeleteL() iLargeData TRUE")); |
|
722 cmdName = *iDSLargeObjectCmdName; |
|
723 delete iDSLargeObjectCmdName; |
|
724 iDSLargeObjectCmdName = NULL; |
|
725 iDSContent.CurrentUID( localUid ); |
|
726 DBG_FILE(_S8("CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoAddOrReplaceOrDeleteL() iLargeData TRUE ends")); |
|
727 } |
|
728 else |
|
729 { |
|
730 if ( iDataBuffer ) |
|
731 { |
|
732 delete iDataBuffer; |
|
733 iDataBuffer = 0; |
|
734 } |
|
735 |
|
736 iDataBuffer = CBufFlat::NewL( 1 ); |
|
737 |
|
738 meta = CNSmlDbMeta::NewLC(); |
|
739 DBG_FILE(_S8("before OpenNextItemL")); |
|
740 ret = iDSContent.OpenNextItemL( localUid, parentUid, cmdName, iItemSizeInStream, *meta ); |
|
741 |
|
742 iBytesSent = 0; |
|
743 |
|
744 switch ( ret ) |
|
745 { |
|
746 case KErrNone: |
|
747 iItemOpened = ETrue; |
|
748 break; |
|
749 |
|
750 case KErrEof: |
|
751 CleanupStack::PopAndDestroy(); // meta |
|
752 return CNSmlCmdsBase::EReturnEndData; |
|
753 |
|
754 case KErrNotFound: |
|
755 CleanupStack::PopAndDestroy(); // meta |
|
756 iDSContent.SetCurrentItemWritten(); |
|
757 serverModifications.iNumFailed = 1; |
|
758 iDSObserver.OnSyncMLDataSyncModifications( iDSContent.TaskId(), clientModifications, serverModifications ); |
|
759 return CNSmlCmdsBase::EReturnNotFound; |
|
760 |
|
761 default: |
|
762 User::Leave( ret ); |
|
763 } |
|
764 |
|
765 // check that item's data can be accepted by the server |
|
766 TInt maxObjSize( iDSContent.MaxObjSizeInServer() ); |
|
767 |
|
768 if ( maxObjSize > 0 ) |
|
769 { |
|
770 if ( iItemSizeInStream > maxObjSize ) |
|
771 { |
|
772 CleanupStack::PopAndDestroy(); // meta |
|
773 iDSContent.SetCurrentItemWritten(); |
|
774 iDSContent.SetAsReceivedL( localUid ); |
|
775 |
|
776 if ( iItemOpened ) |
|
777 { |
|
778 iItemOpened = EFalse; |
|
779 iDSContent.CloseItemL(); |
|
780 } |
|
781 |
|
782 serverModifications.iNumFailed = 1; |
|
783 iDSObserver.OnSyncMLDataSyncModifications( iDSContent.TaskId(), clientModifications, serverModifications ); |
|
784 return CNSmlCmdsBase::EReturnSkipped; |
|
785 } |
|
786 } |
|
787 } |
|
788 |
|
789 // begin to process the data |
|
790 CNSmlCmdsBase::TReturnValue returnValue( CNSmlCmdsBase::EReturnOK ); |
|
791 |
|
792 // initialise command element |
|
793 SmlGenericCmd_t* genericCmd = new ( ELeave ) SmlGenericCmd_t; |
|
794 CleanupStack::PushL( genericCmd ); |
|
795 |
|
796 DBG_FILE(_S8("before DoCmdIdL")); |
|
797 // CmdID element |
|
798 DoCmdIdL( genericCmd->cmdID ); |
|
799 |
|
800 // Item element |
|
801 genericCmd->itemList = new ( ELeave ) SmlItemList_t; |
|
802 |
|
803 // if in the middle of a large item then there's no need to recreate it |
|
804 if ( (iLargeData) && (iLargeObjectItem) ) |
|
805 { |
|
806 DBG_FILE(_S8("LARGE")); |
|
807 genericCmd->itemList->item = iLargeObjectItem; |
|
808 iLargeObjectItem = NULL; |
|
809 } |
|
810 else |
|
811 { |
|
812 DBG_FILE(_S8("NO LARGE")); |
|
813 genericCmd->itemList->item = new ( ELeave ) SmlItem_t; |
|
814 |
|
815 // Source element |
|
816 TBuf<16> unicodeId; |
|
817 unicodeId.Num( localUid ); |
|
818 |
|
819 DoSourceL( genericCmd->itemList->item->source, unicodeId ); |
|
820 |
|
821 if ( parentUid != KNullDataItemId ) |
|
822 { |
|
823 TBuf8<16> parentDes; |
|
824 |
|
825 if ( parentUid == KDbItemUidRoot ) |
|
826 { |
|
827 parentDes.Append( KNSmlRoot ); |
|
828 } |
|
829 else |
|
830 { |
|
831 parentDes.Num( parentUid ); |
|
832 } |
|
833 |
|
834 genericCmd->itemList->item->sourceParent = new ( ELeave ) sml_source_or_target_parent_s; |
|
835 PcdataNewL ( genericCmd->itemList->item->sourceParent->locURI, parentDes ); |
|
836 } |
|
837 |
|
838 if ( cmdName == KNSmlAgentAdd || cmdName == KNSmlAgentReplace || cmdName == KNSmlAgentPartialReplace ) |
|
839 { |
|
840 if ( meta ) |
|
841 { |
|
842 SmlMetInfMetInf_t* metaInf = meta->MetInfL(); |
|
843 |
|
844 if ( metaInf ) |
|
845 { |
|
846 DoMetaL( genericCmd->itemList->item->meta, metaInf ); |
|
847 } |
|
848 } |
|
849 } |
|
850 } |
|
851 |
|
852 // generate command |
|
853 if ( cmdName == KNSmlAgentAdd || cmdName == KNSmlAgentReplace || cmdName == KNSmlAgentPartialReplace ) |
|
854 { |
|
855 // set data |
|
856 TPtr8 bufPtr( 0, 0 ); |
|
857 TInt bufPos( iDataBuffer->Size() ); |
|
858 |
|
859 if ( iItemSizeInStream - iBytesSent > iMaxWorkspaceSize ) |
|
860 { |
|
861 iDataBuffer->ResizeL( iMaxWorkspaceSize ); |
|
862 } |
|
863 else |
|
864 { |
|
865 iDataBuffer->ResizeL( iItemSizeInStream - iBytesSent ); |
|
866 } |
|
867 |
|
868 bufPtr.Set( iDataBuffer->Ptr( bufPos ) ); |
|
869 bufPtr.SetLength( 0 ); |
|
870 iDSContent.ReadItemL( bufPtr ); |
|
871 |
|
872 delete genericCmd->itemList->item->data; |
|
873 genericCmd->itemList->item->data = NULL; |
|
874 PcdataNewL( genericCmd->itemList->item->data, iDataBuffer->Ptr( 0 ) ); |
|
875 |
|
876 // fill in the correct element structure |
|
877 DBG_FILE_CODE( genericCmd->itemList->item->data->length, _S8("length")); |
|
878 if ( genericCmd->itemList->item->data->length >= KNSmlLargeObjectMinSize ) |
|
879 { |
|
880 DBG_FILE(_S8("iLargeData SET TRUE")); |
|
881 DBG_FILE_CODE( genericCmd->itemList->item->data->length, _S8("length")); |
|
882 iLargeData = ETrue; |
|
883 iGenerator->SetContentLength( iItemSizeInStream ); |
|
884 iGenerator->SetTruncate( ETrue ); |
|
885 } |
|
886 |
|
887 if ( cmdName == KNSmlAgentAdd ) // Add |
|
888 { |
|
889 DBG_FILE(_S8("KNSmlAgentAdd")); |
|
890 genericCmd->elementType = SML_PE_ADD; |
|
891 ret = iGenerator->smlAddCmd( genericCmd ); |
|
892 serverModifications.iNumAdded = 1; |
|
893 } |
|
894 else if ( cmdName == KNSmlAgentReplace ) // Replace |
|
895 { |
|
896 DBG_FILE(_S8("KNSmlAgentReplace")); |
|
897 genericCmd->elementType = SML_PE_REPLACE; |
|
898 ret = iGenerator->smlReplaceCmd( genericCmd ); |
|
899 serverModifications.iNumReplaced = 1; |
|
900 } |
|
901 else if ( cmdName == KNSmlAgentPartialReplace ) // PartialReplace |
|
902 { |
|
903 DBG_FILE(_S8("KNSmlAgentPartialReplace")); |
|
904 SmlMetInfMetInf_t* metInf; |
|
905 DoMetInfLC( metInf ); |
|
906 PcdataNewL( metInf->fieldLevel, KNullDesC8() ); |
|
907 DoMetaL( genericCmd->meta, metInf ); |
|
908 CleanupStack::Pop(); // metInf |
|
909 genericCmd->elementType = SML_PE_REPLACE; |
|
910 ret = iGenerator->smlReplaceCmd( genericCmd ); |
|
911 serverModifications.iNumReplaced = 1; |
|
912 } |
|
913 } |
|
914 else if ( cmdName == KNSmlAgentDelete ) // Delete |
|
915 { |
|
916 DBG_FILE(_S8("KNSmlAgentDelete")); |
|
917 genericCmd->elementType = SML_PE_DELETE; |
|
918 ret = iGenerator->smlDeleteCmd( genericCmd ); |
|
919 serverModifications.iNumDeleted = 1; |
|
920 } |
|
921 else if ( cmdName == KNSmlAgentMove ) // Move |
|
922 { |
|
923 DBG_FILE(_S8("KNSmlAgentMove")); |
|
924 genericCmd->elementType = SML_PE_MOVE; |
|
925 ret = iGenerator->smlMoveCmd( genericCmd ); |
|
926 serverModifications.iNumMoved = 1; |
|
927 } |
|
928 else // SoftDelete |
|
929 { |
|
930 DBG_FILE(_S8("SoftDelete")); |
|
931 genericCmd->elementType = SML_PE_DELETE; |
|
932 genericCmd->flags += SmlSftDel_f; |
|
933 ret = iGenerator->smlDeleteCmd( genericCmd ); |
|
934 serverModifications.iNumDeleted = 1; |
|
935 } |
|
936 DBG_FILE_CODE( ret, _S8("ret")); |
|
937 |
|
938 switch ( ret ) |
|
939 { |
|
940 case KWBXMLGeneratorOk: |
|
941 if ( iGenerator->WasTruncated() ) |
|
942 { |
|
943 DBG_FILE(_S8("WasTruncated TRUE")); |
|
944 if ( genericCmd->itemList->item->data->length < iGenerator->DataConsumed() ) |
|
945 { |
|
946 DBG_FILE_CODE( iBytesSent, _S8("iBytesSent")); |
|
947 iBytesSent += genericCmd->itemList->item->data->length; |
|
948 DBG_FILE_CODE( iBytesSent, _S8("iBytesSent")); |
|
949 } |
|
950 else |
|
951 { |
|
952 DBG_FILE_CODE( iBytesSent, _S8("iBytesSent")); |
|
953 iBytesSent += iGenerator->DataConsumed(); |
|
954 DBG_FILE_CODE( iBytesSent, _S8("iBytesSent")); |
|
955 } |
|
956 |
|
957 // change item's ownership from struct to this class |
|
958 iLargeObjectItem = genericCmd->itemList->item; |
|
959 genericCmd->itemList->item = NULL; |
|
960 |
|
961 if ( iLargeData ) |
|
962 { |
|
963 delete iDSLargeObjectCmdName; |
|
964 iDSLargeObjectCmdName = NULL; |
|
965 iDSLargeObjectCmdName = cmdName.AllocL(); |
|
966 } |
|
967 |
|
968 if ( iGenerator->DataConsumed() < iDataBuffer->Size() ) |
|
969 { |
|
970 iDataBuffer->Delete( 0, iGenerator->DataConsumed() ); |
|
971 iDataBuffer->Compress(); |
|
972 } |
|
973 else |
|
974 { |
|
975 delete iDataBuffer; |
|
976 iDataBuffer = NULL; |
|
977 } |
|
978 |
|
979 returnValue = CNSmlCmdsBase::EReturnBufferFull; |
|
980 } |
|
981 else |
|
982 { |
|
983 DBG_FILE(_S8("WasTruncated FALSE")); |
|
984 iDSContent.SetCurrentItemWritten(); |
|
985 |
|
986 if ( cmdName != KNSmlAgentDelete && cmdName != KNSmlAgentMove ) |
|
987 { |
|
988 iBytesSent += genericCmd->itemList->item->data->length; |
|
989 DBG_FILE_CODE( genericCmd->itemList->item->data->length, _S8("length")); |
|
990 DBG_FILE_CODE( iBytesSent, _S8("iBytesSent")); |
|
991 if ( iBytesSent == iItemSizeInStream ) |
|
992 { |
|
993 DBG_FILE(_S8("iLargeData SET FALSE")); |
|
994 iLargeData = EFalse; |
|
995 } |
|
996 } |
|
997 |
|
998 } |
|
999 break; |
|
1000 |
|
1001 case KWBXMLGeneratorBufferFull: |
|
1002 DBG_FILE(_S8("KWBXMLGeneratorBufferFull")); |
|
1003 delete iDSLargeObjectCmdName; |
|
1004 iDSLargeObjectCmdName = NULL; |
|
1005 iDSLargeObjectCmdName = cmdName.AllocL(); |
|
1006 returnValue = CNSmlCmdsBase::EReturnBufferFull; |
|
1007 DBG_FILE(_S8("KWBXMLGeneratorBufferFull end")); |
|
1008 break; |
|
1009 |
|
1010 default: |
|
1011 DBG_FILE_CODE( ret, _S8("ret")); |
|
1012 User::Leave( ret ); |
|
1013 } |
|
1014 |
|
1015 DBG_FILE(_S8("before SetTruncate( EFalse )")); |
|
1016 iGenerator->SetTruncate( EFalse ); |
|
1017 |
|
1018 if ( ret == KWBXMLGeneratorOk ) |
|
1019 { |
|
1020 DBG_FILE(_S8("KWBXMLGeneratorOk")); |
|
1021 TInt respID( CreateAndInitResponseItemL( cmdName ) ); |
|
1022 TBuf8<16> localDes; |
|
1023 localDes.Num( localUid ); |
|
1024 iResponseController->SetLUIDL( respID, localDes ); |
|
1025 iResponseController->SetAppIndex( respID, iDSContent.CurrentIndex() ); |
|
1026 |
|
1027 if ( returnValue == CNSmlCmdsBase::EReturnBufferFull ) |
|
1028 { |
|
1029 DBG_FILE(_S8("iLargeData SET TRUE after EReturnBufferFull")); |
|
1030 iResponseController->SetMoreData( respID ); |
|
1031 iLargeData = ETrue; |
|
1032 } |
|
1033 } |
|
1034 |
|
1035 if ( !iLargeData ) |
|
1036 { |
|
1037 DBG_FILE(_S8("!iLargeData")); |
|
1038 iItemOpened = EFalse; |
|
1039 iDSContent.CloseItemL(); |
|
1040 } |
|
1041 |
|
1042 CleanupStack::PopAndDestroy(); // genericCmd |
|
1043 |
|
1044 if ( meta ) |
|
1045 { |
|
1046 CleanupStack::PopAndDestroy(); // meta |
|
1047 } |
|
1048 |
|
1049 if ( returnValue == CNSmlCmdsBase::EReturnOK ) |
|
1050 { |
|
1051 iDSObserver.OnSyncMLDataSyncModifications( iDSContent.TaskId(), clientModifications, serverModifications ); |
|
1052 } |
|
1053 |
|
1054 DBG_FILE_CODE( returnValue, _S8("returnValue")); |
|
1055 return returnValue; |
|
1056 } |
|
1057 |
|
1058 // ----------------------------------------------------------------------------- |
|
1059 // CNSmlDSCmds::DoMapL |
|
1060 // Build a structure for the Map command. |
|
1061 // ----------------------------------------------------------------------------- |
|
1062 // |
|
1063 CNSmlCmdsBase::TReturnValue CNSmlDSCmds::DoMapL() |
|
1064 { |
|
1065 if ( !iDSContent.MapExists() ) |
|
1066 { |
|
1067 return EReturnEndData; |
|
1068 } |
|
1069 |
|
1070 SmlMap_t* map = new( ELeave ) SmlMap_t; |
|
1071 CleanupStack::PushL( map ); |
|
1072 map->elementType = SML_PE_MAP; |
|
1073 |
|
1074 // CmdID element |
|
1075 DoCmdIdL( map->cmdID ); |
|
1076 |
|
1077 // Target element |
|
1078 DoTargetL( map->target, iDSContent.RemoteDatabase()->Database() ); |
|
1079 |
|
1080 // Source element |
|
1081 DoSourceL( map->source, iDSContent.LocalDatabase()->Database() ); |
|
1082 |
|
1083 map->mapItemList = iDSContent.MapItemListL(); |
|
1084 |
|
1085 TInt ret( iGenerator->smlMapCmd( map ) ); |
|
1086 CNSmlCmdsBase::TReturnValue returnValue( CNSmlCmdsBase::EReturnOK ); |
|
1087 |
|
1088 switch ( ret ) |
|
1089 { |
|
1090 case KWBXMLGeneratorOk: |
|
1091 iDSContent.RemoveMap(); |
|
1092 break; |
|
1093 |
|
1094 case KWBXMLGeneratorBufferFull: |
|
1095 iDSContent.SetMapItemList( map->mapItemList ); //map item list is returned |
|
1096 map->mapItemList = NULL; //to the buffer |
|
1097 returnValue = CNSmlCmdsBase::EReturnBufferFull; |
|
1098 break; |
|
1099 |
|
1100 default: |
|
1101 User::Leave( ret ); |
|
1102 } |
|
1103 |
|
1104 CleanupStack::PopAndDestroy(); // map |
|
1105 |
|
1106 if ( returnValue != CNSmlCmdsBase::EReturnBufferFull ) |
|
1107 { |
|
1108 // save Status response information for response status controlling |
|
1109 TInt respID( CreateAndInitResponseItemL( KNSmlAgentMap ) ); |
|
1110 iResponseController->SetAppIndex( respID, iDSContent.CurrentIndex() ); |
|
1111 } |
|
1112 |
|
1113 return returnValue; |
|
1114 } |
|
1115 |
|
1116 // ----------------------------------------------------------------------------- |
|
1117 // CNSmlDSCmds::ProcessResultsCmdL |
|
1118 // Processes DevInfo in the Results command that was received from the server. |
|
1119 // ----------------------------------------------------------------------------- |
|
1120 // |
|
1121 void CNSmlDSCmds::ProcessResultsCmdL( SmlResults_t* aResults ) |
|
1122 { |
|
1123 TInt statusID( iStatusToServer->CreateNewStatusElementL() ); |
|
1124 |
|
1125 iStatusToServer->SetCmdRefL( statusID, aResults->cmdID ); |
|
1126 iStatusToServer->SetCmdL( statusID, KNSmlAgentResults ); |
|
1127 |
|
1128 if ( iStatusToServerNoResponse ) |
|
1129 { |
|
1130 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
1131 } |
|
1132 else |
|
1133 { |
|
1134 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
1135 } |
|
1136 |
|
1137 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1138 |
|
1139 // Is synchronisation already interrupted? |
|
1140 if ( iDSContent.AllDatabasesAreInterrupted() ) |
|
1141 { |
|
1142 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1143 return; |
|
1144 } |
|
1145 |
|
1146 if ( aResults->cmdID->length == 0 ) |
|
1147 { |
|
1148 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1149 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1150 return; |
|
1151 } |
|
1152 |
|
1153 // content type |
|
1154 if ( !IsDevInfoContentTypeOkL( aResults->meta, statusID ) ) |
|
1155 { |
|
1156 return; |
|
1157 } |
|
1158 |
|
1159 // source |
|
1160 if ( !SourceIsUnderItem( aResults->itemList ) ) |
|
1161 { |
|
1162 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1163 iAgent->Interrupt( TNSmlError::ESmlResultsItemSourceMissing, EFalse, EFalse ); |
|
1164 return; |
|
1165 } |
|
1166 |
|
1167 CNSmlURI* deviceInfoURI( CNSmlURI::NewLC() ); |
|
1168 |
|
1169 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
1170 { |
|
1171 deviceInfoURI->SetDatabaseL( KNSmlDSAgentDeviceInfo11URI ); |
|
1172 } |
|
1173 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
1174 { |
|
1175 deviceInfoURI->SetDatabaseL( KNSmlDSAgentDeviceInfo12URI ); |
|
1176 } |
|
1177 |
|
1178 HBufC* resultsSource; |
|
1179 PCDATAToUnicodeLC( *aResults->itemList->item->source->locURI, resultsSource ); |
|
1180 resultsSource->Des().TrimRight(); |
|
1181 CNSmlURI* resultsSourceURI = CNSmlURI::NewLC(); |
|
1182 resultsSourceURI->SetDatabaseL( *resultsSource ); |
|
1183 |
|
1184 if ( !resultsSourceURI->IsEqualL( *deviceInfoURI ) ) |
|
1185 { |
|
1186 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1187 iAgent->Interrupt( TNSmlError::ESmlResultsItemSourceInvalid, EFalse, EFalse ); |
|
1188 CleanupStack::PopAndDestroy( 3 ); // resultsSourceURI, resultsSource, deviceInfoURI |
|
1189 return; |
|
1190 } |
|
1191 |
|
1192 CleanupStack::PopAndDestroy( 3 ); // resultsSourceURI, resultsSource, deviceInfoURI |
|
1193 |
|
1194 // Device Info in Data element |
|
1195 if ( !aResults->itemList->item->data ) |
|
1196 { |
|
1197 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1198 iAgent->Interrupt( TNSmlDSError::ESmlDSDeviceInfoMissing, EFalse, EFalse ); |
|
1199 return; |
|
1200 } |
|
1201 |
|
1202 if ( !aResults->itemList->item->data->content ) |
|
1203 { |
|
1204 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1205 iAgent->Interrupt( TNSmlDSError::ESmlDSDeviceInfoMissing, EFalse, EFalse ); |
|
1206 return; |
|
1207 } |
|
1208 |
|
1209 TPtrC8 deviceInfo( static_cast<TUint8*>( aResults->itemList->item->data->content ), aResults->itemList->item->data->length ); |
|
1210 |
|
1211 ParseDeviceInfoL( statusID, deviceInfo ); |
|
1212 } |
|
1213 |
|
1214 // ----------------------------------------------------------------------------- |
|
1215 // CNSmlDSCmds::ProcessPutCmdL |
|
1216 // Handle the Put command from the server. DevInfo element in the command is |
|
1217 // processed. |
|
1218 // ----------------------------------------------------------------------------- |
|
1219 // |
|
1220 void CNSmlDSCmds::ProcessPutCmdL( SmlPut_t* aPut ) |
|
1221 { |
|
1222 TInt statusID( iStatusToServer->CreateNewStatusElementL() ); |
|
1223 |
|
1224 iStatusToServer->SetCmdRefL( statusID, aPut->cmdID ); |
|
1225 iStatusToServer->SetCmdL( statusID, KNSmlAgentPut ); |
|
1226 |
|
1227 if ( iStatusToServerNoResponse || IsFlagSet( aPut->flags, SmlNoResp_f ) ) |
|
1228 { |
|
1229 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
1230 } |
|
1231 else |
|
1232 { |
|
1233 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
1234 } |
|
1235 |
|
1236 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1237 |
|
1238 // Is synchronisation already interrupted? |
|
1239 if ( iDSContent.AllDatabasesAreInterrupted() ) |
|
1240 { |
|
1241 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1242 return; |
|
1243 } |
|
1244 |
|
1245 if ( aPut->cmdID->length == 0 ) |
|
1246 { |
|
1247 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1248 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1249 return; |
|
1250 } |
|
1251 |
|
1252 // content type |
|
1253 if ( !IsDevInfoContentTypeOkL( aPut->meta, statusID ) ) |
|
1254 { |
|
1255 return; |
|
1256 } |
|
1257 |
|
1258 // source |
|
1259 if ( !SourceIsUnderItem( aPut->itemList ) ) |
|
1260 { |
|
1261 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1262 iAgent->Interrupt( TNSmlError::ESmlPutItemSourceMissing, EFalse, EFalse ); |
|
1263 return; |
|
1264 } |
|
1265 |
|
1266 CNSmlURI* deviceInfoURI( CNSmlURI::NewLC() ); |
|
1267 |
|
1268 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
1269 { |
|
1270 deviceInfoURI->SetDatabaseL( KNSmlDSAgentDeviceInfo11URI ); |
|
1271 } |
|
1272 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
1273 { |
|
1274 deviceInfoURI->SetDatabaseL( KNSmlDSAgentDeviceInfo12URI ); |
|
1275 } |
|
1276 |
|
1277 HBufC* putSource; |
|
1278 PCDATAToUnicodeLC( *aPut->itemList->item->source->locURI, putSource ); |
|
1279 putSource->Des().TrimRight(); |
|
1280 CNSmlURI* putSourceURI = CNSmlURI::NewLC(); |
|
1281 putSourceURI->SetDatabaseL( *putSource ); |
|
1282 |
|
1283 if ( !putSourceURI->IsEqualL( *deviceInfoURI ) ) |
|
1284 { |
|
1285 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1286 iAgent->Interrupt( TNSmlError::ESmlPutItemSourceInvalid, EFalse, EFalse ); |
|
1287 CleanupStack::PopAndDestroy( 3 ); // putSourceURI, putSource, deviceInfoURI |
|
1288 return; |
|
1289 } |
|
1290 |
|
1291 CleanupStack::PopAndDestroy( 3 ); // putSourceURI, putSource, deviceInfoURI |
|
1292 |
|
1293 // Device Info in Data element |
|
1294 if ( !aPut->itemList->item->data ) |
|
1295 { |
|
1296 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1297 iAgent->Interrupt( TNSmlDSError::ESmlDSDeviceInfoMissing, EFalse, EFalse ); |
|
1298 return; |
|
1299 } |
|
1300 |
|
1301 if ( !aPut->itemList->item->data->content ) |
|
1302 { |
|
1303 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1304 iAgent->Interrupt( TNSmlDSError::ESmlDSDeviceInfoMissing, EFalse, EFalse ); |
|
1305 return; |
|
1306 } |
|
1307 |
|
1308 TPtrC8 deviceInfo( static_cast<TUint8*>( aPut->itemList->item->data->content ), aPut->itemList->item->data->length ); |
|
1309 |
|
1310 ParseDeviceInfoL( statusID, deviceInfo ); |
|
1311 } |
|
1312 |
|
1313 // ----------------------------------------------------------------------------- |
|
1314 // CNSmlDSCmds::ProcessGetCmdL |
|
1315 // Handles the DevInfo request from the server in the Get command. |
|
1316 // ----------------------------------------------------------------------------- |
|
1317 // |
|
1318 void CNSmlDSCmds::ProcessGetCmdL( SmlGet_t* aGet ) |
|
1319 { |
|
1320 TInt statusID( iStatusToServer->CreateNewStatusElementL() ); |
|
1321 |
|
1322 iStatusToServer->SetCmdRefL( statusID, aGet->cmdID ); |
|
1323 iStatusToServer->SetCmdL( statusID, KNSmlAgentGet ); |
|
1324 |
|
1325 if ( iAtomicModeOn ) |
|
1326 { |
|
1327 iStatusToServer->SetAtomicOrSequenceId( statusID, iAtomicId ); |
|
1328 } |
|
1329 |
|
1330 if ( iStatusToServerNoResponse || IsFlagSet( aGet->flags, SmlNoResp_f ) ) |
|
1331 { |
|
1332 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
1333 } |
|
1334 else |
|
1335 { |
|
1336 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
1337 } |
|
1338 |
|
1339 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1340 |
|
1341 // Is synchronisation already interrupted? |
|
1342 if ( iDSContent.AllDatabasesAreInterrupted() ) |
|
1343 { |
|
1344 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1345 return; |
|
1346 } |
|
1347 |
|
1348 // cmdID |
|
1349 if ( aGet->cmdID->length == 0 ) |
|
1350 { |
|
1351 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1352 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1353 return; |
|
1354 } |
|
1355 |
|
1356 // atomic command has failed |
|
1357 if ( iAtomicHasFailed ) |
|
1358 { |
|
1359 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1360 return; |
|
1361 } |
|
1362 |
|
1363 TPtrC8 cmdID( static_cast<TUint8*>( aGet->cmdID->content ), aGet->cmdID->length ); |
|
1364 |
|
1365 delete iDSGetCmdId; |
|
1366 iDSGetCmdId = NULL; |
|
1367 iDSGetCmdId = cmdID.AllocL(); |
|
1368 |
|
1369 delete iDSGetMsgId; |
|
1370 iDSGetMsgId = NULL; |
|
1371 iDSGetMsgId = iCurrServerMsgID->AllocL(); |
|
1372 |
|
1373 // content type |
|
1374 if ( !IsDevInfoContentTypeOkL( aGet->meta, statusID ) ) |
|
1375 { |
|
1376 return; |
|
1377 } |
|
1378 |
|
1379 // target |
|
1380 if ( !TargetIsUnderItem( aGet->itemList ) ) |
|
1381 { |
|
1382 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1383 iAgent->Interrupt( TNSmlError::ESmlGetItemTargetMissing, EFalse, EFalse ); |
|
1384 return; |
|
1385 } |
|
1386 |
|
1387 HBufC* getTarget; |
|
1388 PCDATAToUnicodeLC( *aGet->itemList->item->target->locURI, getTarget ); |
|
1389 getTarget->Des().TrimRight(); |
|
1390 CNSmlURI* deviceInfoURI = CNSmlURI::NewLC(); |
|
1391 |
|
1392 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
1393 { |
|
1394 deviceInfoURI->SetDatabaseL( KNSmlDSAgentDeviceInfo11URI ); |
|
1395 } |
|
1396 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
1397 { |
|
1398 deviceInfoURI->SetDatabaseL( KNSmlDSAgentDeviceInfo12URI ); |
|
1399 } |
|
1400 |
|
1401 CNSmlURI* getTargetURI( CNSmlURI::NewLC() ); |
|
1402 |
|
1403 getTargetURI->SetDatabaseL( *getTarget ); |
|
1404 |
|
1405 if ( !getTargetURI->IsEqualL( *deviceInfoURI ) ) |
|
1406 { |
|
1407 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1408 iAgent->Interrupt( TNSmlError::ESmlGetItemTargetInvalid, EFalse, EFalse ); |
|
1409 CleanupStack::PopAndDestroy( 3 ); // getTargetURI, deviceInfoURI, getTarget |
|
1410 return; |
|
1411 } |
|
1412 |
|
1413 CleanupStack::PopAndDestroy( 3 ); // getTargetURI, deviceInfoURI, getTarget |
|
1414 } |
|
1415 |
|
1416 // ----------------------------------------------------------------------------- |
|
1417 // CNSmlDSCmds::ProcessAlertCmdL |
|
1418 // Handles the Alert command from a server. |
|
1419 // ----------------------------------------------------------------------------- |
|
1420 // |
|
1421 void CNSmlDSCmds::ProcessAlertCmdL( SmlAlert_t* aAlert, TBool aNextAlert, TBool aServerAlert, TBool aDisplayAlert ) |
|
1422 { |
|
1423 TBool databaseExists( EFalse ); |
|
1424 TBool initAlert( ETrue ); |
|
1425 |
|
1426 if ( aNextAlert || aServerAlert || aDisplayAlert ) |
|
1427 { |
|
1428 initAlert = EFalse; |
|
1429 } |
|
1430 |
|
1431 TInt statusID( iStatusToServer->CreateNewStatusElementL() ); |
|
1432 |
|
1433 iStatusToServer->SetCmdRefL( statusID, aAlert->cmdID ); |
|
1434 iStatusToServer->SetCmdL( statusID, KNSmlAgentAlert ); |
|
1435 |
|
1436 if ( iStatusToServerNoResponse || IsFlagSet( aAlert->flags, SmlNoResp_f ) ) |
|
1437 { |
|
1438 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
1439 } |
|
1440 else |
|
1441 { |
|
1442 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
1443 } |
|
1444 |
|
1445 if ( iAtomicHasFailed ) |
|
1446 { |
|
1447 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1448 return; |
|
1449 } |
|
1450 |
|
1451 if ( aNextAlert && iDSContent.AllDatabasesAreInterrupted() ) |
|
1452 { |
|
1453 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1454 return; |
|
1455 } |
|
1456 else |
|
1457 { |
|
1458 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1459 } |
|
1460 |
|
1461 if ( aAlert->itemList ) |
|
1462 { |
|
1463 if ( aAlert->itemList->item ) |
|
1464 { |
|
1465 iStatusToServer->AddTargetRefL( statusID, aAlert->itemList->item->target ); |
|
1466 iStatusToServer->AddSourceRefL( statusID, aAlert->itemList->item->source ); |
|
1467 } |
|
1468 else |
|
1469 { |
|
1470 iStatusToServer->AddTargetRefL( statusID, NULL ); |
|
1471 iStatusToServer->AddSourceRefL( statusID, NULL ); |
|
1472 } |
|
1473 } |
|
1474 else |
|
1475 { |
|
1476 iStatusToServer->AddTargetRefL( statusID, NULL ); |
|
1477 iStatusToServer->AddSourceRefL( statusID, NULL ); |
|
1478 } |
|
1479 |
|
1480 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1481 |
|
1482 // Next Sync anchor in Item/Meta element |
|
1483 if ( initAlert ) |
|
1484 { |
|
1485 if ( aAlert->itemList ) |
|
1486 { |
|
1487 if ( aAlert->itemList->item ) |
|
1488 { |
|
1489 if ( aAlert->itemList->item->meta ) |
|
1490 { |
|
1491 if ( aAlert->itemList->item->meta->content && aAlert->itemList->item->meta->contentType == SML_PCDATA_EXTENSION && aAlert->itemList->item->meta->extension == SML_EXT_METINF ) |
|
1492 { |
|
1493 SmlMetInfMetInf_t* metInf; |
|
1494 metInf = (SmlMetInfMetInf_t*) aAlert->itemList->item->meta->content; |
|
1495 if ( metInf->anchor ) |
|
1496 { |
|
1497 iStatusToServer->AddItemDataL( statusID, aAlert->itemList->item->meta ); |
|
1498 } |
|
1499 } |
|
1500 } |
|
1501 } |
|
1502 } |
|
1503 } |
|
1504 |
|
1505 TBool errorInCmdID( EFalse ); |
|
1506 |
|
1507 if ( aAlert->cmdID->length == 0 ) |
|
1508 { |
|
1509 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1510 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1511 errorInCmdID = ETrue; |
|
1512 } |
|
1513 |
|
1514 if ( aServerAlert ) |
|
1515 { |
|
1516 databaseExists = MatchServerAlertL( aAlert, statusID ); |
|
1517 |
|
1518 if ( !databaseExists ) |
|
1519 { |
|
1520 return; |
|
1521 } |
|
1522 |
|
1523 iDSContent.SetAsServerAlerted(); |
|
1524 iDSContent.InitSyncLogEventL( *iAgent->SyncLog() ); |
|
1525 } |
|
1526 |
|
1527 // DisplayAlert |
|
1528 if( aDisplayAlert ) |
|
1529 { |
|
1530 if ( !aAlert->itemList ) |
|
1531 { |
|
1532 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1533 iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse ); |
|
1534 return; |
|
1535 } |
|
1536 if( !aAlert->itemList->item ) |
|
1537 { |
|
1538 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1539 iAgent->Interrupt( TNSmlError::ESmlAlertInvalid, EFalse, EFalse ); |
|
1540 return; |
|
1541 } |
|
1542 |
|
1543 //Read min and max times |
|
1544 // MINDT |
|
1545 TInt mindt = AlertParameter( aAlert->itemList->item->data, KNSmlDSAgentMINDT ); |
|
1546 // MAXDT |
|
1547 TInt maxdt = AlertParameter( aAlert->itemList->item->data, KNSmlDSAgentMAXDT ); |
|
1548 |
|
1549 HBufC* alertData = AlertDataLC( aAlert->itemList ); |
|
1550 |
|
1551 //Fill notifier params |
|
1552 TSyncMLDlgNotifParams params; |
|
1553 params.iNoteType = ESyncMLInfoNote; |
|
1554 params.iServerMsg = TBufC<KSyncMLMaxServerMsgLength>(alertData->Des()); |
|
1555 |
|
1556 CleanupStack::PopAndDestroy(); //alertData |
|
1557 |
|
1558 //Pack data and start notifier |
|
1559 RNotifier notifier; |
|
1560 User::LeaveIfError( notifier.Connect() ); |
|
1561 CleanupClosePushL(notifier); |
|
1562 |
|
1563 TPckgBuf<TBool> resBuf; |
|
1564 |
|
1565 TRequestStatus status; |
|
1566 |
|
1567 TSyncMLDlgNotifParamsPckg data(params); |
|
1568 |
|
1569 notifier.StartNotifierAndGetResponse( status, KSyncMLDlgNotifierUid, data, resBuf ); |
|
1570 User::WaitForRequest(status); |
|
1571 |
|
1572 CleanupStack::PopAndDestroy(); //notifier, |
|
1573 |
|
1574 return; |
|
1575 } |
|
1576 |
|
1577 // Target element |
|
1578 if ( initAlert ) |
|
1579 { |
|
1580 if ( !TargetIsUnderItem( aAlert->itemList ) ) |
|
1581 { |
|
1582 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1583 iAgent->Interrupt( TNSmlError::ESmlAlertTargetLocURIMissing, EFalse, EFalse ); |
|
1584 } |
|
1585 else |
|
1586 { |
|
1587 HBufC* alertTarget; |
|
1588 PCDATAToUnicodeLC( *aAlert->itemList->item->target->locURI, alertTarget ); |
|
1589 alertTarget->Des().TrimRight(); |
|
1590 CNSmlURI* alertTargetURI = CNSmlURI::NewLC( iSentSyncHdrSource->HostName() ); |
|
1591 alertTargetURI->SetDatabaseL( *alertTarget ); |
|
1592 databaseExists = iDSContent.SetIndexByLocalDatabaseL( *alertTargetURI ); |
|
1593 CleanupStack::PopAndDestroy(); // alertTargetURI |
|
1594 |
|
1595 if ( !databaseExists ) |
|
1596 { |
|
1597 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusNotFound ); |
|
1598 } |
|
1599 |
|
1600 CleanupStack::PopAndDestroy(); // alertTarget |
|
1601 |
|
1602 if ( databaseExists && iDSContent.Interrupted() ) |
|
1603 { |
|
1604 if ( !errorInCmdID ) |
|
1605 { |
|
1606 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1607 } |
|
1608 return; |
|
1609 } |
|
1610 } |
|
1611 if ( !databaseExists ) |
|
1612 { |
|
1613 return; |
|
1614 } |
|
1615 } |
|
1616 |
|
1617 // Alert Code in Data element |
|
1618 if ( !aAlert->data ) |
|
1619 { |
|
1620 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1621 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlAlertCodeMissing, EFalse, EFalse ); |
|
1622 } |
|
1623 else if ( !aAlert->data->content ) |
|
1624 { |
|
1625 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1626 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlAlertCodeMissing, EFalse, EFalse ); |
|
1627 } |
|
1628 else |
|
1629 { |
|
1630 TPtr8 alertCode( static_cast<TUint8*>( aAlert->data->content ), aAlert->data->length, aAlert->data->length ); |
|
1631 |
|
1632 TrimRightSpaceAndNull( alertCode ); |
|
1633 |
|
1634 if ( alertCode.Length() == 0 ) |
|
1635 { |
|
1636 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1637 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlAlertCodeMissing, EFalse, EFalse ); |
|
1638 } |
|
1639 if ( aNextAlert ) |
|
1640 { |
|
1641 if ( alertCode != KNSmlDSAgentNextMessage ) |
|
1642 { |
|
1643 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1644 iAgent->Interrupt( TNSmlError::ESmlAlertCodeInvalid, EFalse, EFalse ); |
|
1645 } |
|
1646 } |
|
1647 else |
|
1648 { |
|
1649 if ( ( alertCode != KNSmlDSTwoWay ) && ( alertCode != KNSmlDSSlowSync ) && ( alertCode != KNSmlDSTwoWayByServer ) ) |
|
1650 { |
|
1651 if ( !iDSContent.IsSupportedSyncTypeL( alertCode ) ) |
|
1652 { |
|
1653 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOptFeatureNotSupported ); |
|
1654 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlDSError::ESmlDSUnsupportedSyncType, EFalse, EFalse ); |
|
1655 } |
|
1656 } |
|
1657 //RD_SUSPEND_RESUME |
|
1658 if(iDSContent.GetSessionResumed()) |
|
1659 { |
|
1660 TNSmlPreviousSyncType prevalertcode=iDSContent.PreviousSyncTypeL(); |
|
1661 TBool refreshrequired=EFalse; |
|
1662 refreshrequired=iDSContent.GetRefreshRequired(); |
|
1663 //Checks if the Sync Type of the Resumed session and Suspened session is same |
|
1664 if(prevalertcode!=ETypeNotSet && alertCode.Compare(CNSmlDSAgent::MapAlertCode(prevalertcode))!=0) |
|
1665 { |
|
1666 //Sesion is interrupted if the Resumed command rejected by the Server with status code 508 &Sync Type other than 201 |
|
1667 //or if Resume command accepted by Server with 200 & Sync Type different than the Suspened session |
|
1668 if(refreshrequired && alertCode.Compare(KNSmlDSSlowSync)!=0 || !refreshrequired) |
|
1669 { |
|
1670 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed); |
|
1671 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlDSError::ESmlDSUnsupportedSyncType, EFalse, EFalse ); |
|
1672 } |
|
1673 //If the Resume session is rejected by the Server,Client modifications need to be sent in Pacakge#3 |
|
1674 else if(refreshrequired && alertCode.Compare(KNSmlDSSlowSync)==0) |
|
1675 { |
|
1676 iDSContent.SetSessionResumedL(EFalse); |
|
1677 } |
|
1678 } |
|
1679 } |
|
1680 //RD_SUSPEND_RESUME |
|
1681 |
|
1682 } |
|
1683 |
|
1684 if ( databaseExists ) |
|
1685 { |
|
1686 if ( !iDSContent.Interrupted() ) |
|
1687 { |
|
1688 if ( initAlert || aServerAlert ) |
|
1689 { |
|
1690 // MaxObjSize |
|
1691 TInt maxObjSize( ServerMaxObjSize( aAlert->itemList->item->meta ) ); |
|
1692 |
|
1693 if ( maxObjSize > 0 ) |
|
1694 { |
|
1695 iDSContent.SetMaxObjSizeInServer( maxObjSize ); |
|
1696 } |
|
1697 } |
|
1698 |
|
1699 // update content specific data |
|
1700 if ( initAlert ) |
|
1701 { |
|
1702 iDSContent.SetSyncTypeL( alertCode ); |
|
1703 iDSContent.SetInitAlertReceived(); |
|
1704 } |
|
1705 |
|
1706 if ( aServerAlert ) |
|
1707 { |
|
1708 SwitchAlertCode( alertCode ); |
|
1709 iDSContent.SetSyncTypeL( alertCode ); |
|
1710 } |
|
1711 } |
|
1712 } |
|
1713 } |
|
1714 |
|
1715 // status 406 is returned if <Filter> is present BUT the session continues |
|
1716 if ( aAlert->itemList->item ) |
|
1717 { |
|
1718 if ( aAlert->itemList->item->target ) |
|
1719 { |
|
1720 if ( aAlert->itemList->item->target->filter ) |
|
1721 { |
|
1722 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOptFeatureNotSupported ); |
|
1723 } |
|
1724 } |
|
1725 } |
|
1726 } |
|
1727 |
|
1728 // --------------------------------------------------------- |
|
1729 // CNSmlDSCmds::AlertParameter() |
|
1730 // |
|
1731 // --------------------------------------------------------- |
|
1732 TInt CNSmlDSCmds::AlertParameter( const SmlPcdata_t* aData, const TDesC8& aParamID ) const |
|
1733 { |
|
1734 TInt valueNum = 0; |
|
1735 if ( aData ) |
|
1736 { |
|
1737 if ( aData->content ) |
|
1738 { |
|
1739 TPtr8 parameters( (TUint8*) aData->content, aData->length, aData->length ); |
|
1740 TrimRightSpaceAndNull( parameters ); |
|
1741 TInt startPos = parameters.Find( aParamID ); |
|
1742 if ( startPos >= 0 ) |
|
1743 { |
|
1744 if ( parameters.Length() > startPos + aParamID.Length() ) |
|
1745 { |
|
1746 TPtrC8 strPart = parameters.Right( parameters.Length() - ( startPos + aParamID.Length() ) ); |
|
1747 TInt length = 0; |
|
1748 while ( length < strPart.Length() ) |
|
1749 { |
|
1750 TChar character = strPart[length]; |
|
1751 if ( character.IsDigit() ) |
|
1752 { |
|
1753 ++length; |
|
1754 } |
|
1755 else |
|
1756 { |
|
1757 break; |
|
1758 } |
|
1759 } |
|
1760 TPtrC8 valueStr = strPart.Left( length ); |
|
1761 TLex8 lexicalValue( valueStr ); |
|
1762 if ( lexicalValue.Val( valueNum ) != KErrNone ) |
|
1763 { |
|
1764 valueNum = 0; |
|
1765 } |
|
1766 } |
|
1767 } |
|
1768 } |
|
1769 } |
|
1770 return valueNum; |
|
1771 } |
|
1772 // ----------------------------------------------------------------------------- |
|
1773 // CNSmlDSCmds::ProcessSyncL |
|
1774 // Handles the Sync command from a server. |
|
1775 // ----------------------------------------------------------------------------- |
|
1776 // |
|
1777 void CNSmlDSCmds::ProcessSyncL( SmlSync_t* aSync ) |
|
1778 { |
|
1779 TBool databaseExists( EFalse ); |
|
1780 TInt statusID( iStatusToServer->CreateNewStatusElementL() ); |
|
1781 |
|
1782 iBatchModeOn = EFalse; |
|
1783 |
|
1784 iStatusToServer->SetCmdRefL( statusID, aSync->cmdID ); |
|
1785 iStatusToServer->SetCmdL( statusID, KNSmlAgentSync ); |
|
1786 |
|
1787 if ( iStatusToServerNoResponse || IsFlagSet( aSync->flags, SmlNoResp_f ) ) |
|
1788 { |
|
1789 iStatusToServer->SetNoResponse( statusID, ETrue ); |
|
1790 } |
|
1791 else |
|
1792 { |
|
1793 iStatusToServer->SetNoResponse( statusID, EFalse ); |
|
1794 } |
|
1795 |
|
1796 iStatusToServer->AddTargetRefL( statusID, aSync->target ); |
|
1797 iStatusToServer->AddSourceRefL( statusID, aSync->source ); |
|
1798 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusOK ); |
|
1799 |
|
1800 if ( iAtomicModeOn ) |
|
1801 { |
|
1802 iStatusToServer->SetAtomicOrSequenceId( statusID, iAtomicId ); |
|
1803 } |
|
1804 |
|
1805 // cmdID |
|
1806 if ( aSync->cmdID->length == 0 ) |
|
1807 { |
|
1808 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1809 iAgent->Interrupt( TNSmlError::ESmlCmdIDMissing, EFalse, EFalse ); |
|
1810 } |
|
1811 |
|
1812 // Local Database in Target element |
|
1813 if ( !aSync->target ) |
|
1814 { |
|
1815 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1816 iAgent->Interrupt( TNSmlError::ESmlSyncTargetLocURIMissing, EFalse, EFalse ); |
|
1817 } |
|
1818 else |
|
1819 { |
|
1820 if ( !aSync->target->locURI ) |
|
1821 { |
|
1822 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1823 iAgent->Interrupt( TNSmlError::ESmlSyncTargetLocURIMissing, EFalse, EFalse ); |
|
1824 } |
|
1825 else |
|
1826 { |
|
1827 HBufC* syncTarget( NULL ); |
|
1828 |
|
1829 PCDATAToUnicodeLC( *aSync->target->locURI, syncTarget ); |
|
1830 syncTarget->Des().TrimRight(); |
|
1831 |
|
1832 if ( syncTarget->Length() == 0 ) |
|
1833 { |
|
1834 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
1835 iAgent->Interrupt( TNSmlError::ESmlSyncTargetLocURIMissing, EFalse, EFalse ); |
|
1836 } |
|
1837 else |
|
1838 { |
|
1839 CNSmlURI* syncTargetURI = CNSmlURI::NewLC( iSentSyncHdrSource->HostName() ); |
|
1840 |
|
1841 syncTargetURI->SetDatabaseL( *syncTarget ); |
|
1842 databaseExists = iDSContent.SetIndexByLocalDatabaseL( *syncTargetURI ); |
|
1843 |
|
1844 if ( iMoreData ) |
|
1845 { |
|
1846 if ( !syncTargetURI->IsEqualL( *iDSPreviousSyncTargetURI ) ) |
|
1847 { |
|
1848 ResetLargeObjectBuffer(); |
|
1849 iAgent->SetEndOfDataAlertRequest(); |
|
1850 } |
|
1851 } |
|
1852 |
|
1853 delete iDSPreviousSyncTargetURI; |
|
1854 iDSPreviousSyncTargetURI = syncTargetURI; |
|
1855 CleanupStack::Pop(); // syncTargetURI |
|
1856 } |
|
1857 |
|
1858 CleanupStack::PopAndDestroy(); // syncTarget |
|
1859 } |
|
1860 } |
|
1861 |
|
1862 if ( !databaseExists ) |
|
1863 { |
|
1864 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusNotFound ); |
|
1865 iAgent->Interrupt( TNSmlError::ESmlSyncTargetLocURIInvalid, EFalse, EFalse ); |
|
1866 |
|
1867 if ( iAtomicModeOn ) |
|
1868 { |
|
1869 iAtomicHasFailed = ETrue; |
|
1870 } |
|
1871 } |
|
1872 |
|
1873 // Is synchronisation already interrupted? |
|
1874 // Is sync type one-way from client? |
|
1875 if ( databaseExists ) |
|
1876 { |
|
1877 if ( iDSContent.Interrupted() || iDSContent.SyncType() == KNSmlDSOneWayFromClient |
|
1878 || iDSContent.SyncType() == KNSmlDSRefreshFromClient |
|
1879 || iDSContent.SyncType() == KNSmlDSOneWayFromClientByServer |
|
1880 || iDSContent.SyncType() == KNSmlDSRefreshFromClientByServer ) |
|
1881 |
|
1882 { |
|
1883 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusCommandFailed ); |
|
1884 return; |
|
1885 } |
|
1886 } |
|
1887 |
|
1888 // ensure that transactions are supported if the atomic mode is on |
|
1889 if ( databaseExists && iAtomicModeOn ) |
|
1890 { |
|
1891 if ( !iDSContent.SupportsOperationL( KUidSmlSupportTransaction ) ) |
|
1892 { |
|
1893 iAtomicHasFailed = ETrue; |
|
1894 } |
|
1895 else |
|
1896 { |
|
1897 iDSContent.BeginTransActionL(); |
|
1898 } |
|
1899 } |
|
1900 |
|
1901 // Format |
|
1902 TPtrC8 format; |
|
1903 |
|
1904 if ( !IsChrFormat( aSync->meta, format ) ) |
|
1905 { |
|
1906 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
1907 SmlPcdata_t* data( NULL ); |
|
1908 PcdataNewL( data, format ); |
|
1909 CleanupStack::PushL( data ); |
|
1910 iStatusToServer->AddItemDataL( statusID, data ); |
|
1911 CleanupStack::PopAndDestroy(); // data |
|
1912 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlFormatNotSupported, EFalse, EFalse ); |
|
1913 } |
|
1914 |
|
1915 // MaxObjSize |
|
1916 if ( databaseExists ) |
|
1917 { |
|
1918 TInt maxObjSize( ServerMaxObjSize( aSync->meta ) ); |
|
1919 |
|
1920 if ( maxObjSize > 0 ) |
|
1921 { |
|
1922 iDSContent.SetMaxObjSizeInServer( maxObjSize ); |
|
1923 } |
|
1924 } |
|
1925 |
|
1926 // NumberOfChanges |
|
1927 if ( databaseExists ) |
|
1928 { |
|
1929 TInt nocNum( -1 ); |
|
1930 TBool NocNumReceived( EFalse ); |
|
1931 if ( !iDSContent.ServerItemCountAsked() ) |
|
1932 { |
|
1933 // If new number of changes info is received |
|
1934 if ( aSync->noc ) |
|
1935 { |
|
1936 if ( aSync->noc->content ) |
|
1937 { |
|
1938 TPtr8 nocStr( static_cast<TUint8*>( aSync->noc->content ), |
|
1939 aSync->noc->length, aSync->noc->length ); |
|
1940 TrimRightSpaceAndNull( nocStr ); |
|
1941 TLex8 lexicalValue( nocStr ); |
|
1942 |
|
1943 if ( lexicalValue.Val( nocNum ) == KErrNone ) |
|
1944 { |
|
1945 NocNumReceived = ETrue; |
|
1946 iDSContent.SetServerItemCount( nocNum ); |
|
1947 } |
|
1948 } |
|
1949 } |
|
1950 // else number of changes information is not received |
|
1951 if ( !NocNumReceived ) |
|
1952 { |
|
1953 iDSContent.SetServerItemCount( nocNum ); |
|
1954 } |
|
1955 iDSObserver.OnSyncMLSyncProgress( |
|
1956 MSyncMLProgressObserver::ESmlReceivingModificationsFromServer, |
|
1957 iDSContent.ServerItemCount(), 0 ); |
|
1958 } |
|
1959 |
|
1960 // If number of changes is more than batch limit then batch is used if |
|
1961 // plug in adapter supports batch mode |
|
1962 if ( iDSContent.ServerItemCount() >= KNSmlBatchLimit && !iMoreData ) |
|
1963 { |
|
1964 if ( iDSContent.SupportsOperationL( KUidSmlSupportBatch ) ) |
|
1965 { |
|
1966 iBatchModeOn = ETrue; |
|
1967 iDSContent.BeginBatchL(); |
|
1968 |
|
1969 if ( !iBatchBuffer ) |
|
1970 { |
|
1971 iBatchBuffer = new ( ELeave ) CNSmlDSBatchBuffer; |
|
1972 } |
|
1973 else |
|
1974 { |
|
1975 iBatchBuffer->Reset(); |
|
1976 } |
|
1977 } |
|
1978 } |
|
1979 } |
|
1980 } |
|
1981 |
|
1982 // ----------------------------------------------------------------------------- |
|
1983 // CNSmlDSCmds::ProcessEndSyncL |
|
1984 // Handles the end of the Sync command. |
|
1985 // ----------------------------------------------------------------------------- |
|
1986 // |
|
1987 void CNSmlDSCmds::ProcessEndSyncL() |
|
1988 { |
|
1989 if ( iDSContent.ContentIndexIsSet() ) |
|
1990 { |
|
1991 CommitBatchL(); |
|
1992 } |
|
1993 } |
|
1994 |
|
1995 // ----------------------------------------------------------------------------- |
|
1996 // CNSmlDSCmds::ProcessUpdatesL |
|
1997 // Processes received Add, Replace, Move and Delete commands. |
|
1998 // ----------------------------------------------------------------------------- |
|
1999 // |
|
2000 void CNSmlDSCmds::ProcessUpdatesL( const TDesC8& aCmd, SmlGenericCmd_t* aContent ) |
|
2001 { |
|
2002 // Is the sync previously interrupted? |
|
2003 TBool alreadyInterrupted ( EFalse ); |
|
2004 |
|
2005 if ( iDSContent.AllDatabasesAreInterrupted() ) |
|
2006 { |
|
2007 alreadyInterrupted = ETrue; |
|
2008 } |
|
2009 else |
|
2010 { |
|
2011 if ( !iDSContent.ContentIndexIsSet() ) |
|
2012 { |
|
2013 alreadyInterrupted = ETrue; |
|
2014 } |
|
2015 else |
|
2016 { |
|
2017 if ( iDSContent.Interrupted() ) |
|
2018 { |
|
2019 alreadyInterrupted = ETrue; |
|
2020 } |
|
2021 } |
|
2022 } |
|
2023 |
|
2024 if ( !aContent->itemList ) |
|
2025 { |
|
2026 return; |
|
2027 } |
|
2028 else |
|
2029 { |
|
2030 if ( !aContent->itemList->item ) |
|
2031 { |
|
2032 return; |
|
2033 } |
|
2034 } |
|
2035 |
|
2036 SmlItemList_t* itemList( aContent->itemList ); |
|
2037 SmlItem_t* item( aContent->itemList->item ); |
|
2038 |
|
2039 do |
|
2040 { |
|
2041 TBool processUpdate( EFalse ); |
|
2042 |
|
2043 if ( alreadyInterrupted ) |
|
2044 { |
|
2045 StatusDataToGenericCommandL( aCmd, aContent, item, TNSmlError::ESmlStatusCommandFailed ); |
|
2046 } |
|
2047 else if ( iAtomicHasFailed ) |
|
2048 { |
|
2049 StatusDataToGenericCommandL( aCmd, aContent, item, TNSmlError::ESmlStatusCommandFailed ); |
|
2050 } |
|
2051 else |
|
2052 { |
|
2053 TBool typeAndFormatOK( EFalse ); |
|
2054 |
|
2055 if ( iMoreData ) |
|
2056 { |
|
2057 typeAndFormatOK = ETrue; |
|
2058 } |
|
2059 else |
|
2060 { |
|
2061 if ( CheckAndSetReceivedMediaTypeL( aCmd, aContent, item ) ) |
|
2062 { |
|
2063 if ( IsFormatOkL( aCmd, aContent, item ) ) |
|
2064 { |
|
2065 typeAndFormatOK = ETrue; |
|
2066 } |
|
2067 } |
|
2068 } |
|
2069 |
|
2070 if ( typeAndFormatOK ) |
|
2071 { |
|
2072 TSmlDbItemUid parent; |
|
2073 TBool resumeBatchMode( EFalse ); |
|
2074 HBufC8* sourceParent( NULL ); |
|
2075 |
|
2076 processUpdate = ETrue; |
|
2077 |
|
2078 // check if SourceParent is received |
|
2079 if ( !IsParentOkL( item->targetParent, parent ) ) |
|
2080 { |
|
2081 if ( IsParentOkLC( item->sourceParent, sourceParent ) ) |
|
2082 { |
|
2083 if ( iBatchModeOn ) |
|
2084 { |
|
2085 CommitBatchL(); |
|
2086 resumeBatchMode = ETrue; |
|
2087 } |
|
2088 |
|
2089 if ( !iDSContent.MapSourceParent( *sourceParent, parent ) ) |
|
2090 { |
|
2091 TInt statusId; |
|
2092 |
|
2093 if ( aCmd == KNSmlAgentMove ) |
|
2094 { |
|
2095 statusId = StatusDataToGenericCommandL( aCmd, aContent, item, TNSmlError::ESmlStatusMoveFailed ); |
|
2096 } |
|
2097 else |
|
2098 { |
|
2099 statusId = StatusDataToGenericCommandL( aCmd, aContent, item, TNSmlError::ESmlStatusCommandFailed ); |
|
2100 } |
|
2101 |
|
2102 processUpdate = EFalse; |
|
2103 |
|
2104 if ( iAtomicModeOn ) |
|
2105 { |
|
2106 iStatusToServer->SetAtomicOrSequenceId( statusId, iAtomicId ); |
|
2107 iAtomicHasFailed = ETrue; |
|
2108 } |
|
2109 } |
|
2110 } |
|
2111 // Move MUST include either TargetParent or SourceParent |
|
2112 else if ( aCmd == KNSmlAgentMove ) |
|
2113 { |
|
2114 processUpdate = EFalse; |
|
2115 StatusDataToGenericCommandL( aCmd, aContent, item, TNSmlError::ESmlStatusIncompleteCommand ); |
|
2116 } |
|
2117 } |
|
2118 |
|
2119 if ( processUpdate ) |
|
2120 { |
|
2121 HBufC8* cmdLUID( NULL ); |
|
2122 HBufC8* cmdGUID( NULL ); |
|
2123 |
|
2124 if ( aCmd == KNSmlAgentReplace || aCmd == KNSmlAgentDelete || aCmd == KNSmlAgentMove ) |
|
2125 { |
|
2126 if ( IsLUIDOkLC( aCmd, aContent, item, cmdLUID ) ) |
|
2127 { |
|
2128 UpdateL( aCmd, aContent, item, *cmdLUID, parent ); |
|
2129 } |
|
2130 else |
|
2131 { |
|
2132 processUpdate = EFalse; |
|
2133 |
|
2134 if ( iAtomicModeOn ) |
|
2135 { |
|
2136 iAtomicHasFailed = ETrue; |
|
2137 } |
|
2138 } |
|
2139 } |
|
2140 else // Add |
|
2141 { |
|
2142 if ( IsGUIDOkLC( aCmd, aContent, item, cmdGUID ) ) |
|
2143 { |
|
2144 UpdateL( aCmd, aContent, item, *cmdGUID, parent ); |
|
2145 } |
|
2146 else |
|
2147 { |
|
2148 processUpdate = EFalse; |
|
2149 |
|
2150 if ( iAtomicModeOn ) |
|
2151 { |
|
2152 iAtomicHasFailed = ETrue; |
|
2153 } |
|
2154 } |
|
2155 } |
|
2156 |
|
2157 if ( cmdGUID ) |
|
2158 { |
|
2159 CleanupStack::PopAndDestroy(); // cmdGUID; |
|
2160 } |
|
2161 |
|
2162 if ( cmdLUID ) |
|
2163 { |
|
2164 CleanupStack::PopAndDestroy(); // cmdLUID; |
|
2165 } |
|
2166 } |
|
2167 |
|
2168 if ( sourceParent ) |
|
2169 { |
|
2170 CleanupStack::PopAndDestroy(); // sourceParent |
|
2171 } |
|
2172 |
|
2173 if ( resumeBatchMode ) |
|
2174 { |
|
2175 iDSContent.BeginBatchL(); |
|
2176 } |
|
2177 } |
|
2178 } |
|
2179 |
|
2180 // if no updates were done then the item has failed |
|
2181 if ( !processUpdate ) |
|
2182 { |
|
2183 MSyncMLProgressObserver::TSyncMLDataSyncModifications clientModifications = { 0, 0, 0, 0, 0 }; |
|
2184 MSyncMLProgressObserver::TSyncMLDataSyncModifications serverModifications = { 0, 0, 0, 0, 0 }; |
|
2185 |
|
2186 clientModifications.iNumFailed = 1; |
|
2187 iDSObserver.OnSyncMLDataSyncModifications( iDSContent.TaskId(), clientModifications, serverModifications ); |
|
2188 |
|
2189 if ( iDSContent.ContentIndexIsSet() ) |
|
2190 { |
|
2191 iDSContent.IncreaseServerItemsFailed(); |
|
2192 } |
|
2193 } |
|
2194 |
|
2195 // next item |
|
2196 item = NULL; |
|
2197 |
|
2198 if ( itemList->next ) |
|
2199 { |
|
2200 itemList = itemList->next; |
|
2201 |
|
2202 if ( itemList->item ) |
|
2203 { |
|
2204 item = itemList->item; |
|
2205 } |
|
2206 } |
|
2207 } while ( item ); |
|
2208 } |
|
2209 |
|
2210 // ----------------------------------------------------------------------------- |
|
2211 // CNSmlDSCmds::ProcessAtomicL |
|
2212 // Processes the Atomic command. |
|
2213 // ----------------------------------------------------------------------------- |
|
2214 // |
|
2215 void CNSmlDSCmds::ProcessAtomicL( SmlAtomic_t* aAtomic ) |
|
2216 { |
|
2217 TInt statusId( iStatusToServer->CreateNewStatusElementL() ); |
|
2218 |
|
2219 iStatusToServer->SetCmdRefL( statusId, aAtomic->cmdID ); |
|
2220 iStatusToServer->SetCmdL( statusId, KNSmlAgentAtomic ); |
|
2221 |
|
2222 if ( iStatusToServerNoResponse || IsFlagSet( aAtomic->flags, SmlNoResp_f ) ) |
|
2223 { |
|
2224 iStatusToServer->SetNoResponse( statusId, ETrue ); |
|
2225 } |
|
2226 else |
|
2227 { |
|
2228 iStatusToServer->SetNoResponse( statusId, EFalse ); |
|
2229 } |
|
2230 |
|
2231 if ( iDSContent.AllDatabasesAreInterrupted() ) |
|
2232 { |
|
2233 iStatusToServer->SetStatusCodeL( statusId, TNSmlError::ESmlStatusAtomicFailed ); |
|
2234 return; |
|
2235 } |
|
2236 |
|
2237 ++iAtomicId; |
|
2238 |
|
2239 if ( iDSContent.ContentIndexIsSet() ) |
|
2240 { |
|
2241 if ( iDSContent.SupportsOperationL( KUidSmlSupportTransaction) ) |
|
2242 { |
|
2243 iAtomicHasFailed = EFalse; |
|
2244 iDSContent.BeginTransActionL(); |
|
2245 iStatusToServer->SetStatusCodeL( statusId, TNSmlError::ESmlStatusOK ); |
|
2246 iStatusToServer->SetAtomicOrSequenceId( statusId, iAtomicId ); |
|
2247 } |
|
2248 else |
|
2249 { |
|
2250 iAtomicHasFailed = ETrue; |
|
2251 iStatusToServer->SetStatusCodeL( statusId, TNSmlError::ESmlStatusAtomicFailed ); |
|
2252 } |
|
2253 } |
|
2254 else |
|
2255 { |
|
2256 iAtomicHasFailed = EFalse; |
|
2257 iStatusToServer->SetStatusCodeL( statusId, TNSmlError::ESmlStatusOK ); |
|
2258 iStatusToServer->SetAtomicOrSequenceId( statusId, iAtomicId ); |
|
2259 } |
|
2260 |
|
2261 iAtomicModeOn = ETrue; |
|
2262 } |
|
2263 |
|
2264 // ----------------------------------------------------------------------------- |
|
2265 // CNSmlDSCmds::ProcessEndAtomicL |
|
2266 // Handles the end of the Atomic command. |
|
2267 // ----------------------------------------------------------------------------- |
|
2268 // |
|
2269 void CNSmlDSCmds::ProcessEndAtomicL() |
|
2270 { |
|
2271 TInt resultCode; |
|
2272 |
|
2273 iDSContent.SaveCurrentIndex(); |
|
2274 iDSContent.SetToFirst(); |
|
2275 |
|
2276 do |
|
2277 { |
|
2278 if ( iDSContent.BatchModeOn() ) |
|
2279 { |
|
2280 CommitBatchL(); |
|
2281 } |
|
2282 } |
|
2283 while ( iDSContent.SetToNext() ); |
|
2284 |
|
2285 iDSContent.SetIndexToSaved(); |
|
2286 |
|
2287 if ( iAtomicHasFailed ) |
|
2288 { |
|
2289 iDSContent.SaveCurrentIndex(); |
|
2290 iDSContent.SetToFirst(); |
|
2291 |
|
2292 do |
|
2293 { |
|
2294 if ( iDSContent.AtomicModeOn() ) |
|
2295 { |
|
2296 iDSContent.RemoveFailedMappingsL( iAtomicId ); |
|
2297 iDSContent.RevertTransactionL( resultCode ); |
|
2298 } |
|
2299 } |
|
2300 while ( iDSContent.SetToNext() ); |
|
2301 |
|
2302 iDSContent.SetIndexToSaved(); |
|
2303 |
|
2304 iStatusToServer->SetStatusCodesInAtomicL( iAtomicId, TNSmlError::ESmlStatusRollBackOK, EFalse ); |
|
2305 iStatusToServer->SetStatusCodeToAtomicOrSequenceCmdL( iAtomicId, TNSmlError::ESmlStatusAtomicFailed, KNSmlAgentAtomic ); |
|
2306 } |
|
2307 else |
|
2308 { |
|
2309 TBool atomicSucceeded( ETrue ); |
|
2310 iDSContent.SaveCurrentIndex(); |
|
2311 iDSContent.SetToFirst(); |
|
2312 |
|
2313 do |
|
2314 { |
|
2315 if ( iDSContent.AtomicModeOn() ) |
|
2316 { |
|
2317 iDSContent.CommitTransactionL( resultCode ); |
|
2318 |
|
2319 if ( resultCode != KErrNone ) |
|
2320 { |
|
2321 atomicSucceeded = EFalse; |
|
2322 } |
|
2323 } |
|
2324 } |
|
2325 while ( iDSContent.SetToNext() ); |
|
2326 |
|
2327 iDSContent.SetIndexToSaved(); |
|
2328 |
|
2329 if ( !atomicSucceeded ) |
|
2330 { |
|
2331 iStatusToServer->SetStatusCodesInAtomicL( iAtomicId, TNSmlError::ESmlStatusRollBackOK, EFalse ); |
|
2332 iStatusToServer->SetStatusCodeToAtomicOrSequenceCmdL( iAtomicId, TNSmlError::ESmlStatusAtomicFailed, KNSmlAgentAtomic ); |
|
2333 } |
|
2334 } |
|
2335 |
|
2336 iAtomicModeOn = EFalse; |
|
2337 iAtomicHasFailed = EFalse; |
|
2338 } |
|
2339 |
|
2340 // ----------------------------------------------------------------------------- |
|
2341 // CNSmlDSCmds::ProcessSequenceL |
|
2342 // Processes the Sequence command. Currently this command is not supported. |
|
2343 // ----------------------------------------------------------------------------- |
|
2344 // |
|
2345 void CNSmlDSCmds::ProcessSequenceL( SmlSequence_t* /*aSequence*/ ) |
|
2346 { |
|
2347 } |
|
2348 |
|
2349 // ----------------------------------------------------------------------------- |
|
2350 // CNSmlDSCmds::ProcessEndSequence |
|
2351 // Handles the end of the Sequence command. Currently this command is not |
|
2352 // supported. |
|
2353 // ----------------------------------------------------------------------------- |
|
2354 // |
|
2355 void CNSmlDSCmds::ProcessEndSequence() |
|
2356 { |
|
2357 } |
|
2358 |
|
2359 // ----------------------------------------------------------------------------- |
|
2360 // CNSmlDSCmds::DoEndMessageL |
|
2361 // Generates end tag of a SyncML element and possible final flag in SyncBody. |
|
2362 // ----------------------------------------------------------------------------- |
|
2363 // |
|
2364 void CNSmlDSCmds::DoEndMessageL( TBool aFinal ) |
|
2365 { |
|
2366 TInt ret; |
|
2367 |
|
2368 if ( aFinal ) |
|
2369 { |
|
2370 ret = iGenerator->smlEndMessage( ETrue ); |
|
2371 } |
|
2372 else |
|
2373 { |
|
2374 ret = iGenerator->smlEndMessage( EFalse ); |
|
2375 } |
|
2376 |
|
2377 if ( ret != KWBXMLGeneratorOk ) |
|
2378 { |
|
2379 User::Leave( ret ); |
|
2380 } |
|
2381 } |
|
2382 |
|
2383 // ----------------------------------------------------------------------------- |
|
2384 // CNSmlDSCmds::MatchServerAlertL |
|
2385 // Constructs URIs for local and remote databases received from a server. |
|
2386 // ----------------------------------------------------------------------------- |
|
2387 // |
|
2388 TBool CNSmlDSCmds::MatchServerAlertL( const SmlAlert_t* aAlert, TInt aStatusID ) |
|
2389 { |
|
2390 TBool databaseExists( EFalse ); |
|
2391 HBufC* imeiCode = HBufC::NewLC( 50 ); |
|
2392 HBufC* alertTarget; |
|
2393 TPtr imeiCodePtr( imeiCode->Des() ); |
|
2394 iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneSerialNumber, imeiCodePtr ); |
|
2395 CNSmlURI* localURI = CNSmlURI::NewLC( *imeiCode ); |
|
2396 |
|
2397 if ( !TargetIsUnderItem( aAlert->itemList ) ) |
|
2398 { |
|
2399 alertTarget = HBufC::NewLC( 0 ); |
|
2400 } |
|
2401 else |
|
2402 { |
|
2403 PCDATAToUnicodeLC( *aAlert->itemList->item->target->locURI, alertTarget ); |
|
2404 alertTarget->Des().TrimRight(); |
|
2405 } |
|
2406 |
|
2407 localURI->SetDatabaseL( *alertTarget ); |
|
2408 |
|
2409 HBufC* alertSource; |
|
2410 CNSmlURI* remoteURI = CNSmlURI::NewLC(); |
|
2411 |
|
2412 *remoteURI = *iSyncServer; |
|
2413 |
|
2414 if ( !SourceIsUnderItem( aAlert->itemList ) ) |
|
2415 { |
|
2416 alertSource = HBufC::NewLC( 0 ); |
|
2417 } |
|
2418 else |
|
2419 { |
|
2420 PCDATAToUnicodeLC( *aAlert->itemList->item->source->locURI, alertSource ); |
|
2421 alertSource->Des().TrimRight(); |
|
2422 } |
|
2423 |
|
2424 remoteURI->SetDatabaseL( *alertSource ); |
|
2425 |
|
2426 SmlMetInfMetInf_t* metInf; |
|
2427 TPtr8 mediaType( NULL, 0, 0 ); |
|
2428 |
|
2429 if ( aAlert->itemList->item->meta ) |
|
2430 { |
|
2431 if ( aAlert->itemList->item->meta->content && |
|
2432 aAlert->itemList->item->meta->contentType == SML_PCDATA_EXTENSION && |
|
2433 aAlert->itemList->item->meta->extension == SML_EXT_METINF ) |
|
2434 { |
|
2435 metInf = (SmlMetInfMetInf_t*) aAlert->itemList->item->meta->content; |
|
2436 |
|
2437 if ( metInf->type ) |
|
2438 { |
|
2439 mediaType.Set( static_cast<TUint8*>( metInf->type->content ), metInf->type->length, metInf->type->length ); |
|
2440 TrimRightSpaceAndNull( mediaType ); |
|
2441 } |
|
2442 } |
|
2443 } |
|
2444 |
|
2445 if( iDSContent.SetIndexByRemoteDatabaseL( *remoteURI,ETrue ) ) |
|
2446 { |
|
2447 databaseExists = ETrue; |
|
2448 } |
|
2449 else |
|
2450 { |
|
2451 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusNotFound ); |
|
2452 } |
|
2453 |
|
2454 if ( iUnknownDevice && databaseExists ) |
|
2455 { |
|
2456 databaseExists = EFalse; |
|
2457 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusNotFound ); |
|
2458 } |
|
2459 CleanupStack::PopAndDestroy( 5 ); // alertSource, remoteURI, alertTarget, localURI, imeiCode |
|
2460 |
|
2461 return databaseExists; |
|
2462 } |
|
2463 |
|
2464 // ----------------------------------------------------------------------------- |
|
2465 // CNSmlDSCmds::DoDeviceInfoL |
|
2466 // Builds DevInfo structure. |
|
2467 // ----------------------------------------------------------------------------- |
|
2468 // |
|
2469 TPtrC8 CNSmlDSCmds::DoDeviceInfoL( TBool aConvert ) |
|
2470 { |
|
2471 // create generator instance first |
|
2472 if ( !iDSDevGenerator ) |
|
2473 { |
|
2474 iDSDevGenerator = new( ELeave ) CWBXMLDevInfGenerator; |
|
2475 } |
|
2476 |
|
2477 // create workspace |
|
2478 iDSDevGenerator->CreateWorkspaceL(); |
|
2479 |
|
2480 //initialise DevInf |
|
2481 SmlDevInfDevInf_t* devInf = new( ELeave ) SmlDevInfDevInf_t; |
|
2482 CleanupStack::PushL( devInf ); |
|
2483 |
|
2484 // VerDTD element |
|
2485 PcdataNewL ( devInf->verdtd, KNSmlAgentVerDTD12 ); |
|
2486 |
|
2487 // Man element (manufacturer) |
|
2488 HBufC* manufacturer = HBufC::NewLC( 50 ); |
|
2489 TPtr manufacturerPtr( manufacturer->Des() ); |
|
2490 iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneManufacturer, manufacturerPtr ); |
|
2491 HBufC8* manufacturerInUTF8( NULL ); |
|
2492 NSmlUnicodeConverter::HBufC8InUTF8LC( *manufacturer, manufacturerInUTF8 ); |
|
2493 PcdataNewL ( devInf->man, *manufacturerInUTF8 ); |
|
2494 CleanupStack::PopAndDestroy( 2 ); // manufacturerInUTF8, manufacturer |
|
2495 |
|
2496 PcdataNewL ( devInf->fwv, KNullDesC8() ); |
|
2497 |
|
2498 // Mod element (model name) |
|
2499 HBufC* model = HBufC::NewLC( 50 ); |
|
2500 TPtr modelPtr = model->Des(); |
|
2501 iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneModelId, modelPtr ); |
|
2502 HBufC8* modelInUTF8 = NULL; |
|
2503 NSmlUnicodeConverter::HBufC8InUTF8LC( *model, modelInUTF8 ); |
|
2504 PcdataNewL ( devInf->mod, *modelInUTF8 ); |
|
2505 CleanupStack::PopAndDestroy( 2 ); // modelInUTF8, model |
|
2506 // SwV element (software version) |
|
2507 PcdataNewL ( devInf->swv, iPhoneInfo->SwVersionL() ); |
|
2508 |
|
2509 PcdataNewL ( devInf->hwv, KNullDesC8() ); |
|
2510 |
|
2511 // DevId element |
|
2512 HBufC* devId = HBufC::NewLC( 50 ); |
|
2513 TPtr devIdPtr( devId->Des() ); |
|
2514 iPhoneInfo->PhoneDataL( CNSmlPhoneInfo::EPhoneSerialNumber, devIdPtr ); |
|
2515 HBufC8* devIdInUTF8( NULL ); |
|
2516 NSmlUnicodeConverter::HBufC8InUTF8LC( *devId, devIdInUTF8 ); |
|
2517 PcdataNewL ( devInf->devid, *devIdInUTF8 ); |
|
2518 CleanupStack::PopAndDestroy( 2 ); // devIdInUTF8, devId |
|
2519 |
|
2520 // DevTyp element |
|
2521 _LIT8( KDevTyp, "phone" ); |
|
2522 PcdataNewL ( devInf->devtyp, KDevTyp ); |
|
2523 |
|
2524 // SupportLargeObjs element |
|
2525 devInf->flags += SmlSupportLargeObjects_f; |
|
2526 |
|
2527 // SupportNumberOfChanges element |
|
2528 devInf->flags += SmlSupportNumberOfChanges_f; |
|
2529 |
|
2530 // SupportUTC element |
|
2531 devInf->flags += SmlUTC_f; |
|
2532 |
|
2533 // DataStore elements |
|
2534 SmlDevInfDatastoreList_t** currDatastorePtr = &devInf->datastore; |
|
2535 |
|
2536 iDSContent.SetToFirst(); |
|
2537 |
|
2538 do |
|
2539 { |
|
2540 if ( iDSContent.Interrupted() ) |
|
2541 { |
|
2542 continue; |
|
2543 } |
|
2544 |
|
2545 CDesCArray* storeNames = iDSContent.StoreNamesL(); |
|
2546 CleanupStack::PushL( storeNames ); |
|
2547 |
|
2548 for ( TInt i = 0; i < storeNames->Count(); i++ ) |
|
2549 { |
|
2550 CNSmlDbCaps* dbCaps; |
|
2551 TInt result = iDSContent.DbCapabilitiesL( dbCaps ); |
|
2552 |
|
2553 if ( result != KErrNone ) |
|
2554 { |
|
2555 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlStatusCommandFailed, EFalse, EFalse ); |
|
2556 continue; |
|
2557 } |
|
2558 |
|
2559 CleanupStack::PushL( dbCaps ); |
|
2560 |
|
2561 // DataStore begins |
|
2562 *currDatastorePtr = new( ELeave ) SmlDevInfDatastoreList_t; |
|
2563 (*currDatastorePtr)->data = dbCaps->DatastoreL(); // ownership is changed |
|
2564 |
|
2565 CNSmlURI *databaseURI = CNSmlURI::NewLC(); |
|
2566 databaseURI->SetDatabaseL( (*storeNames)[i], ETrue ); |
|
2567 HBufC8* databaseURIInUTF8; |
|
2568 NSmlUnicodeConverter::HBufC8InUTF8LC( databaseURI->Database(), databaseURIInUTF8 ); |
|
2569 delete (*currDatastorePtr)->data->sourceref; |
|
2570 PcdataNewL ( (*currDatastorePtr)->data->sourceref,*databaseURIInUTF8 ); |
|
2571 CleanupStack::PopAndDestroy( 2 ); // databaseURI, databaseURIInUTF8 |
|
2572 |
|
2573 (*currDatastorePtr)->data->filtercap = dbCaps->FilterCaps(); |
|
2574 |
|
2575 // SourceRef element |
|
2576 // MaxGUIDSize |
|
2577 PcdataNewL ( (*currDatastorePtr)->data->maxguidsize, KNSmlDSAgentMaxGUIDSize ); |
|
2578 // RxPref, Rx, TxPref and Tx elements are already filled by an adpater |
|
2579 // SyncCap begins |
|
2580 (*currDatastorePtr)->data->synccap = new( ELeave ) SmlDevInfSyncCap_t; |
|
2581 (*currDatastorePtr)->data->synccap->synctype = new( ELeave ) SmlPcdataList_t; |
|
2582 SmlPcdataList_t** currSynctypePtr = &(*currDatastorePtr)->data->synccap->synctype; |
|
2583 // Sync Type elements |
|
2584 |
|
2585 TBuf8<1> stringSyncType; |
|
2586 |
|
2587 stringSyncType.Num( (TInt) CNSmlDbCaps::ETwoWaySync ); |
|
2588 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2589 (*currSynctypePtr)->next = new( ELeave ) SmlPcdataList_t; |
|
2590 currSynctypePtr = &(*currSynctypePtr)->next; |
|
2591 stringSyncType.Num( (TInt) CNSmlDbCaps::ESlowTwoWaySync ); |
|
2592 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2593 |
|
2594 if ( iDSContent.IsSupportedSyncTypeL( CNSmlDbCaps::EOneWaySyncFromClient ) ) |
|
2595 { |
|
2596 (*currSynctypePtr)->next = new( ELeave ) SmlPcdataList_t; |
|
2597 currSynctypePtr = &(*currSynctypePtr)->next; |
|
2598 stringSyncType.Num( (TInt) CNSmlDbCaps::EOneWaySyncFromClient ); |
|
2599 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2600 } |
|
2601 |
|
2602 if ( iDSContent.IsSupportedSyncTypeL( CNSmlDbCaps::ERefreshSyncFromClient ) ) |
|
2603 { |
|
2604 (*currSynctypePtr)->next = new( ELeave ) SmlPcdataList_t; |
|
2605 currSynctypePtr = &(*currSynctypePtr)->next; |
|
2606 stringSyncType.Num( (TInt) CNSmlDbCaps::ERefreshSyncFromClient ); |
|
2607 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2608 } |
|
2609 |
|
2610 if ( iDSContent.IsSupportedSyncTypeL( CNSmlDbCaps::EOneWaySyncFromServer ) ) |
|
2611 { |
|
2612 (*currSynctypePtr)->next = new( ELeave ) SmlPcdataList_t; |
|
2613 currSynctypePtr = &(*currSynctypePtr)->next; |
|
2614 stringSyncType.Num( (TInt) CNSmlDbCaps::EOneWaySyncFromServer ); |
|
2615 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2616 } |
|
2617 |
|
2618 if ( iDSContent.IsSupportedSyncTypeL( CNSmlDbCaps::ERefreshSyncFromServer ) ) |
|
2619 { |
|
2620 (*currSynctypePtr)->next = new( ELeave ) SmlPcdataList_t; |
|
2621 currSynctypePtr = &(*currSynctypePtr)->next; |
|
2622 stringSyncType.Num( (TInt) CNSmlDbCaps::ERefreshSyncFromServer ); |
|
2623 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2624 } |
|
2625 |
|
2626 (*currSynctypePtr)->next = new( ELeave ) SmlPcdataList_t; |
|
2627 currSynctypePtr = &(*currSynctypePtr)->next; |
|
2628 stringSyncType.Num( (TInt) CNSmlDbCaps::EServerAlertedSync ); |
|
2629 PcdataNewL ( (*currSynctypePtr)->data, stringSyncType ); |
|
2630 |
|
2631 // SyncCap ends |
|
2632 currDatastorePtr = &(*currDatastorePtr)->next; |
|
2633 |
|
2634 CleanupStack::PopAndDestroy(); // dbCaps |
|
2635 } |
|
2636 |
|
2637 CleanupStack::PopAndDestroy(); // storeNames |
|
2638 } while ( iDSContent.SetToNext() ); |
|
2639 |
|
2640 if ( aConvert ) |
|
2641 { |
|
2642 CNSmlDbCaps* dbcaps = CNSmlDbCaps::NewLC(); |
|
2643 dbcaps->ConvertDeviceInfoL( devInf ); |
|
2644 CleanupStack::PopAndDestroy(); // dbcaps |
|
2645 } |
|
2646 |
|
2647 TInt ret( iDSDevGenerator->smlDeviceInfo( devInf ) ); |
|
2648 |
|
2649 CleanupStack::PopAndDestroy(); // devInf |
|
2650 |
|
2651 if ( ret != KWBXMLGeneratorOk ) |
|
2652 { |
|
2653 User::Leave( ret ); |
|
2654 } |
|
2655 |
|
2656 return iDSDevGenerator->Document(); |
|
2657 } |
|
2658 |
|
2659 // ----------------------------------------------------------------------------- |
|
2660 // CNSmlCmdsBase::DoTargetWithFilterL |
|
2661 // Makes Source or Target element with Filter. |
|
2662 // ----------------------------------------------------------------------------- |
|
2663 // |
|
2664 void CNSmlDSCmds::DoTargetWithFilterL( sml_target_s*& aTarget, const TDesC& aLocURIData) const |
|
2665 { |
|
2666 DoTargetL( aTarget, aLocURIData ); |
|
2667 aTarget->locName = NULL; |
|
2668 |
|
2669 if ( !iDSContent.HasFilters() ) |
|
2670 { |
|
2671 return; |
|
2672 } |
|
2673 |
|
2674 CNSmlFilter* filter( CNSmlFilter::NewLC() ); |
|
2675 |
|
2676 TInt retval( iDSContent.GetFilterL( filter ) ); |
|
2677 |
|
2678 if ( retval == KErrNone ) |
|
2679 { |
|
2680 aTarget->filter = filter->FilterL(); |
|
2681 } |
|
2682 else if ( retval != KErrNotSupported ) |
|
2683 { |
|
2684 User::Leave( retval ); |
|
2685 } |
|
2686 |
|
2687 CleanupStack::PopAndDestroy(); // filter |
|
2688 } |
|
2689 |
|
2690 // ----------------------------------------------------------------------------- |
|
2691 // CNSmlDSCmds::FreeDeviceInfo |
|
2692 // Frees resources allocated by the DevInfo generator. |
|
2693 // ----------------------------------------------------------------------------- |
|
2694 // |
|
2695 void CNSmlDSCmds::FreeDeviceInfo() |
|
2696 { |
|
2697 delete iDSDevGenerator; |
|
2698 iDSDevGenerator = NULL; |
|
2699 } |
|
2700 |
|
2701 // ----------------------------------------------------------------------------- |
|
2702 // CNSmlDSCmds::ParseDeviceInfoL |
|
2703 // Parses the given DevInfo structure. |
|
2704 // ----------------------------------------------------------------------------- |
|
2705 // |
|
2706 void CNSmlDSCmds::ParseDeviceInfoL( TInt aStatusID, const TPtrC8& aDeviceInfo ) |
|
2707 { |
|
2708 CWBXMLDevInfDocHandler* devDocHandler = CWBXMLDevInfDocHandler::NewL( this ); |
|
2709 CleanupStack::PushL( devDocHandler ); |
|
2710 |
|
2711 CWBXMLParser* devParser = CWBXMLParser::NewL(); |
|
2712 CleanupStack::PushL( devParser ); |
|
2713 |
|
2714 devParser->SetDocumentHandler( devDocHandler ); |
|
2715 devParser->SetExtensionHandler( devDocHandler ); |
|
2716 RDesReadStream devReadStream( aDeviceInfo ); |
|
2717 devParser->SetDocumentL( devReadStream ); |
|
2718 TWBXMLParserError ret( KWBXMLParserErrorOk ); |
|
2719 iDSDeviceInfoParsed = EFalse; |
|
2720 |
|
2721 do |
|
2722 { |
|
2723 ret = devParser->ParseL(); |
|
2724 |
|
2725 if ( ret != KWBXMLParserErrorOk && ret != KWBXMLParserErrorEof ) |
|
2726 { |
|
2727 iAgent->Interrupt( TNSmlDSError::ESmlDSDeviceInfoInvalid, EFalse, EFalse ); |
|
2728 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusCommandFailed ); |
|
2729 } |
|
2730 } while ( ret == KWBXMLParserErrorOk && iDSDeviceInfoParsed == EFalse ); |
|
2731 |
|
2732 CleanupStack::PopAndDestroy( 2 ); // devParser, devDocHandler |
|
2733 } |
|
2734 |
|
2735 |
|
2736 // ----------------------------------------------------------------------------- |
|
2737 // CNSmlDSCmds::ProcessDeviceInfoL |
|
2738 // Processes the DevInfo structure received from a server. |
|
2739 // ----------------------------------------------------------------------------- |
|
2740 // |
|
2741 void CNSmlDSCmds::ProcessDeviceInfoL( const SmlDevInfDevInf_t& aContent ) |
|
2742 { |
|
2743 iDSDeviceInfoParsed = ETrue; |
|
2744 TInt statusID( iStatusToServer->LastEntryID() ); |
|
2745 |
|
2746 // VerDTD |
|
2747 if ( iVersionCheck ) |
|
2748 { |
|
2749 if ( !IsVersionOkL( aContent, statusID ) ) |
|
2750 return; |
|
2751 } |
|
2752 |
|
2753 if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
2754 { |
|
2755 if ( !UpdateServerIdInSettingsL( aContent, statusID ) ) |
|
2756 return; |
|
2757 } |
|
2758 |
|
2759 // DataStore |
|
2760 SmlDevInfDatastoreList_t* currDatastore( aContent.datastore ); |
|
2761 SmlDevInfCtCapList_t* currCtCapList( aContent.ctcap ); |
|
2762 |
|
2763 RPointerArray<CNSmlDbCaps> dbCapArray; |
|
2764 CleanupStack::PushL( TCleanupItem( DeleteRPointerArray, &dbCapArray ) ); |
|
2765 // check if all remote databases are present in devinf |
|
2766 SmlDevInfDatastoreList_t* tempDatastore = currDatastore; |
|
2767 RPointerArray<CNSmlURI> srcRefArray; |
|
2768 TInt count = 0; |
|
2769 |
|
2770 while( tempDatastore ) |
|
2771 { |
|
2772 if ( !tempDatastore->data ) |
|
2773 { |
|
2774 tempDatastore = tempDatastore->next; |
|
2775 continue; |
|
2776 } |
|
2777 HBufC8* srcRef = tempDatastore->data->sourceref->Data().AllocLC(); |
|
2778 TPtr8 srcRefPtr( srcRef->Des() ); |
|
2779 TrimRightSpaceAndNull( srcRefPtr ); |
|
2780 CNSmlURI* srcRefURI = CNSmlURI::NewLC( iSyncServer->HostName() ); |
|
2781 count = count + 2; |
|
2782 |
|
2783 srcRefURI->SetDatabaseL( *srcRef ); |
|
2784 srcRefArray.Append( srcRefURI ); |
|
2785 tempDatastore = tempDatastore->next; |
|
2786 } |
|
2787 |
|
2788 TBool resp( EFalse ); |
|
2789 if ( iRespURI ) |
|
2790 { |
|
2791 resp = ETrue; |
|
2792 } |
|
2793 if( !iDSContent.CheckValidRemoteDbL( srcRefArray, resp )) |
|
2794 { |
|
2795 // interrupt sync session, Invalid remote database error shown |
|
2796 iAgent->Interrupt( TNSmlError::ESmlStatusNotFound, EFalse, EFalse ); |
|
2797 } |
|
2798 |
|
2799 CleanupStack::PopAndDestroy( count ); |
|
2800 while ( currDatastore ) |
|
2801 { |
|
2802 if ( !currDatastore->data ) |
|
2803 { |
|
2804 currDatastore = currDatastore->next; |
|
2805 continue; |
|
2806 } |
|
2807 |
|
2808 CNSmlDbCaps* dbcaps = CNSmlDbCaps::NewLC(); |
|
2809 // If device info from server is accordant with 1.1 standard, |
|
2810 // copy it under correct datastore (like in 1.2) |
|
2811 AppendCTCapsL( *dbcaps, currDatastore->data, currCtCapList ); |
|
2812 |
|
2813 dbCapArray.Append( dbcaps ); |
|
2814 CleanupStack::Pop(); // dbcaps |
|
2815 |
|
2816 // SourceRef |
|
2817 TBool databaseExists( EFalse ); |
|
2818 HBufC8* sourceRef = currDatastore->data->sourceref->Data().AllocLC(); |
|
2819 TPtr8 sourceRefPtr( sourceRef->Des() ); |
|
2820 TrimRightSpaceAndNull( sourceRefPtr ); |
|
2821 |
|
2822 if ( sourceRefPtr.Length() == 0 ) |
|
2823 { |
|
2824 iStatusToServer->SetStatusCodeL( statusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
2825 iAgent->Interrupt( TNSmlDSError::ESmlDSDatastoreSourceRefMissing, EFalse, EFalse ); |
|
2826 CleanupStack::PopAndDestroy(); // sourceRef |
|
2827 break; |
|
2828 } |
|
2829 else |
|
2830 { |
|
2831 CNSmlURI* sourceRefURI = CNSmlURI::NewLC( iSyncServer->HostName() ); |
|
2832 sourceRefURI->SetDatabaseL( *sourceRef ); |
|
2833 TBool respURIExists( EFalse ); |
|
2834 |
|
2835 if ( iRespURI ) |
|
2836 { |
|
2837 respURIExists = ETrue; |
|
2838 } |
|
2839 |
|
2840 databaseExists = iDSContent.SetIndexByRemoteDatabaseL( *sourceRefURI, respURIExists ); |
|
2841 CleanupStack::PopAndDestroy(); // sourceRefURI |
|
2842 } |
|
2843 |
|
2844 CleanupStack::PopAndDestroy(); // sourceRef |
|
2845 |
|
2846 if ( !databaseExists ) |
|
2847 { |
|
2848 currDatastore = currDatastore->next; |
|
2849 continue; |
|
2850 } |
|
2851 |
|
2852 if ( !IsRxTxOkL( currDatastore, statusID, dbCapArray ) ) |
|
2853 { |
|
2854 // Something wrong with Rx or Tx |
|
2855 break; |
|
2856 } |
|
2857 |
|
2858 // Sync Types |
|
2859 CArrayFix<HBufC8*>* syncTypeArray = new( ELeave ) CArrayFixFlat<HBufC8*>(7); |
|
2860 CleanupStack::PushL( syncTypeArray ); |
|
2861 TInt pushed( 1 ); |
|
2862 SmlPcdataList_t* syncTypeList( NULL ); |
|
2863 |
|
2864 if ( currDatastore->data->synccap ) |
|
2865 { |
|
2866 syncTypeList = currDatastore->data->synccap->synctype; |
|
2867 } |
|
2868 |
|
2869 while ( syncTypeList ) |
|
2870 { |
|
2871 if ( syncTypeList->data ) |
|
2872 { |
|
2873 HBufC8* syncType = syncTypeList->data->Data().AllocLC(); |
|
2874 ++pushed; |
|
2875 TPtr8 syncTypePtr( syncType->Des() ); |
|
2876 TrimRightSpaceAndNull( syncTypePtr ); |
|
2877 syncTypeArray->AppendL( syncType ); |
|
2878 } |
|
2879 |
|
2880 syncTypeList = syncTypeList->next; |
|
2881 } |
|
2882 |
|
2883 iDSContent.UpdateSyncTypeL( *syncTypeArray ); |
|
2884 CleanupStack::PopAndDestroy( pushed ); // syncType, syncTypeArray |
|
2885 |
|
2886 // Support HierarchicalSync |
|
2887 TInt support( 0 ); |
|
2888 |
|
2889 if ( currDatastore->data->supportHierarchicalSync ) |
|
2890 { |
|
2891 support = 1; |
|
2892 } |
|
2893 |
|
2894 iDSContent.UpdateSupportHierarchicalSyncL( support ); |
|
2895 |
|
2896 // Filter-rx |
|
2897 iDSContent.RemoveFilterCapsL(); |
|
2898 |
|
2899 if ( currDatastore->data->filterrx ) |
|
2900 { |
|
2901 SmlDevInfXmitList_t* filterRxList( currDatastore->data->filterrx ); |
|
2902 |
|
2903 while ( filterRxList ) |
|
2904 { |
|
2905 if ( filterRxList->data ) |
|
2906 { |
|
2907 HBufC8* filterRxCTType = filterRxList->data->cttype->Data().AllocLC(); |
|
2908 TPtr8 filterRxCTTypePtr( filterRxCTType->Des() ); |
|
2909 TrimRightSpaceAndNull( filterRxCTTypePtr ); |
|
2910 ProcessFilterCapL ( *currDatastore->data->filtercap, *filterRxCTType ); |
|
2911 CleanupStack::PopAndDestroy(); // filterRxCTType |
|
2912 } |
|
2913 |
|
2914 filterRxList = filterRxList->next; |
|
2915 } |
|
2916 } |
|
2917 |
|
2918 currDatastore = currDatastore->next; |
|
2919 } |
|
2920 |
|
2921 CleanupStack::PopAndDestroy(); // dbCapArray |
|
2922 } |
|
2923 |
|
2924 // ----------------------------------------------------------------------------- |
|
2925 // CNSmlDSCmds::IsVersionOkL |
|
2926 // Checks the verDTD field in DevInfo. |
|
2927 // ----------------------------------------------------------------------------- |
|
2928 // |
|
2929 TBool CNSmlDSCmds::IsVersionOkL( const SmlDevInfDevInf_t& aContent, TInt aStatusID ) |
|
2930 { |
|
2931 TBool versionOK( ETrue ); |
|
2932 HBufC8* verDTD = aContent.verdtd->Data().AllocLC(); |
|
2933 TPtr8 verDTDPtr( verDTD->Des() ); |
|
2934 TrimRightSpaceAndNull( verDTDPtr ); |
|
2935 |
|
2936 if ( verDTDPtr.Length() == 0 || verDTDPtr != *iVerDTD ) |
|
2937 { |
|
2938 versionOK = EFalse; |
|
2939 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusVersionNotSupported ); |
|
2940 SmlPcdata_t* data( NULL ); |
|
2941 PcdataNewL( data, *iVerDTD ); |
|
2942 CleanupStack::PushL( data ); |
|
2943 |
|
2944 iStatusToServer->AddItemDataL( aStatusID, data ); |
|
2945 CleanupStack::PopAndDestroy(); // data |
|
2946 |
|
2947 if ( verDTDPtr.Length() == 0 ) |
|
2948 { |
|
2949 iAgent->Interrupt( TNSmlError::ESmlVerDTDMissing, EFalse, EFalse ); |
|
2950 } |
|
2951 else |
|
2952 { |
|
2953 iAgent->Interrupt( TNSmlError::ESmlVerDTDNotSupported, EFalse, EFalse ); |
|
2954 } |
|
2955 } |
|
2956 |
|
2957 CleanupStack::PopAndDestroy(); // verDTD |
|
2958 |
|
2959 return versionOK; |
|
2960 } |
|
2961 |
|
2962 // ----------------------------------------------------------------------------- |
|
2963 // CNSmlDSCmds::UpdateServerIdInSettingsL |
|
2964 // ServerId is dragged out of device info because OMA settings are currently |
|
2965 // lacking ServerId. |
|
2966 // ----------------------------------------------------------------------------- |
|
2967 // |
|
2968 TBool CNSmlDSCmds::UpdateServerIdInSettingsL( const SmlDevInfDevInf_t& aContent, TInt aStatusID ) |
|
2969 { |
|
2970 TBool serverIdOK( ETrue ); |
|
2971 HBufC8* serverId = aContent.devid->Data().AllocLC(); |
|
2972 TPtr8 serverIdPtr( serverId->Des() ); |
|
2973 TrimRightSpaceAndNull( serverIdPtr ); |
|
2974 |
|
2975 if ( serverIdPtr.Length() == 0 ) |
|
2976 { |
|
2977 serverIdOK = EFalse; |
|
2978 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
2979 iAgent->Interrupt( TNSmlDSError::ESmlDSDeviceInfoInvalid, EFalse, EFalse ); |
|
2980 } |
|
2981 else |
|
2982 { |
|
2983 TInt profileId( iAgent->ProfileId() ); |
|
2984 CNSmlDSProfile* profile = CNSmlDSSettings::NewLC()->ProfileL( profileId ); |
|
2985 |
|
2986 if ( !profile ) |
|
2987 { |
|
2988 User::Leave( TNSmlError::ESmlErrorInSettings ); |
|
2989 } |
|
2990 else |
|
2991 { |
|
2992 CleanupStack::PushL( profile ); |
|
2993 HBufC* unicode( NULL ); |
|
2994 NSmlUnicodeConverter::HBufC16InUnicodeLC( serverIdPtr, unicode ); |
|
2995 |
|
2996 // If this is a first sync with this server, there is a default |
|
2997 // ServerId (='None') in the AgentLog and Authentication tables. |
|
2998 // It must be updated. |
|
2999 TInt status = iDSContent.UpdateServerIdL( *unicode ); |
|
3000 |
|
3001 if ( status == KErrNone ) |
|
3002 { |
|
3003 profile->SetStrValue( EDSProfileServerId, *unicode ); |
|
3004 profile->SaveL(); |
|
3005 } |
|
3006 else |
|
3007 { |
|
3008 iAgent->Interrupt( status, EFalse, EFalse ); |
|
3009 serverIdOK = EFalse; |
|
3010 } |
|
3011 |
|
3012 CleanupStack::PopAndDestroy( 2 ); //profile, uniPtr |
|
3013 } |
|
3014 CleanupStack::PopAndDestroy(); |
|
3015 } |
|
3016 |
|
3017 CleanupStack::PopAndDestroy(); // serverId |
|
3018 |
|
3019 return serverIdOK; |
|
3020 } |
|
3021 |
|
3022 // ----------------------------------------------------------------------------- |
|
3023 // CNSmlDSCmds::IsRxTxOkL |
|
3024 // Checks that the types proposed by the server in DevInfo are supported both |
|
3025 // for receiving and sending. |
|
3026 // ----------------------------------------------------------------------------- |
|
3027 // |
|
3028 TBool CNSmlDSCmds::IsRxTxOkL( SmlDevInfDatastoreList_t* aCurrDatastore, TInt aStatusID, RPointerArray<CNSmlDbCaps>& aDbCapArray ) |
|
3029 { |
|
3030 iDSContent.RemoveCtCapsL(); |
|
3031 |
|
3032 // RxPref |
|
3033 TBool clientCanTransmitType( EFalse ); |
|
3034 HBufC8* rxPrefCTType( NULL ); |
|
3035 |
|
3036 if ( aCurrDatastore->data->rxpref ) |
|
3037 { |
|
3038 if ( aCurrDatastore->data->rxpref->cttype ) |
|
3039 { |
|
3040 rxPrefCTType = aCurrDatastore->data->rxpref->cttype->Data().AllocLC(); |
|
3041 TPtr8 rxPrefCTTypePtr( rxPrefCTType->Des() ); |
|
3042 TrimRightSpaceAndNull( rxPrefCTTypePtr ); |
|
3043 |
|
3044 if ( rxPrefCTTypePtr.Length() == 0 ) |
|
3045 { |
|
3046 CleanupStack::PopAndDestroy(); // rxPrefCTType |
|
3047 rxPrefCTType = NULL; |
|
3048 } |
|
3049 } |
|
3050 } |
|
3051 |
|
3052 if ( !rxPrefCTType ) |
|
3053 { |
|
3054 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
3055 iAgent->Interrupt( TNSmlDSError::ESmlDSDatastoreRxPrefCTTypeMissing, EFalse, EFalse ); |
|
3056 return EFalse; |
|
3057 } |
|
3058 |
|
3059 TInt status ( KErrNone ); |
|
3060 TRAPD( error, status = iDSContent.IsSupportedTxL( *rxPrefCTType ) ); |
|
3061 |
|
3062 if ( error != KErrNone ) |
|
3063 { |
|
3064 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusCommandFailed ); |
|
3065 iAgent->Interrupt( error, EFalse, EFalse ); |
|
3066 CleanupStack::PopAndDestroy(); // rxPrefCTType |
|
3067 return EFalse; |
|
3068 } |
|
3069 |
|
3070 if ( status ) |
|
3071 { |
|
3072 // if client supports RxPref it is used |
|
3073 clientCanTransmitType = ETrue; |
|
3074 } |
|
3075 |
|
3076 CleanupStack::PopAndDestroy(); // rxPrefCTType |
|
3077 |
|
3078 // Rx elements |
|
3079 // Read only when RxPref is not supported |
|
3080 if ( !clientCanTransmitType ) |
|
3081 { |
|
3082 SmlDevInfXmitList_t* rxList = aCurrDatastore->data->rx; |
|
3083 while ( rxList ) |
|
3084 { |
|
3085 HBufC8* rxCTType = rxList->data->cttype->Data().AllocLC(); |
|
3086 TPtr8 rxCTTypePtr( rxCTType->Des() ); |
|
3087 TrimRightSpaceAndNull( rxCTTypePtr ); |
|
3088 |
|
3089 TInt status (KErrNone ); |
|
3090 |
|
3091 TRAP( error, status = iDSContent.IsSupportedTxL( *rxCTType ) ); |
|
3092 if ( error != KErrNone ) |
|
3093 { |
|
3094 CleanupStack::PopAndDestroy(); // rxCTType |
|
3095 break; |
|
3096 } |
|
3097 |
|
3098 if ( status ) |
|
3099 { |
|
3100 clientCanTransmitType = ETrue; |
|
3101 CleanupStack::PopAndDestroy(); // rxCTType |
|
3102 break; |
|
3103 } |
|
3104 |
|
3105 CleanupStack::PopAndDestroy(); //rxCTType |
|
3106 rxList = rxList->next; |
|
3107 } |
|
3108 } |
|
3109 |
|
3110 if ( error != KErrNone ) |
|
3111 { |
|
3112 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusCommandFailed ); |
|
3113 iAgent->Interrupt( error, EFalse, EFalse ); |
|
3114 return EFalse; |
|
3115 } |
|
3116 else |
|
3117 if ( !clientCanTransmitType ) |
|
3118 { |
|
3119 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3120 iAgent->Interrupt( TNSmlDSError::ESmlDSDatastoreRxCTTypeNotMatching, EFalse, EFalse ); |
|
3121 return EFalse; |
|
3122 } |
|
3123 |
|
3124 //txPref |
|
3125 TBool clientCanReceiveType( EFalse ); |
|
3126 HBufC8* txPrefCTType( NULL ); |
|
3127 |
|
3128 if ( aCurrDatastore->data->txpref ) |
|
3129 { |
|
3130 if ( aCurrDatastore->data->txpref->cttype ) |
|
3131 { |
|
3132 txPrefCTType = aCurrDatastore->data->txpref->cttype->Data().AllocLC(); |
|
3133 TPtr8 txPrefCTTypePtr( txPrefCTType->Des() ); |
|
3134 TrimRightSpaceAndNull( txPrefCTTypePtr ); |
|
3135 |
|
3136 if ( txPrefCTTypePtr.Length() == 0 ) |
|
3137 { |
|
3138 CleanupStack::PopAndDestroy(); // txPrefCTType |
|
3139 txPrefCTType = NULL; |
|
3140 } |
|
3141 } |
|
3142 } |
|
3143 |
|
3144 if ( !txPrefCTType ) |
|
3145 { |
|
3146 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusIncompleteCommand ); |
|
3147 iAgent->Interrupt( TNSmlDSError::ESmlDSDatastoreTxPrefCTTypeMissing, EFalse, EFalse ); |
|
3148 return EFalse; // break the loop |
|
3149 } |
|
3150 |
|
3151 |
|
3152 TRAP( error, status = iDSContent.IsSupportedRxL( *txPrefCTType )); |
|
3153 if ( error != KErrNone ) |
|
3154 { |
|
3155 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusCommandFailed ); |
|
3156 iAgent->Interrupt( error, EFalse, EFalse ); |
|
3157 CleanupStack::PopAndDestroy(); // txPrefCTType |
|
3158 return EFalse; |
|
3159 } |
|
3160 else |
|
3161 if ( status ) |
|
3162 { |
|
3163 iDSContent.UpdateCtCapsL( aDbCapArray ); |
|
3164 clientCanReceiveType = ETrue; |
|
3165 } |
|
3166 |
|
3167 CleanupStack::PopAndDestroy(); // txPrefCTType |
|
3168 |
|
3169 |
|
3170 // Tx elements |
|
3171 if ( !clientCanReceiveType ) |
|
3172 { |
|
3173 SmlDevInfXmitList_t* txList = aCurrDatastore->data->tx; |
|
3174 while ( txList ) |
|
3175 { |
|
3176 if ( txList->data ) |
|
3177 { |
|
3178 HBufC8* txCTType = txList->data->cttype->Data().AllocLC(); |
|
3179 TPtr8 txCTTypePtr( txCTType->Des() ); |
|
3180 TrimRightSpaceAndNull( txCTTypePtr ); |
|
3181 |
|
3182 TInt status ( EFalse ); |
|
3183 TRAP( error, status = iDSContent.IsSupportedRxL( *txCTType )); |
|
3184 if ( error != KErrNone ) |
|
3185 { |
|
3186 CleanupStack::PopAndDestroy(); // txCTType |
|
3187 break; |
|
3188 } |
|
3189 else |
|
3190 if ( status ) |
|
3191 { |
|
3192 clientCanReceiveType = ETrue; |
|
3193 iDSContent.UpdateCtCapsL( aDbCapArray ); |
|
3194 CleanupStack::PopAndDestroy(); // txCTType |
|
3195 break; |
|
3196 } |
|
3197 |
|
3198 CleanupStack::PopAndDestroy(); // txCTType |
|
3199 } |
|
3200 |
|
3201 txList = txList->next; |
|
3202 } |
|
3203 } |
|
3204 |
|
3205 if ( error != KErrNone ) |
|
3206 { |
|
3207 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusCommandFailed ); |
|
3208 iAgent->Interrupt( error, EFalse, EFalse ); |
|
3209 return EFalse; |
|
3210 } |
|
3211 else |
|
3212 if ( !clientCanReceiveType ) |
|
3213 { |
|
3214 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3215 iAgent->Interrupt( TNSmlDSError::ESmlDSDatastoreTxCTTypeNotMatching, EFalse, EFalse ); |
|
3216 return EFalse; |
|
3217 } |
|
3218 |
|
3219 return ETrue; |
|
3220 } |
|
3221 |
|
3222 // ----------------------------------------------------------------------------- |
|
3223 // CNSmlDSCmds::ProcessCTCapL |
|
3224 // Reads CTCap elements and stores them to the Agent log. |
|
3225 // ----------------------------------------------------------------------------- |
|
3226 // |
|
3227 void CNSmlDSCmds::ProcessCTCapL( SmlDevInfCtCapList_t& aCapList, const TDesC8& aCTType ) const |
|
3228 { |
|
3229 CNSmlCtCapsHandler* ctCapsHandler = new(ELeave) CNSmlCtCapsHandler( &aCapList ); |
|
3230 CleanupStack::PushL( ctCapsHandler ); |
|
3231 CArrayFix<TNSmlCtCapData>* ctCapArray = new( ELeave ) CArrayFixFlat<TNSmlCtCapData>(8); |
|
3232 CleanupStack::PushL( ctCapArray ); |
|
3233 ctCapsHandler->GetCtCapsL( *ctCapArray, aCTType ); |
|
3234 |
|
3235 if ( ctCapArray->Count() > 0 ) |
|
3236 { |
|
3237 CArrayFix<TNSmlCtCapData>* currCtCapArray = new( ELeave ) CArrayFixFlat<TNSmlCtCapData>(8); |
|
3238 CleanupStack::PushL( currCtCapArray ); |
|
3239 |
|
3240 for ( TInt i = 0; i < currCtCapArray->Count(); i++ ) |
|
3241 { |
|
3242 if ( (*currCtCapArray)[i].iTag == TNSmlCtCapData::ECtType ) |
|
3243 { |
|
3244 if ( (*currCtCapArray)[i].iValue == aCTType ) |
|
3245 { |
|
3246 // CtCaps of the given content type are already stored |
|
3247 CleanupStack::PopAndDestroy( 3 ); // currCtCapArray, ctCapArray, ctCapsHandler |
|
3248 return; |
|
3249 } |
|
3250 } |
|
3251 } |
|
3252 |
|
3253 for ( TInt j = 0; j < ctCapArray->Count(); j++ ) |
|
3254 { |
|
3255 TNSmlCtCapData ctCapData( (*ctCapArray)[j].iTag, (*ctCapArray)[j].iValue ); |
|
3256 currCtCapArray->AppendL( ctCapData ); |
|
3257 } |
|
3258 |
|
3259 CleanupStack::PopAndDestroy(); // currCtCapArray |
|
3260 } |
|
3261 |
|
3262 CleanupStack::PopAndDestroy( 2 ); // ctCapArray, ctCapsHandler |
|
3263 } |
|
3264 |
|
3265 // ----------------------------------------------------------------------------- |
|
3266 // CNSmlDSCmds::ProcessFilterCapL() |
|
3267 // Reads FilterCap elements and stores them to the Agent log. |
|
3268 // ----------------------------------------------------------------------------- |
|
3269 // |
|
3270 void CNSmlDSCmds::ProcessFilterCapL ( SmlDevInfFilterCapList_t& aFilterCapList, const TDesC8& aCTType ) const |
|
3271 { |
|
3272 CNSmlFilterCapsHandler* filterCapsHandler = new ( ELeave ) CNSmlFilterCapsHandler ( &aFilterCapList ); |
|
3273 CleanupStack::PushL( filterCapsHandler ); |
|
3274 CArrayFix<TNSmlFilterCapData>* filterCapArray = new ( ELeave ) CArrayFixFlat<TNSmlFilterCapData>(8); |
|
3275 CleanupStack::PushL( filterCapArray ); |
|
3276 filterCapsHandler->GetFilterCapsL( *filterCapArray, aCTType ); |
|
3277 |
|
3278 if ( filterCapArray->Count() > 0 ) |
|
3279 { |
|
3280 CArrayFix<TNSmlFilterCapData>* currFilterCapArray = new ( ELeave ) CArrayFixFlat<TNSmlFilterCapData>(8); |
|
3281 CleanupStack::PushL( currFilterCapArray ); |
|
3282 iDSContent.GetSavedFilterCapsL( currFilterCapArray ); |
|
3283 |
|
3284 for ( TInt i = 0; i < currFilterCapArray->Count(); i++ ) |
|
3285 { |
|
3286 if ( (*currFilterCapArray)[i].iTag == TNSmlFilterCapData::ECtType ) |
|
3287 { |
|
3288 if ( (*currFilterCapArray)[i].iValue == aCTType ) |
|
3289 { |
|
3290 // FilterCaps of given content type are already stored |
|
3291 CleanupStack::PopAndDestroy( 3 ); //currFilterCapArray, filtarCapArray, filterCapsHandler |
|
3292 return; |
|
3293 } |
|
3294 } |
|
3295 } |
|
3296 |
|
3297 for ( TInt j = 0; j < filterCapArray->Count(); j++ ) |
|
3298 { |
|
3299 TNSmlFilterCapData filterCapData ( (*filterCapArray)[j].iTag, (*filterCapArray)[j].iValue ); |
|
3300 currFilterCapArray->AppendL ( filterCapData ); |
|
3301 } |
|
3302 |
|
3303 iDSContent.UpdateFilterCapsL ( currFilterCapArray ); |
|
3304 |
|
3305 CleanupStack::PopAndDestroy( ); // currFilterCapArray |
|
3306 } |
|
3307 |
|
3308 CleanupStack::PopAndDestroy( 2 ); // filterCapArray, filterCapsHandler |
|
3309 } |
|
3310 |
|
3311 // ----------------------------------------------------------------------------- |
|
3312 // CNSmlDSCmds::DoNumberOfChangesL |
|
3313 // Generates the NumberOfChanges element. |
|
3314 // ----------------------------------------------------------------------------- |
|
3315 // |
|
3316 void CNSmlDSCmds::DoNumberOfChangesL( SmlPcdata_t*& aNoc ) const |
|
3317 { |
|
3318 HBufC8* stringNoc = HBufC8::NewLC( 16 ); |
|
3319 //RD_SUSPEND_RESUME - Code commented for Usability issue. |
|
3320 /*if(iDSContent.SuspendedState() == EStateServerModification && iDSContent.GetSessionResumed() ) |
|
3321 stringNoc->Des().Num( 0 ); |
|
3322 else*/ |
|
3323 //RD_SUSPEND_RESUME |
|
3324 stringNoc->Des().Num( iDSContent.ClientItemCount() ); |
|
3325 PcdataNewL ( aNoc, *stringNoc ); |
|
3326 CleanupStack::PopAndDestroy(); // stringNoc |
|
3327 } |
|
3328 |
|
3329 // ----------------------------------------------------------------------------- |
|
3330 // CNSmlDSCmds::GetChunkL |
|
3331 // Buffer the received item and handles large objects. |
|
3332 // ----------------------------------------------------------------------------- |
|
3333 // |
|
3334 TNSmlError::TNSmlSyncMLStatusCode CNSmlDSCmds::GetChunkL( const TDesC8& aUid, const SmlItem_t* aCurrentItem, const SmlPcdata_t* aMetaInCommand, CBufBase*& aBuffer ) |
|
3335 { |
|
3336 iItemSizeInStream = 0; |
|
3337 TNSmlError::TNSmlSyncMLStatusCode status( TNSmlError::ESmlStatusOK ); |
|
3338 iMoreData = IsFlagSet( aCurrentItem->flags, SmlMoreData_f ); |
|
3339 DBG_ARGS(_S("iMoreData flag (GetChunk): %d"), iMoreData); |
|
3340 // check that the previously received chunk belongs to the same item |
|
3341 if ( iAmountReceived != 0 ) |
|
3342 { |
|
3343 if ( aUid != *iLargeUid ) |
|
3344 { |
|
3345 iAgent->SetEndOfDataAlertRequest(); |
|
3346 delete iRecBuf; |
|
3347 iRecBuf = NULL; |
|
3348 delete iLargeUid; |
|
3349 iLargeUid = NULL; |
|
3350 iServerLargeObjectSize = 0; |
|
3351 } |
|
3352 } |
|
3353 |
|
3354 if ( iMoreData && ( iAmountReceived == 0 ) ) |
|
3355 { |
|
3356 iServerLargeObjectSize = ServerObjectSize( aCurrentItem->meta ); |
|
3357 |
|
3358 if ( iServerLargeObjectSize == 0 ) |
|
3359 { |
|
3360 iServerLargeObjectSize = ServerObjectSize( aMetaInCommand ); |
|
3361 } |
|
3362 |
|
3363 iItemSizeInStream = iServerLargeObjectSize; |
|
3364 delete iLargeUid; |
|
3365 iLargeUid = NULL; |
|
3366 iLargeUid = aUid.AllocL(); |
|
3367 } |
|
3368 |
|
3369 iRecBuf = CBufFlat::NewL( 1 ); |
|
3370 |
|
3371 // buffer data |
|
3372 if ( aCurrentItem->data ) |
|
3373 { |
|
3374 if ( iItemSizeInStream == 0 ) |
|
3375 { |
|
3376 iItemSizeInStream = aCurrentItem->data->length; |
|
3377 } |
|
3378 |
|
3379 if ( aCurrentItem->data->content ) |
|
3380 { |
|
3381 TPtr8 data( static_cast<TUint8*>( aCurrentItem->data->content ), aCurrentItem->data->length, aCurrentItem->data->length ); |
|
3382 iRecBuf->InsertL( iRecBuf->Size(), data ); |
|
3383 } |
|
3384 } |
|
3385 else |
|
3386 { |
|
3387 aBuffer = iRecBuf; |
|
3388 iRecBuf = NULL; |
|
3389 return status; |
|
3390 } |
|
3391 |
|
3392 // last / only chunk |
|
3393 if ( !iMoreData ) |
|
3394 { |
|
3395 TBool notFirst( iAmountReceived != 0 ); |
|
3396 iAmountReceived += aCurrentItem->data->length; |
|
3397 |
|
3398 if ( notFirst && ( iAmountReceived != iServerLargeObjectSize ) ) |
|
3399 { |
|
3400 status = TNSmlError::ESmlStatusSizeMismatch; |
|
3401 delete iRecBuf; |
|
3402 iRecBuf = NULL; |
|
3403 } |
|
3404 aBuffer = iRecBuf; |
|
3405 iRecBuf = NULL; |
|
3406 iAmountReceived = 0; |
|
3407 } |
|
3408 // middle chunk |
|
3409 else |
|
3410 { |
|
3411 iAmountReceived += aCurrentItem->data->length; |
|
3412 aBuffer = iRecBuf; |
|
3413 status = TNSmlError::ESmlStatusItemAccepted; |
|
3414 } |
|
3415 |
|
3416 return status; |
|
3417 } |
|
3418 |
|
3419 // ----------------------------------------------------------------------------- |
|
3420 // CNSmlDSCmds::UpdateL |
|
3421 // Performs updates to local databases. |
|
3422 // ----------------------------------------------------------------------------- |
|
3423 // |
|
3424 void CNSmlDSCmds::UpdateL( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem, const TDesC8& aUID, const TSmlDbItemUid aParent ) |
|
3425 { |
|
3426 TInt returnCode( KErrNone ); |
|
3427 TInt statusId( -1 ); |
|
3428 TBool resumeBatchMode( EFalse ); |
|
3429 TBool backToBatchMode( EFalse ); |
|
3430 MSyncMLProgressObserver::TSyncMLDataSyncModifications clientModifications = { 0, 0, 0, 0, 0 }; |
|
3431 MSyncMLProgressObserver::TSyncMLDataSyncModifications serverModifications = { 0, 0, 0, 0, 0 }; |
|
3432 |
|
3433 if ( aCmd == KNSmlAgentAdd || aCmd == KNSmlAgentReplace ) |
|
3434 { |
|
3435 TPtr8 data( 0, 0 ); |
|
3436 CBufBase* dataBuffer( NULL ); |
|
3437 TBool canGo( EFalse ); |
|
3438 if ( iMoreData ) |
|
3439 { |
|
3440 backToBatchMode = ETrue; |
|
3441 } |
|
3442 TNSmlError::TNSmlSyncMLStatusCode statusCode( GetChunkL( aUID, aItem, aContent->meta, dataBuffer ) ); |
|
3443 if ( !iMoreData && backToBatchMode ) |
|
3444 { |
|
3445 resumeBatchMode = ETrue; |
|
3446 } |
|
3447 |
|
3448 if ( dataBuffer ) |
|
3449 { |
|
3450 data.Set( dataBuffer->Ptr( 0 ) ); |
|
3451 CleanupStack::PushL( dataBuffer ); |
|
3452 } |
|
3453 |
|
3454 // if size of large item does not match |
|
3455 if ( statusCode == TNSmlError::ESmlStatusSizeMismatch ) |
|
3456 { |
|
3457 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusSizeMismatch ); |
|
3458 } |
|
3459 // check that some data was actually received |
|
3460 else if ( data.Length() == 0 ) |
|
3461 { |
|
3462 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
3463 } |
|
3464 else |
|
3465 { |
|
3466 if ( statusCode == TNSmlError::ESmlStatusOK ) |
|
3467 { |
|
3468 canGo = ETrue; |
|
3469 } |
|
3470 else if ( statusCode == TNSmlError::ESmlStatusItemAccepted ) |
|
3471 { |
|
3472 // large items are not allowed during batch mode |
|
3473 if ( iBatchModeOn ) |
|
3474 { |
|
3475 CommitBatchL(); |
|
3476 resumeBatchMode = ETrue; |
|
3477 } |
|
3478 |
|
3479 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusItemAccepted ); |
|
3480 canGo = ETrue; |
|
3481 } |
|
3482 } |
|
3483 |
|
3484 if ( canGo ) |
|
3485 { |
|
3486 SmlMetInfMetInf_t* metInf( NULL ); |
|
3487 |
|
3488 if ( aItem->meta ) |
|
3489 { |
|
3490 if ( ( aItem->meta->content ) && ( aItem->meta->contentType == SML_PCDATA_EXTENSION ) && ( aItem->meta->extension == SML_EXT_METINF ) ) |
|
3491 { |
|
3492 if ( ((SmlMetInfMetInf_t*) aItem->meta->content)->type ) |
|
3493 { |
|
3494 metInf = (SmlMetInfMetInf_t*) aItem->meta->content; |
|
3495 } |
|
3496 } |
|
3497 } |
|
3498 |
|
3499 if ( !metInf ) |
|
3500 { |
|
3501 if ( (aContent->meta) && ( aContent->meta->content ) && ( aContent->meta->contentType == SML_PCDATA_EXTENSION ) && ( aContent->meta->extension == SML_EXT_METINF ) ) |
|
3502 { |
|
3503 metInf = (SmlMetInfMetInf_t*) aContent->meta->content; |
|
3504 } |
|
3505 } |
|
3506 |
|
3507 CNSmlDbMetaHandler* metaHandler; |
|
3508 |
|
3509 if ( !metInf ) |
|
3510 { |
|
3511 metaHandler = new ( ELeave ) CNSmlDbMetaHandler; |
|
3512 } |
|
3513 else |
|
3514 { |
|
3515 metaHandler = new ( ELeave ) CNSmlDbMetaHandler( metInf ); |
|
3516 } |
|
3517 |
|
3518 CleanupStack::PushL( metaHandler ); |
|
3519 |
|
3520 if ( aCmd == KNSmlAgentAdd ) |
|
3521 { |
|
3522 if ( !iItemOpened ) |
|
3523 { |
|
3524 iItemOpened = ETrue; |
|
3525 |
|
3526 if ( !iBatchModeOn && !iMoreData ) |
|
3527 { |
|
3528 returnCode = iDSContent.CreateItemL( iNewUid, data.Length(), metaHandler->Type(), metaHandler->Version(), aParent ); |
|
3529 } |
|
3530 else if ( !iBatchModeOn ) |
|
3531 { |
|
3532 returnCode = iDSContent.CreateItemL( iNewUid, iServerLargeObjectSize, metaHandler->Type(), metaHandler->Version(), aParent ); |
|
3533 } |
|
3534 else |
|
3535 { |
|
3536 iBatchBuffer->CreateNewItemL( aCmd ); |
|
3537 iBatchBuffer->SetGUidL( aUID ); |
|
3538 returnCode = iDSContent.CreateItemL( iBatchBuffer->Uid(), data.Length(), metaHandler->Type(), metaHandler->Version(), aParent ); |
|
3539 } |
|
3540 } |
|
3541 |
|
3542 if ( returnCode == KErrNone ) |
|
3543 { |
|
3544 TRAPD( error, iDSContent.WriteItemL( data ) ); |
|
3545 |
|
3546 if ( error != KErrNone ) |
|
3547 { |
|
3548 iMoreData = EFalse; |
|
3549 iItemOpened = EFalse; |
|
3550 } |
|
3551 |
|
3552 returnCode = error; |
|
3553 } |
|
3554 |
|
3555 // if this is the last or the only chunk then commit it |
|
3556 if ( !iMoreData ) |
|
3557 { |
|
3558 if ( returnCode == KErrNone ) |
|
3559 { |
|
3560 returnCode = iDSContent.CommitItemL(); |
|
3561 |
|
3562 if ( iBatchModeOn ) |
|
3563 { |
|
3564 iBatchBuffer->Increase(); |
|
3565 } |
|
3566 } |
|
3567 |
|
3568 iItemOpened = EFalse; |
|
3569 |
|
3570 switch ( returnCode ) |
|
3571 { |
|
3572 case KErrNone: |
|
3573 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusItemAdded ); |
|
3574 |
|
3575 if ( !iBatchModeOn ) |
|
3576 { |
|
3577 iDSContent.IncreaseServerItemsAdded(); |
|
3578 clientModifications.iNumAdded = 1; |
|
3579 |
|
3580 if ( !iAtomicModeOn ) |
|
3581 { |
|
3582 iDSContent.CreateNewMapItemL( iNewUid, aUID, 0 ); |
|
3583 } |
|
3584 else |
|
3585 { |
|
3586 iDSContent.CreateNewMapItemL( iNewUid, aUID, iAtomicId ); |
|
3587 } |
|
3588 } |
|
3589 else |
|
3590 { |
|
3591 clientModifications.iNumAdded = 1; |
|
3592 iBatchBuffer->SetStatusEntryId( statusId ); |
|
3593 } |
|
3594 break; |
|
3595 |
|
3596 case KErrDiskFull: |
|
3597 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusDeviceFull ); |
|
3598 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
3599 break; |
|
3600 |
|
3601 case KErrNotSupported: |
|
3602 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3603 break; |
|
3604 |
|
3605 default: |
|
3606 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed ); |
|
3607 break; |
|
3608 } |
|
3609 } |
|
3610 } |
|
3611 else // KNSmlAgentReplace |
|
3612 { |
|
3613 TBool partialUpdate( EFalse ); |
|
3614 iNewUid = KNullDataItemId; |
|
3615 |
|
3616 if ( (aContent->meta) && ( aContent->meta->content ) && ( aContent->meta->contentType == SML_PCDATA_EXTENSION ) && ( aContent->meta->extension == SML_EXT_METINF ) ) |
|
3617 { |
|
3618 SmlMetInfMetInf_t* metInfForPartial( (SmlMetInfMetInf_t*)aContent->meta->content ); |
|
3619 |
|
3620 if ( metInfForPartial->fieldLevel ) |
|
3621 { |
|
3622 partialUpdate = ETrue; |
|
3623 } |
|
3624 } |
|
3625 |
|
3626 if ( !iItemOpened ) |
|
3627 { |
|
3628 iItemOpened = ETrue; |
|
3629 |
|
3630 TSmlDbItemUid uid; |
|
3631 |
|
3632 returnCode = ConvertUid( aUID, uid ); |
|
3633 |
|
3634 if ( returnCode == KErrNone && !iMoreData ) |
|
3635 { |
|
3636 returnCode = iDSContent.ReplaceItemL( uid, data.Length(), aParent, partialUpdate ); |
|
3637 } |
|
3638 else if ( returnCode == KErrNone ) |
|
3639 { |
|
3640 returnCode = iDSContent.ReplaceItemL( uid, iServerLargeObjectSize, aParent, partialUpdate ); |
|
3641 } |
|
3642 |
|
3643 if ( returnCode == KErrNotFound ) |
|
3644 { |
|
3645 if ( iBatchModeOn ) |
|
3646 { |
|
3647 iBatchBuffer->CreateNewItemL( aCmd ); |
|
3648 iBatchBuffer->SetGUidL( aUID ); |
|
3649 returnCode = iDSContent.CreateItemL( iBatchBuffer->Uid(), data.Length(), metaHandler->Type(), metaHandler->Version(), aParent ); |
|
3650 } |
|
3651 else |
|
3652 { |
|
3653 if ( !iMoreData ) |
|
3654 { |
|
3655 returnCode = iDSContent.CreateItemL( iNewUid, data.Length(), metaHandler->Type(), metaHandler->Version(), aParent ); |
|
3656 } |
|
3657 else |
|
3658 { |
|
3659 returnCode = iDSContent.CreateItemL( iNewUid, iServerLargeObjectSize, metaHandler->Type(), metaHandler->Version(), aParent ); |
|
3660 } |
|
3661 } |
|
3662 } |
|
3663 else |
|
3664 { |
|
3665 if ( iBatchModeOn ) |
|
3666 { |
|
3667 iBatchBuffer->CreateNewItemL( aCmd ); |
|
3668 iBatchBuffer->SetGUidL( aUID ); |
|
3669 iBatchBuffer->StoreItemDataL( data ); |
|
3670 iBatchBuffer->SetMetaInformationL( metaHandler ); |
|
3671 iBatchBuffer->SetParent( aParent ); |
|
3672 } |
|
3673 } |
|
3674 } |
|
3675 |
|
3676 if ( returnCode == KErrNone ) |
|
3677 { |
|
3678 TRAPD( error, iDSContent.WriteItemL( data ) ); |
|
3679 |
|
3680 if ( error != KErrNone ) |
|
3681 { |
|
3682 iMoreData = EFalse; |
|
3683 iItemOpened = EFalse; |
|
3684 } |
|
3685 |
|
3686 returnCode = error; |
|
3687 } |
|
3688 |
|
3689 // if this is the last or the only chunk then commit it |
|
3690 if ( !iMoreData ) |
|
3691 { |
|
3692 if ( returnCode == KErrNone ) |
|
3693 { |
|
3694 returnCode = iDSContent.CommitItemL(); |
|
3695 |
|
3696 if ( iBatchModeOn ) |
|
3697 { |
|
3698 iBatchBuffer->Increase(); |
|
3699 } |
|
3700 } |
|
3701 |
|
3702 iItemOpened = EFalse; |
|
3703 |
|
3704 switch ( returnCode ) |
|
3705 { |
|
3706 case KErrNone: |
|
3707 if ( iNewUid == KNullDataItemId ) // item to be replaced was found |
|
3708 { |
|
3709 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusOK ); |
|
3710 |
|
3711 if ( !iBatchModeOn ) |
|
3712 { |
|
3713 iDSContent.IncreaseServerItemsChanged(); |
|
3714 clientModifications.iNumReplaced = 1; |
|
3715 } |
|
3716 else |
|
3717 { |
|
3718 clientModifications.iNumReplaced = 1; |
|
3719 iBatchBuffer->SetStatusEntryId( statusId ); |
|
3720 } |
|
3721 } |
|
3722 else // Replace was converted to Add |
|
3723 { |
|
3724 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusItemAdded ); |
|
3725 |
|
3726 if ( !iBatchModeOn ) |
|
3727 { |
|
3728 iDSContent.IncreaseServerItemsAdded(); |
|
3729 clientModifications.iNumAdded = 1; |
|
3730 |
|
3731 if ( !iAtomicModeOn ) |
|
3732 { |
|
3733 iDSContent.CreateNewMapItemL( iNewUid, aUID, 0 ); |
|
3734 } |
|
3735 else |
|
3736 { |
|
3737 iDSContent.CreateNewMapItemL( iNewUid, aUID, iAtomicId ); |
|
3738 } |
|
3739 } |
|
3740 else |
|
3741 { |
|
3742 clientModifications.iNumAdded = 1; |
|
3743 iBatchBuffer->SetStatusEntryId( statusId ); |
|
3744 } |
|
3745 } |
|
3746 |
|
3747 break; |
|
3748 |
|
3749 case KErrNotFound: |
|
3750 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusNotFound ); |
|
3751 break; |
|
3752 |
|
3753 case KErrDiskFull: |
|
3754 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusDeviceFull ); |
|
3755 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
3756 break; |
|
3757 |
|
3758 case KErrNotSupported: |
|
3759 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3760 break; |
|
3761 |
|
3762 default: |
|
3763 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed ); |
|
3764 break; |
|
3765 } |
|
3766 } |
|
3767 } |
|
3768 |
|
3769 CleanupStack::PopAndDestroy(); // metaHandler |
|
3770 } |
|
3771 |
|
3772 if ( dataBuffer ) |
|
3773 { |
|
3774 CleanupStack::PopAndDestroy(); // dataBuffer |
|
3775 iRecBuf = NULL; |
|
3776 } |
|
3777 |
|
3778 if ( statusCode != TNSmlError::ESmlStatusItemAccepted ) |
|
3779 { |
|
3780 iNewUid = KNullDataItemId; |
|
3781 } |
|
3782 } |
|
3783 else if ( aCmd == KNSmlAgentDelete ) |
|
3784 { |
|
3785 TSmlDbItemUid uid; |
|
3786 |
|
3787 returnCode = ConvertUid( aUID, uid ); |
|
3788 |
|
3789 if ( returnCode == KErrNone ) |
|
3790 { |
|
3791 returnCode = iDSContent.DeleteItemL( uid, IsFlagSet( aContent->flags, SmlSftDel_f ) ); |
|
3792 } |
|
3793 |
|
3794 switch ( returnCode ) |
|
3795 { |
|
3796 case KErrNone: |
|
3797 if ( !iBatchModeOn ) |
|
3798 { |
|
3799 iDSContent.IncreaseServerItemsDeleted(); |
|
3800 clientModifications.iNumDeleted = 1; |
|
3801 |
|
3802 if ( IsFlagSet( aContent->flags, SmlArchive_f ) ) |
|
3803 { |
|
3804 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusDeleteWithoutArchive ); |
|
3805 } |
|
3806 else |
|
3807 { |
|
3808 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusOK ); |
|
3809 } |
|
3810 } |
|
3811 else |
|
3812 { |
|
3813 iBatchBuffer->CreateNewItemL( aCmd ); |
|
3814 iBatchBuffer->Increase(); |
|
3815 clientModifications.iNumDeleted = 1; |
|
3816 if ( IsFlagSet( aContent->flags, SmlArchive_f ) ) |
|
3817 { |
|
3818 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusDeleteWithoutArchive ); |
|
3819 } |
|
3820 else |
|
3821 { |
|
3822 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusOK ); |
|
3823 } |
|
3824 |
|
3825 iBatchBuffer->SetStatusEntryId( statusId ); |
|
3826 } |
|
3827 break; |
|
3828 |
|
3829 case KErrNotFound: |
|
3830 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusItemIsNotDeleted ); |
|
3831 break; |
|
3832 |
|
3833 case KErrDiskFull: |
|
3834 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusDeviceFull ); |
|
3835 iAgent->InterruptL( iDSContent.CurrentIndex(), TNSmlError::ESmlLowMemory, EFalse, EFalse ); |
|
3836 break; |
|
3837 |
|
3838 case KErrNotSupported: |
|
3839 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3840 break; |
|
3841 |
|
3842 default: |
|
3843 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed ); |
|
3844 break; |
|
3845 } |
|
3846 } |
|
3847 else if ( aCmd == KNSmlAgentMove ) |
|
3848 { |
|
3849 TSmlDbItemUid uid; |
|
3850 |
|
3851 returnCode = ConvertUid( aUID, uid ); |
|
3852 |
|
3853 if ( returnCode == KErrNone ) |
|
3854 { |
|
3855 returnCode = iDSContent.MoveItemL( uid, aParent ); |
|
3856 } |
|
3857 |
|
3858 switch ( returnCode ) |
|
3859 { |
|
3860 case KErrNone: |
|
3861 if ( !iBatchModeOn ) |
|
3862 { |
|
3863 iDSContent.IncreaseServerItemsMoved(); |
|
3864 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusOK ); |
|
3865 clientModifications.iNumMoved = 1; |
|
3866 } |
|
3867 else |
|
3868 { |
|
3869 iBatchBuffer->CreateNewItemL( aCmd ); |
|
3870 iBatchBuffer->Increase(); |
|
3871 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusOK ); |
|
3872 iBatchBuffer->SetStatusEntryId( statusId ); |
|
3873 clientModifications.iNumMoved = 1; |
|
3874 } |
|
3875 break; |
|
3876 |
|
3877 case KErrNotSupported: |
|
3878 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed ); |
|
3879 break; |
|
3880 |
|
3881 default: |
|
3882 statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusMoveFailed ); |
|
3883 break; |
|
3884 } |
|
3885 } |
|
3886 |
|
3887 if ( iDSContent.PartiallyUpdated() ) |
|
3888 { |
|
3889 iDSContent.SetSyncStatus( CNSmlDSAgent::EServerDataPartiallyUpdated ); |
|
3890 } |
|
3891 |
|
3892 if ( iAtomicModeOn ) |
|
3893 { |
|
3894 iStatusToServer->SetAtomicOrSequenceId( statusId, iAtomicId ); |
|
3895 |
|
3896 if ( returnCode != KErrNone ) |
|
3897 { |
|
3898 iAtomicHasFailed = ETrue; |
|
3899 } |
|
3900 } |
|
3901 |
|
3902 if ( !iMoreData ) |
|
3903 { |
|
3904 // build the modifications struct |
|
3905 TInt num( clientModifications.iNumAdded ); |
|
3906 num += clientModifications.iNumReplaced; |
|
3907 num += clientModifications.iNumMoved; |
|
3908 num += clientModifications.iNumDeleted; |
|
3909 |
|
3910 if ( num == 0 && !iBatchModeOn ) |
|
3911 { |
|
3912 // If items are handled in Batch mode then it never goes here |
|
3913 // Status of batch item is handled in CommitBatchL method |
|
3914 clientModifications.iNumFailed = 1; |
|
3915 iDSContent.IncreaseServerItemsFailed(); |
|
3916 } |
|
3917 |
|
3918 iDSObserver.OnSyncMLDataSyncModifications( iDSContent.TaskId(), clientModifications, serverModifications ); |
|
3919 iDSContent.SetServerItemCount( iDSContent.ServerItemCount() - 1 ); |
|
3920 } |
|
3921 |
|
3922 if ( resumeBatchMode && !iMoreData ) |
|
3923 { |
|
3924 if ( iDSContent.SupportsOperationL( KUidSmlSupportBatch ) ) |
|
3925 { |
|
3926 iBatchModeOn = ETrue; |
|
3927 if ( !iBatchBuffer ) |
|
3928 { |
|
3929 iBatchBuffer = new ( ELeave ) CNSmlDSBatchBuffer; |
|
3930 } |
|
3931 else |
|
3932 { |
|
3933 iBatchBuffer->Reset(); |
|
3934 } |
|
3935 |
|
3936 iDSContent.BeginBatchL(); |
|
3937 } |
|
3938 } |
|
3939 } |
|
3940 |
|
3941 // ----------------------------------------------------------------------------- |
|
3942 // CNSmlDSCmds::IsDevInfoContentTypeOkL |
|
3943 // Validates the content type in server's DevInfo. |
|
3944 // ----------------------------------------------------------------------------- |
|
3945 // |
|
3946 TBool CNSmlDSCmds::IsDevInfoContentTypeOkL( const SmlPcdata_t* aMeta, TInt aStatusID ) |
|
3947 { |
|
3948 if ( !aMeta ) |
|
3949 { |
|
3950 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3951 iAgent->Interrupt( TNSmlError::ESmlTypeInvalid, EFalse, EFalse ); |
|
3952 return EFalse; |
|
3953 } |
|
3954 |
|
3955 if ( ( !aMeta->content ) || ( aMeta->contentType != SML_PCDATA_EXTENSION ) || ( aMeta->extension != SML_EXT_METINF ) ) |
|
3956 { |
|
3957 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3958 iAgent->Interrupt( TNSmlError::ESmlTypeInvalid, EFalse, EFalse ); |
|
3959 return EFalse; |
|
3960 } |
|
3961 |
|
3962 SmlMetInfMetInf_t* metInf( static_cast<SmlMetInfMetInf_t*>( aMeta->content ) ); |
|
3963 |
|
3964 if ( !metInf->type ) |
|
3965 { |
|
3966 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3967 iAgent->Interrupt( TNSmlError::ESmlTypeInvalid, EFalse, EFalse ); |
|
3968 return EFalse; |
|
3969 } |
|
3970 |
|
3971 if ( !metInf->type->content ) |
|
3972 { |
|
3973 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3974 iAgent->Interrupt( TNSmlError::ESmlTypeInvalid, EFalse, EFalse ); |
|
3975 return EFalse; |
|
3976 } |
|
3977 |
|
3978 TPtr8 deviceInfoContentType( static_cast<TUint8*>( metInf->type->content ), metInf->type->length, metInf->type->length ); |
|
3979 TrimRightSpaceAndNull( deviceInfoContentType ); |
|
3980 |
|
3981 if ( deviceInfoContentType.Length() == 0 ) |
|
3982 { |
|
3983 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3984 iAgent->Interrupt( TNSmlError::ESmlTypeInvalid, EFalse, EFalse ); |
|
3985 return EFalse; |
|
3986 } |
|
3987 |
|
3988 if ( deviceInfoContentType != KNSmlDSAgentDeviceInfoContentType ) |
|
3989 { |
|
3990 iStatusToServer->SetStatusCodeL( aStatusID, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat ); |
|
3991 iAgent->Interrupt( TNSmlError::ESmlTypeInvalid, EFalse, EFalse ); |
|
3992 return EFalse; |
|
3993 } |
|
3994 |
|
3995 return ETrue; |
|
3996 } |
|
3997 |
|
3998 // ----------------------------------------------------------------------------- |
|
3999 // CNSmlDSCmds::IsLUIDOkLC |
|
4000 // Checks that LUID is present in the Target element and returns it. |
|
4001 // ----------------------------------------------------------------------------- |
|
4002 // |
|
4003 TBool CNSmlDSCmds::IsLUIDOkLC( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem, HBufC8*& aLUID ) |
|
4004 { |
|
4005 if ( !aItem->target ) |
|
4006 { |
|
4007 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
4008 return EFalse; |
|
4009 } |
|
4010 |
|
4011 if ( !aItem->target->locURI ) |
|
4012 { |
|
4013 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
4014 return EFalse; |
|
4015 } |
|
4016 |
|
4017 TPtr8 LUID( static_cast<TUint8*>( aItem->target->locURI->content ), aItem->target->locURI->length, aItem->target->locURI->length ); |
|
4018 TrimRightSpaceAndNull( LUID ); |
|
4019 aLUID = LUID.AllocLC(); |
|
4020 |
|
4021 if ( aLUID->Length() == 0 ) |
|
4022 { |
|
4023 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
4024 CleanupStack::PopAndDestroy(); // aLUID |
|
4025 return EFalse; |
|
4026 } |
|
4027 |
|
4028 return ETrue; |
|
4029 } |
|
4030 |
|
4031 // ----------------------------------------------------------------------------- |
|
4032 // CNSmlDSCmds::IsGUIDOkLC |
|
4033 // Checks that GUID is present in the Source element and returns it. |
|
4034 // ----------------------------------------------------------------------------- |
|
4035 // |
|
4036 TBool CNSmlDSCmds::IsGUIDOkLC( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem, HBufC8*& aGUID ) |
|
4037 { |
|
4038 if ( !aItem->source ) |
|
4039 { |
|
4040 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
4041 return EFalse; |
|
4042 } |
|
4043 |
|
4044 if ( !aItem->source->locURI ) |
|
4045 { |
|
4046 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
4047 return EFalse; |
|
4048 } |
|
4049 |
|
4050 TPtr8 GUID( static_cast<TUint8*>( aItem->source->locURI->content ), aItem->source->locURI->length, aItem->source->locURI->length ); |
|
4051 TrimRightSpaceAndNull( GUID ); |
|
4052 aGUID = GUID.AllocLC(); |
|
4053 |
|
4054 if ( aGUID->Length() == 0 ) |
|
4055 { |
|
4056 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusIncompleteCommand ); |
|
4057 CleanupStack::PopAndDestroy(); // aGUID |
|
4058 return EFalse; |
|
4059 } |
|
4060 |
|
4061 return ETrue; |
|
4062 } |
|
4063 |
|
4064 // ----------------------------------------------------------------------------- |
|
4065 // CNSmlDSCmds::IsParentOkL |
|
4066 // Checks that GUID is present in the Parent element and returns GUID. If GUID |
|
4067 // is not present then KNullDataItemId is returned. |
|
4068 // ----------------------------------------------------------------------------- |
|
4069 // |
|
4070 TBool CNSmlDSCmds::IsParentOkL( const sml_source_or_target_parent_s* aParent, TSmlDbItemUid& aGUID ) |
|
4071 { |
|
4072 if ( !aParent ) |
|
4073 { |
|
4074 aGUID = KNullDataItemId; |
|
4075 return EFalse; |
|
4076 } |
|
4077 |
|
4078 if ( !aParent->locURI ) |
|
4079 { |
|
4080 aGUID = KNullDataItemId; |
|
4081 return EFalse; |
|
4082 } |
|
4083 |
|
4084 TPtr8 GUID( static_cast<TUint8*>( aParent->locURI->content ), aParent->locURI->length, aParent->locURI->length ); |
|
4085 TrimRightSpaceAndNull( GUID ); |
|
4086 |
|
4087 if ( GUID == KNSmlRoot ) |
|
4088 { |
|
4089 aGUID = KDbItemUidRoot; |
|
4090 return ETrue; |
|
4091 } |
|
4092 |
|
4093 TLex8 lex( GUID ); |
|
4094 |
|
4095 if ( lex.Val( aGUID ) != KErrNone ) |
|
4096 { |
|
4097 aGUID = KNullDataItemId; |
|
4098 return EFalse; |
|
4099 } |
|
4100 |
|
4101 return ETrue ; |
|
4102 } |
|
4103 |
|
4104 // ----------------------------------------------------------------------------- |
|
4105 // CNSmlDSCmds::IsParentOkLC |
|
4106 // Checks that GUID is present in the Parent element and returns GUID. If GUID |
|
4107 // is not present then an empty descriptor is returned. |
|
4108 // ----------------------------------------------------------------------------- |
|
4109 // |
|
4110 TBool CNSmlDSCmds::IsParentOkLC( const sml_source_or_target_parent_s* aParent, HBufC8*& aGUID ) |
|
4111 { |
|
4112 if ( !aParent ) |
|
4113 { |
|
4114 aGUID = KNullDesC8().AllocLC(); |
|
4115 return EFalse; |
|
4116 } |
|
4117 |
|
4118 if ( !aParent->locURI ) |
|
4119 { |
|
4120 aGUID = KNullDesC8().AllocLC(); |
|
4121 return EFalse; |
|
4122 } |
|
4123 |
|
4124 TPtr8 GUID( static_cast<TUint8*>( aParent->locURI->content ), aParent->locURI->length, aParent->locURI->length ); |
|
4125 TrimRightSpaceAndNull( GUID ); |
|
4126 |
|
4127 aGUID = GUID.AllocLC(); |
|
4128 |
|
4129 return ETrue ; |
|
4130 } |
|
4131 |
|
4132 // ----------------------------------------------------------------------------- |
|
4133 // CNSmlDSCmds::IsFormatOkL |
|
4134 // Validates the Format element received from the server. |
|
4135 // ----------------------------------------------------------------------------- |
|
4136 // |
|
4137 TBool CNSmlDSCmds::IsFormatOkL( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem ) |
|
4138 { |
|
4139 TPtrC8 format; |
|
4140 |
|
4141 if ( ( !IsChrFormat( aContent->meta, format ) ) || ( !IsChrFormat( aItem->meta, format ) ) ) |
|
4142 { |
|
4143 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat, &format ); |
|
4144 return EFalse; |
|
4145 } |
|
4146 |
|
4147 return ETrue; |
|
4148 } |
|
4149 |
|
4150 // ----------------------------------------------------------------------------- |
|
4151 // CNSmlDSCmds::IsChrFormat |
|
4152 // Checks if the Format elements value is chr. |
|
4153 // ----------------------------------------------------------------------------- |
|
4154 // |
|
4155 TBool CNSmlDSCmds::IsChrFormat( const SmlPcdata_t* aMeta, TPtrC8& aFormat ) const |
|
4156 { |
|
4157 if ( aMeta ) |
|
4158 { |
|
4159 if ( aMeta->content && aMeta->contentType == SML_PCDATA_EXTENSION && aMeta->extension == SML_EXT_METINF ) |
|
4160 { |
|
4161 SmlMetInfMetInf_t* metInf( static_cast<SmlMetInfMetInf_t*>( aMeta->content ) ); |
|
4162 |
|
4163 if ( metInf->format ) |
|
4164 { |
|
4165 if ( metInf->format->content ) |
|
4166 { |
|
4167 TPtr8 format( static_cast<TUint8*>( metInf->format->content ), metInf->format->length, metInf->format->length ); |
|
4168 TrimRightSpaceAndNull( format ); |
|
4169 |
|
4170 if ( format.Length() > 0 ) |
|
4171 { |
|
4172 if ( format != KNSmlAgentChrFormat ) |
|
4173 { |
|
4174 aFormat.Set( format ); |
|
4175 return EFalse; |
|
4176 } |
|
4177 } |
|
4178 } |
|
4179 } |
|
4180 } |
|
4181 } |
|
4182 |
|
4183 return ETrue; |
|
4184 } |
|
4185 |
|
4186 // ----------------------------------------------------------------------------- |
|
4187 // CNSmlDSCmds:::CheckAndSetReceivedMediaTypeL |
|
4188 // Validates the received media (content) type. |
|
4189 // ----------------------------------------------------------------------------- |
|
4190 // |
|
4191 TBool CNSmlDSCmds::CheckAndSetReceivedMediaTypeL( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem ) |
|
4192 { |
|
4193 if ( aCmd == KNSmlAgentDelete ) |
|
4194 { |
|
4195 return ETrue; |
|
4196 } |
|
4197 |
|
4198 TPtr8 mediaType( NULL, 0, 0 ); |
|
4199 TBool found( EFalse ); |
|
4200 |
|
4201 // first check item level media type |
|
4202 if ( MediaTypeSetOkL( aItem->meta, found, mediaType, aCmd ) ) |
|
4203 { |
|
4204 return ETrue; |
|
4205 } |
|
4206 |
|
4207 // check under command if item level media type was not found |
|
4208 if ( !found ) |
|
4209 { |
|
4210 if ( MediaTypeSetOkL( aContent->meta, found, mediaType,aCmd ) ) |
|
4211 { |
|
4212 return ETrue; |
|
4213 } |
|
4214 } |
|
4215 |
|
4216 if ( found ) |
|
4217 { |
|
4218 //mediatype found but does not suppport hierarchical sync (move) |
|
4219 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusOptFeatureNotSupported ); |
|
4220 } |
|
4221 else |
|
4222 { |
|
4223 StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat, &mediaType ); |
|
4224 } |
|
4225 |
|
4226 return EFalse; |
|
4227 } |
|
4228 |
|
4229 // ----------------------------------------------------------------------------- |
|
4230 // CNSmlDSCmds:::MediaTypeSetOkL |
|
4231 // If the media (content) type is OK its devcaps are set to the corresponding |
|
4232 // DataStore. |
|
4233 // ----------------------------------------------------------------------------- |
|
4234 // |
|
4235 TBool CNSmlDSCmds::MediaTypeSetOkL( const SmlPcdata_t* aMeta, TBool& aFound, TPtr8& aMediaType,const TDesC8& aCmd ) const |
|
4236 { |
|
4237 aFound = EFalse; |
|
4238 |
|
4239 if ( aMeta ) |
|
4240 { |
|
4241 if ( aMeta->content && aMeta->contentType == SML_PCDATA_EXTENSION && aMeta->extension == SML_EXT_METINF ) |
|
4242 { |
|
4243 SmlMetInfMetInf_t* metInf( (SmlMetInfMetInf_t*)aMeta->content ); |
|
4244 |
|
4245 if ( metInf->type ) |
|
4246 { |
|
4247 aMediaType.Set( static_cast<TUint8*>( metInf->type->content ), metInf->type->length, metInf->type->length ); |
|
4248 TrimRightSpaceAndNull( aMediaType ); |
|
4249 |
|
4250 if ( aMediaType.Length() > 0 ) |
|
4251 { |
|
4252 aFound = ETrue; |
|
4253 |
|
4254 if ( iDSContent.SetSavedPartnerDevCapsL() == KErrNone ) |
|
4255 { |
|
4256 TInt status( KErrNone ); |
|
4257 TRAPD( error, status = iDSContent.IsHierarchicalSyncSupportedL( aMediaType ) ); |
|
4258 |
|
4259 if ( error != KErrNone ) |
|
4260 { |
|
4261 return EFalse; |
|
4262 } |
|
4263 |
|
4264 if ( aCmd == KNSmlAgentMove && !status ) |
|
4265 { |
|
4266 return EFalse; |
|
4267 } |
|
4268 |
|
4269 return ETrue; |
|
4270 } |
|
4271 } |
|
4272 } |
|
4273 } |
|
4274 } |
|
4275 |
|
4276 return EFalse; |
|
4277 } |
|
4278 |
|
4279 // ----------------------------------------------------------------------------- |
|
4280 // CNSmlDSCmds::smlDeviceInfoL |
|
4281 // Callback function used by the DevInfo parser. |
|
4282 // ----------------------------------------------------------------------------- |
|
4283 // |
|
4284 Ret_t CNSmlDSCmds::smlDeviceInfoL( SmlDevInfDevInfPtr_t aContent ) |
|
4285 { |
|
4286 ProcessDeviceInfoL( *aContent ); |
|
4287 return 0; |
|
4288 } |
|
4289 |
|
4290 // ----------------------------------------------------------------------------- |
|
4291 // CNSmlDSCmds::AlertDataLC() |
|
4292 // |
|
4293 // ----------------------------------------------------------------------------- |
|
4294 // |
|
4295 HBufC* CNSmlDSCmds::AlertDataLC( const SmlItemList_t* aItemList ) const |
|
4296 { |
|
4297 HBufC* unicodeData( NULL ); |
|
4298 |
|
4299 if ( aItemList ) |
|
4300 { |
|
4301 if ( aItemList->item->data->content ) |
|
4302 { |
|
4303 TPtr8 data( static_cast<TUint8*>( aItemList->item->data->content ), aItemList->item->data->length, aItemList->item->data->length ); |
|
4304 TrimRightSpaceAndNull( data ); |
|
4305 NSmlUnicodeConverter::HBufC16InUnicodeLC( data, unicodeData ); |
|
4306 } |
|
4307 } |
|
4308 |
|
4309 if ( !unicodeData ) |
|
4310 { |
|
4311 unicodeData = HBufC::NewLC( 0 ); |
|
4312 } |
|
4313 |
|
4314 return unicodeData; |
|
4315 } |
|
4316 |
|
4317 // ----------------------------------------------------------------------------- |
|
4318 // CNSmlDSCmds::AppendCTCapsL |
|
4319 // |
|
4320 // ----------------------------------------------------------------------------- |
|
4321 // |
|
4322 void CNSmlDSCmds::AppendCTCapsL( CNSmlDbCaps& aDbCaps, const SmlDevInfDatastore_t* aDataStore, SmlDevInfCtCapList_t* aCtCapList ) const |
|
4323 { |
|
4324 if ( aDataStore->sourceref ) |
|
4325 { |
|
4326 aDbCaps.SetSourceRefL( aDataStore->sourceref->Data() ); |
|
4327 } |
|
4328 |
|
4329 if ( aDataStore->displayname ) |
|
4330 { |
|
4331 aDbCaps.SetDisplayNameL( aDataStore->displayname->Data() ); |
|
4332 } |
|
4333 |
|
4334 if ( aDataStore->maxguidsize ) |
|
4335 { |
|
4336 aDbCaps.SetMaxGuidSizeL( aDataStore->maxguidsize->Data() ); |
|
4337 } |
|
4338 |
|
4339 if ( aDataStore->rxpref ) |
|
4340 { |
|
4341 aDbCaps.SetRxPrefL( aDataStore->rxpref->cttype->Data(), aDataStore->rxpref->verct->Data() ); |
|
4342 } |
|
4343 |
|
4344 if ( aDataStore->rx ) |
|
4345 { |
|
4346 SmlDevInfXmitListPtr_t rx( aDataStore->rx ); |
|
4347 |
|
4348 while ( rx ) |
|
4349 { |
|
4350 aDbCaps.AddRxL( rx->data->cttype->Data(), rx->data->verct->Data() ); |
|
4351 rx = rx->next; |
|
4352 } |
|
4353 } |
|
4354 |
|
4355 if ( aDataStore->txpref ) |
|
4356 { |
|
4357 aDbCaps.SetTxPrefL( aDataStore->txpref->cttype->Data(), aDataStore->txpref->verct->Data() ); |
|
4358 } |
|
4359 |
|
4360 if ( aDataStore->tx ) |
|
4361 { |
|
4362 SmlDevInfXmitListPtr_t tx( aDataStore->tx ); |
|
4363 |
|
4364 while ( tx ) |
|
4365 { |
|
4366 aDbCaps.AddTxL( tx->data->cttype->Data(), tx->data->verct->Data() ); |
|
4367 tx = tx->next; |
|
4368 } |
|
4369 } |
|
4370 |
|
4371 if ( aDataStore->supportHierarchicalSync ) |
|
4372 { |
|
4373 aDbCaps.SetSupportHierarchicalSyncL(); |
|
4374 } |
|
4375 |
|
4376 if ( aDataStore->synccap ) |
|
4377 { |
|
4378 SmlPcdataListPtr_t syncType( aDataStore->synccap->synctype ); |
|
4379 |
|
4380 while ( syncType ) |
|
4381 { |
|
4382 TLex8 lex( syncType->data->Data() ); |
|
4383 TInt type; |
|
4384 lex.Val( type ); |
|
4385 aDbCaps.SetSyncType( (CNSmlDbCaps::ENSmlSyncTypes)type ); |
|
4386 syncType = syncType->next; |
|
4387 } |
|
4388 } |
|
4389 |
|
4390 TInt pc( 0 ); |
|
4391 SmlDevInfCtCapListPtr_t ctcap( NULL ); |
|
4392 |
|
4393 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
4394 { |
|
4395 ctcap = aCtCapList; |
|
4396 } |
|
4397 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
4398 { |
|
4399 ctcap = aDataStore->ctcap; |
|
4400 } |
|
4401 |
|
4402 while ( ctcap ) |
|
4403 { |
|
4404 if ( ctcap->data ) |
|
4405 { |
|
4406 CNSmlCtCap* cap = aDbCaps.AddCtCapLC(); |
|
4407 ++pc; |
|
4408 |
|
4409 if ( ctcap->data->cttype ) |
|
4410 { |
|
4411 cap->SetCtTypeL( ctcap->data->cttype->Data() ); |
|
4412 } |
|
4413 |
|
4414 if ( ctcap->data->verct ) |
|
4415 { |
|
4416 cap->SetVerCtL( ctcap->data->verct->Data() ); |
|
4417 } |
|
4418 |
|
4419 if ( ctcap->data->fieldlevel ) |
|
4420 { |
|
4421 cap->SetFieldLevelL(); |
|
4422 } |
|
4423 |
|
4424 if ( iVersionPublicId == KNSmlSyncMLPublicId ) |
|
4425 { |
|
4426 if( ctcap->data->prop ) |
|
4427 { |
|
4428 SmlDevInfCTDataPropListPtr_t prop( ctcap->data->prop ); |
|
4429 |
|
4430 while ( prop ) |
|
4431 { |
|
4432 if( prop->data ) |
|
4433 { |
|
4434 CNSmlDevInfProp* pr( cap->AddDevInfPropLC( prop->data->prop->name->Data() ) ); |
|
4435 ++pc; |
|
4436 |
|
4437 if ( prop->data->prop->datatype ) |
|
4438 { |
|
4439 pr->SetDataTypeL( prop->data->prop->datatype->Data() ); |
|
4440 } |
|
4441 |
|
4442 if ( prop->data->prop->dname ) |
|
4443 { |
|
4444 pr->SetDisplayNameL( prop->data->prop->dname->Data() ); |
|
4445 } |
|
4446 |
|
4447 if ( prop->data->prop->size ) |
|
4448 { |
|
4449 pr->SetMaxSizeL( prop->data->prop->size->Data() ); |
|
4450 } |
|
4451 |
|
4452 if ( prop->data->prop->valenum ) |
|
4453 { |
|
4454 SmlPcdataListPtr_t propValEnum( prop->data->prop->valenum ); |
|
4455 |
|
4456 while ( propValEnum ) |
|
4457 { |
|
4458 if ( propValEnum->data ) |
|
4459 { |
|
4460 pr->AddValEnumL( propValEnum->data->Data() ); |
|
4461 } |
|
4462 |
|
4463 propValEnum = propValEnum->next; |
|
4464 } |
|
4465 } |
|
4466 |
|
4467 if ( prop->data->param ) |
|
4468 { |
|
4469 SmlDevInfCTDataListPtr_t param( prop->data->param ); |
|
4470 |
|
4471 while ( param ) |
|
4472 { |
|
4473 if ( param->data ) |
|
4474 { |
|
4475 CNSmlPropParam* par( pr->AddParamLC( param->data->name->Data() ) ); |
|
4476 ++pc; |
|
4477 |
|
4478 if ( param->data->datatype ) |
|
4479 { |
|
4480 par->SetDataTypeL( param->data->datatype->Data() ); |
|
4481 } |
|
4482 |
|
4483 if ( param->data->dname ) |
|
4484 { |
|
4485 par->SetDisplayNameL( param->data->dname->Data() ); |
|
4486 } |
|
4487 |
|
4488 if ( param->data->valenum ) |
|
4489 { |
|
4490 SmlPcdataListPtr_t valenum( param->data->valenum ); |
|
4491 |
|
4492 while (valenum) |
|
4493 { |
|
4494 if ( valenum->data ) |
|
4495 { |
|
4496 par->AddValEnumL( valenum->data->Data() ); |
|
4497 } |
|
4498 |
|
4499 valenum = valenum->next; |
|
4500 } |
|
4501 } |
|
4502 } |
|
4503 |
|
4504 param = param->next; |
|
4505 } |
|
4506 } |
|
4507 } |
|
4508 |
|
4509 prop = prop->next; |
|
4510 } |
|
4511 } |
|
4512 } |
|
4513 else if ( iVersionPublicId == KNSmlSyncMLPublicId12 ) |
|
4514 { |
|
4515 if ( ctcap->data->property ) |
|
4516 { |
|
4517 SmlDevInfPropertyListPtr_t prop( ctcap->data->property ); |
|
4518 |
|
4519 while ( prop ) |
|
4520 { |
|
4521 if ( prop->data ) |
|
4522 { |
|
4523 |
|
4524 if ( prop->data->propname == NULL ) |
|
4525 { |
|
4526 User::Leave( KErrArgument ); |
|
4527 } |
|
4528 |
|
4529 CNSmlDevInfProp* pr( cap->AddDevInfPropLC(prop->data->propname->Data() ) ); |
|
4530 ++pc; |
|
4531 |
|
4532 if ( prop->data->datatype ) |
|
4533 { |
|
4534 pr->SetDataTypeL( prop->data->datatype->Data() ); |
|
4535 } |
|
4536 |
|
4537 if ( prop->data->displayname ) |
|
4538 { |
|
4539 pr->SetDisplayNameL( prop->data->displayname->Data() ); |
|
4540 } |
|
4541 |
|
4542 if ( prop->data->maxoccur ) |
|
4543 { |
|
4544 pr->SetMaxOccurL( prop->data->maxoccur->Data() ); |
|
4545 } |
|
4546 |
|
4547 if ( prop->data->maxsize ) |
|
4548 { |
|
4549 pr->SetMaxSizeL( prop->data->maxsize->Data() ); |
|
4550 } |
|
4551 |
|
4552 if ( prop->data->notruncate ) |
|
4553 { |
|
4554 pr->SetNoTruncateL(); |
|
4555 } |
|
4556 |
|
4557 if ( prop->data->propparam ) |
|
4558 { |
|
4559 SmlDevInfPropParamListPtr_t param( prop->data->propparam ); |
|
4560 |
|
4561 while ( param ) |
|
4562 { |
|
4563 if ( param->data ) |
|
4564 { |
|
4565 CNSmlPropParam* par( pr->AddParamLC( param->data->paramname->Data() ) ); |
|
4566 ++pc; |
|
4567 |
|
4568 if ( param->data->datatype ) |
|
4569 { |
|
4570 par->SetDataTypeL( param->data->datatype->Data() ); |
|
4571 } |
|
4572 |
|
4573 if ( param->data->displayname ) |
|
4574 { |
|
4575 par->SetDisplayNameL( param->data->displayname->Data() ); |
|
4576 } |
|
4577 |
|
4578 if ( param->data->valenum ) |
|
4579 { |
|
4580 SmlPcdataListPtr_t valenum( param->data->valenum ); |
|
4581 |
|
4582 while ( valenum ) |
|
4583 { |
|
4584 if ( valenum->data ) |
|
4585 { |
|
4586 par->AddValEnumL( valenum->data->Data() ); |
|
4587 } |
|
4588 valenum = valenum->next; |
|
4589 } |
|
4590 } |
|
4591 } |
|
4592 |
|
4593 param = param->next; |
|
4594 } |
|
4595 } |
|
4596 } |
|
4597 |
|
4598 prop = prop->next; |
|
4599 } |
|
4600 } |
|
4601 } |
|
4602 } |
|
4603 |
|
4604 ctcap = ctcap->next; |
|
4605 } |
|
4606 |
|
4607 CleanupStack::PopAndDestroy( pc ); |
|
4608 } |
|
4609 |
|
4610 // ----------------------------------------------------------------------------- |
|
4611 // CNSmlDSCmds::SwitchAlertCodeL |
|
4612 // Does mapping between OMA DS 1.1 and 1.2 alert codes. |
|
4613 // ----------------------------------------------------------------------------- |
|
4614 // |
|
4615 void CNSmlDSCmds::SwitchAlertCode( TDes8& aAlertCode ) |
|
4616 { |
|
4617 if ( aAlertCode == KNSmlDSTwoWayByServer ) |
|
4618 { |
|
4619 aAlertCode = KNSmlDSTwoWay; |
|
4620 } |
|
4621 else if ( aAlertCode == KNSmlDSOneWayFromClientByServer ) |
|
4622 { |
|
4623 aAlertCode = KNSmlDSOneWayFromClient; |
|
4624 } |
|
4625 else if ( aAlertCode == KNSmlDSRefreshFromClientByServer ) |
|
4626 { |
|
4627 aAlertCode = KNSmlDSRefreshFromClient; |
|
4628 } |
|
4629 else if ( aAlertCode == KNSmlDSOneWayFromServerByServer ) |
|
4630 { |
|
4631 aAlertCode = KNSmlDSOneWayFromServer; |
|
4632 } |
|
4633 else if ( aAlertCode == KNSmlDSRefreshFromServerByServer ) |
|
4634 { |
|
4635 aAlertCode = KNSmlDSRefreshFromServer; |
|
4636 } |
|
4637 } |
|
4638 |
|
4639 // ----------------------------------------------------------------------------- |
|
4640 // CNSmlDSCmds::ConvertUid |
|
4641 // Converts UID from literal to numeric presentation. |
|
4642 // ----------------------------------------------------------------------------- |
|
4643 // |
|
4644 TInt CNSmlDSCmds::ConvertUid( const TDesC8& aLiteralUid, TSmlDbItemUid& aNumericUid ) |
|
4645 { |
|
4646 TLex8 lexer( aLiteralUid ); |
|
4647 |
|
4648 aNumericUid = KNullDataItemId; |
|
4649 |
|
4650 return lexer.Val( aNumericUid ); |
|
4651 } |
|
4652 |
|
4653 // End of File |