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 |
* Defines 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 |
@file
|
sl@0
|
22 |
@test
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifndef DUMPUPSDB_H
|
sl@0
|
26 |
#define DUMPUPSDB_H
|
sl@0
|
27 |
|
sl@0
|
28 |
#include "upsdbw.h"
|
sl@0
|
29 |
#include "activewaiter.h"
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <e32std.h>
|
sl@0
|
32 |
#include <f32file.h>
|
sl@0
|
33 |
#include <e32cons.h>
|
sl@0
|
34 |
#include <bacline.h>
|
sl@0
|
35 |
#include <utf.h>
|
sl@0
|
36 |
|
sl@0
|
37 |
using namespace UserPromptService;
|
sl@0
|
38 |
|
sl@0
|
39 |
|
sl@0
|
40 |
_LIT(KAppName, "UPS Decision Database Dump Tool");
|
sl@0
|
41 |
|
sl@0
|
42 |
//Set flag values
|
sl@0
|
43 |
static const TUint16 KLocClientSid = 0x0001;
|
sl@0
|
44 |
static const TUint16 KLocEvaluatorId = 0x0002;
|
sl@0
|
45 |
static const TUint16 KLocServiceId = 0x0004;
|
sl@0
|
46 |
static const TUint16 KLocServerSid = 0x0008;
|
sl@0
|
47 |
static const TUint16 KLocFingerprint = 0x0010;
|
sl@0
|
48 |
static const TUint16 KLocClientEntity = 0x0020;
|
sl@0
|
49 |
static const TUint16 KLocDescription = 0x0040;
|
sl@0
|
50 |
static const TUint16 KLocResult = 0x0080;
|
sl@0
|
51 |
static const TUint16 KLocEvaluatorInfo = 0x0100;
|
sl@0
|
52 |
static const TUint16 KLocMajorPolicyVersion = 0x0200;
|
sl@0
|
53 |
static const TUint16 KLocRecordId = 0x0400;
|
sl@0
|
54 |
|
sl@0
|
55 |
//
|
sl@0
|
56 |
//CPrinter
|
sl@0
|
57 |
//
|
sl@0
|
58 |
|
sl@0
|
59 |
class CPrinter : public CBase
|
sl@0
|
60 |
/**
|
sl@0
|
61 |
Class that prints text to the console and optionally writes to a log file.
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
{
|
sl@0
|
64 |
public:
|
sl@0
|
65 |
static CPrinter* NewLC(CConsoleBase* aConsole);
|
sl@0
|
66 |
static CPrinter* NewLC(CConsoleBase* aConsole, RFile& aFile);
|
sl@0
|
67 |
static void Usage(CConsoleBase* aConsole);
|
sl@0
|
68 |
|
sl@0
|
69 |
~CPrinter();
|
sl@0
|
70 |
|
sl@0
|
71 |
void PrintfL(TRefByValue<const TDesC16> aFormat, ...);
|
sl@0
|
72 |
void Printf8L(TRefByValue<const TDesC8> aFormat, ...);
|
sl@0
|
73 |
void PrintOnlyConsoleL(const TDesC16& aFormat, ...);
|
sl@0
|
74 |
void Wait();
|
sl@0
|
75 |
void ReadNextLineL(TDes8& aLine);
|
sl@0
|
76 |
TInt FileSizeL();
|
sl@0
|
77 |
|
sl@0
|
78 |
private :
|
sl@0
|
79 |
CPrinter(CConsoleBase* aConsole);
|
sl@0
|
80 |
void ConstructL(RFile& aFile);
|
sl@0
|
81 |
|
sl@0
|
82 |
private:
|
sl@0
|
83 |
/** Console object to print text to the console*/
|
sl@0
|
84 |
CConsoleBase* iConsole;
|
sl@0
|
85 |
|
sl@0
|
86 |
/** Optional file handle to write text to the file*/
|
sl@0
|
87 |
RFile iFile;
|
sl@0
|
88 |
|
sl@0
|
89 |
/** Whether to log to the output to the file */
|
sl@0
|
90 |
TBool iLogToFile;
|
sl@0
|
91 |
|
sl@0
|
92 |
/** Temporary 16-bit buffer*/
|
sl@0
|
93 |
TBuf<256> iBuffer;
|
sl@0
|
94 |
|
sl@0
|
95 |
/** Temporary 8-bit buffer*/
|
sl@0
|
96 |
TBuf8<256> iBuffer8;
|
sl@0
|
97 |
|
sl@0
|
98 |
/** File stream handle*/
|
sl@0
|
99 |
RFileReadStream iReader;
|
sl@0
|
100 |
};
|
sl@0
|
101 |
|
sl@0
|
102 |
//
|
sl@0
|
103 |
//CDatabase
|
sl@0
|
104 |
//
|
sl@0
|
105 |
|
sl@0
|
106 |
class CDatabase : public CBase
|
sl@0
|
107 |
/**
|
sl@0
|
108 |
This class connects to the database and import/exports it to the console/file
|
sl@0
|
109 |
*/
|
sl@0
|
110 |
{
|
sl@0
|
111 |
public:
|
sl@0
|
112 |
static CDatabase* NewLC(CConsoleBase* aConsole, RFs& aFs, TBool aImport, const TDesC& aDb, const TDesC& aFile);
|
sl@0
|
113 |
|
sl@0
|
114 |
~CDatabase();
|
sl@0
|
115 |
|
sl@0
|
116 |
void DumpL();
|
sl@0
|
117 |
|
sl@0
|
118 |
private:
|
sl@0
|
119 |
CDatabase(TBool aImport);
|
sl@0
|
120 |
void ConstructL(CConsoleBase* aConsole, RFs& aFs, const TDesC& aDb, const TDesC& aFile);
|
sl@0
|
121 |
|
sl@0
|
122 |
void PrintDecisionL(CDecisionRecord& aRecord);
|
sl@0
|
123 |
void PrintHeaderL();
|
sl@0
|
124 |
CDecisionRecord* ParseAndCreateRecordLC(TDesC8& aLine);
|
sl@0
|
125 |
TUint8 HexToIntL(TUint8* aPtr);
|
sl@0
|
126 |
void HexToStrL(TDes8& aSource);
|
sl@0
|
127 |
void PrintTestResultsL();
|
sl@0
|
128 |
void PrintTestHeaderL();
|
sl@0
|
129 |
|
sl@0
|
130 |
private:
|
sl@0
|
131 |
/** Indicates the operation type: Import Db is ETrue and Export Db is EFalse*/
|
sl@0
|
132 |
TBool iImport;
|
sl@0
|
133 |
|
sl@0
|
134 |
/** Handle to the decision database*/
|
sl@0
|
135 |
CDecisionDbW* iUpsDb;
|
sl@0
|
136 |
|
sl@0
|
137 |
/** Handle to the printer object*/
|
sl@0
|
138 |
CPrinter* iPrinter;
|
sl@0
|
139 |
|
sl@0
|
140 |
/** Optional file handle to write text to the file*/
|
sl@0
|
141 |
RFile iFile;
|
sl@0
|
142 |
|
sl@0
|
143 |
public:
|
sl@0
|
144 |
/** Enumerated values to arrange run options. */
|
sl@0
|
145 |
enum TDbOptions
|
sl@0
|
146 |
{
|
sl@0
|
147 |
/** Indicates whether the dummy test result lines are written into the output file. */
|
sl@0
|
148 |
EAppendTestResults = 0x01,
|
sl@0
|
149 |
/** Indicates whether the command line waits for the user input at the end of the operation.*/
|
sl@0
|
150 |
EDoNotStop = 0x02,
|
sl@0
|
151 |
/** Indicates that fingerprint and client entity fields are printed as binary instead hexadecimal. */
|
sl@0
|
152 |
EPrintBinary = 0x04
|
sl@0
|
153 |
};
|
sl@0
|
154 |
|
sl@0
|
155 |
TUint8 iFlag; ///< A flag for running options.
|
sl@0
|
156 |
};
|
sl@0
|
157 |
|
sl@0
|
158 |
|
sl@0
|
159 |
static void MainL(void)
|
sl@0
|
160 |
/**
|
sl@0
|
161 |
Takes a User Prompt Service decision database file and dumps it as human readable text to the
|
sl@0
|
162 |
console. The user may also specify the name of an output file on the command line. If so, text
|
sl@0
|
163 |
is also written to this file. Also recreates a UPS decision database from a dumped file. Where
|
sl@0
|
164 |
the database is created is specified by the user.
|
sl@0
|
165 |
*/
|
sl@0
|
166 |
{
|
sl@0
|
167 |
|
sl@0
|
168 |
RFs fs;
|
sl@0
|
169 |
|
sl@0
|
170 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
171 |
CleanupClosePushL(fs);
|
sl@0
|
172 |
|
sl@0
|
173 |
CConsoleBase *console = Console::NewL(KAppName,TSize(KDefaultConsWidth, KDefaultConsHeight));
|
sl@0
|
174 |
CleanupStack::PushL(console);
|
sl@0
|
175 |
|
sl@0
|
176 |
CCommandLineArguments *cmdLineArgs = CCommandLineArguments::NewLC();
|
sl@0
|
177 |
|
sl@0
|
178 |
TInt argc;
|
sl@0
|
179 |
argc = cmdLineArgs->Count();
|
sl@0
|
180 |
|
sl@0
|
181 |
//At least operation type and database file path must be given
|
sl@0
|
182 |
if(argc < 4)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
CPrinter::Usage(console);
|
sl@0
|
185 |
User::Leave(KErrArgument);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
TInt loopCount(1);
|
sl@0
|
189 |
TBool import(EFalse);
|
sl@0
|
190 |
TUint16 *dbPath(0);
|
sl@0
|
191 |
TInt dbPathLen(0);
|
sl@0
|
192 |
TUint16 *filePath(0);
|
sl@0
|
193 |
TInt filePathLen(0);
|
sl@0
|
194 |
TUint8 flag(0);
|
sl@0
|
195 |
|
sl@0
|
196 |
while(loopCount+1 <= argc)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TPtrC argv = cmdLineArgs->Arg(loopCount);
|
sl@0
|
199 |
|
sl@0
|
200 |
if(argv.Locate('-'))
|
sl@0
|
201 |
{
|
sl@0
|
202 |
break;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
switch(argv.Ptr()[1])
|
sl@0
|
206 |
{
|
sl@0
|
207 |
case 'i':
|
sl@0
|
208 |
case 'I':
|
sl@0
|
209 |
{//the operation type is import
|
sl@0
|
210 |
import = ETrue;
|
sl@0
|
211 |
break;
|
sl@0
|
212 |
}
|
sl@0
|
213 |
case 'e':
|
sl@0
|
214 |
case 'E':
|
sl@0
|
215 |
{//the operation type is export
|
sl@0
|
216 |
import = EFalse;
|
sl@0
|
217 |
break;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
case 'd':
|
sl@0
|
220 |
case 'D':
|
sl@0
|
221 |
{//the decision database file path
|
sl@0
|
222 |
TPtrC path = cmdLineArgs->Arg(++loopCount);
|
sl@0
|
223 |
dbPath = (TUint16 *)path.Ptr();
|
sl@0
|
224 |
dbPathLen = path.Length();
|
sl@0
|
225 |
break;
|
sl@0
|
226 |
}
|
sl@0
|
227 |
case 'f':
|
sl@0
|
228 |
case 'F':
|
sl@0
|
229 |
{//the file which the database will be dumped to or populated from
|
sl@0
|
230 |
TPtrC path = cmdLineArgs->Arg(++loopCount);
|
sl@0
|
231 |
filePath = (TUint16 *)path.Ptr();
|
sl@0
|
232 |
filePathLen = path.Length();
|
sl@0
|
233 |
break;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
case 's':
|
sl@0
|
236 |
case 'S':
|
sl@0
|
237 |
{//This parameter is not published in the help page
|
sl@0
|
238 |
//It's been added to get rid of waiting at the end of the program.
|
sl@0
|
239 |
flag |= CDatabase::EDoNotStop;
|
sl@0
|
240 |
break;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
case 't':
|
sl@0
|
243 |
case 'T':
|
sl@0
|
244 |
{//This parameter is not published in the help page
|
sl@0
|
245 |
//It's been added to get rid of parsing error in the test environment.
|
sl@0
|
246 |
flag |= CDatabase::EAppendTestResults;
|
sl@0
|
247 |
break;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
case 'b':
|
sl@0
|
250 |
case 'B':
|
sl@0
|
251 |
{//This parameter is not published in the help page
|
sl@0
|
252 |
//It's been added to print fields as binary instead hexadecimal.
|
sl@0
|
253 |
flag |= CDatabase::EPrintBinary;
|
sl@0
|
254 |
break;
|
sl@0
|
255 |
}
|
sl@0
|
256 |
default:
|
sl@0
|
257 |
break;
|
sl@0
|
258 |
}//switch
|
sl@0
|
259 |
|
sl@0
|
260 |
++loopCount;
|
sl@0
|
261 |
|
sl@0
|
262 |
}//while loop
|
sl@0
|
263 |
|
sl@0
|
264 |
if(loopCount != argc || !dbPath || (import && !filePath))
|
sl@0
|
265 |
{
|
sl@0
|
266 |
CPrinter::Usage(console);
|
sl@0
|
267 |
User::Leave(KErrArgument);
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
TPtr db(dbPath,dbPathLen);
|
sl@0
|
271 |
db.SetLength(dbPathLen);
|
sl@0
|
272 |
|
sl@0
|
273 |
CDatabase* database = NULL;
|
sl@0
|
274 |
|
sl@0
|
275 |
if(filePath)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
TPtr file(filePath,filePathLen);
|
sl@0
|
278 |
file.SetLength(filePathLen);
|
sl@0
|
279 |
database = CDatabase::NewLC(console, fs, import, db, file);
|
sl@0
|
280 |
}
|
sl@0
|
281 |
else
|
sl@0
|
282 |
{
|
sl@0
|
283 |
database = CDatabase::NewLC(console, fs, import, db, KNullDesC);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
database->iFlag = flag;
|
sl@0
|
287 |
|
sl@0
|
288 |
//Do actual import or export database operation
|
sl@0
|
289 |
database->DumpL();
|
sl@0
|
290 |
|
sl@0
|
291 |
CleanupStack::PopAndDestroy(4, &fs);
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
|
sl@0
|
295 |
GLDEF_C TInt E32Main()
|
sl@0
|
296 |
{
|
sl@0
|
297 |
CTrapCleanup *dumpupsdbCleanup = CTrapCleanup::New();
|
sl@0
|
298 |
if(dumpupsdbCleanup == NULL)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
return KErrNoMemory;
|
sl@0
|
301 |
}
|
sl@0
|
302 |
|
sl@0
|
303 |
CActiveScheduler* dumpupsdbScheduler = new(ELeave) CActiveScheduler;
|
sl@0
|
304 |
CActiveScheduler::Install(dumpupsdbScheduler);
|
sl@0
|
305 |
|
sl@0
|
306 |
__UHEAP_MARK;
|
sl@0
|
307 |
|
sl@0
|
308 |
TRAPD(retval,MainL());
|
sl@0
|
309 |
|
sl@0
|
310 |
__UHEAP_MARKEND;
|
sl@0
|
311 |
|
sl@0
|
312 |
delete dumpupsdbCleanup;
|
sl@0
|
313 |
delete dumpupsdbScheduler;
|
sl@0
|
314 |
|
sl@0
|
315 |
if(retval == KErrArgument)
|
sl@0
|
316 |
{
|
sl@0
|
317 |
return KErrNone;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
return retval;
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
#endif
|