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 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "keytool_defs.h"
|
sl@0
|
20 |
#include "keytoolfileview.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <e32cons.h>
|
sl@0
|
23 |
#include "keytool_utils.h"
|
sl@0
|
24 |
#include <s32file.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
/*static*/ CKeytoolFileView* CKeytoolFileView::NewLC(const TDesC& aInputFile)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
CKeytoolFileView* self = new (ELeave) CKeytoolFileView();
|
sl@0
|
30 |
CleanupStack::PushL(self);
|
sl@0
|
31 |
self->ConstructL(aInputFile);
|
sl@0
|
32 |
return self;
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
CKeytoolFileView::CKeytoolFileView()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
CKeytoolFileView::~CKeytoolFileView()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
iFs.Close();
|
sl@0
|
42 |
iFile.Close();
|
sl@0
|
43 |
iArgs.ResetAndDestroy();
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
void CKeytoolFileView::ConstructL(const TDesC& aInputFile)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
49 |
User::LeaveIfError(iFile.Open(iFs, aInputFile, EFileShareExclusive));
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
void CKeytoolFileView::DisplayUsage()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void CKeytoolFileView::BoilerPlate()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
void CKeytoolFileView::DisplayKeyInfoL(CCTKeyInfo& aKey, TBool aIsDetailed, TBool /*aPageWise*/)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
// Display the key infos
|
sl@0
|
64 |
KeyToolUtils::PrintKeyInfoL(aKey, aIsDetailed);
|
sl@0
|
65 |
KeyToolUtils::PrintInfoL(_L("\n"));
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
void CKeytoolFileView::DisplayErrorL(const TDesC& aError, TInt aErrorCode, TBool/* aPageWise*/)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
KeyToolUtils::PrintInfoL(aError);
|
sl@0
|
71 |
KeyToolUtils::PrintInfoL(_L("\nError code: "));
|
sl@0
|
72 |
KeyToolUtils::WriteErrorL(aErrorCode);
|
sl@0
|
73 |
KeyToolUtils::PrintInfoL(_L("\n"));
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
void CKeytoolFileView::DisplayErrorL(const TDesC& aError, TBool/* aPageWise*/)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
KeyToolUtils::PrintInfoL(aError);
|
sl@0
|
79 |
KeyToolUtils::PrintInfoL(_L("\n"));
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
void CKeytoolFileView::DisplayCertL(CCTCertInfo& aCert, CCertificate& aCertificate, RUidArray aApps, TBool aTrusted, TBool aIsDetailed, TBool/* aPageWise*/)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
// Display the key infos
|
sl@0
|
85 |
KeyToolUtils::PrintCertInfoL(aCert, aCertificate, aApps, aTrusted, aIsDetailed);
|
sl@0
|
86 |
KeyToolUtils::PrintInfoL(_L("\n"));
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
CArrayFixFlat<TPtrC>* CKeytoolFileView::ReadArrayArgumentsLC(TInt cmdIndex)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
CArrayFixFlat<TPtrC>* currentCmd = new (ELeave) CArrayFixFlat<TPtrC> (10);
|
sl@0
|
92 |
CleanupStack::PushL(currentCmd);
|
sl@0
|
93 |
TPtr cmd = iArgs[cmdIndex]->Des();
|
sl@0
|
94 |
cmd.Trim();
|
sl@0
|
95 |
TLex arguments(cmd);
|
sl@0
|
96 |
while(!arguments.Eos())
|
sl@0
|
97 |
{
|
sl@0
|
98 |
TPtrC token = arguments.NextToken();
|
sl@0
|
99 |
currentCmd->AppendL(token);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
TBuf<150> string;
|
sl@0
|
103 |
string.Format(_L("Command : %S\noutput :"), &cmd);
|
sl@0
|
104 |
KeyToolUtils::PrintInfoL(_L("================================================"));
|
sl@0
|
105 |
KeyToolUtils::PrintInfoL(_L("================================================\n"));
|
sl@0
|
106 |
DisplayErrorL(string, 0);
|
sl@0
|
107 |
return currentCmd;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
TInt CKeytoolFileView::SplitFileInputToArrayL()
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TInt fSize;
|
sl@0
|
113 |
iFile.Size(fSize);
|
sl@0
|
114 |
|
sl@0
|
115 |
HBufC8* fileContents = HBufC8::NewLC(fSize);
|
sl@0
|
116 |
TPtr8 ptr(fileContents->Des());
|
sl@0
|
117 |
ptr.SetLength(fSize);
|
sl@0
|
118 |
|
sl@0
|
119 |
// create file stream and Read the content from the file
|
sl@0
|
120 |
RFileReadStream inputFileStream(iFile);
|
sl@0
|
121 |
CleanupClosePushL(inputFileStream);
|
sl@0
|
122 |
inputFileStream.ReadL(ptr, fSize);
|
sl@0
|
123 |
CleanupStack::PopAndDestroy(&inputFileStream);
|
sl@0
|
124 |
|
sl@0
|
125 |
TInt readPos = 0;
|
sl@0
|
126 |
TPtrC8 lineContents;
|
sl@0
|
127 |
|
sl@0
|
128 |
TInt lineCount = 0;
|
sl@0
|
129 |
while (!ReadLine(*fileContents, readPos, lineContents))
|
sl@0
|
130 |
{
|
sl@0
|
131 |
TInt lineLength = lineContents.Length();
|
sl@0
|
132 |
if (lineLength)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
lineCount++;
|
sl@0
|
135 |
HBufC* currentLine = HBufC::NewLC(lineLength);
|
sl@0
|
136 |
currentLine->Des().Copy(lineContents);
|
sl@0
|
137 |
iArgs.AppendL(currentLine);
|
sl@0
|
138 |
CleanupStack::Pop(currentLine);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
CleanupStack::PopAndDestroy(fileContents);
|
sl@0
|
142 |
return lineCount;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
TInt CKeytoolFileView::ReadLine(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
TBool endOfBuffer = EFalse;
|
sl@0
|
148 |
const TChar KCarriageReturn = '\r';
|
sl@0
|
149 |
const TChar KLineReturn = '\n';
|
sl@0
|
150 |
|
sl@0
|
151 |
TInt bufferLength = aBuffer.Length();
|
sl@0
|
152 |
if ( aPos > bufferLength || aPos < 0 )
|
sl@0
|
153 |
{
|
sl@0
|
154 |
return ETrue; // End of buffer
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
// find the position of the next delimter
|
sl@0
|
158 |
TInt endPos = aPos;
|
sl@0
|
159 |
while (endPos < bufferLength)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
TChar c = aBuffer[endPos];
|
sl@0
|
162 |
|
sl@0
|
163 |
if (c == KCarriageReturn || c == KLineReturn)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
break;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
endPos++;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
if (endPos != aPos)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TInt tokenLen = endPos - aPos;
|
sl@0
|
173 |
aLine.Set(&aBuffer[aPos], tokenLen);
|
sl@0
|
174 |
endPos += 2;
|
sl@0
|
175 |
}
|
sl@0
|
176 |
else
|
sl@0
|
177 |
{
|
sl@0
|
178 |
return ETrue; // End of buffer
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
aPos = endPos;
|
sl@0
|
182 |
return endOfBuffer;
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
|