|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cstsfiledatamanager.h" |
|
21 #include <JavaUtils.h> |
|
22 |
|
23 #include <utf.h> |
|
24 #include "cstsauthtype.h" |
|
25 #include "cstspinattributes.h" |
|
26 |
|
27 namespace java |
|
28 { |
|
29 namespace satsa |
|
30 { |
|
31 |
|
32 // CONSTANTS |
|
33 //max size got from PKCS#15 standard, TokenInfo.label field description |
|
34 const TInt KSTSWIMLabelMaxLength = 255; |
|
35 const TInt KSTSWIMPathMaxLength = 6; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSTSFileDataManager::CSTSFileDataManager |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CSTSFileDataManager::CSTSFileDataManager() : |
|
46 CActive(EPriorityNormal), iWimLabelAndPathDone(EFalse) |
|
47 { |
|
48 CActiveScheduler::Add(this); |
|
49 iState = ENotReady; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSTSFileDataManager::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CSTSFileDataManager::ConstructL() |
|
58 { |
|
59 iWait = new(ELeave) CActiveSchedulerWait; |
|
60 iMidpProv = CWimJavaUtils::NewL(); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CSTSFileDataManager::NewL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CSTSFileDataManager* CSTSFileDataManager::NewL() |
|
69 { |
|
70 CSTSFileDataManager* self = new(ELeave) CSTSFileDataManager(); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // Destructor |
|
78 CSTSFileDataManager::~CSTSFileDataManager() |
|
79 { |
|
80 |
|
81 delete iMidpProv; |
|
82 delete iWait; |
|
83 |
|
84 delete iACFData; |
|
85 delete iACIFData; |
|
86 delete iWimPath; |
|
87 delete iWimLabel16; |
|
88 |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CSTSFileDataManager::InitializeL |
|
93 // |
|
94 // ----------------------------------------------------------------------------- |
|
95 void CSTSFileDataManager::InitializeL() |
|
96 { |
|
97 iMidpProv->Initialize(iStatus); |
|
98 iState = EInitializing; |
|
99 WaitAndCheckL(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSTSFileDataManager::RetrieveACIFContentL |
|
104 // |
|
105 // ----------------------------------------------------------------------------- |
|
106 const TDesC8& CSTSFileDataManager::RetrieveACIFContentL() |
|
107 { |
|
108 TInt fileSize = 0; |
|
109 iMidpProv->GetACIFSize(fileSize, iStatus); |
|
110 iState = EGettingACIFSize; |
|
111 WaitAndCheckL(); |
|
112 |
|
113 //allocate buffer for file data |
|
114 HBufC8* tmp = HBufC8::NewL(fileSize); |
|
115 delete iACIFData; |
|
116 iACIFData = tmp; |
|
117 |
|
118 TPtr8 wholeData(iACIFData->Des()); |
|
119 |
|
120 iMidpProv->RetrieveACIFContent(wholeData, iStatus); |
|
121 iState = ERetrievingACIF; |
|
122 WaitAndCheckL(); |
|
123 |
|
124 return *iACIFData; |
|
125 |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CSTSFileDataManager::RetrieveACFContentL |
|
130 // |
|
131 // ----------------------------------------------------------------------------- |
|
132 const TDesC8& CSTSFileDataManager::RetrieveACFContentL( |
|
133 const TDesC8& aFileIdOrPath) |
|
134 { |
|
135 TInt fileSize = 0; |
|
136 iMidpProv->GetACFSize(fileSize, aFileIdOrPath, iStatus); |
|
137 iState = EGettingACFSize; |
|
138 WaitAndCheckL(); |
|
139 //allocate buffer for file data |
|
140 HBufC8* tmp = HBufC8::NewL(fileSize); |
|
141 delete iACFData; |
|
142 iACFData = tmp; |
|
143 |
|
144 TPtr8 wholeData(iACFData->Des()); |
|
145 |
|
146 iMidpProv->RetrieveACFContent(wholeData, aFileIdOrPath, iStatus); |
|
147 iState = ERetrievingACF; |
|
148 WaitAndCheckL(); |
|
149 |
|
150 return *iACFData; |
|
151 |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSTSFileDataManager::GetAuthObjsInfoL |
|
156 // |
|
157 // ----------------------------------------------------------------------------- |
|
158 void CSTSFileDataManager::GetAuthObjectsL(CArrayPtr<CSTSAuthType>* aAuthTypes, |
|
159 const RArray<TInt>& aAuthIdList) |
|
160 { |
|
161 TInt auhtIdCount = aAuthIdList.Count(); |
|
162 |
|
163 if (auhtIdCount > 0) |
|
164 { |
|
165 |
|
166 RArray<TJavaPINParams> authObjsInfoList(auhtIdCount); |
|
167 |
|
168 iMidpProv->GetAuthObjsInfo(aAuthIdList, authObjsInfoList, iStatus); |
|
169 iState = EGettingAuthObjsInfo; |
|
170 WaitAndCheckL(); |
|
171 |
|
172 //make conversion to own struct |
|
173 TInt count = authObjsInfoList.Count(); |
|
174 |
|
175 for (TInt i = 0; i < count; i++) |
|
176 { |
|
177 //creates authType and add values |
|
178 CSTSAuthType* currentObject = CSTSAuthType::NewLC(); |
|
179 currentObject->SetAuthIDL(authObjsInfoList[i].iAuthId); |
|
180 currentObject->SetLabelL(authObjsInfoList[i].iPINLabel); |
|
181 |
|
182 CSTSPinAttributes* pinAttr = CSTSPinAttributes::NewLC( |
|
183 authObjsInfoList[i].iPinType, |
|
184 authObjsInfoList[i].iMinLength, |
|
185 authObjsInfoList[i].iStoredLength, |
|
186 authObjsInfoList[i].iMaxLength, |
|
187 authObjsInfoList[i].iPinReference, |
|
188 authObjsInfoList[i].iPadChar, authObjsInfoList[i].iFlags); |
|
189 |
|
190 currentObject->SetPinAttributesL(*pinAttr); |
|
191 |
|
192 CleanupStack::PopAndDestroy(pinAttr); |
|
193 |
|
194 //append authType to the parameter array (ownership transferred) |
|
195 aAuthTypes->AppendL(currentObject); |
|
196 CleanupStack::Pop(currentObject); |
|
197 |
|
198 } |
|
199 |
|
200 authObjsInfoList.Close(); |
|
201 |
|
202 } |
|
203 |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CSTSFileDataManager::RetrieveWIMLabelL |
|
208 // |
|
209 // ----------------------------------------------------------------------------- |
|
210 const TDesC& CSTSFileDataManager::RetrieveWIMLabelL() |
|
211 { |
|
212 doRetrieveWIMLabelAndPathL(); |
|
213 return *iWimLabel16; |
|
214 |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CSTSFileDataManager::RetrieveWIMPathL |
|
219 // |
|
220 // ----------------------------------------------------------------------------- |
|
221 const TDesC8& CSTSFileDataManager::RetrieveWIMPathL() |
|
222 { |
|
223 doRetrieveWIMLabelAndPathL(); |
|
224 return *iWimPath; |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CSTSFileDataManager::WaitAndCheckL |
|
229 // |
|
230 // ----------------------------------------------------------------------------- |
|
231 void CSTSFileDataManager::WaitAndCheckL() |
|
232 { |
|
233 |
|
234 SetActive(); |
|
235 |
|
236 if (!iWait->IsStarted()) |
|
237 { |
|
238 iWait->Start(); |
|
239 } |
|
240 User::LeaveIfError(iError); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CSTSFileDataManager::doRetrieveWIMLabelAndPathL |
|
245 // Retrieves WIM label and path and saves values to member variables. |
|
246 // Saves information that retrieve is done and does not do retrieve if it is |
|
247 // already done. |
|
248 // ----------------------------------------------------------------------------- |
|
249 void CSTSFileDataManager::doRetrieveWIMLabelAndPathL() |
|
250 { |
|
251 if (!iWimLabelAndPathDone) |
|
252 { |
|
253 //allocate buffer for WIM label |
|
254 HBufC8* wimLabelBuf = HBufC8::NewLC(KSTSWIMLabelMaxLength); |
|
255 TPtr8 wimLabel(wimLabelBuf->Des()); |
|
256 |
|
257 //allocate buffer for WIM path |
|
258 HBufC8* tmpPath = HBufC8::NewL(KSTSWIMPathMaxLength); |
|
259 delete iWimPath; |
|
260 iWimPath = tmpPath; |
|
261 TPtr8 wimPath(iWimPath->Des()); |
|
262 |
|
263 iMidpProv->RetrieveWimLabelAndPath(wimLabel, wimPath, iStatus); |
|
264 iState = EGettingWimLabelAndPath; |
|
265 WaitAndCheckL(); |
|
266 |
|
267 //convert label to TDesC format |
|
268 //allocate member buffer for WIM label |
|
269 HBufC16* tmpLabel16 = HBufC16::NewL(wimLabel.Length()); |
|
270 delete iWimLabel16; |
|
271 iWimLabel16 = tmpLabel16; |
|
272 TPtr16 label16(iWimLabel16->Des()); |
|
273 |
|
274 TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(label16, wimLabel); |
|
275 User::LeaveIfError(err); |
|
276 CleanupStack::PopAndDestroy(wimLabelBuf); |
|
277 //save information that both has retrieved |
|
278 iWimLabelAndPathDone = ETrue; |
|
279 } |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CSTSFileDataManager::RunL |
|
284 // |
|
285 // (other items were commented in a header). |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 void CSTSFileDataManager::RunL() |
|
289 { |
|
290 iError = iStatus.Int(); |
|
291 iState = EReady; |
|
292 iWait->AsyncStop(); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CSTSFileDataManager::DoCancel |
|
297 // Cancels all possible active actions |
|
298 // (other items were commented in a header). |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CSTSFileDataManager::DoCancel() |
|
302 { |
|
303 switch (iState) |
|
304 { |
|
305 case EInitializing: |
|
306 { |
|
307 iMidpProv->CancelInitialize(); |
|
308 break; |
|
309 } |
|
310 case EGettingACIFSize: |
|
311 { |
|
312 iMidpProv->CancelGetACIFSize(); |
|
313 break; |
|
314 } |
|
315 case ERetrievingACIF: |
|
316 { |
|
317 iMidpProv->CancelRetrieveACIFContent(); |
|
318 break; |
|
319 } |
|
320 case EGettingACFSize: |
|
321 { |
|
322 iMidpProv->CancelGetACFSize(); |
|
323 break; |
|
324 } |
|
325 case ERetrievingACF: |
|
326 { |
|
327 iMidpProv->CancelRetrieveACFContent(); |
|
328 break; |
|
329 } |
|
330 case EGettingAuthObjsInfo: |
|
331 { |
|
332 iMidpProv->CancelGetAuthObjsInfo(); |
|
333 break; |
|
334 } |
|
335 case EGettingWimLabelAndPath: |
|
336 { |
|
337 iMidpProv->CancelRetrieveWimLabelAndPath(); |
|
338 break; |
|
339 } |
|
340 |
|
341 default: |
|
342 { |
|
343 // nothing to cancel |
|
344 } |
|
345 } |
|
346 iState = EReady; |
|
347 iError = KErrCancel; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CSTSFileDataManager::RunError |
|
352 // If leave occures in RunL,this method is called. |
|
353 // (other items were commented in a header). |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 TInt CSTSFileDataManager::RunError(TInt /*aError*/) |
|
357 { |
|
358 //must return KErrNone |
|
359 return KErrNone; |
|
360 } |
|
361 |
|
362 } // namespace satsa |
|
363 } // namespace java |
|
364 // End of File |