eapol/eapol_framework/eapol_symbian/am/common/symbian/EapPluginTools.cpp
branchRCL_3
changeset 19 c74b3d9f6b9e
parent 18 bad0cc58d154
equal deleted inserted replaced
18:bad0cc58d154 19:c74b3d9f6b9e
     1 /*
       
     2 * Copyright (c) 2001-2010 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:  Tools for plugin handling on Symbian.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 19 %
       
    20 */
       
    21 
       
    22 #include <EapTraceSymbian.h>
       
    23 #include <EapTypePlugin.h>
       
    24 #include <ecom.h>
       
    25 
       
    26 #include "EapPluginTools.h"
       
    27 #include "EapAutomatic.h"
       
    28 
       
    29 /** @file */
       
    30 
       
    31 // ----------------------------------------------------------------------
       
    32 
       
    33 EXPORT_C EapPluginTools::EapPluginTools()
       
    34 {
       
    35 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::EapPluginTools(): this=0x%08x.\n"),
       
    36 		this));
       
    37 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapPluginTools::EapPluginTools()"));
       
    38 }
       
    39 
       
    40 // ----------------------------------------------------------------------
       
    41 
       
    42 EXPORT_C EapPluginTools::~EapPluginTools()
       
    43 {
       
    44 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::~EapPluginTools(): this=0x%08x.\n"),
       
    45 		this));
       
    46 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapPluginTools::~EapPluginTools()"));
       
    47 }
       
    48 
       
    49 // ----------------------------------------------------------------------
       
    50 
       
    51 EXPORT_C void EapPluginTools::CleanupImplArray( TAny* aAny )
       
    52 {
       
    53 	RImplInfoPtrArray* implArray = 
       
    54 		reinterpret_cast<RImplInfoPtrArray*>( aAny );
       
    55 
       
    56 	implArray->ResetAndDestroy();
       
    57 	implArray->Close();
       
    58 }
       
    59 
       
    60 // ----------------------------------------------------------------------
       
    61 
       
    62 EXPORT_C void EapPluginTools::ListAllEapPluginsL(const TIndexType aIndexType, const TEapExpandedType & aTunnelingEapType, RPointerArray<TEapExpandedType> & aPlugins)
       
    63 {
       
    64 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): this=0x%08x, aTunnelingEapType=0xfe%06x%08x.\n"),
       
    65 		this,
       
    66 		aTunnelingEapType.GetVendorId(),
       
    67 		aTunnelingEapType.GetVendorType()));
       
    68 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapPluginTools::ListAllEapPluginsL()"));
       
    69 
       
    70 	aPlugins.Reset();   // Reset this first
       
    71 
       
    72 	RImplInfoPtrArray aEapArray;
       
    73 
       
    74 	CleanupStack::PushL( TCleanupItem( CleanupImplArray, &aEapArray ) );
       
    75 
       
    76 	REComSession::ListImplementationsL( KEapTypeInterfaceUid, aEapArray );
       
    77 
       
    78 	// Checks which plugins are allowed inside the tunneling EAP-methods and which are allowed outer most EAP-methods.
       
    79 	for( TInt counter = 0; counter < aEapArray.Count(); counter++ )
       
    80 	{
       
    81 		TEapExpandedType plugin_type(aEapArray[counter]->DataType());
       
    82 
       
    83 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x\n"),
       
    84 			counter,
       
    85 			plugin_type.GetVendorId(),
       
    86 			plugin_type.GetVendorType()));
       
    87 
       
    88 		TBool aNotAllowed(EFalse);
       
    89 
       
    90 		if (aIndexType == ELan
       
    91 			&& aTunnelingEapType == (*EapExpandedTypeNone.GetType()))
       
    92 		{
       
    93 			// Filter out the EAP types which are NOT allowed outside PEAP, TTLS or FAST on WLAN.
       
    94 			if( CEapTypePlugin::IsDisallowedOutsidePEAP( *aEapArray[counter] ) )
       
    95 			{
       
    96 				EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x, IsDisallowedOutsidePEAP()\n"),
       
    97 					counter,
       
    98 					plugin_type.GetVendorId(),
       
    99 					plugin_type.GetVendorType()));
       
   100 
       
   101 				aNotAllowed = ETrue;
       
   102 			}
       
   103 		}
       
   104 		else if (aTunnelingEapType == (*EapExpandedTypePeap.GetType())
       
   105 			|| aTunnelingEapType == (*EapExpandedTypeFast.GetType()))
       
   106 		{
       
   107 			// Filter out the EAP types which are NOT allowed inside PEAP or FAST.
       
   108 			if( CEapTypePlugin::IsDisallowedInsidePEAP( *aEapArray[counter] ) )
       
   109 			{
       
   110 				EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x, IsDisallowedInsidePEAP()\n"),
       
   111 					counter,
       
   112 					plugin_type.GetVendorId(),
       
   113 					plugin_type.GetVendorType()));
       
   114 
       
   115 				aNotAllowed = ETrue;
       
   116 			}
       
   117 		}
       
   118 		else if (aTunnelingEapType == (*EapExpandedTypeTtls.GetType()))
       
   119 		{
       
   120 			// Filter out the EAP types which are NOT allowed inside TTLS.
       
   121 			if( CEapTypePlugin::IsDisallowedInsideTTLS( *aEapArray[counter] ) )
       
   122 			{
       
   123 				EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x, IsDisallowedInsideTTLS()\n"),
       
   124 					counter,
       
   125 					plugin_type.GetVendorId(),
       
   126 					plugin_type.GetVendorType()));
       
   127 
       
   128 				aNotAllowed = ETrue;
       
   129 			}
       
   130 		}
       
   131 
       
   132 		if (aNotAllowed)
       
   133 		{
       
   134 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): Removes EAP-plugin aEapArray[%d] EAP-type=0xfe%06x%08x\n"),
       
   135 				counter,
       
   136 				plugin_type.GetVendorId(),
       
   137 				plugin_type.GetVendorType()));
       
   138 
       
   139 			// Delete the EAP type, which isn't allowed here from the array.
       
   140 			delete aEapArray[counter];
       
   141 			aEapArray.Remove( counter );
       
   142 
       
   143 			// One item removed from the array. So reduce the item counter.
       
   144 			counter--;
       
   145 		}
       
   146 	}
       
   147 
       
   148 	// Adds allowed EAP-methods to an array.
       
   149 	for (TInt ind = 0; ind < aEapArray.Count(); ind++ )
       
   150 	{
       
   151 		TEapExpandedType * eap_type = new TEapExpandedType;
       
   152 		if (eap_type != 0)
       
   153 		{
       
   154 			*eap_type = aEapArray[ind]->DataType();
       
   155 
       
   156 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x\n"),
       
   157 				ind,
       
   158 				eap_type->GetVendorId(),
       
   159 				eap_type->GetVendorType()));
       
   160 
       
   161 			User::LeaveIfError( aPlugins.Append( eap_type ) );
       
   162 		}
       
   163 	}
       
   164 
       
   165 	CleanupStack::PopAndDestroy(&aEapArray);
       
   166 }
       
   167 
       
   168 // ----------------------------------------------------------------------
       
   169 
       
   170 EXPORT_C void EapPluginTools::GetPrivatePathL(
       
   171 	RFs& aFileServerSession,
       
   172 	TFileName& aPrivateDatabasePathName)
       
   173 {
       
   174 	// Reads the private folder. Caller must connect file server before calling this function.
       
   175 
       
   176 	CleanupClosePushL(aFileServerSession);
       
   177 
       
   178 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - calls aFileServerSession.PrivatePath()\n")));
       
   179 
       
   180 	aPrivateDatabasePathName.SetLength(0);
       
   181 
       
   182 	TInt error = aFileServerSession.PrivatePath(aPrivateDatabasePathName);
       
   183 
       
   184 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - aFileServerSession.PrivatePath(), error=%d\n"), error));
       
   185 
       
   186 	User::LeaveIfError(error);
       
   187 
       
   188 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("aPrivateDatabasePathName",
       
   189 		aPrivateDatabasePathName.Ptr(),
       
   190 		aPrivateDatabasePathName.Size()));
       
   191 
       
   192 	CleanupStack::Pop(&aFileServerSession);
       
   193 }
       
   194 
       
   195 // ----------------------------------------------------------------------
       
   196 
       
   197 EXPORT_C void EapPluginTools::GetPrivatePathL(
       
   198 	TFileName& aPrivateDatabasePathName)
       
   199 {
       
   200 	// Reads the private folder.
       
   201 
       
   202 	RFs aFileServerSession;
       
   203 
       
   204 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - calls aFileServerSession.Connect()\n")));
       
   205 
       
   206 	TInt error = aFileServerSession.Connect();
       
   207 
       
   208 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - aFileServerSession.Connect(), error=%d\n"), error));
       
   209 
       
   210 	User::LeaveIfError(error);
       
   211 
       
   212 	EapPluginTools::GetPrivatePathL(
       
   213 		aFileServerSession,
       
   214 		aPrivateDatabasePathName);
       
   215 
       
   216 	aFileServerSession.Close();
       
   217 }
       
   218 
       
   219 // ----------------------------------------------------------------------
       
   220 
       
   221 EXPORT_C void EapPluginTools::CreateDatabaseLC(
       
   222 	RDbNamedDatabase& aDatabase,
       
   223 	RFs& aFileServerSession,
       
   224 	TInt& error,
       
   225 	const TDesC& aDatabaseName,
       
   226 	TFileName& aPrivateDatabasePathName)
       
   227 {
       
   228 	// Caller must connect file server before calling this function.
       
   229 
       
   230 	// aDatabase is pushed to the cleanup stack even though they may be member
       
   231 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
   232 	// that if they are not member variables they will be closed. Closing the handle twice
       
   233 	// does no harm.	
       
   234 	CleanupClosePushL(aFileServerSession);
       
   235 	CleanupClosePushL(aDatabase);
       
   236 
       
   237 	// Create the private database in the private folder of EAP-server.
       
   238 
       
   239 	EapPluginTools::GetPrivatePathL(
       
   240 		aFileServerSession,
       
   241 		aPrivateDatabasePathName);
       
   242 
       
   243 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::CreateDatabaseLC(): - calls aPrivateDatabasePathName.Append()\n")));
       
   244 
       
   245 	aPrivateDatabasePathName.Append(aDatabaseName);
       
   246 
       
   247 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("aPrivateDatabasePathName",
       
   248 		aPrivateDatabasePathName.Ptr(),
       
   249 		aPrivateDatabasePathName.Size()));
       
   250 
       
   251 	User::LeaveIfError(error);
       
   252 
       
   253 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::CreateDatabaseLC(): - calls aDatabase.Create()\n")));
       
   254 
       
   255 	error = aDatabase.Create(aFileServerSession, aPrivateDatabasePathName);
       
   256 
       
   257 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::CreateDatabaseLC(): - Created private DB for %S. error=%d, (%d is KErrAlreadyExists)\n"),
       
   258 		&aDatabaseName,
       
   259 		error,
       
   260 		KErrAlreadyExists));
       
   261 }
       
   262 
       
   263 // ----------------------------------------------------------------------
       
   264 // End