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