sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "cregen.h" sl@0: #include "heaprepos.h" sl@0: #include "srvparams.h" sl@0: sl@0: _LIT(KTmpExtension,"tmp"); sl@0: sl@0: void CCreGenerator::CommitChangesToCreL(RFs& aFs,TUint8 aPersistVersion,CHeapRepository& aRep,const TDesC& aTargetFilePath) sl@0: { sl@0: HBufC* tmpFilePath=aTargetFilePath.AllocLC(); sl@0: TPtr tmpFilePathPtr(tmpFilePath->Des()); sl@0: tmpFilePathPtr.Replace(tmpFilePath->Length()-3,3,KTmpExtension()); sl@0: sl@0: CDirectFileStore* store = CDirectFileStore::ReplaceLC(aFs, *tmpFilePath,(EFileWrite | EFileShareExclusive)); sl@0: sl@0: const TUid uid2 = KNullUid ; sl@0: store->SetTypeL(TUidType(KDirectFileStoreLayoutUid, uid2, KServerUid3)) ; sl@0: sl@0: // Write the stream index/dictionary as root stream within the store sl@0: // so we can access it when we do a restore later on sl@0: RStoreWriteStream rootStream ; sl@0: TStreamId rootStreamId = rootStream.CreateLC(*store) ; sl@0: ExternalizeCre(aPersistVersion,aRep, rootStream) ; sl@0: rootStream.CommitL() ; sl@0: sl@0: CleanupStack::PopAndDestroy(&rootStream) ; sl@0: store->SetRootL(rootStreamId); sl@0: store->CommitL(); sl@0: CleanupStack::PopAndDestroy(store) ; sl@0: User::LeaveIfError(aFs.Replace(*tmpFilePath,aTargetFilePath)); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: void CCreGenerator::CreateReposFromCreL(RFs& aFs,CHeapRepository& aRep, const TDesC& aFilePath sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,TUint8& aCreVersion sl@0: #endif sl@0: ) sl@0: { sl@0: RFile file; sl@0: TInt err = file.Open(aFs,aFilePath,EFileRead|EFileShareReadersOnly); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: if(err ==KErrNotFound || err==KErrPathNotFound) sl@0: User::Leave(KErrNotFound); sl@0: else sl@0: User::Leave(err); sl@0: } sl@0: sl@0: CleanupClosePushL(file); sl@0: sl@0: CDirectFileStore* store = CDirectFileStore::FromLC (file); sl@0: if(store->Type()[0] != KDirectFileStoreLayoutUid) sl@0: { sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: sl@0: // Get the root stream and attempt to read the index from it sl@0: TStreamId rootStreamId = store->Root() ; sl@0: RStoreReadStream rootStream ; sl@0: rootStream.OpenLC(*store, rootStreamId); sl@0: // Internalize the repository sl@0: InternalizeCreL(aRep, rootStream sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,aCreVersion sl@0: #endif sl@0: ); sl@0: CleanupStack::PopAndDestroy(3, &file); sl@0: } sl@0: sl@0: void CCreGenerator::ExternalizeCre(TUint8 aPersistVersion,const CHeapRepository& aRep, RWriteStream& aStream) sl@0: { sl@0: aStream << aPersistVersion; sl@0: aStream << aRep.iUid ; sl@0: aStream << aRep.iOwner ; sl@0: sl@0: TUint32 count=aRep.iSinglePolicies.Count(); sl@0: aStream << count; sl@0: for(TUint32 i=0; iPackage() ; sl@0: aStream << aRep.iDefaultPolicy.GetWriteAccessPolicy()->Package() ; sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: if (aPersistVersion>=KPersistFormatSupportsIndMetaIndicator) sl@0: { sl@0: aStream << aRep.iDefaultPolicy.HighKey(); sl@0: aStream << aRep.iDefaultPolicy.KeyMask(); sl@0: } sl@0: #endif sl@0: sl@0: aStream << aRep.iDefaultMeta ; sl@0: aStream << aRep.iRangeMeta ; sl@0: aStream << aRep.iTimeStamp.Int64() ; sl@0: sl@0: aStream << aRep.iSettings ; sl@0: sl@0: // Deleted settings sl@0: count = aRep.iDeletedSettings.Count() ; sl@0: aStream << count ; sl@0: for (TUint32 i=0; i> version; sl@0: sl@0: // Check the UID is the same as that expected. sl@0: // UID should always be correctly initialised by the time we reach sl@0: // this point. sl@0: TUid tempUid; sl@0: aStream >> tempUid; sl@0: sl@0: if (tempUid != aRep.iUid) sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CSharedRepository::InternalizeCreL - expected UID (from filename) - %08X, UID extracted from binary file - %08X "), aRep.iUid.iUid, tempUid.iUid); sl@0: #endif sl@0: User::Leave(KErrCorrupt); sl@0: } sl@0: sl@0: aStream >> aRep.iOwner ; sl@0: sl@0: TUint32 count; sl@0: aStream >> count; sl@0: for(TUint32 i=0; i> *singlePolicy; sl@0: aRep.iSinglePolicies.AppendL(singlePolicy); sl@0: CleanupStack::Pop(singlePolicy); sl@0: } sl@0: sl@0: aRep.iRangePolicies.Reset(); sl@0: aStream >> aRep.iRangePolicies ; sl@0: sl@0: HBufC8* securityPolicyPackage ; sl@0: securityPolicyPackage = HBufC8::NewLC(aStream, 10000) ; sl@0: TSecurityPolicy defaultReadPolicy; sl@0: defaultReadPolicy.Set(securityPolicyPackage->Des()) ; sl@0: CleanupStack::PopAndDestroy(securityPolicyPackage) ; sl@0: securityPolicyPackage = HBufC8::NewLC(aStream, 10000) ; sl@0: TSecurityPolicy defaultWritePolicy; sl@0: defaultWritePolicy.Set(securityPolicyPackage->Des()) ; sl@0: CleanupStack::PopAndDestroy(securityPolicyPackage) ; sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: aCreVersion=version; sl@0: TUint32 highKey=0; sl@0: TUint32 keyMask=0; sl@0: if (aCreVersion>=KPersistFormatSupportsIndMetaIndicator) sl@0: { sl@0: aStream >> highKey; sl@0: aStream >> keyMask; sl@0: } sl@0: aRep.iDefaultPolicy=TSettingsAccessPolicy(defaultReadPolicy,defaultWritePolicy, KUnspecifiedKey,highKey,keyMask); sl@0: #else sl@0: aRep.iDefaultPolicy=TSettingsAccessPolicy(defaultReadPolicy,defaultWritePolicy, KUnspecifiedKey); sl@0: #endif sl@0: aStream >> aRep.iDefaultMeta ; sl@0: sl@0: aRep.iRangeMeta.Reset(); sl@0: aStream >> aRep.iRangeMeta ; sl@0: sl@0: TInt64 timeStampInt ; sl@0: aStream >> timeStampInt ; sl@0: aRep.iTimeStamp = timeStampInt ; sl@0: sl@0: aRep.iSettings.Reset() ; sl@0: aStream >> aRep.iSettings ; sl@0: sl@0: if (version >= KPersistFormatSupportsDeletedSettings) sl@0: { sl@0: // Deleted Settings sl@0: aStream >> count ; sl@0: for (TUint32 i=0; i> keyValue ; sl@0: aRep.iDeletedSettings.InsertInUnsignedKeyOrderL(keyValue); sl@0: } sl@0: } sl@0: sl@0: // Set up access policies sl@0: TInt numElements = aRep.iSettings.Count(); sl@0: for (TInt count = 0; count < numElements; count++) sl@0: { sl@0: TServerSetting* setting= &(aRep.iSettings[count]); sl@0: TUint32 key=setting->Key(); sl@0: setting->SetAccessPolicy(aRep.GetFallbackAccessPolicy(key)); sl@0: } sl@0: }