|
1 /* |
|
2 * Copyright (c) 2004-2009 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 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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "certtool_engine.h" |
|
20 #include "certtool_controller.h" |
|
21 #include "keytool_controller.h" |
|
22 |
|
23 |
|
24 /*static*/ CCertToolEngine* CCertToolEngine::NewLC(CCertToolController* aController) |
|
25 { |
|
26 CCertToolEngine* self = new (ELeave) CCertToolEngine(aController); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 /*static*/ CCertToolEngine* CCertToolEngine::NewL(CCertToolController* aController) |
|
33 { |
|
34 CCertToolEngine* self = CCertToolEngine::NewLC(aController); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CCertToolEngine::CCertToolEngine(CCertToolController* aController) : CActive(EPriorityNormal) |
|
40 { |
|
41 iCurrentAction = EIdle; |
|
42 iController = aController; |
|
43 } |
|
44 |
|
45 CCertToolEngine::~CCertToolEngine() |
|
46 { |
|
47 Cancel(); |
|
48 delete iHandler; |
|
49 delete iKeyHandler; |
|
50 delete iKeyController; |
|
51 |
|
52 delete iKeyStore; |
|
53 iFsKeyStore.Close(); |
|
54 delete iCertStore; |
|
55 iFs.Close(); |
|
56 delete iScheduler; |
|
57 } |
|
58 |
|
59 void CCertToolEngine::ConstructL() |
|
60 { |
|
61 iScheduler = new(ELeave) CActiveScheduler; |
|
62 CActiveScheduler::Install(iScheduler); |
|
63 |
|
64 User::LeaveIfError(iFs.Connect()); |
|
65 |
|
66 iCertStore = CUnifiedCertStore::NewL(iFs, ETrue); |
|
67 |
|
68 User::LeaveIfError(iFsKeyStore.Connect()); |
|
69 |
|
70 iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore); |
|
71 |
|
72 CActiveScheduler::Add(this); |
|
73 } |
|
74 |
|
75 void CCertToolEngine::RunL() |
|
76 { |
|
77 if (iStatus.Int() != KErrNone) |
|
78 { |
|
79 User::Leave(iStatus.Int()); |
|
80 } |
|
81 |
|
82 switch (iState) |
|
83 { |
|
84 case EInitialiseKeyStore: |
|
85 { |
|
86 iKeyHandler->DoCommandL(*iKeyStore, iParam); |
|
87 iState = EDone; |
|
88 } |
|
89 break; |
|
90 case EInitialise: |
|
91 { |
|
92 iHandler->DoCommandL(*iCertStore, iParam); |
|
93 iState = EDone; |
|
94 } |
|
95 break; |
|
96 case EDone: |
|
97 { |
|
98 } |
|
99 break; |
|
100 default: |
|
101 { |
|
102 User::Panic(_L("Certtool Engine - Illegal state"), 0); |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 TInt CCertToolEngine::RunError(TInt aError) |
|
108 { |
|
109 CActiveScheduler::Stop(); |
|
110 |
|
111 switch (iCurrentAction) |
|
112 { |
|
113 case EList: |
|
114 { |
|
115 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_LIST, aError)); |
|
116 } |
|
117 break; |
|
118 case EImport: |
|
119 { |
|
120 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_IMPORT, aError)); |
|
121 } |
|
122 break; |
|
123 default: |
|
124 { |
|
125 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_UNKNOWN, aError)); |
|
126 } |
|
127 } |
|
128 return KErrNone; |
|
129 } |
|
130 |
|
131 |
|
132 void CCertToolEngine::DoCancel() |
|
133 { |
|
134 //CActiveScheduler::Stop(); |
|
135 } |
|
136 |
|
137 |
|
138 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\// |
|
139 //\\//\\//\\//\\// Business methods //\\//\\//\\//\\// |
|
140 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\// |
|
141 |
|
142 void CCertToolEngine::ListL(CKeyToolParameters* aParam) |
|
143 { |
|
144 Cancel(); |
|
145 iParam = aParam; |
|
146 iCurrentAction = EList; |
|
147 delete iHandler; |
|
148 iHandler = NULL; |
|
149 iHandler = CCertToolList::NewL(iController); |
|
150 iState = EInitialise; |
|
151 iCertStore->Initialize(iStatus); |
|
152 SetActive(); |
|
153 } |
|
154 |
|
155 void CCertToolEngine::ListStoresL(CKeyToolParameters* aParam) |
|
156 { |
|
157 Cancel(); |
|
158 iParam = aParam; |
|
159 iCurrentAction = EList; |
|
160 iHandler = CCertToolListStores::NewL(iController); |
|
161 iState = EInitialise; |
|
162 iCertStore->Initialize(iStatus); |
|
163 SetActive(); |
|
164 } |
|
165 |
|
166 void CCertToolEngine::ImportPrivateL(CKeyToolParameters* aParam) |
|
167 { |
|
168 Cancel(); |
|
169 |
|
170 iKeyController = CKeyToolController::NewL(iController->GetView()); |
|
171 if (!aParam->iDefault) |
|
172 { |
|
173 iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE); |
|
174 User::Leave(KErrArgument); |
|
175 } |
|
176 |
|
177 iParam = aParam; |
|
178 iCurrentAction = EImport; |
|
179 iKeyHandler = CKeytoolImport::NewL(iKeyController); |
|
180 iState = EInitialiseKeyStore; |
|
181 iKeyStore->Initialize(iStatus); |
|
182 SetActive(); |
|
183 } |
|
184 |
|
185 void CCertToolEngine::SetManagerPolicyL(CKeyToolParameters* aParam) |
|
186 { |
|
187 Cancel(); |
|
188 delete iKeyController; |
|
189 iKeyController = NULL; |
|
190 iKeyController = CKeyToolController::NewL(iController->GetView()); |
|
191 if (!aParam->iDefault) |
|
192 { |
|
193 iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE); |
|
194 User::Leave(KErrArgument); |
|
195 } |
|
196 |
|
197 iParam = aParam; |
|
198 iCurrentAction = ESetPolicy; |
|
199 delete iKeyHandler; |
|
200 iKeyHandler = NULL; |
|
201 iKeyHandler = CKeytoolSetPolicy::NewL(iKeyController); |
|
202 iState = EInitialiseKeyStore; |
|
203 delete iKeyStore; |
|
204 iKeyStore = NULL; |
|
205 iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore); |
|
206 iKeyStore->Initialize(iStatus); |
|
207 SetActive(); |
|
208 } |
|
209 |
|
210 void CCertToolEngine::RemovePrivateL(CKeyToolParameters* aParam) |
|
211 { |
|
212 Cancel(); |
|
213 |
|
214 iKeyController = CKeyToolController::NewL(iController->GetView()); |
|
215 if (!aParam->iDefault) |
|
216 { |
|
217 iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE); |
|
218 User::Leave(KErrArgument); |
|
219 } |
|
220 |
|
221 iParam = aParam; |
|
222 iCurrentAction = ERemove; |
|
223 iKeyHandler = CKeytoolRemove::NewL(iKeyController); |
|
224 iState = EInitialiseKeyStore; |
|
225 User::LeaveIfError(iFsKeyStore.Connect()); |
|
226 delete iKeyStore; |
|
227 iKeyStore = NULL; |
|
228 iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore); |
|
229 iKeyStore->Initialize(iStatus); |
|
230 SetActive(); |
|
231 } |
|
232 |
|
233 void CCertToolEngine::ImportL(CKeyToolParameters* aParam) |
|
234 { |
|
235 Cancel(); |
|
236 delete iKeyHandler; |
|
237 iKeyHandler = NULL; |
|
238 delete iKeyController; |
|
239 iKeyController = NULL; |
|
240 |
|
241 if (!aParam->iDefault) |
|
242 { |
|
243 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_CERTFILE); |
|
244 User::Leave(KErrArgument); |
|
245 } |
|
246 |
|
247 iParam = aParam; |
|
248 iCurrentAction = EImport; |
|
249 iHandler = CCertToolAdd::NewL(iController); |
|
250 iState = EInitialise; |
|
251 iCertStore->Initialize(iStatus); |
|
252 SetActive(); |
|
253 } |
|
254 |
|
255 void CCertToolEngine::RemoveL(CKeyToolParameters* aParam) |
|
256 { |
|
257 Cancel(); |
|
258 delete iKeyHandler; |
|
259 iKeyHandler = NULL; |
|
260 delete iKeyController; |
|
261 iKeyController = NULL; |
|
262 |
|
263 if (!aParam->iDefault) |
|
264 { |
|
265 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE); |
|
266 User::Leave(KErrArgument); |
|
267 } |
|
268 |
|
269 iParam = aParam; |
|
270 iCurrentAction = ERemove; |
|
271 iHandler = CCertToolRemove::NewL(iController); |
|
272 iState = EInitialise; |
|
273 iCertStore->Initialize(iStatus); |
|
274 SetActive(); |
|
275 } |
|
276 |
|
277 void CCertToolEngine::SetupUidCommandL(CKeyToolParameters* aParam) |
|
278 { |
|
279 Cancel(); |
|
280 if (!aParam->iDefault && !aParam->iLabel) |
|
281 { |
|
282 iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOCERT); |
|
283 User::Leave(KErrArgument); |
|
284 } |
|
285 |
|
286 if (aParam->iUIDs.Count()==0) |
|
287 { |
|
288 iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOAPPS); |
|
289 User::Leave(KErrArgument); |
|
290 } |
|
291 |
|
292 iParam = aParam; |
|
293 iCurrentAction = EAddApps; |
|
294 iState = EInitialise; |
|
295 iCertStore->Initialize(iStatus); |
|
296 SetActive(); |
|
297 } |
|
298 |
|
299 void CCertToolEngine::SetAppsL(CKeyToolParameters* aParam) |
|
300 { |
|
301 iCurrentAction = ESetApps; |
|
302 iHandler = CCertToolSetApps::NewL(iController); |
|
303 SetupUidCommandL(aParam); |
|
304 } |
|
305 |
|
306 |
|
307 void CCertToolEngine::RemoveAppsL(CKeyToolParameters* aParam) |
|
308 { |
|
309 iHandler = CCertToolRemoveApps::NewL(iController); |
|
310 SetupUidCommandL(aParam); |
|
311 } |
|
312 |
|
313 |
|
314 void CCertToolEngine::AddAppsL(CKeyToolParameters* aParam) |
|
315 { |
|
316 iHandler = CCertToolAddApps::NewL(iController); |
|
317 SetupUidCommandL(aParam); |
|
318 } |
|
319 |
|
320 |
|
321 |
|
322 void CCertToolEngine::DisplayUsageL(CKeyToolParameters* aParam) |
|
323 { |
|
324 iHandler = CCertToolUsage::NewL(iController); |
|
325 iHandler->DoCommandL(*iCertStore, aParam); |
|
326 } |