sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "keytool_engine.h" sl@0: #include "keytool_controller.h" sl@0: #include "keytool_commands.h" sl@0: sl@0: #include sl@0: sl@0: sl@0: /*static*/ CKeyToolEngine* CKeyToolEngine::NewLC(CKeyToolController* aController) sl@0: { sl@0: CKeyToolEngine* self = new (ELeave) CKeyToolEngine(aController); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: /* static */ CKeyToolEngine* CKeyToolEngine::NewL(CKeyToolController* aController) sl@0: { sl@0: CKeyToolEngine* self = CKeyToolEngine::NewLC(aController); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CKeyToolEngine::CKeyToolEngine(CKeyToolController* aController) : CActive(EPriorityNormal) sl@0: { sl@0: iCurrentAction = EIdle; sl@0: iController = aController; sl@0: iInitialized = EFalse; sl@0: } sl@0: sl@0: CKeyToolEngine::~CKeyToolEngine() sl@0: { sl@0: Cancel(); sl@0: delete iHandler; sl@0: delete iKeyStore; sl@0: iFs.Close(); sl@0: if (iActiveStarted) sl@0: { sl@0: delete iScheduler; sl@0: } sl@0: iInitialized = EFalse; sl@0: #ifdef KEYTOOL sl@0: delete iMigrateStoreHandler; sl@0: #endif // KEYTOOL sl@0: } sl@0: sl@0: void CKeyToolEngine::ConstructL() sl@0: { sl@0: iActiveStarted = EFalse; sl@0: iScheduler = CActiveScheduler::Current(); sl@0: if (!iScheduler) sl@0: { sl@0: iActiveStarted = ETrue; sl@0: iScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iScheduler); sl@0: } sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: sl@0: iKeyStore = CUnifiedKeyStore::NewL(iFs); sl@0: sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CKeyToolEngine::RunL() sl@0: { sl@0: if (iStatus.Int() != KErrNone) sl@0: { sl@0: User::Leave(iStatus.Int()); sl@0: } sl@0: sl@0: switch (iState) sl@0: { sl@0: case EInitialise: sl@0: { sl@0: iInitialized = ETrue; sl@0: iHandler->DoCommandL(*iKeyStore, iParam); sl@0: iState = EDone; sl@0: } sl@0: break; sl@0: case EDone: sl@0: { sl@0: } sl@0: break; sl@0: default: sl@0: { sl@0: User::Panic(_L("Keytool Engine - Illegal state"), 0); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TInt CKeyToolEngine::RunError(TInt aError) sl@0: { sl@0: CActiveScheduler::Stop(); sl@0: sl@0: switch (iCurrentAction) sl@0: { sl@0: case EList: sl@0: { sl@0: TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_LIST, aError)); sl@0: } sl@0: break; sl@0: case EImport: sl@0: { sl@0: TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_IMPORT, aError)); sl@0: } sl@0: break; sl@0: default: sl@0: { sl@0: TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_UNKNOWN, aError)); sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: void CKeyToolEngine::DoCancel() sl@0: { sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: sl@0: sl@0: //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\// sl@0: //\\//\\//\\//\\// Business methods //\\//\\//\\//\\// sl@0: //\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\// sl@0: sl@0: void CKeyToolEngine::InitializeL() sl@0: { sl@0: if (!iInitialized) sl@0: { sl@0: iState = EInitialise; sl@0: iKeyStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: else sl@0: { sl@0: iHandler->DoCommandL(*iKeyStore, iParam); sl@0: iState = EDone; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CKeyToolEngine::ListL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: iParam = aParam; sl@0: iCurrentAction = EList; sl@0: delete iHandler; sl@0: iHandler = NULL; sl@0: iHandler = CKeytoolList::NewL(iController); sl@0: InitializeL(); sl@0: } sl@0: sl@0: void CKeyToolEngine::ImportL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: sl@0: if (!aParam->iDefault) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = EImport; sl@0: delete iHandler; // Reentrant call sl@0: iHandler = NULL; sl@0: iHandler = CKeytoolImport::NewL(iController); sl@0: InitializeL(); sl@0: } sl@0: sl@0: void CKeyToolEngine::RemoveL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: sl@0: if (!aParam->iDefault) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = ERemove; sl@0: iHandler = CKeytoolRemove::NewL(iController); sl@0: InitializeL(); sl@0: } sl@0: sl@0: sl@0: void CKeyToolEngine::DisplayUsageL(CKeyToolParameters* aParam) sl@0: { sl@0: iHandler = CKeytoolUsage::NewL(iController); sl@0: iHandler->DoCommandL(*iKeyStore, aParam); sl@0: } sl@0: sl@0: void CKeyToolEngine::ListStoresL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: iParam = aParam; sl@0: iCurrentAction = EList; sl@0: iHandler = CKeyToolListStores::NewL(iController); sl@0: InitializeL(); sl@0: } sl@0: sl@0: void CKeyToolEngine::SetPolicyL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: sl@0: if (!aParam->iDefault) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SUSERFAIL); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = ESetPolicy; sl@0: iHandler = CKeytoolSetPolicy::NewL(iController); sl@0: InitializeL(); sl@0: } sl@0: sl@0: #ifdef KEYTOOL sl@0: sl@0: void CKeyToolEngine::MigrateStoreL(CKeyToolParameters* aParams) sl@0: { sl@0: iParam = aParams; sl@0: iMigrateStoreHandler = CKeytoolMigrateStore::NewL(aParams); sl@0: iMigrateStoreHandler->DoCommandL(); sl@0: } sl@0: sl@0: #endif // KEYTOOL