Update contrib.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "heaprepos.h"
19 #include "srvparams.h"
21 _LIT(KTmpExtension,"tmp");
23 void CCreGenerator::CommitChangesToCreL(RFs& aFs,TUint8 aPersistVersion,CHeapRepository& aRep,const TDesC& aTargetFilePath)
25 HBufC* tmpFilePath=aTargetFilePath.AllocLC();
26 TPtr tmpFilePathPtr(tmpFilePath->Des());
27 tmpFilePathPtr.Replace(tmpFilePath->Length()-3,3,KTmpExtension());
29 CDirectFileStore* store = CDirectFileStore::ReplaceLC(aFs, *tmpFilePath,(EFileWrite | EFileShareExclusive));
31 const TUid uid2 = KNullUid ;
32 store->SetTypeL(TUidType(KDirectFileStoreLayoutUid, uid2, KServerUid3)) ;
34 // Write the stream index/dictionary as root stream within the store
35 // so we can access it when we do a restore later on
36 RStoreWriteStream rootStream ;
37 TStreamId rootStreamId = rootStream.CreateLC(*store) ;
38 ExternalizeCre(aPersistVersion,aRep, rootStream) ;
39 rootStream.CommitL() ;
41 CleanupStack::PopAndDestroy(&rootStream) ;
42 store->SetRootL(rootStreamId);
44 CleanupStack::PopAndDestroy(store) ;
45 User::LeaveIfError(aFs.Replace(*tmpFilePath,aTargetFilePath));
46 CleanupStack::PopAndDestroy();
49 void CCreGenerator::CreateReposFromCreL(RFs& aFs,CHeapRepository& aRep, const TDesC& aFilePath
50 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
56 TInt err = file.Open(aFs,aFilePath,EFileRead|EFileShareReadersOnly);
60 if(err ==KErrNotFound || err==KErrPathNotFound)
61 User::Leave(KErrNotFound);
66 CleanupClosePushL(file);
68 CDirectFileStore* store = CDirectFileStore::FromLC (file);
69 if(store->Type()[0] != KDirectFileStoreLayoutUid)
71 User::Leave(KErrCorrupt);
74 // Get the root stream and attempt to read the index from it
75 TStreamId rootStreamId = store->Root() ;
76 RStoreReadStream rootStream ;
77 rootStream.OpenLC(*store, rootStreamId);
78 // Internalize the repository
79 InternalizeCreL(aRep, rootStream
80 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
84 CleanupStack::PopAndDestroy(3, &file);
87 void CCreGenerator::ExternalizeCre(TUint8 aPersistVersion,const CHeapRepository& aRep, RWriteStream& aStream)
89 aStream << aPersistVersion;
90 aStream << aRep.iUid ;
91 aStream << aRep.iOwner ;
93 TUint32 count=aRep.iSinglePolicies.Count();
95 for(TUint32 i=0; i<count;i++)
97 aStream << *(aRep.iSinglePolicies[i]);
100 aStream << aRep.iRangePolicies ;
101 aStream << aRep.iDefaultPolicy.GetReadAccessPolicy()->Package() ;
102 aStream << aRep.iDefaultPolicy.GetWriteAccessPolicy()->Package() ;
103 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
104 if (aPersistVersion>=KPersistFormatSupportsIndMetaIndicator)
106 aStream << aRep.iDefaultPolicy.HighKey();
107 aStream << aRep.iDefaultPolicy.KeyMask();
111 aStream << aRep.iDefaultMeta ;
112 aStream << aRep.iRangeMeta ;
113 aStream << aRep.iTimeStamp.Int64() ;
115 aStream << aRep.iSettings ;
118 count = aRep.iDeletedSettings.Count() ;
120 for (TUint32 i=0; i<count; i++)
122 aStream << aRep.iDeletedSettings[i];
126 void CCreGenerator::InternalizeCreL(CHeapRepository& aRep, RReadStream& aStream
127 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
135 // Check the UID is the same as that expected.
136 // UID should always be correctly initialised by the time we reach
141 if (tempUid != aRep.iUid)
144 RDebug::Print(_L("CSharedRepository::InternalizeCreL - expected UID (from filename) - %08X, UID extracted from binary file - %08X "), aRep.iUid.iUid, tempUid.iUid);
146 User::Leave(KErrCorrupt);
149 aStream >> aRep.iOwner ;
153 for(TUint32 i=0; i<count;i++)
155 TSettingsAccessPolicy* singlePolicy = new(ELeave) TSettingsAccessPolicy;
156 CleanupStack::PushL(singlePolicy);
157 aStream >> *singlePolicy;
158 aRep.iSinglePolicies.AppendL(singlePolicy);
159 CleanupStack::Pop(singlePolicy);
162 aRep.iRangePolicies.Reset();
163 aStream >> aRep.iRangePolicies ;
165 HBufC8* securityPolicyPackage ;
166 securityPolicyPackage = HBufC8::NewLC(aStream, 10000) ;
167 TSecurityPolicy defaultReadPolicy;
168 defaultReadPolicy.Set(securityPolicyPackage->Des()) ;
169 CleanupStack::PopAndDestroy(securityPolicyPackage) ;
170 securityPolicyPackage = HBufC8::NewLC(aStream, 10000) ;
171 TSecurityPolicy defaultWritePolicy;
172 defaultWritePolicy.Set(securityPolicyPackage->Des()) ;
173 CleanupStack::PopAndDestroy(securityPolicyPackage) ;
174 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
178 if (aCreVersion>=KPersistFormatSupportsIndMetaIndicator)
183 aRep.iDefaultPolicy=TSettingsAccessPolicy(defaultReadPolicy,defaultWritePolicy, KUnspecifiedKey,highKey,keyMask);
185 aRep.iDefaultPolicy=TSettingsAccessPolicy(defaultReadPolicy,defaultWritePolicy, KUnspecifiedKey);
187 aStream >> aRep.iDefaultMeta ;
189 aRep.iRangeMeta.Reset();
190 aStream >> aRep.iRangeMeta ;
192 TInt64 timeStampInt ;
193 aStream >> timeStampInt ;
194 aRep.iTimeStamp = timeStampInt ;
196 aRep.iSettings.Reset() ;
197 aStream >> aRep.iSettings ;
199 if (version >= KPersistFormatSupportsDeletedSettings)
203 for (TUint32 i=0; i<count; i++)
206 aStream >> keyValue ;
207 aRep.iDeletedSettings.InsertInUnsignedKeyOrderL(keyValue);
211 // Set up access policies
212 TInt numElements = aRep.iSettings.Count();
213 for (TInt count = 0; count < numElements; count++)
215 TServerSetting* setting= &(aRep.iSettings[count]);
216 TUint32 key=setting->Key();
217 setting->SetAccessPolicy(aRep.GetFallbackAccessPolicy(key));