|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <s32file.h> |
|
17 #include "cregen.h" |
|
18 #include "heaprepos.h" |
|
19 #include "srvparams.h" |
|
20 |
|
21 _LIT(KTmpExtension,"tmp"); |
|
22 |
|
23 void CCreGenerator::CommitChangesToCreL(RFs& aFs,TUint8 aPersistVersion,CHeapRepository& aRep,const TDesC& aTargetFilePath) |
|
24 { |
|
25 HBufC* tmpFilePath=aTargetFilePath.AllocLC(); |
|
26 TPtr tmpFilePathPtr(tmpFilePath->Des()); |
|
27 tmpFilePathPtr.Replace(tmpFilePath->Length()-3,3,KTmpExtension()); |
|
28 |
|
29 CDirectFileStore* store = CDirectFileStore::ReplaceLC(aFs, *tmpFilePath,(EFileWrite | EFileShareExclusive)); |
|
30 |
|
31 const TUid uid2 = KNullUid ; |
|
32 store->SetTypeL(TUidType(KDirectFileStoreLayoutUid, uid2, KServerUid3)) ; |
|
33 |
|
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() ; |
|
40 |
|
41 CleanupStack::PopAndDestroy(&rootStream) ; |
|
42 store->SetRootL(rootStreamId); |
|
43 store->CommitL(); |
|
44 CleanupStack::PopAndDestroy(store) ; |
|
45 User::LeaveIfError(aFs.Replace(*tmpFilePath,aTargetFilePath)); |
|
46 CleanupStack::PopAndDestroy(); |
|
47 } |
|
48 |
|
49 void CCreGenerator::CreateReposFromCreL(RFs& aFs,CHeapRepository& aRep, const TDesC& aFilePath |
|
50 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
51 ,TUint8& aCreVersion |
|
52 #endif |
|
53 ) |
|
54 { |
|
55 RFile file; |
|
56 TInt err = file.Open(aFs,aFilePath,EFileRead|EFileShareReadersOnly); |
|
57 |
|
58 if (err != KErrNone) |
|
59 { |
|
60 if(err ==KErrNotFound || err==KErrPathNotFound) |
|
61 User::Leave(KErrNotFound); |
|
62 else |
|
63 User::Leave(err); |
|
64 } |
|
65 |
|
66 CleanupClosePushL(file); |
|
67 |
|
68 CDirectFileStore* store = CDirectFileStore::FromLC (file); |
|
69 if(store->Type()[0] != KDirectFileStoreLayoutUid) |
|
70 { |
|
71 User::Leave(KErrCorrupt); |
|
72 } |
|
73 |
|
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 |
|
81 ,aCreVersion |
|
82 #endif |
|
83 ); |
|
84 CleanupStack::PopAndDestroy(3, &file); |
|
85 } |
|
86 |
|
87 void CCreGenerator::ExternalizeCre(TUint8 aPersistVersion,const CHeapRepository& aRep, RWriteStream& aStream) |
|
88 { |
|
89 aStream << aPersistVersion; |
|
90 aStream << aRep.iUid ; |
|
91 aStream << aRep.iOwner ; |
|
92 |
|
93 TUint32 count=aRep.iSinglePolicies.Count(); |
|
94 aStream << count; |
|
95 for(TUint32 i=0; i<count;i++) |
|
96 { |
|
97 aStream << *(aRep.iSinglePolicies[i]); |
|
98 } |
|
99 |
|
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) |
|
105 { |
|
106 aStream << aRep.iDefaultPolicy.HighKey(); |
|
107 aStream << aRep.iDefaultPolicy.KeyMask(); |
|
108 } |
|
109 #endif |
|
110 |
|
111 aStream << aRep.iDefaultMeta ; |
|
112 aStream << aRep.iRangeMeta ; |
|
113 aStream << aRep.iTimeStamp.Int64() ; |
|
114 |
|
115 aStream << aRep.iSettings ; |
|
116 |
|
117 // Deleted settings |
|
118 count = aRep.iDeletedSettings.Count() ; |
|
119 aStream << count ; |
|
120 for (TUint32 i=0; i<count; i++) |
|
121 { |
|
122 aStream << aRep.iDeletedSettings[i]; |
|
123 } |
|
124 } |
|
125 |
|
126 void CCreGenerator::InternalizeCreL(CHeapRepository& aRep, RReadStream& aStream |
|
127 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
128 ,TUint8& aCreVersion |
|
129 #endif |
|
130 ) |
|
131 { |
|
132 TUint8 version; |
|
133 aStream >> version; |
|
134 |
|
135 // Check the UID is the same as that expected. |
|
136 // UID should always be correctly initialised by the time we reach |
|
137 // this point. |
|
138 TUid tempUid; |
|
139 aStream >> tempUid; |
|
140 |
|
141 if (tempUid != aRep.iUid) |
|
142 { |
|
143 #ifdef _DEBUG |
|
144 RDebug::Print(_L("CSharedRepository::InternalizeCreL - expected UID (from filename) - %08X, UID extracted from binary file - %08X "), aRep.iUid.iUid, tempUid.iUid); |
|
145 #endif |
|
146 User::Leave(KErrCorrupt); |
|
147 } |
|
148 |
|
149 aStream >> aRep.iOwner ; |
|
150 |
|
151 TUint32 count; |
|
152 aStream >> count; |
|
153 for(TUint32 i=0; i<count;i++) |
|
154 { |
|
155 TSettingsAccessPolicy* singlePolicy = new(ELeave) TSettingsAccessPolicy; |
|
156 CleanupStack::PushL(singlePolicy); |
|
157 aStream >> *singlePolicy; |
|
158 aRep.iSinglePolicies.AppendL(singlePolicy); |
|
159 CleanupStack::Pop(singlePolicy); |
|
160 } |
|
161 |
|
162 aRep.iRangePolicies.Reset(); |
|
163 aStream >> aRep.iRangePolicies ; |
|
164 |
|
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 |
|
175 aCreVersion=version; |
|
176 TUint32 highKey=0; |
|
177 TUint32 keyMask=0; |
|
178 if (aCreVersion>=KPersistFormatSupportsIndMetaIndicator) |
|
179 { |
|
180 aStream >> highKey; |
|
181 aStream >> keyMask; |
|
182 } |
|
183 aRep.iDefaultPolicy=TSettingsAccessPolicy(defaultReadPolicy,defaultWritePolicy, KUnspecifiedKey,highKey,keyMask); |
|
184 #else |
|
185 aRep.iDefaultPolicy=TSettingsAccessPolicy(defaultReadPolicy,defaultWritePolicy, KUnspecifiedKey); |
|
186 #endif |
|
187 aStream >> aRep.iDefaultMeta ; |
|
188 |
|
189 aRep.iRangeMeta.Reset(); |
|
190 aStream >> aRep.iRangeMeta ; |
|
191 |
|
192 TInt64 timeStampInt ; |
|
193 aStream >> timeStampInt ; |
|
194 aRep.iTimeStamp = timeStampInt ; |
|
195 |
|
196 aRep.iSettings.Reset() ; |
|
197 aStream >> aRep.iSettings ; |
|
198 |
|
199 if (version >= KPersistFormatSupportsDeletedSettings) |
|
200 { |
|
201 // Deleted Settings |
|
202 aStream >> count ; |
|
203 for (TUint32 i=0; i<count; i++) |
|
204 { |
|
205 TUint32 keyValue ; |
|
206 aStream >> keyValue ; |
|
207 aRep.iDeletedSettings.InsertInUnsignedKeyOrderL(keyValue); |
|
208 } |
|
209 } |
|
210 |
|
211 // Set up access policies |
|
212 TInt numElements = aRep.iSettings.Count(); |
|
213 for (TInt count = 0; count < numElements; count++) |
|
214 { |
|
215 TServerSetting* setting= &(aRep.iSettings[count]); |
|
216 TUint32 key=setting->Key(); |
|
217 setting->SetAccessPolicy(aRep.GetFallbackAccessPolicy(key)); |
|
218 } |
|
219 } |