os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_engine.cpp
Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "certtool_engine.h"
20 #include "certtool_controller.h"
21 #include "keytool_controller.h"
24 /*static*/ CCertToolEngine* CCertToolEngine::NewLC(CCertToolController* aController)
26 CCertToolEngine* self = new (ELeave) CCertToolEngine(aController);
27 CleanupStack::PushL(self);
32 /*static*/ CCertToolEngine* CCertToolEngine::NewL(CCertToolController* aController)
34 CCertToolEngine* self = CCertToolEngine::NewLC(aController);
35 CleanupStack::Pop(self);
39 CCertToolEngine::CCertToolEngine(CCertToolController* aController) : CActive(EPriorityNormal)
41 iCurrentAction = EIdle;
42 iController = aController;
45 CCertToolEngine::~CCertToolEngine()
50 delete iKeyController;
59 void CCertToolEngine::ConstructL()
61 iScheduler = new(ELeave) CActiveScheduler;
62 CActiveScheduler::Install(iScheduler);
64 User::LeaveIfError(iFs.Connect());
66 iCertStore = CUnifiedCertStore::NewL(iFs, ETrue);
68 User::LeaveIfError(iFsKeyStore.Connect());
70 iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
72 CActiveScheduler::Add(this);
75 void CCertToolEngine::RunL()
77 if (iStatus.Int() != KErrNone)
79 User::Leave(iStatus.Int());
84 case EInitialiseKeyStore:
86 iKeyHandler->DoCommandL(*iKeyStore, iParam);
92 iHandler->DoCommandL(*iCertStore, iParam);
102 User::Panic(_L("Certtool Engine - Illegal state"), 0);
107 TInt CCertToolEngine::RunError(TInt aError)
109 CActiveScheduler::Stop();
111 switch (iCurrentAction)
115 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_LIST, aError));
120 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_IMPORT, aError));
125 TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_UNKNOWN, aError));
132 void CCertToolEngine::DoCancel()
134 //CActiveScheduler::Stop();
138 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
139 //\\//\\//\\//\\// Business methods //\\//\\//\\//\\//
140 //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
142 void CCertToolEngine::ListL(CKeyToolParameters* aParam)
146 iCurrentAction = EList;
149 iHandler = CCertToolList::NewL(iController);
150 iState = EInitialise;
151 iCertStore->Initialize(iStatus);
155 void CCertToolEngine::ListStoresL(CKeyToolParameters* aParam)
159 iCurrentAction = EList;
160 iHandler = CCertToolListStores::NewL(iController);
161 iState = EInitialise;
162 iCertStore->Initialize(iStatus);
166 void CCertToolEngine::ImportPrivateL(CKeyToolParameters* aParam)
170 iKeyController = CKeyToolController::NewL(iController->GetView());
171 if (!aParam->iDefault)
173 iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE);
174 User::Leave(KErrArgument);
178 iCurrentAction = EImport;
179 iKeyHandler = CKeytoolImport::NewL(iKeyController);
180 iState = EInitialiseKeyStore;
181 iKeyStore->Initialize(iStatus);
185 void CCertToolEngine::SetManagerPolicyL(CKeyToolParameters* aParam)
188 delete iKeyController;
189 iKeyController = NULL;
190 iKeyController = CKeyToolController::NewL(iController->GetView());
191 if (!aParam->iDefault)
193 iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);
194 User::Leave(KErrArgument);
198 iCurrentAction = ESetPolicy;
201 iKeyHandler = CKeytoolSetPolicy::NewL(iKeyController);
202 iState = EInitialiseKeyStore;
205 iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
206 iKeyStore->Initialize(iStatus);
210 void CCertToolEngine::RemovePrivateL(CKeyToolParameters* aParam)
214 iKeyController = CKeyToolController::NewL(iController->GetView());
215 if (!aParam->iDefault)
217 iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);
218 User::Leave(KErrArgument);
222 iCurrentAction = ERemove;
223 iKeyHandler = CKeytoolRemove::NewL(iKeyController);
224 iState = EInitialiseKeyStore;
225 User::LeaveIfError(iFsKeyStore.Connect());
228 iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
229 iKeyStore->Initialize(iStatus);
233 void CCertToolEngine::ImportL(CKeyToolParameters* aParam)
238 delete iKeyController;
239 iKeyController = NULL;
241 if (!aParam->iDefault)
243 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_CERTFILE);
244 User::Leave(KErrArgument);
248 iCurrentAction = EImport;
249 iHandler = CCertToolAdd::NewL(iController);
250 iState = EInitialise;
251 iCertStore->Initialize(iStatus);
255 void CCertToolEngine::RemoveL(CKeyToolParameters* aParam)
260 delete iKeyController;
261 iKeyController = NULL;
263 if (!aParam->iDefault)
265 iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE);
266 User::Leave(KErrArgument);
270 iCurrentAction = ERemove;
271 iHandler = CCertToolRemove::NewL(iController);
272 iState = EInitialise;
273 iCertStore->Initialize(iStatus);
277 void CCertToolEngine::SetupUidCommandL(CKeyToolParameters* aParam)
280 if (!aParam->iDefault && !aParam->iLabel)
282 iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOCERT);
283 User::Leave(KErrArgument);
286 if (aParam->iUIDs.Count()==0)
288 iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOAPPS);
289 User::Leave(KErrArgument);
293 iCurrentAction = EAddApps;
294 iState = EInitialise;
295 iCertStore->Initialize(iStatus);
299 void CCertToolEngine::SetAppsL(CKeyToolParameters* aParam)
301 iCurrentAction = ESetApps;
302 iHandler = CCertToolSetApps::NewL(iController);
303 SetupUidCommandL(aParam);
307 void CCertToolEngine::RemoveAppsL(CKeyToolParameters* aParam)
309 iHandler = CCertToolRemoveApps::NewL(iController);
310 SetupUidCommandL(aParam);
314 void CCertToolEngine::AddAppsL(CKeyToolParameters* aParam)
316 iHandler = CCertToolAddApps::NewL(iController);
317 SetupUidCommandL(aParam);
322 void CCertToolEngine::DisplayUsageL(CKeyToolParameters* aParam)
324 iHandler = CCertToolUsage::NewL(iController);
325 iHandler->DoCommandL(*iCertStore, aParam);