sl@0: // Copyright (c) 2004-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: // TPDStreamLoader class sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "SC_Defs.h" sl@0: #include "SC_StrmIn.h" sl@0: sl@0: namespace DBSC sl@0: { sl@0: sl@0: /** sl@0: MPolicyDomainLoader::RunL() implementation, which is used to load security policies sl@0: from a binary file, create the related security policy objects and add them sl@0: to CPolicyDomain instance, controlled by aPolicyDomainBuilder object. sl@0: It is not called directly, but will be called back. sl@0: @param aPolicyDomainBuilder TPolicyDomainBuilder instance, which will be used to add sl@0: created security policy objects to the controlled by it collection. sl@0: @leave System-wide error codes sl@0: */ sl@0: void TPDStreamLoader::RunL(TPolicyDomainBuilder& aPolicyDomainBuilder) sl@0: { sl@0: //Load policy file version sl@0: TVersion fileVer; sl@0: iStream >> fileVer.iMajor; sl@0: iStream >> fileVer.iMinor; sl@0: iStream >> fileVer.iBuild; sl@0: //Check policy file version against the software version sl@0: TInt fileVersion = CVERSION(fileVer.iMajor, fileVer.iMinor); sl@0: if(KDBSCVersion < fileVersion) sl@0: { sl@0: __LEAVE(KErrNotSupported); sl@0: } sl@0: // sl@0: CPolicyBase::RPolicyCollection policyColl; sl@0: CleanupClosePushL(policyColl); sl@0: //Load database policy sl@0: LoadPolicyCollectionL(policyColl); sl@0: CDbPolicy* dbPolicy = CDbPolicy::NewLC(policyColl); sl@0: aPolicyDomainBuilder.SetDbPolicyL(dbPolicy); sl@0: CleanupStack::Pop(dbPolicy); sl@0: //Load all table policies sl@0: TInt16 tblCnt; sl@0: iStream >> tblCnt; sl@0: for(TInt i=0;i tblName; sl@0: iStream >> tblName; sl@0: LoadPolicyCollectionL(policyColl); sl@0: CTblPolicy* tblPolicy = CTblPolicy::NewLC(tblName, policyColl, dbPolicy); sl@0: aPolicyDomainBuilder.AddTblPolicyL(tblPolicy); sl@0: CleanupStack::Pop(tblPolicy); sl@0: } sl@0: CleanupStack::PopAndDestroy(&policyColl); sl@0: //Load backup&restore SID (supported after version 1.1 (including 1.1)). sl@0: if(fileVersion >= CVERSION(KDBSCMajorVersion1, KDBSCMinorVersion1_1)) sl@0: { sl@0: TSecureId backupSID; sl@0: iStream >> backupSID.iId; sl@0: aPolicyDomainBuilder.SetBackupSID(backupSID); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Loads security policies collection from a binary file sl@0: @param aPolicyColl A reference to a security policy collection object which has sl@0: to be filled with the loaded security policies. sl@0: @leave System-wide error codes sl@0: */ sl@0: void TPDStreamLoader::LoadPolicyCollectionL(CPolicyBase::RPolicyCollection& aPolicyColl) sl@0: { sl@0: aPolicyColl.Reset(); sl@0: TInt8 cnt; sl@0: iStream >> cnt; sl@0: for(TInt i=0;i> type; sl@0: policy.iType = static_cast (type); sl@0: TBuf8 buf; sl@0: iStream >> buf; sl@0: __LEAVE_IF_ERROR(policy.iData.Set(buf)); sl@0: __LEAVE_IF_ERROR(aPolicyColl.Append(policy)); sl@0: } sl@0: } sl@0: sl@0: } //end of - namespace DBSC