persistentstorage/dbms/security/SC_Policy.inl
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 namespace DBSC
       
    17 {
       
    18 
       
    19 //////////////////////////////////////////////////////////////////////////////////////////////
       
    20 //class CPolicyBase
       
    21 
       
    22 /**
       
    23 */
       
    24 inline CPolicyBase::CPolicyBase()
       
    25 	{
       
    26 	}
       
    27 
       
    28 /**
       
    29 @return A const reference to the controlled collection of R/W/S policies.
       
    30 */
       
    31 inline const CPolicyBase::RPolicyCollection& CPolicyBase::PolicyCollection() const
       
    32 	{
       
    33 	return iPolicyCollection;
       
    34 	}
       
    35 
       
    36 //////////////////////////////////////////////////////////////////////////////////////////////
       
    37 //class CDbPolicy
       
    38 
       
    39 /**
       
    40 */
       
    41 inline CDbPolicy::CDbPolicy()
       
    42 	{
       
    43 	}
       
    44 
       
    45 /**
       
    46 Standard phase-one CDbPolicy factory method.
       
    47 @param aPolicyCollection A collection of R/W/S policies.
       
    48 @return A pointer to just created CDbPolicy instance.
       
    49 @leave System-wide error codes, including KErrNoMemory
       
    50 */
       
    51 inline CDbPolicy* CDbPolicy::NewL(const RPolicyCollection& aPolicyCollection)
       
    52 	{
       
    53 	CDbPolicy* policy = CDbPolicy::NewLC(aPolicyCollection);
       
    54 	CleanupStack::Pop(policy);
       
    55 	return policy;
       
    56 	}
       
    57 
       
    58 //////////////////////////////////////////////////////////////////////////////////////////////
       
    59 //class CTblPolicy
       
    60 
       
    61 /**
       
    62 */
       
    63 inline CTblPolicy::CTblPolicy(const CDbPolicy* aDbPolicy) :
       
    64 	iDbPolicy(aDbPolicy)
       
    65 	{
       
    66 	__ASSERT(iDbPolicy);
       
    67 	}
       
    68 
       
    69 /**
       
    70 Standard phase-one CTblPolicy factory method.
       
    71 @param aTblName The name of the table, access to which is controlled by the supplied policies
       
    72 @param aPolicyCollection A collection of R/W/S policies.
       
    73 @param aDbPolicy The related for the table database policy.
       
    74 @return A pointer to just created CTblPolicy instance.
       
    75 @leave System-wide error codes, including KErrNoMemory
       
    76 */
       
    77 inline CTblPolicy* CTblPolicy::NewL(const TDesC& aTblName, 
       
    78 									const RPolicyCollection& aPolicyCollection,
       
    79 									const CDbPolicy* aDbPolicy)
       
    80 	{
       
    81 	CTblPolicy* policy = CTblPolicy::NewLC(aTblName, aPolicyCollection, aDbPolicy);
       
    82 	CleanupStack::Pop(policy);
       
    83 	return policy;
       
    84 	}
       
    85 
       
    86 /**
       
    87 @return A const reference to the table name.
       
    88 */
       
    89 inline const TDesC& CTblPolicy::TableName() const
       
    90 	{
       
    91 	DB_INVARIANT();
       
    92 	return *iTblName;
       
    93 	}
       
    94 
       
    95 //////////////////////////////////////////////////////////////////////////////////////////////
       
    96 //class CPolicyDomain
       
    97 
       
    98 /**
       
    99 CPolicyDomain collection of table security policies  - the granularity.
       
   100 @internalComponent
       
   101 */
       
   102 const TInt KTblPolicyCollGranularity = 32;
       
   103 
       
   104 /**
       
   105 @param aUid The domain UID
       
   106 */
       
   107 inline CPolicyDomain::CPolicyDomain(TUid aUid) :
       
   108 	iUid(aUid),
       
   109 	iTPCollection(KTblPolicyCollGranularity)
       
   110 	{
       
   111 	}
       
   112 
       
   113 /**
       
   114 Standard phase-one CPolicyDomain factory method.
       
   115 @param aUid The format uid of the databases, access to which is controlled by security policies
       
   116 @param aPDLoader The interface, which actual implementation is used to load the related set
       
   117                  of security policies into CPolicyDomain collection. Currently CPolicyDomain
       
   118 				 policy collection can be loaded from a text or binary policy file.
       
   119 @return A pointer to just created CPolicyDomain instance.
       
   120 @leave System-wide error codes, including KErrNoMemory
       
   121 */
       
   122 inline CPolicyDomain* CPolicyDomain::NewL(TUid aUid, MPolicyDomainLoader& aPDLoader)
       
   123 	{
       
   124 	CPolicyDomain* domain = CPolicyDomain::NewLC(aUid, aPDLoader);
       
   125 	CleanupStack::Pop(domain);
       
   126 	return domain;
       
   127 	}
       
   128 
       
   129 /**
       
   130 @return Policy domain UID.
       
   131 */
       
   132 inline TUid CPolicyDomain::Uid() const
       
   133 	{
       
   134 	DB_INVARIANT();
       
   135 	return iUid;
       
   136 	}
       
   137 
       
   138 /**
       
   139 @return Backup&restore SID.
       
   140 */
       
   141 inline TSecureId CPolicyDomain::BackupSID() const
       
   142 	{
       
   143 	DB_INVARIANT();
       
   144 	return iBackupSID;
       
   145 	}
       
   146 
       
   147 //////////////////////////////////////////////////////////////////////////////////////////////
       
   148 //class TPolicyDomainBuilder
       
   149 
       
   150 /**
       
   151 TPolicyDomainBuilder is a friend class of CPolicyDomain, which means that it can access
       
   152 CPolicyDomain's data members and add/update new policies there.
       
   153 The idea is that TPolicyDomainBuilder will be used by the implementors of MPolicyDomainLoader
       
   154 interface, removing the need of making them friends of CPolicyDomain or visible from CPolicyDomain.
       
   155 @param aPolicyDomain A reference to the policy domain object, which collection has to be 
       
   156                      created by the TPolicyDomainBuilder instance.
       
   157 */
       
   158 inline TPolicyDomainBuilder::TPolicyDomainBuilder(CPolicyDomain& aPolicyDomain) :
       
   159 	iPolicyDomain(aPolicyDomain)
       
   160 	{
       
   161 	}
       
   162 
       
   163 /**
       
   164 The method adds a table policy to the related CPolicyDomain collection.
       
   165 @param aTblPolicy A pointer to CTblPolicy instance, which has to be added to 
       
   166                   the related CPolicyDomain collection. CPolicyDomain collection takes the
       
   167 				  ownership on the supplied CTblPolicy instance.
       
   168 */
       
   169 inline void TPolicyDomainBuilder::AddTblPolicyL(CTblPolicy* aTblPolicy)
       
   170 	{
       
   171 	__ASSERT(aTblPolicy);
       
   172 	__LEAVE_IF_ERROR(iPolicyDomain.iTPCollection.Append(aTblPolicy));
       
   173 	}
       
   174 
       
   175 /**
       
   176 The method initializes CPolicyDomain::iBackupSID data member.
       
   177 The backup&restore SID can be ECapability_None, which means - no one is allowed to do backup&restore
       
   178 for the databases, covered by current policy domain.
       
   179 @param aTblPolicy aSecureId SID of the process, which is allowed to do backup&restore
       
   180                   for databases covered by current TPolicyDomainBuilder object.
       
   181 */
       
   182 inline void TPolicyDomainBuilder::SetBackupSID(TSecureId& aSecureId)
       
   183 	{
       
   184 	iPolicyDomain.iBackupSID = aSecureId;
       
   185 	}
       
   186 
       
   187 //////////////////////////////////////////////////////////////////////////////////////////////
       
   188 //class TPolicyDomainReader
       
   189 
       
   190 /**
       
   191 TPolicyDomainReader is a friend class of CPolicyDomain, which means that it can access
       
   192 CPolicyDomain's data members and iterate through the policies collection.
       
   193 The idea is that TPolicyDomainReader will be used by the implementors of MPolicyDomainPersister
       
   194 interface, removing the need of making them friends of CPolicyDomain or visible from CPolicyDomain.
       
   195 @param aPolicyDomain A reference to the policy domain object, which collection has to be 
       
   196                      traversed by the TPolicyDomainReader instance.
       
   197 */
       
   198 inline TPolicyDomainReader::TPolicyDomainReader(const CPolicyDomain& aPolicyDomain) :
       
   199 	iPolicyDomain(aPolicyDomain),
       
   200 	iIndex(0)
       
   201 	{
       
   202 	}
       
   203 
       
   204 /**
       
   205 @return The UID of the related CPolicyDomain object.
       
   206 */
       
   207 inline TUid TPolicyDomainReader::Uid() const
       
   208 	{
       
   209 	return iPolicyDomain.Uid();
       
   210 	}
       
   211 
       
   212 /**
       
   213 @return A const reference to the existing CDbPolicy instance - part of the related
       
   214         CPolicyDomain security policies collection.
       
   215 */
       
   216 inline const CDbPolicy& TPolicyDomainReader::DbPolicy() const
       
   217 	{
       
   218 	__ASSERT(iPolicyDomain.iDbPolicy);
       
   219 	return *iPolicyDomain.iDbPolicy;
       
   220 	}
       
   221 
       
   222 /**
       
   223 Resets the iterator for a new scan from the beginning of the controlled table 
       
   224 policies collection.
       
   225 */
       
   226 inline void TPolicyDomainReader::ResetTblPos() const
       
   227 	{
       
   228 	iIndex = 0;
       
   229 	}
       
   230 
       
   231 /**
       
   232 @return The count of security policies in the controlled table policies collection.
       
   233 */
       
   234 inline TInt TPolicyDomainReader::TblPolicyCount() const
       
   235 	{
       
   236 	return iPolicyDomain.iTPCollection.Count();
       
   237 	}
       
   238 
       
   239 /**
       
   240 @return A const pointer to the next CTblPolicy instance in the controlled collection
       
   241         of table security policies.
       
   242 */
       
   243 inline const CTblPolicy* TPolicyDomainReader::NextTblPolicy() const
       
   244 	{
       
   245 	return iIndex < iPolicyDomain.iTPCollection.Count() ? iPolicyDomain.iTPCollection[iIndex++] : NULL;
       
   246 	}
       
   247 
       
   248 /**
       
   249 @return Backup&restore process SID.
       
   250 */
       
   251 inline TSecureId TPolicyDomainReader::BackupSID() const
       
   252 	{
       
   253 	return iPolicyDomain.iBackupSID;
       
   254 	}
       
   255 
       
   256 } //end of - namespace DBSC