rtsecuritymanager/rtsecuritymanagerserver/src/rtsecmgrserversession.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2009 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:      
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include <e32svr.h>
       
    23 #include <e32uid.h>
       
    24 
       
    25 #include "rtsecmgrserver.h"
       
    26 #include "rtsecmgrdata.h"
       
    27 #include "rtsecmgrpolicyparser.h"
       
    28 #include "rtsecmgrsession.h"
       
    29 #include "rtsecmgrsubsession.h"
       
    30 
       
    31 /**
       
    32  * Called by client/server framework after 
       
    33  * session has been successfully created.
       
    34  * In effect, a second-phase constructor.
       
    35  * creates:
       
    36  * 
       
    37  *  1. the object index
       
    38  *  2. the object container for this session.
       
    39  *
       
    40  */
       
    41 void CRTSecMgrSession::CreateL()
       
    42 	{
       
    43 	if(!iSecMgrServer)
       
    44 		iSecMgrServer = dynamic_cast<CRTSecMgrServer*> (const_cast<CServer2*> (Server()));
       
    45 		
       
    46 	iSecMgrServer->AddSession ();
       
    47 
       
    48 	iSubSessionObjectIndex = CObjectIx::NewL ();
       
    49 	iContainer = iSecMgrServer->NewContainerL ();
       
    50 	}
       
    51 
       
    52 void CRTSecMgrSession::CloseSession()
       
    53 	{
       
    54 	//delete the object index (this stores the objects for this session)
       
    55 	Delete (iSubSessionObjectIndex);
       
    56 	//delete the object container (this provides unique ids for the objects of this session )
       
    57 
       
    58 	iSecMgrServer->RemoveFromContainerIx (iContainer);
       
    59 	iSecMgrServer->RemoveSession ();
       
    60 	}
       
    61 
       
    62 /**
       
    63  * A simple utility function to return the appropriate 
       
    64  * CRTSecMgrSubSession object given a client's subsession handle.
       
    65  */
       
    66 CRTSecMgrSubSession* CRTSecMgrSession::SubSessionFromHandle(
       
    67 		const RMessage2& aMessage, TInt aHandle)
       
    68 	{
       
    69 	CRTSecMgrSubSession* subSession = (CRTSecMgrSubSession*)iSubSessionObjectIndex->At(aHandle);
       
    70 
       
    71 	if ( !subSession)
       
    72 		{
       
    73 		PanicClient (aMessage, EBadSubsessionHandle);
       
    74 		}
       
    75 	return subSession;
       
    76 	}
       
    77 
       
    78 void CRTSecMgrSession::DispatchMessageL(const RMessage2& aMessage)
       
    79 	{
       
    80 	// First check for session-relative requests
       
    81 	switch (aMessage.Function ())
       
    82 		{
       
    83 		case ESetPolicy:
       
    84 			SetPolicy (aMessage);
       
    85 			return;
       
    86 		case EUpdatePolicy:
       
    87 			UpdatePolicy (aMessage);
       
    88 			return;
       
    89 		case EUnsetPolicy:
       
    90 			UnsetPolicy (aMessage);
       
    91 			return;
       
    92 		case ERegisterScript:
       
    93 			RegisterScript (aMessage);
       
    94 			return;
       
    95 		case ERegisterScriptWithHash:
       
    96 			RegisterScript (aMessage, ETrue);
       
    97 			return;
       
    98 		case EUnRegisterScript:
       
    99 			UnregisterScript (aMessage);
       
   100 			return;
       
   101 		case EGetScriptSession:
       
   102 			GetScriptSessionL (aMessage);
       
   103 			return;
       
   104 		case EGetTrustedUnRegScriptSession:
       
   105 			GetTrustedUnRegScriptSessionL (aMessage);
       
   106 			return;
       
   107 		case ESecServCloseSession:
       
   108 			CloseSession ();
       
   109 			return;
       
   110 			}
       
   111 
       
   112 	// All other function codes must be subsession relative.
       
   113 	// We need to find the appropriate server side subsession
       
   114 	// i.e. the CRTSecMgrSubSession object. 
       
   115 	// The handle value is passed as the 4th aregument.
       
   116 	CRTSecMgrSubSession* subSession = SubSessionFromHandle (aMessage,
       
   117 			aMessage.Int3 ());
       
   118 	switch (aMessage.Function ())
       
   119 		{
       
   120 		case ECloseScriptSession:
       
   121 			DeleteSubSession (aMessage.Int3 ());
       
   122 			return;
       
   123 		case EUpdatePermanentGrant:
       
   124 			subSession->UpdatePermGrantL (aMessage);
       
   125 			return;
       
   126 		case EGetScriptFile:
       
   127 			subSession->GetScriptFile (aMessage);
       
   128 			return;
       
   129 		case EUpdatePermanentGrantProvider:
       
   130 		    subSession->UpdatePermGrantProviderL (aMessage);
       
   131 		    return;
       
   132 		default:
       
   133 			PanicClient (aMessage, EBadRequest);
       
   134 			return;
       
   135 		}
       
   136 	}
       
   137 TBool CRTSecMgrSession::IsScriptOpenWithPolicy(TPolicyID aPolicyID)
       
   138 	{
       
   139 	for (TInt i(0); i!=iSubSessionObjectIndex->Count ();++i)
       
   140 		{
       
   141 		CRTSecMgrSubSession
       
   142 				* subsession = ((CRTSecMgrSubSession*)iSubSessionObjectIndex->operator[](i));
       
   143 		if ( subsession)
       
   144 			{
       
   145 			if ( aPolicyID==subsession->Script().PolicyID ())
       
   146 				{
       
   147 				return ETrue;
       
   148 				}
       
   149 			}
       
   150 		else
       
   151 			{
       
   152 			continue;
       
   153 			}
       
   154 
       
   155 		}
       
   156 	return EFalse;
       
   157 	}
       
   158 
       
   159 TBool CRTSecMgrSession::IsScriptSessionOpen(TExecutableID aScriptID,CRTSecMgrSubSession* aCurrentSession)
       
   160 	{
       
   161 	for (TInt i(0); i!=iSubSessionObjectIndex->Count ();++i)
       
   162 		{
       
   163 		CRTSecMgrSubSession
       
   164 				* subsession = ((CRTSecMgrSubSession*)iSubSessionObjectIndex->operator[](i));
       
   165 		if ( subsession && ( subsession != aCurrentSession))
       
   166 			{
       
   167 			if ( aScriptID==subsession->ScriptID ())
       
   168 				{
       
   169 				return ETrue;
       
   170 				}
       
   171 			}
       
   172 		else
       
   173 			{
       
   174 			continue;
       
   175 			}
       
   176 
       
   177 		}
       
   178 	return EFalse;
       
   179 	}