os/security/authorisation/userpromptservice/database/test/dumpupsdb/source/dumpupsdb.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/database/test/dumpupsdb/source/dumpupsdb.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,632 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Implements a tool to export/import UPS Decision Database
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 + 
    1.24 +#include "dumpupsdb.h"
    1.25 +
    1.26 +using namespace UserPromptService;
    1.27 +
    1.28 +//
    1.29 +//CPrinter
    1.30 +//
    1.31 +
    1.32 +CPrinter::CPrinter(CConsoleBase* aConsole):iConsole(aConsole)
    1.33 +/** Constructor */
    1.34 +	{
    1.35 +	
    1.36 +	}
    1.37 +	
    1.38 +CPrinter::~CPrinter()
    1.39 +/** Destructor */
    1.40 +	{
    1.41 +	iReader.Close();
    1.42 +	iFile.Close();
    1.43 +	}
    1.44 +	
    1.45 +
    1.46 +CPrinter* CPrinter::NewLC(CConsoleBase* aConsole)
    1.47 +/**
    1.48 +	Creates a new printer object and places the pointer on the cleanup stack.
    1.49 +	@param	aConsole The console object to print text to.
    1.50 +	@return A pointer to the new printer object.
    1.51 +*/
    1.52 +	{
    1.53 +	CPrinter *self = new(ELeave)CPrinter(aConsole);
    1.54 +	CleanupStack::PushL(self);
    1.55 +	return self;
    1.56 +	}
    1.57 +	
    1.58 +CPrinter* CPrinter::NewLC(CConsoleBase* aConsole, RFile& aFile)
    1.59 +/**
    1.60 +	Creates a new printer object and places the pointer on the cleanup stack.
    1.61 +	@param	aConsole	The console object to print text to.
    1.62 +	@param	aFile		A handle to a file to write the text to. The handle is duplicated internally.					
    1.63 +	@return A pointer to the new printer object.
    1.64 +*/
    1.65 +	{
    1.66 +	CPrinter *self = CPrinter::NewLC(aConsole);
    1.67 +	self->ConstructL(aFile);
    1.68 +	return self;
    1.69 +	}
    1.70 +
    1.71 +
    1.72 +void CPrinter::ConstructL(RFile& aFile)
    1.73 +/** Second phase constructor*/
    1.74 +	{
    1.75 +	User::LeaveIfError(iFile.Duplicate(aFile));
    1.76 +	iLogToFile = ETrue;
    1.77 +	//iReader.Set(iFile);
    1.78 +	iReader.Attach(aFile);
    1.79 +	}
    1.80 +
    1.81 +void CPrinter::PrintfL(TRefByValue<const TDesC16> aFormat, ...)
    1.82 +/**
    1.83 +	Formats and writes 16-bit text to the console and/or file
    1.84 +	@param aFormat The 16-bit non-modifiable descriptor containing the format string.
    1.85 + */
    1.86 +	{
    1.87 +	VA_LIST list;
    1.88 +	VA_START (list, aFormat);
    1.89 +	
    1.90 +	iBuffer.Zero();
    1.91 +	iBuffer.AppendFormatList(aFormat, list);
    1.92 +	
    1.93 +	iConsole->Printf(iBuffer);
    1.94 +	
    1.95 +	if(iLogToFile)
    1.96 +		{
    1.97 +		HBufC8* utf8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L(iBuffer);
    1.98 +		CleanupStack::PushL(utf8);
    1.99 +		User::LeaveIfError(iFile.Write(*utf8));
   1.100 +		CleanupStack::PopAndDestroy(utf8);
   1.101 +		}
   1.102 +		
   1.103 +	VA_END(list);
   1.104 +	}
   1.105 +
   1.106 +
   1.107 +void CPrinter::Printf8L(TRefByValue<const TDesC8> aFormat, ...)
   1.108 +/**
   1.109 +	Formats and writes 8-bit text to the console and/or file
   1.110 +	@param aFormat The 8-bit non-modifiable descriptor containing the format string.
   1.111 + */
   1.112 +	{
   1.113 +	VA_LIST list;
   1.114 +	VA_START (list, aFormat);
   1.115 +	
   1.116 +	iBuffer8.Zero();
   1.117 +	iBuffer8.AppendFormatList(aFormat, list);
   1.118 +	iBuffer.Copy(iBuffer8);
   1.119 +	iConsole->Printf(iBuffer);
   1.120 +	
   1.121 +	if(iLogToFile)
   1.122 +		{
   1.123 +		User::LeaveIfError(iFile.Write(iBuffer8));
   1.124 +		}
   1.125 +	
   1.126 +	VA_END(list);
   1.127 +	}
   1.128 +
   1.129 +void CPrinter::PrintOnlyConsoleL(const TDesC& aFormat, ...)
   1.130 +/**
   1.131 +	Formats and writes 16-bit text to the console.
   1.132 +	@param aFormat The 16-bit non-modifiable descriptor containing the format string.
   1.133 + */
   1.134 +	{
   1.135 +	TBool temp;
   1.136 +	temp = iLogToFile;
   1.137 +	iLogToFile = EFalse;
   1.138 +	
   1.139 +	PrintfL(aFormat);
   1.140 +	
   1.141 +	iLogToFile = temp;
   1.142 +	}
   1.143 +	
   1.144 +	
   1.145 +void CPrinter::Usage(CConsoleBase* aConsole)
   1.146 +/**
   1.147 +	Prints how to use DumpUpsDb Tool.
   1.148 +	@param	aConsole A pointer to the console object
   1.149 + */
   1.150 +	{
   1.151 +	aConsole->Printf(_L("DUMPUPSDB Version 1, 0\n"));
   1.152 +	aConsole->Printf(_L("A utility for importing and exporting UPS Decision Database.\n"));
   1.153 +	aConsole->Printf(_L("Copyright (c) 2007 Symbian Ltd.  All rights reserved.\n\n"));
   1.154 +	aConsole->Printf(_L("error: wrong number of arguments\n"));
   1.155 +	aConsole->Printf(_L("Usage: DumpUpsDb [-h] [-i] [-e] [-b] -db dbpath [-f filepath]\n\n"));
   1.156 +	aConsole->Printf(_L("Options : -h  Show help page\n"));
   1.157 +	aConsole->Printf(_L("Options : -i  Import an exported database\n"));
   1.158 +	aConsole->Printf(_L("Options : -e  Export the database\n"));
   1.159 +	aConsole->Printf(_L("Options : -db Database file\n"));
   1.160 +	aConsole->Printf(_L("Options : -f  Output/Input file\n"));
   1.161 +	aConsole->Printf(_L("Options : -b  Import/export Client Entity as binary\n\n"));
   1.162 +	aConsole->Printf(_L("Press any key to continue\r\n"));
   1.163 +	aConsole->Getch();
   1.164 +	}
   1.165 +
   1.166 +void CPrinter::Wait()
   1.167 +/**
   1.168 +	If no output file is specified then pause after finishing because the console 
   1.169 +	will vanish when it is closed.
   1.170 + */
   1.171 +	{
   1.172 +	iConsole->Printf(_L("Press any key to continue\r\n"));
   1.173 +	iConsole->Getch();
   1.174 +	}
   1.175 +	
   1.176 +
   1.177 +void CPrinter::ReadNextLineL(TDes8& aLine)
   1.178 +	{
   1.179 +	TChar achar = '\n';
   1.180 +	iReader.ReadL(aLine, achar);
   1.181 +	}
   1.182 +
   1.183 +TInt CPrinter::FileSizeL()
   1.184 +	{
   1.185 +	return iReader.Source()->SizeL();
   1.186 +	}
   1.187 +//
   1.188 +//CDatabase
   1.189 +//
   1.190 +
   1.191 +CDatabase::CDatabase(TBool aImport):iImport(aImport)
   1.192 +/** Constructor */
   1.193 +	{
   1.194 +	
   1.195 +	}
   1.196 +	
   1.197 +CDatabase::~CDatabase()
   1.198 +/** Destructor */
   1.199 +	{
   1.200 +	delete iPrinter;
   1.201 +	delete iUpsDb;
   1.202 +	}
   1.203 +	
   1.204 +
   1.205 +CDatabase* CDatabase::NewLC(CConsoleBase* aConsole, RFs& aFs, TBool aImport, const TDesC& aDb, const TDesC& aFile)
   1.206 +/**
   1.207 +	Creates a new database object and places the pointer on the cleanup stack.
   1.208 +	
   1.209 +	@param aConsole Pointer to the console object
   1.210 +	@param aFs Handle to the file server
   1.211 +	@param aImport Whether the operation type is import
   1.212 +	@param aDb The fully qualified path of the decision database
   1.213 +	@param aFile The fully qualified path of the dump file
   1.214 +	@return A pointer to the newly created database object
   1.215 + */
   1.216 +	{
   1.217 +	CDatabase *self = new(ELeave)CDatabase(aImport);
   1.218 +	CleanupStack::PushL(self);
   1.219 +	self->ConstructL(aConsole, aFs, aDb, aFile);
   1.220 +	return self;
   1.221 +	}
   1.222 +	
   1.223 +
   1.224 +void CDatabase::ConstructL(CConsoleBase* aConsole, RFs& aFs, const TDesC& aDb, const TDesC& aFile)
   1.225 +/**
   1.226 +	Second phase constructor for database object
   1.227 + */
   1.228 +	{
   1.229 +	if(aFile.Length() > 0)
   1.230 +		{
   1.231 +		if(iImport)
   1.232 +			{
   1.233 +			User::LeaveIfError(iFile.Open(aFs, aFile, EFileWrite|EFileShareExclusive));
   1.234 +			}
   1.235 +		else
   1.236 +			{
   1.237 +			User::LeaveIfError(iFile.Replace(aFs, aFile, EFileWrite|EFileShareExclusive));
   1.238 +			}
   1.239 +		
   1.240 +		iPrinter = CPrinter::NewLC(aConsole, iFile);
   1.241 +		}
   1.242 +	else
   1.243 +		{
   1.244 +		iPrinter = CPrinter::NewLC(aConsole);
   1.245 +		}
   1.246 +	
   1.247 +	CleanupStack::Pop(iPrinter);
   1.248 +	
   1.249 +	iUpsDb = CDecisionDbW::NewL(aDb, aFs);
   1.250 +	
   1.251 +	}
   1.252 +
   1.253 +void CDatabase::DumpL()
   1.254 +	{
   1.255 +	if(!iImport)
   1.256 +		{//Dump database to the console and files
   1.257 +		//Create an empty filter to get all decisions in the table
   1.258 +		CDecisionFilter *filter = CDecisionFilter::NewLC();
   1.259 +		
   1.260 +		//Create a view object
   1.261 +		CDecisionView *dbView = iUpsDb->CreateViewL(*filter);
   1.262 +		CleanupStack::PushL(dbView);
   1.263 +		
   1.264 +		CActiveWaiter *waiter = new(ELeave)CActiveWaiter();
   1.265 +		CleanupStack::PushL(waiter);
   1.266 +		
   1.267 +		//Fill the decisions into the view object
   1.268 +		dbView->EvaluateView(waiter->iStatus);
   1.269 +		waiter->WaitActiveL(KErrNone);	
   1.270 +		if(iFlag & EAppendTestResults)
   1.271 +			{
   1.272 +			PrintTestHeaderL();
   1.273 +			}
   1.274 +		PrintHeaderL();
   1.275 +		
   1.276 +		CDecisionRecord *record = NULL;
   1.277 +		while((record = dbView->NextDecisionL()) != NULL)
   1.278 +			{
   1.279 +			CleanupStack::PushL(record);
   1.280 +			PrintDecisionL(*record);
   1.281 +			CleanupStack::PopAndDestroy(record);
   1.282 +			}
   1.283 +		
   1.284 +		CleanupStack::PopAndDestroy(3, filter);
   1.285 +		iPrinter->PrintOnlyConsoleL(_L("Exported successfully!\n"));
   1.286 +		if(iFlag & EAppendTestResults)
   1.287 +			{
   1.288 +			PrintTestResultsL();
   1.289 +			}
   1.290 +		}
   1.291 +	else
   1.292 +		{//Import an exported decision file to the decision database
   1.293 +		TInt fileSize;
   1.294 +		fileSize = iPrinter->FileSizeL();
   1.295 +		TInt readSize=0;
   1.296 +		TBuf8<256> buffer;
   1.297 +		TBool skipFirstLine = ETrue;
   1.298 +		CDecisionRecord *record = NULL;
   1.299 +		do
   1.300 +			{
   1.301 +			iPrinter->ReadNextLineL(buffer);
   1.302 +			readSize +=buffer.Length();
   1.303 +			if(skipFirstLine)
   1.304 +				{
   1.305 +				skipFirstLine = EFalse;
   1.306 +				}
   1.307 +			else
   1.308 +				{
   1.309 +				record = ParseAndCreateRecordLC(buffer);
   1.310 +				iUpsDb->CreateDecisionL(*record);
   1.311 +				CleanupStack::PopAndDestroy(record);
   1.312 +				}
   1.313 +		
   1.314 +			buffer.Zero();
   1.315 +			}while(readSize < fileSize);
   1.316 +			
   1.317 +		iPrinter->PrintOnlyConsoleL(_L("Imported successfully!\n"));
   1.318 +		}
   1.319 +	//If both of the flags are not set, wait.
   1.320 +	if(!(iFlag & EAppendTestResults || iFlag & EDoNotStop))
   1.321 +		{
   1.322 +		iPrinter->Wait();
   1.323 +		}
   1.324 +	}
   1.325 +
   1.326 +
   1.327 +void CDatabase::PrintDecisionL(CDecisionRecord& aRecord)
   1.328 +	{
   1.329 +	_LIT(KDelimiter,	";");
   1.330 +	_LIT(KWriteId,		"\"%08x\"");
   1.331 +	_LIT(KWriteString,	"\"%S\"");
   1.332 +	_LIT8(KWriteString8,"\"%S\"");
   1.333 +	_LIT8(KWriteHex8,	"%02x");
   1.334 +
   1.335 +	
   1.336 +	iPrinter->PrintfL(KWriteId,aRecord.iClientSid.iId);
   1.337 +	iPrinter->PrintfL(KDelimiter);
   1.338 +	iPrinter->PrintfL(KWriteId,aRecord.iEvaluatorId.iUid);
   1.339 +	iPrinter->PrintfL(KDelimiter);
   1.340 +	iPrinter->PrintfL(KWriteId,aRecord.iServiceId.iUid);
   1.341 +	iPrinter->PrintfL(KDelimiter);
   1.342 +	iPrinter->PrintfL(KWriteId,aRecord.iServerSid.iId);
   1.343 +	iPrinter->PrintfL(KDelimiter);
   1.344 +	
   1.345 +	TBuf8<KUpsMaxFingerprintLength*2> hexdump;
   1.346 +	TUint8 *ptr = (TUint8 *)aRecord.iFingerprint.Ptr();
   1.347 +	TInt i;
   1.348 +	TInt len = aRecord.iFingerprint.Length();
   1.349 +
   1.350 +	for(i=0; i<len; ++i)
   1.351 +		{
   1.352 +		hexdump.AppendFormat(KWriteHex8,ptr[i]);
   1.353 +		}
   1.354 +	iPrinter->Printf8L(KWriteString8,&hexdump);
   1.355 +	iPrinter->PrintfL(KDelimiter);
   1.356 +		
   1.357 +	if(iFlag & EPrintBinary)
   1.358 +		{
   1.359 +		iPrinter->Printf8L(KWriteString8,&aRecord.iClientEntity);
   1.360 +		iPrinter->PrintfL(KDelimiter);
   1.361 +		}
   1.362 +	else
   1.363 +		{
   1.364 +		hexdump.Zero();
   1.365 +		ptr = (TUint8 *)aRecord.iClientEntity.Ptr();
   1.366 +		len = aRecord.iClientEntity.Length();
   1.367 +		for(i=0; i<len; ++i)
   1.368 +			{
   1.369 +			hexdump.AppendFormat(KWriteHex8,ptr[i]);
   1.370 +			}
   1.371 +		iPrinter->Printf8L(KWriteString8,&hexdump);
   1.372 +		iPrinter->PrintfL(KDelimiter);
   1.373 +		}	
   1.374 +		
   1.375 +	iPrinter->PrintfL(KWriteString,&aRecord.iDescription);
   1.376 +	iPrinter->PrintfL(KDelimiter);
   1.377 +	
   1.378 +	iPrinter->PrintfL(KWriteId,aRecord.iResult);
   1.379 +	iPrinter->PrintfL(KDelimiter);
   1.380 +	iPrinter->PrintfL(KWriteId,aRecord.iEvaluatorInfo);
   1.381 +	iPrinter->PrintfL(KDelimiter);
   1.382 +	iPrinter->PrintfL(KWriteId,aRecord.iMajorPolicyVersion);
   1.383 +	iPrinter->PrintfL(KDelimiter);
   1.384 +	iPrinter->PrintfL(KWriteId,aRecord.iRecordId);
   1.385 +	
   1.386 +	iPrinter->Printf8L(_L8("\n"));
   1.387 +	}
   1.388 +
   1.389 +
   1.390 +void CDatabase::PrintHeaderL()
   1.391 +	{
   1.392 +	_LIT(KDelimiter,	";");
   1.393 +	_LIT(KWriteString,	"\"%S\"");
   1.394 +	
   1.395 +	iPrinter->PrintfL(KWriteString,&KColClientSid);
   1.396 +	iPrinter->PrintfL(KDelimiter);
   1.397 +	iPrinter->PrintfL(KWriteString,&KColEvaluatorId);
   1.398 +	iPrinter->PrintfL(KDelimiter);
   1.399 +	iPrinter->PrintfL(KWriteString,&KColServiceId);
   1.400 +	iPrinter->PrintfL(KDelimiter);
   1.401 +	iPrinter->PrintfL(KWriteString,&KColServerSid);
   1.402 +	iPrinter->PrintfL(KDelimiter);
   1.403 +	iPrinter->PrintfL(KWriteString,&KColFingerprint);
   1.404 +	iPrinter->PrintfL(KDelimiter);
   1.405 +	iPrinter->PrintfL(KWriteString,&KColClientEntity);
   1.406 +	iPrinter->PrintfL(KDelimiter);
   1.407 +	iPrinter->PrintfL(KWriteString,&KColDescription);
   1.408 +	iPrinter->PrintfL(KDelimiter);
   1.409 +	iPrinter->PrintfL(KWriteString,&KColResult);
   1.410 +	iPrinter->PrintfL(KDelimiter);
   1.411 +	iPrinter->PrintfL(KWriteString,&KColEvaluatorInfo);
   1.412 +	iPrinter->PrintfL(KDelimiter);
   1.413 +	iPrinter->PrintfL(KWriteString,&KColMajorPolicyVersion);
   1.414 +	iPrinter->PrintfL(KDelimiter);
   1.415 +	iPrinter->PrintfL(KWriteString,&KColRecordId);
   1.416 +	iPrinter->Printf8L(_L8("\n"));
   1.417 +	}
   1.418 +	
   1.419 +CDecisionRecord* CDatabase::ParseAndCreateRecordLC(TDesC8& aLine)
   1.420 +/**
   1.421 +	Parse a line and create a decision record from the parsed values
   1.422 +	@param aLine A line containing a decision record values quoted with double quotes and separated by semi-colon
   1.423 +	@return A newly created decision record
   1.424 + */
   1.425 +	{
   1.426 +	CDecisionRecord* record = NULL;
   1.427 +	
   1.428 +	TLex8 parser(aLine);
   1.429 +	TChar achar;
   1.430 +	TBool start = ETrue;
   1.431 +	
   1.432 +	TUint16 flag = 0x078F;
   1.433 +	TUint16 pos	 = 0x0001;
   1.434 +	
   1.435 +	TInt32 value=0; 
   1.436 +	TUint32 hexVal = 0;
   1.437 +	
   1.438 +	TSecureId clientSid(0);
   1.439 +	TSecureId serverSid(0);
   1.440 +	TUid serviceId = TUid::Null();
   1.441 +	TUid evaluatorId = TUid::Null();
   1.442 +	TBuf8<KUpsMaxFingerprintLength*2> fingerprint;
   1.443 +	TBuf8<KUpsMaxClientEntityLength*2> clientEntity;
   1.444 +	RBuf description;
   1.445 +	TUint8 result=0;
   1.446 +	TUint32 evaluatorInfo=0;
   1.447 +	TUint16 policyVer=0;
   1.448 +	TUint32 recordId=0;
   1.449 +	
   1.450 +	while(!parser.Eos())
   1.451 +		{
   1.452 +		//Get cyrrent char
   1.453 +		achar = parser.Get();
   1.454 +		//Skip delimiter
   1.455 +		if(achar == ';')
   1.456 +			{
   1.457 +			start = ETrue;
   1.458 +			}
   1.459 +		//if double quote start or stop token reading	
   1.460 +		if('\"' == achar)
   1.461 +			{
   1.462 +			if(start)
   1.463 +				{
   1.464 +				parser.Mark();
   1.465 +				start = EFalse;
   1.466 +				}
   1.467 +			else
   1.468 +				{
   1.469 +				parser.UnGet();
   1.470 +				
   1.471 +				if(flag & pos)
   1.472 +					{
   1.473 +					TLex8 intToken(parser.MarkedToken());
   1.474 +					switch(pos)
   1.475 +						{
   1.476 +						case KLocClientSid:
   1.477 +							intToken.Val(hexVal,EHex);
   1.478 +							clientSid.iId = hexVal;
   1.479 +							break;
   1.480 +						case KLocEvaluatorId:
   1.481 +							intToken.Val(hexVal,EHex);
   1.482 +							evaluatorId.iUid = hexVal;
   1.483 +							break;
   1.484 +						case KLocServiceId:
   1.485 +							intToken.Val(hexVal,EHex);
   1.486 +							serviceId.iUid = hexVal;
   1.487 +							break;
   1.488 +						case KLocServerSid:
   1.489 +							intToken.Val(hexVal,EHex);
   1.490 +							serverSid.iId = hexVal;
   1.491 +							break;
   1.492 +						case KLocResult:
   1.493 +							intToken.Val(value);
   1.494 +							result = (TUint8)value;
   1.495 +							break;
   1.496 +						case KLocEvaluatorInfo:
   1.497 +							intToken.Val(value);
   1.498 +							evaluatorInfo = value;
   1.499 +							break;
   1.500 +						case KLocMajorPolicyVersion:
   1.501 +							intToken.Val(value);
   1.502 +							policyVer = (TUint16)value;
   1.503 +							break;
   1.504 +						case KLocRecordId:
   1.505 +							intToken.Val(value);
   1.506 +							recordId = (TUint32)value;							
   1.507 +							break;
   1.508 +						default:
   1.509 +							User::Leave(KErrGeneral);
   1.510 +						}
   1.511 +					}
   1.512 +				else
   1.513 +					{
   1.514 +					switch(pos)
   1.515 +						{
   1.516 +						case KLocDescription:
   1.517 +							{	
   1.518 +							TPtrC8 tmpDescription = parser.MarkedToken();
   1.519 +							description.Create(tmpDescription.Length());
   1.520 +							description.CleanupClosePushL();
   1.521 +							description.Copy(tmpDescription);
   1.522 +							break;
   1.523 +							}
   1.524 +	
   1.525 +						case KLocFingerprint:
   1.526 +							{
   1.527 +							fingerprint = parser.MarkedToken();
   1.528 +							HexToStrL(fingerprint);	
   1.529 +							break;						
   1.530 +							}
   1.531 +						case KLocClientEntity:
   1.532 +							{
   1.533 +							clientEntity = parser.MarkedToken();
   1.534 +							if(!(iFlag & EPrintBinary))							
   1.535 +								{
   1.536 +								HexToStrL(clientEntity);
   1.537 +								}
   1.538 +							break;							
   1.539 +							}
   1.540 +							default:
   1.541 +							User::Leave(KErrGeneral);
   1.542 +						}
   1.543 +					}
   1.544 +				
   1.545 +					
   1.546 +				start = ETrue;
   1.547 +				pos = pos<<1;
   1.548 +				
   1.549 +				}			
   1.550 +			}
   1.551 +		}
   1.552 +	record = CDecisionRecord::NewL(clientSid,evaluatorId,serviceId,serverSid,fingerprint,clientEntity,description,result,policyVer,evaluatorInfo,recordId);
   1.553 +	CleanupStack::PopAndDestroy(&description);
   1.554 +	CleanupStack::PushL(record);
   1.555 +	return record;
   1.556 +	}
   1.557 +
   1.558 +	
   1.559 +TUint8 CDatabase::HexToIntL(TUint8* aPtr)
   1.560 +/**
   1.561 +	Convert a 2-byte hexadecimal representation value to integer (Ex: C2 -> 194).
   1.562 +	@param aPtr Pointer to source data
   1.563 +	@return An integer value against 2-byte hexadecimal value
   1.564 + */
   1.565 +	{
   1.566 +	//Save and then set third byte NULL
   1.567 +	TUint8 temp = aPtr[2];
   1.568 +	aPtr[2] = '\n';
   1.569 +	//Create a lex string from first two bytes
   1.570 +	TLex8 lex(aPtr);
   1.571 +	//Convert two bytes hex value (ex:9F) to integer (ex:159)
   1.572 +	TUint8 intVal;
   1.573 +	User::LeaveIfError(lex.Val(intVal,EHex));
   1.574 +	//Put the original value back
   1.575 +	aPtr[2] = temp;
   1.576 +	//return integer value of first two hex bytes
   1.577 +	return intVal;
   1.578 +	}
   1.579 +
   1.580 +	
   1.581 +void CDatabase::HexToStrL(TDes8& aSource)
   1.582 +/**
   1.583 +	Convert a string containing hexadecimal representation to another string containing binary representation
   1.584 +	@param aSource Source data containing a string
   1.585 + */
   1.586 +	{
   1.587 +	TUint8 *pSource = (TUint8 *)aSource.Ptr();
   1.588 +	TUint8 *pDest	= (TUint8 *)aSource.Ptr();
   1.589 +	
   1.590 +	TInt len = aSource.Length();
   1.591 +	TInt idxSource;
   1.592 +	TInt idxDest;
   1.593 +	
   1.594 +	for(idxSource=0, idxDest=0; idxSource<len; ++idxDest,idxSource+=2)
   1.595 +		{
   1.596 +		pDest[idxDest] = HexToIntL(pSource+idxSource);
   1.597 +		}
   1.598 +	
   1.599 +	aSource.SetLength(idxDest);
   1.600 +	}
   1.601 +
   1.602 +
   1.603 +void CDatabase::PrintTestResultsL()
   1.604 +/**
   1.605 +	Prints dummy test results to get rid of log file parsing error in showing test results.
   1.606 + */
   1.607 +	{
   1.608 +#if 1
   1.609 +	iPrinter->PrintfL(_L("\n\n0 tests failed out of 1\n"));
   1.610 +#else
   1.611 +	iPrinter->PrintfL(_L("\n\nTEST STEP SUMMARY:\n"));
   1.612 +	iPrinter->PrintfL(_L("PASS = 1\n"));
   1.613 +	iPrinter->PrintfL(_L("FAIL = 0\n"));
   1.614 +	iPrinter->PrintfL(_L("ABORT = 0\n"));
   1.615 +	iPrinter->PrintfL(_L("PANIC = 0\n"));
   1.616 +	iPrinter->PrintfL(_L("INCONCLUSIVE = 0\n"));
   1.617 +	iPrinter->PrintfL(_L("UNKNOWN = 0\n"));
   1.618 +	iPrinter->PrintfL(_L("UNEXECUTED = 0\n"));
   1.619 +	iPrinter->PrintfL(_L("COMMENTED COMMAND'S = 0\n"));
   1.620 +	iPrinter->PrintfL(_L("TEST CASE SUMMARY:\n"));
   1.621 +	iPrinter->PrintfL(_L("PASS = 1\n"));
   1.622 +	iPrinter->PrintfL(_L("FAIL = 0\n"));
   1.623 +	iPrinter->PrintfL(_L("INCONCLUSIVE = 0\n"));
   1.624 +#endif
   1.625 +	}
   1.626 +	
   1.627 +void CDatabase::PrintTestHeaderL()
   1.628 +	{
   1.629 +	iPrinter->PrintfL(_L("TEST SYNOPSIS:\n"));
   1.630 +	iPrinter->PrintfL(_L("TEF Version : 2.1.2004\n"));
   1.631 +	iPrinter->PrintfL(_L("START_TESTCASE COUNT : 1\n"));
   1.632 +	iPrinter->PrintfL(_L("RUN_TEST_STEP COUNT : 1\n"));
   1.633 +	iPrinter->PrintfL(_L("RUN_TEST_STEP_RESULT COUNT : 1\n\n"));
   1.634 +	}
   1.635 +