eapol/eapol_framework/eapol_symbian/am/type/aka/symbian/plugin/src/EapAkaUiDataConnection.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
       
     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: 15.1.3.1.2 %
       
    20 */
       
    21 
       
    22 // This is enumeration of EAPOL source code.
       
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    24 	#undef EAP_FILE_NUMBER_ENUM
       
    25 	#define EAP_FILE_NUMBER_ENUM 184 
       
    26 	#undef EAP_FILE_NUMBER_DATE 
       
    27 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    28 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    29 
       
    30 #include <e32base.h>
       
    31 #include "EapAkaDbUtils.h"
       
    32 #include "EapAkaDbParameterNames.h"
       
    33 #include "EapAkaDbDefaults.h"
       
    34 #include <EapAkaUiConnection.h>
       
    35 #include <EapAkaUiDataConnection.h>
       
    36 #include <EapAkaUiAkaData.h>
       
    37 #include "eap_am_trace_symbian.h"
       
    38 
       
    39 const TUint KMaxSqlQueryLength = 256;
       
    40 
       
    41 CEapAkaUiDataConnection::CEapAkaUiDataConnection(CEapAkaUiConnection * aUiConn)
       
    42 : iIsOpened(EFalse)
       
    43 , iUiConn(aUiConn)
       
    44 , iColSet(NULL)
       
    45 , iDataPtr(NULL)
       
    46 {
       
    47 }
       
    48 
       
    49 
       
    50 CEapAkaUiDataConnection::~CEapAkaUiDataConnection()
       
    51 {
       
    52     if (iUiConn)
       
    53     {
       
    54         Close();
       
    55         iUiConn = NULL;
       
    56     }
       
    57 }
       
    58 
       
    59 
       
    60 TInt CEapAkaUiDataConnection::Open()
       
    61 {
       
    62     if (iIsOpened)
       
    63     {
       
    64         return KErrAlreadyExists;
       
    65     }
       
    66 
       
    67     TInt err = iUiConn->GetDatabase(iDatabase);
       
    68     if (err != KErrNone)
       
    69     {
       
    70         return err;
       
    71     }
       
    72 
       
    73     iIsOpened = ETrue;
       
    74     return KErrNone;
       
    75 }
       
    76 
       
    77 
       
    78 TInt CEapAkaUiDataConnection::GetData(CEapAkaUiAkaData ** aDataPtr)
       
    79 {
       
    80     if (aDataPtr == NULL)
       
    81     {
       
    82         return KErrArgument;
       
    83     }
       
    84     if (iIsOpened == EFalse)
       
    85     {
       
    86         return KErrSessionClosed;
       
    87     }
       
    88     iDataPtr = new CEapAkaUiAkaData();
       
    89     if (!iDataPtr)
       
    90     {
       
    91         return KErrNoMemory;
       
    92     }
       
    93 
       
    94     TRAPD(err, FetchDataL());
       
    95     if (err != KErrNone)
       
    96     {
       
    97 		delete iDataPtr;
       
    98 		iDataPtr = NULL;
       
    99 		
       
   100 		delete iColSet;
       
   101 		iColSet = NULL;
       
   102 
       
   103         iView.Close();
       
   104         
       
   105         return err;
       
   106     }
       
   107 
       
   108     *aDataPtr = iDataPtr;
       
   109 
       
   110     return KErrNone;
       
   111 }
       
   112 
       
   113 
       
   114 TInt CEapAkaUiDataConnection::Update()
       
   115 {
       
   116     TRAPD(err, iView.UpdateL());
       
   117     if (err != KErrNone)
       
   118     {
       
   119         return err;
       
   120     }
       
   121 
       
   122 	// Check if length of username and realm are less than the max length possible in DB.
       
   123 	if(iDataPtr->GetManualUsername().Length() > KMaxManualUsernameLengthInDB
       
   124 		|| iDataPtr->GetManualRealm().Length() > KMaxManualRealmLengthInDB)
       
   125 	{
       
   126 		// Username or realm too long. Can not be stored in DB.
       
   127 		EAP_TRACE_DEBUG_SYMBIAN((_L("CEapAkaUiDataConnection::Update: Too long username or realm. Length: UN=%d, Realm=%d\n"),
       
   128 			iDataPtr->GetManualUsername().Length(),
       
   129 			iDataPtr->GetManualRealm().Length()));
       
   130 		
       
   131 		return KErrArgument;
       
   132 	}
       
   133     
       
   134     TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_manual_username_literal), iDataPtr->GetManualUsername()));
       
   135 	if (err != KErrNone)
       
   136 	{
       
   137 		return err;
       
   138 	}
       
   139 
       
   140     TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_manual_realm_literal), iDataPtr->GetManualRealm()));
       
   141 	if (err != KErrNone)
       
   142 	{
       
   143 		return err;
       
   144 	}
       
   145 
       
   146     if (*(iDataPtr->GetUseManualUsername()))
       
   147     {
       
   148         TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_username_literal), EAKAUseManualUsernameYes));
       
   149 		if (err != KErrNone)
       
   150 		{
       
   151 			return err;
       
   152 		}
       
   153     }
       
   154     else
       
   155     {
       
   156         TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_username_literal), EAKAUseManualUsernameNo));
       
   157 		if (err != KErrNone)
       
   158 		{
       
   159 			return err;
       
   160 		}
       
   161     }
       
   162 
       
   163     if (*(iDataPtr->GetUseManualRealm()))
       
   164     {
       
   165         TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_realm_literal), EAKAUseManualRealmYes));
       
   166 		if (err != KErrNone)
       
   167 		{
       
   168 			return err;
       
   169 		}
       
   170     }
       
   171     else
       
   172     {
       
   173         TRAP(err, iView.SetColL(iColSet->ColNo(cf_str_EAP_AKA_use_manual_realm_literal), EAKAUseManualRealmNo));
       
   174 		if (err != KErrNone)
       
   175 		{
       
   176 			return err;
       
   177 		}
       
   178     }
       
   179 
       
   180 	// Last full authentication time should be made zero when EAP configurations are modified.
       
   181 	// This makes sure that the next authentication with this EAP would be full authentication
       
   182 	// instead of reauthentication even if the session is still valid.
       
   183 	
       
   184 	TRAP(err, iView.SetColL(iColSet->ColNo(KAKALastFullAuthTime), default_FullAuthTime));
       
   185     if (err != KErrNone)
       
   186     {
       
   187         return err;
       
   188     }
       
   189 
       
   190 	EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: Resetting Full Auth Time since EAP-AKA settings are modified\n")));
       
   191 
       
   192     TRAP(err, iView.PutL());
       
   193         
       
   194     return err;
       
   195 }
       
   196 
       
   197 
       
   198 TInt CEapAkaUiDataConnection::Close()
       
   199 {
       
   200     if (iIsOpened == EFalse)
       
   201     {
       
   202         return KErrNone;
       
   203     }
       
   204 
       
   205 	delete iDataPtr;
       
   206 	iDataPtr = NULL;
       
   207 	
       
   208 	delete iColSet;
       
   209 	iColSet = NULL;
       
   210 
       
   211     iView.Close();
       
   212 
       
   213     iUiConn = NULL;
       
   214     
       
   215     return KErrNone;
       
   216 }
       
   217 
       
   218 
       
   219 void CEapAkaUiDataConnection::FetchDataL()
       
   220 {
       
   221 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
       
   222 	TPtr sqlStatement = buf->Des();
       
   223 
       
   224 	// Form the query. Query everything.
       
   225 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
       
   226 	sqlStatement.Format(KSQLQuery,
       
   227 						&KAkaTableName,
       
   228 						&KServiceType,
       
   229 						iUiConn->GetIndexType(),
       
   230 						&KServiceIndex,
       
   231 						iUiConn->GetIndex(),
       
   232 						&KTunnelingType, 
       
   233 						iUiConn->GetTunnelingType());
       
   234 	// Evaluate view
       
   235 	User::LeaveIfError(iView.Prepare(iDatabase, TDbQuery(sqlStatement)));
       
   236 	User::LeaveIfError(iView.EvaluateAll());	
       
   237 	// Get the first (and only) row
       
   238 	iView.FirstL();
       
   239 	iView.GetL();				
       
   240 	// Get column set so we get the correct column numbers
       
   241 	delete iColSet;
       
   242 	iColSet = NULL;
       
   243 	iColSet = iView.ColSetL();
       
   244 
       
   245 	// Start fetching the values
       
   246 
       
   247 	// use manual username
       
   248 	TUint intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_AKA_use_manual_username_literal));
       
   249     if (intValue == 0)
       
   250     {
       
   251         *(iDataPtr->GetUseManualUsername()) = EFalse;
       
   252     }
       
   253     else
       
   254     {
       
   255         *(iDataPtr->GetUseManualUsername()) = ETrue;
       
   256     }
       
   257 
       
   258 	// use manual realm
       
   259 	intValue = iView.ColUint(iColSet->ColNo(cf_str_EAP_AKA_use_manual_realm_literal));
       
   260     if (intValue == 0)
       
   261     {
       
   262         *(iDataPtr->GetUseManualRealm()) = EFalse;
       
   263     }
       
   264     else
       
   265     {
       
   266         *(iDataPtr->GetUseManualRealm()) = ETrue;
       
   267     }
       
   268 
       
   269     // manual username
       
   270     iDataPtr->GetManualUsername().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_AKA_manual_username_literal)));
       
   271 
       
   272 	// manual realm
       
   273 	iDataPtr->GetManualRealm().Copy(iView.ColDes16(iColSet->ColNo(cf_str_EAP_AKA_manual_realm_literal)));
       
   274 
       
   275     CleanupStack::PopAndDestroy(buf);
       
   276 }