|
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 "keytool_engine.h" |
|
20 #include "keytool_controller.h" |
|
21 #include "keytool_commands.h" |
|
22 |
|
23 #include <keytool.rsg> |
|
24 |
|
25 |
|
26 /*static*/ CKeyToolEngine* CKeyToolEngine::NewLC(CKeyToolController* aController) |
|
27 { |
|
28 CKeyToolEngine* self = new (ELeave) CKeyToolEngine(aController); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 /* static */ CKeyToolEngine* CKeyToolEngine::NewL(CKeyToolController* aController) |
|
35 { |
|
36 CKeyToolEngine* self = CKeyToolEngine::NewLC(aController); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 CKeyToolEngine::CKeyToolEngine(CKeyToolController* aController) : CActive(EPriorityNormal) |
|
42 { |
|
43 iCurrentAction = EIdle; |
|
44 iController = aController; |
|
45 iInitialized = EFalse; |
|
46 } |
|
47 |
|
48 CKeyToolEngine::~CKeyToolEngine() |
|
49 { |
|
50 Cancel(); |
|
51 delete iHandler; |
|
52 delete iKeyStore; |
|
53 iFs.Close(); |
|
54 if (iActiveStarted) |
|
55 { |
|
56 delete iScheduler; |
|
57 } |
|
58 iInitialized = EFalse; |
|
59 } |
|
60 |
|
61 void CKeyToolEngine::ConstructL() |
|
62 { |
|
63 iActiveStarted = EFalse; |
|
64 iScheduler = CActiveScheduler::Current(); |
|
65 if (!iScheduler) |
|
66 { |
|
67 iActiveStarted = ETrue; |
|
68 iScheduler = new(ELeave) CActiveScheduler; |
|
69 CActiveScheduler::Install(iScheduler); |
|
70 } |
|
71 |
|
72 User::LeaveIfError(iFs.Connect()); |
|
73 |
|
74 iKeyStore = CUnifiedKeyStore::NewL(iFs); |
|
75 |
|
76 CActiveScheduler::Add(this); |
|
77 } |
|
78 |
|
79 void CKeyToolEngine::RunL() |
|
80 { |
|
81 if (iStatus.Int() != KErrNone) |
|
82 { |
|
83 User::Leave(iStatus.Int()); |
|
84 } |
|
85 |
|
86 switch (iState) |
|
87 { |
|
88 case EInitialise: |
|
89 { |
|
90 iInitialized = ETrue; |
|
91 iHandler->DoCommandL(*iKeyStore, iParam); |
|
92 iState = EDone; |
|
93 } |
|
94 break; |
|
95 case EDone: |
|
96 { |
|
97 } |
|
98 break; |
|
99 default: |
|
100 { |
|
101 User::Panic(_L("Keytool Engine - Illegal state"), 0); |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 TInt CKeyToolEngine::RunError(TInt aError) |
|
107 { |
|
108 CActiveScheduler::Stop(); |
|
109 |
|
110 switch (iCurrentAction) |
|
111 { |
|
112 case EList: |
|
113 { |
|
114 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_LIST, aError)); |
|
115 } |
|
116 break; |
|
117 case EImport: |
|
118 { |
|
119 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_IMPORT, aError)); |
|
120 } |
|
121 break; |
|
122 default: |
|
123 { |
|
124 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_UNKNOWN, aError)); |
|
125 } |
|
126 } |
|
127 return KErrNone; |
|
128 } |
|
129 |
|
130 |
|
131 void CKeyToolEngine::DoCancel() |
|
132 { |
|
133 CActiveScheduler::Stop(); |
|
134 } |
|
135 |
|
136 |
|
137 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\// |
|
138 //\\//\\//\\//\\// Business methods //\\//\\//\\//\\// |
|
139 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\// |
|
140 |
|
141 void CKeyToolEngine::InitializeL() |
|
142 { |
|
143 if (!iInitialized) |
|
144 { |
|
145 iState = EInitialise; |
|
146 iKeyStore->Initialize(iStatus); |
|
147 SetActive(); |
|
148 } |
|
149 else |
|
150 { |
|
151 iHandler->DoCommandL(*iKeyStore, iParam); |
|
152 iState = EDone; |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 void CKeyToolEngine::ListL(CKeyToolParameters* aParam) |
|
158 { |
|
159 Cancel(); |
|
160 iParam = aParam; |
|
161 iCurrentAction = EList; |
|
162 delete iHandler; |
|
163 iHandler = NULL; |
|
164 iHandler = CKeytoolList::NewL(iController); |
|
165 InitializeL(); |
|
166 } |
|
167 |
|
168 void CKeyToolEngine::ImportL(CKeyToolParameters* aParam) |
|
169 { |
|
170 Cancel(); |
|
171 |
|
172 if (!aParam->iDefault) |
|
173 { |
|
174 iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE); |
|
175 User::Leave(KErrArgument); |
|
176 } |
|
177 |
|
178 iParam = aParam; |
|
179 iCurrentAction = EImport; |
|
180 delete iHandler; // Reentrant call |
|
181 iHandler = NULL; |
|
182 iHandler = CKeytoolImport::NewL(iController); |
|
183 InitializeL(); |
|
184 } |
|
185 |
|
186 void CKeyToolEngine::RemoveL(CKeyToolParameters* aParam) |
|
187 { |
|
188 Cancel(); |
|
189 |
|
190 if (!aParam->iDefault) |
|
191 { |
|
192 iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE); |
|
193 User::Leave(KErrArgument); |
|
194 } |
|
195 |
|
196 iParam = aParam; |
|
197 iCurrentAction = ERemove; |
|
198 iHandler = CKeytoolRemove::NewL(iController); |
|
199 InitializeL(); |
|
200 } |
|
201 |
|
202 |
|
203 void CKeyToolEngine::DisplayUsageL(CKeyToolParameters* aParam) |
|
204 { |
|
205 iHandler = CKeytoolUsage::NewL(iController); |
|
206 iHandler->DoCommandL(*iKeyStore, aParam); |
|
207 } |
|
208 |
|
209 void CKeyToolEngine::ListStoresL(CKeyToolParameters* aParam) |
|
210 { |
|
211 Cancel(); |
|
212 iParam = aParam; |
|
213 iCurrentAction = EList; |
|
214 iHandler = CKeyToolListStores::NewL(iController); |
|
215 InitializeL(); |
|
216 } |
|
217 |
|
218 void CKeyToolEngine::SetPolicyL(CKeyToolParameters* aParam) |
|
219 { |
|
220 Cancel(); |
|
221 |
|
222 if (!aParam->iDefault) |
|
223 { |
|
224 iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SUSERFAIL); |
|
225 User::Leave(KErrArgument); |
|
226 } |
|
227 |
|
228 iParam = aParam; |
|
229 iCurrentAction = ESetPolicy; |
|
230 iHandler = CKeytoolSetPolicy::NewL(iController); |
|
231 InitializeL(); |
|
232 } |