authenticationservices/authenticationserver/source/server/pluginmgr.cpp
branchRCL_3
changeset 62 a71299154b21
parent 61 641f389e9157
child 63 94225563cd41
equal deleted inserted replaced
61:641f389e9157 62:a71299154b21
     1 /*
       
     2 * Copyright (c) 2005-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 * Implementation of CPluginMgr
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include "authserver_impl.h"
       
    25 #include <authserver/authpatchdata.h>
       
    26 #include <u32hal.h>
       
    27 #include <e32svr.h> 
       
    28 using namespace AuthServer;
       
    29 
       
    30 TLinearOrder<CAuthPluginInterface> CPluginMgr::SPluginOrder(PluginCompare);
       
    31 
       
    32 TInt CPluginMgr::PluginCompare(const CAuthPluginInterface& aLhs,
       
    33 									  const CAuthPluginInterface& aRhs)
       
    34   {
       
    35   return aLhs.Id() - aRhs.Id();
       
    36   }
       
    37 
       
    38 TInt CPluginMgr::FindById(const TPluginId* aId,
       
    39 						 const CAuthPluginInterface& aRhs)
       
    40   {
       
    41   return *aId - aRhs.Id();
       
    42   }
       
    43 
       
    44 
       
    45 CPluginMgr* CPluginMgr::NewLC()
       
    46   {
       
    47   CPluginMgr* me = new (ELeave) CPluginMgr();
       
    48   CleanupStack::PushL(me);
       
    49   me->ConstructL();
       
    50   return me;
       
    51   } 
       
    52 
       
    53 CPluginMgr* CPluginMgr::NewL()
       
    54   {
       
    55   CPluginMgr* me = CPluginMgr::NewLC();
       
    56   CleanupStack::Pop(me);
       
    57   return me;
       
    58   }
       
    59 
       
    60 CPluginMgr::~CPluginMgr()
       
    61   {
       
    62   ReleasePlugins();
       
    63   ReleaseImplInfo();
       
    64   }
       
    65 
       
    66 
       
    67 void CPluginMgr::ConstructL()
       
    68   {
       
    69   BuildAuthPluginsListL();
       
    70   }
       
    71 
       
    72 CAuthPluginInterface* CPluginMgr::PluginL(const TPluginId& aId)
       
    73   {
       
    74   TInt idx = iPlugins.FindInOrder<>(aId, CPluginMgr::FindById);
       
    75   CAuthPluginInterface* plugin = 0;
       
    76   if (idx == KErrNotFound)
       
    77 	{
       
    78 	  plugin = CreatePluginImplementationL(aId);
       
    79 	  iPlugins.InsertInOrder(plugin, SPluginOrder);
       
    80 	}
       
    81   else
       
    82 	{
       
    83 	plugin = iPlugins[idx];
       
    84 	}
       
    85   
       
    86   return plugin;
       
    87   }
       
    88 
       
    89 CAuthPluginInterface* CPluginMgr::ImplementationL(TInt aIndex)
       
    90 	{
       
    91 	if( aIndex < 0 || aIndex > iPlugins.Count()-1 )
       
    92 		{
       
    93 		User::Leave(KErrArgument);
       
    94 		}
       
    95 	return iPlugins[aIndex];
       
    96 	}
       
    97 
       
    98 const RImplInfoPtrArray& CPluginMgr::ImplementationsL()
       
    99     {
       
   100     if (iImplArray.Count() == 0) 
       
   101         {
       
   102         //To load plugins from sources other than ROM the patch 
       
   103         // data KEnablePostMarketAuthenticationPlugins must be set to True.
       
   104         TUint32 enablePostMarketPlugin = KEnablePostMarketAuthenticationPlugins;
       
   105 
       
   106         #ifdef __WINS__
       
   107 
       
   108         // Default SymbianOS behavior is to only load auth plugins from ROM.
       
   109         enablePostMarketPlugin = 0;
       
   110 
       
   111         // For the emulator allow the constant to be patched via epoc.ini
       
   112         UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
       
   113         (TAny*)"KEnablePostMarketAuthenticationPlugins", &enablePostMarketPlugin); // read emulator property (if present)
       
   114 
       
   115         #endif
       
   116           
       
   117         if(enablePostMarketPlugin == 0)
       
   118         	{
       
   119          	TEComResolverParams resolverParams;
       
   120            	REComSession::ListImplementationsL(KCAuthPluginInterfaceUid,
       
   121         									 resolverParams,
       
   122         									 KRomOnlyResolverUid,
       
   123         									 iImplArray);
       
   124         									 
       
   125             }
       
   126             
       
   127          else
       
   128          	{
       
   129          	REComSession::ListImplementationsL(KCAuthPluginInterfaceUid, iImplArray);
       
   130           	}
       
   131         }
       
   132     return iImplArray;
       
   133     }
       
   134 
       
   135 void CPluginMgr::ReleasePlugins()
       
   136   {
       
   137   TInt i = iPlugins.Count();
       
   138   while (i)
       
   139 	{
       
   140 	delete iPlugins[--i];
       
   141 	}
       
   142   
       
   143   i = iPluginDtorUids.Count();
       
   144   
       
   145   while(i)
       
   146 	  {
       
   147 	  REComSession::DestroyedImplementation(iPluginDtorUids[--i]);
       
   148 	  }
       
   149   iPlugins.Reset();
       
   150   iPluginDtorUids.Reset();
       
   151   }
       
   152 
       
   153 void CPluginMgr::ForgetIdentityL(TIdentityId aId)
       
   154   {
       
   155   ImplementationsL();
       
   156   
       
   157   TInt i = iImplArray.Count();
       
   158   while (i)
       
   159 	{
       
   160 	PluginL(iImplArray[--i]->ImplementationUid().iUid)->Forget(aId);
       
   161 	}
       
   162   }
       
   163 
       
   164 void CPluginMgr::ReleaseImplInfo()
       
   165   {
       
   166   TInt i = iImplArray.Count();
       
   167   while (i)
       
   168 	{
       
   169 	  delete iImplArray[--i];
       
   170 	}
       
   171   
       
   172   iImplArray.Reset();
       
   173   }
       
   174   
       
   175 void CPluginMgr::BuildAuthPluginsListL()
       
   176 	{
       
   177 	ReleasePlugins();
       
   178   	ReleaseImplInfo();
       
   179   	
       
   180 	ImplementationsL();
       
   181   	CAuthPluginInterface* plugin = 0;
       
   182   	for( TInt count=0; count < iImplArray.Count(); ++count)
       
   183 		{
       
   184 		plugin = CreatePluginImplementationL(iImplArray[count]->ImplementationUid().iUid);
       
   185 
       
   186 		CleanupStack::PushL(plugin);
       
   187 		User::LeaveIfError(iPlugins.InsertInOrder(plugin, SPluginOrder));
       
   188 		CleanupStack::Pop(plugin);
       
   189 		}
       
   190 	}
       
   191 
       
   192 CAuthPluginInterface* CPluginMgr::CreatePluginImplementationL(const TPluginId &aId)
       
   193 	{
       
   194 	TEComResolverParams resolverParams;
       
   195 	TBufC8<16> pluginIdTxt;
       
   196 	pluginIdTxt.Des().Format(_L8("%x"), aId);
       
   197 	pluginIdTxt.Des().UpperCase();
       
   198 	resolverParams.SetDataType(pluginIdTxt);
       
   199 		  
       
   200 	//To load plugins from sources other than ROM the patch 
       
   201 	// data KEnablePostMarketAuthenticationPlugins must be set to True.
       
   202 	TUint32 enablePostMarketPlugin = KEnablePostMarketAuthenticationPlugins;
       
   203 
       
   204 #ifdef __WINS__
       
   205 
       
   206 	// Default SymbianOS behavior is to only load auth plugins from ROM.
       
   207 	enablePostMarketPlugin = 0;
       
   208 
       
   209 	// For the emulator allow the constant to be patched via epoc.ini
       
   210 	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
       
   211 	(TAny*)"KEnablePostMarketAuthenticationPlugins", &enablePostMarketPlugin); // read emulator property (if present)
       
   212 
       
   213 #endif
       
   214 
       
   215 	TAny* plugin = 0;
       
   216 	TInt err = 0;
       
   217 	TUid dtor_ID_Key = TUid::Null();
       
   218 	if(enablePostMarketPlugin == 0) 
       
   219 	  	{
       
   220 	  	TRAP(err, plugin = 
       
   221 		REComSession::CreateImplementationL(KCAuthPluginInterfaceUid,
       
   222 											dtor_ID_Key,
       
   223 											resolverParams,
       
   224 											KRomOnlyResolverUid));
       
   225 	  	}
       
   226 		  
       
   227 	  else
       
   228 	  	{
       
   229 	  	TRAP(err, plugin = 
       
   230 		REComSession::CreateImplementationL(KCAuthPluginInterfaceUid,
       
   231 											dtor_ID_Key,
       
   232 											resolverParams));
       
   233 	  	}
       
   234 		  
       
   235 	 if (err == KErrNotFound)
       
   236 	    {
       
   237 	    err = KErrAuthServNoSuchPlugin;  
       
   238 	    }
       
   239 	 
       
   240 	 //Add key to plugin destructor keys list .
       
   241 	 TInt err2 =  iPluginDtorUids.Append(dtor_ID_Key);
       
   242 	 
       
   243 	 if(KErrNoMemory == err2)
       
   244 		 {
       
   245 		 CAuthPluginInterface* authPlugin = reinterpret_cast<CAuthPluginInterface*>(plugin);
       
   246 		 delete authPlugin;
       
   247 		 REComSession::DestroyedImplementation(dtor_ID_Key);
       
   248 		 User::LeaveNoMemory();
       
   249 		 }
       
   250 	 User::LeaveIfError(err);
       
   251 
       
   252 	return reinterpret_cast<CAuthPluginInterface*>(plugin);
       
   253 	}
       
   254