os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_remove.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "certtool_commands.h"
    20 #include "certtool_controller.h"
    21 
    22 /*static*/ CCertToolRemove* CCertToolRemove::NewLC(CCertToolController* aController)
    23 	{
    24 	CCertToolRemove* self = new (ELeave) CCertToolRemove(aController);
    25 	CleanupStack::PushL(self);
    26 	self->ConstructL();
    27 	return self;	
    28 	}
    29 	
    30 /*static*/ CCertToolRemove* CCertToolRemove::NewL(CCertToolController* aController)
    31 	{
    32 	CCertToolRemove* self = CCertToolRemove::NewLC(aController);
    33 	CleanupStack::Pop(self);
    34 	return self;	  
    35 	}
    36 	
    37 CCertToolRemove::CCertToolRemove(CCertToolController* aController) : CCertToolList(aController)
    38 	{
    39 	
    40 	}
    41 	
    42 CCertToolRemove::~CCertToolRemove()
    43 	{
    44 	Cancel();
    45 	}
    46 	
    47 void CCertToolRemove::RunL()
    48 	{
    49 	if (iStatus.Int() != KErrNone)
    50 		{
    51 		User::Leave(iStatus.Int());
    52 		}	
    53 	switch (iState)
    54 		{	 
    55 		case EListCerts:
    56 			{
    57 			// Look for a specific certificate					
    58 			TInt certIndex = -1;
    59 			for (TInt j = 0; j < iCertInfos.Count(); j++)
    60 				{
    61 				if (iCertInfos[j]->Label() == *iParams->iDefault) 
    62 					{
    63 					certIndex = j;
    64 					break;
    65 					}
    66 				}	
    67 				
    68 			if (certIndex != -1)
    69 				{
    70 				iState = EFinished;
    71 				SetActive();				
    72 				iCertStore->Remove(*iCertInfos[certIndex], iStatus);
    73 				}
    74 			else 
    75 				{
    76 				User::Leave(KErrNotFound);
    77 				}			
    78 			}
    79 			break;
    80 		case EFinished:
    81 			{
    82 
    83 			User::LeaveIfError(iStatus.Int());
    84 
    85 		     // We are done!
    86 		    iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE_SUCCESS);   
    87 			 		
    88 			CActiveScheduler::Stop();
    89 			}
    90 			break;
    91 		default:
    92 			{
    93 			User::Panic(_L("REMOVE action: Illegal state."), 1);					
    94 			}			
    95 		}
    96 	}
    97 
    98 TInt CCertToolRemove::RunError(TInt aError)
    99     {
   100     CActiveScheduler::Stop();
   101 
   102     switch (aError)
   103         {
   104         case KErrNotFound :
   105             {
   106             TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTFOUND));         
   107             }
   108             break;
   109         default:
   110             {
   111             TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE_FAILURE, aError));                
   112             }
   113         }   
   114 
   115 	TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));  
   116     return KErrNone;        
   117     }
   118