backupandrestore/backupengine/src/sbedataowner.cpp
changeset 0 d0791faffa3f
child 13 81da3301b632
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of CDataOwner
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 #include <d32dbms.h>
       
    22 
       
    23 #include "sbedataowner.h"
       
    24 #include "abserver.h"
       
    25 #include "sbtypes.h"
       
    26 #include "sblog.h"
       
    27 #include "sbeparserdefs.h"
       
    28 #include <connect/panic.h>
       
    29 
       
    30 namespace conn
       
    31 	{	
       
    32 	_LIT(KDrive, "?:");
       
    33 	_LIT(KDriveAndSlash, "?:\\");
       
    34 	_LIT(KPrivateMatch, "?:\\private\\*");
       
    35 	_LIT(KPrivateSidMatch, "?:\\private\\");
       
    36 	_LIT(KSys, "?:\\sys\\*");
       
    37 	_LIT(KSystem, "?:\\system\\*");
       
    38 	_LIT(KResource, "?:\\resource\\*");
       
    39 	_LIT(KOther, "*\\..\\*");
       
    40 	_LIT(KPad, "00000000"); // Used for padding if required
       
    41 	_LIT(KQuestionMark, "?");
       
    42 	_LIT8(KVersion, "1.0");
       
    43 	_LIT( KExclamationAsDrive, "!"); // Used to generic drives for public data as in .SIS file package
       
    44 	_LIT( KPrivateNoBackup, "?:\\private\\????????\\NoBackup\\*"); // Used to exclude the file if it is in "NoBackup" folder.
       
    45 	
       
    46 		
       
    47 	
       
    48 	void CleanupRPointerArray(TAny* aPtr)
       
    49 		{
       
    50 		RPointerArray<CBase>* array = static_cast<RPointerArray<CBase>*>(aPtr);
       
    51 		array->ResetAndDestroy();
       
    52 		delete array;
       
    53 		}
       
    54 	
       
    55 	// CSelection //
       
    56 	
       
    57 	/**
       
    58 	
       
    59 	Symbian 2nd phase construction creates a Selection
       
    60 	
       
    61 	@param aType - Selection Type
       
    62 	@param aSelection - Selection Nmae
       
    63 	@return CSelection a pointer to a new object 
       
    64 	*/
       
    65 	CSelection* CSelection::NewLC(TSelectionType aType, const TDesC& aSelection)
       
    66 		{
       
    67 		CSelection* self = new (ELeave) CSelection(aType);
       
    68 		CleanupStack::PushL(self);
       
    69 		self->ConstructL(aSelection);
       
    70 		return self;
       
    71 		}
       
    72 	
       
    73 	/**
       
    74 	Standard C++ destructor
       
    75 	*/
       
    76 	CSelection::~CSelection()
       
    77 		{
       
    78 		delete iSelection;
       
    79 		}
       
    80 	
       
    81 	/**
       
    82 	Standard C++ constructor
       
    83 	*/
       
    84 	CSelection::CSelection(TSelectionType aType) : iType(aType)
       
    85 		{
       
    86 		}
       
    87 		
       
    88 	/**
       
    89 	Symbian 2nd phase constructor
       
    90 	*/
       
    91 	void CSelection::ConstructL(const TDesC& aSelection)
       
    92 		{
       
    93 		iSelection = aSelection.AllocL();
       
    94 		}
       
    95 	
       
    96 	/**
       
    97 	Selection Type
       
    98 	
       
    99 	@return TSelectionType Type
       
   100 	*/
       
   101 	TSelectionType CSelection::SelectionType() const
       
   102 		{
       
   103 		return iType;
       
   104 		}
       
   105 	
       
   106 	/**
       
   107 	Selection Name
       
   108 	
       
   109 	@return const TDesC& Name
       
   110 	*/
       
   111 	const TDesC& CSelection::SelectionName() const
       
   112 		{
       
   113 		return *iSelection;
       
   114 		}
       
   115 	
       
   116 	// CSelection End //
       
   117 		
       
   118 	CDataOwner* CDataOwner::NewL(TSecureId aSID, CDataOwnerManager* apDataOwnerManager)
       
   119 	/** Symbian OS static constructor
       
   120 
       
   121 	@param aSID secure id of data owner
       
   122 	@param apDataOwnerManager data owner manager to access resources
       
   123 	@return a CDataOwner object
       
   124 	*/
       
   125 		{
       
   126 		CDataOwner* self = CDataOwner::NewLC(aSID, apDataOwnerManager);
       
   127 		CleanupStack::Pop(self);
       
   128 
       
   129 		return self;
       
   130 		}
       
   131 
       
   132 	CDataOwner* CDataOwner::NewLC(TSecureId aSID, CDataOwnerManager* apDataOwnerManager)
       
   133 	/** Symbian OS static constructor
       
   134 
       
   135 	@param aSID secure id of data owner
       
   136 	@param apDataOwnerManager data owner manager to access resources
       
   137 	@return a CDataOwner object
       
   138 	*/
       
   139 		{
       
   140 		CDataOwner* self = new(ELeave) CDataOwner(aSID, apDataOwnerManager);
       
   141 		CleanupStack::PushL(self);
       
   142 
       
   143 		self->ConstructL();
       
   144 		
       
   145 		return self;
       
   146 		}
       
   147 
       
   148 	CDataOwner::CDataOwner(TSecureId aSID, CDataOwnerManager* apDataOwnerManager) :
       
   149 	    iStatus(EUnset), iFilesParsed(EFalse), iPrimaryFile(EFalse), /*iBackupAsPartial(EFalse), */
       
   150 	    iSecureId(aSID),
       
   151 	    iBufferFileWriter(NULL), iBufferFileReader(NULL), iBufferSnapshotWriter(NULL), 
       
   152 	    iTempSnapshotHolder(NULL), ipDataOwnerManager(apDataOwnerManager)
       
   153 	/** Standard C++ constructor
       
   154 
       
   155 	@param aSID secure id of data owner
       
   156 	@param apDataOwnerManager data owner manager to access resources
       
   157 	*/
       
   158 		{
       
   159 		}
       
   160 		
       
   161 	void CDataOwner::ConstructL()
       
   162 	/** Symbian 2nd stage constructor */
       
   163 		{
       
   164 		iRegistrationFiles = new (ELeave) CDesCArrayFlat(KDesCArrayGranularity);
       
   165 		iPrivatePath = HBufC::NewL(0);
       
   166 		iProxyInformationArray.Reset();
       
   167 		iPublicDirStack.Reset();
       
   168 		iPublicDirNameStack.Reset();
       
   169 		iPublicExcludes.Reset();
       
   170 		}
       
   171 
       
   172 	CDataOwner::~CDataOwner()
       
   173 	/** Standard C++ destructor
       
   174 	*/
       
   175 		{
       
   176 		// Close the RArrays
       
   177 		iProxyInformationArray.Close();
       
   178 		iStateByDrive.Close();
       
   179 		iProxyStateByDrive.Close();
       
   180 		iDBMSSelections.Close();
       
   181 		
       
   182 		iPublicSelections.ResetAndDestroy();
       
   183 		iPassiveSelections.ResetAndDestroy();
       
   184 		iSnapshots.ResetAndDestroy();
       
   185 		
       
   186 		for (TInt x = iPublicDirStack.Count(); x > 0; --x)
       
   187 			{
       
   188 			iPublicDirStack[x-1].Close();
       
   189 			delete iPublicDirNameStack[x-1];
       
   190 			}
       
   191 		iPublicDirStack.Close();
       
   192 		iPublicDirNameStack.Close();
       
   193 		iPublicExcludes.Close();
       
   194 		
       
   195 		delete iPrivatePath;
       
   196 		delete iBufferFileWriter;
       
   197 		delete iBufferFileReader;
       
   198 		delete iBufferSnapshotWriter;
       
   199 		delete iBufferSnapshotReader;
       
   200 		delete iTempSnapshotHolder;
       
   201 		delete iRegistrationFiles;
       
   202 		}
       
   203 
       
   204 	void CDataOwner::AddRegistrationFilesL(const TDesC& aFileName)
       
   205 	/** Adds a registration file
       
   206 
       
   207 	Adds a registration file to the list of registration files for this data owner
       
   208 
       
   209 	@param aFileName the filename of the 
       
   210 	*/
       
   211 		{
       
   212 		iRegistrationFiles->AppendL(aFileName);
       
   213 		}
       
   214 		
       
   215 	void CDataOwner::StartProcessIfNecessaryL()
       
   216 	/**
       
   217 	Start the active process
       
   218 	*/
       
   219 		{
       
   220 		// Do we need to check that the process is started?
       
   221 		if (iActiveInformation.iSupported && iActiveInformation.iActiveDataOwner)
       
   222 			{
       
   223 			// Get the list of currently running processes
       
   224 			TBool processFound = EFalse;
       
   225 			TFullName processName;
       
   226 			TFindProcess findProcess;
       
   227 			while (!processFound && (findProcess.Next(processName) == KErrNone))
       
   228 				{
       
   229 				RProcess process;
       
   230 				CleanupClosePushL(process);
       
   231 				if (process.Open(processName) == KErrNone) // Should we leave on any errors?
       
   232 					{
       
   233 					if (process.SecureId() == iSecureId)
       
   234 						{
       
   235 						// Process already exists - see if it's previuosly connected and has a current session
       
   236 						__LOG1("Process %S already exists - not starting", &processName);
       
   237 						TRAPD(err, iStatus = ipDataOwnerManager->ABServer().SessionReadyStateL(iSecureId));
       
   238 						if (err == KErrNone)
       
   239 							{
       
   240 							__LOG2("Existing session for process %S has status %d", &processName, iStatus);
       
   241 							} // if
       
   242 						else
       
   243 							{
       
   244 							__LOG1("Existing process %S hasn't yet connected to a session", &processName);
       
   245 							iStatus = EDataOwnerNotConnected;//ReadyState only check session state when this status not equal to 'EDataOwnerReadyNoImpl' and 'EDataOwnerReady' 
       
   246 							} // else
       
   247 						
       
   248 						processFound = ETrue;
       
   249 						} // if
       
   250 					} // if
       
   251 					
       
   252 					CleanupStack::PopAndDestroy(&process);
       
   253 				} // while
       
   254 				
       
   255 			// If the process is not started then we need to start it
       
   256 			if (!processFound)
       
   257 				{
       
   258 				// Create the process
       
   259 				TUidType uidType(KNullUid, KNullUid, iSecureId);
       
   260 				RProcess process;
       
   261 				CleanupClosePushL(process);
       
   262 				TInt createErr = process.Create(iActiveInformation.iProcessName, KNullDesC, uidType);
       
   263 				if (createErr != KErrNone)
       
   264 					{
       
   265 					__LOG2("Process %S failed to start(%d)", &iActiveInformation.iProcessName, createErr);
       
   266 					iStatus = EDataOwnerFailed;
       
   267 					} // if
       
   268 				else
       
   269 					{
       
   270 					__LOG1("Process %S started.", &iActiveInformation.iProcessName);
       
   271 					process.Resume();
       
   272 					} // else
       
   273 					
       
   274 				CleanupStack::PopAndDestroy(&process);
       
   275 				} // if
       
   276 			} // if
       
   277 		}
       
   278 		
       
   279 
       
   280 	void CDataOwner::ParseFilesL()
       
   281 	/** Parse the registration files
       
   282 
       
   283 	@leave KErrGeneral data owner has no primary registration file
       
   284 	*/
       
   285 		{
       
   286 		if (!iFilesParsed)
       
   287 			{
       
   288 			TUint count = iRegistrationFiles->Count();
       
   289 			TBool foundPrimaryFile = EFalse;
       
   290 			while(count--)
       
   291 				{
       
   292 				const TDesC& fileName = (*iRegistrationFiles)[count];
       
   293 
       
   294 			  // Determine if this is the primary file
       
   295 				iPrimaryFile = (fileName.FindF(KPrimaryBackupRegistrationFile) != KErrNotFound);
       
   296 				if (iPrimaryFile)
       
   297 					{
       
   298 					foundPrimaryFile = ETrue;
       
   299 					}
       
   300 
       
   301 				// Parse file
       
   302 
       
   303 				__LOG2("CDataOwner::ParseFilesL() - [0x%08x] - parsing reg file: %S...", iSecureId.iId, &fileName);
       
   304 				TRAPD(err, ParseFileL(fileName));
       
   305 				if	(err == KErrNone)
       
   306 					{
       
   307 					__LOG1("CDataOwner::ParseFilesL() - [0x%08x] - ...file parsed okay", iSecureId.iId);
       
   308 					}
       
   309 				else
       
   310 					{
       
   311 					__LOG2("CDataOwner::ParseFilesL() - [0x%08x] - ...*** PARSING FAILED *** - error: %d", iSecureId.iId, err);
       
   312 					User::Leave(err);
       
   313 					}
       
   314 				
       
   315 				// Add the registration file to the exclude list
       
   316 				CSelection* selection = CSelection::NewLC(EExclude, fileName);
       
   317 				iPassiveSelections.AppendL(selection);
       
   318 				CleanupStack::Pop(selection);
       
   319 				}
       
   320 
       
   321 			// Check that a primary file was found, as there must be one	
       
   322 			if (!foundPrimaryFile)
       
   323 				{
       
   324 				User::Leave(KErrGeneral);
       
   325 				} // if
       
   326 			
       
   327 			iFilesParsed = ETrue;
       
   328 			} // if
       
   329 		
       
   330 		if (!iActiveInformation.iSupported && (iPassiveInformation.iSupported || iSystemInformation.iSupported))
       
   331 			{
       
   332 			iStatus = EDataOwnerReady;
       
   333 			}
       
   334  		}
       
   335 		
       
   336 	void CDataOwner::GetExpectedDataSizeL(TTransferDataType aTransferType,
       
   337 										  TDriveNumber aDriveNumber, TUint& aSize)
       
   338 	/** Gets the expected data size of the backkup.
       
   339 	
       
   340 	@param aTransferType the type of the transfer
       
   341 	@param aDriveNumber the drive to check for files
       
   342 	@param aSize on return the total size in bytes of the backup
       
   343 	@leave KErrNotReady the snapshot has not been set
       
   344 	*/
       
   345 		{
       
   346 		aSize = 0;
       
   347 		switch (aTransferType)
       
   348 			{
       
   349 		case EPassiveSnapshotData:
       
   350 			{
       
   351 			__LOG1("CDataOwner::GetExpectedDataSizeL() - START - EPassiveSnapshotData - aDriveNumber: %c", aDriveNumber + 'A');
       
   352 
       
   353             CDesCArray* files = new(ELeave) CDesC16ArrayFlat(KDesCArrayGranularity);
       
   354             CleanupStack::PushL(files);
       
   355 		
       
   356 			BuildFileListL(iPassiveSelections, aDriveNumber, aTransferType, EFalse, NULL, NULL, files);
       
   357 			
       
   358 			// DBMS file?
       
   359 			AddDBMSFilesL(aDriveNumber, files, NULL);
       
   360 			
       
   361 			TUint count = files->Count();
       
   362 			aSize = count * sizeof(TSnapshot);
       
   363             __LOG2("CDataOwner::GetExpectedDataSizeL() - passive snapshot count: %d, expected size: %d", count, aSize);
       
   364 			
       
   365 			CleanupStack::PopAndDestroy(files);
       
   366 			break;
       
   367 			}
       
   368 		case EPassiveBaseData:
       
   369 		case EPassiveIncrementalData:
       
   370 			{
       
   371 			__LOG1("CDataOwner::GetExpectedDataSizeL() - START - EPassiveBaseData/EPassiveIncrementalData - aDriveNumber: %c", aDriveNumber + 'A');
       
   372 
       
   373             RFileArray files;
       
   374 			CleanupClosePushL(files);
       
   375 			
       
   376 			// Find all the files
       
   377 			if (aTransferType == EPassiveBaseData)
       
   378 				{
       
   379 	            __LOG("CDataOwner::GetExpectedDataSizeL() - EPassiveBaseData");
       
   380 				BuildFileListL(iPassiveSelections, aDriveNumber, aTransferType, EFalse, NULL, &files, NULL);
       
   381 				
       
   382 				// Do we need to add the DBMS file?
       
   383 				AddDBMSFilesL(aDriveNumber, NULL, &files);
       
   384 				} // if
       
   385 			else
       
   386 				{
       
   387 	            __LOG("CDataOwner::GetExpectedDataSizeL() - EPassiveIncrementalData");
       
   388 
       
   389 				// Do we have a snapshot?
       
   390 				const TUint count = iSnapshots.Count();
       
   391 				RSnapshots* pSnapshot = NULL;
       
   392 				for (TInt x = 0; !pSnapshot && (x < count); x++)
       
   393 					{
       
   394 					if (iSnapshots[x]->iDriveNumber == aDriveNumber)
       
   395 						{
       
   396 						pSnapshot = &(iSnapshots[x]->iSnapshots);
       
   397 						} // if
       
   398 					} // for x
       
   399 					
       
   400 				BuildFileListL(iPassiveSelections, aDriveNumber, aTransferType, EFalse, pSnapshot, &files, NULL);
       
   401 				
       
   402 				// Do we need to add the DBMS file?
       
   403 				AddDBMSFilesL(aDriveNumber, NULL, &files);
       
   404 				} // else
       
   405 			
       
   406 			// Calculate the expected data size
       
   407 			const TUint count = files.Count();
       
   408 	        __LOG1("CDataOwner::GetExpectedDataSizeL() - passive file count: %d", count);
       
   409 			aSize = (count * sizeof(TFileFixedHeader));
       
   410 			for (TInt x = 0; x < count; x++)
       
   411 				{
       
   412                 const TEntry& fileEntry = files[x];
       
   413                 const TInt fileSize = fileEntry.iSize;
       
   414                 __LOG2("CDataOwner::GetExpectedDataSizeL() - passive file: %S, size: %d", &fileEntry.iName, fileSize);
       
   415 
       
   416 				aSize += fileEntry.iName.Length();
       
   417 				aSize += fileSize;
       
   418 				}
       
   419 			CleanupStack::PopAndDestroy(&files);
       
   420 			break;
       
   421 			}
       
   422 		case EActiveBaseData:
       
   423 		case EActiveIncrementalData:
       
   424 			{
       
   425 			__LOG1("CDataOwner::GetExpectedDataSizeL() - START - EActiveBaseData/EActiveIncrementalData - aDriveNumber: %c", aDriveNumber + 'A');
       
   426 			// Only request expected data size if it's for this data owner, not the proxies
       
   427 			if (iActiveInformation.iSupported && iActiveInformation.iActiveDataOwner && (iActiveInformation.iActiveType != EProxyImpOnly))
       
   428 				{
       
   429 				ipDataOwnerManager->ABServer().GetExpectedDataSizeL(iSecureId, aDriveNumber, aSize);
       
   430 				}
       
   431 			else
       
   432 				{
       
   433 				aSize = 0;
       
   434                 __LOG1("CDataOwner::GetExpectedDataSizeL() - ACTIVE BASE - DO 0x%08x is PROXY, so setting size to 0!", iSecureId.iId);
       
   435 				}
       
   436 				
       
   437 			} break;
       
   438 		case EActiveSnapshotData:
       
   439 			{
       
   440 			__LOG1("CDataOwner::GetExpectedDataSizeL() - START - EActiveSnapshotData - aDriveNumber: %c", aDriveNumber + 'A');
       
   441 			aSize = 0;		// ABClient M class doesn't provide retrieval of snapshot data size
       
   442 			} break;
       
   443 		default:
       
   444 			__LOG1("CDataOwner::GetExpectedDataSizeL() - START - ERROR - UNSUPPORTED TYPE! => KErrNotSupported - aDriveNumber: %c", aDriveNumber + 'A');
       
   445 			User::Leave(KErrNotSupported);
       
   446 			} // switch
       
   447 
       
   448 		__LOG2("CDataOwner::GetExpectedDataSizeL() - END - size is: %d, data owner 0x%08x", aSize, iSecureId.iId);
       
   449 		}
       
   450 
       
   451 
       
   452 	void CDataOwner::GetPublicFileListL(TDriveNumber aDriveNumber, RFileArray& aFiles)
       
   453 	/** Gets the public file list
       
   454 
       
   455 	Gets the public file list for the given drive
       
   456 	@param aDriveNumber the drive to retrieve the public files for
       
   457 	@param aFiles on return a list of public files
       
   458 	*/
       
   459 		{
       
   460 		BuildFileListL(iPublicSelections, aDriveNumber, EPassiveBaseData, ETrue, NULL, &aFiles, NULL);
       
   461 		}
       
   462 		
       
   463 	
       
   464 	void CDataOwner::GetRawPublicFileListL(TDriveNumber aDriveNumber, 
       
   465 										   RRestoreFileFilterArray& aRestoreFileFilter)
       
   466 	/** Gets the raw public file list 
       
   467 	
       
   468 	@param aDriveNumber the drive to return the list for
       
   469 	@param aRestoreFileFilter on return the file filter
       
   470 	*/
       
   471 		{
       
   472 		// Convert drive number to letter
       
   473 		TChar drive;
       
   474 		User::LeaveIfError(ipDataOwnerManager->GetRFs().DriveToChar(aDriveNumber, drive));
       
   475 		
       
   476 		const TUint count = iPublicSelections.Count();
       
   477 		for (TInt x = 0; x < count; x++)
       
   478 			{
       
   479 			TBool include = (iPublicSelections[x]->SelectionType() == EInclude);
       
   480 			TFileName filename;
       
   481 			
       
   482 			const TDesC& selectionName = iPublicSelections[x]->SelectionName();
       
   483 			// Name
       
   484 			TBool add = false;
       
   485 			if ((selectionName.Length() > 1) && (selectionName[1] == KColon()[0]))
       
   486 				{
       
   487 				// It has a drive specified
       
   488 				TInt drive;
       
   489 				ipDataOwnerManager->GetRFs().CharToDrive(selectionName[0], drive);
       
   490 				if (static_cast<TDriveNumber>(drive) == aDriveNumber)
       
   491 					{
       
   492 					add = true;
       
   493 					filename.Append(selectionName);
       
   494 					} // if
       
   495 				} // if
       
   496 			else if (selectionName[0] == KBackSlash()[0])
       
   497 				{
       
   498 					add = true;
       
   499 					filename.Append(drive);
       
   500 					filename.Append(KColon);
       
   501 					filename.Append(selectionName);
       
   502 				} // if
       
   503 			else
       
   504 				{
       
   505 					filename.Append(drive);
       
   506 					filename.Append(KColon);
       
   507 					filename.Append(KBackSlash);
       
   508 					filename.Append(selectionName);
       
   509 				} // else
       
   510 			
       
   511 				if (add)
       
   512 					{
       
   513 					aRestoreFileFilter.AppendL(TRestoreFileFilter(include, filename));
       
   514 					} // if
       
   515 			} // for x
       
   516 		}
       
   517 		
       
   518 	void CDataOwner::ProcessSupplyDataL(TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
       
   519 								 TDesC8& aBuffer, TBool aLastSection)
       
   520 	/** Supply data to the data owner
       
   521 	
       
   522 	@param aDriveNumber the drive requesting data for
       
   523 	@param aTransferType the type of transfer
       
   524 	@param aBuffer the buffer containing the data
       
   525 	@param aLastSection have we received all our information
       
   526 	@leave KErrNotReady In the process of another call
       
   527 	@leave KErrNotSupported Unsupported transfer type
       
   528 	@leave KErrCorrupt If commands have been issued that violate the allowed sequence
       
   529 	*/
       
   530 		{
       
   531 		TBURPartType burType = ipDataOwnerManager->BURType();
       
   532         __LOG2("CDataOwner::ProcessSupplyDataL() - START - drive: %c, aTransferType: %d", aDriveNumber + 'A', aTransferType);
       
   533 		
       
   534 
       
   535 		switch (aTransferType)
       
   536 			{
       
   537 			case EPassiveSnapshotData:
       
   538 				{
       
   539 				__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying passive snapshot data to data owner with SID 0x%08x", iSecureId.iId);
       
   540 				// Check that no passive data has been received for a data owner that doesn't support it
       
   541 				if (!iPassiveInformation.iSupported)
       
   542 					{
       
   543 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Passive restore has been requested but isn't supported");
       
   544 					User::Leave(KErrCorrupt);
       
   545 					}
       
   546 				
       
   547 				// Check that no snapshot is supplied after backup data has been requested during a backup
       
   548 				if (((burType == EBURBackupFull) || (burType == EBURBackupPartial)) && 
       
   549 					(StateByDriveL(aDriveNumber).iPassiveBaseDataRequested || 
       
   550 					 StateByDriveL(aDriveNumber).iPassiveIncDataRequested))
       
   551 					{
       
   552 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Snapshot has been supplied after data has been requested");
       
   553 					User::Leave(KErrCorrupt);
       
   554 					}
       
   555 					
       
   556 				// Check that no snapshot is supplied for a data owner expecting base backup
       
   557 				if (iPassiveInformation.iBaseBackupOnly)
       
   558 					{
       
   559 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Snapshot data has been supplied for a base data owner");
       
   560 					User::Leave(KErrCorrupt);
       
   561 					}
       
   562 					
       
   563 				// Check that no snapshot data is provided after backup data has been supplied during a restore
       
   564 				if (((burType == EBURRestorePartial) || (burType == EBURRestoreFull)) 
       
   565 					&& (StateByDriveL(aDriveNumber).iPassiveBaseDataReceived || 
       
   566 					    StateByDriveL(aDriveNumber).iPassiveIncDataReceived))
       
   567 					{
       
   568 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Snapshot has been supplied after restore data has been supplied");
       
   569 					User::Leave(KErrCorrupt);
       
   570 					}
       
   571   				
       
   572 				SupplyPassiveSnapshotDataL(aDriveNumber, aBuffer, aLastSection);
       
   573 				
       
   574 				if (aLastSection)
       
   575 					{
       
   576 					StateByDriveL(aDriveNumber).iPassiveSnapshotReceived = ETrue;
       
   577 					}
       
   578 				break;
       
   579 				}
       
   580 			case EPassiveBaseData:
       
   581 			case EPassiveIncrementalData:
       
   582 				{
       
   583 				if (aTransferType == EPassiveBaseData)
       
   584 					{
       
   585 					__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying passive base data to data owner with SID 0x%08x", iSecureId.iId);
       
   586 					}
       
   587 				else if (aTransferType == EPassiveIncrementalData)
       
   588 					{
       
   589 					__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying passive inc data to data owner with SID 0x%08x", iSecureId.iId);
       
   590 					}
       
   591 				
       
   592 				// Check that no passive data has been received for a data owner that doesn't support it
       
   593 				if (!iPassiveInformation.iSupported)
       
   594 					{
       
   595 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Passive restore data has been supplied but isn't supported");
       
   596 					User::Leave(KErrCorrupt);
       
   597 					}
       
   598 
       
   599 				// Check that no incremental data has been received for a SID that doesn't support it
       
   600 				if (iPassiveInformation.iBaseBackupOnly && (aTransferType == EPassiveIncrementalData))
       
   601 					{
       
   602 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Incremental restore data has been received for a base only data owner");
       
   603 					User::Leave(KErrCorrupt);
       
   604 					}
       
   605 					
       
   606 				// Passive Base data should only have been provided once for a SID
       
   607 				if ((aTransferType == EPassiveBaseData) && StateByDriveL(aDriveNumber).iPassiveBaseDataReceived)
       
   608 					{
       
   609 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Data is being restored more than once to a DO");
       
   610 					User::Leave(KErrCorrupt);
       
   611 					}
       
   612 				
       
   613 				// A snapshot should already have been supplied if we're incremental
       
   614 				if (!StateByDriveL(aDriveNumber).iPassiveSnapshotReceived && (aTransferType == EPassiveIncrementalData))
       
   615 					{
       
   616 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Snapshot has not yet been supplied and should have whether we're base or inc");
       
   617 					User::Leave(KErrCorrupt);
       
   618 					}
       
   619 				
       
   620 				// If incremental data is being supplied, then base data must already have been supplied
       
   621 				if ((aTransferType == EPassiveIncrementalData) && !StateByDriveL(aDriveNumber).iPassiveBaseDataReceived)
       
   622 					{
       
   623 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Incremental data supplied before base data");
       
   624 					User::Leave(KErrCorrupt);
       
   625 					}
       
   626 				
       
   627 				SupplyPassiveBaseDataL(aDriveNumber, aBuffer, aLastSection);
       
   628 				
       
   629 				if ((aTransferType == EPassiveBaseData) && aLastSection)
       
   630 					{
       
   631 					StateByDriveL(aDriveNumber).iPassiveBaseDataReceived = ETrue;
       
   632 					}
       
   633 				
       
   634 				if ((aTransferType == EPassiveIncrementalData) && aLastSection)
       
   635 					{
       
   636 					StateByDriveL(aDriveNumber).iPassiveIncDataReceived = ETrue;
       
   637 					}
       
   638 				break;
       
   639 				}
       
   640 			case EActiveSnapshotData:
       
   641 				{
       
   642 				__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying active snapshot data to data owner with SID 0x%08x", iSecureId.iId);
       
   643 				
       
   644 				// Check that no active data has been received for a data owner that doesn't support it
       
   645 				if (!iActiveInformation.iSupported)
       
   646 					{
       
   647 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Active snapshot data has been supplied for a DO that doesn't support it");
       
   648 					User::Leave(KErrCorrupt);
       
   649 					}
       
   650 
       
   651 				// Check that no active data has been received for a data owner that doesn't support it
       
   652 				if (!iActiveInformation.iSupportsIncremental)
       
   653 					{
       
   654 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Active snapshot data has been supplied for a base only Data Owner");
       
   655 					User::Leave(KErrCorrupt);
       
   656 					}
       
   657 				
       
   658 				// Check that no snapshot is supplied after backup data has been requested during a backup
       
   659 				if (((burType == EBURBackupFull) || (burType == EBURBackupPartial)) && StateByDriveL(aDriveNumber).iActiveBaseDataRequested)
       
   660 					{
       
   661 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Active snapshot has been supplied after backup data has been requested");
       
   662 					User::Leave(KErrCorrupt);
       
   663 					}
       
   664 					
       
   665 				// Check that no snapshot data is provided after backup data has been supplied during a restore
       
   666 				if (((burType == EBURRestorePartial) || (burType == EBURRestoreFull)) && StateByDriveL(aDriveNumber).iActiveBaseDataReceived)
       
   667 					{
       
   668 					__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Active snapshot data has been supplied after restore data");
       
   669 					User::Leave(KErrCorrupt);
       
   670 					}
       
   671 
       
   672 				ipDataOwnerManager->ABServer().SupplyDataL(iSecureId, aDriveNumber, aTransferType, 
       
   673 					aBuffer, aLastSection);
       
   674 				
       
   675 				if (aLastSection)
       
   676 					{
       
   677 					StateByDriveL(aDriveNumber).iActiveSnapshotReceived = ETrue;
       
   678 					}
       
   679 				} break;
       
   680 			case EActiveBaseData:
       
   681 			case EActiveIncrementalData:
       
   682 				{
       
   683 				if (aTransferType == EActiveBaseData)
       
   684 					{
       
   685 					__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying active base data to data owner with SID 0x%08x", iSecureId.iId);					
       
   686 					}
       
   687 				else if (aTransferType == EActiveIncrementalData)
       
   688 					{
       
   689 					__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying active incremental data to data owner with SID 0x%08x", iSecureId.iId);
       
   690 					}
       
   691 				
       
   692 				const TUint supportedProxyCount = iProxyInformationArray.Count();
       
   693 				TInt offset = 0;
       
   694 				
       
   695 				// Only unpack from the first supply message
       
   696 				if (StateByDriveL(aDriveNumber).iFirstActiveTransaction)
       
   697 					{
       
   698 					iCurrentProxy = 0;
       
   699 					TInt proxyCountCheck = 0;
       
   700 					UnpackTypeAdvance(proxyCountCheck, aBuffer, offset);
       
   701 					StateByDriveL(aDriveNumber).iFirstActiveTransaction = EFalse;
       
   702 					__LOG1("CDataOwner::ProcessSupplyDataL() - Proxy Info : Unpacked TotalProxyCount = %d", proxyCountCheck);
       
   703 
       
   704 					// If the backup stream specifies a different number of proxy's to the registration file,
       
   705 					// then we're looking at different reg file versions. This isn't supported as far as proxy's
       
   706 					// are concerned
       
   707 					if (supportedProxyCount != proxyCountCheck)
       
   708 						{
       
   709 						__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Number of proxies supported (reg file) differs from backed up data");
       
   710 						User::Leave(KErrCorrupt);
       
   711 						}
       
   712 
       
   713 					// Check that no active data has been requested for a data owner that doesn't support it
       
   714 					if ((!iActiveInformation.iSupported) && (supportedProxyCount == 0))
       
   715 						{
       
   716 						// No proxies or active data 
       
   717 						__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Active data has been received but this DO doesn't support Active/Proxies");
       
   718 						User::Leave(KErrCorrupt);
       
   719 						}
       
   720 						
       
   721 					// Reset proxy state information for this drive
       
   722 					for (TInt numProxy=0; numProxy < supportedProxyCount; numProxy++)
       
   723 						{
       
   724 						ProxyStateByDriveL(aDriveNumber,numProxy) = TProxyStateByDrive(aDriveNumber,numProxy);
       
   725 						}
       
   726 					
       
   727 					for (TInt numProxies=0;numProxies<iProxyInformationArray.Count();numProxies++)
       
   728 						{
       
   729 						iProxyInformationArray[numProxies].iDataRequested = 0;
       
   730 						iProxyInformationArray[numProxies].iDataSupplied = 0;
       
   731 						iProxyInformationArray[numProxies].iOpInProgress = ETrue;												
       
   732 						}
       
   733 					}
       
   734 
       
   735 				__LOG1("CDataOwner::ProcessSupplyDataL() - Supplying active base data of size = %D", aBuffer.Length());
       
   736 				
       
   737 				// Restore the proxy data first
       
   738 				TBool currentBufferConsumed = EFalse;  
       
   739 				while ( (iCurrentProxy < supportedProxyCount) && (!currentBufferConsumed))
       
   740 					{
       
   741 					__LOG2("CDataOwner::ProcessSupplyDataL() - Proxy Info : Unpacking proxy info %d of %d", iCurrentProxy + 1, supportedProxyCount);
       
   742 					
       
   743 					// Unpack the proxy's finished flag, len and sid if we are handling the proxy for the first time
       
   744 					if ( iProxyInformationArray[iCurrentProxy].iDataSupplied == 0)
       
   745 						{						
       
   746 						UnpackTypeAdvance(iProxyInformationArray[iCurrentProxy].iOpInProgress, aBuffer, offset);						
       
   747 						__LOG1("CDataOwner::ProcessSupplyDataL() - Proxy Info : FinishedFlag = %d", iProxyInformationArray[iCurrentProxy].iOpInProgress);												
       
   748 						UnpackTypeAdvance(iProxyInformationArray[iCurrentProxy].iDataRequested, aBuffer, offset);						
       
   749 						__LOG1("CDataOwner::ProcessSupplyDataL() - Proxy Info : ProxyDataStreamLength = %d", iProxyInformationArray[iCurrentProxy].iDataRequested);
       
   750 						TSecureId 	proxySecureId;
       
   751 						UnpackTypeAdvance(proxySecureId, aBuffer, offset);
       
   752 						
       
   753 						if ( iProxyInformationArray[iCurrentProxy].iSecureId.iId != proxySecureId.iId )
       
   754 							{
       
   755 							User::Leave(KErrCorrupt);
       
   756 							}
       
   757 							
       
   758 						__LOG1("CDataOwner::ProcessSupplyDataL() - Proxy Info : ProxySID = 0x%08x", proxySecureId.iId);
       
   759 						}
       
   760 		
       
   761 					// Is no more data coming , either from the buffer manager or from the server
       
   762 					TBool proxyFinished = iProxyInformationArray[iCurrentProxy].iOpInProgress && aLastSection;
       
   763 
       
   764 					TInt dataLengthRemaining = iProxyInformationArray[iCurrentProxy].iDataRequested - iProxyInformationArray[iCurrentProxy].iDataSupplied;
       
   765 					
       
   766 					TInt currentBufferLen = 0;
       
   767 					
       
   768 					// The data remaining for this proxy is more than data in this buffer
       
   769 					if (dataLengthRemaining >= aBuffer.Length()-offset )
       
   770 						{
       
   771 						
       
   772 						// more data was expected but both server and data mgr have finished, then leave
       
   773 						if  (proxyFinished && dataLengthRemaining > aBuffer.Length()-offset)
       
   774 							{
       
   775 							User::Leave(KErrCorrupt);
       
   776 							}
       
   777 							
       
   778 						// use the buffer upto the end
       
   779 						currentBufferLen = aBuffer.Length() - offset;
       
   780 						currentBufferConsumed = ETrue;
       
   781 						}
       
   782 					else
       
   783 						{
       
   784 						// use the buffer upto the remaining length of this proxy
       
   785 						currentBufferLen = dataLengthRemaining;
       
   786 						}
       
   787 					
       
   788 					// Create a pointer to the data of this proxy 
       
   789 					TPtrC8 buffer(aBuffer.Mid(offset, currentBufferLen));					
       
   790 					iProxyInformationArray[iCurrentProxy].iDataSupplied +=  currentBufferLen;
       
   791 					__LOG1("CDataOwner::ProcessSupplyDataL() - iProxyConsumedLength = %D",iProxyInformationArray[iCurrentProxy].iDataSupplied);
       
   792 					
       
   793 					offset += currentBufferLen;	
       
   794 
       
   795 					TBool proxyLastSection = EFalse;
       
   796 					
       
   797 					// If the data to send is the last section, set proxyLastSection with true.
       
   798 					if ((iProxyInformationArray[iCurrentProxy].iOpInProgress == (TInt)ETrue) && (iProxyInformationArray[iCurrentProxy].iDataSupplied == iProxyInformationArray[iCurrentProxy].iDataRequested))
       
   799 						{
       
   800 						__LOG("CDataOwner::ProcessSupplyDataL() - Last Section to Proxy");
       
   801 						proxyLastSection = ETrue;
       
   802 						}
       
   803 					else
       
   804 						{
       
   805 						proxyLastSection = proxyFinished;
       
   806 						}
       
   807 
       
   808 					
       
   809 					// Call the proxy and give it the restore data. 
       
   810 					ipDataOwnerManager->ABServer().SupplyDataL(
       
   811 									iProxyInformationArray[iCurrentProxy].iSecureId,
       
   812 									aDriveNumber, 
       
   813 									aTransferType, 
       
   814 									buffer, 
       
   815 									proxyLastSection,
       
   816 									ProxyStateByDriveL(aDriveNumber,iCurrentProxy).iOpInProgress,
       
   817 									iSecureId);
       
   818 					
       
   819 					
       
   820 					// If the proxy still has data to send, record the fact to that the 
       
   821 					// data server or datamanager can supply again.
       
   822 					if (!proxyFinished)
       
   823 						{
       
   824 						__LOG("CDataOwner::ProcessSupplyDataL() - Proxy Info : Multipart send not complete, expecting more proxy data");
       
   825 						ProxyStateByDriveL(aDriveNumber,iCurrentProxy).iOpInProgress = ETrue;							
       
   826 						}
       
   827 					else
       
   828 						{
       
   829 						__LOG("CDataOwner::ProcessSupplyDataL() - Proxy Info : Send complete");
       
   830 						ProxyStateByDriveL(aDriveNumber,iCurrentProxy).iOpInProgress = EFalse;
       
   831 						ProxyStateByDriveL(aDriveNumber,iCurrentProxy).iDataSupplied = ETrue;
       
   832 	
       
   833 						}				
       
   834 					
       
   835 					__LOG2("CDataOwner::ProcessSupplyDataL() - Check proxyConsumedLength = %D & proxyTotalDataLength = %D",iProxyInformationArray[iCurrentProxy].iDataSupplied,iProxyInformationArray[iCurrentProxy].iDataRequested);
       
   836 					if (iProxyInformationArray[iCurrentProxy].iDataSupplied == iProxyInformationArray[iCurrentProxy].iDataRequested)
       
   837 						{
       
   838 						__LOG("CDataOwner::ProcessSupplyDataL() - Resetting internal variables");
       
   839 						// when whole packet from server is read.						
       
   840 						iProxyInformationArray[iCurrentProxy].iDataSupplied = 0;
       
   841 						iProxyInformationArray[iCurrentProxy].iDataRequested = 0;
       
   842 						}
       
   843 					
       
   844 					// Check 
       
   845 					if ( (iProxyInformationArray[iCurrentProxy].iOpInProgress == (TInt)ETrue) && (iProxyInformationArray[iCurrentProxy].iDataSupplied == iProxyInformationArray[iCurrentProxy].iDataRequested) )
       
   846 						{
       
   847 						__LOG("CDataOwner::ProcessSupplyDataL() - Proxy Finished");
       
   848 						iCurrentProxy++;
       
   849 						}
       
   850 						
       
   851 					} // while more proxies.
       
   852 
       
   853 				// Active data can be sent under 2 circumstances, data for a proxy and data for an actual active client				
       
   854 				if (iActiveInformation.iSupported && iActiveInformation.iActiveDataOwner && (offset < aBuffer.Size()))
       
   855 					{
       
   856 					__LOG("CDataOwner::ProcessSupplyDataL() - State iActiveInformation.iSupported");					
       
   857 					// Active Base data should only have been provided once for a SID
       
   858 					if ((aTransferType == EActiveBaseData) && StateByDriveL(aDriveNumber).iActiveBaseDataReceived)
       
   859 						{
       
   860 						__LOG("CDataOwner::ProcessSupplyDataL() - State Error - Active restore data has been provided more than once for this DO");
       
   861 						User::Leave(KErrCorrupt);
       
   862 						}
       
   863 					
       
   864 					TPtrC8 buffer(aBuffer.Mid(offset));
       
   865 
       
   866 					ipDataOwnerManager->ABServer().SupplyDataL(
       
   867 								iSecureId,
       
   868 								aDriveNumber,
       
   869 								aTransferType,
       
   870 								buffer,
       
   871 								aLastSection,
       
   872 								StateByDriveL(aDriveNumber).iOpInProgress);
       
   873 					
       
   874 					if (!aLastSection)
       
   875 						{
       
   876 						StateByDriveL(aDriveNumber).iOpInProgress = ETrue;
       
   877 						}
       
   878 					else 
       
   879 						{
       
   880 						StateByDriveL(aDriveNumber).iOpInProgress = EFalse;
       
   881 						StateByDriveL(aDriveNumber).iFirstActiveTransaction = ETrue;
       
   882 						if (aTransferType == EActiveBaseData)
       
   883 							{
       
   884 							StateByDriveL(aDriveNumber).iActiveBaseDataReceived = ETrue;
       
   885 							}
       
   886 						
       
   887 						if (aTransferType == EActiveIncrementalData)
       
   888 							{
       
   889 							StateByDriveL(aDriveNumber).iActiveIncDataReceived = ETrue;
       
   890 							}
       
   891 						}
       
   892 					}
       
   893 				} break;
       
   894 			default:
       
   895 				{
       
   896 				__LOG("CDataOwner::ProcessSupplyDataL() - State Error - An unsupported transfer type has been supplied");
       
   897 				User::Leave(KErrNotSupported);
       
   898 				}
       
   899 			} // switch
       
   900 		}
       
   901 		
       
   902 	void CDataOwner::SupplyDataL(TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
       
   903 								 TDesC8& aBuffer, TBool aLastSection)
       
   904 	/** Supply data to the data owner
       
   905 	
       
   906 	@param aDriveNumber the drive requesting data for
       
   907 	@param aTransferType the type of transfer
       
   908 	@param aBuffer the buffer containing the data
       
   909 	@param aLastSection have we received all our information
       
   910 	@leave KErrNotReady In the process of another call
       
   911 	@leave KErrNotSupported Unsupported transfer type
       
   912 	@leave KErrCorrupt If commands have been issued that violate the allowed sequence
       
   913 	*/
       
   914 		{
       
   915 		__LOG5("CDataOwner::SupplyDataL() - START - SID: 0x%08x, aDrive: %c, aTransferType: %d, aLastSection: %d, iState: %d", iSecureId.iId, aDriveNumber + 'A', aTransferType, aLastSection, iState.iState);
       
   916 		// Check our state
       
   917 		if (!((iState.iState == ENone) ||
       
   918 		     ((iState.iState == ESupply) && (iState.iDriveNumber == aDriveNumber) && 
       
   919 		      (iState.iTransferType == aTransferType))))
       
   920 			{
       
   921 			User::Leave(KErrNotReady);			
       
   922 			}
       
   923 			
       
   924 		// Set the state?
       
   925 		if (iState.iState == ENone)
       
   926 			{
       
   927 			iState.iState = ESupply;
       
   928 			iState.iDriveNumber = aDriveNumber;
       
   929 			iState.iTransferType = aTransferType;
       
   930 			} // if
       
   931 			
       
   932 		// What are we doing then?
       
   933 		// We must trap any errors and rethrow them so we can reset our state
       
   934 		TInt err = KErrNone;
       
   935 		
       
   936 		// Do we need to perform a cleanup before restore?
       
   937 		if ((aTransferType == EPassiveBaseData) ||
       
   938 		    (aTransferType == EPassiveIncrementalData) ||
       
   939 		    (aTransferType == EActiveBaseData) ||
       
   940 		    (aTransferType == EActiveIncrementalData))
       
   941 			{
       
   942 			TRAP(err, CleanupBeforeRestoreL(aDriveNumber));
       
   943 			}
       
   944 		if (err != KErrNone)
       
   945 			{
       
   946 			__LOG2("CDataOwner::SupplyDataL() - Data owner 0x%08x, drive %d could not cleanup before restore", iSecureId.iId, aDriveNumber);
       
   947 			}
       
   948 
       
   949 		TRAP(err, ProcessSupplyDataL(aDriveNumber, aTransferType, aBuffer, aLastSection));
       
   950 
       
   951 		
       
   952 		// Was there an error?
       
   953 		if (err != KErrNone)
       
   954 			{
       
   955 			iState.iState = ENone;
       
   956 			delete iBufferFileReader;
       
   957 			iBufferFileReader = NULL;
       
   958 			delete iBufferSnapshotReader;
       
   959 			iBufferSnapshotReader = NULL;
       
   960 			User::Leave(err);
       
   961 			} // if
       
   962 			     
       
   963 		if (aLastSection) // If last section reset state
       
   964 			{
       
   965 			iState.iState = ENone;
       
   966 			} // if
       
   967 		__LOG("CDataOwner::SupplyDataL() - END");
       
   968 		} // SupplyDataL
       
   969 		
       
   970 		
       
   971 	void CDataOwner::ProcessRequestDataL(TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
       
   972     		TPtr8& aBuffer, TBool& aLastSection)
       
   973     /**
       
   974     So that the TRAPD isn't massive, this switch statement has been moved to this function
       
   975     */
       
   976 		{
       
   977         __LOG4("CDataOwner::ProcessRequestDataL() - START - aDrive: %c, aTransferType: %d, aBuffer.Ptr(): 0x%08x, aBuffer.Length(): %d", aDriveNumber + 'A', aTransferType, aBuffer.Ptr(), aBuffer.Length());
       
   978         //__LOGDATA("CDataOwner::ProcessRequestDataL() - %S", aBuffer.Ptr(), aBuffer.Length() );
       
   979 
       
   980         //
       
   981 		switch (aTransferType)
       
   982 			{
       
   983 			case EPassiveSnapshotData:
       
   984 				{
       
   985 				__LOG1("CDataOwner::ProcessRequestDataL() - Requesting passive snapshot data from data owner with SID 0x%08x", iSecureId.iId);
       
   986 
       
   987 				// Check that no passive data has been requested for a data owner that doesn't support it
       
   988 				if (!iPassiveInformation.iSupported)
       
   989 					{
       
   990 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Passive snapshot data has been requested for a non-passive data owner");
       
   991 					User::Leave(KErrCorrupt);
       
   992 					}
       
   993 					
       
   994 				// Check that snapshot data is only requested once
       
   995 				if (StateByDriveL(aDriveNumber).iPassiveSnapshotRequested)
       
   996 					{
       
   997 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Passive snapshot data has been requested more than once");
       
   998 					User::Leave(KErrCorrupt);
       
   999 					}
       
  1000 
       
  1001 				RequestPassiveSnapshotDataL(aDriveNumber, aBuffer, aLastSection);
       
  1002 				
       
  1003 				if (aLastSection)
       
  1004 					{
       
  1005 					StateByDriveL(aDriveNumber).iPassiveSnapshotRequested = ETrue;
       
  1006 					}
       
  1007 				break;
       
  1008 				}
       
  1009 			case EPassiveBaseData:
       
  1010 			case EPassiveIncrementalData:
       
  1011 				{
       
  1012 				if (aTransferType == EPassiveBaseData)
       
  1013 					{
       
  1014 					__LOG1("CDataOwner::ProcessRequestDataL() - Requesting passive base data from data owner with SID 0x%08x", iSecureId.iId);
       
  1015 					}
       
  1016 				else if (aTransferType == EPassiveIncrementalData)
       
  1017 					{
       
  1018 					__LOG1("CDataOwner::ProcessRequestDataL() - Requesting passive inc data from data owner with SID 0x%08x", iSecureId.iId);
       
  1019 					}
       
  1020 
       
  1021 				// Check that no passive data has been requested for a data owner that doesn't support it
       
  1022 				if (!iPassiveInformation.iSupported)
       
  1023 					{
       
  1024 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Passive backup data has been requested for a non-passive data owner");
       
  1025 					User::Leave(KErrCorrupt);
       
  1026 					}
       
  1027 
       
  1028 				// Check that if this is an incremental backup, complete snapshot data has been received
       
  1029 				if ((aTransferType == EPassiveIncrementalData) && !StateByDriveL(aDriveNumber).iPassiveSnapshotReceived)
       
  1030 					{
       
  1031 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Incremental data has been requested without a snapshot being supplied");
       
  1032 					User::Leave(KErrCorrupt);
       
  1033 					}
       
  1034 				
       
  1035 				// Check that Passive data has only been requested once for a Data Owner
       
  1036 				if (((aTransferType == EPassiveBaseData) && StateByDriveL(aDriveNumber).iPassiveBaseDataRequested) ||
       
  1037 					((aTransferType == EPassiveIncrementalData) && StateByDriveL(aDriveNumber).iPassiveIncDataRequested))
       
  1038 					{
       
  1039 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Passive data has been requested more than once for this data owner");
       
  1040 					User::Leave(KErrCorrupt);
       
  1041 					}
       
  1042 				
       
  1043 				// Check that for base backup, no snapshot data has been supplied
       
  1044 				if ((aTransferType == EPassiveBaseData) && StateByDriveL(aDriveNumber).iPassiveSnapshotReceived)
       
  1045 					{
       
  1046 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Snapshot data has been received for a base only data owner");
       
  1047 					User::Leave(KErrCorrupt);
       
  1048 					}
       
  1049 				
       
  1050 				// Check that only Base OR Incremental data is requested - not both
       
  1051 				if (((aTransferType == EPassiveBaseData) && StateByDriveL(aDriveNumber).iPassiveIncDataRequested) || 
       
  1052 					((aTransferType == EPassiveIncrementalData) && StateByDriveL(aDriveNumber).iPassiveBaseDataRequested))
       
  1053 					{
       
  1054 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Base and Incremental data have been requested in the same session");
       
  1055 					User::Leave(KErrCorrupt);
       
  1056 					}
       
  1057 				
       
  1058 				RequestPassiveDataL(aTransferType, aDriveNumber, aBuffer, aLastSection);
       
  1059 				
       
  1060 				if ((aTransferType == EPassiveBaseData) && aLastSection)
       
  1061 					{
       
  1062 					StateByDriveL(aDriveNumber).iPassiveBaseDataRequested = ETrue;
       
  1063 					}
       
  1064 				
       
  1065 				if ((aTransferType == EPassiveIncrementalData) && aLastSection)
       
  1066 					{
       
  1067 					StateByDriveL(aDriveNumber).iPassiveIncDataRequested = ETrue;
       
  1068 					}
       
  1069 				break;
       
  1070 				}
       
  1071 			case EActiveSnapshotData:
       
  1072 				{
       
  1073 				__LOG1("CDataOwner::ProcessRequestDataL() - Requesting active snapshot data from data owner with SID 0x%08x", iSecureId.iId);
       
  1074 
       
  1075 				// Check that active data hasn't been requested for a data owner that doesn't support it
       
  1076 				if (!iActiveInformation.iSupported)
       
  1077 					{
       
  1078 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Active snapshot data has been requested from a non-active data owner");
       
  1079 					User::Leave(KErrCorrupt);
       
  1080 					}
       
  1081 
       
  1082 				// Check that no active snapshot data has been requested for a base only active data owner
       
  1083 				if (!iActiveInformation.iSupportsIncremental)
       
  1084 					{
       
  1085 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Active snapshot data has been requested from a base only data owner");
       
  1086 					User::Leave(KErrCorrupt);
       
  1087 					}
       
  1088 
       
  1089 				// Check that the Active client has prepared it's data and is ready
       
  1090 				if (iStatus != EDataOwnerReady)
       
  1091 					{
       
  1092 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Active Snapshot data has been requested from a data owner that isn't ready");
       
  1093 					User::Leave(KErrNotReady);
       
  1094 					}
       
  1095 					
       
  1096 				// Check that snapshot data is only requested once
       
  1097 				if (StateByDriveL(aDriveNumber).iActiveSnapshotRequested)
       
  1098 					{
       
  1099 					__LOG("CDataOwner::ProcessRequestDataL() - State Error - Active Snapshot data has been requested more than once");
       
  1100 					User::Leave(KErrCorrupt);
       
  1101 					}
       
  1102 					
       
  1103 				// Request the snapshot data from the abclient
       
  1104 				ipDataOwnerManager->ABServer().RequestDataL(iSecureId, aDriveNumber, aTransferType, 
       
  1105 					aBuffer, aLastSection);
       
  1106 				
       
  1107 				if (aLastSection)
       
  1108 					{
       
  1109 					StateByDriveL(aDriveNumber).iActiveSnapshotRequested = ETrue;
       
  1110 					}
       
  1111 				} break;
       
  1112 			case EActiveBaseData:
       
  1113 			case EActiveIncrementalData:
       
  1114 				{
       
  1115 				if (aTransferType == EActiveBaseData)
       
  1116 					{
       
  1117 					__LOG1("CDataOwner::ProcessRequestDataL() - Requesting active base data from data owner with SID 0x%08x", iSecureId.iId);
       
  1118 					}
       
  1119 				else if (aTransferType == EActiveIncrementalData)
       
  1120 					{
       
  1121 					__LOG1("CDataOwner::ProcessRequestDataL() - Requesting active inc data from data owner with SID 0x%08x", iSecureId.iId);
       
  1122 					}
       
  1123 
       
  1124 				TInt supportedProxyCount = iProxyInformationArray.Count();
       
  1125 				TInt offset = 0;
       
  1126 
       
  1127 				// Prepend the number of proxies into the data stream
       
  1128 				if (StateByDriveL(aDriveNumber).iFirstActiveTransaction)
       
  1129 					{
       
  1130 					// Check that no active data has been requested for a data owner that doesn't support it
       
  1131 					if ((!iActiveInformation.iSupported) && (supportedProxyCount == 0))
       
  1132 						{
       
  1133 						// No proxies or active data 
       
  1134 						__LOG("CDataOwner::ProcessRequestDataL() - State Error - Active data has been requested from a non-active/no proxy data owner");
       
  1135 						User::Leave(KErrCorrupt);
       
  1136 						}
       
  1137 					
       
  1138 					StateByDriveL(aDriveNumber).iFirstActiveTransaction = EFalse;
       
  1139 					
       
  1140 					PackTypeAdvance(supportedProxyCount, aBuffer, offset);
       
  1141 					__LOG1("CDataOwner::ProcessRequestDataL() - Proxy Info : Packing TotalProxyCount = %d", supportedProxyCount);
       
  1142 
       
  1143 					aBuffer.SetLength(offset);
       
  1144 			        //__LOGDATA( "CDataOwner::ProcessRequestDataL() - after adding proxy info - %S", aBuffer.Ptr(), aBuffer.Length() );
       
  1145 					
       
  1146 					// Reset proxy state information for this drive
       
  1147 					for (TInt numProxy=0; numProxy < supportedProxyCount; numProxy++)
       
  1148 						{
       
  1149 						ProxyStateByDriveL(aDriveNumber,numProxy) = TProxyStateByDrive(aDriveNumber,numProxy);
       
  1150 						}
       
  1151 					}
       
  1152 					
       
  1153 				// Proxy data is always at the beginning of the data block
       
  1154 				for (TInt index = 0; index < supportedProxyCount; index++)
       
  1155 					{
       
  1156 					__LOG2("CDataOwner::ProcessRequestDataL() - Proxy Info : Packing proxy info %d of %d", index + 1, supportedProxyCount);
       
  1157 
       
  1158 					// Request data from each of the data owners that haven't yet been added
       
  1159 					// If the buffer's overflowed, then let the PC request again
       
  1160 					if (!ProxyStateByDriveL(aDriveNumber,index).iDataRequested && aLastSection)
       
  1161 						{
       
  1162 						if (static_cast<TUint>(aBuffer.MaxSize() - aBuffer.Size()) > (sizeof(TBool) + sizeof(TInt32) + sizeof(TSecureId)))
       
  1163 							{
       
  1164 							// Pack protocol into active stream [Proxy data length][Proxy SID][Proxy Data]
       
  1165 							// Set the descriptor to be maximum length and use the offset to determine where we're up to
       
  1166 							aBuffer.SetMax();
       
  1167 							
       
  1168 							// buffer for proxy data finished flag
       
  1169 							TPtr8 finishedBuf(aBuffer.MidTPtr(offset, sizeof(TBool)));
       
  1170 							offset += sizeof(TBool);
       
  1171 							
       
  1172 							// buffer for length
       
  1173 							TPtr8 lengthBuf(aBuffer.MidTPtr(offset, sizeof(TInt32)));
       
  1174 							offset += sizeof(TInt32);
       
  1175 							
       
  1176 							// buffer for the sid 
       
  1177 							TPtr8 sidBuf(aBuffer.MidTPtr(offset, sizeof(TSecureId)));
       
  1178 							offset += sizeof(TSecureId);
       
  1179 							
       
  1180 							// Create a buffer for the data
       
  1181 							TPtr8 buffer(aBuffer.MidTPtr(offset));
       
  1182 							
       
  1183 							// Call the proxy
       
  1184 							ipDataOwnerManager->ABServer().RequestDataL(
       
  1185 											iProxyInformationArray[index].iSecureId,
       
  1186 											aDriveNumber, 
       
  1187 											aTransferType, 
       
  1188 											buffer, 
       
  1189 											aLastSection, 
       
  1190 											ProxyStateByDriveL(aDriveNumber,index).iOpInProgress,
       
  1191 											iSecureId);
       
  1192 											
       
  1193 							TInt size = buffer.Size();
       
  1194 
       
  1195 							// Write the proxy protocol block to the active backup data stream
       
  1196 							PackType(aLastSection, finishedBuf, 0);
       
  1197 							__LOG1("CDataOwner::ProcessRequestDataL() - Proxy Info : FinishedFlag = %d", aLastSection);
       
  1198 							
       
  1199 							PackType(size, lengthBuf, 0);
       
  1200 							__LOG1("CDataOwner::ProcessRequestDataL() - Proxy Info : ProxyStreamSize= %d", size);
       
  1201 
       
  1202 							PackType(iProxyInformationArray[index].iSecureId, sidBuf, 0);
       
  1203 							__LOG1("CDataOwner::ProcessRequestDataL() - Proxy Info : ProxySID = 0x%08x", iProxyInformationArray[index].iSecureId.iId);
       
  1204 							
       
  1205 							// Update the offset and main buffer size
       
  1206 							offset += size;
       
  1207 							aBuffer.SetLength(offset);
       
  1208 							
       
  1209 							// If the proxy still has data to send, record the fact to that the PC can request again
       
  1210 							if (!aLastSection)
       
  1211 								{
       
  1212 								ProxyStateByDriveL(aDriveNumber,index).iOpInProgress = ETrue;
       
  1213 								}
       
  1214 							else
       
  1215 								{
       
  1216 								ProxyStateByDriveL(aDriveNumber,index).iOpInProgress = EFalse;
       
  1217 								ProxyStateByDriveL(aDriveNumber,index).iDataRequested = ETrue;
       
  1218 								}
       
  1219 							}
       
  1220 						else
       
  1221 							{
       
  1222 							// If there's not enough room for the protocol info, then set the last section flag
       
  1223 							aLastSection = EFalse;
       
  1224 							}
       
  1225 						}
       
  1226 					}
       
  1227 
       
  1228 				if (iActiveInformation.iSupported && iActiveInformation.iActiveDataOwner && (aBuffer.Size() < aBuffer.MaxLength()))
       
  1229 					{
       
  1230 					// Check that if this is a base backup, no snapshot has been provided
       
  1231 					if ((aTransferType == EActiveBaseData) && StateByDriveL(aDriveNumber).iActiveSnapshotReceived)
       
  1232 						{
       
  1233 						__LOG("CDataOwner::ProcessRequestDataL() - State Error - A snapshot has been provided before a request for base data");
       
  1234 						User::Leave(KErrCorrupt);
       
  1235 						}
       
  1236 					
       
  1237 					// Check that if this is an incremental backup that at least one complete snapshot has been sent
       
  1238 					if ((aTransferType == EActiveIncrementalData) && !StateByDriveL(aDriveNumber).iActiveSnapshotReceived)
       
  1239 						{
       
  1240 						__LOG("CDataOwner::ProcessRequestDataL() - State Error - No snapshot has been supplied, yet incremental data has been requested");
       
  1241 						User::Leave(KErrCorrupt);
       
  1242 						}
       
  1243 					
       
  1244 					// Check that only one (possibly multi-part) request of actual data is made to an active backup client
       
  1245 					if (((aTransferType == EActiveBaseData) && StateByDriveL(aDriveNumber).iActiveBaseDataRequested) || 
       
  1246 						((aTransferType == EActiveIncrementalData) && StateByDriveL(aDriveNumber).iActiveIncDataRequested))
       
  1247 						{
       
  1248 						__LOG("CDataOwner::ProcessRequestDataL() - State Error - Active data has been requested more than once (not counting multi-part)");
       
  1249 						User::Leave(KErrCorrupt);
       
  1250 						}
       
  1251 						
       
  1252 					// Check that only Base OR Incremental data is requested - not both
       
  1253 					if (((aTransferType == EActiveBaseData) && StateByDriveL(aDriveNumber).iActiveIncDataRequested) || 
       
  1254 						((aTransferType == EActiveIncrementalData) && StateByDriveL(aDriveNumber).iActiveBaseDataRequested))
       
  1255 						{
       
  1256 						__LOG("CDataOwner::ProcessRequestDataL() - State Error - Only active base or incremental data can be requested in the same session");
       
  1257 						User::Leave(KErrCorrupt);
       
  1258 						}
       
  1259 
       
  1260 					// Create a buffer pointer allowing the client to fill the remainder of the buffer
       
  1261 					TInt currentBufferLength = aBuffer.Size();
       
  1262 					aBuffer.SetMax();
       
  1263 					
       
  1264 					TPtr8 buffer(aBuffer.MidTPtr(currentBufferLength));
       
  1265 					
       
  1266 					// Request data from the abclient
       
  1267 					ipDataOwnerManager->ABServer().RequestDataL(
       
  1268 									iSecureId,
       
  1269 									aDriveNumber,
       
  1270 									aTransferType, 
       
  1271 									buffer,
       
  1272 									aLastSection,
       
  1273 									StateByDriveL(aDriveNumber).iOpInProgress);
       
  1274 
       
  1275 					aBuffer.SetLength(currentBufferLength + buffer.Size());
       
  1276 
       
  1277 					// If the active data owner still has data to send, record the fact to that the PC can request again
       
  1278 					if (!aLastSection)
       
  1279 						{
       
  1280 						StateByDriveL(aDriveNumber).iOpInProgress = ETrue;
       
  1281 						}
       
  1282 					else 
       
  1283 						{
       
  1284 						StateByDriveL(aDriveNumber).iOpInProgress = EFalse;
       
  1285 						StateByDriveL(aDriveNumber).iFirstActiveTransaction = ETrue;
       
  1286 						if (aTransferType == EActiveBaseData)
       
  1287 							{
       
  1288 							StateByDriveL(aDriveNumber).iActiveBaseDataRequested = ETrue;
       
  1289 							}
       
  1290 						
       
  1291 						if (aTransferType == EActiveIncrementalData)
       
  1292 							{
       
  1293 							StateByDriveL(aDriveNumber).iActiveIncDataRequested = ETrue;
       
  1294 							}
       
  1295 						}
       
  1296 					}	// Active data owner
       
  1297 				} break;
       
  1298 			default:
       
  1299 				{
       
  1300 				User::Leave(KErrNotSupported);
       
  1301 				}
       
  1302 			} // switch
       
  1303 
       
  1304         __LOG2("CDataOwner::ProcessRequestDataL() - NEAR END - aBuffer.Ptr(): 0x%08x, aBuffer.Length(): %d", aBuffer.Ptr(), aBuffer.Length());
       
  1305         //__LOGDATA( "CDataOwner::ProcessRequestDataL() - %S", aBuffer.Ptr(), aBuffer.Length() );
       
  1306         __LOG("CDataOwner::ProcessRequestDataL() - END");
       
  1307 		}
       
  1308 		
       
  1309     void CDataOwner::RequestDataL(TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
       
  1310     				  			  TPtr8& aBuffer, TBool& aLastSection)
       
  1311     	{
       
  1312     	aLastSection = ETrue;		// Set the last section to be true by default
       
  1313     	
       
  1314 		// Check our state
       
  1315 		if (!((iState.iState == ENone) ||
       
  1316 		     ((iState.iState == ERequest) && (iState.iDriveNumber == aDriveNumber) && 
       
  1317 		      (iState.iTransferType == aTransferType))))
       
  1318 			{
       
  1319 			User::Leave(KErrNotReady);			
       
  1320 			}
       
  1321 			
       
  1322 		// Set the state?
       
  1323 		if (iState.iState == ENone)
       
  1324 			{
       
  1325 			iState.iState = ERequest;
       
  1326 			iState.iDriveNumber = aDriveNumber;
       
  1327 			iState.iTransferType = aTransferType;
       
  1328 			}
       
  1329 			
       
  1330 		// What are we doing then?
       
  1331 		// We must trap any errors and rethrow them so we can reset our state
       
  1332 		TRAPD(err, ProcessRequestDataL(aDriveNumber, aTransferType, aBuffer, aLastSection));
       
  1333 		
       
  1334 		if (err != KErrNone)
       
  1335 			{
       
  1336 			__LOG4("CDataOwner::RequestDataL() - drive: %c:, aTransferType: %d, secureId: 0x%08x - ERROR: %d", 'a' + aDriveNumber, aTransferType, iSecureId.iId, err);
       
  1337 			iState.iState = ENone;
       
  1338 			delete iBufferFileWriter;
       
  1339 			iBufferFileWriter = NULL;
       
  1340 			delete iBufferSnapshotWriter;
       
  1341 			iBufferSnapshotWriter = NULL;
       
  1342 			User::Leave(err);
       
  1343 			} // if
       
  1344 		
       
  1345 		if (aLastSection) // If last section reset state
       
  1346 			{
       
  1347 			iState.iState = ENone;
       
  1348 			} // if
       
  1349     	} // RequestDataL
       
  1350     	
       
  1351     void CDataOwner::RestoreCompleteL()
       
  1352     /** Indicate to the active client that the restore operation has been completed
       
  1353     */
       
  1354     	{
       
  1355     	// Find all of the drives that this data owner could have stored data on
       
  1356     	TDriveList driveList;
       
  1357     	GetDriveListL(driveList);
       
  1358     	
       
  1359     	for (TInt driveCountIndex = 0; driveCountIndex < KMaxDrives; driveCountIndex++)
       
  1360     		{
       
  1361     		if (driveList[driveCountIndex])
       
  1362     			{
       
  1363     			// If the particular drive is supported, then indicate that the restore is complete
       
  1364     			ipDataOwnerManager->ABServer().RestoreCompleteL(iSecureId, static_cast<TDriveNumber>(driveCountIndex));
       
  1365     			}
       
  1366     		}
       
  1367     	}
       
  1368 
       
  1369 
       
  1370 	TSecureId CDataOwner::SecureId() const
       
  1371 	/** Get the secure id of the data owner
       
  1372 
       
  1373 	@return the secure id of the data owner
       
  1374 	*/
       
  1375 		{
       
  1376 		return iSecureId;
       
  1377 		}
       
  1378 		
       
  1379 	TDataOwnerStatus CDataOwner::ReadyState()
       
  1380 	/** Gets the ready state of the data owner
       
  1381 	
       
  1382 	@return The ready state
       
  1383 	*/
       
  1384 		{
       
  1385 		TDataOwnerStatus status = EDataOwnerReady;
       
  1386 		TInt proxyIndex = 0;
       
  1387 		const TUint proxyCount = iProxyInformationArray.Count();
       
  1388 		CDataOwner* pProxyDataOwner = NULL; // TRAPD forces us to use a pointer instead of ref
       
  1389 		
       
  1390 		while ((proxyIndex < proxyCount) && (status == EDataOwnerReady || status == EDataOwnerReadyNoImpl))
       
  1391 			{
       
  1392 			// For each proxy required, query for ready state
       
  1393 			TRAPD(err, pProxyDataOwner = &(ipDataOwnerManager->DataOwnerL(
       
  1394 				iProxyInformationArray[proxyIndex].iSecureId)));
       
  1395 
       
  1396 			// If the proxy data owner doesn't exist - then error
       
  1397 			if (err == KErrNotFound)
       
  1398 				{
       
  1399 				status = EDataOwnerNotFound;
       
  1400 				}
       
  1401 			else
       
  1402 				{
       
  1403 				if (pProxyDataOwner->ActiveInformation().iActiveType != EActiveOnly)
       
  1404 					{
       
  1405 					// Get the status from each of the supported proxies
       
  1406 					status = pProxyDataOwner->ReadyState();
       
  1407 					proxyIndex++;					
       
  1408 					}
       
  1409 				else
       
  1410 					{
       
  1411 					status = EDataOwnerFailed;
       
  1412 					break;
       
  1413 					}
       
  1414 
       
  1415 				}
       
  1416 			}
       
  1417 
       
  1418 		
       
  1419 		// If this data owner has only proxy data to backup, then echo the state of the proxies
       
  1420 		if ((proxyCount > 0) && !iActiveInformation.iActiveDataOwner) // is passive
       
  1421 			{
       
  1422 			if (status == EDataOwnerReadyNoImpl) // proxy (eg.cent rep) is ready
       
  1423 				{
       
  1424 				iStatus = EDataOwnerReady;
       
  1425 				}
       
  1426 			else
       
  1427 				{
       
  1428 				iStatus = status;
       
  1429 				}
       
  1430 			}
       
  1431 			
       
  1432 		if ((iActiveInformation.iActiveDataOwner) && (iStatus != EDataOwnerReady) && (iStatus != EDataOwnerReadyNoImpl))
       
  1433 			{
       
  1434 			TRAPD(err, iStatus = ipDataOwnerManager->ABServer().SessionReadyStateL(iSecureId));
       
  1435 			if (err != KErrNone)
       
  1436 				{
       
  1437 				iStatus = EDataOwnerNotConnected;
       
  1438 				}
       
  1439 			}
       
  1440 
       
  1441 		// If all of the proxies are ok, then set the status to be that of this data owner
       
  1442 		if (status == EDataOwnerReady || status == EDataOwnerReadyNoImpl)
       
  1443 			{
       
  1444 			status = iStatus;
       
  1445 			}
       
  1446 		
       
  1447 		
       
  1448 		__LOG2("CDataOwner::ReadyState() - Ready status for data owner 0x%08x is %d", iSecureId.iId, static_cast<TInt>(status));
       
  1449 			
       
  1450 		return status;
       
  1451 		}
       
  1452 		
       
  1453 	void CDataOwner::SetReadyState(TDataOwnerStatus aDataOwnerStatus)
       
  1454 	/**
       
  1455 	Set upon a ConfirmReadyForBUR IPC call from an active backup client
       
  1456 	*/
       
  1457 		{
       
  1458 		__LOG2("CDataOwner::SetReadyState() - Setting ready state of data owner 0x%08x to %d", iSecureId.iId, static_cast<TInt>(aDataOwnerStatus));
       
  1459 		iStatus = aDataOwnerStatus;
       
  1460 		if (aDataOwnerStatus == EDataOwnerReady && iActiveInformation.iActiveType == EProxyImpOnly)
       
  1461 			{
       
  1462 			iStatus = EDataOwnerReadyNoImpl;
       
  1463 			}
       
  1464 		}
       
  1465 
       
  1466 	TCommonBURSettings CDataOwner::CommonSettingsL()
       
  1467 	/** Get the common settings of the data owner
       
  1468 
       
  1469 	@pre CDataOwner::ParseFilesL() must have been called
       
  1470 	@return the common settings of the data owner
       
  1471 	@leave KErrNotReady if CDataOwner::ParseFilesL() not called
       
  1472 	*/
       
  1473 		{
       
  1474 		__LOG2("CDataOwner::CommonSettingsL() - START - sid: 0x%08x, iFilesParsed: %d", iSecureId.iId, iFilesParsed);
       
  1475 		if (!iFilesParsed)
       
  1476 			{
       
  1477 			User::Leave(KErrNotReady);
       
  1478 			}
       
  1479 			
       
  1480 		__LOG2("CDataOwner::CommonSettingsL() - Active Supported: %d, proxyCount: %d", iActiveInformation.iSupported, iProxyInformationArray.Count());
       
  1481 		TCommonBURSettings settings = ENoOptions;
       
  1482 		if (iActiveInformation.iSupported || iProxyInformationArray.Count())
       
  1483 			{
       
  1484 			settings |= EActiveBUR;
       
  1485 			} // if
       
  1486 
       
  1487 		__LOG1("CDataOwner::CommonSettingsL() - Passive Supported: %d", iPassiveInformation.iSupported);
       
  1488 		if (iPassiveInformation.iSupported)
       
  1489 			{
       
  1490 			settings |= EPassiveBUR;
       
  1491 			}
       
  1492 
       
  1493 		__LOG1("CDataOwner::CommonSettingsL() - System Supported: %d", iSystemInformation.iSupported);
       
  1494 		if (iSystemInformation.iSupported)
       
  1495 			{
       
  1496 			settings |= EHasSystemFiles;
       
  1497 			}
       
  1498 
       
  1499 		__LOG2("CDataOwner::CommonSettingsL() - SelActive: %d, SelPassive: %d", iActiveInformation.iSupportsSelective, iPassiveInformation.iSupportsSelective);
       
  1500 		if (iActiveInformation.iSupportsSelective && iPassiveInformation.iSupportsSelective)
       
  1501 			{
       
  1502 			settings |= ESupportsSelective;
       
  1503 			}
       
  1504 
       
  1505 		__LOG1("CDataOwner::CommonSettingsL() - Reboot required: %d", iRestoreInformation.iRequiresReboot);
       
  1506 		if (iRestoreInformation.iRequiresReboot)
       
  1507 			{
       
  1508 			settings |= ERequiresReboot;
       
  1509 			}
       
  1510 
       
  1511 		__LOG("CDataOwner::CommonSettingsL() - END");
       
  1512 		return settings;
       
  1513 		}
       
  1514 
       
  1515 	TPassiveBURSettings CDataOwner::PassiveSettingsL()
       
  1516 	/** Get the passive settings of the data owner
       
  1517 
       
  1518 	@pre CDataOwner::ParseFilesL() must have been called
       
  1519 	@return the passive settings of the data owner
       
  1520 	@leave KErrNotReady if CDataOwner::ParseFilesL() not called
       
  1521 	*/
       
  1522 		{
       
  1523 		if (!iFilesParsed)
       
  1524 			{
       
  1525 			User::Leave(KErrNotReady);
       
  1526 			}
       
  1527 		
       
  1528 		TPassiveBURSettings settings = ENoPassiveOptions;
       
  1529 		if (iPassiveInformation.iSupported)
       
  1530 			{
       
  1531 			if (iPassiveInformation.iDeleteBeforeRestore)
       
  1532 				{
       
  1533 				settings |= EDeleteBeforeRestore;
       
  1534 				} // if
       
  1535 			if (!iPassiveInformation.iBaseBackupOnly)
       
  1536 				{
       
  1537 				settings |= EPassiveSupportsInc;
       
  1538 				} // if
       
  1539 			} // if
       
  1540 		if (iPublicInformation.iSupported)
       
  1541 			{
       
  1542 			settings |= EHasPublicFiles;
       
  1543 			} // if
       
  1544 			
       
  1545 			
       
  1546 		return settings;
       
  1547 		}
       
  1548 
       
  1549 	TActiveBURSettings CDataOwner::ActiveSettingsL()
       
  1550 	/** Get the active settings of the data owner
       
  1551 
       
  1552 	@pre CDataOwner::ParseFilesL() must have been called
       
  1553 	@return the active settings of the data owner
       
  1554 	@leave KErrNotReady if CDataOwner::ParseFilesL() not called
       
  1555 	*/
       
  1556 		{
       
  1557 		if (!iFilesParsed)
       
  1558 			{
       
  1559 			User::Leave(KErrNotReady);
       
  1560 			}
       
  1561 			
       
  1562 		TActiveBURSettings settings = ENoActiveOptions;
       
  1563 		if (iActiveInformation.iSupported)
       
  1564 			{
       
  1565 			if (iActiveInformation.iRequiresDelayToPrepareData)
       
  1566 				{
       
  1567 				settings |= EDelayToPrepareData;
       
  1568 				} // if
       
  1569 			if (iActiveInformation.iSupportsIncremental)
       
  1570 				{
       
  1571 				settings |= EActiveSupportsInc;
       
  1572 				} // if
       
  1573 			} // if
       
  1574 
       
  1575 		return settings;
       
  1576 		}
       
  1577 		
       
  1578 	/**
       
  1579 	Get ActiveInformation of the data owner
       
  1580 	
       
  1581 	@return TActiveInformation active information
       
  1582 	*/
       
  1583 	TActiveInformation CDataOwner::ActiveInformation()
       
  1584 		{
       
  1585 		return iActiveInformation;
       
  1586 		}
       
  1587 
       
  1588 	void CDataOwner::GetDriveListL(TDriveList& aDriveList)
       
  1589 	/** Get the drive list for the data owner
       
  1590 
       
  1591 	@pre CDataOwner::ParseFilesL() must have been called
       
  1592 	@return the active settings of the data owner
       
  1593 	@leave KErrNotReady if CDataOwner::ParseFilesL() not called
       
  1594 	*/
       
  1595 		{
       
  1596 		__LOG2("CDataOwner::GetDriveListL() - SID: 0x%08x, iFilesParsed: %d", iSecureId.iId, iFilesParsed);
       
  1597 		if (!iFilesParsed)
       
  1598 			{
       
  1599 			User::Leave(KErrNotReady);
       
  1600 			}
       
  1601 
       
  1602 		// Get the list of available drives, dont return drives that dont exist.
       
  1603 		TDriveList existingDrives;
       
  1604 		const TInt error = ipDataOwnerManager->GetRFs().DriveList(existingDrives);
       
  1605         if  ( error != KErrNone )
       
  1606             {
       
  1607             __LOG1("CDataOwner::GetDriveListL() - couldnt get drive list: %d", error);
       
  1608             }
       
  1609         User::LeaveIfError(error);
       
  1610 		
       
  1611 		// We now no longer return the Z drive, it has been decided that the Z drive will always be the
       
  1612 		// ROM. Backing up and restoring the ROM drive should not be possible, as what is the point
       
  1613 		
       
  1614 		TDriveList notToBackup = ipDataOwnerManager->Config().ExcludeDriveList();
       
  1615 		
       
  1616 		for (TInt i = 0; i < KMaxDrives; i++)
       
  1617 			{
       
  1618 			if (notToBackup[i]) // if this drive is set
       
  1619 				{
       
  1620 				// don't include this drive
       
  1621 				existingDrives[i] = EFalse;
       
  1622 				}
       
  1623 			}
       
  1624 		
       
  1625 		// If we do active backup or dbms backup then we
       
  1626 		// have to say all drives
       
  1627 		if ((iActiveInformation.iSupported) || (iDBMSSelections.Count()))
       
  1628 			{
       
  1629             __LOG("CDataOwner::GetDriveListL() - active DO, so using all existing drives");
       
  1630 			aDriveList = existingDrives;		
       
  1631 			} // if
       
  1632 		else
       
  1633 			{
       
  1634 			// See where we have files?
       
  1635 			TBool allDrives = EFalse;
       
  1636             				
       
  1637      		// Reset drives passed in
       
  1638 			aDriveList.SetLength(KMaxDrives);
       
  1639 			aDriveList.FillZ();
       
  1640 			
       
  1641 			// Loop through passive files
       
  1642 			TInt count = iPassiveSelections.Count();
       
  1643             __LOG1("CDataOwner::GetDriveListL() - checking %d passive file entries...", count);
       
  1644 			for (TInt x = 0; !allDrives &&  x < count; x++)
       
  1645 				{
       
  1646                 const TDesC& selection = iPassiveSelections[x]->SelectionName();
       
  1647                 if (iPassiveSelections[x]->SelectionType() != EExclude)
       
  1648                 	{
       
  1649 	                TInt drive = GetDrive(selection);
       
  1650 							
       
  1651 					if (drive == -1)
       
  1652 						{
       
  1653 	                    __LOG3("CDataOwner::GetDriveListL() - passive[%2d/%2d] => all drives (no specific drive letter) - fullName: %S", x+1, count, &selection);
       
  1654 						allDrives = ETrue;
       
  1655 						}
       
  1656 					else if (existingDrives[drive] != 0)
       
  1657 						{
       
  1658 	                    __LOG4("CDataOwner::GetDriveListL() - passive[%2d/%2d] => drive: %c, fullName: %S", x+1, count, drive + 'A', &selection);
       
  1659 						aDriveList[drive] = ETrue;
       
  1660 						}
       
  1661                 	}
       
  1662 
       
  1663 				} // for
       
  1664 
       
  1665             __LOG(" ");
       
  1666 					
       
  1667 			// Loop through public files
       
  1668 			count = iPublicSelections.Count();
       
  1669             __LOG1("CDataOwner::GetDriveListL() - checking %d public file entries...", count);
       
  1670 
       
  1671             for (TInt x = 0; !allDrives &&  (x < count); x++)
       
  1672 				{
       
  1673                 const TDesC& selection = iPublicSelections[x]->SelectionName();
       
  1674                 if (iPublicSelections[x]->SelectionType() != EExclude)
       
  1675                 	{
       
  1676 					TInt drive = GetDrive(selection);
       
  1677 						
       
  1678 					if (drive == -1)
       
  1679 						{
       
  1680 	                    __LOG3("CDataOwner::GetDriveListL() - public[%2d/%2d] => all drives (no specific drive letter) - fullName: %S", x+1, count, &selection);
       
  1681 						allDrives = ETrue;
       
  1682 						}
       
  1683 					else if (existingDrives[drive] != 0)
       
  1684 						{
       
  1685 	                    __LOG4("CDataOwner::GetDriveListL() - public[%2d/%2d] => drive: %c, fullName: %S", x+1, count, drive + 'A', &selection);
       
  1686 						aDriveList[drive] = ETrue;
       
  1687 						}
       
  1688                 	}
       
  1689 				} // for
       
  1690 					
       
  1691 			if (allDrives)
       
  1692 				{
       
  1693                 __LOG("CDataOwner::GetDriveListL() - using all drives!");
       
  1694 				aDriveList = existingDrives;
       
  1695 				} // if
       
  1696 			} // else
       
  1697 
       
  1698 	#ifdef SBE_LOGGING_ENABLED
       
  1699 		TBuf<256> drivePrint;
       
  1700 		//
       
  1701 		for(TInt i=0; i<KMaxDrives; i++)
       
  1702 			{
       
  1703 			if	(aDriveList[i] != 0)
       
  1704 				{
       
  1705 				const TDriveUnit driveUnit(i);
       
  1706 				const TDriveName name(driveUnit.Name());
       
  1707 				drivePrint.Append(name);
       
  1708 				if	(i < KMaxDrives - 1)
       
  1709 					{
       
  1710 					drivePrint.Append(_L(", "));
       
  1711 					}
       
  1712 				}
       
  1713 			}
       
  1714 
       
  1715         __LOG2("CDataOwner::GetDriveListL() - END - SID: 0x%08x, supports drives: %S", iSecureId.iId, &drivePrint);
       
  1716 	#endif
       
  1717 		}
       
  1718 
       
  1719 	void CDataOwner::SetBackedUpAsPartial(TBool aPartial)
       
  1720 	/**
       
  1721 	Inform's the data owner that upon a partial backup, this DO is to be backed up
       
  1722 	*/
       
  1723 		{
       
  1724 		iBackupAsPartial = aPartial;
       
  1725 		}
       
  1726 		
       
  1727 	TBool CDataOwner::PartialAffectsMe() const
       
  1728 	/**
       
  1729 	Accessor to discover whether or not the sbe client has specified this Data Owner to be backed 
       
  1730 	up as part of a partial backup
       
  1731 	
       
  1732 	@return ETrue if this data owner has been requested to backup as partial
       
  1733 	*/
       
  1734 		{
       
  1735 		return iBackupAsPartial;
       
  1736 		}
       
  1737 
       
  1738 	void CDataOwner::ParseFileL(const TDesC& aFileName)
       
  1739 	/** Parse a given registration file
       
  1740 
       
  1741 	@param aFileName the registration file to parse
       
  1742 	*/
       
  1743 		{
       
  1744 		__LOG2("CDataOwner::ParseFileL() - START - aFileName: %S, iPrimaryFile: %d", &aFileName, iPrimaryFile);
       
  1745 		
       
  1746 		PrivatePathL(aFileName);
       
  1747 		// Parse the file
       
  1748 		ipDataOwnerManager->ParserProxy().ParseL(aFileName, *this);
       
  1749 		}
       
  1750 		
       
  1751 	void CDataOwner::PrivatePathL(const TDesC& aFileName)
       
  1752 	/** Get the private path
       
  1753 	@param aPath The path to extract the drive from
       
  1754 	*/
       
  1755 		{
       
  1756 		delete iPrivatePath;
       
  1757   		TParsePtrC parse(aFileName);
       
  1758   		iPrivatePath = parse.Path().AllocL();
       
  1759 		}
       
  1760 
       
  1761 	TInt CDataOwner::GetDrive(const TDesC& aPath) const
       
  1762 	/** Gets the drive relating to a path.
       
  1763 	
       
  1764 	@param aPath The path to extract the drive from
       
  1765 	@return A TDriveNumber or -1 if a drive is not specified
       
  1766 	*/
       
  1767 		{
       
  1768 		TInt ret = KErrNotFound;
       
  1769 		
       
  1770 		if (aPath.Length() > 0)
       
  1771 			{
       
  1772 			if (ipDataOwnerManager->GetRFs().CharToDrive(static_cast<TChar>(aPath[0]).GetLowerCase(), ret) != KErrNone)
       
  1773 				{
       
  1774 				ret = KErrNotFound;
       
  1775 				} // if			
       
  1776 			}
       
  1777 
       
  1778 		return ret;
       
  1779 		}
       
  1780 		
       
  1781 	void CDataOwner::BuildFileListL(const RSelections& aFileSelection, 
       
  1782 									const TDriveNumber aDriveNumber,
       
  1783 									const TTransferDataType aTransferType,
       
  1784 									const TBool aIsPublic,
       
  1785 									RSnapshots* apSnapshots,
       
  1786 								    RFileArray* apFileEntries,
       
  1787 								    CDesCArray* apFileNames)
       
  1788 	/** Builds a file list.
       
  1789 	
       
  1790 	Builds a file list for a given selection.
       
  1791 	
       
  1792 	@param aFileSelection the selection
       
  1793 	@param aDriveNumber The drive that the file resides on
       
  1794 	@param aTransferType The type of the transfer
       
  1795 	@param aIsPublic Are we building a public file list
       
  1796 	@param apSnapshots A snapshot to compare files against
       
  1797 	@param apFileEntries Array of file info's to populate
       
  1798 	@param apFileNames Array of file names to populate
       
  1799 	*/
       
  1800 		{
       
  1801 		TInt count = aFileSelection.Count();
       
  1802 		__LOG4("CDataOwner::BuildFileListL() - START - aDriveNumber: %c, count: %d, aIsPublic: %d, aTransferType: %d", aDriveNumber + 'A', count, aIsPublic, aTransferType);		
       
  1803 		// Split selections into include and exclude
       
  1804 		RArray<TPtrC> include;
       
  1805 		CleanupClosePushL(include);
       
  1806 		RArray<TPtrC> exclude;
       
  1807 		CleanupClosePushL(exclude);
       
  1808 		// sort the snapshost to speed up IsNewerL()
       
  1809 		if (apSnapshots)
       
  1810 			{
       
  1811 			apSnapshots->Sort(CSnapshot::Compare);
       
  1812 			}	
       
  1813 
       
  1814         __LOG("CDataOwner::BuildFileListL() - file selection listing...:");
       
  1815 		for (TInt x = 0; x < count; x++)
       
  1816 			{
       
  1817             const TDesC& selectionName = aFileSelection[x]->SelectionName();
       
  1818             __LOG3("CDataOwner::BuildFileListL() - selection[%03d]: %S, type: %d", x, &selectionName, aFileSelection[x]->SelectionType());
       
  1819 			if (aFileSelection[x]->SelectionType() == EInclude)
       
  1820 				{
       
  1821 				include.AppendL(selectionName);
       
  1822 				} // if
       
  1823 			else
       
  1824 				{
       
  1825 				exclude.AppendL(selectionName);
       
  1826 				} // else
       
  1827 			} // for x
       
  1828 			
       
  1829 		// Loop through all includes
       
  1830 		count = include.Count();
       
  1831         __LOG("CDataOwner::BuildFileListL() - include listing...:");
       
  1832         TFileName* fileName = new(ELeave) TFileName();
       
  1833         CleanupStack::PushL(fileName);
       
  1834 		for (TInt x = 0; x < count; x++)
       
  1835 			{
       
  1836 			fileName->Zero();
       
  1837 			TChar drive;
       
  1838 			User::LeaveIfError(ipDataOwnerManager->GetRFs().DriveToChar(aDriveNumber, drive));
       
  1839 
       
  1840             const TDesC& includeEntry( include[x] );
       
  1841             __LOG2("CDataOwner::BuildFileListL() - entry[%03d] is: %S", x, &includeEntry);
       
  1842             
       
  1843             // See if the drive is specified
       
  1844 			if (includeEntry[0] == KBackSlash()[0])
       
  1845 				{
       
  1846 				// Add the drive
       
  1847 				fileName->Append(drive);
       
  1848 				fileName->Append(KColon);
       
  1849 				fileName->Append(includeEntry);
       
  1850 				}
       
  1851 			else if (static_cast<TChar>(includeEntry[0]).GetLowerCase() == drive.GetLowerCase())
       
  1852 				{
       
  1853 				fileName->Copy(includeEntry);
       
  1854 				} // else
       
  1855 
       
  1856 			
       
  1857             __LOG2("CDataOwner::BuildFileListL() - entry[%03d] filename is therefore: %S", x, fileName);
       
  1858 			if (fileName->Length() > 0)
       
  1859 				{
       
  1860 				
       
  1861 				// Check to see if fileName is just a drive(we cant get an entry)
       
  1862 				TBool isDrive = EFalse;
       
  1863 				if ((fileName->MatchF(KDrive) != KErrNotFound) ||
       
  1864 				    (fileName->MatchF(KDriveAndSlash) != KErrNotFound))
       
  1865 					{
       
  1866 					isDrive = ETrue;
       
  1867                     __LOG("CDataOwner::BuildFileListL() - filename is a drive");
       
  1868 					} // if
       
  1869 					
       
  1870 				TEntry entry;
       
  1871 				TBool isEntry = EFalse;
       
  1872 				if (!isDrive)
       
  1873 					{
       
  1874 					TInt err = ipDataOwnerManager->GetRFs().Entry(*fileName, entry);
       
  1875                     __LOG1("CDataOwner::BuildFileListL() - get entry error: %d", err);
       
  1876 					entry.iName = *fileName;
       
  1877 					switch (err)
       
  1878 						{
       
  1879 					case KErrNone:
       
  1880 						isEntry = ETrue;
       
  1881 						break;
       
  1882 					case KErrNotFound:
       
  1883 					case KErrPathNotFound:
       
  1884 					case KErrBadName:
       
  1885 						break;
       
  1886 					default:
       
  1887 						User::Leave(err);
       
  1888 						} // switch
       
  1889 					} // if
       
  1890 					
       
  1891 				if (isDrive || (isEntry && entry.IsDir()))
       
  1892 					{
       
  1893                     __LOG("CDataOwner::BuildFileListL() - parsing directory...");
       
  1894 					ParseDirL(*fileName, exclude, aTransferType, aIsPublic, apSnapshots, apFileEntries, apFileNames);
       
  1895 
       
  1896 				#ifdef SBE_LOGGING_ENABLED
       
  1897                     if  (apFileNames)
       
  1898                         {
       
  1899                         const TInt fNameCount = apFileNames->Count();
       
  1900                         for(TInt k=0; k<fNameCount; k++)
       
  1901                             {
       
  1902                             const TDesC& fileName = (*apFileNames)[k];
       
  1903                             __LOG2("CDataOwner::BuildFileListL() - directory entry[%03d] %S", k, &fileName);
       
  1904                             }
       
  1905                         }
       
  1906 
       
  1907                     __LOG("CDataOwner::BuildFileListL() - end of parsing directory");
       
  1908 				#endif
       
  1909 					} // if
       
  1910 				else
       
  1911 					{
       
  1912 					if (isEntry)
       
  1913 						{
       
  1914                         const TBool isExcluded = IsExcluded(aIsPublic, *fileName, exclude);
       
  1915 						if (!isExcluded)
       
  1916 							{
       
  1917 							TInt err = KErrNone;
       
  1918 							TBool newer = EFalse;
       
  1919 							if (apSnapshots && (aTransferType == EPassiveIncrementalData))
       
  1920 								{
       
  1921 								TRAP(err, IsNewerL(*fileName, entry, apSnapshots, newer));
       
  1922 								} // if
       
  1923 							if (!apSnapshots || 
       
  1924 							    (aTransferType == EPassiveBaseData) || 
       
  1925 							    newer || 
       
  1926 							    (err != KErrNone))
       
  1927 								{
       
  1928                                 __LOG1("CDataOwner::BuildFileListL() - adding fully verified file: %S", fileName);
       
  1929 								if (apFileEntries)
       
  1930 									{
       
  1931 									// Add to list of files
       
  1932 									apFileEntries->AppendL(entry);
       
  1933 									} // if
       
  1934 								
       
  1935 								if (apFileNames)
       
  1936 									{
       
  1937 									apFileNames->AppendL(*fileName);
       
  1938 									} // else
       
  1939 								} // if
       
  1940 							} // if
       
  1941                         else
       
  1942                             {
       
  1943                             __LOG("CDataOwner::BuildFileListL() - file is excluded!");
       
  1944                             }
       
  1945 						} // if
       
  1946 					} // else
       
  1947 				} // if
       
  1948 			} // for x
       
  1949 		CleanupStack::PopAndDestroy(fileName);
       
  1950 		CleanupStack::PopAndDestroy(&exclude);
       
  1951 		CleanupStack::PopAndDestroy(&include);
       
  1952         __LOG("CDataOwner::BuildFileListL() - END");
       
  1953 		}
       
  1954 
       
  1955 	void CDataOwner::ParseDirL(const TDesC& aDirName, 
       
  1956 							   const RArray<TPtrC>& aExclude,
       
  1957 							   const TTransferDataType aTransferType,
       
  1958 							   const TBool aIsPublic,
       
  1959 							   RSnapshots* apSnapshots,
       
  1960 							   RFileArray* apFileEntries,
       
  1961 							   CDesCArray* apFileNames)
       
  1962 	/** Parses a directory for files.
       
  1963 	
       
  1964 	Parses the given directory for files. The function is called recursivily if a directory is found.
       
  1965 	
       
  1966 	@param aDirName the directory to search
       
  1967 	@param aExclude a list of directories or files to exclude
       
  1968 	@param apFileEntries Array of file entries to populate
       
  1969 	@param apFileNames Array of filenames to populate
       
  1970 	*/							   
       
  1971 		{
       
  1972 		CDir* pFiles = NULL;
       
  1973 		
       
  1974 		// This function requires a / on the end otherwise it does not work!
       
  1975 		TFileName* path = new(ELeave) TFileName(aDirName);
       
  1976 		CleanupStack::PushL(path);
       
  1977 		
       
  1978 		if ((*path)[path->Length() - 1] != KBackSlash()[0])
       
  1979 			{
       
  1980 			path->Append(KBackSlash);
       
  1981 			}
       
  1982 		
       
  1983 		TInt err = ipDataOwnerManager->GetRFs().GetDir(*path, KEntryAttMatchMask, ESortNone, pFiles);
       
  1984 		if ((err != KErrNone) && (err != KErrNotFound)) // Do we need to leave?
       
  1985 			{
       
  1986 			User::Leave(err);
       
  1987 			} // if
       
  1988 		
       
  1989 		CleanupStack::PushL(pFiles);
       
  1990 		
       
  1991 		// sort the snapshost to speed up IsNewerL()
       
  1992 		if (apSnapshots)
       
  1993 			{
       
  1994 			apSnapshots->Sort(CSnapshot::Compare);
       
  1995 			}
       
  1996 		
       
  1997 		TUint count = pFiles->Count();
       
  1998 		
       
  1999 		if (count==0)
       
  2000 	 		{
       
  2001  			// empty directory			
       
  2002  			TEntry entry;
       
  2003  			TInt err = ipDataOwnerManager->GetRFs().Entry(*path, entry);
       
  2004  			entry.iName = *path;
       
  2005  			if (entry.IsDir() && (!IsExcluded(aIsPublic, entry.iName, aExclude)))
       
  2006  				{
       
  2007 				// append empty directory entry to the list
       
  2008  				entry.iSize = 0;
       
  2009  				if (apFileEntries)
       
  2010  					{
       
  2011  					apFileEntries->AppendL(entry);
       
  2012  					} 
       
  2013  				if (apFileNames)
       
  2014  					{
       
  2015  					apFileNames->AppendL(entry.iName);
       
  2016  					} 
       
  2017  				}	
       
  2018  			}
       
  2019 
       
  2020 		TFileName* fileName = new(ELeave) TFileName();
       
  2021 		CleanupStack::PushL(fileName);
       
  2022 		
       
  2023 		while(count--)
       
  2024 			{
       
  2025 			TEntry entry((*pFiles)[count]); 
       
  2026 			
       
  2027 			fileName->Zero();
       
  2028 			// Build full path
       
  2029 			fileName->Append(*path);
       
  2030 			fileName->Append(entry.iName);
       
  2031 			entry.iName = *fileName;
       
  2032 			
       
  2033 			if (!IsExcluded(aIsPublic, entry.iName, aExclude))
       
  2034 				{
       
  2035 				if (entry.IsDir())
       
  2036 					{
       
  2037 					ParseDirL(entry.iName, aExclude, aTransferType, aIsPublic, apSnapshots, apFileEntries, apFileNames);
       
  2038 					} // if
       
  2039 				else
       
  2040 					{
       
  2041 					TInt err = KErrNone;
       
  2042 					TBool newer = EFalse;
       
  2043 					if (apSnapshots && (aTransferType == EPassiveIncrementalData))
       
  2044 						{
       
  2045 						TRAP(err, IsNewerL(entry.iName, entry, apSnapshots, newer));
       
  2046 						} // if
       
  2047 					if (!apSnapshots ||
       
  2048 					    (aTransferType == EPassiveBaseData) || 
       
  2049 					    newer || 
       
  2050 					    (err != KErrNone))
       
  2051 						{
       
  2052 						if (apFileEntries)
       
  2053 							{
       
  2054 							// Add to list of files
       
  2055 							apFileEntries->AppendL(entry);
       
  2056 							} // if
       
  2057 						
       
  2058 						if (apFileNames)
       
  2059 							{
       
  2060 							apFileNames->AppendL(entry.iName);
       
  2061 							} // else
       
  2062 						} // if
       
  2063 					} // else
       
  2064 				} // if
       
  2065 			} // while
       
  2066 			
       
  2067 		// Cleanup
       
  2068 		CleanupStack::PopAndDestroy(fileName);
       
  2069 		CleanupStack::PopAndDestroy(pFiles);
       
  2070 		CleanupStack::PopAndDestroy(path);
       
  2071 		}
       
  2072 
       
  2073 
       
  2074 	void CDataOwner::GetNextPublicFileL(TBool aReset, TDriveNumber aDriveNumber, TEntry& aEntry)
       
  2075 	/** Gets the next public file associated with the data owner
       
  2076 
       
  2077 	@param aReset set true to start reading from the beginning of the list
       
  2078 	@param aDriveNumber the drive to retrieve the public files for
       
  2079 	@param aEntry on return the next entry in the list, an empty entry indicates the end of the list has been reached
       
  2080 	*/
       
  2081 		{
       
  2082 		TInt stackCount;
       
  2083 		TFileName fileName;
       
  2084 		TBool endOfList = EFalse;
       
  2085 		TBool gotEntry = EFalse;
       
  2086 		TChar drive;
       
  2087 		User::LeaveIfError(ipDataOwnerManager->GetRFs().DriveToChar(aDriveNumber, drive));
       
  2088 		
       
  2089 		if (aReset) 
       
  2090 			{
       
  2091 			// Reset and start at the beginning
       
  2092 			iPublicFileIndex = -1;
       
  2093 			
       
  2094 			// Go through and close all RDirs, then reset the array.
       
  2095 			for (stackCount = iPublicDirStack.Count(); stackCount > 0; --stackCount)
       
  2096 				{
       
  2097 				iPublicDirStack[stackCount-1].Close();
       
  2098 				delete iPublicDirNameStack[stackCount-1];
       
  2099 				}
       
  2100 			iPublicDirStack.Reset();
       
  2101 			iPublicDirNameStack.Reset();
       
  2102 
       
  2103 			// Build the list of excludes			
       
  2104 			iPublicExcludes.Reset();
       
  2105 			TInt selectionCount = iPublicSelections.Count();
       
  2106 			for (TInt x = 0; x < selectionCount; ++x)
       
  2107 				{
       
  2108 	            const TDesC& selectionName = iPublicSelections[x]->SelectionName();
       
  2109 	            __LOG3("CDataOwner::GetNextPublicFileL() - selection[%03d]: %S, type: %d", x, &selectionName, iPublicSelections[x]->SelectionType());
       
  2110 				if (iPublicSelections[x]->SelectionType() == EExclude)
       
  2111 					{
       
  2112 					iPublicExcludes.AppendL(selectionName);
       
  2113 					} // else
       
  2114 				} // for x
       
  2115 			} // if (aReset)
       
  2116 			
       
  2117 		while (!endOfList && !gotEntry)
       
  2118 			{
       
  2119 			stackCount = iPublicDirStack.Count();
       
  2120 			if (stackCount == 0)
       
  2121 				{
       
  2122 				// Directory stack is empty, proceed to the next included file entry
       
  2123 				do { ++iPublicFileIndex; }
       
  2124 				while (iPublicFileIndex < iPublicSelections.Count() &&
       
  2125 						iPublicSelections[iPublicFileIndex]->SelectionType() != EInclude);
       
  2126 
       
  2127 				if (iPublicFileIndex < iPublicSelections.Count())
       
  2128 					{
       
  2129 					const TDesC& selectionName = iPublicSelections[iPublicFileIndex]->SelectionName();
       
  2130 			        
       
  2131 					if (selectionName[0] == KBackSlash()[0])
       
  2132 						{
       
  2133 						// Add the drive
       
  2134 						fileName.Zero();
       
  2135 						fileName.Append(drive);
       
  2136 						fileName.Append(KColon);
       
  2137 						fileName.Append(selectionName);
       
  2138 						}
       
  2139 					else
       
  2140 						{
       
  2141 						// Handle the Exclamation (!) in Public data paths, if any.  
       
  2142 						// Exclamation mark in place of drive letter means that the path is to be checked in all available drives.
       
  2143 						// And any dataowner can keep their public files in any drive and it can be mentioned in backup_registration file as below.
       
  2144 						// <public_backup>
       
  2145 						// <include_directory name="!:\mydatabases\" />
       
  2146 						// </public_backup>				
       
  2147 						
       
  2148 						if ( selectionName[0] == KExclamationAsDrive()[0])
       
  2149 							{	
       
  2150 							// Map public data path using current drive being backed up.
       
  2151 							fileName.Zero();
       
  2152 							fileName.Append(drive);
       
  2153 							fileName.Append( selectionName.Mid(1) );
       
  2154 							}
       
  2155 						else
       
  2156 							if (static_cast<TChar>(selectionName[0]).GetUpperCase() == drive.GetUpperCase())
       
  2157 							{								
       
  2158 							fileName.Copy(selectionName);
       
  2159 							} // else
       
  2160 						
       
  2161 						} // else
       
  2162 
       
  2163 		            __LOG1("CDataOwner::GetNextPublicFileL() - next include entry filename is therefore: %S", &fileName);
       
  2164 					if (fileName.Length() > 0)
       
  2165 						{
       
  2166 						
       
  2167 						// Check to see if fileName is just a drive(we cant get an entry)
       
  2168 						TBool isDrive = EFalse;
       
  2169 						if ((fileName.MatchF(KDrive) != KErrNotFound) ||
       
  2170 						    (fileName.MatchF(KDriveAndSlash) != KErrNotFound))
       
  2171 							{
       
  2172 							isDrive = ETrue;
       
  2173 		                    __LOG("CDataOwner::GetNextPublicFileL() - filename is a drive");
       
  2174 							} // if
       
  2175 							
       
  2176 						TBool isEntry = EFalse;
       
  2177 						if (!isDrive)
       
  2178 							{
       
  2179 							TInt err = ipDataOwnerManager->GetRFs().Entry(fileName, aEntry);
       
  2180 		                    __LOG1("CDataOwner::GetNextPublicFileL() - get entry error: %d", err);
       
  2181 							aEntry.iName = fileName;
       
  2182 							switch (err)
       
  2183 								{
       
  2184 							case KErrNone:
       
  2185 								isEntry = ETrue;
       
  2186 								break;
       
  2187 							case KErrNotFound:
       
  2188 							case KErrPathNotFound:
       
  2189 							case KErrBadName:
       
  2190 								break;
       
  2191 							default:
       
  2192 								User::Leave(err);
       
  2193 								} // switch
       
  2194 
       
  2195 							// Must have a trailing backslash on a directory
       
  2196 							if (aEntry.IsDir() && (fileName[fileName.Length() - 1] != '\\'))
       
  2197 								{
       
  2198 								fileName.Append(KBackSlash);
       
  2199 								}
       
  2200 							} // if
       
  2201 					
       
  2202 						if (isDrive || (isEntry && aEntry.IsDir()))
       
  2203 							{
       
  2204 		                    __LOG("CDataOwner::GetNextPublicFileL() - parsing directory...");
       
  2205 							RDir dir;
       
  2206 							dir.Open(ipDataOwnerManager->GetRFs(), fileName, KEntryAttMaskSupported);
       
  2207 							iPublicDirStack.AppendL(dir);
       
  2208 							iPublicDirNameStack.AppendL(fileName.AllocL());
       
  2209 							++stackCount;
       
  2210 							} // if
       
  2211 						else if (isEntry)
       
  2212 							{
       
  2213 							if (!IsExcluded(ETrue, fileName, iPublicExcludes))
       
  2214 								{
       
  2215 								gotEntry = ETrue;
       
  2216 								}
       
  2217 	                        else
       
  2218 	                            {
       
  2219 	                            __LOG("CDataOwner::BuildFileListL() - file is excluded!");
       
  2220 	                            }
       
  2221 							} // if
       
  2222 						} // else if
       
  2223 					}
       
  2224 				else
       
  2225 					{
       
  2226 					endOfList = ETrue;					
       
  2227 					}
       
  2228 				} // if (stackCount == 0)
       
  2229 
       
  2230 			if (stackCount > 0)
       
  2231 				{
       
  2232 				// There is a directory on the stack, so iterate through it
       
  2233 				RDir& dir = iPublicDirStack[stackCount-1];
       
  2234 				TInt err = dir.Read(aEntry);
       
  2235 
       
  2236 				if (err == KErrNone) 
       
  2237 					{
       
  2238 					// Succesfully read the next directory entry
       
  2239 
       
  2240 					// Build full file path
       
  2241 					fileName.Zero();
       
  2242 					
       
  2243 					// loop through dir stack adding entries seperated by '\'.
       
  2244 					for (TInt x = 0; x < iPublicDirStack.Count(); ++x)
       
  2245 						{
       
  2246 						fileName.Append(*iPublicDirNameStack[x]);
       
  2247 						// Add a backslash if there's not already one
       
  2248 						if (fileName[fileName.Length()-1] != KBackSlash()[0]) 
       
  2249 							{
       
  2250 							fileName.Append(KBackSlash);
       
  2251 							}
       
  2252 						}
       
  2253 
       
  2254 					// Append the currently entry name to complete the path
       
  2255 					fileName.Append(aEntry.iName);
       
  2256 
       
  2257 					if (aEntry.IsDir())
       
  2258 						{
       
  2259 						// Must have a trailing backslash on directory paths
       
  2260 						fileName.Append(KBackSlash);
       
  2261 						
       
  2262 						// Open the directory and push it onto the dir stack
       
  2263 						RDir dir;
       
  2264 						User::LeaveIfError(dir.Open(ipDataOwnerManager->GetRFs(), fileName, KEntryAttMaskSupported));
       
  2265 						iPublicDirStack.AppendL(dir);
       
  2266 						iPublicDirNameStack.AppendL(aEntry.iName.AllocL());
       
  2267 						++stackCount;
       
  2268 						}
       
  2269 					else
       
  2270 						{
       
  2271 						// Update entry with full path ready to return
       
  2272 						aEntry.iName = fileName;
       
  2273 						gotEntry = ETrue;
       
  2274 						}
       
  2275 					// if (entry.IsDir())
       
  2276 						
       
  2277 					}
       
  2278 				else if (err == KErrEof)
       
  2279 					{
       
  2280 					// Finished reading this directory, close it and pop it from the directory stack
       
  2281 					stackCount--;
       
  2282 					
       
  2283 					iPublicDirStack[stackCount].Close();
       
  2284 					iPublicDirStack.Remove(stackCount);
       
  2285 					
       
  2286 					delete iPublicDirNameStack[stackCount];
       
  2287 					iPublicDirNameStack.Remove(stackCount);
       
  2288 					}
       
  2289 				else
       
  2290 					{
       
  2291 					User::Leave(err);
       
  2292 					}
       
  2293 				} // if (stackCount > 0)
       
  2294 			}
       
  2295 
       
  2296 		if (endOfList)
       
  2297 			{
       
  2298 			// If the end of the list has been reached, make sure that an empty TEntry is returned
       
  2299 			aEntry = TEntry();
       
  2300 			}
       
  2301 		}
       
  2302 
       
  2303 
       
  2304 	TBool CDataOwner::IsExcluded(const TBool aIsPublic, const TDesC& aFileName, const RArray<TPtrC>& aExclude)
       
  2305 	/** Checks to see if a given file is excluded
       
  2306 	
       
  2307 	Checks to see if the given file is not in a private directory or in the exclude list.
       
  2308 	
       
  2309 	@param aFileName file to check
       
  2310 	@param aExclude list of excluded files
       
  2311 	@return ETrue if excluded otherwise EFalse
       
  2312 	*/
       
  2313 		{
       
  2314 		TBool ret = EFalse;
       
  2315 		
       
  2316 		// Check it is not in sys, resource, system or backwards path
       
  2317 		ret = (!((aFileName.MatchF(KSystem) == KErrNotFound) &&
       
  2318 			     (aFileName.MatchF(KResource) == KErrNotFound) &&
       
  2319 			     (aFileName.MatchF(KSys) == KErrNotFound) && 
       
  2320 			     (aFileName.MatchF(KOther) == KErrNotFound)
       
  2321 			    )
       
  2322 			  );
       
  2323 		
       
  2324 		// If this is public backup remove the private directory
       
  2325 		if (!ret && aIsPublic)
       
  2326 			{
       
  2327 		    ret = (!(aFileName.MatchF(KPrivateMatch) == KErrNotFound));
       
  2328 			}
       
  2329 		
       
  2330 		/**		 
       
  2331 		 * Check whether file is in the "NoBackup" folder or not, if yes exclude it from the backup
       
  2332 		 * @note: All files which are kept in "NoBackup" folder under the private directory will be 
       
  2333 		 * excluded from the backup by default.
       
  2334 		 */		
       
  2335 		if (!ret)
       
  2336 		    {
       
  2337 		    ret = (!(aFileName.MatchF(KPrivateNoBackup) == KErrNotFound));		    
       
  2338 		    }
       
  2339 		
       
  2340 		// See if the file is in a private directory the data owner can access
       
  2341 		if (!ret && (aFileName.MatchF(KPrivateMatch) != KErrNotFound))
       
  2342 			{
       
  2343 			// The path includes a private directory, make sure it is the data owners
       
  2344 			// private directory.
       
  2345 			const TInt KSecureIdLength(8); // This is currently the length of a secure id
       
  2346 			TBuf<KSecureIdLength> sid;
       
  2347 			sid.Num(iSecureId, EHex);
       
  2348 			TFileName match(KPrivateSidMatch());
       
  2349 			match.Append(KPad().Ptr(), KPad().Length() - sid.Length());
       
  2350 			match.Append(sid);
       
  2351 			match.Append(KStar);
       
  2352 			ret = (aFileName.MatchF(match) == KErrNotFound);
       
  2353 			} // if
       
  2354 		
       
  2355 		if (!ret)
       
  2356 			{
       
  2357 			// Is the file in the exclude list?
       
  2358 			const TInt count = aExclude.Count();
       
  2359 			for (TInt x = 0; !ret && x < count; x++)
       
  2360 				{				
       
  2361 				__LOG1("file name: %S",&aFileName);
       
  2362 				if (aExclude[x][0] == KBackSlash()[0])
       
  2363 					{
       
  2364 					// Compare with out drive
       
  2365 					TFileName compare = KQuestionMark();
       
  2366 					compare.Append(KColon);
       
  2367 					compare.Append(aExclude[x]);
       
  2368 					ret = (!(aFileName.MatchF(compare) == KErrNotFound));
       
  2369 					} // if
       
  2370 				else
       
  2371 					{
       
  2372 					// Normal compare
       
  2373 					ret = (aFileName.CompareF(aExclude[x]) == 0);
       
  2374 					} // else
       
  2375 				} // for x
       
  2376 			} // if
       
  2377 		
       
  2378         __LOG2("CDataOwner::IsExcluded() - END - returns excluded: %d for file: %S", ret, &aFileName);
       
  2379 		return ret;
       
  2380 		}
       
  2381 		
       
  2382 	void CDataOwner::SupplyPassiveSnapshotDataL(TDriveNumber aDriveNumber, TDesC8& aBuffer, TBool aLastSection)
       
  2383 	/** Handles the supply of passive snapshot data
       
  2384 	
       
  2385 	@param aBuffer The buffer containing the snapshot data.
       
  2386 	@param aLastSection Is this the last section?
       
  2387 	*/
       
  2388 		{
       
  2389         __LOG2("CDataOwner::SupplyPassiveSnapshotDataL() - START - aDriveNumber: %c, aLastSection: %d", aDriveNumber + 'A', aLastSection);
       
  2390 
       
  2391 		TInt err = KErrNone;
       
  2392 		if (iBufferSnapshotReader == NULL)
       
  2393 			{
       
  2394             __LOG("CDataOwner::SupplyPassiveSnapshotDataL() - making temporary snapshot holder..");
       
  2395 			iTempSnapshotHolder = CSnapshotHolder::NewL();
       
  2396 			iTempSnapshotHolder->iDriveNumber = aDriveNumber;
       
  2397 			iBufferSnapshotReader = CBufferSnapshotReader::NewL(iTempSnapshotHolder->iSnapshots);
       
  2398 			
       
  2399             __LOG("CDataOwner::SupplyPassiveSnapshotDataL() - trying to unpack snapshots from buffer...");
       
  2400 			TRAP(err, iBufferSnapshotReader->StartL(aBuffer, aLastSection));
       
  2401             __LOG1("CDataOwner::SupplyPassiveSnapshotDataL() - unpack result was: %d", err);
       
  2402 			} // if
       
  2403 		else
       
  2404 			{
       
  2405             __LOG("CDataOwner::SupplyPassiveSnapshotDataL() - continuing unpack operation...");
       
  2406 			TRAP(err, iBufferSnapshotReader->ContinueL(aBuffer, aLastSection));
       
  2407             __LOG1("CDataOwner::SupplyPassiveSnapshotDataL() - continued unpack operation result was: %d", err);
       
  2408 			}
       
  2409 			
       
  2410 		if ((err != KErrNone) || aLastSection)
       
  2411 			{
       
  2412 			delete iBufferSnapshotReader;
       
  2413 			iBufferSnapshotReader = NULL;
       
  2414 			
       
  2415 			if (err == KErrNone)
       
  2416 				{
       
  2417                 __LOG("CDataOwner::SupplyPassiveSnapshotDataL() - Snapshots identified ok!");
       
  2418 				
       
  2419 				iSnapshots.AppendL(iTempSnapshotHolder);
       
  2420 				iTempSnapshotHolder = NULL;
       
  2421 				} // if
       
  2422 			else
       
  2423 				{
       
  2424                 __LOG1("CDataOwner::SupplyPassiveSnapshotDataL() - END - leaving with error: %d", err);
       
  2425 				User::Leave(err);
       
  2426 				} // else
       
  2427 			} // if
       
  2428 
       
  2429         __LOG("CDataOwner::SupplyPassiveSnapshotDataL() - END");
       
  2430 		}
       
  2431 	
       
  2432 	void CDataOwner::SupplyPassiveBaseDataL(const TDriveNumber aDriveNumber, TDesC8& aBuffer, TBool aLastSection)
       
  2433 	/** Handles the supply of passive base data
       
  2434 	*/
       
  2435 		{
       
  2436 		__LOG3("CDataOwner::SupplyPassiveBaseDataL() - START - drive: %c, aLastSection: %d, iBufferFileReader: 0x%08x", aDriveNumber + 'A', aLastSection, iBufferFileReader);
       
  2437 
       
  2438         TInt err = KErrNone;
       
  2439 		if (iBufferFileReader == NULL)
       
  2440 			{
       
  2441 			iBufferFileReader = CBufferFileReader::NewL(ipDataOwnerManager->GetRFs(), FindSnapshot(aDriveNumber), this);
       
  2442 			
       
  2443 			TRAP(err, iBufferFileReader->StartL(aBuffer, aLastSection));
       
  2444 			} // if
       
  2445 		else
       
  2446 			{
       
  2447 			TRAP(err, iBufferFileReader->ContinueL(aBuffer, aLastSection));
       
  2448 			} // else
       
  2449 			
       
  2450 		if ((err != KErrNone) || aLastSection)
       
  2451 			{
       
  2452             if  ( err != KErrNone )
       
  2453                 {
       
  2454                 __LOG1("CDataOwner::SupplyPassiveBaseDataL() - ERROR - error: %d", err);
       
  2455                 }
       
  2456 	
       
  2457             delete iBufferFileReader;
       
  2458 			iBufferFileReader = NULL;
       
  2459 			
       
  2460 			User::LeaveIfError(err);
       
  2461 			} // if
       
  2462 
       
  2463         __LOG("CDataOwner::SupplyPassiveBaseDataL() - END");
       
  2464 		}
       
  2465 		
       
  2466 	void CDataOwner::RequestPassiveSnapshotDataL(TDriveNumber aDriveNumber, TPtr8& aBuffer, 
       
  2467 												 TBool& aLastSection)
       
  2468 	/** Handles the request for passive snapshot data
       
  2469 	
       
  2470 	@param aDriveNumber The drive snapshot data is required.
       
  2471 	@param aBuffer The buffer to write the data too.
       
  2472 	@param aLastSection On return set to true if finished.
       
  2473 	*/													 
       
  2474 		{
       
  2475         __LOG3("CDataOwner::RequestPassiveSnapshotDataL() - START - aDriveNumber: %c, owner: 0x%08x, bufferLen: %d", aDriveNumber + 'A', iSecureId.iId, aBuffer.Length() );
       
  2476 
       
  2477 		if (iBufferSnapshotWriter == NULL)
       
  2478 			{
       
  2479 			RFileArray fileinfos;
       
  2480 			CleanupClosePushL(fileinfos);
       
  2481 			
       
  2482 			CDesCArray* filenames = new(ELeave) CDesCArrayFlat(KDesCArrayGranularity);
       
  2483 			CleanupStack::PushL(filenames);
       
  2484 
       
  2485 			BuildFileListL(iPassiveSelections, aDriveNumber, EPassiveBaseData, EFalse, NULL, &fileinfos, filenames);
       
  2486 			
       
  2487 			// Add the DBMS file
       
  2488 			AddDBMSFilesL(aDriveNumber, filenames, &fileinfos);
       
  2489 			
       
  2490 			const TInt count = fileinfos.Count();
       
  2491 			if (count > 0)
       
  2492 				{
       
  2493                 __LOG1("CDataOwner::SupplyPassiveBaseDataL() - got %d entries...", count);
       
  2494 
       
  2495 				// Create a tempory snapshot holder
       
  2496 				RSnapshots* tempSnapshots = new(ELeave) RSnapshots();
       
  2497 				TCleanupItem cleanup(CleanupRPointerArray, tempSnapshots);
       
  2498 				CleanupStack::PushL(cleanup);
       
  2499 				
       
  2500 				for (TInt x = 0; x < count; x++)
       
  2501 					{
       
  2502 					const TDesC& fileName = (*filenames)[x];
       
  2503 					CSnapshot* snapshot = CSnapshot::NewLC(fileinfos[x].iModified.Int64(), fileName);
       
  2504 					__LOG3("CDataOwner::RequestPassiveSnapshotDataL() - snapshot[%2d/%2d] = %S", x+1, count, &fileName);
       
  2505 					tempSnapshots->AppendL(snapshot);
       
  2506 					CleanupStack::Pop(snapshot);
       
  2507 					} // for x
       
  2508 				
       
  2509 				// Create a buffer writer
       
  2510 				iBufferSnapshotWriter = CBufferSnapshotWriter::NewL(tempSnapshots);
       
  2511 				CleanupStack::Pop(tempSnapshots);
       
  2512 				
       
  2513                 __LOG("CDataOwner::RequestPassiveSnapshotDataL() - writing snapshots to buffer...");
       
  2514 				iBufferSnapshotWriter->StartL(aBuffer, aLastSection);
       
  2515 				if (aLastSection)
       
  2516 					{
       
  2517 					delete iBufferSnapshotWriter;
       
  2518 					iBufferSnapshotWriter = NULL;
       
  2519 					} // if
       
  2520 					
       
  2521 				
       
  2522 				} // if
       
  2523 			else
       
  2524 				{
       
  2525 				aLastSection = ETrue;
       
  2526 				} // else
       
  2527 			
       
  2528 			CleanupStack::PopAndDestroy(filenames);
       
  2529 			CleanupStack::PopAndDestroy(&fileinfos);
       
  2530 			} // if
       
  2531 		else
       
  2532 			{
       
  2533 			iBufferSnapshotWriter->ContinueL(aBuffer, aLastSection);
       
  2534 			if (aLastSection)
       
  2535 				{
       
  2536 				delete iBufferSnapshotWriter;
       
  2537 				iBufferSnapshotWriter = NULL;
       
  2538 				} // if
       
  2539 			} // else
       
  2540 
       
  2541         __LOG2("CDataOwner::RequestPassiveSnapshotDataL() - END - aLastSection: %d, bufferLen: %d", aLastSection, aBuffer.Length());
       
  2542 		} // RequestPassiveSnapShotDataL
       
  2543 		
       
  2544 	void CDataOwner::RequestPassiveDataL(TTransferDataType aTransferType, 
       
  2545 										 TDriveNumber aDriveNumber, TPtr8& aBuffer, 
       
  2546 									     TBool& aLastSection)
       
  2547 	/** Handles the request for passive base data
       
  2548 	
       
  2549 	@param aDriveNumber The drive that files must be on.
       
  2550 	@param aBuffer The buffer to write the data to.
       
  2551 	@param aLastSection On return set to true if finished.
       
  2552 	*/
       
  2553 		{
       
  2554         __LOG4("CDataOwner::RequestPassiveDataL() - START - aDrive: %c, aTransferType: %d, iSecureId: 0x%08x, iBufferFileWriter: 0x%08x", aDriveNumber + 'A', aTransferType, iSecureId.iId, iBufferFileWriter);
       
  2555 
       
  2556         // Build the list of files
       
  2557 		if (iBufferFileWriter == NULL)
       
  2558 			{
       
  2559 			CDesCArray* filenames = new(ELeave) CDesCArrayFlat(KDesCArrayGranularity);
       
  2560 			CleanupStack::PushL(filenames);
       
  2561 
       
  2562 			if (aTransferType == EPassiveBaseData)
       
  2563 				{
       
  2564                 __LOG("CDataOwner::RequestPassiveDataL() - EPassiveBaseData...");
       
  2565 				BuildFileListL(iPassiveSelections, aDriveNumber, aTransferType, EFalse, NULL, NULL, filenames);
       
  2566 				
       
  2567 				// Add the DBMS file
       
  2568 				AddDBMSFilesL(aDriveNumber, filenames, NULL);
       
  2569 				} // if
       
  2570 			else
       
  2571 				{
       
  2572 				// Do we have a snapshot?
       
  2573 				const TInt count = iSnapshots.Count();
       
  2574 				RSnapshots* pSnapshot = NULL;
       
  2575 				for (TInt x = 0; !pSnapshot && (x < count); x++)
       
  2576 					{
       
  2577 					if (iSnapshots[x]->iDriveNumber == aDriveNumber)
       
  2578 						{
       
  2579 						pSnapshot = &(iSnapshots[x]->iSnapshots);
       
  2580 						} // if
       
  2581 					} // for x
       
  2582 					
       
  2583 				BuildFileListL(iPassiveSelections, aDriveNumber, aTransferType, EFalse, pSnapshot, NULL, filenames);
       
  2584 				
       
  2585 				// Do we need to add the DBMS file?
       
  2586 				AddDBMSFilesL(aDriveNumber, filenames, NULL);
       
  2587 				} // else
       
  2588 
       
  2589 
       
  2590             __LOG1("CDataOwner::RequestPassiveDataL() - Got %d files...", filenames->Count());
       
  2591 			if (filenames->Count() > 0)
       
  2592 				{
       
  2593 				// Create a file writer
       
  2594 				iBufferFileWriter = CBufferFileWriter::NewL(ipDataOwnerManager->GetRFs(), filenames);
       
  2595 				CleanupStack::Pop(filenames);
       
  2596 				
       
  2597 				iBufferFileWriter->StartL(aBuffer, aLastSection);
       
  2598 				if (aLastSection)
       
  2599 					{
       
  2600 					delete iBufferFileWriter;
       
  2601 					iBufferFileWriter = NULL;
       
  2602 					}
       
  2603 				} // if
       
  2604 			else
       
  2605 				{
       
  2606 				CleanupStack::PopAndDestroy(filenames);
       
  2607 				aLastSection = ETrue;
       
  2608 				} // else
       
  2609 
       
  2610 			} // if
       
  2611 		else
       
  2612 			{
       
  2613 			iBufferFileWriter->ContinueL(aBuffer, aLastSection);
       
  2614 			if (aLastSection)
       
  2615 				{
       
  2616 				delete iBufferFileWriter;
       
  2617 				iBufferFileWriter = NULL;
       
  2618 				} // if
       
  2619 			} // else
       
  2620 		
       
  2621         __LOG("CDataOwner::RequestPassiveDataL() - END");
       
  2622 		}
       
  2623 		
       
  2624 	void CDataOwner::IsNewerL(const TDesC& aFileName, const TEntry& aFile, const RSnapshots* aSnapshots, TBool& aNewer)
       
  2625 	/** Check to see if a file is newer.
       
  2626 	
       
  2627 	Checks to see if aFile is newer than the one contained in aFiles.
       
  2628 	
       
  2629 	@param aFile the file to check.
       
  2630 	@param aFiles the array of files to check agaisnt
       
  2631 	@param aNewer on return ETrue if aFile is newer, EFalse otherwise.
       
  2632 	@leave KErrNotFound if aFile does not exist in aFiles.
       
  2633 	*/
       
  2634 		{
       
  2635 		CSnapshot* snapshot = CSnapshot::NewLC(TTime().Int64(), aFileName);
       
  2636 		TInt res = aSnapshots->Find(snapshot, CSnapshot::Match);
       
  2637 		CleanupStack::PopAndDestroy(snapshot);
       
  2638 		User::LeaveIfError(res);
       
  2639 		if (aFile.iModified.Int64() > (*aSnapshots)[res]->Modified())
       
  2640 			{
       
  2641 			aNewer = ETrue;
       
  2642 			}
       
  2643 		else
       
  2644 			{
       
  2645 			aNewer = EFalse;
       
  2646 			}
       
  2647 		}
       
  2648 	
       
  2649 	RSnapshots* CDataOwner::FindSnapshot(TDriveNumber aDriveNumber)
       
  2650 	/** Searches the snapshots find a snapshot
       
  2651 	
       
  2652 	@param aDriveNumber find snapshot for drive aDriveNumber
       
  2653 	@return The snapshot or NULL
       
  2654 	*/
       
  2655 		{
       
  2656 		const TInt count = iSnapshots.Count();
       
  2657 		__LOG3("CDataOwner::FindSnapshot() - START - aDriveNumber: %c, count: %d, iSecureId: 0x%08x", aDriveNumber + 'A', count, iSecureId.iId);
       
  2658 
       
  2659         RSnapshots* pRet = NULL;
       
  2660 		
       
  2661 		for (TInt x = 0; !pRet && (x < count); x++)
       
  2662 			{
       
  2663             CSnapshotHolder* snapshotHolder = iSnapshots[x];
       
  2664 
       
  2665 		#ifdef SBE_LOGGING_ENABLED            
       
  2666             const TInt entryCount = snapshotHolder->iSnapshots.Count();
       
  2667             __LOG4("CDataOwner::FindSnapshot() - snapshot[%02d] - drive: %c, entry Count: %d, addr: 0x%08x", x, snapshotHolder->iDriveNumber + 'A', entryCount, &snapshotHolder->iSnapshots);
       
  2668 
       
  2669             for(TInt i=0; i<entryCount; i++)
       
  2670                 {
       
  2671                 const TDesC& snapshot = snapshotHolder->iSnapshots[i]->FileName();
       
  2672                 __LOG2("CDataOwner::FindSnapshot() -     file[%04d]: %S", i+1, &snapshot);
       
  2673                 }
       
  2674 		#endif
       
  2675 
       
  2676 			if (snapshotHolder->iDriveNumber == aDriveNumber)
       
  2677 				{
       
  2678 				pRet = &(snapshotHolder->iSnapshots);
       
  2679 				} // if
       
  2680 			} // for x
       
  2681 			
       
  2682 		__LOG1("CDataOwner::FindSnapshot() - END - ret: 0x%08x", pRet);
       
  2683 		return pRet;
       
  2684 		}
       
  2685 		
       
  2686 	/**
       
  2687 	Returns a reference to a state by drive object. Object is located using aDrive as a key
       
  2688 	@param aDrive Index identifying the TDataOwnerStateByDrive
       
  2689 	*/
       
  2690 	TDataOwnerStateByDrive& CDataOwner::StateByDriveL(TDriveNumber& aDrive)
       
  2691 		{
       
  2692 		TBool found = EFalse;
       
  2693 		const TInt count = iStateByDrive.Count();
       
  2694 		TInt index = 0;
       
  2695 
       
  2696 		// Loop around until we find		
       
  2697 		while ((index < count) && !found)
       
  2698 			{
       
  2699 			if (iStateByDrive[index].iDrive == aDrive)
       
  2700 				{
       
  2701 				found = ETrue;
       
  2702 				}
       
  2703 			else
       
  2704 				{
       
  2705 				++index;
       
  2706 				}
       
  2707 			}
       
  2708 		
       
  2709 		// We must have found, otherwise error	
       
  2710 		if (!found)
       
  2711 			{
       
  2712 			User::Leave(KErrNotFound);
       
  2713 			}
       
  2714 			
       
  2715 		return iStateByDrive[index];
       
  2716 		}
       
  2717 
       
  2718 	/**
       
  2719 	Returns a reference to a proxy state by drive object. Object is located using aDrive and aProxy as keys
       
  2720 	@param aDrive Index identifying the TProxyStateByDrive
       
  2721 	@param aProxy Index identifying the proxy
       
  2722 	*/
       
  2723 	TProxyStateByDrive& CDataOwner::ProxyStateByDriveL(TDriveNumber& aDrive, TInt aProxy)
       
  2724 		{
       
  2725 		TBool found = EFalse;
       
  2726 		const TInt count = iProxyStateByDrive.Count();
       
  2727 		TInt index = 0;
       
  2728 
       
  2729 		// Loop around until we find		
       
  2730 		while ((index < count) && !found)
       
  2731 			{
       
  2732 			if (iProxyStateByDrive[index].iDrive == aDrive &&
       
  2733 				iProxyStateByDrive[index].iProxy == aProxy)
       
  2734 				{
       
  2735 				found = ETrue;
       
  2736 				}
       
  2737 			else
       
  2738 				{
       
  2739 				++index;
       
  2740 				}
       
  2741 			}
       
  2742 		
       
  2743 		// Add a new entry if not found
       
  2744 		if (!found)
       
  2745 			{
       
  2746 			iProxyStateByDrive.Append(TProxyStateByDrive(aDrive,aProxy));
       
  2747 			index = count;
       
  2748 			}
       
  2749 			
       
  2750 		return iProxyStateByDrive[index];
       
  2751 		}
       
  2752 
       
  2753 
       
  2754 	
       
  2755 	/**
       
  2756 	Called to re-create the state-by-drive array
       
  2757 	*/
       
  2758 	void CDataOwner::BuildDriveStateArrayL()
       
  2759 		{
       
  2760 		TDriveList driveList;
       
  2761 		driveList.SetMax();
       
  2762 		
       
  2763 		TRAPD(err, GetDriveListL(driveList));
       
  2764         __LOG2("CDataOwner::BuildDriveStateArrayL() - START - SID: 0x%08x, error: %d", iSecureId.iId, err);
       
  2765 		
       
  2766 		if (err == KErrNone)
       
  2767 			{
       
  2768 			for (TInt index = 0; index < KMaxDrives; index++)
       
  2769 				{
       
  2770 				if (driveList[index])
       
  2771 					{
       
  2772 					// Add a new state object to the array of states
       
  2773 					iStateByDrive.AppendL(TDataOwnerStateByDrive(static_cast<TDriveNumber>(index)));
       
  2774 					}
       
  2775 				}
       
  2776 			}
       
  2777 		else
       
  2778 			{
       
  2779 			__LOG1("CDataOwner::BuildDriveStateArrayL() - Warning! error ocurred whilst getting the drivelist from data owner %08x", iSecureId.iId);
       
  2780 			}
       
  2781 		}
       
  2782 		
       
  2783 		
       
  2784 	/** 
       
  2785 	Adds the list of DBMS files to a filename list
       
  2786 	*/
       
  2787 	void CDataOwner::AddDBMSFilesL(TDriveNumber aDriveNumber, CDesCArray* apFileNames, RFileArray* apEntries)
       
  2788 		{
       
  2789 		const TInt count = iDBMSSelections.Count();
       
  2790 		__LOG3("CDataOwner::AddDBMSFilesL() - START - aDriveNumber: %c, owner: 0x%08x, count: %d", aDriveNumber + 'A', iSecureId.iId, count);
       
  2791 
       
  2792         if (count > 0)
       
  2793 			{
       
  2794 			// Get DB connection
       
  2795 			RDbs dbs;
       
  2796 			User::LeaveIfError(dbs.Connect());
       
  2797 			CleanupClosePushL(dbs);
       
  2798 			
       
  2799 			for (TInt x = 0; x < count; x++)
       
  2800 				{
       
  2801 				// Get list of filenames
       
  2802 				TInt err = KErrNone; 
       
  2803 				CDbStrings* pFilenames = NULL;
       
  2804 				TRAP(err, pFilenames = dbs.BackupPathsL(iSecureId, iDBMSSelections[x]));
       
  2805 					
       
  2806 				if (err == KErrNone)
       
  2807 					{
       
  2808 					CleanupStack::PushL(pFilenames);
       
  2809 					
       
  2810 		        	__LOG1("CDataOwner::AddDBMSFilesL() - getting backup paths for owner returned error: %d", err);
       
  2811 		        	
       
  2812 					const TInt count = pFilenames->Count();
       
  2813 					for (TInt x = 0; x < count; x++)
       
  2814 						{
       
  2815                         const TDesC& pFileName = (*pFilenames)[x];
       
  2816 	                	__LOG3("CDataOwner::AddDBMSFilesL() - file[%3d/%3d] = %S", x + 1, count, &pFileName);
       
  2817 
       
  2818 						TInt drive = -1;
       
  2819 						TInt driveerr = RFs::CharToDrive( pFileName[0], drive);
       
  2820 						if ((driveerr == KErrNone) && (drive == aDriveNumber))
       
  2821 							{ 
       
  2822 							if (apFileNames)
       
  2823 								{
       
  2824 	                	        __LOG1("CDataOwner::AddDBMSFilesL() - adding validated filename: %S", &pFileName);
       
  2825 								apFileNames->AppendL( pFileName );
       
  2826 								}
       
  2827 							if (apEntries)
       
  2828 								{
       
  2829 								TEntry entry;
       
  2830 								TInt entryError = ipDataOwnerManager->GetRFs().Entry( pFileName, entry);
       
  2831 	                	        __LOG2("CDataOwner::AddDBMSFilesL() - drive entry result for file \'%S\' is: %d", &pFileName, entryError);
       
  2832 								if (entryError == KErrNone)
       
  2833 									{
       
  2834 	                	            __LOG1("CDataOwner::AddDBMSFilesL() - adding validated entry: %S", &pFileName);
       
  2835 									apEntries->AppendL(entry);
       
  2836 									} // if
       
  2837 								else if (entryError != KErrNotFound)
       
  2838 									{
       
  2839 									__LOG2("CDataOwner::AddDBMSFilesL() - Could not get entry for 0x%08x, error: %d", iSecureId.iId, entryError);
       
  2840 									} // else if
       
  2841 								} // if
       
  2842 							} // if
       
  2843 						else
       
  2844     						{
       
  2845 							__LOG("CDataOwner::AddDBMSFilesL() - File is not applicable for this drive => file ignored");
       
  2846     						}
       
  2847 						} // for x
       
  2848 					
       
  2849 					// Cleanup	
       
  2850 					CleanupStack::PopAndDestroy(pFilenames);
       
  2851 					}
       
  2852 				else
       
  2853 					{
       
  2854 					__LOG2("CDataOwner::AddDBMSFilesL() - RDbs error %d SID: 0x%08x", err, iSecureId.iId);
       
  2855 					} // else
       
  2856 				} // for x
       
  2857 			
       
  2858 			// Cleanup
       
  2859 			CleanupStack::PopAndDestroy(&dbs);	
       
  2860 			} // if
       
  2861 		
       
  2862         __LOG2("CDataOwner::AddDBMSFilesL() - END - aDriveNumber: %c, owner: 0x%08x", aDriveNumber + 'A', iSecureId.iId);
       
  2863 		} // AddDBMSFiles
       
  2864 		
       
  2865 	/** Disables system data
       
  2866 	*/
       
  2867 	void CDataOwner::DisableSystemData()
       
  2868 		{
       
  2869 		iSystemInformation.iSupported = EFalse;
       
  2870 		} // Disable system data
       
  2871 		
       
  2872 	TInt CDataOwner::AddProxyToList(TProxyInformation aProxy)
       
  2873 	/** Adds proxy to list making sure there are no duplicates
       
  2874 	@param TProxyInformation Proxy to add 
       
  2875 	@return error if Append failes
       
  2876 	*/
       
  2877 		{
       
  2878 		TInt count = iProxyInformationArray.Count();
       
  2879 		TBool found = EFalse;
       
  2880 		
       
  2881 		while (count && !found)
       
  2882 			{
       
  2883 			--count;
       
  2884 			if (iProxyInformationArray[count].iSecureId == aProxy.iSecureId)
       
  2885 				{
       
  2886 				found = ETrue;
       
  2887 				}
       
  2888 			}
       
  2889 			
       
  2890 		TInt err = KErrNone;		
       
  2891 		if (!found)
       
  2892 			{
       
  2893 			err = iProxyInformationArray.Append(aProxy);
       
  2894 			__LOG2("Data owner(0x%08x): Adding Proxy(0x%08x) to the list", iSecureId.iId,aProxy.iSecureId.iId);
       
  2895 			}
       
  2896 		return err;
       
  2897 		}	
       
  2898 		
       
  2899 	void CDataOwner::CleanupBeforeRestoreL(TDriveNumber& aDriveNumber)
       
  2900 	/** Performs a cleanup before restore if required
       
  2901 	@param aDriveNumber drive to clear
       
  2902 	*/
       
  2903 		{
       
  2904         const TBool passiveDeleteBeforeRestore = iPassiveInformation.iDeleteBeforeRestore;
       
  2905         const TBool driveAlreadyCleaned = StateByDriveL(aDriveNumber).iDeleteBeforeRestorePerformed;
       
  2906 
       
  2907         __LOG4("CDataOwner::CleanupBeforeRestoreL() - START - aDriveNumber: %c, owner: 0x%08x, passiveDeleteBeforeRestore: %d, driveAlreadyCleaned: %d", aDriveNumber + 'A', iSecureId.iId, passiveDeleteBeforeRestore, driveAlreadyCleaned);
       
  2908 
       
  2909         if  ( passiveDeleteBeforeRestore && !driveAlreadyCleaned )
       
  2910 			{
       
  2911 			RSelections* selections = new(ELeave) RSelections();
       
  2912 			TCleanupItem cleanup(CleanupRPointerArray, selections);
       
  2913 			CleanupStack::PushL(cleanup);
       
  2914 			// The path to search for files to delete
       
  2915 			
       
  2916 			CSelection* selection = NULL;
       
  2917 			const TDesC& privatePath = *iPrivatePath;
       
  2918 			if (privatePath[0] == KBackSlash()[0])
       
  2919 				{
       
  2920 				selection = CSelection::NewLC(EInclude, privatePath);
       
  2921 				} // if
       
  2922 			else
       
  2923 				{
       
  2924 				selection = CSelection::NewLC(EInclude, privatePath.Right(privatePath.Length() - 2));
       
  2925 				} // else
       
  2926 			selections->AppendL(selection);
       
  2927 			CleanupStack::Pop(selection);
       
  2928 			
       
  2929 			// Find the files to delete
       
  2930 			CDesCArray* toDelete = new(ELeave) CDesCArrayFlat(KDesCArrayGranularity);
       
  2931 			CleanupStack::PushL(toDelete);
       
  2932 			
       
  2933 			BuildFileListL(*selections, aDriveNumber, EPassiveBaseData, EFalse, NULL, NULL, toDelete);
       
  2934 			
       
  2935 			// Loop through the files to delete, deleting them
       
  2936 			const TInt count = toDelete->Count();
       
  2937 			for (TInt x = 0; x < count; x++)
       
  2938 				{
       
  2939 				const TDesC& fileName = (*toDelete)[x];
       
  2940 
       
  2941 	            __LOG3("CDataOwner::CleanupBeforeRestoreL() - checking file[%2d/%2d] for match = %S", x + 1, count, &fileName);
       
  2942 
       
  2943                 // Check it is not a backup registration file
       
  2944 				if  ( fileName.MatchF(KBackupRegistrationFile) == KErrNotFound )
       
  2945 					{
       
  2946 					TInt deleteError=0;
       
  2947                     if((fileName[(fileName.Length())-1])== KBackSlash()[0])
       
  2948 						{
       
  2949 						  deleteError = ipDataOwnerManager->GetRFs().RmDir( fileName );
       
  2950 						}
       
  2951 					else
       
  2952 						{
       
  2953 						  deleteError = ipDataOwnerManager->GetRFs().Delete( fileName );
       
  2954 						}
       
  2955 					__LOG2("CDataOwner::CleanupBeforeRestoreL() - trying to deleting file %S (error was: %d)", &fileName, deleteError);
       
  2956 					User::LeaveIfError(deleteError);
       
  2957 					} // if
       
  2958 				} // for
       
  2959 			
       
  2960 			// Mark as done
       
  2961 			StateByDriveL(aDriveNumber).iDeleteBeforeRestorePerformed = ETrue;
       
  2962 			
       
  2963 			// Cleanup
       
  2964 			CleanupStack::PopAndDestroy(toDelete);
       
  2965 			CleanupStack::PopAndDestroy(selections);
       
  2966 			} // if
       
  2967 
       
  2968         __LOG2("CDataOwner::CleanupBeforeRestoreL() - END - aDriveNumber: %c, owner: 0x%08x", aDriveNumber + 'A', iSecureId.iId);
       
  2969 		} 
       
  2970 	/**
       
  2971 	Check if the file is in the include list
       
  2972 	
       
  2973 	@param TDesC& aFileName file name to check
       
  2974 	@return TBool ETrue if file is in the include list
       
  2975 	*/
       
  2976 	TBool CDataOwner::ValidFileL(const TDesC& aFileName)
       
  2977 		{
       
  2978         __LOG2("CDataOwner::ValidFileL() - START - owner: 0x%08x, aFileName: %S", iSecureId.iId, &aFileName);
       
  2979 
       
  2980         TInt include = EFalse;
       
  2981 		
       
  2982         const TInt count = iPassiveSelections.Count();
       
  2983 		for (TInt i =0; i < count; i++)
       
  2984 			{
       
  2985 			const TDesC& selectionName = iPassiveSelections[i]->SelectionName();
       
  2986 			TInt match = aFileName.FindF(selectionName);
       
  2987             __LOG5("CDataOwner::ValidFileL() - match result against file[%3d/%3d], selectionType: %d, matchResult: %d, name: %S", i+1, count, iPassiveSelections[i]->SelectionType(), match, &selectionName);
       
  2988             
       
  2989             if (match >= 0)
       
  2990 				{
       
  2991 				if (iPassiveSelections[i]->SelectionType() == EInclude)
       
  2992 					{
       
  2993                     __LOG("CDataOwner::ValidFileL() - file included");
       
  2994 					include = ETrue;
       
  2995 					}
       
  2996 				else
       
  2997 					{
       
  2998                     __LOG("CDataOwner::ValidFileL() - file excluded");
       
  2999 					include = EFalse;
       
  3000 					break;	
       
  3001 					} // else if
       
  3002 				} //if 
       
  3003 			
       
  3004 			} // for
       
  3005 			
       
  3006 
       
  3007         const TInt dbmsSelectionCount = iDBMSSelections.Count();
       
  3008 		if (dbmsSelectionCount && !include)
       
  3009 			{
       
  3010             __LOG1("CDataOwner::ValidFileL() - checking against %d DBMS files...", dbmsSelectionCount);
       
  3011 
       
  3012             for (TInt j = 0; j < dbmsSelectionCount; j++)
       
  3013 				{
       
  3014                 const TDesC& pDbmsFileName =  iDBMSSelections[j].Name();
       
  3015                 const TInt matchResult = aFileName.FindF( pDbmsFileName );
       
  3016 
       
  3017                 __LOG4("CDataOwner::ValidFileL() - checking against DBMS file[%2d/%2d] with result: %d (%S)...", j+1, dbmsSelectionCount, matchResult, &pDbmsFileName);
       
  3018 
       
  3019                 if  ( matchResult )
       
  3020 					{
       
  3021                     __LOG("CDataOwner::ValidFileL() - DBMS file included");
       
  3022 					include = ETrue;
       
  3023 					break;
       
  3024 					} // if
       
  3025 				}//for
       
  3026 			} // if
       
  3027 		
       
  3028         __LOG1("CDataOwner::ValidFileL() - END - valid file result is: %d", include);
       
  3029 		return include;
       
  3030 		}
       
  3031 		
       
  3032 	//	
       
  3033 	//  MContentHandler Implementaion //
       
  3034 	//
       
  3035 	
       
  3036 
       
  3037 
       
  3038 	void CDataOwner::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/, TInt aErrorCode)
       
  3039 	/** MContentHandler::OnStartDocumentL()
       
  3040 	*/
       
  3041 		{
       
  3042 		if (aErrorCode != KErrNone)
       
  3043 			{
       
  3044 			__LOG1("CDataOwner::OnStartDocumentL() - error = %d", aErrorCode);
       
  3045 			User::Leave(aErrorCode);
       
  3046 			}
       
  3047 		}
       
  3048 		
       
  3049 	void CDataOwner::OnEndDocumentL(TInt aErrorCode)
       
  3050 	/** MContentHandler::OnEndDocumentL()
       
  3051 	*/
       
  3052 		{
       
  3053 		if (aErrorCode != KErrNone)
       
  3054 			{
       
  3055 			// just to satifsy UREL compiler
       
  3056 			(void) aErrorCode;
       
  3057 			__LOG1("CDataOwner::OnEndDocumentL() - error = %d", aErrorCode);
       
  3058 			}
       
  3059 		}
       
  3060 		
       
  3061 	void CDataOwner::OnStartElementL(const RTagInfo& aElement, 
       
  3062 									  const RAttributeArray& aAttributes, 
       
  3063 									  TInt aErrorCode)
       
  3064 	/** MContentHandler::OnStartElementL()
       
  3065 
       
  3066 	@leave KErrUnknown an unknown element
       
  3067 	*/
       
  3068 		{
       
  3069 		if (aErrorCode != KErrNone)
       
  3070 			{
       
  3071 			__LOG1("CDataOwner::OnStartElementL() - error = %d", aErrorCode);
       
  3072 			User::LeaveIfError(aErrorCode);
       
  3073 			}
       
  3074 		
       
  3075 		TBool unknownElement = EFalse;
       
  3076 		const TDesC8& localName = aElement.LocalName().DesC();
       
  3077 		if (localName == KIncludeFile) 
       
  3078 			{
       
  3079 			HandlePathL(EInclude, aAttributes, EFalse);
       
  3080 			}
       
  3081 		else if (!localName.CompareF(KIncludeDirectory))
       
  3082 			{
       
  3083 			HandlePathL(EInclude, aAttributes, ETrue);
       
  3084 			}
       
  3085 		else if (!localName.CompareF(KExclude))
       
  3086 			{
       
  3087 			HandlePathL(EExclude, aAttributes, EFalse);
       
  3088 			}
       
  3089 		else if (!localName.CompareF(KBackupRegistration))
       
  3090 			{
       
  3091 			HandleBackupRegistrationL(aAttributes);
       
  3092 			}
       
  3093 		else if (!localName.CompareF(KDBMSBackup))
       
  3094 			{
       
  3095 			User::LeaveIfError(HandleDBMSBackupL(aAttributes));
       
  3096 			}
       
  3097 		else if (!localName.CompareF(KSystemBackup))
       
  3098 			{
       
  3099 			User::LeaveIfError(HandleSystemBackup(aAttributes));
       
  3100 			}
       
  3101 		else if (!localName.CompareF(KProxyDataManager))
       
  3102 			{
       
  3103 			User::LeaveIfError(HandleProxyDataManager(aAttributes));
       
  3104 			}
       
  3105 		else if (!localName.CompareF(KCenrepBackup))
       
  3106 			{
       
  3107 			User::LeaveIfError(HandleCenrepBackup(aAttributes));
       
  3108 			}
       
  3109 		else if (!localName.CompareF(KPublicBackup))
       
  3110 			{
       
  3111 			iCurrentElement = EPublic;
       
  3112 			User::LeaveIfError(HandlePublicBackup(aAttributes));
       
  3113 			}
       
  3114 		else if (!localName.CompareF(KPassiveBackup))
       
  3115 			{
       
  3116 			iCurrentElement = EPassive;
       
  3117 			// Only allow passive to be switched on in primary files
       
  3118 			if (iPrimaryFile)
       
  3119 				{
       
  3120 				User::LeaveIfError(HandlePassiveBackup(aAttributes));
       
  3121 				}
       
  3122 			}
       
  3123 		else if (iPrimaryFile) 
       
  3124 			{
       
  3125 			// These remaining elements are only allowed in primary files
       
  3126 			if (!localName.CompareF(KActiveBackup))
       
  3127 				{
       
  3128 				User::LeaveIfError(HandleActiveBackupL(aAttributes));
       
  3129 				}
       
  3130 			else if (!localName.CompareF(KRestore))
       
  3131 				{
       
  3132 				User::LeaveIfError(HandleRestore(aAttributes));
       
  3133 				}
       
  3134 			else 
       
  3135 				{
       
  3136 				unknownElement = ETrue;
       
  3137 				}
       
  3138 			} // if primary file true
       
  3139 		else
       
  3140 			{
       
  3141 			unknownElement = ETrue;
       
  3142 			}
       
  3143 			
       
  3144 		if (unknownElement)
       
  3145 			{
       
  3146 			__LOG1("CDataOwner::OnStartElementL() - Unknown element while parsing 0x%08x", iSecureId.iId);
       
  3147 			}
       
  3148 		}
       
  3149 
       
  3150 	
       
  3151 	void CDataOwner::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode)
       
  3152 	/** MContentHandler::OnEndElementL()
       
  3153 	*/
       
  3154 		{
       
  3155 		if (aErrorCode != KErrNone)
       
  3156 			{
       
  3157 			__LOG1("CDataOwner::OnEndElementL() - error = %d", aErrorCode);
       
  3158 			User::Leave(aErrorCode);
       
  3159 			}
       
  3160 		
       
  3161 		const TDesC8& localName = aElement.LocalName().DesC();
       
  3162 		if (!localName.CompareF(KPassiveBackup))
       
  3163 			{
       
  3164 			iCurrentElement = ENoElement;
       
  3165 			} // if
       
  3166 		else if (localName == KPublicBackup)
       
  3167 			{
       
  3168 			iCurrentElement = ENoElement;
       
  3169 			} // else if
       
  3170 		}
       
  3171 
       
  3172 	void CDataOwner::OnContentL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
       
  3173 	/** MContentHandler::OnContentL()
       
  3174 	*/
       
  3175 		{
       
  3176 		// Not handled
       
  3177 		}
       
  3178 
       
  3179 	void CDataOwner::OnStartPrefixMappingL(const RString& /*aPrefix*/, 
       
  3180 											const RString& /*aUri*/, TInt /*aErrorCode*/)
       
  3181 	/** MContentHandler::OnStartPrefixMappingL()
       
  3182 	*/
       
  3183 		{
       
  3184 		// Not handled
       
  3185 		}
       
  3186 
       
  3187 	void CDataOwner::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/)
       
  3188 	/** MContentHandler::OnEndPrefixMappingL()
       
  3189 	*/
       
  3190 		{
       
  3191 		// Not handled
       
  3192 		}
       
  3193 
       
  3194 	void CDataOwner::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
       
  3195 	/** MContentHandler::OnIgnorableWhiteSpaceL()
       
  3196 	*/
       
  3197 		{
       
  3198 		// Not handled
       
  3199 		}
       
  3200 
       
  3201 	void CDataOwner::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/)
       
  3202 	/** MContentHandler::OnSkippedEntityL()
       
  3203 	*/
       
  3204 		{
       
  3205 		// Not handled
       
  3206 		}
       
  3207 
       
  3208 	void CDataOwner::OnProcessingInstructionL(const TDesC8& /*aTarget*/, 
       
  3209 											   const TDesC8& /*aData*/, 
       
  3210 											   TInt /*aErrorCode*/)
       
  3211 	/** MContentHandler::OnProcessingInstructionL()
       
  3212 	*/
       
  3213 		{
       
  3214 		// Not handled
       
  3215 		}
       
  3216 
       
  3217 	void CDataOwner::OnError(TInt aErrorCode)
       
  3218 	/** MContentHandler::OnError()
       
  3219 
       
  3220 	@leave aErrorCode
       
  3221 	*/
       
  3222 		{
       
  3223 		(void)aErrorCode;
       
  3224 		__LOG1("CDataOwner::OnError() - error = %d", aErrorCode);
       
  3225 		}
       
  3226 
       
  3227 	TAny* CDataOwner::GetExtendedInterface(const TInt32 /*aUid*/)
       
  3228 	/** MContentHandler::OnEndPrefixMappingL()
       
  3229 	*/
       
  3230 		{
       
  3231 		return NULL;
       
  3232 		}
       
  3233 
       
  3234 	void CDataOwner::HandleBackupRegistrationL(const RAttributeArray& aAttributes)
       
  3235 	/** Handles the "backup_registration" element
       
  3236 
       
  3237 	@param aAttributes the attributes for the element
       
  3238 	@return KErrNone no errors
       
  3239 	@return KErrUnknown unknown version
       
  3240 	*/
       
  3241 		{
       
  3242 		if (aAttributes.Count() == 1)
       
  3243 			{
       
  3244 			// Check the version is correct.
       
  3245 			if (aAttributes[0].Value().DesC() != KVersion()) // Only version we know about
       
  3246 				{
       
  3247 				__LOG1("CDataOwner::HandleBackupRegistrationL() - Unknown version at SID(0x%08x)", iSecureId.iId);
       
  3248 				User::Leave(KErrNotSupported);
       
  3249 				} // else
       
  3250 			} // if
       
  3251 		}
       
  3252 
       
  3253 
       
  3254 	TInt CDataOwner::HandlePassiveBackup(const RAttributeArray& aAttributes)
       
  3255 	/** Handles the "passive_backup" element
       
  3256 
       
  3257 	@param aAttributes the attributes for the element
       
  3258 	@return KErrNone
       
  3259 	*/
       
  3260 		{
       
  3261 		iPassiveInformation.iSupported = ETrue;
       
  3262 		
       
  3263 		// Loop through reading out attribute values
       
  3264 		const TInt count = aAttributes.Count();
       
  3265 		for (TInt x = 0; x < count; x++)
       
  3266 			{
       
  3267 			const TDesC8& localName = aAttributes[x].Attribute().LocalName().DesC();
       
  3268 
       
  3269             if  ( localName.CompareF(KSupportsSelective) == 0 )
       
  3270 				{
       
  3271                 const TBool supportsSelective = ( aAttributes[x].Value().DesC().CompareF(KYes) == 0 );
       
  3272 				iPassiveInformation.iSupportsSelective = supportsSelective;
       
  3273 				__LOG2("CDataOwner::HandlePassiveBackup(0x%08x) - iPassiveInformation.iSupportsSelective: %d", iSecureId.iId, supportsSelective);
       
  3274                 } // if
       
  3275 			else if ( localName.CompareF(KDeleteBeforeRestore) == 0 )
       
  3276 				{
       
  3277 				// AW This logic looks somewhat strange.
       
  3278 				if (!aAttributes[x].Value().DesC().CompareF(KYes))
       
  3279 					{
       
  3280 				    __LOG1("CDataOwner::HandlePassiveBackup(0x%08x) - iPassiveInformation.iDeleteBeforeRestore: ETrue", iSecureId.iId);
       
  3281 					iPassiveInformation.iDeleteBeforeRestore |= ETrue;
       
  3282 					} // if
       
  3283 				else
       
  3284 					{
       
  3285 				    __LOG1("CDataOwner::HandlePassiveBackup(0x%08x) - iPassiveInformation.iDeleteBeforeRestore: EFalse", iSecureId.iId);
       
  3286 					iPassiveInformation.iDeleteBeforeRestore |= EFalse;
       
  3287 					} // else
       
  3288 				} // else if
       
  3289 			else if ( localName.CompareF(KBaseBackupOnly) == 0 )
       
  3290 				{
       
  3291                 const TBool baseBackupOnly = ( aAttributes[x].Value().DesC().CompareF(KYes) == 0 );
       
  3292 				iPassiveInformation.iBaseBackupOnly = baseBackupOnly;
       
  3293 				__LOG2("CDataOwner::HandlePassiveBackup(0x%08x) - iPassiveInformation.iBaseBackupOnly: %d", iSecureId.iId, baseBackupOnly);
       
  3294 				} // else if
       
  3295 			else
       
  3296 				{
       
  3297 				__LOG1("CDataOwner::HandlePassiveBackup() - Unknown element while parsing 0x%08x", iSecureId.iId);
       
  3298 				} // else
       
  3299 			} // for x
       
  3300 		
       
  3301 		return KErrNone;
       
  3302 		}
       
  3303 
       
  3304 
       
  3305 	TInt CDataOwner::HandlePublicBackup(const RAttributeArray& aAttributes)
       
  3306 	/** Handles the "public_backup" element
       
  3307 
       
  3308 	@param aAttributes the attributes for the element
       
  3309 	@return KErrNone
       
  3310 	*/
       
  3311 		{
       
  3312 		iPublicInformation.iSupported = ETrue;
       
  3313 		
       
  3314 		if (aAttributes.Count() > 0)
       
  3315 			{
       
  3316             const TBool deleteBeforeRestore = ( aAttributes[0].Value().DesC().CompareF(KYes) == 0 );
       
  3317 			iPublicInformation.iDeleteBeforeRestore = deleteBeforeRestore;
       
  3318 			__LOG2("CDataOwner::HandlePublicBackup(0x%08x) - iPublicInformation.iDeleteBeforeRestore: %d", iSecureId.iId, deleteBeforeRestore);
       
  3319 			} // if
       
  3320 		
       
  3321 		return KErrNone;
       
  3322 		}
       
  3323 
       
  3324 	TInt CDataOwner::HandleSystemBackup(const RAttributeArray& /*aAttributes*/)
       
  3325 	/** Handles the "system_backup" element
       
  3326 
       
  3327 	@param aAttributes the attributes for the element
       
  3328 	@return KErrNone
       
  3329 	*/
       
  3330 		{
       
  3331 		iSystemInformation.iSupported = ETrue;
       
  3332 		__LOG2("CDataOwner::HandleSystemBackup(0x%08x) - iSystemInformation.iSupported: %d", iSecureId.iId, iSystemInformation.iSupported);
       
  3333 
       
  3334 		return KErrNone;	
       
  3335 		}
       
  3336 
       
  3337 
       
  3338 	TInt CDataOwner::HandleCenrepBackup(const RAttributeArray& /*aAttributes*/)
       
  3339 	/** Handles the "cenrep_backup" element
       
  3340 
       
  3341 	@param aAttributes the attributes for the element
       
  3342 	@return KErrNone
       
  3343 	*/
       
  3344 		{
       
  3345 		TInt err = KErrNone;
       
  3346 		TProxyInformation proxyInformation;
       
  3347 		
       
  3348 		proxyInformation.iSecureId = ipDataOwnerManager->Config().CentRepId();
       
  3349 
       
  3350 		err = AddProxyToList(proxyInformation);
       
  3351 		
       
  3352 		if (err == KErrNone)
       
  3353 			{
       
  3354 			
       
  3355 			if (iActiveInformation.iSupported == EFalse)
       
  3356 				{
       
  3357 				iActiveInformation.iSupported = ETrue;
       
  3358 				iActiveInformation.iSupportsIncremental = EFalse;
       
  3359 				iStatus = EDataOwnerNotConnected;
       
  3360 				}
       
  3361 				
       
  3362 			}
       
  3363 		
       
  3364 		__LOG2("CDataOwner::HandleCenrepBackup(0x%08x) - proxy creation error: %d", iSecureId.iId, err);
       
  3365 		return err;
       
  3366 		}
       
  3367 
       
  3368 	TInt CDataOwner::HandleProxyDataManager(const RAttributeArray& aAttributes)
       
  3369 	/** Handles the "proxy_data_manager" element
       
  3370 
       
  3371 	@param aAttributes the attributes for the element
       
  3372 	@return KErrNone
       
  3373 	*/
       
  3374 		{	
       
  3375 		TInt err = KErrNone;
       
  3376 		
       
  3377 		TProxyInformation proxyInformation;
       
  3378 		
       
  3379 		const TDesC8& localName = aAttributes[0].Attribute().LocalName().DesC();
       
  3380 		if (!localName.CompareF(KProxySID))
       
  3381 			{
       
  3382 			// The value returned from the XML element attribute parse
       
  3383 			const TDesC8& hexString = aAttributes[0].Value().DesC();
       
  3384 			TPtrC8 strippedSID;
       
  3385 			
       
  3386 			// Test for lower case hex leader chars
       
  3387 			TInt result = hexString.FindF(KHexLeader);
       
  3388 
       
  3389 			if (result != KErrNotFound)
       
  3390 				{
       
  3391 				if (hexString.Length() < (result + KHexLeader().Size()))
       
  3392 					{
       
  3393 					__LOG1("CDataOwner::HandleProxyDataManager() - The Hex number has incorrect number of digits", iSecureId.iId);
       
  3394 					}
       
  3395 				// Strip off the preceeding upper case hex leader characters
       
  3396 				strippedSID.Set(hexString.Mid(result + KHexLeader().Size()));
       
  3397 				}
       
  3398 			else
       
  3399 				{
       
  3400 				// There were no leading characters in the data
       
  3401 				strippedSID.Set(hexString);
       
  3402 				}
       
  3403 			
       
  3404 			TLex8 sIdLex(strippedSID);
       
  3405 			err = sIdLex.Val(proxyInformation.iSecureId.iId, EHex);
       
  3406 			
       
  3407 			if (err == KErrNone && proxyInformation.iSecureId.iId != iSecureId.iId)
       
  3408 				{
       
  3409 				err = AddProxyToList(proxyInformation);
       
  3410 				
       
  3411 				if (err == KErrNone)
       
  3412 					{
       
  3413 					if (iActiveInformation.iSupported == EFalse)
       
  3414 						{
       
  3415 						iActiveInformation.iSupported = ETrue;
       
  3416 						iActiveInformation.iSupportsIncremental = EFalse;
       
  3417 						iStatus = EDataOwnerNotConnected;
       
  3418 						}
       
  3419 					}
       
  3420         		
       
  3421                 __LOG3("CDataOwner::HandleProxyDataManager(0x%08x) - proxy creation error: %d for proxySid: 0x%08x", iSecureId.iId, err, proxyInformation.iSecureId.iId);
       
  3422 				}
       
  3423 			else 
       
  3424 				{
       
  3425 				__LOG1("CDataOwner::HandleProxyDataManager() - Not a Hex Number specified in reg_file of 0x%08x)", iSecureId.iId);
       
  3426 				err = KErrNone;		// We shouldn't return an error unless Append has errored (OOM etc.)
       
  3427 				}
       
  3428 			} // else it's corrupt - don't error, just ignore this attribute
       
  3429 		
       
  3430 		return err;
       
  3431 		}
       
  3432 
       
  3433 	TInt CDataOwner::HandleDBMSBackupL(const RAttributeArray& aAttributes)
       
  3434 	/** Handles the "dbms_backup" element
       
  3435 
       
  3436 	@param aAttributes the attributes for the element
       
  3437 	@return KErrNone
       
  3438 	*/
       
  3439 		{
       
  3440 		iPassiveInformation.iSupported = ETrue;
       
  3441 		
       
  3442 		const TInt count = aAttributes.Count();
       
  3443 		for (TInt x = 0; x < count; x++)
       
  3444 			{
       
  3445 			const TDesC8& localName = aAttributes[x].Attribute().LocalName().DesC();
       
  3446 			if (localName.Length() > 0)
       
  3447 				{
       
  3448 				if (!localName.CompareF(KDatabase))
       
  3449 					{
       
  3450 					__LOG1("CDataOwner::HandleDBMSBackup(0x%08x) - Still using deprecated 'database' attribute", iSecureId.iId);
       
  3451 					}
       
  3452 				else if (!localName.CompareF(KPolicy))
       
  3453 					{
       
  3454 					TName policy;
       
  3455 					if (KErrNone == ipDataOwnerManager->ParserProxy().ConvertToUnicodeL(policy, aAttributes[x].Value().DesC()))
       
  3456 						{
       
  3457 						TLex lex(policy);
       
  3458 						TUint32 temp;
       
  3459 						lex.Val(temp, EHex);
       
  3460 						
       
  3461 						// Check we have not seen this Uid before
       
  3462 						const TInt count = iDBMSSelections.Count();
       
  3463 						TBool toAdd = ETrue;
       
  3464 						for (TInt x = 0; toAdd && (x < count); x++)
       
  3465 							{
       
  3466 							if (iDBMSSelections[x].iUid == temp)
       
  3467 								{
       
  3468 								toAdd = EFalse;
       
  3469 								} // if
       
  3470 							} // for
       
  3471 						
       
  3472 						// Add to list of Uid's
       
  3473 						if (toAdd)
       
  3474 							{
       
  3475         					__LOG2("CDataOwner::HandleDBMSBackup(0x%08x) - adding database with policy uid: 0x%08x", iSecureId.iId, temp);
       
  3476 							TUid tempUID;
       
  3477 							tempUID.iUid = temp;
       
  3478 							TRAP_IGNORE(iDBMSSelections.AppendL(tempUID));
       
  3479 							} // if
       
  3480 						} // if
       
  3481 					else
       
  3482 						{
       
  3483 						__LOG1("CDataOwner::HandleDBMSBackup(0x%08x) - Error converting policy number", iSecureId.iId);
       
  3484 						} // else
       
  3485 					} // else if
       
  3486 				} // if
       
  3487 			else
       
  3488 				{
       
  3489 				__LOG1("CDataOwner::HandleDBMSBackup(0x%08x) - Incorrect use of attributes", iSecureId.iId);
       
  3490 				}
       
  3491 			} // for x
       
  3492 			
       
  3493 		return KErrNone;
       
  3494 	}
       
  3495 
       
  3496 	TInt CDataOwner::HandleActiveBackupL(const RAttributeArray& aAttributes)
       
  3497 	/** Handles the "active_backup" element
       
  3498 
       
  3499 	@param aAttributes the attributes for the element
       
  3500 	@return KErrNone
       
  3501 	*/
       
  3502 		{
       
  3503 		iActiveInformation.iSupported = ETrue;
       
  3504 		iActiveInformation.iActiveDataOwner = ETrue;
       
  3505 		iStatus = EDataOwnerNotConnected;
       
  3506 		
       
  3507 		const TInt count = aAttributes.Count();
       
  3508 		for (TInt x = 0; (iActiveInformation.iSupported && (x < count)); x++)
       
  3509 			{
       
  3510 			const TDesC8& localName = aAttributes[x].Attribute().LocalName().DesC();
       
  3511 			if (!localName.CompareF(KProcessName))
       
  3512 				{
       
  3513 				if (KErrNone != ipDataOwnerManager->ParserProxy().ConvertToUnicodeL(iActiveInformation.iProcessName, aAttributes[x].Value().DesC()))
       
  3514 					{
       
  3515 					iActiveInformation.iSupported = EFalse;
       
  3516 					__LOG1("CDataOwner::HandleActiveBackup(0x%08x) - Error converting process name", iSecureId.iId);
       
  3517 					}
       
  3518 				}
       
  3519 			else if (!localName.CompareF(KRequiresDelay))
       
  3520 				{
       
  3521                 const TBool required = ( aAttributes[x].Value().DesC().CompareF(KYes) == 0 );
       
  3522 				iActiveInformation.iRequiresDelayToPrepareData = required;
       
  3523 				__LOG2("CDataOwner::HandleActiveBackup(0x%08x) - iActiveInformation.iRequiresDelayToPrepareData: %d", iSecureId.iId, required);
       
  3524 				} // else if
       
  3525 			else if (!localName.CompareF(KSupportsSelective))
       
  3526 				{
       
  3527                 const TBool required = ( aAttributes[x].Value().DesC().CompareF(KYes) == 0 );
       
  3528 				iActiveInformation.iSupportsSelective = required;
       
  3529 				__LOG2("CDataOwner::HandleActiveBackup(0x%08x) - iActiveInformation.iSupportsSelective: %d", iSecureId.iId, required);
       
  3530 				} // else if
       
  3531 			else if (!localName.CompareF(KSupportsInc))
       
  3532 				{
       
  3533                 const TBool required = ( aAttributes[x].Value().DesC().CompareF(KYes) == 0 );
       
  3534 				iActiveInformation.iSupportsIncremental = required;
       
  3535 				__LOG2("CDataOwner::HandleActiveBackup(0x%08x) - iActiveInformation.iSupportsIncremental: %d", iSecureId.iId, required);
       
  3536 				} // else if
       
  3537 			else if (!localName.CompareF(KActiveType))
       
  3538 				{
       
  3539 				const TDesC8& value = aAttributes[x].Value().DesC();
       
  3540 				if (!value.CompareF(KActiveOnly))
       
  3541 					{
       
  3542     				__LOG1("CDataOwner::HandleActiveBackup(0x%08x) - iActiveInformation.iActiveType: EActiveOnly", iSecureId.iId);
       
  3543 					iActiveInformation.iActiveType = EActiveOnly;
       
  3544 					}
       
  3545 				else if (!value.CompareF(KActiveAndProxy))
       
  3546 					{
       
  3547     				__LOG1("CDataOwner::HandleActiveBackup(0x%08x) - iActiveInformation.iActiveType: EActiveAndProxyImpl", iSecureId.iId);
       
  3548 					iActiveInformation.iActiveType = EActiveAndProxyImpl;
       
  3549 					}
       
  3550 				else if (!value.CompareF(KProxyOnly))
       
  3551 					{
       
  3552     				__LOG1("CDataOwner::HandleActiveBackup(0x%08x) - iActiveInformation.iActiveType: EProxyImpOnly", iSecureId.iId);
       
  3553 					iActiveInformation.iActiveType = EProxyImpOnly;
       
  3554 					}
       
  3555 				}
       
  3556 			} // for x
       
  3557 		
       
  3558 		return KErrNone;
       
  3559 		}
       
  3560 
       
  3561 
       
  3562 	TInt CDataOwner::HandleRestore(const RAttributeArray& aAttributes)
       
  3563 	/** Handles the "restore" element
       
  3564 
       
  3565 	@param aAttributes the attributes for the element
       
  3566 	@return KErrNone
       
  3567 	*/
       
  3568 		{
       
  3569 		iRestoreInformation.iSupported = ETrue;
       
  3570 		
       
  3571 		if (aAttributes.Count() == 1)
       
  3572 			{
       
  3573 			if (!aAttributes[0].Attribute().LocalName().DesC().CompareF(KRequiresReboot))
       
  3574 				{
       
  3575                 const TBool required = ( aAttributes[0].Value().DesC().CompareF(KYes) == 0 );
       
  3576 				iRestoreInformation.iRequiresReboot = required;
       
  3577 				__LOG2("CDataOwner::HandleRestore(0x%08x) - iRestoreInformation.iRequiresReboot: %d", iSecureId.iId, required);
       
  3578 				} // if
       
  3579 			} // if
       
  3580 		
       
  3581 		return KErrNone;
       
  3582 		}
       
  3583 
       
  3584 
       
  3585 	void CDataOwner::HandlePathL(const TSelectionType aType, 
       
  3586 								  const RAttributeArray& aAttributes,
       
  3587 								  const TBool aDir)
       
  3588 	/** Handles the "include_file", "include_directory" and "exclude" elements
       
  3589 
       
  3590 	@param aType The selection type 
       
  3591 	@param aAttributes The attributes for the element
       
  3592 	@param aDir The element was found in an <include_dir/> element?
       
  3593 	*/
       
  3594 		{
       
  3595 		// Check we dont have a NULL string
       
  3596 		if (aAttributes[0].Value().DesC().Length() > 0)
       
  3597 			{
       
  3598 			TFileName filename;
       
  3599 			if (KErrNone != ipDataOwnerManager->ParserProxy().ConvertToUnicodeL(filename, aAttributes[0].Value().DesC()))
       
  3600 				{
       
  3601 				__LOG1("CDataOwner::HandlePathL(0x%08x) - EPassive - Could not convert filename", iSecureId.iId);
       
  3602 				return;
       
  3603 				}
       
  3604 			else
       
  3605 				{
       
  3606 				__LOG3("CDataOwner::HandlePathL(0x%08x) - path in the registration file is: %S [type: %d]", iSecureId.iId, &filename, aType);
       
  3607 				}
       
  3608 				
       
  3609 			// If it is a directory is do we add a trailing backslash,
       
  3610 			if (aDir && (filename[filename.Length() - 1] != '\\'))
       
  3611 				{
       
  3612 				filename.Append(KBackSlash);
       
  3613 				} // if	
       
  3614 				
       
  3615 	
       
  3616 			switch (iCurrentElement)
       
  3617 				{
       
  3618 			case EPassive:
       
  3619 					{
       
  3620 					TFileName selectionName;
       
  3621 					// first check for absolute path
       
  3622 					TInt offset = filename.FindC(*iPrivatePath);
       
  3623 					if (offset == KErrNotFound)
       
  3624 						{
       
  3625 						//check for collon path
       
  3626 						offset = filename.FindC(KColon);
       
  3627 						if (offset != KErrNotFound)
       
  3628 							{
       
  3629 							// someone other absoulute path
       
  3630 							__LOG2("CDataOwner::HandlePathL(0x%08x) - Path is not recognised by the data owner : %S", iSecureId.iId, &filename);
       
  3631 							return;
       
  3632 							}
       
  3633 						else
       
  3634 							{
       
  3635 							selectionName = *iPrivatePath;
       
  3636 							if (filename[0] == '\\')
       
  3637 								{
       
  3638 								// the filename begins with \, thefore we need to chop it off
       
  3639 								selectionName.SetLength(selectionName.Length() - 1);
       
  3640 								}
       
  3641 							selectionName.Append(filename);
       
  3642 							}
       
  3643 						}
       
  3644 					else
       
  3645 						{
       
  3646 						// get the path but not the drive (e.g c:) 
       
  3647 						selectionName.Copy(filename.Right(filename.Length() - offset) );
       
  3648 						}
       
  3649 						
       
  3650 					CSelection* selection = CSelection::NewLC(aType, selectionName);
       
  3651 					iPassiveSelections.AppendL(selection);
       
  3652 					CleanupStack::Pop(selection);
       
  3653 					__LOG3("CDataOwner::HandlePathL(0x%08x) - Added selection: %S [type: %d]", iSecureId.iId, &selectionName, aType);
       
  3654 					break;
       
  3655 					}
       
  3656 			case EPublic:
       
  3657 					{
       
  3658 					// check if path relative or absolute
       
  3659 					if (filename.FindC(KColon) != KErrNotFound)
       
  3660 						{
       
  3661 						CSelection* selection = CSelection::NewLC(aType, filename);
       
  3662 						iPublicSelections.AppendL(selection);
       
  3663 						CleanupStack::Pop(selection);
       
  3664 						__LOG3("CDataOwner::HandlePathL(0x%08x) - Added selection: %S [type: %d]", iSecureId.iId, &filename, aType);
       
  3665 						}
       
  3666 					else
       
  3667 						{
       
  3668 						__LOG3("CDataOwner::HandlePathL(0x%08x) - Not an Absolute Path: %S [type: %d]", iSecureId.iId, &filename, aType);
       
  3669 						return;
       
  3670 						}
       
  3671 					break;
       
  3672 					}
       
  3673 				} // switch
       
  3674 			} // if
       
  3675 		else
       
  3676 			{
       
  3677 			__LOG1("CDataOwner::HandlePathL(0x%08x) - Path attribute error", iSecureId.iId);
       
  3678 			} // else
       
  3679 		}
       
  3680 		
       
  3681 		
       
  3682 	CSnapshotHolder* CSnapshotHolder::NewL()
       
  3683 	/** Symbain OS constructor
       
  3684 
       
  3685 	@return a CSnapshotHolder object
       
  3686 	*/
       
  3687 		{
       
  3688 		CSnapshotHolder* self = NewLC();
       
  3689 		CleanupStack::Pop(self);
       
  3690 		
       
  3691 		return self;
       
  3692 		}
       
  3693 
       
  3694 	CSnapshotHolder* CSnapshotHolder::NewLC()
       
  3695 	/** Symbain OS constructor
       
  3696 	
       
  3697 	@return a CSnapshotHolder object
       
  3698 	*/
       
  3699 		{
       
  3700 		CSnapshotHolder* self = new(ELeave) CSnapshotHolder();
       
  3701 		CleanupStack::PushL(self);
       
  3702 		
       
  3703 		return self;
       
  3704 		}
       
  3705 		
       
  3706 	CSnapshotHolder::CSnapshotHolder()
       
  3707 	/** Default C++ Constructor
       
  3708 	*/
       
  3709 		{
       
  3710 		}
       
  3711 		
       
  3712 	CSnapshotHolder::~CSnapshotHolder()
       
  3713 	/** Default C++ Constructor
       
  3714 	*/
       
  3715 		{
       
  3716 		iSnapshots.ResetAndDestroy();
       
  3717 		}
       
  3718 			
       
  3719 		
       
  3720 	} // namespace conn
       
  3721 
       
  3722