os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_controller.cpp
First public contribution.
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.
23 #include "certtool_controller.h"
26 _LIT(KCertToolResources,"Z:\\Resource\\Apps\\keytool.RSC");
28 CCertToolController::CCertToolController(MKeyToolView& aView) : CController(aView)
32 CCertToolController::~CCertToolController()
37 /*static*/ CCertToolController* CCertToolController::NewLC(MKeyToolView& aView)
39 CCertToolController* self = new (ELeave) CCertToolController(aView);
40 CleanupStack::PushL(self);
45 void CCertToolController::ConstructL()
47 User::LeaveIfError(iFsSession.Connect()); // Connect session
49 TFileName fileName(KCertToolResources);
51 // open file, leave if error
52 iResourceFile.OpenL(iFsSession, fileName);
54 iResourceFile.ConfirmSignatureL();
56 iEngine = CCertToolEngine::NewL(this);
59 void CCertToolController::HandleCommandL(TInt aCommand, CKeyToolParameters* aParam)
61 TInt certstoreIndex = -1;
66 iEngine->DisplayUsageL(aParam);
71 iEngine->ListL(aParam);
72 CActiveScheduler::Start();
79 CKeyToolParameters* parm = CKeyToolParameters::NewLC();
80 parm->iDefault = aParam->iPrivate->AllocL();
83 parm->iLabel = aParam->iLabel->AllocL();
87 parm->iLabel = aParam->iDefault->AllocL();
89 iEngine->ImportPrivateL(parm);
90 CActiveScheduler::Start();
91 delete parm->iDefault;
92 parm->iDefault = NULL;
95 parm->iDefault = aParam->iLabel->AllocL();
99 parm->iDefault = aParam->iDefault->AllocL();
101 parm->iPolicy = CKeyToolParameters::ESetManagerPolicy;
102 iEngine->SetManagerPolicyL(parm);
103 CActiveScheduler::Start();
104 CleanupStack::PopAndDestroy(parm);
106 iEngine->ImportL(aParam);
107 CActiveScheduler::Start();
110 delete aParam->iDefault;
111 aParam->iDefault = NULL;
112 aParam->iDefault = aParam->iLabel->AllocL();
114 iEngine->ListL(aParam);
115 CActiveScheduler::Start();
120 if (aParam->iRemoveKey)
122 CKeyToolParameters* parm = CKeyToolParameters::NewLC();
123 parm->iDefault = aParam->iDefault->AllocL();
124 iEngine->RemovePrivateL(parm);
125 CActiveScheduler::Start();
126 CleanupStack::PopAndDestroy(parm);
128 iEngine->RemoveL(aParam);
129 CActiveScheduler::Start();
132 case KSetAppsCommand:
134 certstoreIndex = aParam->iCertstoreIndex;
135 iEngine->SetAppsL(aParam);
138 delete aParam->iDefault;
139 aParam->iDefault = NULL;
140 aParam->iDefault = aParam->iLabel->AllocL();
142 CActiveScheduler::Start();
143 aParam->iCertstoreIndex = certstoreIndex;
144 iEngine->ListL(aParam);
145 CActiveScheduler::Start();
148 case KListStoresCommand:
150 iEngine->ListStoresL(aParam);
151 CActiveScheduler::Start();
154 case KAddAppsCommand:
156 certstoreIndex = aParam->iCertstoreIndex;
157 iEngine->AddAppsL(aParam);
160 delete aParam->iDefault;
161 aParam->iDefault = NULL;
162 aParam->iDefault = aParam->iLabel->AllocL();
164 CActiveScheduler::Start();
165 aParam->iCertstoreIndex = certstoreIndex;
166 iEngine->ListL(aParam);
167 CActiveScheduler::Start();
170 case KRemoveAppsCommand:
172 certstoreIndex = aParam->iCertstoreIndex;
173 iEngine->RemoveAppsL(aParam);
174 CActiveScheduler::Start();
175 aParam->iCertstoreIndex = certstoreIndex;
176 iEngine->ListL(aParam);
177 CActiveScheduler::Start();
182 DisplayLocalisedMsgL(R_CERTTOOL_ERR_COMMAND);
183 User::Leave(KErrNotSupported);