os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_controller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <barsc.h>
sl@0
    20
#include <barsread.h>
sl@0
    21
#include <utf.h>
sl@0
    22
sl@0
    23
#include "keytool_controller.h"
sl@0
    24
#include "keytool_view.h"
sl@0
    25
#include "keytool_commands.h"
sl@0
    26
sl@0
    27
#include <keytool.rsg>
sl@0
    28
sl@0
    29
_LIT(KKeyToolResources,"Z:\\Resource\\Apps\\keytool.RSC");
sl@0
    30
sl@0
    31
CKeyToolController::CKeyToolController(MKeyToolView& aView) : CController(aView)
sl@0
    32
	{
sl@0
    33
	}
sl@0
    34
sl@0
    35
CKeyToolController::~CKeyToolController()
sl@0
    36
	{	
sl@0
    37
	delete iEngine; 
sl@0
    38
	//iFsSession.Close();
sl@0
    39
	//iResourceFile.Close();
sl@0
    40
	}
sl@0
    41
sl@0
    42
/*static*/ CKeyToolController*  CKeyToolController::NewLC(MKeyToolView& aView)
sl@0
    43
	{
sl@0
    44
	CKeyToolController* self = new (ELeave) CKeyToolController(aView);
sl@0
    45
	CleanupStack::PushL(self);
sl@0
    46
	self->ConstructL();
sl@0
    47
	return self; 
sl@0
    48
	}
sl@0
    49
sl@0
    50
/*static*/ CKeyToolController*  CKeyToolController::NewL(MKeyToolView& aView)
sl@0
    51
	{
sl@0
    52
	CKeyToolController* self = CKeyToolController::NewLC(aView);
sl@0
    53
	CleanupStack::Pop(self);
sl@0
    54
	return self; 
sl@0
    55
	}
sl@0
    56
sl@0
    57
void CKeyToolController::ConstructL()
sl@0
    58
	{
sl@0
    59
	User::LeaveIfError(iFsSession.Connect()); // Connect session
sl@0
    60
 
sl@0
    61
	TFileName fileName(KKeyToolResources);
sl@0
    62
	 
sl@0
    63
	// open file, leave if error
sl@0
    64
	iResourceFile.OpenL(iFsSession, fileName);
sl@0
    65
sl@0
    66
	iResourceFile.ConfirmSignatureL();
sl@0
    67
sl@0
    68
	iEngine = CKeyToolEngine::NewL(this);
sl@0
    69
	}
sl@0
    70
sl@0
    71
void CKeyToolController::HandleCommandL(TInt aCommand, CKeyToolParameters* aParam)
sl@0
    72
	{
sl@0
    73
	switch (aCommand) 
sl@0
    74
		{
sl@0
    75
		case KUsageCommand:
sl@0
    76
			{
sl@0
    77
			//iView.DisplayUsage();
sl@0
    78
			iEngine->DisplayUsageL(aParam);
sl@0
    79
			}
sl@0
    80
			break;
sl@0
    81
		case KListCommand:
sl@0
    82
			{
sl@0
    83
			iEngine->ListL(aParam);			
sl@0
    84
			CActiveScheduler::Start();	
sl@0
    85
			}
sl@0
    86
			break;
sl@0
    87
		case KImportCommand:
sl@0
    88
			{
sl@0
    89
			// wildcard support
sl@0
    90
			if (aParam->iDefault)
sl@0
    91
				{
sl@0
    92
				CDir* dirList;
sl@0
    93
				RFs fs;
sl@0
    94
				CleanupClosePushL(fs);
sl@0
    95
				User::LeaveIfError(fs.Connect());
sl@0
    96
				User::LeaveIfError(fs.GetDir(*aParam->iDefault, KEntryAttNormal, ESortByName, dirList));
sl@0
    97
				CleanupStack::PushL(dirList);
sl@0
    98
				if (dirList->Count() == 0)
sl@0
    99
					{
sl@0
   100
					DisplayLocalisedMsgL(R_KEYTOOL_ERR_OPENFAIL);				
sl@0
   101
					User::Leave(KErrNotFound);					
sl@0
   102
					}
sl@0
   103
				else
sl@0
   104
					{
sl@0
   105
					TParse fp;
sl@0
   106
					fs.Parse(*aParam->iDefault,fp);	
sl@0
   107
					TPtrC path = fp.DriveAndPath();
sl@0
   108
					
sl@0
   109
					// It's done its job let's take it out of the pic!
sl@0
   110
					//delete aParam->iDefault;
sl@0
   111
					
sl@0
   112
					for (TInt k = 0; k < dirList->Count(); k++)
sl@0
   113
						{
sl@0
   114
						HBufC* fullPath = HBufC::NewMaxL(path.Length() + KMaxFileName);
sl@0
   115
						TPtr fullPathPtr(fullPath->Des());
sl@0
   116
						fullPathPtr.SetLength(0);
sl@0
   117
						fullPathPtr.Append(path);
sl@0
   118
				
sl@0
   119
						const TEntry& entry = (*dirList)[k];
sl@0
   120
						fullPathPtr.Append(entry.iName);						
sl@0
   121
						delete aParam->iDefault;
sl@0
   122
						aParam->iDefault = NULL;
sl@0
   123
sl@0
   124
						aParam->iDefault = fullPath;
sl@0
   125
						if (dirList->Count() > 1)
sl@0
   126
							{
sl@0
   127
							delete aParam->iLabel;
sl@0
   128
							aParam->iLabel = NULL;
sl@0
   129
							aParam->iLabel = entry.iName.AllocL();
sl@0
   130
							}
sl@0
   131
						
sl@0
   132
						iEngine->ImportL(aParam);
sl@0
   133
						CActiveScheduler::Start();
sl@0
   134
						}
sl@0
   135
					}
sl@0
   136
				CleanupStack::PopAndDestroy(dirList);
sl@0
   137
				CleanupStack::PopAndDestroy(&fs);
sl@0
   138
				}
sl@0
   139
			else
sl@0
   140
				{
sl@0
   141
				DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE);
sl@0
   142
				User::Leave(KErrArgument);				
sl@0
   143
				}
sl@0
   144
			}	
sl@0
   145
			break;	
sl@0
   146
		case KRemoveCommand:
sl@0
   147
			{
sl@0
   148
			iEngine->RemoveL(aParam);
sl@0
   149
			CActiveScheduler::Start();							
sl@0
   150
			}	
sl@0
   151
			break;
sl@0
   152
		case KListStoresCommand:
sl@0
   153
			{
sl@0
   154
			iEngine->ListStoresL(aParam);
sl@0
   155
			CActiveScheduler::Start();				
sl@0
   156
			}	
sl@0
   157
			break;
sl@0
   158
		case KSetUserCommand:
sl@0
   159
		case KSetManagerCommand:
sl@0
   160
		case KSetAllUsersCommand:
sl@0
   161
		case KRemoveUserCommand:
sl@0
   162
			{
sl@0
   163
			iEngine->SetPolicyL(aParam);
sl@0
   164
			CActiveScheduler::Start();
sl@0
   165
			iEngine->ListL(aParam);			
sl@0
   166
			CActiveScheduler::Start();
sl@0
   167
			}
sl@0
   168
			break;		
sl@0
   169
			
sl@0
   170
#ifdef KEYTOOL
sl@0
   171
		case KMigrateStore:
sl@0
   172
			{
sl@0
   173
			iEngine->MigrateStoreL(aParam);
sl@0
   174
			CActiveScheduler::Start();
sl@0
   175
			break;
sl@0
   176
			}
sl@0
   177
			
sl@0
   178
#endif // KEYTOOL
sl@0
   179
			
sl@0
   180
		default:
sl@0
   181
			{
sl@0
   182
			DisplayLocalisedMsgL(R_KEYTOOL_ERR_COMMAND);
sl@0
   183
			User::Leave(KErrNotSupported);			
sl@0
   184
			}
sl@0
   185
		}
sl@0
   186
	}