os/security/authorisation/userpromptservice/database/test/dumpupsdb/source/dumpupsdb.h
Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Defines a tool to export/import UPS Decision Database
29 #include "activewaiter.h"
37 using namespace UserPromptService;
40 _LIT(KAppName, "UPS Decision Database Dump Tool");
43 static const TUint16 KLocClientSid = 0x0001;
44 static const TUint16 KLocEvaluatorId = 0x0002;
45 static const TUint16 KLocServiceId = 0x0004;
46 static const TUint16 KLocServerSid = 0x0008;
47 static const TUint16 KLocFingerprint = 0x0010;
48 static const TUint16 KLocClientEntity = 0x0020;
49 static const TUint16 KLocDescription = 0x0040;
50 static const TUint16 KLocResult = 0x0080;
51 static const TUint16 KLocEvaluatorInfo = 0x0100;
52 static const TUint16 KLocMajorPolicyVersion = 0x0200;
53 static const TUint16 KLocRecordId = 0x0400;
59 class CPrinter : public CBase
61 Class that prints text to the console and optionally writes to a log file.
65 static CPrinter* NewLC(CConsoleBase* aConsole);
66 static CPrinter* NewLC(CConsoleBase* aConsole, RFile& aFile);
67 static void Usage(CConsoleBase* aConsole);
71 void PrintfL(TRefByValue<const TDesC16> aFormat, ...);
72 void Printf8L(TRefByValue<const TDesC8> aFormat, ...);
73 void PrintOnlyConsoleL(const TDesC16& aFormat, ...);
75 void ReadNextLineL(TDes8& aLine);
79 CPrinter(CConsoleBase* aConsole);
80 void ConstructL(RFile& aFile);
83 /** Console object to print text to the console*/
84 CConsoleBase* iConsole;
86 /** Optional file handle to write text to the file*/
89 /** Whether to log to the output to the file */
92 /** Temporary 16-bit buffer*/
95 /** Temporary 8-bit buffer*/
98 /** File stream handle*/
99 RFileReadStream iReader;
106 class CDatabase : public CBase
108 This class connects to the database and import/exports it to the console/file
112 static CDatabase* NewLC(CConsoleBase* aConsole, RFs& aFs, TBool aImport, const TDesC& aDb, const TDesC& aFile);
119 CDatabase(TBool aImport);
120 void ConstructL(CConsoleBase* aConsole, RFs& aFs, const TDesC& aDb, const TDesC& aFile);
122 void PrintDecisionL(CDecisionRecord& aRecord);
124 CDecisionRecord* ParseAndCreateRecordLC(TDesC8& aLine);
125 TUint8 HexToIntL(TUint8* aPtr);
126 void HexToStrL(TDes8& aSource);
127 void PrintTestResultsL();
128 void PrintTestHeaderL();
131 /** Indicates the operation type: Import Db is ETrue and Export Db is EFalse*/
134 /** Handle to the decision database*/
135 CDecisionDbW* iUpsDb;
137 /** Handle to the printer object*/
140 /** Optional file handle to write text to the file*/
144 /** Enumerated values to arrange run options. */
147 /** Indicates whether the dummy test result lines are written into the output file. */
148 EAppendTestResults = 0x01,
149 /** Indicates whether the command line waits for the user input at the end of the operation.*/
151 /** Indicates that fingerprint and client entity fields are printed as binary instead hexadecimal. */
155 TUint8 iFlag; ///< A flag for running options.
159 static void MainL(void)
161 Takes a User Prompt Service decision database file and dumps it as human readable text to the
162 console. The user may also specify the name of an output file on the command line. If so, text
163 is also written to this file. Also recreates a UPS decision database from a dumped file. Where
164 the database is created is specified by the user.
170 User::LeaveIfError(fs.Connect());
171 CleanupClosePushL(fs);
173 CConsoleBase *console = Console::NewL(KAppName,TSize(KDefaultConsWidth, KDefaultConsHeight));
174 CleanupStack::PushL(console);
176 CCommandLineArguments *cmdLineArgs = CCommandLineArguments::NewLC();
179 argc = cmdLineArgs->Count();
181 //At least operation type and database file path must be given
184 CPrinter::Usage(console);
185 User::Leave(KErrArgument);
189 TBool import(EFalse);
192 TUint16 *filePath(0);
196 while(loopCount+1 <= argc)
198 TPtrC argv = cmdLineArgs->Arg(loopCount);
205 switch(argv.Ptr()[1])
209 {//the operation type is import
215 {//the operation type is export
221 {//the decision database file path
222 TPtrC path = cmdLineArgs->Arg(++loopCount);
223 dbPath = (TUint16 *)path.Ptr();
224 dbPathLen = path.Length();
229 {//the file which the database will be dumped to or populated from
230 TPtrC path = cmdLineArgs->Arg(++loopCount);
231 filePath = (TUint16 *)path.Ptr();
232 filePathLen = path.Length();
237 {//This parameter is not published in the help page
238 //It's been added to get rid of waiting at the end of the program.
239 flag |= CDatabase::EDoNotStop;
244 {//This parameter is not published in the help page
245 //It's been added to get rid of parsing error in the test environment.
246 flag |= CDatabase::EAppendTestResults;
251 {//This parameter is not published in the help page
252 //It's been added to print fields as binary instead hexadecimal.
253 flag |= CDatabase::EPrintBinary;
264 if(loopCount != argc || !dbPath || (import && !filePath))
266 CPrinter::Usage(console);
267 User::Leave(KErrArgument);
270 TPtr db(dbPath,dbPathLen);
271 db.SetLength(dbPathLen);
273 CDatabase* database = NULL;
277 TPtr file(filePath,filePathLen);
278 file.SetLength(filePathLen);
279 database = CDatabase::NewLC(console, fs, import, db, file);
283 database = CDatabase::NewLC(console, fs, import, db, KNullDesC);
286 database->iFlag = flag;
288 //Do actual import or export database operation
291 CleanupStack::PopAndDestroy(4, &fs);
295 GLDEF_C TInt E32Main()
297 CTrapCleanup *dumpupsdbCleanup = CTrapCleanup::New();
298 if(dumpupsdbCleanup == NULL)
303 CActiveScheduler* dumpupsdbScheduler = new(ELeave) CActiveScheduler;
304 CActiveScheduler::Install(dumpupsdbScheduler);
308 TRAPD(retval,MainL());
312 delete dumpupsdbCleanup;
313 delete dumpupsdbScheduler;
315 if(retval == KErrArgument)