syncmlfw/ds/syncagent/src/nsmldscmds.cpp
branchRCL_3
changeset 24 13d7c31c74e0
parent 18 2de6635c154b
child 25 b183ec05bd8c
--- a/syncmlfw/ds/syncagent/src/nsmldscmds.cpp	Thu Jul 15 19:36:11 2010 +0300
+++ b/syncmlfw/ds/syncagent/src/nsmldscmds.cpp	Thu Aug 19 10:44:50 2010 +0300
@@ -65,6 +65,8 @@
 // CONSTANTS
 _LIT8( KNSmlRoot, "/" );
 static const TInt KMaxLength = 255;
+const TUid KRepositoryId =  { 0x2000CF7E };   
+const TInt KNsmlDsOrphanEvent = 0xB ;
 
 // ============================ MEMBER FUNCTIONS ===============================
 
@@ -3618,7 +3620,9 @@
 						}
 						
 					iItemOpened = EFalse;
-					
+					SmlStatus_t* status = NULL;
+					SmlItemList_t** itemList;
+					CRepository* rep = NULL;
 					switch ( returnCode )
 						{
 						case KErrNone:
@@ -3654,6 +3658,57 @@
 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat );
 							break;
 							
+						case KErrPathNotFound:			
+						    // Read the Orphan Event ID from the cenrep
+						    rep = CRepository::NewLC(KRepositoryId);
+                            TRAPD( err, rep->Get(KNsmlDsOrphanEvent, iNewUid) );
+                            DBG_ARGS(_S("read the cenrep %d %d"), err, iNewUid);
+                            User::LeaveIfError(err);
+                            CleanupStack::PopAndDestroy(rep);
+							
+						    _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : Invalid Parent"));
+						    statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusMovedPermanently );
+						    DBG_ARGS(_S("Invalid parent: statusid %d"), statusId);
+						    status = iStatusToServer->StatusItem( statusId );
+						    DBG_ARGS(_S("Invalid parent: status %d"), status);
+						    if( status )
+                                {
+                                SmlItemList_t* newItemList = new( ELeave ) SmlItemList_t;
+                                _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : creating a new item"));
+                                newItemList->item = new( ELeave ) SmlItem_t;
+                                _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : creating a new data"));
+                                iStatusToServer->FillItemDataL( newItemList->item );
+                                _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : updating"));
+                                
+                                itemList = &(status->itemList);
+                                while ( *itemList )
+                                    {
+                                    itemList = &(*itemList)->next;
+                                    }
+                                *itemList = newItemList;
+                                _DBG_FILE(_S8("CNSmlDSCmds::ADD UpdateL : updated"));
+                                }
+						    if ( !iBatchModeOn )
+                                {
+                                iDSContent.IncreaseServerItemsAdded();
+                                clientModifications.iNumAdded = 1;
+                                
+                                if ( !iAtomicModeOn )
+                                    {
+                                    iDSContent.CreateNewMapItemL( iNewUid, aUID, 0 );
+                                    }
+                                else
+                                    {
+                                    iDSContent.CreateNewMapItemL( iNewUid, aUID, iAtomicId );
+                                    }
+                                }
+                            else
+                                {
+                                clientModifications.iNumAdded = 1;
+                                iBatchBuffer->SetStatusEntryId( statusId );
+                                }
+						    break;
+							
 						default:
 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed );
 							break;
@@ -3811,6 +3866,11 @@
 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusUnsupportedMediaTypeOrFormat );
 							break;
 							
+						case KErrPathNotFound:
+						    _DBG_FILE(_S8("CNSmlDSCmds:: REPLACE UpdateL : Invalid Parent"));
+						    statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusMovedPermanently );
+						    break;
+							
 						default:
 							statusId = StatusDataToGenericCommandL( aCmd, aContent, aItem, TNSmlError::ESmlStatusCommandFailed );
 							break;