eapol/eapol_framework/eapol_symbian/am/type/securid/symbian/plugin/src/EapGtcDbUtils.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 47 %
    19 * %version: 18.1.2 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
    33 #include "EapGtcDbUtils.h"
    33 #include "EapGtcDbUtils.h"
    34 #include "EapGtcDbDefaults.h"
    34 #include "EapGtcDbDefaults.h"
    35 #include "EapGtcDbParameterNames.h"
    35 #include "EapGtcDbParameterNames.h"
    36 #include "EapSecurIDDbParameterNames.h"
    36 #include "EapSecurIDDbParameterNames.h"
    37 
    37 
    38 #include <EapTraceSymbian.h>
    38 #include "eap_am_trace_symbian.h"
    39 #include "EapPluginTools.h"
       
    40 
    39 
    41 const TUint KMaxSqlQueryLength = 512;
    40 const TUint KMaxSqlQueryLength = 512;
    42 const TInt KMicroSecsInAMinute = 60000000; // 60000000 micro seconds is 1 minute.
    41 const TInt KMicroSecsInAMinute = 60000000; // 60000000 micro seconds is 1 minute.
    43 
    42 
    44 // ================= MEMBER FUNCTIONS =======================
    43 // ================= MEMBER FUNCTIONS =======================
    45 
    44 
    46 void EapGtcDbUtils::OpenDatabaseL(
    45 void EapGtcDbUtils::OpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession, const TIndexType aIndexType,
    47 	RDbNamedDatabase& aDatabase,
    46 	const TInt aIndex, const eap_type_value_e aTunnelingType)
    48 	RFs& aFileServerSession,
       
    49 	const TIndexType aIndexType,
       
    50 	const TInt aIndex,
       
    51 	const eap_type_value_e aTunnelingType)
       
    52 {
    47 {
    53 	EAP_TRACE_DEBUG_SYMBIAN(
    48 #ifdef USE_EAP_EXPANDED_TYPES
    54 		(_L("EapGtcDbUtils::OpenDatabaseL(): - Start - aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
    49 
    55 		aIndexType,
    50 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
    56 		aIndex,
    51 
    57 		aTunnelingType.get_vendor_id(),
    52 #else
    58 		aTunnelingType.get_vendor_type()));
    53 
    59 
    54 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
    60     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapGtcDbUtils::OpenDatabaseL()\n"));
    55 
       
    56 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
    57 
       
    58 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL -Start- aIndexType=%d, aIndex=%d, aTunnelingVendorType=%d \n"),
       
    59 	aIndexType,aIndex,aTunnelingVendorType) );
    61 
    60 
    62 	// 1. Open/create a database	
    61 	// 1. Open/create a database	
    63 	
    62 	
    64 	TInt error(KErrNone);
    63 	// Connect to the DBMS server.
    65 	TFileName aPrivateDatabasePathName;
    64 	User::LeaveIfError(aSession.Connect());		
    66 
    65 	CleanupClosePushL(aSession);	
    67 	EapPluginTools::CreateDatabaseLC(
    66 	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
    68 		aDatabase,
    67 	// variables of the calling class and would be closed in the destructor anyway. This ensures
    69 		aFileServerSession,
    68 	// that if they are not member variables they will be closed. Closing the handle twice
    70 		error,
    69 	// does no harm.	
    71 		KEapGtcDatabaseName,
    70 	
    72 		aPrivateDatabasePathName);
    71 #ifdef SYMBIAN_SECURE_DBMS
    73 
    72 	
    74 	if(error == KErrNone)
    73 	// Create the secure shared database with the specified secure policy.
       
    74 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
       
    75 	
       
    76 	TInt err = aDatabase.Create(aSession, KGtcDatabaseName, KGtcSecureUIDFormat);
       
    77 
       
    78 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL - Created Secure DB for eapgtc.dat. err=%d\n"), err));
       
    79 
       
    80 	
       
    81 	if(err == KErrNone)
    75 	{
    82 	{
    76 		aDatabase.Close();
    83 		aDatabase.Close();
    77 	}
    84 		
    78 	else if (error != KErrAlreadyExists) 
    85 	} else if (err != KErrAlreadyExists) 
    79 	{
    86 	{
    80 		User::LeaveIfError(error);
    87 		User::LeaveIfError(err);
    81 	}
    88 	}
    82 	
    89 	
    83 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): - calls aDatabase.Open()\n")));
    90 	User::LeaveIfError(aDatabase.Open(aSession, KGtcDatabaseName, KGtcSecureUIDFormat));
    84 
    91 	CleanupClosePushL(aDatabase);		
    85 	error = aDatabase.Open(aFileServerSession, aPrivateDatabasePathName);
    92 		
    86 
    93 #else
    87 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): - Opened private DB for EAP-GTC. error=%d\n"), error));
    94 	// For non-secured database. The database will be created in the old location (c:\system\data).
    88 
    95 	
    89 	User::LeaveIfError(error);
    96 	RFs fsSession;		
       
    97 	User::LeaveIfError(fsSession.Connect());
       
    98 	CleanupClosePushL(fsSession);	
       
    99 	TInt err = aDatabase.Create(fsSession, KGtcDatabaseName);
       
   100 	
       
   101 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL - Created Non-Secure DB for eapgtc.dat. err=%d\n"), err));
       
   102 	
       
   103 	
       
   104 	if(err == KErrNone)
       
   105 	{
       
   106 		aDatabase.Close();
       
   107 		
       
   108 	} else if (err != KErrAlreadyExists) 
       
   109 	{
       
   110 		User::LeaveIfError(err);
       
   111 	}
       
   112 	CleanupStack::PopAndDestroy(); // close fsSession
       
   113 	
       
   114 	User::LeaveIfError(aDatabase.Open(aSession, KGtcDatabaseName));
       
   115 	CleanupClosePushL(aDatabase);		
       
   116 	    
       
   117 #endif // #ifdef SYMBIAN_SECURE_DBMS
    90 
   118 
    91 	// 2. Create the eap-securid table to database (ignore error if exists)
   119 	// 2. Create the eap-securid table to database (ignore error if exists)
    92 	
   120 	
    93 	// Table columns:
   121 // Table columns:
    94 	//// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
   122 //// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
    95 	//| ServiceType								| UNSIGNED INTEGER 	| KServiceType      |//
   123 //| ServiceType								| UNSIGNED INTEGER 	| KServiceType      |//
    96 	//| ServiceIndex							| UNSIGNED INTEGER 	| KServiceIndex     |//
   124 //| ServiceIndex							| UNSIGNED INTEGER 	| KServiceIndex     |//
    97 	//| TunnelingTypeVendorId                   | UNSIGNED INTEGER  | KTunnelingTypeVendorId    |//
   125 //| TunnelingType							| UNSIGNED INTEGER 	| KTunnelingType    |//
    98 	//| TunnelingType							| UNSIGNED INTEGER 	| KTunnelingType    |//
   126 //| EAP_GTC_identity				    	| VARCHAR(255)     	| cf_str_EAP_GTC_identity_literal	|//
    99 	//| EAP_GTC_identity				    	| VARCHAR(255)     	| cf_str_EAP_GTC_identity_literal	|//
   127 //| EAP_GTC_max_session_validity_time	    | BIGINT		   	| cf_str_EAP_GTC_max_session_validity_time_literal   |//
   100 	//| EAP_GTC_max_session_validity_time	    | BIGINT		   	| cf_str_EAP_GTC_max_session_validity_time_literal   |//
   128 //| EAP_GTC_last_full_authentication_time	| BIGINT		   	| KGTCLastFullAuthTime	|//
   101 	//| EAP_GTC_last_full_authentication_time	| BIGINT		   	| KGTCLastFullAuthTime	|//
       
   102 	//| EAP_GTC_password_prompt                        | UNSIGNED INTEGER  | cf_str_EAP_GTC_passcode_prompt_literal   |//
       
   103 	//| EAP_GTC_password                               | VARCHAR(255)      | cf_str_EAP_GTC_passcode_literal         |//
       
   104 	//////////////////////////////////////////////////////////////////////////////////////////////////
   129 	//////////////////////////////////////////////////////////////////////////////////////////////////
   105 
       
   106 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls HBufC::NewLC()\n")));
       
   107 
   130 
   108 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   131 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   109 	TPtr sqlStatement = buf->Des();
   132 	TPtr sqlStatement = buf->Des();
   110 	
   133 	
   111 	_LIT(KSQLCreateTable1, "CREATE TABLE %S \
   134 	_LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
   112 		(%S UNSIGNED INTEGER, \
   135 											 %S UNSIGNED INTEGER, \
   113 		 %S UNSIGNED INTEGER, \
   136 											 %S UNSIGNED INTEGER, \
   114 		 %S UNSIGNED INTEGER, \
   137 											 %S VARCHAR(255), \
   115 		 %S UNSIGNED INTEGER, \
   138 											 %S BIGINT, \
   116 		 %S VARCHAR(255), \
   139 											 %S BIGINT)");
   117 		 %S BIGINT, \
       
   118 		 %S BIGINT, \
       
   119 		 %S UNSIGNED INTEGER, \
       
   120 		 %S VARCHAR(255))");
       
   121 											 
   140 											 
   122 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls sqlStatement.Format()\n")));
       
   123 
       
   124 	sqlStatement.Format(KSQLCreateTable1, 
   141 	sqlStatement.Format(KSQLCreateTable1, 
   125 						&KGtcTableName, 
   142 						&KGtcTableName, 
   126 						&KServiceType, 
   143 						&KServiceType, 
   127 						&KServiceIndex, 
   144 						&KServiceIndex, 
   128 						&KTunnelingTypeVendorId,
       
   129 						&KTunnelingType, 
   145 						&KTunnelingType, 
   130 						&cf_str_EAP_GTC_identity_literal,
   146 						&cf_str_EAP_GTC_identity_literal,
   131 						&cf_str_EAP_GTC_max_session_validity_time_literal, 
   147 						&cf_str_EAP_GTC_max_session_validity_time_literal, 
   132 						&KGTCLastFullAuthTime,
   148 						&KGTCLastFullAuthTime);
   133 						&cf_str_EAP_GTC_passcode_prompt_literal,
   149 
   134 						&cf_str_EAP_GTC_passcode_literal);
   150 	err = aDatabase.Execute(sqlStatement);
   135 
   151 	if (err != KErrNone && err != KErrAlreadyExists)
   136 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls aDatabase.Execute()\n")));
   152 	{
   137 
   153 		User::Leave(err);
   138 	error = aDatabase.Execute(sqlStatement);
       
   139 	if (error != KErrNone && error != KErrAlreadyExists)
       
   140 	{
       
   141 		EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: EapGtcDbUtils::OpenDatabaseL(): aDatabase.Execute() error=%d\n"),
       
   142 			error));
       
   143 
       
   144 		User::Leave(error);
       
   145 	}
   154 	}
   146 
   155 
   147 	// 4. Check if database table contains a row for this service type and id  
   156 	// 4. Check if database table contains a row for this service type and id  
   148 
   157 	
   149 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls sqlStatement.Format()\n")));
   158 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   150 
   159 	sqlStatement.Format(KSQLQueryRow, &cf_str_EAP_GTC_identity_literal, &KGtcTableName, 
   151 	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   160 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   152 
       
   153 	sqlStatement.Format(KSQLQueryRow,
       
   154 		&cf_str_EAP_GTC_identity_literal,
       
   155 		&KGtcTableName, 
       
   156 		&KServiceType,
       
   157 		aIndexType,
       
   158 		&KServiceIndex,
       
   159 		aIndex,
       
   160 		&KTunnelingTypeVendorId,
       
   161 		aTunnelingType.get_vendor_id(),
       
   162 		&KTunnelingType, 
       
   163 		aTunnelingType.get_vendor_type());
       
   164 			
   161 			
   165 	RDbView view;
   162 	RDbView view;
   166 
   163 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   167 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls view.Prepare()\n")));
       
   168 
       
   169 	error = view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited);
       
   170 
       
   171 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): view.Prepare() error=%d\n"),
       
   172 		error));
       
   173 
       
   174 	User::LeaveIfError(error);
       
   175 	// View must be closed when no longer needed
   164 	// View must be closed when no longer needed
   176 	CleanupClosePushL(view);
   165 	CleanupClosePushL(view);
   177 
   166 	User::LeaveIfError(view.EvaluateAll());
   178 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls view.EvaluateAll()\n")));
       
   179 
       
   180 	error = view.EvaluateAll();
       
   181 
       
   182 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): view.EvaluateAll() error=%d\n"),
       
   183 		error));
       
   184 
       
   185 	User::LeaveIfError(error);
       
   186 	
   167 	
   187 	// 5. If row is not found then add it
   168 	// 5. If row is not found then add it
   188 	
   169 	
   189 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls view.CountL()\n")));
       
   190 
       
   191 	TInt rows = view.CountL();
   170 	TInt rows = view.CountL();
   192 
   171 	CleanupStack::PopAndDestroy(); // view
   193 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): view.CountL() rows=%d\n"),
       
   194 		rows));
       
   195 
       
   196 	CleanupStack::PopAndDestroy(&view);
       
   197 	if (rows == 0)
   172 	if (rows == 0)
   198 	{		
   173 	{		
   199 		_LIT(KSQLInsert, "SELECT * FROM %S");
   174 		_LIT(KSQLInsert, "SELECT * FROM %S");
   200 		sqlStatement.Format(KSQLInsert, &KGtcTableName);		
   175 		sqlStatement.Format(KSQLInsert, &KGtcTableName);		
   201 
   176 		
   202 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls view.Prepare()\n")));
   177 		view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly);
   203 
       
   204 		error = view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly);
       
   205 
       
   206 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): view.Prepare() error=%d\n"),
       
   207 			error));
       
   208 
       
   209 		CleanupClosePushL(view);
   178 		CleanupClosePushL(view);
   210 		
   179 		
   211 		// Get column set so we get the correct column numbers
   180 		// Get column set so we get the correct column numbers
   212 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls view.ColSetL()\n")));
       
   213 
       
   214 		CDbColSet* colSet = view.ColSetL();		
   181 		CDbColSet* colSet = view.ColSetL();		
   215 		CleanupStack::PushL(colSet);
   182 		CleanupStack::PushL(colSet);
   216 		
   183 		
   217 		EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls view.InsertL()\n")));
       
   218 
       
   219 		view.InsertL();
   184 		view.InsertL();
   220 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt> (aIndexType));
   185 		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt> (aIndexType));
   221 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
   186 		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
   222 		view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aTunnelingType.get_vendor_id());
   187 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
   223 		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingType.get_vendor_type());
   188 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_identity_literal), default_EAP_GTC_identity);
   224 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_identity_literal), default_EAP_identity);
       
   225 		
   189 		
   226 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal), default_MaxSessionTime);
   190 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal), default_MaxSessionTime);
   227 		
   191 		
   228 		view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), default_FullAuthTime);		
   192 		view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), default_FullAuthTime);		
   229 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_passcode_prompt_literal), default_EAP_password_prompt);
       
   230 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_passcode_literal), default_EAP_password);
       
   231 				
   193 				
   232 		view.PutL();
   194 		view.PutL();
   233 
   195 
   234 		CleanupStack::PopAndDestroy( colSet );
   196 		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.
   235 		
   197 		
   236 		CleanupStack::PopAndDestroy( &view );
   198 		CleanupStack::PopAndDestroy( &view ); // Close view.
   237 		
   199 		
   238 	}
   200 	}
   239 
   201 	
   240 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::OpenDatabaseL(): calls aDatabase.Compact()\n")));
   202 	CleanupStack::PopAndDestroy( buf ); // Delete buf	
   241 
   203 	CleanupStack::Pop( &aDatabase );	
       
   204 	CleanupStack::Pop( &aSession );	
       
   205 	
   242 	aDatabase.Compact();
   206 	aDatabase.Compact();
   243 
       
   244 	CleanupStack::PopAndDestroy( buf );
       
   245 	CleanupStack::Pop( &aDatabase );	
       
   246 	CleanupStack::Pop( &aFileServerSession );
       
   247 }
   207 }
   248 
   208 
   249 // ----------------------------------------------------------
       
   250 
   209 
   251 void EapGtcDbUtils::SetIndexL(
   210 void EapGtcDbUtils::SetIndexL(
   252 	RDbNamedDatabase& aDatabase, 		
   211 	RDbNamedDatabase& aDatabase, 		
   253 	const TIndexType aIndexType,
   212 	const TIndexType aIndexType,
   254 	const TInt aIndex,
   213 	const TInt aIndex,
   255 	const eap_type_value_e aTunnelingType,
   214 	const eap_type_value_e aTunnelingType,
   256 	const TIndexType aNewIndexType,
   215 	const TIndexType aNewIndexType,
   257 	const TInt aNewIndex,
   216 	const TInt aNewIndex,
   258 	const eap_type_value_e aNewTunnelingType)
   217 	const eap_type_value_e aNewTunnelingType)
   259 {
   218 {
   260 	EAP_TRACE_DEBUG_SYMBIAN(
   219 #ifdef USE_EAP_EXPANDED_TYPES
   261 		(_L("EapGtcDbUtils::SetIndexL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   220 
   262 		aIndexType,
   221 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   263 		aIndex,
   222 	TUint aNewTunnelingVendorType = aNewTunnelingType.get_vendor_type();
   264 		aTunnelingType.get_vendor_id(),
   223 
   265 		aTunnelingType.get_vendor_type()));
   224 #else
   266 	
   225 
   267 	EAP_TRACE_DEBUG_SYMBIAN(
   226 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   268 		(_L("EapGtcDbUtils::SetIndexL(): -Start- aNewIndexType=%d, aNewIndex=%d, aNewTunnelingType=0xfe%06x%08x\n"),
   227 	TUint aNewTunnelingVendorType = static_cast<TUint>(aNewTunnelingType);
   269 		aNewIndexType,
   228 
   270 		aNewIndex,
   229 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   271 		aNewTunnelingType.get_vendor_id(),
       
   272 		aNewTunnelingType.get_vendor_type()));
       
   273 
       
   274     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapGtcDbUtils::SetIndexL()\n"));
       
   275 
   230 
   276 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   231 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   277 	TPtr sqlStatement = buf->Des();
   232 	TPtr sqlStatement = buf->Des();
   278 
   233 
   279 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   234 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   280 
   235 
   281 	sqlStatement.Format(KSQL,
   236 	sqlStatement.Format(KSQL, &KGtcTableName, 
   282 		&KGtcTableName, 
   237 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   283 		&KServiceType,
       
   284 		aIndexType,
       
   285 		&KServiceIndex,
       
   286 		aIndex,
       
   287 		&KTunnelingTypeVendorId,
       
   288 		aTunnelingType.get_vendor_id(),
       
   289 		&KTunnelingType, 
       
   290 		aTunnelingType.get_vendor_type());
       
   291 	
   238 	
   292 	RDbView view;
   239 	RDbView view;
   293 	
   240 	
   294 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   241 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   295 	
   242 	
   315 	CleanupStack::PushL(colSet);
   262 	CleanupStack::PushL(colSet);
   316 
   263 
   317 	
   264 	
   318 	view.UpdateL();
   265 	view.UpdateL();
   319 	
   266 	
   320 	view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aNewIndexType));
   267         view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aNewIndexType));
   321 	view.SetColL(colSet->ColNo(KServiceIndex), aNewIndex);
   268     
   322 	view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aNewTunnelingType.get_vendor_id());
   269     view.SetColL(colSet->ColNo(KServiceIndex), aNewIndex);
   323 	view.SetColL(colSet->ColNo(KTunnelingType), aNewTunnelingType.get_vendor_type());
   270     
       
   271     view.SetColL(colSet->ColNo(KTunnelingType), aNewTunnelingVendorType);
   324 
   272 
   325     view.PutL();
   273     view.PutL();
   326     	
   274     	
   327 	CleanupStack::PopAndDestroy(colSet);
   275 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   328 	CleanupStack::PopAndDestroy(&view);
       
   329 	CleanupStack::PopAndDestroy(buf);
       
   330 }
   276 }
   331 
       
   332 // ----------------------------------------------------------
       
   333 
   277 
   334 void EapGtcDbUtils::SetConfigurationL(
   278 void EapGtcDbUtils::SetConfigurationL(
   335 	RDbNamedDatabase& aDatabase,
   279 	RDbNamedDatabase& aDatabase,
   336 	const EAPSettings& aSettings, 
   280 	const EAPSettings& aSettings, 
   337 	const TIndexType aIndexType,
   281 	const TIndexType aIndexType,
   338 	const TInt aIndex,
   282 	const TInt aIndex,
   339 	const eap_type_value_e aTunnelingType)
   283 	const eap_type_value_e aTunnelingType)
   340 {
   284 {
   341 	EAP_TRACE_DEBUG_SYMBIAN(
   285 #ifdef USE_EAP_EXPANDED_TYPES
   342 		(_L("EapGtcDbUtils::SetConfigurationL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   286 
   343 		aIndexType,
   287 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   344 		aIndex,
   288 
   345 		aTunnelingType.get_vendor_id(),
   289 #else
   346 		aTunnelingType.get_vendor_type()));
   290 
   347 
   291 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   348     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapGtcDbUtils::SetConfigurationL()\n"));
   292 
   349 
   293 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   350 	EAP_TRACE_SETTINGS(&aSettings);
       
   351 
   294 
   352 	// Check if the settings are for the correct type
   295 	// Check if the settings are for the correct type
   353 	if (aSettings.iEAPExpandedType != (*EapExpandedTypeGtc.GetType()))
   296 	if (aSettings.iEAPType != EAPSettings::EEapGtc)
   354 	{
   297 	{
   355 		User::Leave(KErrNotSupported);
   298 		User::Leave(KErrNotSupported);
   356 	}
   299 	}
   357 	
   300 	
   358 	
   301 	
   359 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   302 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   360 	TPtr sqlStatement = buf->Des();	
   303 	TPtr sqlStatement = buf->Des();	
   361 
   304 
   362 	RDbView view;
   305 	RDbView view;
   363 
   306 
   364 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   307 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   365 
   308 	sqlStatement.Format(KSQLQuery, &KGtcTableName, 
   366 	sqlStatement.Format(KSQLQuery,
   309 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   367 		&KGtcTableName, 
       
   368 		&KServiceType,
       
   369 		aIndexType,
       
   370 		&KServiceIndex,
       
   371 		aIndex,
       
   372 		&KTunnelingTypeVendorId,
       
   373 		aTunnelingType.get_vendor_id(),
       
   374 		&KTunnelingType, 
       
   375 		aTunnelingType.get_vendor_type());
       
   376 	
   310 	
   377 	// Evaluate view
   311 	// Evaluate view
   378 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   312 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   379 	
   313 	
   380 	CleanupClosePushL(view);
   314 	CleanupClosePushL(view);
   395 		// Validate length.
   329 		// Validate length.
   396 		if(aSettings.iUsername.Length() > KMaxIdentityLengthInDB)
   330 		if(aSettings.iUsername.Length() > KMaxIdentityLengthInDB)
   397 		{
   331 		{
   398 			// Username too long. Can not be stored in DB.
   332 			// Username too long. Can not be stored in DB.
   399 			
   333 			
   400 			EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: EapGtcDbUtils::SetConfigurationL(): Too long Username. Length=%d \n"),
   334 			EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::SetConfigurationL: Too long Username. Length=%d \n"),
   401 			aSettings.iUsername.Length()));
   335 			aSettings.iUsername.Length()));
   402 			
   336 			
   403 			User::Leave(KErrArgument);
   337 			User::Leave(KErrArgument);
   404 		}
   338 		}
   405 		
   339 		
   415 		
   349 		
   416 		TInt64 validityInMicro = (aSettings.iSessionValidityTime) *  KMicroSecsInAMinute;
   350 		TInt64 validityInMicro = (aSettings.iSessionValidityTime) *  KMicroSecsInAMinute;
   417 		
   351 		
   418 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal), validityInMicro);
   352 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal), validityInMicro);
   419 	}
   353 	}
   420 
   354 	
   421 	// Last full authentication time should be made zero when EAP configurations are modified.
   355 	// Last full authentication time should be made zero when EAP configurations are modified.
   422 	// This makes sure that the next authentication with this EAP would be full authentication
   356 	// This makes sure that the next authentication with this EAP would be full authentication
   423 	// instead of reauthentication even if the session is still valid.
   357 	// instead of reauthentication even if the session is still valid.
   424 
   358 	
   425 	view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), default_FullAuthTime);
   359 	view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), default_FullAuthTime);
   426 
   360 
   427 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::SetConfigurationL(): Session Validity: Resetting Full Auth Time since settings are modified\n")));
   361 	EAP_TRACE_DEBUG_SYMBIAN((_L("Session Validity: EAP-Type=%d, Resetting Full Auth Time since settings are modified\n"),
   428 
   362 								aSettings.iEAPType ));
   429 	// Password existence.
       
   430 	if (aSettings.iPasswordExistPresent
       
   431 		&& !aSettings.iPasswordExist)
       
   432 	{
       
   433 		// Clear password from database.
       
   434 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_passcode_literal), KNullPasswordData);
       
   435 		view.SetColNullL(colSet->ColNo(cf_str_EAP_GTC_passcode_literal));
       
   436 	}
       
   437 
       
   438 	// Password
       
   439 	if (aSettings.iPasswordPresent)
       
   440 	{
       
   441 		// Validate length.
       
   442 		if(aSettings.iPassword.Length() > KMaxPasswordLengthInDB)
       
   443 		{
       
   444 			// Password too long. Can not be stored in DB.
       
   445 			
   363 			
   446 			EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: EapGtcDbUtils::SetConfigurationL(): Too long Password. Length=%d \n"),
       
   447 				aSettings.iPassword.Length()));
       
   448 			
       
   449 			User::Leave(KErrArgument);
       
   450 		}
       
   451 					
       
   452 		// Length is ok. Set the value in DB.	
       
   453 		view.SetColL(colSet->ColNo(cf_str_EAP_GTC_passcode_literal), aSettings.iPassword);
       
   454 		
       
   455 	}
       
   456 			
       
   457 	if (aSettings.iShowPassWordPromptPresent)
       
   458 		{	
       
   459 		// If password was supplied set password prompting off
       
   460 		if (aSettings.iShowPassWordPrompt != EFalse)
       
   461 			view.SetColL(colSet->ColNo(cf_str_EAP_GTC_passcode_prompt_literal), EEapDbTrue);		
       
   462 		else
       
   463 			view.SetColL(colSet->ColNo(cf_str_EAP_GTC_passcode_prompt_literal), EEapDbFalse);		
       
   464 		}
       
   465 		
       
   466 	view.PutL();
   364 	view.PutL();
   467 
   365 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   468 	CleanupStack::PopAndDestroy(colSet);
   366 
   469 	CleanupStack::PopAndDestroy(&view);
       
   470 	CleanupStack::PopAndDestroy(buf);
       
   471 }
   367 }
   472 
       
   473 // ----------------------------------------------------------
       
   474 
   368 
   475 void EapGtcDbUtils::GetConfigurationL(
   369 void EapGtcDbUtils::GetConfigurationL(
   476 	RDbNamedDatabase& aDatabase,
   370 	RDbNamedDatabase& aDatabase,
   477 	EAPSettings& aSettings, 
   371 	EAPSettings& aSettings, 
   478 	const TIndexType aIndexType,
   372 	const TIndexType aIndexType,
   479 	const TInt aIndex,
   373 	const TInt aIndex,
   480 	const eap_type_value_e aTunnelingType)
   374 	const eap_type_value_e aTunnelingType)
   481 {
   375 {
   482 	EAP_TRACE_DEBUG_SYMBIAN(
   376 #ifdef USE_EAP_EXPANDED_TYPES
   483 		(_L("EapGtcDbUtils::GetConfigurationL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   377 
   484 		aIndexType,
   378 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   485 		aIndex,
   379 
   486 		aTunnelingType.get_vendor_id(),
   380 #else
   487 		aTunnelingType.get_vendor_type()));
   381 
   488 
   382 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   489     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapGtcDbUtils::GetConfigurationL()\n"));
   383 
       
   384 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   490 
   385 
   491 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   386 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   492 	TPtr sqlStatement = buf->Des();	
   387 	TPtr sqlStatement = buf->Des();	
   493 
   388 
   494 	RDbView view;
   389 	RDbView view;
   495 
   390 
   496 	// Form the query
   391 	// Form the query
   497 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   392 	_LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   498 
   393 	sqlStatement.Format(KSQLQuery, &KGtcTableName, 
   499 	sqlStatement.Format(KSQLQuery,
   394 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   500 		&KGtcTableName, 
       
   501 		&KServiceType,
       
   502 		aIndexType,
       
   503 		&KServiceIndex,
       
   504 		aIndex,
       
   505 		&KTunnelingTypeVendorId,
       
   506 		aTunnelingType.get_vendor_id(),
       
   507 		&KTunnelingType, 
       
   508 		aTunnelingType.get_vendor_type());
       
   509 	
   395 	
   510 	// Evaluate view
   396 	// Evaluate view
   511 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   397 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement)));
   512 	
   398 	
   513 	CleanupClosePushL(view);
   399 	CleanupClosePushL(view);
   520 	
   406 	
   521 	// Get column set so we get the correct column numbers
   407 	// Get column set so we get the correct column numbers
   522 	CDbColSet* colSet = view.ColSetL();
   408 	CDbColSet* colSet = view.ColSetL();
   523 	CleanupStack::PushL(colSet);
   409 	CleanupStack::PushL(colSet);
   524 
   410 
   525 	aSettings.iEAPExpandedType = *EapExpandedTypeGtc.GetType();
   411 	aSettings.iEAPType = EAPSettings::EEapGtc;
   526 	
   412 	
   527 	// Username
   413 	// Username
   528 	TPtrC username = view.ColDes(colSet->ColNo(cf_str_EAP_GTC_identity_literal));
   414 	TPtrC username = view.ColDes(colSet->ColNo(cf_str_EAP_GTC_identity_literal));
   529 	aSettings.iUsername.Copy(username);
   415 	aSettings.iUsername.Copy(username);
   530 	aSettings.iUsernamePresent = ETrue;
   416 	aSettings.iUsernamePresent = ETrue;
   531 	
   417 	
   532 	// Password existence.
       
   533 	aSettings.iPasswordExistPresent = ETrue;
       
   534 	aSettings.iPasswordExist = ! view.IsColNull(colSet->ColNo(cf_str_EAP_GTC_passcode_literal));
       
   535 
       
   536 #if defined(USE_EAP_PASSWORD_READ_FROM_DATABASE)
       
   537 	// Password
       
   538 	TPtrC password = view.ColDes(colSet->ColNo(cf_str_EAP_GTC_passcode_literal));
       
   539 	aSettings.iPassword.Copy(password);
       
   540 	aSettings.iPasswordPresent = ETrue;
       
   541 #else
       
   542 	EAP_TRACE_DEBUG_SYMBIAN((_L("WARNING: EapGtcDbUtils::GetConfigurationL(): Password read is disabled\n")));
       
   543 #endif //#if defined(USE_EAP_PASSWORD_READ_FROM_DATABASE)
       
   544 
       
   545 	aSettings.iShowPassWordPromptPresent = ETrue;
       
   546 
       
   547 	TUint aShow = view.ColUint(colSet->ColNo(cf_str_EAP_GTC_passcode_prompt_literal));
       
   548 	if(aShow == EEapDbFalse)
       
   549 	{
       
   550 		aSettings.iShowPassWordPrompt = EFalse;
       
   551 	}
       
   552 	else
       
   553 	{
       
   554 		aSettings.iShowPassWordPrompt = ETrue;
       
   555 	}
       
   556 
       
   557 	// Session validity time	
   418 	// Session validity time	
   558 	TInt64 maxSessionTimeMicro = view.ColInt64(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal));
   419 	TInt64 maxSessionTimeMicro = view.ColInt64(colSet->ColNo(cf_str_EAP_GTC_max_session_validity_time_literal));
   559 	
   420 	
   560 	// Convert the time to minutes.	
   421 	// Convert the time to minutes.	
   561 	TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute;
   422 	TInt64 maxSessionTimeMin = maxSessionTimeMicro / KMicroSecsInAMinute;
   562 	
   423 	
   563 	aSettings.iSessionValidityTime = static_cast<TUint>(maxSessionTimeMin);
   424 	aSettings.iSessionValidityTime = static_cast<TUint>(maxSessionTimeMin);
   564 	aSettings.iSessionValidityTimePresent = ETrue;
   425 	aSettings.iSessionValidityTimePresent = ETrue;
   565 	
   426 	
   566 	CleanupStack::PopAndDestroy(colSet);
   427 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   567 	CleanupStack::PopAndDestroy(&view);
       
   568 	CleanupStack::PopAndDestroy(buf);
       
   569 
       
   570 	EAP_TRACE_SETTINGS(&aSettings);
       
   571 }
   428 }
   572 
       
   573 // ----------------------------------------------------------
       
   574 
   429 
   575 void EapGtcDbUtils::CopySettingsL(
   430 void EapGtcDbUtils::CopySettingsL(
   576 	RDbNamedDatabase& aDatabase, 		
   431 	RDbNamedDatabase& aDatabase, 		
   577 	const TIndexType aSrcIndexType,
   432 	const TIndexType aSrcIndexType,
   578 	const TInt aSrcIndex,
   433 	const TInt aSrcIndex,
   579 	const eap_type_value_e aSrcTunnelingType,
   434 	const eap_type_value_e aSrcTunnelingType,
   580 	const TIndexType aDestIndexType,
   435 	const TIndexType aDestIndexType,
   581 	const TInt aDestIndex,
   436 	const TInt aDestIndex,
   582 	const eap_type_value_e aDestTunnelingType)
   437 	const eap_type_value_e aDestTunnelingType)
   583 {
   438 {
   584 	EAP_TRACE_DEBUG_SYMBIAN(
   439 #ifdef USE_EAP_EXPANDED_TYPES
   585 		(_L("EapGtcDbUtils::CopySettingsL(): -Start- aSrcIndexType=%d, aSrcIndex=%d, aSrcTunnelingType=0xfe%06x%08x\n"),
   440 
   586 		aSrcIndexType,
   441 	TUint aSrcTunnelingVendorType = aSrcTunnelingType.get_vendor_type();
   587 		aSrcIndex,
   442 	TUint aDestTunnelingVendorType = aDestTunnelingType.get_vendor_type();
   588 		aSrcTunnelingType.get_vendor_id(),
   443 
   589 		aSrcTunnelingType.get_vendor_type()));
   444 #else
   590 	
   445 
   591 	EAP_TRACE_DEBUG_SYMBIAN(
   446 	TUint aSrcTunnelingVendorType = static_cast<TUint>(aSrcTunnelingType);
   592 		(_L("EapGtcDbUtils::CopySettingsL(): -Start- aDestIndexType=%d, aDestTunnelingType=0xfe%06x%08x\n"),
   447 	TUint aDestTunnelingVendorType = static_cast<TUint>(aDestTunnelingType);
   593 		aDestIndexType,
   448 
   594 		aDestIndex,
   449 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   595 		aDestTunnelingType.get_vendor_id(),
       
   596 		aDestTunnelingType.get_vendor_type()));
       
   597 
       
   598     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapGtcDbUtils::CopySettingsL()\n"));
       
   599 
   450 
   600 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   451 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   601 	TPtr sqlStatement = buf->Des();
   452 	TPtr sqlStatement = buf->Des();
   602 
   453 
   603 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   454 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   604 
   455 
   605 	sqlStatement.Format(KSQL,
   456 	sqlStatement.Format(KSQL, &KGtcTableName, 
   606 		&KGtcTableName, 
   457 		&KServiceType, aSrcIndexType, &KServiceIndex, aSrcIndex, &KTunnelingType, aSrcTunnelingVendorType);
   607 		&KServiceType,
       
   608 		aSrcIndexType,
       
   609 		&KServiceIndex,
       
   610 		aSrcIndex,
       
   611 		&KTunnelingTypeVendorId,
       
   612 		aSrcTunnelingType.get_vendor_id(),
       
   613 		&KTunnelingType, 
       
   614 		aSrcTunnelingType.get_vendor_type());
       
   615 	
   458 	
   616 	RDbView view;
   459 	RDbView view;
   617 	
   460 	
   618 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   461 	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   619 	
   462 	
   640 	CDbColSet* colSet = view.ColSetL();
   483 	CDbColSet* colSet = view.ColSetL();
   641 	
   484 	
   642 	CleanupStack::PushL(colSet);
   485 	CleanupStack::PushL(colSet);
   643 		
   486 		
   644 	view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aDestIndexType));
   487 	view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(aDestIndexType));
       
   488     
   645     view.SetColL(colSet->ColNo(KServiceIndex), aDestIndex);
   489     view.SetColL(colSet->ColNo(KServiceIndex), aDestIndex);
   646 	view.SetColL(colSet->ColNo(KTunnelingTypeVendorId), aDestTunnelingType.get_vendor_id());
   490     
   647 	view.SetColL(colSet->ColNo(KTunnelingType), aDestTunnelingType.get_vendor_type());
   491     view.SetColL(colSet->ColNo(KTunnelingType), aDestTunnelingVendorType);
   648 
   492 
   649     view.PutL();
   493     view.PutL();
   650     	
   494     	
   651 	CleanupStack::PopAndDestroy(colSet);
   495 	CleanupStack::PopAndDestroy(3); // view, colset, buf
   652 	CleanupStack::PopAndDestroy(&view);
       
   653 	CleanupStack::PopAndDestroy(buf);
       
   654 }
   496 }
   655 
       
   656 // ----------------------------------------------------------
       
   657 
   497 
   658 void EapGtcDbUtils::DeleteConfigurationL(	
   498 void EapGtcDbUtils::DeleteConfigurationL(	
   659 	const TIndexType aIndexType,
   499 	const TIndexType aIndexType,
   660 	const TInt aIndex,
   500 	const TInt aIndex,
   661 	const eap_type_value_e aTunnelingType)
   501 	const eap_type_value_e aTunnelingType)
   662 {
   502 {
   663 	EAP_TRACE_DEBUG_SYMBIAN(
   503 #ifdef USE_EAP_EXPANDED_TYPES
   664 		(_L("EapGtcDbUtils::DeleteConfigurationL(): -Start- aIndexType=%d, aIndex=%d, aTunnelingType=0xfe%06x%08x\n"),
   504 
   665 		aIndexType,
   505 	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
   666 		aIndex,
   506 
   667 		aTunnelingType.get_vendor_id(),
   507 #else
   668 		aTunnelingType.get_vendor_type()));
   508 
   669 
   509 	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
   670     EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: EapGtcDbUtils::DeleteConfigurationL()\n"));
   510 
   671 
   511 #endif //#ifdef USE_EAP_EXPANDED_TYPES
   672 	RDbNamedDatabase aDatabase;
   512 
   673 	RFs aFileServerSession;
   513 	RDbs session;
   674 
   514 	RDbNamedDatabase database;
   675 	TInt error(KErrNone);
   515 	// Connect to the DBMS server.
   676 	TFileName aPrivateDatabasePathName;
   516 	User::LeaveIfError(session.Connect());
   677 	
   517 	CleanupClosePushL(session);	
   678 	error = aFileServerSession.Connect();
   518 		
   679 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::DeleteConfigurationL(): - aFileServerSession.Connect(), error=%d\n"), error));
   519 #ifdef SYMBIAN_SECURE_DBMS
   680 	User::LeaveIfError(error);
   520 	
   681 
   521 	// Create the secure shared database with the specified secure policy.
   682 	EapPluginTools::CreateDatabaseLC(
   522 	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
   683 		aDatabase,
   523 	
   684 		aFileServerSession,
   524 	TInt err = database.Create(session, KGtcDatabaseName, KGtcSecureUIDFormat);
   685 		error,
   525 	
   686 		KEapGtcDatabaseName,
   526 	if(err == KErrNone)
   687 		aPrivateDatabasePathName);
       
   688 
       
   689 	if(error == KErrNone)
       
   690 	{
   527 	{
   691 		// Database was created so it was empty. No need for further actions.
   528 		// Database was created so it was empty. No need for further actions.
   692 		aDatabase.Destroy();
   529 		database.Destroy();
   693 		CleanupStack::PopAndDestroy(&aDatabase);
   530 		CleanupStack::PopAndDestroy();
   694 		CleanupStack::PopAndDestroy(&aFileServerSession);
       
   695 		return;
   531 		return;
   696 	}
   532 		
   697 	else if (error != KErrAlreadyExists) 
   533 	} 
   698 	{
   534 	else if (err != KErrAlreadyExists) 
   699 		User::LeaveIfError(error);
   535 	{
   700 	}
   536 		User::LeaveIfError(err);
   701 	
   537 	}
   702 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::DeleteConfigurationL(): - calls aDatabase.Open()\n")));
   538 	
   703 
   539 	// Database existed, open it.
   704 	error = aDatabase.Open(aFileServerSession, aPrivateDatabasePathName);
   540 	User::LeaveIfError(database.Open(session, KGtcDatabaseName, KGtcSecureUIDFormat));
   705 
   541 	CleanupClosePushL(database);
   706 	EAP_TRACE_DEBUG_SYMBIAN((_L("EapGtcDbUtils::DeleteConfigurationL(): - Opened private DB for EAP-GTC. error=%d\n"), error));
   542 		
   707 
   543 #else
   708 	User::LeaveIfError(error);
   544 	// For non-secured database. The database will be created in the old location (c:\system\data).
       
   545 	
       
   546 	RFs fsSession;		
       
   547 	User::LeaveIfError(fsSession.Connect());
       
   548 	CleanupClosePushL(fsSession);	
       
   549 	TInt err = database.Create(fsSession, KGtcDatabaseName);
       
   550 
       
   551 	if(err == KErrNone)
       
   552 	{
       
   553 		// Database was created so it was empty. No need for further actions.
       
   554 		database.Destroy();
       
   555 		CleanupStack::PopAndDestroy(2); // fsSession, database session
       
   556 		return;
       
   557 		
       
   558 	} 
       
   559 	else if (err != KErrAlreadyExists) 
       
   560 	{
       
   561 		User::LeaveIfError(err);
       
   562 	}
       
   563 	
       
   564 	CleanupStack::PopAndDestroy(); // close fsSession
       
   565 	
       
   566 	User::LeaveIfError(database.Open(session, KGtcDatabaseName));
       
   567 	CleanupClosePushL(database);		
       
   568 	    
       
   569 #endif // #ifdef SYMBIAN_SECURE_DBMS
   709 
   570 
   710 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   571 	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
   711 	TPtr sqlStatement = buf->Des();
   572 	TPtr sqlStatement = buf->Des();
   712 
   573 
   713 	// Main settings table
   574 	// Main settings table
   714 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
   575 	_LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
   715 
   576 	sqlStatement.Format(KSQL, &KGtcTableName, 
   716 	sqlStatement.Format(KSQL,
   577 		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
   717 		&KGtcTableName, 
       
   718 		&KServiceType,
       
   719 		aIndexType,
       
   720 		&KServiceIndex,
       
   721 		aIndex,
       
   722 		&KTunnelingTypeVendorId,
       
   723 		aTunnelingType.get_vendor_id(),
       
   724 		&KTunnelingType, 
       
   725 		aTunnelingType.get_vendor_type());
       
   726 
       
   727 	// Evaluate view
   578 	// Evaluate view
   728 	RDbView view;
   579 	RDbView view;
   729 	User::LeaveIfError(view.Prepare(aDatabase,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   580 	User::LeaveIfError(view.Prepare(database,TDbQuery(sqlStatement), TDbWindow::EUnlimited));
   730 	CleanupClosePushL(view);
   581 	CleanupClosePushL(view);
   731 	User::LeaveIfError(view.EvaluateAll());
   582 	User::LeaveIfError(view.EvaluateAll());
   732 
   583 
   733 	// Delete rows
   584 	// Delete rows
   734 	if (view.FirstL())
   585 	if (view.FirstL())
   736 		do {
   587 		do {
   737 			view.DeleteL();
   588 			view.DeleteL();
   738 		} while (view.NextL() != EFalse);
   589 		} while (view.NextL() != EFalse);
   739 	}
   590 	}
   740 
   591 
   741 	CleanupStack::PopAndDestroy(&view);
   592 	// Close database
   742 	CleanupStack::PopAndDestroy(buf);
   593 	CleanupStack::PopAndDestroy(4); // view, buf, database, session
   743 	CleanupStack::PopAndDestroy(&aDatabase);
       
   744 	CleanupStack::PopAndDestroy(&aFileServerSession);
       
   745 }
   594 }
   746 
   595 
   747 // ----------------------------------------------------------
       
   748 
       
   749 // End of File
   596 // End of File