os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_controller.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_controller.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,186 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <barsc.h>
1.23 +#include <barsread.h>
1.24 +#include <utf.h>
1.25 +
1.26 +#include "certtool_controller.h"
1.27 +
1.28 +
1.29 +_LIT(KCertToolResources,"Z:\\Resource\\Apps\\keytool.RSC");
1.30 +
1.31 +CCertToolController::CCertToolController(MKeyToolView& aView) : CController(aView)
1.32 + {
1.33 + }
1.34 +
1.35 +CCertToolController::~CCertToolController()
1.36 + {
1.37 + delete iEngine;
1.38 + }
1.39 +
1.40 +/*static*/ CCertToolController* CCertToolController::NewLC(MKeyToolView& aView)
1.41 + {
1.42 + CCertToolController* self = new (ELeave) CCertToolController(aView);
1.43 + CleanupStack::PushL(self);
1.44 + self->ConstructL();
1.45 + return self;
1.46 + }
1.47 +
1.48 +void CCertToolController::ConstructL()
1.49 + {
1.50 + User::LeaveIfError(iFsSession.Connect()); // Connect session
1.51 +
1.52 + TFileName fileName(KCertToolResources);
1.53 +
1.54 + // open file, leave if error
1.55 + iResourceFile.OpenL(iFsSession, fileName);
1.56 +
1.57 + iResourceFile.ConfirmSignatureL();
1.58 +
1.59 + iEngine = CCertToolEngine::NewL(this);
1.60 + }
1.61 +
1.62 +void CCertToolController::HandleCommandL(TInt aCommand, CKeyToolParameters* aParam)
1.63 + {
1.64 + TInt certstoreIndex = -1;
1.65 + switch (aCommand)
1.66 + {
1.67 + case KUsageCommand:
1.68 + {
1.69 + iEngine->DisplayUsageL(aParam);
1.70 + }
1.71 + break;
1.72 + case KListCommand:
1.73 + {
1.74 + iEngine->ListL(aParam);
1.75 + CActiveScheduler::Start();
1.76 + }
1.77 + break;
1.78 + case KImportCommand:
1.79 + {
1.80 + if (aParam->iPrivate)
1.81 + {
1.82 + CKeyToolParameters* parm = CKeyToolParameters::NewLC();
1.83 + parm->iDefault = aParam->iPrivate->AllocL();
1.84 + if(aParam->iLabel)
1.85 + {
1.86 + parm->iLabel = aParam->iLabel->AllocL();
1.87 + }
1.88 + else
1.89 + {
1.90 + parm->iLabel = aParam->iDefault->AllocL();
1.91 + }
1.92 + iEngine->ImportPrivateL(parm);
1.93 + CActiveScheduler::Start();
1.94 + delete parm->iDefault;
1.95 + parm->iDefault = NULL;
1.96 + if(aParam->iLabel)
1.97 + {
1.98 + parm->iDefault = aParam->iLabel->AllocL();
1.99 + }
1.100 + else
1.101 + {
1.102 + parm->iDefault = aParam->iDefault->AllocL();
1.103 + }
1.104 + parm->iPolicy = CKeyToolParameters::ESetManagerPolicy;
1.105 + iEngine->SetManagerPolicyL(parm);
1.106 + CActiveScheduler::Start();
1.107 + CleanupStack::PopAndDestroy(parm);
1.108 + }
1.109 + iEngine->ImportL(aParam);
1.110 + CActiveScheduler::Start();
1.111 + if (aParam->iLabel)
1.112 + {
1.113 + delete aParam->iDefault;
1.114 + aParam->iDefault = NULL;
1.115 + aParam->iDefault = aParam->iLabel->AllocL();
1.116 + }
1.117 + iEngine->ListL(aParam);
1.118 + CActiveScheduler::Start();
1.119 + }
1.120 + break;
1.121 + case KRemoveCommand:
1.122 + {
1.123 + if (aParam->iRemoveKey)
1.124 + {
1.125 + CKeyToolParameters* parm = CKeyToolParameters::NewLC();
1.126 + parm->iDefault = aParam->iDefault->AllocL();
1.127 + iEngine->RemovePrivateL(parm);
1.128 + CActiveScheduler::Start();
1.129 + CleanupStack::PopAndDestroy(parm);
1.130 + }
1.131 + iEngine->RemoveL(aParam);
1.132 + CActiveScheduler::Start();
1.133 + }
1.134 + break;
1.135 + case KSetAppsCommand:
1.136 + {
1.137 + certstoreIndex = aParam->iCertstoreIndex;
1.138 + iEngine->SetAppsL(aParam);
1.139 + if (aParam->iLabel)
1.140 + {
1.141 + delete aParam->iDefault;
1.142 + aParam->iDefault = NULL;
1.143 + aParam->iDefault = aParam->iLabel->AllocL();
1.144 + }
1.145 + CActiveScheduler::Start();
1.146 + aParam->iCertstoreIndex = certstoreIndex;
1.147 + iEngine->ListL(aParam);
1.148 + CActiveScheduler::Start();
1.149 + }
1.150 + break;
1.151 + case KListStoresCommand:
1.152 + {
1.153 + iEngine->ListStoresL(aParam);
1.154 + CActiveScheduler::Start();
1.155 + }
1.156 + break;
1.157 + case KAddAppsCommand:
1.158 + {
1.159 + certstoreIndex = aParam->iCertstoreIndex;
1.160 + iEngine->AddAppsL(aParam);
1.161 + if (aParam->iLabel)
1.162 + {
1.163 + delete aParam->iDefault;
1.164 + aParam->iDefault = NULL;
1.165 + aParam->iDefault = aParam->iLabel->AllocL();
1.166 + }
1.167 + CActiveScheduler::Start();
1.168 + aParam->iCertstoreIndex = certstoreIndex;
1.169 + iEngine->ListL(aParam);
1.170 + CActiveScheduler::Start();
1.171 + }
1.172 + break;
1.173 + case KRemoveAppsCommand:
1.174 + {
1.175 + certstoreIndex = aParam->iCertstoreIndex;
1.176 + iEngine->RemoveAppsL(aParam);
1.177 + CActiveScheduler::Start();
1.178 + aParam->iCertstoreIndex = certstoreIndex;
1.179 + iEngine->ListL(aParam);
1.180 + CActiveScheduler::Start();
1.181 + }
1.182 + break;
1.183 + default:
1.184 + {
1.185 + DisplayLocalisedMsgL(R_CERTTOOL_ERR_COMMAND);
1.186 + User::Leave(KErrNotSupported);
1.187 + }
1.188 + }
1.189 + }