os/persistentdata/persistentstorage/dbms/security/SC_Policy.inl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/security/SC_Policy.inl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,256 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +namespace DBSC
    1.20 +{
    1.21 +
    1.22 +//////////////////////////////////////////////////////////////////////////////////////////////
    1.23 +//class CPolicyBase
    1.24 +
    1.25 +/**
    1.26 +*/
    1.27 +inline CPolicyBase::CPolicyBase()
    1.28 +	{
    1.29 +	}
    1.30 +
    1.31 +/**
    1.32 +@return A const reference to the controlled collection of R/W/S policies.
    1.33 +*/
    1.34 +inline const CPolicyBase::RPolicyCollection& CPolicyBase::PolicyCollection() const
    1.35 +	{
    1.36 +	return iPolicyCollection;
    1.37 +	}
    1.38 +
    1.39 +//////////////////////////////////////////////////////////////////////////////////////////////
    1.40 +//class CDbPolicy
    1.41 +
    1.42 +/**
    1.43 +*/
    1.44 +inline CDbPolicy::CDbPolicy()
    1.45 +	{
    1.46 +	}
    1.47 +
    1.48 +/**
    1.49 +Standard phase-one CDbPolicy factory method.
    1.50 +@param aPolicyCollection A collection of R/W/S policies.
    1.51 +@return A pointer to just created CDbPolicy instance.
    1.52 +@leave System-wide error codes, including KErrNoMemory
    1.53 +*/
    1.54 +inline CDbPolicy* CDbPolicy::NewL(const RPolicyCollection& aPolicyCollection)
    1.55 +	{
    1.56 +	CDbPolicy* policy = CDbPolicy::NewLC(aPolicyCollection);
    1.57 +	CleanupStack::Pop(policy);
    1.58 +	return policy;
    1.59 +	}
    1.60 +
    1.61 +//////////////////////////////////////////////////////////////////////////////////////////////
    1.62 +//class CTblPolicy
    1.63 +
    1.64 +/**
    1.65 +*/
    1.66 +inline CTblPolicy::CTblPolicy(const CDbPolicy* aDbPolicy) :
    1.67 +	iDbPolicy(aDbPolicy)
    1.68 +	{
    1.69 +	__ASSERT(iDbPolicy);
    1.70 +	}
    1.71 +
    1.72 +/**
    1.73 +Standard phase-one CTblPolicy factory method.
    1.74 +@param aTblName The name of the table, access to which is controlled by the supplied policies
    1.75 +@param aPolicyCollection A collection of R/W/S policies.
    1.76 +@param aDbPolicy The related for the table database policy.
    1.77 +@return A pointer to just created CTblPolicy instance.
    1.78 +@leave System-wide error codes, including KErrNoMemory
    1.79 +*/
    1.80 +inline CTblPolicy* CTblPolicy::NewL(const TDesC& aTblName, 
    1.81 +									const RPolicyCollection& aPolicyCollection,
    1.82 +									const CDbPolicy* aDbPolicy)
    1.83 +	{
    1.84 +	CTblPolicy* policy = CTblPolicy::NewLC(aTblName, aPolicyCollection, aDbPolicy);
    1.85 +	CleanupStack::Pop(policy);
    1.86 +	return policy;
    1.87 +	}
    1.88 +
    1.89 +/**
    1.90 +@return A const reference to the table name.
    1.91 +*/
    1.92 +inline const TDesC& CTblPolicy::TableName() const
    1.93 +	{
    1.94 +	DB_INVARIANT();
    1.95 +	return *iTblName;
    1.96 +	}
    1.97 +
    1.98 +//////////////////////////////////////////////////////////////////////////////////////////////
    1.99 +//class CPolicyDomain
   1.100 +
   1.101 +/**
   1.102 +CPolicyDomain collection of table security policies  - the granularity.
   1.103 +@internalComponent
   1.104 +*/
   1.105 +const TInt KTblPolicyCollGranularity = 32;
   1.106 +
   1.107 +/**
   1.108 +@param aUid The domain UID
   1.109 +*/
   1.110 +inline CPolicyDomain::CPolicyDomain(TUid aUid) :
   1.111 +	iUid(aUid),
   1.112 +	iTPCollection(KTblPolicyCollGranularity)
   1.113 +	{
   1.114 +	}
   1.115 +
   1.116 +/**
   1.117 +Standard phase-one CPolicyDomain factory method.
   1.118 +@param aUid The format uid of the databases, access to which is controlled by security policies
   1.119 +@param aPDLoader The interface, which actual implementation is used to load the related set
   1.120 +                 of security policies into CPolicyDomain collection. Currently CPolicyDomain
   1.121 +				 policy collection can be loaded from a text or binary policy file.
   1.122 +@return A pointer to just created CPolicyDomain instance.
   1.123 +@leave System-wide error codes, including KErrNoMemory
   1.124 +*/
   1.125 +inline CPolicyDomain* CPolicyDomain::NewL(TUid aUid, MPolicyDomainLoader& aPDLoader)
   1.126 +	{
   1.127 +	CPolicyDomain* domain = CPolicyDomain::NewLC(aUid, aPDLoader);
   1.128 +	CleanupStack::Pop(domain);
   1.129 +	return domain;
   1.130 +	}
   1.131 +
   1.132 +/**
   1.133 +@return Policy domain UID.
   1.134 +*/
   1.135 +inline TUid CPolicyDomain::Uid() const
   1.136 +	{
   1.137 +	DB_INVARIANT();
   1.138 +	return iUid;
   1.139 +	}
   1.140 +
   1.141 +/**
   1.142 +@return Backup&restore SID.
   1.143 +*/
   1.144 +inline TSecureId CPolicyDomain::BackupSID() const
   1.145 +	{
   1.146 +	DB_INVARIANT();
   1.147 +	return iBackupSID;
   1.148 +	}
   1.149 +
   1.150 +//////////////////////////////////////////////////////////////////////////////////////////////
   1.151 +//class TPolicyDomainBuilder
   1.152 +
   1.153 +/**
   1.154 +TPolicyDomainBuilder is a friend class of CPolicyDomain, which means that it can access
   1.155 +CPolicyDomain's data members and add/update new policies there.
   1.156 +The idea is that TPolicyDomainBuilder will be used by the implementors of MPolicyDomainLoader
   1.157 +interface, removing the need of making them friends of CPolicyDomain or visible from CPolicyDomain.
   1.158 +@param aPolicyDomain A reference to the policy domain object, which collection has to be 
   1.159 +                     created by the TPolicyDomainBuilder instance.
   1.160 +*/
   1.161 +inline TPolicyDomainBuilder::TPolicyDomainBuilder(CPolicyDomain& aPolicyDomain) :
   1.162 +	iPolicyDomain(aPolicyDomain)
   1.163 +	{
   1.164 +	}
   1.165 +
   1.166 +/**
   1.167 +The method adds a table policy to the related CPolicyDomain collection.
   1.168 +@param aTblPolicy A pointer to CTblPolicy instance, which has to be added to 
   1.169 +                  the related CPolicyDomain collection. CPolicyDomain collection takes the
   1.170 +				  ownership on the supplied CTblPolicy instance.
   1.171 +*/
   1.172 +inline void TPolicyDomainBuilder::AddTblPolicyL(CTblPolicy* aTblPolicy)
   1.173 +	{
   1.174 +	__ASSERT(aTblPolicy);
   1.175 +	__LEAVE_IF_ERROR(iPolicyDomain.iTPCollection.Append(aTblPolicy));
   1.176 +	}
   1.177 +
   1.178 +/**
   1.179 +The method initializes CPolicyDomain::iBackupSID data member.
   1.180 +The backup&restore SID can be ECapability_None, which means - no one is allowed to do backup&restore
   1.181 +for the databases, covered by current policy domain.
   1.182 +@param aTblPolicy aSecureId SID of the process, which is allowed to do backup&restore
   1.183 +                  for databases covered by current TPolicyDomainBuilder object.
   1.184 +*/
   1.185 +inline void TPolicyDomainBuilder::SetBackupSID(TSecureId& aSecureId)
   1.186 +	{
   1.187 +	iPolicyDomain.iBackupSID = aSecureId;
   1.188 +	}
   1.189 +
   1.190 +//////////////////////////////////////////////////////////////////////////////////////////////
   1.191 +//class TPolicyDomainReader
   1.192 +
   1.193 +/**
   1.194 +TPolicyDomainReader is a friend class of CPolicyDomain, which means that it can access
   1.195 +CPolicyDomain's data members and iterate through the policies collection.
   1.196 +The idea is that TPolicyDomainReader will be used by the implementors of MPolicyDomainPersister
   1.197 +interface, removing the need of making them friends of CPolicyDomain or visible from CPolicyDomain.
   1.198 +@param aPolicyDomain A reference to the policy domain object, which collection has to be 
   1.199 +                     traversed by the TPolicyDomainReader instance.
   1.200 +*/
   1.201 +inline TPolicyDomainReader::TPolicyDomainReader(const CPolicyDomain& aPolicyDomain) :
   1.202 +	iPolicyDomain(aPolicyDomain),
   1.203 +	iIndex(0)
   1.204 +	{
   1.205 +	}
   1.206 +
   1.207 +/**
   1.208 +@return The UID of the related CPolicyDomain object.
   1.209 +*/
   1.210 +inline TUid TPolicyDomainReader::Uid() const
   1.211 +	{
   1.212 +	return iPolicyDomain.Uid();
   1.213 +	}
   1.214 +
   1.215 +/**
   1.216 +@return A const reference to the existing CDbPolicy instance - part of the related
   1.217 +        CPolicyDomain security policies collection.
   1.218 +*/
   1.219 +inline const CDbPolicy& TPolicyDomainReader::DbPolicy() const
   1.220 +	{
   1.221 +	__ASSERT(iPolicyDomain.iDbPolicy);
   1.222 +	return *iPolicyDomain.iDbPolicy;
   1.223 +	}
   1.224 +
   1.225 +/**
   1.226 +Resets the iterator for a new scan from the beginning of the controlled table 
   1.227 +policies collection.
   1.228 +*/
   1.229 +inline void TPolicyDomainReader::ResetTblPos() const
   1.230 +	{
   1.231 +	iIndex = 0;
   1.232 +	}
   1.233 +
   1.234 +/**
   1.235 +@return The count of security policies in the controlled table policies collection.
   1.236 +*/
   1.237 +inline TInt TPolicyDomainReader::TblPolicyCount() const
   1.238 +	{
   1.239 +	return iPolicyDomain.iTPCollection.Count();
   1.240 +	}
   1.241 +
   1.242 +/**
   1.243 +@return A const pointer to the next CTblPolicy instance in the controlled collection
   1.244 +        of table security policies.
   1.245 +*/
   1.246 +inline const CTblPolicy* TPolicyDomainReader::NextTblPolicy() const
   1.247 +	{
   1.248 +	return iIndex < iPolicyDomain.iTPCollection.Count() ? iPolicyDomain.iTPCollection[iIndex++] : NULL;
   1.249 +	}
   1.250 +
   1.251 +/**
   1.252 +@return Backup&restore process SID.
   1.253 +*/
   1.254 +inline TSecureId TPolicyDomainReader::BackupSID() const
   1.255 +	{
   1.256 +	return iPolicyDomain.iBackupSID;
   1.257 +	}
   1.258 +
   1.259 +} //end of - namespace DBSC