os/security/authorisation/userpromptservice/database/test/dumpupsdb/source/dumpupsdb.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Implements a tool to export/import UPS Decision Database
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
 
sl@0
    21
#include "dumpupsdb.h"
sl@0
    22
sl@0
    23
using namespace UserPromptService;
sl@0
    24
sl@0
    25
//
sl@0
    26
//CPrinter
sl@0
    27
//
sl@0
    28
sl@0
    29
CPrinter::CPrinter(CConsoleBase* aConsole):iConsole(aConsole)
sl@0
    30
/** Constructor */
sl@0
    31
	{
sl@0
    32
	
sl@0
    33
	}
sl@0
    34
	
sl@0
    35
CPrinter::~CPrinter()
sl@0
    36
/** Destructor */
sl@0
    37
	{
sl@0
    38
	iReader.Close();
sl@0
    39
	iFile.Close();
sl@0
    40
	}
sl@0
    41
	
sl@0
    42
sl@0
    43
CPrinter* CPrinter::NewLC(CConsoleBase* aConsole)
sl@0
    44
/**
sl@0
    45
	Creates a new printer object and places the pointer on the cleanup stack.
sl@0
    46
	@param	aConsole The console object to print text to.
sl@0
    47
	@return A pointer to the new printer object.
sl@0
    48
*/
sl@0
    49
	{
sl@0
    50
	CPrinter *self = new(ELeave)CPrinter(aConsole);
sl@0
    51
	CleanupStack::PushL(self);
sl@0
    52
	return self;
sl@0
    53
	}
sl@0
    54
	
sl@0
    55
CPrinter* CPrinter::NewLC(CConsoleBase* aConsole, RFile& aFile)
sl@0
    56
/**
sl@0
    57
	Creates a new printer object and places the pointer on the cleanup stack.
sl@0
    58
	@param	aConsole	The console object to print text to.
sl@0
    59
	@param	aFile		A handle to a file to write the text to. The handle is duplicated internally.					
sl@0
    60
	@return A pointer to the new printer object.
sl@0
    61
*/
sl@0
    62
	{
sl@0
    63
	CPrinter *self = CPrinter::NewLC(aConsole);
sl@0
    64
	self->ConstructL(aFile);
sl@0
    65
	return self;
sl@0
    66
	}
sl@0
    67
sl@0
    68
sl@0
    69
void CPrinter::ConstructL(RFile& aFile)
sl@0
    70
/** Second phase constructor*/
sl@0
    71
	{
sl@0
    72
	User::LeaveIfError(iFile.Duplicate(aFile));
sl@0
    73
	iLogToFile = ETrue;
sl@0
    74
	//iReader.Set(iFile);
sl@0
    75
	iReader.Attach(aFile);
sl@0
    76
	}
sl@0
    77
sl@0
    78
void CPrinter::PrintfL(TRefByValue<const TDesC16> aFormat, ...)
sl@0
    79
/**
sl@0
    80
	Formats and writes 16-bit text to the console and/or file
sl@0
    81
	@param aFormat The 16-bit non-modifiable descriptor containing the format string.
sl@0
    82
 */
sl@0
    83
	{
sl@0
    84
	VA_LIST list;
sl@0
    85
	VA_START (list, aFormat);
sl@0
    86
	
sl@0
    87
	iBuffer.Zero();
sl@0
    88
	iBuffer.AppendFormatList(aFormat, list);
sl@0
    89
	
sl@0
    90
	iConsole->Printf(iBuffer);
sl@0
    91
	
sl@0
    92
	if(iLogToFile)
sl@0
    93
		{
sl@0
    94
		HBufC8* utf8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L(iBuffer);
sl@0
    95
		CleanupStack::PushL(utf8);
sl@0
    96
		User::LeaveIfError(iFile.Write(*utf8));
sl@0
    97
		CleanupStack::PopAndDestroy(utf8);
sl@0
    98
		}
sl@0
    99
		
sl@0
   100
	VA_END(list);
sl@0
   101
	}
sl@0
   102
sl@0
   103
sl@0
   104
void CPrinter::Printf8L(TRefByValue<const TDesC8> aFormat, ...)
sl@0
   105
/**
sl@0
   106
	Formats and writes 8-bit text to the console and/or file
sl@0
   107
	@param aFormat The 8-bit non-modifiable descriptor containing the format string.
sl@0
   108
 */
sl@0
   109
	{
sl@0
   110
	VA_LIST list;
sl@0
   111
	VA_START (list, aFormat);
sl@0
   112
	
sl@0
   113
	iBuffer8.Zero();
sl@0
   114
	iBuffer8.AppendFormatList(aFormat, list);
sl@0
   115
	iBuffer.Copy(iBuffer8);
sl@0
   116
	iConsole->Printf(iBuffer);
sl@0
   117
	
sl@0
   118
	if(iLogToFile)
sl@0
   119
		{
sl@0
   120
		User::LeaveIfError(iFile.Write(iBuffer8));
sl@0
   121
		}
sl@0
   122
	
sl@0
   123
	VA_END(list);
sl@0
   124
	}
sl@0
   125
sl@0
   126
void CPrinter::PrintOnlyConsoleL(const TDesC& aFormat, ...)
sl@0
   127
/**
sl@0
   128
	Formats and writes 16-bit text to the console.
sl@0
   129
	@param aFormat The 16-bit non-modifiable descriptor containing the format string.
sl@0
   130
 */
sl@0
   131
	{
sl@0
   132
	TBool temp;
sl@0
   133
	temp = iLogToFile;
sl@0
   134
	iLogToFile = EFalse;
sl@0
   135
	
sl@0
   136
	PrintfL(aFormat);
sl@0
   137
	
sl@0
   138
	iLogToFile = temp;
sl@0
   139
	}
sl@0
   140
	
sl@0
   141
	
sl@0
   142
void CPrinter::Usage(CConsoleBase* aConsole)
sl@0
   143
/**
sl@0
   144
	Prints how to use DumpUpsDb Tool.
sl@0
   145
	@param	aConsole A pointer to the console object
sl@0
   146
 */
sl@0
   147
	{
sl@0
   148
	aConsole->Printf(_L("DUMPUPSDB Version 1, 0\n"));
sl@0
   149
	aConsole->Printf(_L("A utility for importing and exporting UPS Decision Database.\n"));
sl@0
   150
	aConsole->Printf(_L("Copyright (c) 2007 Symbian Ltd.  All rights reserved.\n\n"));
sl@0
   151
	aConsole->Printf(_L("error: wrong number of arguments\n"));
sl@0
   152
	aConsole->Printf(_L("Usage: DumpUpsDb [-h] [-i] [-e] [-b] -db dbpath [-f filepath]\n\n"));
sl@0
   153
	aConsole->Printf(_L("Options : -h  Show help page\n"));
sl@0
   154
	aConsole->Printf(_L("Options : -i  Import an exported database\n"));
sl@0
   155
	aConsole->Printf(_L("Options : -e  Export the database\n"));
sl@0
   156
	aConsole->Printf(_L("Options : -db Database file\n"));
sl@0
   157
	aConsole->Printf(_L("Options : -f  Output/Input file\n"));
sl@0
   158
	aConsole->Printf(_L("Options : -b  Import/export Client Entity as binary\n\n"));
sl@0
   159
	aConsole->Printf(_L("Press any key to continue\r\n"));
sl@0
   160
	aConsole->Getch();
sl@0
   161
	}
sl@0
   162
sl@0
   163
void CPrinter::Wait()
sl@0
   164
/**
sl@0
   165
	If no output file is specified then pause after finishing because the console 
sl@0
   166
	will vanish when it is closed.
sl@0
   167
 */
sl@0
   168
	{
sl@0
   169
	iConsole->Printf(_L("Press any key to continue\r\n"));
sl@0
   170
	iConsole->Getch();
sl@0
   171
	}
sl@0
   172
	
sl@0
   173
sl@0
   174
void CPrinter::ReadNextLineL(TDes8& aLine)
sl@0
   175
	{
sl@0
   176
	TChar achar = '\n';
sl@0
   177
	iReader.ReadL(aLine, achar);
sl@0
   178
	}
sl@0
   179
sl@0
   180
TInt CPrinter::FileSizeL()
sl@0
   181
	{
sl@0
   182
	return iReader.Source()->SizeL();
sl@0
   183
	}
sl@0
   184
//
sl@0
   185
//CDatabase
sl@0
   186
//
sl@0
   187
sl@0
   188
CDatabase::CDatabase(TBool aImport):iImport(aImport)
sl@0
   189
/** Constructor */
sl@0
   190
	{
sl@0
   191
	
sl@0
   192
	}
sl@0
   193
	
sl@0
   194
CDatabase::~CDatabase()
sl@0
   195
/** Destructor */
sl@0
   196
	{
sl@0
   197
	delete iPrinter;
sl@0
   198
	delete iUpsDb;
sl@0
   199
	}
sl@0
   200
	
sl@0
   201
sl@0
   202
CDatabase* CDatabase::NewLC(CConsoleBase* aConsole, RFs& aFs, TBool aImport, const TDesC& aDb, const TDesC& aFile)
sl@0
   203
/**
sl@0
   204
	Creates a new database object and places the pointer on the cleanup stack.
sl@0
   205
	
sl@0
   206
	@param aConsole Pointer to the console object
sl@0
   207
	@param aFs Handle to the file server
sl@0
   208
	@param aImport Whether the operation type is import
sl@0
   209
	@param aDb The fully qualified path of the decision database
sl@0
   210
	@param aFile The fully qualified path of the dump file
sl@0
   211
	@return A pointer to the newly created database object
sl@0
   212
 */
sl@0
   213
	{
sl@0
   214
	CDatabase *self = new(ELeave)CDatabase(aImport);
sl@0
   215
	CleanupStack::PushL(self);
sl@0
   216
	self->ConstructL(aConsole, aFs, aDb, aFile);
sl@0
   217
	return self;
sl@0
   218
	}
sl@0
   219
	
sl@0
   220
sl@0
   221
void CDatabase::ConstructL(CConsoleBase* aConsole, RFs& aFs, const TDesC& aDb, const TDesC& aFile)
sl@0
   222
/**
sl@0
   223
	Second phase constructor for database object
sl@0
   224
 */
sl@0
   225
	{
sl@0
   226
	if(aFile.Length() > 0)
sl@0
   227
		{
sl@0
   228
		if(iImport)
sl@0
   229
			{
sl@0
   230
			User::LeaveIfError(iFile.Open(aFs, aFile, EFileWrite|EFileShareExclusive));
sl@0
   231
			}
sl@0
   232
		else
sl@0
   233
			{
sl@0
   234
			User::LeaveIfError(iFile.Replace(aFs, aFile, EFileWrite|EFileShareExclusive));
sl@0
   235
			}
sl@0
   236
		
sl@0
   237
		iPrinter = CPrinter::NewLC(aConsole, iFile);
sl@0
   238
		}
sl@0
   239
	else
sl@0
   240
		{
sl@0
   241
		iPrinter = CPrinter::NewLC(aConsole);
sl@0
   242
		}
sl@0
   243
	
sl@0
   244
	CleanupStack::Pop(iPrinter);
sl@0
   245
	
sl@0
   246
	iUpsDb = CDecisionDbW::NewL(aDb, aFs);
sl@0
   247
	
sl@0
   248
	}
sl@0
   249
sl@0
   250
void CDatabase::DumpL()
sl@0
   251
	{
sl@0
   252
	if(!iImport)
sl@0
   253
		{//Dump database to the console and files
sl@0
   254
		//Create an empty filter to get all decisions in the table
sl@0
   255
		CDecisionFilter *filter = CDecisionFilter::NewLC();
sl@0
   256
		
sl@0
   257
		//Create a view object
sl@0
   258
		CDecisionView *dbView = iUpsDb->CreateViewL(*filter);
sl@0
   259
		CleanupStack::PushL(dbView);
sl@0
   260
		
sl@0
   261
		CActiveWaiter *waiter = new(ELeave)CActiveWaiter();
sl@0
   262
		CleanupStack::PushL(waiter);
sl@0
   263
		
sl@0
   264
		//Fill the decisions into the view object
sl@0
   265
		dbView->EvaluateView(waiter->iStatus);
sl@0
   266
		waiter->WaitActiveL(KErrNone);	
sl@0
   267
		if(iFlag & EAppendTestResults)
sl@0
   268
			{
sl@0
   269
			PrintTestHeaderL();
sl@0
   270
			}
sl@0
   271
		PrintHeaderL();
sl@0
   272
		
sl@0
   273
		CDecisionRecord *record = NULL;
sl@0
   274
		while((record = dbView->NextDecisionL()) != NULL)
sl@0
   275
			{
sl@0
   276
			CleanupStack::PushL(record);
sl@0
   277
			PrintDecisionL(*record);
sl@0
   278
			CleanupStack::PopAndDestroy(record);
sl@0
   279
			}
sl@0
   280
		
sl@0
   281
		CleanupStack::PopAndDestroy(3, filter);
sl@0
   282
		iPrinter->PrintOnlyConsoleL(_L("Exported successfully!\n"));
sl@0
   283
		if(iFlag & EAppendTestResults)
sl@0
   284
			{
sl@0
   285
			PrintTestResultsL();
sl@0
   286
			}
sl@0
   287
		}
sl@0
   288
	else
sl@0
   289
		{//Import an exported decision file to the decision database
sl@0
   290
		TInt fileSize;
sl@0
   291
		fileSize = iPrinter->FileSizeL();
sl@0
   292
		TInt readSize=0;
sl@0
   293
		TBuf8<256> buffer;
sl@0
   294
		TBool skipFirstLine = ETrue;
sl@0
   295
		CDecisionRecord *record = NULL;
sl@0
   296
		do
sl@0
   297
			{
sl@0
   298
			iPrinter->ReadNextLineL(buffer);
sl@0
   299
			readSize +=buffer.Length();
sl@0
   300
			if(skipFirstLine)
sl@0
   301
				{
sl@0
   302
				skipFirstLine = EFalse;
sl@0
   303
				}
sl@0
   304
			else
sl@0
   305
				{
sl@0
   306
				record = ParseAndCreateRecordLC(buffer);
sl@0
   307
				iUpsDb->CreateDecisionL(*record);
sl@0
   308
				CleanupStack::PopAndDestroy(record);
sl@0
   309
				}
sl@0
   310
		
sl@0
   311
			buffer.Zero();
sl@0
   312
			}while(readSize < fileSize);
sl@0
   313
			
sl@0
   314
		iPrinter->PrintOnlyConsoleL(_L("Imported successfully!\n"));
sl@0
   315
		}
sl@0
   316
	//If both of the flags are not set, wait.
sl@0
   317
	if(!(iFlag & EAppendTestResults || iFlag & EDoNotStop))
sl@0
   318
		{
sl@0
   319
		iPrinter->Wait();
sl@0
   320
		}
sl@0
   321
	}
sl@0
   322
sl@0
   323
sl@0
   324
void CDatabase::PrintDecisionL(CDecisionRecord& aRecord)
sl@0
   325
	{
sl@0
   326
	_LIT(KDelimiter,	";");
sl@0
   327
	_LIT(KWriteId,		"\"%08x\"");
sl@0
   328
	_LIT(KWriteString,	"\"%S\"");
sl@0
   329
	_LIT8(KWriteString8,"\"%S\"");
sl@0
   330
	_LIT8(KWriteHex8,	"%02x");
sl@0
   331
sl@0
   332
	
sl@0
   333
	iPrinter->PrintfL(KWriteId,aRecord.iClientSid.iId);
sl@0
   334
	iPrinter->PrintfL(KDelimiter);
sl@0
   335
	iPrinter->PrintfL(KWriteId,aRecord.iEvaluatorId.iUid);
sl@0
   336
	iPrinter->PrintfL(KDelimiter);
sl@0
   337
	iPrinter->PrintfL(KWriteId,aRecord.iServiceId.iUid);
sl@0
   338
	iPrinter->PrintfL(KDelimiter);
sl@0
   339
	iPrinter->PrintfL(KWriteId,aRecord.iServerSid.iId);
sl@0
   340
	iPrinter->PrintfL(KDelimiter);
sl@0
   341
	
sl@0
   342
	TBuf8<KUpsMaxFingerprintLength*2> hexdump;
sl@0
   343
	TUint8 *ptr = (TUint8 *)aRecord.iFingerprint.Ptr();
sl@0
   344
	TInt i;
sl@0
   345
	TInt len = aRecord.iFingerprint.Length();
sl@0
   346
sl@0
   347
	for(i=0; i<len; ++i)
sl@0
   348
		{
sl@0
   349
		hexdump.AppendFormat(KWriteHex8,ptr[i]);
sl@0
   350
		}
sl@0
   351
	iPrinter->Printf8L(KWriteString8,&hexdump);
sl@0
   352
	iPrinter->PrintfL(KDelimiter);
sl@0
   353
		
sl@0
   354
	if(iFlag & EPrintBinary)
sl@0
   355
		{
sl@0
   356
		iPrinter->Printf8L(KWriteString8,&aRecord.iClientEntity);
sl@0
   357
		iPrinter->PrintfL(KDelimiter);
sl@0
   358
		}
sl@0
   359
	else
sl@0
   360
		{
sl@0
   361
		hexdump.Zero();
sl@0
   362
		ptr = (TUint8 *)aRecord.iClientEntity.Ptr();
sl@0
   363
		len = aRecord.iClientEntity.Length();
sl@0
   364
		for(i=0; i<len; ++i)
sl@0
   365
			{
sl@0
   366
			hexdump.AppendFormat(KWriteHex8,ptr[i]);
sl@0
   367
			}
sl@0
   368
		iPrinter->Printf8L(KWriteString8,&hexdump);
sl@0
   369
		iPrinter->PrintfL(KDelimiter);
sl@0
   370
		}	
sl@0
   371
		
sl@0
   372
	iPrinter->PrintfL(KWriteString,&aRecord.iDescription);
sl@0
   373
	iPrinter->PrintfL(KDelimiter);
sl@0
   374
	
sl@0
   375
	iPrinter->PrintfL(KWriteId,aRecord.iResult);
sl@0
   376
	iPrinter->PrintfL(KDelimiter);
sl@0
   377
	iPrinter->PrintfL(KWriteId,aRecord.iEvaluatorInfo);
sl@0
   378
	iPrinter->PrintfL(KDelimiter);
sl@0
   379
	iPrinter->PrintfL(KWriteId,aRecord.iMajorPolicyVersion);
sl@0
   380
	iPrinter->PrintfL(KDelimiter);
sl@0
   381
	iPrinter->PrintfL(KWriteId,aRecord.iRecordId);
sl@0
   382
	
sl@0
   383
	iPrinter->Printf8L(_L8("\n"));
sl@0
   384
	}
sl@0
   385
sl@0
   386
sl@0
   387
void CDatabase::PrintHeaderL()
sl@0
   388
	{
sl@0
   389
	_LIT(KDelimiter,	";");
sl@0
   390
	_LIT(KWriteString,	"\"%S\"");
sl@0
   391
	
sl@0
   392
	iPrinter->PrintfL(KWriteString,&KColClientSid);
sl@0
   393
	iPrinter->PrintfL(KDelimiter);
sl@0
   394
	iPrinter->PrintfL(KWriteString,&KColEvaluatorId);
sl@0
   395
	iPrinter->PrintfL(KDelimiter);
sl@0
   396
	iPrinter->PrintfL(KWriteString,&KColServiceId);
sl@0
   397
	iPrinter->PrintfL(KDelimiter);
sl@0
   398
	iPrinter->PrintfL(KWriteString,&KColServerSid);
sl@0
   399
	iPrinter->PrintfL(KDelimiter);
sl@0
   400
	iPrinter->PrintfL(KWriteString,&KColFingerprint);
sl@0
   401
	iPrinter->PrintfL(KDelimiter);
sl@0
   402
	iPrinter->PrintfL(KWriteString,&KColClientEntity);
sl@0
   403
	iPrinter->PrintfL(KDelimiter);
sl@0
   404
	iPrinter->PrintfL(KWriteString,&KColDescription);
sl@0
   405
	iPrinter->PrintfL(KDelimiter);
sl@0
   406
	iPrinter->PrintfL(KWriteString,&KColResult);
sl@0
   407
	iPrinter->PrintfL(KDelimiter);
sl@0
   408
	iPrinter->PrintfL(KWriteString,&KColEvaluatorInfo);
sl@0
   409
	iPrinter->PrintfL(KDelimiter);
sl@0
   410
	iPrinter->PrintfL(KWriteString,&KColMajorPolicyVersion);
sl@0
   411
	iPrinter->PrintfL(KDelimiter);
sl@0
   412
	iPrinter->PrintfL(KWriteString,&KColRecordId);
sl@0
   413
	iPrinter->Printf8L(_L8("\n"));
sl@0
   414
	}
sl@0
   415
	
sl@0
   416
CDecisionRecord* CDatabase::ParseAndCreateRecordLC(TDesC8& aLine)
sl@0
   417
/**
sl@0
   418
	Parse a line and create a decision record from the parsed values
sl@0
   419
	@param aLine A line containing a decision record values quoted with double quotes and separated by semi-colon
sl@0
   420
	@return A newly created decision record
sl@0
   421
 */
sl@0
   422
	{
sl@0
   423
	CDecisionRecord* record = NULL;
sl@0
   424
	
sl@0
   425
	TLex8 parser(aLine);
sl@0
   426
	TChar achar;
sl@0
   427
	TBool start = ETrue;
sl@0
   428
	
sl@0
   429
	TUint16 flag = 0x078F;
sl@0
   430
	TUint16 pos	 = 0x0001;
sl@0
   431
	
sl@0
   432
	TInt32 value=0; 
sl@0
   433
	TUint32 hexVal = 0;
sl@0
   434
	
sl@0
   435
	TSecureId clientSid(0);
sl@0
   436
	TSecureId serverSid(0);
sl@0
   437
	TUid serviceId = TUid::Null();
sl@0
   438
	TUid evaluatorId = TUid::Null();
sl@0
   439
	TBuf8<KUpsMaxFingerprintLength*2> fingerprint;
sl@0
   440
	TBuf8<KUpsMaxClientEntityLength*2> clientEntity;
sl@0
   441
	RBuf description;
sl@0
   442
	TUint8 result=0;
sl@0
   443
	TUint32 evaluatorInfo=0;
sl@0
   444
	TUint16 policyVer=0;
sl@0
   445
	TUint32 recordId=0;
sl@0
   446
	
sl@0
   447
	while(!parser.Eos())
sl@0
   448
		{
sl@0
   449
		//Get cyrrent char
sl@0
   450
		achar = parser.Get();
sl@0
   451
		//Skip delimiter
sl@0
   452
		if(achar == ';')
sl@0
   453
			{
sl@0
   454
			start = ETrue;
sl@0
   455
			}
sl@0
   456
		//if double quote start or stop token reading	
sl@0
   457
		if('\"' == achar)
sl@0
   458
			{
sl@0
   459
			if(start)
sl@0
   460
				{
sl@0
   461
				parser.Mark();
sl@0
   462
				start = EFalse;
sl@0
   463
				}
sl@0
   464
			else
sl@0
   465
				{
sl@0
   466
				parser.UnGet();
sl@0
   467
				
sl@0
   468
				if(flag & pos)
sl@0
   469
					{
sl@0
   470
					TLex8 intToken(parser.MarkedToken());
sl@0
   471
					switch(pos)
sl@0
   472
						{
sl@0
   473
						case KLocClientSid:
sl@0
   474
							intToken.Val(hexVal,EHex);
sl@0
   475
							clientSid.iId = hexVal;
sl@0
   476
							break;
sl@0
   477
						case KLocEvaluatorId:
sl@0
   478
							intToken.Val(hexVal,EHex);
sl@0
   479
							evaluatorId.iUid = hexVal;
sl@0
   480
							break;
sl@0
   481
						case KLocServiceId:
sl@0
   482
							intToken.Val(hexVal,EHex);
sl@0
   483
							serviceId.iUid = hexVal;
sl@0
   484
							break;
sl@0
   485
						case KLocServerSid:
sl@0
   486
							intToken.Val(hexVal,EHex);
sl@0
   487
							serverSid.iId = hexVal;
sl@0
   488
							break;
sl@0
   489
						case KLocResult:
sl@0
   490
							intToken.Val(value);
sl@0
   491
							result = (TUint8)value;
sl@0
   492
							break;
sl@0
   493
						case KLocEvaluatorInfo:
sl@0
   494
							intToken.Val(value);
sl@0
   495
							evaluatorInfo = value;
sl@0
   496
							break;
sl@0
   497
						case KLocMajorPolicyVersion:
sl@0
   498
							intToken.Val(value);
sl@0
   499
							policyVer = (TUint16)value;
sl@0
   500
							break;
sl@0
   501
						case KLocRecordId:
sl@0
   502
							intToken.Val(value);
sl@0
   503
							recordId = (TUint32)value;							
sl@0
   504
							break;
sl@0
   505
						default:
sl@0
   506
							User::Leave(KErrGeneral);
sl@0
   507
						}
sl@0
   508
					}
sl@0
   509
				else
sl@0
   510
					{
sl@0
   511
					switch(pos)
sl@0
   512
						{
sl@0
   513
						case KLocDescription:
sl@0
   514
							{	
sl@0
   515
							TPtrC8 tmpDescription = parser.MarkedToken();
sl@0
   516
							description.Create(tmpDescription.Length());
sl@0
   517
							description.CleanupClosePushL();
sl@0
   518
							description.Copy(tmpDescription);
sl@0
   519
							break;
sl@0
   520
							}
sl@0
   521
	
sl@0
   522
						case KLocFingerprint:
sl@0
   523
							{
sl@0
   524
							fingerprint = parser.MarkedToken();
sl@0
   525
							HexToStrL(fingerprint);	
sl@0
   526
							break;						
sl@0
   527
							}
sl@0
   528
						case KLocClientEntity:
sl@0
   529
							{
sl@0
   530
							clientEntity = parser.MarkedToken();
sl@0
   531
							if(!(iFlag & EPrintBinary))							
sl@0
   532
								{
sl@0
   533
								HexToStrL(clientEntity);
sl@0
   534
								}
sl@0
   535
							break;							
sl@0
   536
							}
sl@0
   537
							default:
sl@0
   538
							User::Leave(KErrGeneral);
sl@0
   539
						}
sl@0
   540
					}
sl@0
   541
				
sl@0
   542
					
sl@0
   543
				start = ETrue;
sl@0
   544
				pos = pos<<1;
sl@0
   545
				
sl@0
   546
				}			
sl@0
   547
			}
sl@0
   548
		}
sl@0
   549
	record = CDecisionRecord::NewL(clientSid,evaluatorId,serviceId,serverSid,fingerprint,clientEntity,description,result,policyVer,evaluatorInfo,recordId);
sl@0
   550
	CleanupStack::PopAndDestroy(&description);
sl@0
   551
	CleanupStack::PushL(record);
sl@0
   552
	return record;
sl@0
   553
	}
sl@0
   554
sl@0
   555
	
sl@0
   556
TUint8 CDatabase::HexToIntL(TUint8* aPtr)
sl@0
   557
/**
sl@0
   558
	Convert a 2-byte hexadecimal representation value to integer (Ex: C2 -> 194).
sl@0
   559
	@param aPtr Pointer to source data
sl@0
   560
	@return An integer value against 2-byte hexadecimal value
sl@0
   561
 */
sl@0
   562
	{
sl@0
   563
	//Save and then set third byte NULL
sl@0
   564
	TUint8 temp = aPtr[2];
sl@0
   565
	aPtr[2] = '\n';
sl@0
   566
	//Create a lex string from first two bytes
sl@0
   567
	TLex8 lex(aPtr);
sl@0
   568
	//Convert two bytes hex value (ex:9F) to integer (ex:159)
sl@0
   569
	TUint8 intVal;
sl@0
   570
	User::LeaveIfError(lex.Val(intVal,EHex));
sl@0
   571
	//Put the original value back
sl@0
   572
	aPtr[2] = temp;
sl@0
   573
	//return integer value of first two hex bytes
sl@0
   574
	return intVal;
sl@0
   575
	}
sl@0
   576
sl@0
   577
	
sl@0
   578
void CDatabase::HexToStrL(TDes8& aSource)
sl@0
   579
/**
sl@0
   580
	Convert a string containing hexadecimal representation to another string containing binary representation
sl@0
   581
	@param aSource Source data containing a string
sl@0
   582
 */
sl@0
   583
	{
sl@0
   584
	TUint8 *pSource = (TUint8 *)aSource.Ptr();
sl@0
   585
	TUint8 *pDest	= (TUint8 *)aSource.Ptr();
sl@0
   586
	
sl@0
   587
	TInt len = aSource.Length();
sl@0
   588
	TInt idxSource;
sl@0
   589
	TInt idxDest;
sl@0
   590
	
sl@0
   591
	for(idxSource=0, idxDest=0; idxSource<len; ++idxDest,idxSource+=2)
sl@0
   592
		{
sl@0
   593
		pDest[idxDest] = HexToIntL(pSource+idxSource);
sl@0
   594
		}
sl@0
   595
	
sl@0
   596
	aSource.SetLength(idxDest);
sl@0
   597
	}
sl@0
   598
sl@0
   599
sl@0
   600
void CDatabase::PrintTestResultsL()
sl@0
   601
/**
sl@0
   602
	Prints dummy test results to get rid of log file parsing error in showing test results.
sl@0
   603
 */
sl@0
   604
	{
sl@0
   605
#if 1
sl@0
   606
	iPrinter->PrintfL(_L("\n\n0 tests failed out of 1\n"));
sl@0
   607
#else
sl@0
   608
	iPrinter->PrintfL(_L("\n\nTEST STEP SUMMARY:\n"));
sl@0
   609
	iPrinter->PrintfL(_L("PASS = 1\n"));
sl@0
   610
	iPrinter->PrintfL(_L("FAIL = 0\n"));
sl@0
   611
	iPrinter->PrintfL(_L("ABORT = 0\n"));
sl@0
   612
	iPrinter->PrintfL(_L("PANIC = 0\n"));
sl@0
   613
	iPrinter->PrintfL(_L("INCONCLUSIVE = 0\n"));
sl@0
   614
	iPrinter->PrintfL(_L("UNKNOWN = 0\n"));
sl@0
   615
	iPrinter->PrintfL(_L("UNEXECUTED = 0\n"));
sl@0
   616
	iPrinter->PrintfL(_L("COMMENTED COMMAND'S = 0\n"));
sl@0
   617
	iPrinter->PrintfL(_L("TEST CASE SUMMARY:\n"));
sl@0
   618
	iPrinter->PrintfL(_L("PASS = 1\n"));
sl@0
   619
	iPrinter->PrintfL(_L("FAIL = 0\n"));
sl@0
   620
	iPrinter->PrintfL(_L("INCONCLUSIVE = 0\n"));
sl@0
   621
#endif
sl@0
   622
	}
sl@0
   623
	
sl@0
   624
void CDatabase::PrintTestHeaderL()
sl@0
   625
	{
sl@0
   626
	iPrinter->PrintfL(_L("TEST SYNOPSIS:\n"));
sl@0
   627
	iPrinter->PrintfL(_L("TEF Version : 2.1.2004\n"));
sl@0
   628
	iPrinter->PrintfL(_L("START_TESTCASE COUNT : 1\n"));
sl@0
   629
	iPrinter->PrintfL(_L("RUN_TEST_STEP COUNT : 1\n"));
sl@0
   630
	iPrinter->PrintfL(_L("RUN_TEST_STEP_RESULT COUNT : 1\n\n"));
sl@0
   631
	}
sl@0
   632