os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_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 "certtool_controller.h"
    24 
    25 
    26 _LIT(KCertToolResources,"Z:\\Resource\\Apps\\keytool.RSC");
    27 
    28 CCertToolController::CCertToolController(MKeyToolView& aView) : CController(aView)
    29 	{
    30 	}
    31 
    32 CCertToolController::~CCertToolController()
    33 	{	
    34 	delete iEngine; 
    35 	}
    36 
    37 /*static*/ CCertToolController*  CCertToolController::NewLC(MKeyToolView& aView)
    38 	{
    39 	CCertToolController* self = new (ELeave) CCertToolController(aView);
    40 	CleanupStack::PushL(self);
    41 	self->ConstructL();
    42 	return self; 
    43 	}
    44 
    45 void CCertToolController::ConstructL()
    46 	{
    47 	User::LeaveIfError(iFsSession.Connect()); // Connect session
    48  
    49 	TFileName fileName(KCertToolResources);
    50 	 
    51 	// open file, leave if error
    52 	iResourceFile.OpenL(iFsSession, fileName);
    53 
    54 	iResourceFile.ConfirmSignatureL();
    55 	
    56 	iEngine = CCertToolEngine::NewL(this);
    57 	}
    58 
    59 void CCertToolController::HandleCommandL(TInt aCommand, CKeyToolParameters* aParam)
    60 	{
    61 	TInt certstoreIndex = -1;
    62 	switch (aCommand) 
    63 		{
    64 		case KUsageCommand:
    65 			{
    66 			iEngine->DisplayUsageL(aParam);
    67 			}
    68 			break;
    69 		case KListCommand:
    70 			{
    71 			iEngine->ListL(aParam);			
    72 			CActiveScheduler::Start();	
    73 			}
    74 			break;
    75 		case KImportCommand:
    76 			{
    77 			if (aParam->iPrivate)
    78 				{
    79 				CKeyToolParameters* parm = CKeyToolParameters::NewLC();
    80 				parm->iDefault = aParam->iPrivate->AllocL();
    81 				if(aParam->iLabel)
    82 					{
    83 					parm->iLabel = aParam->iLabel->AllocL();											
    84 					}
    85 				else
    86 					{
    87 					parm->iLabel = aParam->iDefault->AllocL();					
    88 					}
    89 				iEngine->ImportPrivateL(parm);
    90 				CActiveScheduler::Start();
    91 				delete parm->iDefault;
    92  				parm->iDefault = NULL;
    93  				if(aParam->iLabel)
    94  					{
    95  					parm->iDefault = aParam->iLabel->AllocL();						
    96  					}
    97  				else
    98  					{
    99 					parm->iDefault = aParam->iDefault->AllocL();					
   100  					}
   101 				parm->iPolicy = CKeyToolParameters::ESetManagerPolicy;
   102 				iEngine->SetManagerPolicyL(parm);
   103 				CActiveScheduler::Start();
   104 				CleanupStack::PopAndDestroy(parm);								
   105 				}			
   106 			iEngine->ImportL(aParam);
   107 			CActiveScheduler::Start();
   108 			if (aParam->iLabel)
   109 				{
   110 				delete aParam->iDefault;
   111 				aParam->iDefault = NULL;
   112 				aParam->iDefault = aParam->iLabel->AllocL();
   113 				}
   114 			iEngine->ListL(aParam);			
   115 			CActiveScheduler::Start();				
   116 			}
   117 			break;	
   118 		case KRemoveCommand:
   119 			{
   120 			if (aParam->iRemoveKey)
   121 				{
   122 				CKeyToolParameters* parm = CKeyToolParameters::NewLC();
   123 				parm->iDefault = aParam->iDefault->AllocL();	
   124 				iEngine->RemovePrivateL(parm);
   125 				CActiveScheduler::Start();
   126 				CleanupStack::PopAndDestroy(parm);
   127 				}
   128 			iEngine->RemoveL(aParam);
   129 			CActiveScheduler::Start();				
   130 			}	
   131 			break;
   132 		case KSetAppsCommand:
   133 			{
   134 			certstoreIndex = aParam->iCertstoreIndex;
   135 			iEngine->SetAppsL(aParam);
   136 			if (aParam->iLabel)
   137 				{
   138 				delete aParam->iDefault;
   139 				aParam->iDefault = NULL;
   140 				aParam->iDefault = aParam->iLabel->AllocL();
   141 				}
   142 			CActiveScheduler::Start();
   143 			aParam->iCertstoreIndex = certstoreIndex;
   144 			iEngine->ListL(aParam);			
   145 			CActiveScheduler::Start();							
   146 			}	
   147 			break;
   148 		case KListStoresCommand:
   149 			{
   150 			iEngine->ListStoresL(aParam);
   151 			CActiveScheduler::Start();				
   152 			}
   153 			break;
   154 		case KAddAppsCommand:
   155 			{
   156 			certstoreIndex = aParam->iCertstoreIndex;
   157 			iEngine->AddAppsL(aParam);
   158 			if (aParam->iLabel)
   159 				{
   160 				delete aParam->iDefault;
   161 				aParam->iDefault = NULL;
   162 				aParam->iDefault = aParam->iLabel->AllocL();
   163 				}
   164 			CActiveScheduler::Start();
   165 			aParam->iCertstoreIndex = certstoreIndex;	
   166 			iEngine->ListL(aParam);			
   167 			CActiveScheduler::Start();						
   168 			}	
   169 			break;				
   170 		case KRemoveAppsCommand:
   171 			{
   172 			certstoreIndex = aParam->iCertstoreIndex;
   173 			iEngine->RemoveAppsL(aParam);
   174 			CActiveScheduler::Start();	
   175 			aParam->iCertstoreIndex = certstoreIndex;
   176 			iEngine->ListL(aParam);			
   177 			CActiveScheduler::Start();						
   178 			}	
   179 			break;
   180 		default:
   181 			{
   182 			DisplayLocalisedMsgL(R_CERTTOOL_ERR_COMMAND);
   183 			User::Leave(KErrNotSupported);			
   184 			}
   185 		}
   186 	}