rtsecuritymanager/rtsecuritymanagerserver/src/rtsecmgrpolicy.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:       Defines security policy data structure 
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include <e32debug.h>
       
    24 #include "rtsecmgrpolicy.h"
       
    25 #include "rtsecmgrserverdef.h"
       
    26 
       
    27 CPolicy::CPolicy(TPolicyID aPolicyID) :
       
    28 	iPolicyID(aPolicyID)
       
    29 	{
       
    30 	}
       
    31 
       
    32 void CPolicy::ConstructL(const RProtectionDomains& aProtectionDomains, RAliasGroup& aAliasGroup)
       
    33 	{
       
    34 	iAccessPolicy.Reset();
       
    35 	iAliasGroup.Reset();
       
    36 	iAccessPolicy = aProtectionDomains;
       
    37 	iAliasGroup = aAliasGroup;
       
    38 	}
       
    39 
       
    40 CPolicy* CPolicy::NewL(TPolicyID aPolicyID,
       
    41 		const RProtectionDomains& aProtectionDomains, RAliasGroup& aAliasGroup)
       
    42 	{
       
    43 	CPolicy* self = CPolicy::NewLC (aPolicyID, aProtectionDomains, aAliasGroup);
       
    44 	CleanupStack::Pop (self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 CPolicy* CPolicy::NewLC(TPolicyID aPolicyID,
       
    49 		const RProtectionDomains& aProtectionDomains, RAliasGroup& aAliasGroup)
       
    50 	{
       
    51 	CPolicy* self = new (ELeave) CPolicy(aPolicyID);
       
    52 	CleanupStack::PushL (self);
       
    53 	self->ConstructL (aProtectionDomains, aAliasGroup);
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 CPolicy* CPolicy::NewL(TPolicyID aPolicyID, RStoreReadStream& aSource)
       
    58 	{
       
    59 	CPolicy* self = CPolicy::NewLC (aPolicyID, aSource);
       
    60 	CleanupStack::Pop (self);
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 CPolicy* CPolicy::NewLC(TPolicyID aPolicyID, RStoreReadStream& aSource)
       
    65 	{
       
    66 	CPolicy* self = new (ELeave) CPolicy(aPolicyID);
       
    67 	CleanupStack::PushL (self);
       
    68 	self->InternalizeL (aSource);
       
    69 	return self;
       
    70 	}
       
    71 
       
    72 void CPolicy::InternalizeL(RStoreReadStream& aSource)
       
    73 	{
       
    74 	//Read version of the policy
       
    75 	TReal version(aSource.ReadReal32L());
       
    76 	TInt aliasCnt(aSource.ReadInt32L());
       
    77 	
       
    78 	for (TInt i(0); i<aliasCnt;++i)
       
    79 		{
       
    80 		CPermission* alias = CPermission::NewL ();
       
    81 		alias->InternalizeL(aSource);
       
    82 		iAliasGroup.Append (alias);
       
    83 		}
       
    84 		
       
    85 	TInt domainCnt(aSource.ReadInt32L ());
       
    86 	for (TInt i(0); i<domainCnt;++i)
       
    87 		{
       
    88 		CProtectionDomain* domain = CProtectionDomain::NewL (aSource);
       
    89 		iAccessPolicy.Append (domain);
       
    90 		}
       
    91 	}
       
    92 
       
    93 CProtectionDomain* CPolicy::ProtectionDomain(const TDesC& aDomainName) const
       
    94 	{
       
    95 	for (TInt idx(0); idx<iAccessPolicy.Count ();++idx)
       
    96 		{
       
    97 		if ( KErrNone ==iAccessPolicy[idx]->DomainName().CompareF (aDomainName))
       
    98 			{
       
    99 			return iAccessPolicy[idx];
       
   100 			}
       
   101 		}
       
   102 
       
   103 	return NULL;
       
   104 	}
       
   105 
       
   106 CPermission* CPolicy::AliasGroup(const TDesC& aAliasName) const
       
   107 	{
       
   108 	for (TInt idx(0); idx<iAliasGroup.Count ();++idx)
       
   109 		{
       
   110 		if ( KErrNone ==iAliasGroup[idx]->PermName().CompareF (aAliasName))
       
   111 			{
       
   112 			return iAliasGroup[idx];
       
   113 			}
       
   114 		}
       
   115 
       
   116 	return NULL;
       
   117 	}