eapol/eapol_framework/eapol_symbian/am/common/symbian/EapPluginTools.cpp
changeset 26 9abfd4f00d37
child 34 ad1f037f1ac2
equal deleted inserted replaced
25:e03a3db4489e 26:9abfd4f00d37
       
     1 /*
       
     2 * Copyright (c) 2001-2006 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:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 11 %
       
    20 */
       
    21 
       
    22 #include <EapTraceSymbian.h>
       
    23 #include <EapAutomatic.h>
       
    24 #include <EapPluginTools.h>
       
    25 #include <EapTypePlugin.h>
       
    26 #include <ecom.h>
       
    27 
       
    28 /** @file */
       
    29 
       
    30 // ----------------------------------------------------------------------
       
    31 
       
    32 EXPORT_C EapPluginTools::EapPluginTools()
       
    33 {
       
    34 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::EapPluginTools(): this=0x%08x.\n"),
       
    35 		this));
       
    36 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapPluginTools::EapPluginTools()"));
       
    37 }
       
    38 
       
    39 // ----------------------------------------------------------------------
       
    40 
       
    41 EXPORT_C EapPluginTools::~EapPluginTools()
       
    42 {
       
    43 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::~EapPluginTools(): this=0x%08x.\n"),
       
    44 		this));
       
    45 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapPluginTools::~EapPluginTools()"));
       
    46 }
       
    47 
       
    48 // ----------------------------------------------------------------------
       
    49 
       
    50 EXPORT_C void EapPluginTools::CleanupImplArray( TAny* aAny )
       
    51 {
       
    52 	RImplInfoPtrArray* implArray = 
       
    53 		reinterpret_cast<RImplInfoPtrArray*>( aAny );
       
    54 
       
    55 	implArray->ResetAndDestroy();
       
    56 	implArray->Close();
       
    57 }
       
    58 
       
    59 // ----------------------------------------------------------------------
       
    60 
       
    61 EXPORT_C void EapPluginTools::ListAllEapPluginsL(const TEapExpandedType & aTunnelingEapType, RPointerArray<TEapExpandedType> & aPlugins)
       
    62 {
       
    63 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): this=0x%08x, aTunnelingEapType=0xfe%06x%08x.\n"),
       
    64 		this,
       
    65 		aTunnelingEapType.GetVendorId(),
       
    66 		aTunnelingEapType.GetVendorType()));
       
    67 	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapPluginTools::ListAllEapPluginsL()"));
       
    68 
       
    69 	aPlugins.Reset();   // Reset this first
       
    70 
       
    71 	RImplInfoPtrArray aEapArray;
       
    72 
       
    73 	CleanupStack::PushL( TCleanupItem( CleanupImplArray, &aEapArray ) );
       
    74 
       
    75 	REComSession::ListImplementationsL( KEapTypeInterfaceUid, aEapArray );
       
    76 
       
    77 	// EAP plugin interface dialog should show only the EAP types that allowed
       
    78 	// outside EAP-PEAP, EAP-TTLS and EAP-FAST.
       
    79 
       
    80 	for( TInt counter = 0; counter < aEapArray.Count(); counter++ )
       
    81 	{
       
    82 		TEapExpandedType plugin_type(aEapArray[counter]->DataType());
       
    83 
       
    84 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x\n"),
       
    85 			counter,
       
    86 			plugin_type.GetVendorId(),
       
    87 			plugin_type.GetVendorType()));
       
    88 
       
    89 		TBool aNotAllowed(EFalse);
       
    90 
       
    91 		if (aTunnelingEapType == (*EapExpandedTypeNone.GetType()))
       
    92 		{
       
    93 			// Filter out the EAP types which are NOT allowed outside PEAP, TTLS or FAST.
       
    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 	for (TInt ind = 0; ind < aEapArray.Count(); ind++ )
       
   149 	{
       
   150 		TEapExpandedType * eap_type = new TEapExpandedType;
       
   151 		if (eap_type != 0)
       
   152 		{
       
   153 			*eap_type = aEapArray[ind]->DataType();
       
   154 
       
   155 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::ListAllEapPluginsL(): aEapArray[%d] EAP-type=0xfe%06x%08x\n"),
       
   156 				ind,
       
   157 				eap_type->GetVendorId(),
       
   158 				eap_type->GetVendorType()));
       
   159 
       
   160 			User::LeaveIfError( aPlugins.Append( eap_type ) );
       
   161 		}
       
   162 	}
       
   163 
       
   164 	CleanupStack::PopAndDestroy(&aEapArray);
       
   165 }
       
   166 
       
   167 // ----------------------------------------------------------------------
       
   168 
       
   169 EXPORT_C void EapPluginTools::GetPrivatePathL(
       
   170 	RFs& aFileServerSession,
       
   171 	TFileName& aPrivateDatabasePathName)
       
   172 {
       
   173 	// Reads the private folder.
       
   174 
       
   175 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - calls aFileServerSession.Connect()\n")));
       
   176 
       
   177 	TInt error = aFileServerSession.Connect();
       
   178 
       
   179 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - aFileServerSession.Connect(), error=%d\n"), error));
       
   180 
       
   181 	User::LeaveIfError(error);
       
   182 
       
   183 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - calls aFileServerSession.PrivatePath()\n")));
       
   184 
       
   185 	aPrivateDatabasePathName.SetLength(0);
       
   186 
       
   187 	error = aFileServerSession.PrivatePath(aPrivateDatabasePathName);
       
   188 
       
   189 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::GetPrivatePathL(): - aFileServerSession.PrivatePath(), error=%d\n"), error));
       
   190 
       
   191 	User::LeaveIfError(error);
       
   192 
       
   193 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("aPrivateDatabasePathName",
       
   194 		aPrivateDatabasePathName.Ptr(),
       
   195 		aPrivateDatabasePathName.Size()));
       
   196 }
       
   197 
       
   198 // ----------------------------------------------------------------------
       
   199 
       
   200 EXPORT_C void EapPluginTools::GetPrivatePathL(
       
   201 	TFileName& aPrivateDatabasePathName)
       
   202 {
       
   203 	// Reads the private folder.
       
   204 
       
   205 	RFs aFileServerSession;
       
   206 
       
   207 	EapPluginTools::GetPrivatePathL(
       
   208 		aFileServerSession,
       
   209 		aPrivateDatabasePathName);
       
   210 }
       
   211 
       
   212 // ----------------------------------------------------------------------
       
   213 
       
   214 EXPORT_C void EapPluginTools::CreateDatabaseLC(
       
   215 	RDbNamedDatabase& aDatabase,
       
   216 	RFs& aFileServerSession,
       
   217 	TInt& error,
       
   218 	const TDesC& aDatabaseName,
       
   219 	TFileName& aPrivateDatabasePathName)
       
   220 {
       
   221 	CleanupClosePushL(aFileServerSession);
       
   222 	CleanupClosePushL(aDatabase);
       
   223 
       
   224 	// aDatabase is pushed to the cleanup stack even though they may be member
       
   225 	// variables of the calling class and would be closed in the destructor anyway. This ensures
       
   226 	// that if they are not member variables they will be closed. Closing the handle twice
       
   227 	// does no harm.	
       
   228 
       
   229 	// Create the private database in the private folder of EAP-server.
       
   230 
       
   231 	EapPluginTools::GetPrivatePathL(
       
   232 		aFileServerSession,
       
   233 		aPrivateDatabasePathName);
       
   234 
       
   235 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::CreateDatabaseLC(): - calls aPrivateDatabasePathName.Append()\n")));
       
   236 
       
   237 	aPrivateDatabasePathName.Append(aDatabaseName);
       
   238 
       
   239 	EAP_TRACE_DATA_DEBUG_SYMBIAN(("aPrivateDatabasePathName",
       
   240 		aPrivateDatabasePathName.Ptr(),
       
   241 		aPrivateDatabasePathName.Size()));
       
   242 
       
   243 	User::LeaveIfError(error);
       
   244 
       
   245 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::CreateDatabaseLC(): - calls aDatabase.Create()\n")));
       
   246 
       
   247 	error = aDatabase.Create(aFileServerSession, aPrivateDatabasePathName);
       
   248 
       
   249 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapPluginTools::CreateDatabaseLC(): - Created private DB for %S. error=%d, (%d is KErrAlreadyExists)\n"),
       
   250 		&aDatabaseName,
       
   251 		error,
       
   252 		KErrAlreadyExists));
       
   253 }
       
   254 
       
   255 // ----------------------------------------------------------------------
       
   256 // End