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