eapol/eapol_framework/eapol_symbian/am/type/securid/symbian/plugin/src/EapSecurIDDbUtils.cpp
author Pat Downey <patd@symbian.org>
Wed, 01 Sep 2010 12:23:57 +0100
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
permissions -rw-r--r--
Revert incorrect RCL_3 drop: Revision: 201029 Kit: 201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:  EAP and WLAN authentication protocols.
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
2
1c7bc153c08e Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    18
/*
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    19
* %version: 14.1.2 %
2
1c7bc153c08e Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    20
*/
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
// This is enumeration of EAPOL source code.
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
	#undef EAP_FILE_NUMBER_ENUM
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
	#define EAP_FILE_NUMBER_ENUM 349 
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
	#undef EAP_FILE_NUMBER_DATE 
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
	#define EAP_FILE_NUMBER_DATE 1127594498 
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
// INCLUDE FILES
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
#include "EapSecurIDDbUtils.h"
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
#include "EapSecurIDDbDefaults.h"
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
#include "EapSecurIDDbParameterNames.h"
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    37
#include "eap_am_trace_symbian.h"
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
const TUint KMaxSqlQueryLength = 512;
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
// ================= MEMBER FUNCTIONS =======================
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    43
void EapSecurIDDbUtils::OpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession, const TIndexType aIndexType,
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    44
	const TInt aIndex, const eap_type_value_e aTunnelingType)
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
{
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    46
#ifdef USE_EAP_EXPANDED_TYPES
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    47
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    48
	TUint aTunnelingVendorType = aTunnelingType.get_vendor_type();
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    50
#else
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    51
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    52
	TUint aTunnelingVendorType = static_cast<TUint>(aTunnelingType);
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    53
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    54
#endif //#ifdef USE_EAP_EXPANDED_TYPES
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
	// 1. Open/create a database	
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    57
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    58
	// Connect to the DBMS server.
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    59
	User::LeaveIfError(aSession.Connect());		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    60
	CleanupClosePushL(aSession);	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    61
	// aSession and aDatabase are pushed to the cleanup stack even though they may be member
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    62
	// variables of the calling class and would be closed in the destructor anyway. This ensures
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    63
	// that if they are not member variables they will be closed. Closing the handle twice
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    64
	// does no harm.	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    65
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    66
#ifdef SYMBIAN_SECURE_DBMS
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    67
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    68
	// Create the secure shared database with the specified secure policy.
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    69
	// Database will be created in the data caging path for DBMS (C:\private\100012a5).
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    70
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    71
	TInt err = aDatabase.Create(aSession, KDatabaseName, KSecureUIDFormat);
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    73
	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSecurIDDbUtils::OpenDatabaseL - Created Secure DB for eapsecurid.dat. err=%d\n"), err));
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    75
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    76
	if(err == KErrNone)
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
	{
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
		aDatabase.Close();
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    79
		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    80
	} else if (err != KErrAlreadyExists) 
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
	{
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    82
		User::LeaveIfError(err);
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
	}
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
	
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    85
	User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName, KSecureUIDFormat));
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    86
	CleanupClosePushL(aDatabase);		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    87
		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    88
#else
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    89
	// For non-secured database. The database will be created in the old location (c:\system\data).
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    90
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    91
	RFs fsSession;		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    92
	User::LeaveIfError(fsSession.Connect());
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    93
	CleanupClosePushL(fsSession);	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    94
	TInt err = aDatabase.Create(fsSession, KDatabaseName);
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    95
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    96
	EAP_TRACE_DEBUG_SYMBIAN((_L("EapSecurIDDbUtils::OpenDatabaseL - Created Non-Secure DB for eapsecurid.dat. err=%d\n"), err));
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    97
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    98
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
    99
	if(err == KErrNone)
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   100
	{
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   101
		aDatabase.Close();
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   102
		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   103
	} else if (err != KErrAlreadyExists) 
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   104
	{
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   105
		User::LeaveIfError(err);
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   106
	}
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   107
	CleanupStack::PopAndDestroy(); // close fsSession
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   108
	
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   109
	User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName));
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   110
	CleanupClosePushL(aDatabase);		
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   111
	    
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   112
#endif // #ifdef SYMBIAN_SECURE_DBMS
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   114
	// 2. Create the eap-securid table to database (ignore error if exists)
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   115
	// Table columns:
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   116
	//// NAME ///////////////////////////////////////////////// TYPE ////////////// Constant /////////
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
	//| ServiceType											| UNSIGNED INTEGER | KServiceType      |//
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
	//| ServiceIndex										| UNSIGNED INTEGER | KServiceIndex     |//
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
	//| TunnelingType										| UNSIGNED INTEGER | KTunnelingType    |//
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   120
	//| EAP_SECURID_identity				        		| VARCHAR(255)     | cf_str_EAP_SECURID_identity_literal         |//
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
	//////////////////////////////////////////////////////////////////////////////////////////////////
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
	TPtr sqlStatement = buf->Des();
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   126
	_LIT(KSQLCreateTable1, "CREATE TABLE %S (%S UNSIGNED INTEGER, \
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   127
											 %S UNSIGNED INTEGER, \
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   128
											 %S UNSIGNED INTEGER, \
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   129
											 %S VARCHAR(255))");
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   130
	sqlStatement.Format(KSQLCreateTable1, &KSecurIDTableName, &KServiceType, &KServiceIndex, &KTunnelingType, &cf_str_EAP_SECURID_identity_literal);
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   131
	err = aDatabase.Execute(sqlStatement);
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   132
	if (err != KErrNone && err != KErrAlreadyExists)
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   133
	{
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   134
		User::Leave(err);
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   135
	}
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
	// 4. Check if database table contains a row for this service type and id  
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
	
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   139
	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d");
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   140
	sqlStatement.Format(KSQLQueryRow, &cf_str_EAP_SECURID_identity_literal, &KSecurIDTableName, 
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   141
		&KServiceType, aIndexType, &KServiceIndex, aIndex, &KTunnelingType, aTunnelingVendorType);
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
	RDbView view;
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
	User::LeaveIfError(view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
	// View must be closed when no longer needed
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
	CleanupClosePushL(view);
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
	User::LeaveIfError(view.EvaluateAll());
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
	// 5. If row is not found then add it
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
	TInt rows = view.CountL();
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   149
	CleanupStack::PopAndDestroy(); // view
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
	if (rows == 0)
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
	{
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
		_LIT(KSQLInsert, "SELECT * FROM %S");
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
		sqlStatement.Format(KSQLInsert, &KSecurIDTableName);		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   154
		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
		view.Prepare(aDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited, RDbView::EInsertOnly);
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
		CleanupClosePushL(view);
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
		// Get column set so we get the correct column numbers
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
		CDbColSet* colSet = view.ColSetL();		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
		CleanupStack::PushL(colSet);
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
		view.InsertL();
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
		view.SetColL(colSet->ColNo(KServiceType), static_cast<TInt> (aIndexType));
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
		view.SetColL(colSet->ColNo(KServiceIndex), aIndex);
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   165
		view.SetColL(colSet->ColNo(KTunnelingType), aTunnelingVendorType);
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
		view.SetColL(colSet->ColNo(cf_str_EAP_SECURID_identity_literal), default_EAP_SECURID_identity);
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
		view.PutL();
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
		CleanupStack::PopAndDestroy( colSet ); // Delete colSet.
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
		
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
		CleanupStack::PopAndDestroy( &view ); // Close view.
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
	} 
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
	
46
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   174
	CleanupStack::PopAndDestroy(); // sqlStatement
c74b3d9f6b9e Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents: 45
diff changeset
   175
	CleanupStack::Pop(2); // database, session
0
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
	aDatabase.Compact();
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   177
}
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   178
c8830336c852 Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
// End of File