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 "certtool_engine.h" sl@0: #include "certtool_controller.h" sl@0: #include "keytool_controller.h" sl@0: sl@0: sl@0: /*static*/ CCertToolEngine* CCertToolEngine::NewLC(CCertToolController* aController) sl@0: { sl@0: CCertToolEngine* self = new (ELeave) CCertToolEngine(aController); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: /*static*/ CCertToolEngine* CCertToolEngine::NewL(CCertToolController* aController) sl@0: { sl@0: CCertToolEngine* self = CCertToolEngine::NewLC(aController); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CCertToolEngine::CCertToolEngine(CCertToolController* aController) : CActive(EPriorityNormal) sl@0: { sl@0: iCurrentAction = EIdle; sl@0: iController = aController; sl@0: } sl@0: sl@0: CCertToolEngine::~CCertToolEngine() sl@0: { sl@0: Cancel(); sl@0: delete iHandler; sl@0: delete iKeyHandler; sl@0: delete iKeyController; sl@0: sl@0: delete iKeyStore; sl@0: iFsKeyStore.Close(); sl@0: delete iCertStore; sl@0: iFs.Close(); sl@0: delete iScheduler; sl@0: } sl@0: sl@0: void CCertToolEngine::ConstructL() sl@0: { sl@0: iScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iScheduler); sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: sl@0: iCertStore = CUnifiedCertStore::NewL(iFs, ETrue); sl@0: sl@0: User::LeaveIfError(iFsKeyStore.Connect()); sl@0: sl@0: iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore); sl@0: sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CCertToolEngine::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 EInitialiseKeyStore: sl@0: { sl@0: iKeyHandler->DoCommandL(*iKeyStore, iParam); sl@0: iState = EDone; sl@0: } sl@0: break; sl@0: case EInitialise: sl@0: { sl@0: iHandler->DoCommandL(*iCertStore, 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("Certtool Engine - Illegal state"), 0); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TInt CCertToolEngine::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_CERTTOOL_ERR_LIST, aError)); sl@0: } sl@0: break; sl@0: case EImport: sl@0: { sl@0: TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_IMPORT, aError)); sl@0: } sl@0: break; sl@0: default: sl@0: { sl@0: TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_UNKNOWN, aError)); sl@0: } sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: void CCertToolEngine::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 CCertToolEngine::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 = CCertToolList::NewL(iController); sl@0: iState = EInitialise; sl@0: iCertStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::ListStoresL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: iParam = aParam; sl@0: iCurrentAction = EList; sl@0: iHandler = CCertToolListStores::NewL(iController); sl@0: iState = EInitialise; sl@0: iCertStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::ImportPrivateL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: sl@0: iKeyController = CKeyToolController::NewL(iController->GetView()); sl@0: if (!aParam->iDefault) sl@0: { sl@0: iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = EImport; sl@0: iKeyHandler = CKeytoolImport::NewL(iKeyController); sl@0: iState = EInitialiseKeyStore; sl@0: iKeyStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::SetManagerPolicyL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: delete iKeyController; sl@0: iKeyController = NULL; sl@0: iKeyController = CKeyToolController::NewL(iController->GetView()); sl@0: if (!aParam->iDefault) sl@0: { sl@0: iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = ESetPolicy; sl@0: delete iKeyHandler; sl@0: iKeyHandler = NULL; sl@0: iKeyHandler = CKeytoolSetPolicy::NewL(iKeyController); sl@0: iState = EInitialiseKeyStore; sl@0: delete iKeyStore; sl@0: iKeyStore = NULL; sl@0: iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore); sl@0: iKeyStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::RemovePrivateL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: sl@0: iKeyController = CKeyToolController::NewL(iController->GetView()); sl@0: if (!aParam->iDefault) sl@0: { sl@0: iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = ERemove; sl@0: iKeyHandler = CKeytoolRemove::NewL(iKeyController); sl@0: iState = EInitialiseKeyStore; sl@0: User::LeaveIfError(iFsKeyStore.Connect()); sl@0: delete iKeyStore; sl@0: iKeyStore = NULL; sl@0: iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore); sl@0: iKeyStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::ImportL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: delete iKeyHandler; sl@0: iKeyHandler = NULL; sl@0: delete iKeyController; sl@0: iKeyController = NULL; sl@0: sl@0: if (!aParam->iDefault) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_CERTFILE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = EImport; sl@0: iHandler = CCertToolAdd::NewL(iController); sl@0: iState = EInitialise; sl@0: iCertStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::RemoveL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: delete iKeyHandler; sl@0: iKeyHandler = NULL; sl@0: delete iKeyController; sl@0: iKeyController = NULL; sl@0: sl@0: if (!aParam->iDefault) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = ERemove; sl@0: iHandler = CCertToolRemove::NewL(iController); sl@0: iState = EInitialise; sl@0: iCertStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::SetupUidCommandL(CKeyToolParameters* aParam) sl@0: { sl@0: Cancel(); sl@0: if (!aParam->iDefault && !aParam->iLabel) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOCERT); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: if (aParam->iUIDs.Count()==0) sl@0: { sl@0: iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOAPPS); sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: iParam = aParam; sl@0: iCurrentAction = EAddApps; sl@0: iState = EInitialise; sl@0: iCertStore->Initialize(iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCertToolEngine::SetAppsL(CKeyToolParameters* aParam) sl@0: { sl@0: iCurrentAction = ESetApps; sl@0: iHandler = CCertToolSetApps::NewL(iController); sl@0: SetupUidCommandL(aParam); sl@0: } sl@0: sl@0: sl@0: void CCertToolEngine::RemoveAppsL(CKeyToolParameters* aParam) sl@0: { sl@0: iHandler = CCertToolRemoveApps::NewL(iController); sl@0: SetupUidCommandL(aParam); sl@0: } sl@0: sl@0: sl@0: void CCertToolEngine::AddAppsL(CKeyToolParameters* aParam) sl@0: { sl@0: iHandler = CCertToolAddApps::NewL(iController); sl@0: SetupUidCommandL(aParam); sl@0: } sl@0: sl@0: sl@0: sl@0: void CCertToolEngine::DisplayUsageL(CKeyToolParameters* aParam) sl@0: { sl@0: iHandler = CCertToolUsage::NewL(iController); sl@0: iHandler->DoCommandL(*iCertStore, aParam); sl@0: }