os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_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 "keytool_controller.h"
24 #include "keytool_view.h"
25 #include "keytool_commands.h"
27 #include <keytool.rsg>
29 _LIT(KKeyToolResources,"Z:\\Resource\\Apps\\keytool.RSC");
31 CKeyToolController::CKeyToolController(MKeyToolView& aView) : CController(aView)
35 CKeyToolController::~CKeyToolController()
39 //iResourceFile.Close();
42 /*static*/ CKeyToolController* CKeyToolController::NewLC(MKeyToolView& aView)
44 CKeyToolController* self = new (ELeave) CKeyToolController(aView);
45 CleanupStack::PushL(self);
50 /*static*/ CKeyToolController* CKeyToolController::NewL(MKeyToolView& aView)
52 CKeyToolController* self = CKeyToolController::NewLC(aView);
53 CleanupStack::Pop(self);
57 void CKeyToolController::ConstructL()
59 User::LeaveIfError(iFsSession.Connect()); // Connect session
61 TFileName fileName(KKeyToolResources);
63 // open file, leave if error
64 iResourceFile.OpenL(iFsSession, fileName);
66 iResourceFile.ConfirmSignatureL();
68 iEngine = CKeyToolEngine::NewL(this);
71 void CKeyToolController::HandleCommandL(TInt aCommand, CKeyToolParameters* aParam)
77 //iView.DisplayUsage();
78 iEngine->DisplayUsageL(aParam);
83 iEngine->ListL(aParam);
84 CActiveScheduler::Start();
94 CleanupClosePushL(fs);
95 User::LeaveIfError(fs.Connect());
96 User::LeaveIfError(fs.GetDir(*aParam->iDefault, KEntryAttNormal, ESortByName, dirList));
97 CleanupStack::PushL(dirList);
98 if (dirList->Count() == 0)
100 DisplayLocalisedMsgL(R_KEYTOOL_ERR_OPENFAIL);
101 User::Leave(KErrNotFound);
106 fs.Parse(*aParam->iDefault,fp);
107 TPtrC path = fp.DriveAndPath();
109 // It's done its job let's take it out of the pic!
110 //delete aParam->iDefault;
112 for (TInt k = 0; k < dirList->Count(); k++)
114 HBufC* fullPath = HBufC::NewMaxL(path.Length() + KMaxFileName);
115 TPtr fullPathPtr(fullPath->Des());
116 fullPathPtr.SetLength(0);
117 fullPathPtr.Append(path);
119 const TEntry& entry = (*dirList)[k];
120 fullPathPtr.Append(entry.iName);
121 delete aParam->iDefault;
122 aParam->iDefault = NULL;
124 aParam->iDefault = fullPath;
125 if (dirList->Count() > 1)
127 delete aParam->iLabel;
128 aParam->iLabel = NULL;
129 aParam->iLabel = entry.iName.AllocL();
132 iEngine->ImportL(aParam);
133 CActiveScheduler::Start();
136 CleanupStack::PopAndDestroy(dirList);
137 CleanupStack::PopAndDestroy(&fs);
141 DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE);
142 User::Leave(KErrArgument);
148 iEngine->RemoveL(aParam);
149 CActiveScheduler::Start();
152 case KListStoresCommand:
154 iEngine->ListStoresL(aParam);
155 CActiveScheduler::Start();
158 case KSetUserCommand:
159 case KSetManagerCommand:
160 case KSetAllUsersCommand:
161 case KRemoveUserCommand:
163 iEngine->SetPolicyL(aParam);
164 CActiveScheduler::Start();
165 iEngine->ListL(aParam);
166 CActiveScheduler::Start();
173 iEngine->MigrateStoreL(aParam);
174 CActiveScheduler::Start();
182 DisplayLocalisedMsgL(R_KEYTOOL_ERR_COMMAND);
183 User::Leave(KErrNotSupported);