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