eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiEapTypes.cpp
branchRCL_3
changeset 18 bad0cc58d154
parent 2 1c7bc153c08e
child 19 c74b3d9f6b9e
--- a/eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiEapTypes.cpp	Thu Aug 19 09:58:27 2010 +0300
+++ b/eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiEapTypes.cpp	Tue Aug 31 15:16:37 2010 +0300
@@ -16,7 +16,7 @@
 */
 
 /*
-* %version: 16 %
+* %version: %
 */
 
 // This is enumeration of EAPOL source code.
@@ -30,11 +30,13 @@
 
 // INCLUDE FILES
 #include <e32base.h>
-#include "EapTlsPeapUtils.h"
+//#include "EapTlsPeapUtils.h"
 #include <EapTlsPeapUiConnection.h>
 #include <EapTlsPeapUiEapTypes.h>
 #include <EapTlsPeapUiEapType.h>
-#include "eap_am_trace_symbian.h"
+#include <EapTraceSymbian.h>
+#include "EapConversion.h"
+#include <EapType.h>
 
 const TUint KNumberOfSupportedEAPTypes = 10; //Now 10, including EAP-FAST & TTLS-PAP
 
@@ -42,17 +44,14 @@
 : iIsOpened(EFalse)
 , iUiConn(aUiConn)
 , iDataPtr(NULL)
+, iEapTypeConnection(NULL)
 {
 }
 
 
 CEapTlsPeapUiEapTypes::~CEapTlsPeapUiEapTypes()
 {
-    if (iUiConn)
-    {
-        Close();
-        iUiConn = NULL;
-    }
+    Close();
 }
 
 
@@ -63,49 +62,48 @@
         return KErrAlreadyExists;
     }
 
-    TInt err = iUiConn->GetDatabase(iDatabase);
-    if (err != KErrNone)
-    {
-        return err;
-    }
+	TEapExpandedType aEapType(iUiConn->GetEapType());
 
+	TRAPD(error, iEapTypeConnection = CEapType::NewL(iUiConn->GetIndexType(), iUiConn->GetIndex(), aEapType));
+	if (error != KErrNone)
+	{
+		EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiEapTypes::Open() CEapType::NewL() error=%d\n"),error));
+		return error;
+	}
+    
+    iEapTypeConnection->SetTunnelingType(iUiConn->GetTunnelingType());
+    
     iIsOpened = ETrue;
 
     return KErrNone;
 }
 
 
-TInt CEapTlsPeapUiEapTypes::GetEapTypes(CArrayFixFlat<TEapTlsPeapUiEapType> ** aDataPtr)
+TInt CEapTlsPeapUiEapTypes::GetEapTypes(RPointerArray<TEapTlsPeapUiEapType> ** aDataPtr)
 {
     if (aDataPtr == NULL)
     {
         return KErrArgument;
     }
-    if (iIsOpened == EFalse)
+
+	if (iIsOpened == EFalse)
     {
         return KErrSessionClosed;
     }
+
     if (iDataPtr != 0)
     {
     	*aDataPtr = iDataPtr;
     	return KErrNone;
     }
-    iDataPtr = new CArrayFixFlat<TEapTlsPeapUiEapType>(KNumberOfSupportedEAPTypes);
+
+    iDataPtr = new RPointerArray<TEapTlsPeapUiEapType>(KNumberOfSupportedEAPTypes);
     if (!iDataPtr)
     {
         return KErrNoMemory;
     }
 
-#ifdef USE_EAP_EXPANDED_TYPES
-
     TRAPD(err, FetchExpandedDataL());
-
-#else
-
-    TRAPD(err, FetchDataL());
-
-#endif //#ifdef USE_EAP_EXPANDED_TYPES
-        
     if (err != KErrNone)
     {
         delete iDataPtr;
@@ -121,56 +119,11 @@
 TInt CEapTlsPeapUiEapTypes::Update()
 {
 
-#ifdef USE_EAP_EXPANDED_TYPES
-
 	TRAPD(err, UpdateExpandedDataL());
 
-#else
-
-	TRAPD(err, UpdateL());
-
-#endif //#ifdef USE_EAP_EXPANDED_TYPES
-
 	return err;
 }
 
-#ifndef USE_EAP_EXPANDED_TYPES
-
-void CEapTlsPeapUiEapTypes::UpdateL()
-{
-	TEapArray eapTypes;
-	TEap* eapTmp; 	
-	
-	TInt i(0);
-	
-	for(i = 0; i < iDataPtr->Count(); i++)
-	{
-		eapTmp = new (ELeave) TEap;
-		CleanupStack::PushL(eapTmp);
-		eapTmp->Enabled	= iDataPtr->At(i).iIsEnabled;
-		eapTmp->UID.Copy(iDataPtr->At(i).iEapType);
-		User::LeaveIfError(eapTypes.Append(eapTmp));
-		CleanupStack::Pop(eapTmp);
-	}	
-
-	TRAPD(err, EapTlsPeapUtils::SetEapDataL(
-			iDatabase, 
-			0, 
-			eapTypes, 
-			iUiConn->GetIndexType(),
-			iUiConn->GetIndex(),
-			static_cast<eap_type_value_e>(iUiConn->GetTunnelingType()),
-			static_cast<eap_type_value_e>(iUiConn->GetEapType())));
-
-	eapTypes.ResetAndDestroy();	
-	if (err != KErrNone)
-	{
-		User::Leave(err);
-	}
-}
-#endif // #ifndef USE_EAP_EXPANDED_TYPES
-
-
 TInt CEapTlsPeapUiEapTypes::Close()
 {
     if (iIsOpened == EFalse)
@@ -182,217 +135,158 @@
     iDataPtr = 0;
 		
     iUiConn = NULL;
+
+	if (iEapTypeConnection)
+	{
+		delete iEapTypeConnection;
+		iEapTypeConnection = 0;
+	}
+
+	iIsOpened = EFalse;
+
     return KErrNone;
 }
 
-#ifndef USE_EAP_EXPANDED_TYPES
-
-void CEapTlsPeapUiEapTypes::FetchDataL()
-{		
-	TEapArray eapTypes;
-	
-	TRAPD(err, EapTlsPeapUtils::GetEapDataL(
-			iDatabase, 
-			0, 
-			eapTypes, 
-			iUiConn->GetIndexType(), 
-			iUiConn->GetIndex(), 
-			static_cast<eap_type_value_e>(iUiConn->GetTunnelingType()),
-			static_cast<eap_type_value_e>(iUiConn->GetEapType())));
-
-	if (err != KErrNone)
-	{
-		eapTypes.ResetAndDestroy();
-		User::Leave(err);
-	}
-	
-	TInt i(0);
-	for	(i = 0; i < eapTypes.Count(); i++)	
-	{
-		TEapTlsPeapUiEapType tmp;
-
-		tmp.iIsEnabled = eapTypes[i]->Enabled;
-		
-		tmp.iEapType.Copy(eapTypes[i]->UID);
-		
-		TRAPD(err, iDataPtr->AppendL(tmp));
-		if (err != KErrNone)
-		{
-			eapTypes.ResetAndDestroy();
-			User::Leave(err);
-		}
-	}
-	eapTypes.ResetAndDestroy();	
-}
-#endif // #ifndef USE_EAP_EXPANDED_TYPES
-
-#ifdef USE_EAP_EXPANDED_TYPES
-
 void CEapTlsPeapUiEapTypes::FetchExpandedDataL()
 {
 	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::FetchExpandedDataL: Start\n")));
 
-	RExpandedEapTypePtrArray enabledEAPTypes;
-	RExpandedEapTypePtrArray disabledEAPTypes;
-
-	eap_type_value_e tunnelingType(static_cast<eap_type_ietf_values_e>(iUiConn->GetTunnelingType()));
-	eap_type_value_e eapType(static_cast<eap_type_ietf_values_e>(iUiConn->GetEapType()));
-
-	TRAPD(err, EapTlsPeapUtils::GetTunnelingExpandedEapDataL(
-			iDatabase, 
-			0, 
-			enabledEAPTypes,
-			disabledEAPTypes, 
-			iUiConn->GetIndexType(), 
-			iUiConn->GetIndex(), 
-			tunnelingType,
-			eapType));
-
-	if (err != KErrNone)
+    EAPSettings aSettings;
+    
+	TRAPD(error,iEapTypeConnection->GetConfigurationL(aSettings));
+	if (error)
 	{
-		enabledEAPTypes.ResetAndDestroy();
-		disabledEAPTypes.ResetAndDestroy();
-		
-		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("CEapTlsPeapUiEapTypes::FetchExpandedDataL: Error from GetTunnelingExpandedEapDataL:%d\n"),
-			err));		
-		
-		User::Leave(err);
-	}
-	
-	EAP_TRACE_DEBUG_SYMBIAN(
-		(_L("CEapTlsPeapUiEapTypes::FetchExpandedDataL: Got tunneling EAPs from DB: enabled=%d,disabled=%d\n"),
-		enabledEAPTypes.Count(), disabledEAPTypes.Count()));		
-	
-	TInt i(0);
-	
-	// First fill the enabled EAP types.	
-	for	(i = 0; i < enabledEAPTypes.Count(); i++)	
-	{
-		TEapTlsPeapUiEapType tmpEAP;
-
-		tmpEAP.iIsEnabled = ETrue; // All EAP types here are enabled.
-		
-		tmpEAP.iEapType.Copy(enabledEAPTypes[i]->iExpandedEAPType);
-		
-		TRAPD(err, iDataPtr->AppendL(tmpEAP));
-		if (err != KErrNone)
-		{
-			enabledEAPTypes.ResetAndDestroy();
-			User::Leave(err);
-		}
-		
-		EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::FetchExpandedDataL:Appended ENABLED EAP type:",
-			tmpEAP.iEapType.Ptr(), 
-			tmpEAP.iEapType.Size() ) );		
+		EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiEapTypes::FetchExpandedDataL(): GetConfigurationL() failed %d\n"), error));
+		User::Leave(error);
 	}
 
-	// Now fill the disabled EAP types.	
-	for	(i = 0; i < disabledEAPTypes.Count(); i++)	
-	{
-		TEapTlsPeapUiEapType tmpEAP;
+	TInt i(0);
 
-		tmpEAP.iIsEnabled = EFalse; // All EAP types here are disabled.
-		
-		tmpEAP.iEapType.Copy(disabledEAPTypes[i]->iExpandedEAPType);
-		
-		TRAPD(err, iDataPtr->AppendL(tmpEAP));
-		if (err != KErrNone)
+	{
+		TEapExpandedType enabledEAPType(*EapExpandedTypeNone.GetType());
+
+		if (aSettings.iEnabledEncapsulatedEAPExpandedTypesPresent)
 		{
-			disabledEAPTypes.ResetAndDestroy();
-			User::Leave(err);
+			// First fill the enabled EAP types.	
+			for	(i = 0; i < aSettings.iEnabledEncapsulatedEAPExpandedTypes.Count(); i++)	
+			{
+				TEapTlsPeapUiEapType * tmpEAP = new (ELeave) TEapTlsPeapUiEapType;
+				if (tmpEAP == 0)
+				{
+					User::Leave(KErrNoMemory);
+				}
+
+				tmpEAP->SetIsEnabled(ETrue); // All EAP types here are enabled.
+				
+				tmpEAP->SetEapType(aSettings.iEnabledEncapsulatedEAPExpandedTypes[i]);
+				
+				TRAPD(err, iDataPtr->AppendL(tmpEAP));
+				if (err != KErrNone)
+				{
+					User::Leave(err);
+				}
+				
+				EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::FetchExpandedDataL(): Appended ENABLED EAP type:",
+					tmpEAP->GetEapType().GetValue().Ptr(), 
+					tmpEAP->GetEapType().GetValue().Length() ) );		
+			}
 		}
-		
-		EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::FetchExpandedDataL:Appended DISABLED EAP type:",
-			tmpEAP.iEapType.Ptr(), 
-			tmpEAP.iEapType.Size() ) );		
 	}
-	
-	enabledEAPTypes.ResetAndDestroy();		
-	disabledEAPTypes.ResetAndDestroy();
-	
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::FetchExpandedDataL: End\n")));	
+
+	{
+		TEapExpandedType disabledEAPType(*EapExpandedTypeNone.GetType());
+
+		if (aSettings.iDisabledEncapsulatedEAPExpandedTypesPresent)
+		{
+			// Now fill the disabled EAP types.	
+			for	(i = 0; i < aSettings.iDisabledEncapsulatedEAPExpandedTypes.Count(); i++)	
+			{
+				TEapTlsPeapUiEapType * tmpEAP = new (ELeave) TEapTlsPeapUiEapType;
+				if (tmpEAP == 0)
+				{
+					User::Leave(KErrNoMemory);
+				}
+
+				tmpEAP->SetIsEnabled(EFalse); // All EAP types here are disabled.
+				
+				tmpEAP->SetEapType(aSettings.iDisabledEncapsulatedEAPExpandedTypes[i]);
+				
+				TRAPD(err, iDataPtr->AppendL(tmpEAP));
+				if (err != KErrNone)
+				{
+					User::Leave(err);
+				}
+				
+				EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::FetchExpandedDataL(): Appended DISABLED EAP type:",
+					tmpEAP->GetEapType().GetValue().Ptr(), 
+					tmpEAP->GetEapType().GetValue().Length() ) );		
+			}
+		}
+	}
+
+	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::FetchExpandedDataL(): End\n")));	
 }
 
 void CEapTlsPeapUiEapTypes::UpdateExpandedDataL()
 {
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL: Start\n")));
+	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL(): Start\n")));
 
-	RExpandedEapTypePtrArray enabledEAPTypes;
-	RExpandedEapTypePtrArray disabledEAPTypes;
-	SExpandedEAPType* expandedEAPTmp;
-	
+	if (iDataPtr == 0)
+	{
+		EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL(): iDataPtr == 0\n")));
+		User::Leave(KErrArgument);
+	}
+
+    EAPSettings aSettings;
+
 	for(TInt i=0 ; i < iDataPtr->Count(); i++)
 	{
-		expandedEAPTmp = new (ELeave) SExpandedEAPType;
-		CleanupStack::PushL(expandedEAPTmp);
-		
-		expandedEAPTmp->iExpandedEAPType.Copy(iDataPtr->At(i).iEapType);
-		
-		if(iDataPtr->At(i).iIsEnabled)
+		if ((*iDataPtr)[i] != 0)
 		{
-			// Enabled
-			TInt error = enabledEAPTypes.Append(expandedEAPTmp);
-
-			if (error != KErrNone)
+			TEapExpandedType expandedEAPTmp = (*iDataPtr)[i]->GetEapType();
+			
+			if((*iDataPtr)[i]->GetIsEnabled())
 			{
-				enabledEAPTypes.ResetAndDestroy();
-				disabledEAPTypes.ResetAndDestroy();
-				User::LeaveIfError(error);
-			}
-		
-			EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::UpdateExpandedDataL:Appended ENABLED EAP type:",
-				expandedEAPTmp->iExpandedEAPType.Ptr(), 
-				expandedEAPTmp->iExpandedEAPType.Size() ) );
-		}
-		else
-		{
-			// Disabled
-			TInt error = disabledEAPTypes.Append(expandedEAPTmp);
+				// Enabled
+				TInt error = aSettings.iEnabledEncapsulatedEAPExpandedTypes.Append(expandedEAPTmp);
 
-			if (error != KErrNone)
-			{
-				enabledEAPTypes.ResetAndDestroy();
-				disabledEAPTypes.ResetAndDestroy();
-				User::LeaveIfError(error);
-			}
+				if (error != KErrNone)
+				{
+					User::LeaveIfError(error);
+				}
+			
+				aSettings.iEnabledEncapsulatedEAPExpandedTypesPresent = ETrue;
 
-			EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::UpdateExpandedDataL:Appended DISABLED EAP type:",
-				expandedEAPTmp->iExpandedEAPType.Ptr(), 
-				expandedEAPTmp->iExpandedEAPType.Size() ) );
-		}
-		
-		CleanupStack::Pop(expandedEAPTmp);	
-	}	
+				EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::UpdateExpandedDataL(): Appended ENABLED EAP type:",
+					expandedEAPTmp.GetValue().Ptr(), 
+					expandedEAPTmp.GetValue().Size() ) );
+			}
+			else
+			{
+				// Disabled
+				TInt error = aSettings.iDisabledEncapsulatedEAPExpandedTypes.Append(expandedEAPTmp);
 
-	eap_type_value_e tunnelingType(static_cast<eap_type_ietf_values_e>(iUiConn->GetTunnelingType()));
-	eap_type_value_e eapType(static_cast<eap_type_ietf_values_e>(iUiConn->GetEapType()));
+				if (error != KErrNone)
+				{
+					User::LeaveIfError(error);
+				}
+
+				aSettings.iDisabledEncapsulatedEAPExpandedTypesPresent = ETrue;
 
-	TRAPD(err, EapTlsPeapUtils::SetTunnelingExpandedEapDataL(
-			iDatabase, 
-			0, 
-			enabledEAPTypes,
-			disabledEAPTypes, 
-			iUiConn->GetIndexType(),
-			iUiConn->GetIndex(),
-			tunnelingType,
-			eapType));
+				EAP_TRACE_DATA_DEBUG_SYMBIAN(("CEapTlsPeapUiEapTypes::UpdateExpandedDataL(): Appended DISABLED EAP type:",
+					expandedEAPTmp.GetValue().Ptr(), 
+					expandedEAPTmp.GetValue().Size() ) );
+			}
+		}
+	} // for()
 
-	enabledEAPTypes.ResetAndDestroy();
-	disabledEAPTypes.ResetAndDestroy();
-		
-	if (err != KErrNone)
-	{
-		EAP_TRACE_DEBUG_SYMBIAN(
-			(_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL: Error from SetTunnelingExpandedEapDataL:%d\n"),
-			err));		
+	TRAPD(error,iEapTypeConnection->SetConfigurationL(aSettings));
+
+	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL(): error = %d\n"),error));
+
+	User::LeaveIfError(error);
 	
-		User::Leave(err);
-	}
-	
-	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL: End\n")));	
+	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiEapTypes::UpdateExpandedDataL(): End\n")));	
 }
-    
-#endif // #ifdef USE_EAP_EXPANDED_TYPES
 
 // End of file