First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // TPDStreamLoader class
20 #include "SC_StrmIn.h"
26 MPolicyDomainLoader::RunL() implementation, which is used to load security policies
27 from a binary file, create the related security policy objects and add them
28 to CPolicyDomain instance, controlled by aPolicyDomainBuilder object.
29 It is not called directly, but will be called back.
30 @param aPolicyDomainBuilder TPolicyDomainBuilder instance, which will be used to add
31 created security policy objects to the controlled by it collection.
32 @leave System-wide error codes
34 void TPDStreamLoader::RunL(TPolicyDomainBuilder& aPolicyDomainBuilder)
36 //Load policy file version
38 iStream >> fileVer.iMajor;
39 iStream >> fileVer.iMinor;
40 iStream >> fileVer.iBuild;
41 //Check policy file version against the software version
42 TInt fileVersion = CVERSION(fileVer.iMajor, fileVer.iMinor);
43 if(KDBSCVersion < fileVersion)
45 __LEAVE(KErrNotSupported);
48 CPolicyBase::RPolicyCollection policyColl;
49 CleanupClosePushL(policyColl);
50 //Load database policy
51 LoadPolicyCollectionL(policyColl);
52 CDbPolicy* dbPolicy = CDbPolicy::NewLC(policyColl);
53 aPolicyDomainBuilder.SetDbPolicyL(dbPolicy);
54 CleanupStack::Pop(dbPolicy);
55 //Load all table policies
58 for(TInt i=0;i<TInt(tblCnt);++i)
60 TBuf<KMaxFileName> tblName;
62 LoadPolicyCollectionL(policyColl);
63 CTblPolicy* tblPolicy = CTblPolicy::NewLC(tblName, policyColl, dbPolicy);
64 aPolicyDomainBuilder.AddTblPolicyL(tblPolicy);
65 CleanupStack::Pop(tblPolicy);
67 CleanupStack::PopAndDestroy(&policyColl);
68 //Load backup&restore SID (supported after version 1.1 (including 1.1)).
69 if(fileVersion >= CVERSION(KDBSCMajorVersion1, KDBSCMinorVersion1_1))
72 iStream >> backupSID.iId;
73 aPolicyDomainBuilder.SetBackupSID(backupSID);
78 Loads security policies collection from a binary file
79 @param aPolicyColl A reference to a security policy collection object which has
80 to be filled with the loaded security policies.
81 @leave System-wide error codes
83 void TPDStreamLoader::LoadPolicyCollectionL(CPolicyBase::RPolicyCollection& aPolicyColl)
88 for(TInt i=0;i<TInt(cnt);++i)
90 CPolicyBase::TPolicy policy;
93 policy.iType = static_cast <TPolicyType> (type);
94 TBuf8<sizeof(TSecurityPolicy)> buf;
96 __LEAVE_IF_ERROR(policy.iData.Set(buf));
97 __LEAVE_IF_ERROR(aPolicyColl.Append(policy));
101 } //end of - namespace DBSC