Update contrib.
1 // Copyright (c) 2006-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.
21 #ifdef SYMBIAN_BAFL_SYSUTIL
22 #include <bafl/sysutil.h>
26 #include "clientrequest.h"
28 #include "operations.h"
32 class CRestoredRepository;
34 class CServerRepository : public CRepositoryTransactor, public MOperationLogic
37 void OpenL(TUid aUid, MObserver& aObserver, TBool aFailIfNotFound = ETrue);
38 void HandleOpenMergeL();
40 void RestoreNotify(const CRestoredRepository& aRstRepos);
41 TInt RFSRepositoryL();
42 #ifdef SYMBIAN_BAFL_SYSUTIL
43 static void CheckROMReflashL();
45 static void RFSAllRepositoriesL();
47 inline TInt StartTransaction(TInt aMode)
49 return iRepository->StartTransaction(*this, aMode);
51 inline TInt CommitTransaction(TUint32& aKeyInfo)
53 return iRepository->CommitTransaction(*this, aKeyInfo);
55 inline void CancelTransaction() // serves as both rollback and async cancel
57 TServerResources::iObserver->CancelTransaction(*this,iUid);
59 void CleanupCancelTransactionPushL();
60 inline TInt FailTransaction(TInt aError, TUint32 aErrorKey)
62 // returns aError to allow "return FailTransaction(error, errorKey);" - error written once
63 return iRepository->FailTransaction(*this, aError, aErrorKey);
66 inline void FailAllTransactions()
68 iRepository->FailAllTransactions(NULL);
70 /** must currently be in active Read transaction. Does not fail
71 transaction here if promotion to read/write failed.
72 @return KErrNone if promoted, KErrLocked if not
74 inline TInt AttemptPromoteTransactionToReadWrite()
76 ASSERT(IsInActiveReadTransaction());
77 return iRepository->AttemptPromoteTransactionToReadWrite(*this);
80 inline TServerSetting* GetPersistentSetting(TUint32 aId)
82 return iRepository->GetSettings().Find(aId);
84 inline TServerSetting* GetTransactionSetting(TUint32 aId)
86 return iTransactionSettings.Find(aId);
90 TInt TransactionCreateL(TUint32 aKey, const T& aVal, TUint32* aMeta);
93 TInt TransactionSetL(TUint32 aKey, const T& aVal);
95 inline TInt TransactionDeleteL(TUint32 aId)
97 // all write operations now done in a transaction
98 ASSERT(IsInActiveReadWriteTransaction());
99 TRAPD(err,DeleteSettingL(aId));
100 if (err==KErrNoMemory)
101 User::LeaveNoMemory();
105 TInt TransactionMoveL(const TClientRequest& aMessage, TUint32& aErrorKey);
106 TInt TransactionDeleteRangeL(const TClientRequest& aMessage, TUint32& aErrId);
108 TInt CheckPermissions(RSettingPointerArray& aSettings, const TClientRequest& aMessage, const char* aDiagnostic,TBool aReadPolicy,TUint32& aErrId);
110 TInt CheckAccessPolicyBeforeMoving(const TClientRequest& aMessage, const TServerSetting* aSourceSetting, TUint32 aSourceKey,
111 const TServerSetting* aTargetSetting, TUint32 aTargetKey, TUint32& aErrorKey);
113 TInt CheckMovePermissions(const RSettingPointerArray& aSourceSettings,const TClientRequest& aMessage,TUint aSourceToTarget,TUint32& aErrorKey)
116 for (TInt i=0;i<aSourceSettings.Count() && error==KErrNone;i++)
118 ASSERT(aSourceSettings[i]);
119 TServerSetting* sourceSetting = aSourceSettings[i];
120 TUint32 sourceKey = sourceSetting->Key();
121 TUint32 targetKey = sourceKey ^ aSourceToTarget;
122 TServerSetting* targetSetting = GetSetting(targetKey);
124 error = CheckAccessPolicyBeforeMoving(aMessage, sourceSetting, sourceKey, targetSetting, targetKey, aErrorKey);
129 inline TInt FindPersistentSettings(TUint32 aPartialId, TUint32 aIdMask, RSettingPointerArray& aMatches) const
131 // guarantees to reset RSettingPointerArray in case of error
132 return iRepository->GetSettings().Find(aPartialId, aIdMask, aMatches);
134 inline TInt FindTransactionSettings(TUint32 aPartialId, TUint32 aIdMask, RSettingPointerArray& aMatches) const
136 // guarantees to reset RSettingPointerArray in case of error
137 return iTransactionSettings.Find(aPartialId, aIdMask, aMatches);
140 inline void CommitChangesL(TCentRepLocation aLocation = EPersists) const
142 iRepository->CommitChangesL(aLocation);
145 TInt ResetL(TUint32 aId);
148 inline const TSecurityPolicy& GetReadAccessPolicy(const TServerSetting& aSetting) const
150 return iRepository->GetReadAccessPolicy(aSetting);
152 inline const TSecurityPolicy& GetReadAccessPolicy(TUint32 aId) const
154 return iRepository->GetReadAccessPolicy(aId);
156 inline const TSecurityPolicy& GetDefaultReadAccessPolicy() const
158 return iRepository->GetDefaultReadAccessPolicy();
161 inline const TSecurityPolicy& GetFallbackWriteAccessPolicy(TUint32 aId) const
163 return iRepository->GetFallbackWriteAccessPolicy(aId);
166 inline const TSecurityPolicy& GetWriteAccessPolicy(const TServerSetting& aSetting) const
168 return iRepository->GetWriteAccessPolicy(aSetting);
170 inline const TSecurityPolicy& GetWriteAccessPolicy(TUint32 aId) const
172 return iRepository->GetWriteAccessPolicy(aId);
174 inline const TSecurityPolicy& GetDefaultWriteAccessPolicy() const
176 return iRepository->GetDefaultWriteAccessPolicy();
179 void HandleSWIUpdateL(TUid aUid, TTime aModified, CSessionNotifier& aNotifier);
180 void HandleSWIDeleteL(TUid aUid, CSessionNotifier& aNotifier);
182 void StoreRepositoryContentsL(CStreamStore & aStore, TStreamId & aSettingStreamId, TStreamId & aDeletedSettingsStreamId) const;
183 void StoreRepositorySettingValuesL(CStreamStore& aStore, TStreamId & aSettingStreamId) const;
184 void RestoreRepositoryContentsL(CStreamStore& aStore, TStreamId aSettingStreamId, TStreamId aDeletedSettingsStreamId, CRestoredRepository& aRstRepos);
185 void RestoreRepositorySettingValuesL(CStreamStore& aStore, TStreamId aSettingStreamId, CRestoredRepository& aRstRepos);
187 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
188 void ResetFromIniFileL(TUint32 aId,CIniFileIn::TIniFileOpenMode aIniFileOpenMode,TBool& aKeyFound);
190 void ResetFromIniFileL(TUint32 aId,TCentRepLocation aLocation,TBool& aKeyFound);
193 void LoadIniRepL(CIniFileIn::TIniFileOpenMode aMode);
194 TBool GetMetaFromIni(TUint32 aKey, TUint32& aMeta);
196 void RestoreInstallRepositoryL(TUid aUid, CStreamStore& aStore, TStreamId& aSettingStreamId, CRestoredRepository& aRstRepos);
197 void BackupInstallRepositoryL(TUid aUid, CStreamStore& aStore, TStreamId& aSettingStreamId);
200 #ifdef CACHE_OOM_TESTABILITY
201 TInt SizeiRepository()
203 return iRepository->Size();
207 inline MObserver* Notifier()
213 inline void AccessRepositoryL()
215 iRepository = TServerResources::iObserver->AccessL(iUid);
219 enum TPersistedRepActions {ECenRepReflash,ECenRepReset};
222 static void ProcessPersistsRepositoriesL(TPersistedRepActions aRomFlashOrReset);
223 static void CacheRomVersionL(const TDesC& aFilename, TDesC8& aVersion);
224 TInt HandleReflashofRepositoryL();
226 //--------------------virtual functions from MOperation----------------------------
228 void GetSingleMeta(TUint aKey,TUint32& aMeta)
231 if (GetMetaFromIni(aKey, metaFromIni))
233 aMeta=~KMetaDefaultValue & metaFromIni;
237 //First check for a matching "range" default
238 TSettingsDefaultMeta* defaultMeta = iRepository->iSimRep->RangeMetaArray().Find(aKey);
241 aMeta=defaultMeta->GetDefaultMetadata();
245 // Range value not found, try for a repository default
246 aMeta=iRepository->iSimRep->DefaultMeta();
251 TSettingsAccessPolicy* GetFallbackAccessPolicy(TUint32 aId) const
253 return iRepository->GetFallbackAccessPolicy(aId);
256 RSettingsArray& GetWritableSettingList()
258 return iTransactionSettings;
261 TServerSetting* GetSetting(TUint aKey)
263 // try to be most efficient when no transaction changes
264 if ((iTransactionSettings.Count() > 0) && IsInActiveReadWriteTransaction())
266 TServerSetting* s = GetTransactionSetting(aKey);
272 return GetPersistentSetting(aKey);
275 /** Returns pointer array of settings whose keys match the partial key and mask. Combines
276 settings from the persistent list with those in the transaction, with priority given to the
277 latter, including settings flagged as deleted eliminating the corresponding entry from the
278 persistent settings (plus themselves so the final list has no settings flagged as deleted in it).
279 Can also call this method when not in a transaction.
280 In case of error, aMatches may contain entries and must be Reset.
282 TInt FindSettings(TUint32 aSourcePartialKey,TUint32 aMask,RSettingPointerArray& aOutputArray) const
284 TInt error = FindPersistentSettings(aSourcePartialKey, aMask, aOutputArray);
285 // try to be most efficient when no transaction changes
286 if ((iTransactionSettings.Count() > 0) && IsInActiveReadWriteTransaction() && (KErrNone == error))
288 RSettingPointerArray transactionSettings;
289 error = FindTransactionSettings(aSourcePartialKey, aMask, transactionSettings);
290 if (error == KErrNone)
292 error = RSettingsArray::Merge(aOutputArray, transactionSettings);
294 transactionSettings.Reset();
299 //---------------------end of virtual functions-------------------------------------------
300 #ifndef FOTA_UNIT_TESTING
303 CSharedRepository* iRepository;
304 MObserver* iNotifier;
309 TInt CServerRepository::TransactionSetL(TUint32 aKey, const T& aVal)
311 // all write operations now done in a transaction
312 ASSERT(IsInActiveReadWriteTransaction());
314 TRAPD(error,SetSettingL(aKey,aVal));
315 if (error != KErrNone)
317 FailTransaction(error, aKey);
324 TInt CServerRepository::TransactionCreateL(TUint32 aKey, const T& aVal, TUint32* aMeta)
326 // all write operations now done in a transaction
327 ASSERT(IsInActiveReadWriteTransaction());
329 TRAPD(err,CreateSettingL(aKey,aVal,aMeta));
330 if (err==KErrAlreadyExists)
332 return FailTransaction(KErrAlreadyExists,aKey);
334 User::LeaveIfError(err);