cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool.cpp
changeset 31 c0e7917aa107
parent 11 9d767430696e
parent 29 ece3df019add
equal deleted inserted replaced
30:880bdb445c5c 31:c0e7917aa107
    34 _LIT(KNewLine, "\n");
    34 _LIT(KNewLine, "\n");
    35 
    35 
    36 _LIT(KDone, "Press any key to continue... \n");
    36 _LIT(KDone, "Press any key to continue... \n");
    37 
    37 
    38 // CertTool command line parameters
    38 // CertTool command line parameters
       
    39 
    39 _LIT(KList, "-list");
    40 _LIT(KList, "-list");
    40 _LIT(KListShort, "-l");
    41 _LIT(KListShort, "-l");
    41 
    42 
    42 _LIT(KListStores, "-liststores");
    43 _LIT(KListStores, "-liststores");
    43 _LIT(KListStoresShort, "-ls");
    44 _LIT(KListStoresShort, "-ls");
    83 _LIT(KPageWise, "-page");
    84 _LIT(KPageWise, "-page");
    84 _LIT(KPageWiseShort, "-p");
    85 _LIT(KPageWiseShort, "-p");
    85 
    86 
    86 _LIT(KUids, "-uids");
    87 _LIT(KUids, "-uids");
    87 
    88 
       
    89 _LIT(KDeletable, "-deletable");
       
    90 _LIT(KDeletableShort, "-del");
       
    91 
    88 const TInt KMaxArgs = 10;
    92 const TInt KMaxArgs = 10;
       
    93 
       
    94 /**
       
    95  * Certtool can operate in the following modes.
       
    96 **/
       
    97 enum OperationMode {
       
    98 Interactive,
       
    99 NonInteractive
       
   100 };
       
   101 
    89 
   102 
    90 /**
   103 /**
    91  * Displays tool name and copy-right informations.
   104  * Displays tool name and copy-right informations.
    92  */
   105  */
    93 LOCAL_D void BoilerPlateL(CConsoleBase* console) 
   106 LOCAL_D void BoilerPlateL(CConsoleBase* console) 
   143 
   156 
   144 	return 1;
   157 	return 1;
   145 	}
   158 	}
   146 	
   159 	
   147 /**
   160 /**
       
   161  * Returns the mode in which the tool would operate. If the command is invoked 
       
   162  * with 2 parameters(certool inputFile outputFile), the tool works in non-interactive
       
   163  * mode else the interactive mode is chosen.
       
   164  */
       
   165 
       
   166 LOCAL_D OperationMode ModeOfOperationL(const CCommandLineArguments& aCmdArgs, RFs& aFs, RFile& aFile)
       
   167     {
       
   168     OperationMode mode = Interactive;
       
   169     if (KeyToolUtils::DoesFileExistsL(aFs,aCmdArgs.Arg(1)))
       
   170         {
       
   171 		mode = NonInteractive;
       
   172         TInt error = aFile.Open(aFs, aCmdArgs.Arg(1), EFileRead|EFileShareAny);
       
   173         aFile.Close();
       
   174         
       
   175         TInt error1 = aFile.Replace(aFs, aCmdArgs.Arg(2), EFileWrite|EFileShareExclusive);
       
   176         // If the input file doesn't exist or not able to create outputfile
       
   177         // switch to Interactive mode
       
   178         if (error != KErrNone || error1 != KErrNone)
       
   179             {
       
   180             CleanupStack::PopAndDestroy(&aFile);
       
   181             mode = Interactive;
       
   182             }   
       
   183                     
       
   184          }
       
   185     return mode;
       
   186     }
       
   187 
       
   188 /**
       
   189  * The main parsing logic. Same for interactive and non-interactive modes.
       
   190  */
       
   191 LOCAL_D void ParseAndHandleCommandL(CArrayFixFlat<TPtrC>& aArgs, CCertToolController& aController)
       
   192     {
       
   193     CKeyToolParameters* params = CKeyToolParameters::NewLC();
       
   194             
       
   195     TInt command = -1; 
       
   196     TInt i = -1;
       
   197            
       
   198     TInt argsCount = aArgs.Count();
       
   199     while (i < (argsCount-1))
       
   200         {
       
   201         i++;
       
   202         if ((aArgs.At(i).CompareF(KDetails)==0)|| (aArgs.At(i).Compare(KDetailsShort)==0))
       
   203                     {
       
   204                     params->iIsDetailed = ETrue;
       
   205                     continue;
       
   206                     }
       
   207         
       
   208                 if (aArgs.At(i).CompareF(KPageWise)==0 || (aArgs.At(i).Compare(KPageWiseShort)==0))
       
   209                     {
       
   210                     i++;
       
   211                     params->iPageWise = ETrue;
       
   212                     continue;
       
   213                     }
       
   214 
       
   215                 if (aArgs.At(i).Compare(KRemoveKeyAlso)==0)
       
   216                     {
       
   217                     params->iRemoveKey = ETrue;
       
   218                     continue;
       
   219                     }
       
   220 
       
   221                 if (aArgs.At(i).CompareF(KApps)==0)
       
   222                     {
       
   223                     i++;
       
   224                     RArray<TUid> apps;
       
   225                     TInt k = 0;
       
   226                     for (k = i; k < argsCount; k++)
       
   227                         {               
       
   228                         if (aArgs.At(k).Find(_L("-")) == KErrNotFound)
       
   229                             {
       
   230                             TUint uid;
       
   231                             if (aArgs.At(k).CompareF(KSWInstall)==0)
       
   232                                 {
       
   233                                 uid = swinstalluid;
       
   234                                 }
       
   235                             else
       
   236                                 {
       
   237                                 if (aArgs.At(k).CompareF(KSWInstallOCSP)==0)
       
   238                                     {
       
   239                                     uid = swinstallocspuid;
       
   240                                     }
       
   241                                 else
       
   242                                     {
       
   243                                     if (aArgs.At(k).CompareF(KMidletInstall)==0)
       
   244                                         {
       
   245                                         uid = midletinstalluid;
       
   246                                         }
       
   247                                     else
       
   248                                         {
       
   249                                         if (aArgs.At(k).CompareF(KTls)==0)
       
   250                                             {
       
   251                                             uid = tlsuid;
       
   252                                             }
       
   253                                         else
       
   254                                             {
       
   255                                             // no more valid apps, break cycle
       
   256                                             break;
       
   257                                             }
       
   258                                         }
       
   259                                     }
       
   260                                 }
       
   261                             apps.Append(TUid::Uid(uid));                        
       
   262                             }
       
   263                         else 
       
   264                             {
       
   265                             // We parsed all UIDs, break the cycle and go on!
       
   266                             break;
       
   267                             }
       
   268                         }
       
   269                     i = k-1;
       
   270                     params->iUIDs = apps; // We pass on ownership
       
   271                     params->iIsDetailed = ETrue;
       
   272                     continue;           
       
   273                     }
       
   274             
       
   275                 if (aArgs.At(i).CompareF(KUids)==0)
       
   276                     {
       
   277                     i++;
       
   278                     RArray<TUid> uids;
       
   279                     TInt k = 0;
       
   280                     for (k = i; k < argsCount; k++)
       
   281                         {               
       
   282                         if (aArgs.At(k).Left(2) == _L("0x"))
       
   283                             {
       
   284                             TLex lex(aArgs.At(k).Mid(2));       
       
   285                             TUint uid =0;
       
   286                             TInt err = lex.Val(uid, EHex);
       
   287                             if (err == KErrNone)
       
   288                                 {
       
   289                                 params->iUIDs.Append(TUid::Uid(uid));                       
       
   290                                 }            
       
   291                             }
       
   292                         else 
       
   293                             {
       
   294                             // We parsed all UIDs, break the cycle and go on!
       
   295                             break;
       
   296                             }
       
   297                         }
       
   298                     i = k-1;
       
   299                     params->iIsDetailed = ETrue;
       
   300                     continue;           
       
   301                     }
       
   302                 
       
   303                 TDesC& cmd = aArgs.At(i);
       
   304                 if (cmd.CompareF(KLabel) == 0 || 
       
   305                     cmd.CompareF(KPrivate) == 0 || cmd.CompareF(KStore) == 0 ||
       
   306                     cmd.CompareF(KOwnerType) == 0 || cmd.Compare(KOwnerTypeShort) == 0 ||
       
   307                     cmd.CompareF(KHelp) == 0 || cmd.Compare(KHelpShort) == 0 ||
       
   308                     cmd.CompareF(KDeletable) == 0 || cmd.CompareF(KDeletableShort) == 0)
       
   309                     {
       
   310                     i++;
       
   311                     if (i >= argsCount || aArgs.At(i)[0] == '-')
       
   312                         {
       
   313                         i = argsCount;
       
   314                         command = CertToolDefController::KUsageCommand;
       
   315                         }
       
   316                     else if (cmd.CompareF(KHelp) == 0 || cmd.Compare(KHelpShort) == 0)
       
   317                         {
       
   318                         params->iDefault = aArgs.At(i).AllocL();
       
   319                         i = argsCount;  
       
   320                         }
       
   321                     else if (cmd.CompareF(KLabel) == 0)
       
   322                         {
       
   323                         params->iLabel = aArgs.At(i).AllocL();
       
   324                         }
       
   325                     else if (cmd.CompareF(KPrivate) == 0)
       
   326                         {
       
   327                         params->iPrivate = aArgs.At(i).AllocL();
       
   328                         }
       
   329                     else if (cmd.CompareF(KStore) == 0)
       
   330                         {
       
   331                         TLex parser(aArgs.At(i));
       
   332                         TInt err = parser.Val(params->iCertstoreIndex);
       
   333                         params->iIsDetailed = ETrue;
       
   334                         }
       
   335                     else if (cmd.CompareF(KOwnerType) == 0 || cmd.Compare(KOwnerTypeShort) == 0)
       
   336                         {
       
   337                         params->iIsDetailed = ETrue;
       
   338                         params->iOwnerType = aArgs.At(i).AllocL();
       
   339                         }
       
   340                     else if (cmd.CompareF(KDeletable) == 0 || cmd.CompareF(KDeletableShort) == 0)
       
   341                         {
       
   342                         params->iIsDetailed = ETrue;
       
   343                         params->iIsDeletable = aArgs.At(i).AllocL();
       
   344                         }
       
   345                     continue;
       
   346                     }
       
   347         
       
   348                 if (VerifyCommand(aArgs.At(i), command, i))
       
   349                     {
       
   350                     continue;
       
   351                     }
       
   352 
       
   353                     
       
   354                 if (i!=0) 
       
   355                     {
       
   356                     if (aArgs.At(i)[0] == '-')
       
   357                         {
       
   358                         i = argsCount;
       
   359                         command = CertToolDefController::KUsageCommand;
       
   360                         continue;
       
   361                         }
       
   362                     delete params->iDefault;
       
   363                     params->iDefault = NULL;
       
   364                     params->iDefault = aArgs.At(i).AllocL();
       
   365                     params->iIsDetailed = ETrue;            
       
   366                     }
       
   367                 } 
       
   368              
       
   369              
       
   370             if (command != -1)
       
   371                 {
       
   372                 TRAP_IGNORE(aController.HandleCommandL(command, params));
       
   373                 }
       
   374             else 
       
   375                 {
       
   376                 aController.HandleCommandL(CertToolDefController::KUsageCommand, params);       
       
   377                 }
       
   378             CleanupStack::PopAndDestroy(params);
       
   379             }
       
   380 
       
   381 
       
   382 /**
       
   383  * Parsing the command for non-interactive mode.
       
   384  */
       
   385 
       
   386 LOCAL_D void ParseCommandInNonInteractiveModeL(RFile& aFile, const CCommandLineArguments& aCmdArgs)
       
   387     {
       
   388   
       
   389     KeyToolUtils::SetFile(&aFile);
       
   390     
       
   391     CKeytoolFileView* view(0); 
       
   392     view = CKeytoolFileView::NewLC(aCmdArgs.Arg(1));
       
   393     TInt cmdCount = view->SplitFileInputToArrayL();
       
   394     
       
   395     //For every command, parse and handle.
       
   396     for (TInt j = 0; j < cmdCount; j++)
       
   397         {
       
   398         CCertToolController* controller = CCertToolController::NewLC(*view);
       
   399         
       
   400         CArrayFixFlat<TPtrC>* args = view->ReadArrayArgumentsLC(j);
       
   401         ParseAndHandleCommandL(*args, *controller);
       
   402         
       
   403         CleanupStack::PopAndDestroy(2, controller);
       
   404         }
       
   405         
       
   406     
       
   407     CleanupStack::PopAndDestroy(view);
       
   408     
       
   409     }
       
   410 
       
   411 
       
   412 /**
       
   413  * Parsing the command for interactive mode.
       
   414  */
       
   415 
       
   416 
       
   417 LOCAL_D void ParseCommandInInteractiveModeL(CConsoleBase& aConsole, const CCommandLineArguments& aCmdArgs)
       
   418     {
       
   419     CArrayFixFlat<TPtrC>* args = new (ELeave) CArrayFixFlat<TPtrC> (10);
       
   420     CleanupStack::PushL(args);
       
   421     CKeytoolConsoleView* view = CKeytoolConsoleView::NewLC(aConsole);
       
   422     CCertToolController* controller = CCertToolController::NewLC(*view);
       
   423 
       
   424     TInt cmdArgsCount = aCmdArgs.Count();
       
   425     
       
   426     KeyToolUtils::SetConsole(&aConsole);
       
   427     BoilerPlateL(&aConsole);
       
   428     
       
   429     for (TInt i = 0; i < cmdArgsCount; i++)
       
   430         {
       
   431         args->AppendL(aCmdArgs.Arg(i));
       
   432         }
       
   433     
       
   434     //Interactive mode can handle only one command at a time.
       
   435     ParseAndHandleCommandL(*args, *controller); 
       
   436     
       
   437     // We are done!
       
   438     aConsole.Printf(KNewLine);
       
   439     aConsole.Printf(KDone);
       
   440     aConsole.Getch(); 
       
   441     
       
   442     CleanupStack::PopAndDestroy(3, args); // controller, view, args
       
   443     
       
   444     }
       
   445 
       
   446 /**
   148  * Parses the command line and given control to the handler to deal with the request.
   447  * Parses the command line and given control to the handler to deal with the request.
   149  */
   448  */
   150 LOCAL_D void DoMainL() 
   449 LOCAL_D void DoMainL() 
   151 	{
   450 	{
   152 	TBool interactiveMode = ETrue;
   451 
   153 	
       
   154 	RFs fs;
   452 	RFs fs;
   155 	User::LeaveIfError(fs.Connect());
   453 	User::LeaveIfError(fs.Connect());
   156 	CleanupClosePushL(fs);
   454 	CleanupClosePushL(fs);
       
   455 	RFile file;
   157 	
   456 	
   158 	CConsoleBase* console = Console::NewL(KShortName, TSize(KConsFullScreen, KConsFullScreen));
   457 	CConsoleBase* console = Console::NewL(KShortName, TSize(KConsFullScreen, KConsFullScreen));
   159 	CleanupStack::PushL(console);
   458 	CleanupStack::PushL(console);
   160 	CCommandLineArguments* cmdArgs = CCommandLineArguments::NewLC();
   459 	CCommandLineArguments* cmdArgs = CCommandLineArguments::NewLC();
   161 	TInt cmdArgsCount = cmdArgs->Count();
   460 	TInt cmdArgsCount = cmdArgs->Count();
   162 	
   461 	
   163 	RFile file;
   462 	
   164 	// command: certtool inputfile outputfile
   463 	OperationMode currentMode = Interactive; //Interactive by default.
       
   464 	
       
   465 	// Determine the mode of operation as either interactive or non-interactive.
   165 	if (cmdArgsCount == 3)
   466 	if (cmdArgsCount == 3)
   166 		{
   467 		{
   167 		if (KeyToolUtils::DoesFileExistsL(fs,cmdArgs->Arg(1)))
   468 		currentMode = ModeOfOperationL(*cmdArgs, fs, file);
   168 		  	{
       
   169 		  	interactiveMode = EFalse;
       
   170 		  	TInt error = file.Open(fs, cmdArgs->Arg(1), EFileRead|EFileShareAny);
       
   171 		  	file.Close();
       
   172 		  	TInt error1 = file.Replace(fs, cmdArgs->Arg(2), EFileWrite|EFileShareExclusive);
       
   173 		  	CleanupClosePushL(file);
       
   174 		  	// If the input file doesn't exist or not able to create outputfile
       
   175 		  	// switch to Interactive mode
       
   176 		  	if (error != KErrNone || error1 != KErrNone)
       
   177 		   		{
       
   178 			   	CleanupStack::PopAndDestroy(&file);
       
   179 			   	interactiveMode = ETrue;
       
   180 			  	}	
       
   181 				
       
   182 			}
       
   183 		}
   469 		}
   184 		
   470 		
   185 	CKeytoolConsoleView* view = CKeytoolConsoleView::NewLC(*console);
   471 	switch(currentMode)
   186 	CCertToolController* controller = CCertToolController::NewLC(*view);
   472 	    {
   187 	CArrayFixFlat<TPtrC>* args = new (ELeave) CArrayFixFlat<TPtrC> (10);
   473 	    case Interactive:
   188 	CleanupStack::PushL(args);
   474 	        ParseCommandInInteractiveModeL(*console, *cmdArgs);
   189 	CKeytoolFileView* view1 = NULL;
   475 	        break;
   190 
   476 	        
   191 	TInt cmdCount = 0;
   477 	    case NonInteractive:
   192 	if (interactiveMode)
   478 	        //file refers to the output file name.
   193 		{
   479 	        CleanupClosePushL(file);
   194 		KeyToolUtils::SetConsole(console);
   480 	        ParseCommandInNonInteractiveModeL(file, *cmdArgs);
   195 		BoilerPlateL(console);
   481 	        CleanupStack::PopAndDestroy(&file);
   196 		for (TInt i = 0; i < cmdArgsCount; i++)
   482 	        break;
   197 			{
   483 	    }
   198 			args->AppendL(cmdArgs->Arg(i));
   484 
   199 			}
   485 	CleanupStack::PopAndDestroy(3, &fs);
   200 		// In Interactive mode by default we can execute 1 command only.
       
   201 		cmdCount = 1;
       
   202 		}
       
   203 	else
       
   204 		{
       
   205 		CleanupStack::PopAndDestroy(3, view); // args, controller, view
       
   206 		KeyToolUtils::SetFile(&file);
       
   207 		view1 = CKeytoolFileView::NewLC(cmdArgs->Arg(1));
       
   208 		cmdCount = view1->SplitFileInputToArrayL();
       
   209 		}	
       
   210 	
       
   211 	for (TInt j = 0; j < cmdCount; j++)
       
   212 		{
       
   213 		if (!interactiveMode)
       
   214 			{
       
   215 			controller = CCertToolController::NewLC(*view1);
       
   216 			args = view1->ReadArrayArgumentsLC(j);
       
   217 			}
       
   218 
       
   219 		CKeyToolParameters* params = CKeyToolParameters::NewLC();
       
   220 		
       
   221 		TInt command = -1; 
       
   222 		TInt i = -1;
       
   223 		
       
   224 		TInt argsCount = args->Count();
       
   225 		while (i < (argsCount-1))
       
   226 		 	{
       
   227 		 	i++;
       
   228 			if ((args->At(i).CompareF(KDetails)==0)|| (args->At(i).Compare(KDetailsShort)==0))
       
   229 				{
       
   230 				params->iIsDetailed = ETrue;
       
   231 				continue;
       
   232 				}
       
   233 	
       
   234 			if (args->At(i).CompareF(KPageWise)==0 || (args->At(i).Compare(KPageWiseShort)==0))
       
   235 				{
       
   236 				i++;
       
   237 				params->iPageWise = ETrue;
       
   238 				continue;
       
   239 				}
       
   240 
       
   241 			if (args->At(i).Compare(KRemoveKeyAlso)==0)
       
   242 				{
       
   243 				params->iRemoveKey = ETrue;
       
   244 				continue;
       
   245 				}
       
   246 
       
   247 			if (args->At(i).CompareF(KApps)==0)
       
   248 				{
       
   249 				i++;
       
   250 				RArray<TUid> apps;
       
   251 				TInt k = 0;
       
   252 				for (k = i; k < argsCount; k++)
       
   253 					{				
       
   254 					if (args->At(k).Find(_L("-")) == KErrNotFound)
       
   255 						{
       
   256 						TUint uid;
       
   257 						if (args->At(k).CompareF(KSWInstall)==0)
       
   258 							{
       
   259 							uid = swinstalluid;
       
   260 							}
       
   261 						else
       
   262 							{
       
   263 							if (args->At(k).CompareF(KSWInstallOCSP)==0)
       
   264 								{
       
   265 								uid = swinstallocspuid;
       
   266 								}
       
   267 							else
       
   268 								{
       
   269 								if (args->At(k).CompareF(KMidletInstall)==0)
       
   270 									{
       
   271 									uid = midletinstalluid;
       
   272 									}
       
   273 								else
       
   274 									{
       
   275 									if (args->At(k).CompareF(KTls)==0)
       
   276 										{
       
   277 										uid = tlsuid;
       
   278 										}
       
   279 									else
       
   280 										{
       
   281 										// no more valid apps, break cycle
       
   282 										break;
       
   283 										}
       
   284 									}
       
   285 								}
       
   286 							}
       
   287 						apps.Append(TUid::Uid(uid));						
       
   288 						}
       
   289 					else 
       
   290 						{
       
   291 						// We parsed all UIDs, break the cycle and go on!
       
   292 						break;
       
   293 						}
       
   294 					}
       
   295 				i = k-1;
       
   296 				params->iUIDs = apps; // We pass on ownership
       
   297 				params->iIsDetailed = ETrue;
       
   298 				continue;			
       
   299 				}
       
   300 		
       
   301 			if (args->At(i).CompareF(KUids)==0)
       
   302 				{
       
   303 				i++;
       
   304 				RArray<TUid> uids;
       
   305 				TInt k = 0;
       
   306 				for (k = i; k < argsCount; k++)
       
   307 					{				
       
   308 					if (args->At(k).Left(2) == _L("0x"))
       
   309 						{
       
   310 						TLex lex(args->At(k).Mid(2));		
       
   311 						TUint uid =0;
       
   312 						TInt err = lex.Val(uid, EHex);
       
   313 						if (err == KErrNone)
       
   314 							{
       
   315 							params->iUIDs.Append(TUid::Uid(uid));						
       
   316 							}			 
       
   317 						}
       
   318 					else 
       
   319 						{
       
   320 						// We parsed all UIDs, break the cycle and go on!
       
   321 						break;
       
   322 						}
       
   323 					}
       
   324 				i = k-1;
       
   325 				params->iIsDetailed = ETrue;
       
   326 				continue;			
       
   327 				}
       
   328 			
       
   329 			TDesC& cmd = args->At(i);
       
   330 			if (cmd.CompareF(KLabel) == 0 || 
       
   331 			    cmd.CompareF(KPrivate) == 0 || cmd.CompareF(KStore) == 0 ||
       
   332 			    cmd.CompareF(KOwnerType) == 0 || cmd.Compare(KOwnerTypeShort) == 0 ||
       
   333 			    cmd.CompareF(KHelp) == 0 || cmd.Compare(KHelpShort) == 0 )
       
   334 				{
       
   335 				i++;
       
   336 				if (i >= argsCount || args->At(i)[0] == '-')
       
   337 					{
       
   338 					i = argsCount;
       
   339 					command = CertToolDefController::KUsageCommand;
       
   340 					}
       
   341 				else if (cmd.CompareF(KHelp) == 0 || cmd.Compare(KHelpShort) == 0)
       
   342 					{
       
   343 					params->iDefault = args->At(i).AllocL();
       
   344 					i = argsCount;	
       
   345 					}
       
   346 				else if (cmd.CompareF(KLabel) == 0)
       
   347 					{
       
   348 					params->iLabel = args->At(i).AllocL();
       
   349 					}
       
   350 				else if (cmd.CompareF(KPrivate) == 0)
       
   351 					{
       
   352 					params->iPrivate = args->At(i).AllocL();
       
   353 					}
       
   354 				else if (cmd.CompareF(KStore) == 0)
       
   355 					{
       
   356 					TLex parser(args->At(i));
       
   357 					TInt err = parser.Val(params->iCertstoreIndex);
       
   358 					params->iIsDetailed = ETrue;
       
   359 					}
       
   360 				else if (cmd.CompareF(KOwnerType) == 0 || cmd.Compare(KOwnerTypeShort) == 0)
       
   361 					{
       
   362 					params->iIsDetailed = ETrue;
       
   363 					params->iOwnerType = args->At(i).AllocL();
       
   364 					}
       
   365 				else
       
   366 					{
       
   367 					// no action required	
       
   368 					}
       
   369 				continue;
       
   370 				}
       
   371 	
       
   372 			if (VerifyCommand(args->At(i), command, i))
       
   373 				{
       
   374 				continue;
       
   375 				}
       
   376 
       
   377 				
       
   378 			if (i!=0) 
       
   379 				{
       
   380 				if (args->At(i)[0] == '-')
       
   381 					{
       
   382 					i = argsCount;
       
   383 					command = CertToolDefController::KUsageCommand;
       
   384 					continue;
       
   385 					}
       
   386 				delete params->iDefault;
       
   387 				params->iDefault = NULL;
       
   388 				params->iDefault = args->At(i).AllocL();
       
   389 				params->iIsDetailed = ETrue;			
       
   390 				}
       
   391 		 	} 
       
   392 		 
       
   393 		 
       
   394 		if (command != -1)
       
   395 			{
       
   396 			TRAP_IGNORE(controller->HandleCommandL(command, params));
       
   397 			}
       
   398 		else 
       
   399 			{
       
   400 			controller->HandleCommandL(CertToolDefController::KUsageCommand, params);		
       
   401 			}
       
   402 		CleanupStack::PopAndDestroy(3, controller); // params, args, controller
       
   403 		}
       
   404 	if (interactiveMode)
       
   405 		{
       
   406 		CleanupStack::PopAndDestroy(view);
       
   407 		// We are done!
       
   408 		console->Printf(KNewLine);
       
   409 		console->Printf(KDone);
       
   410 		console->Getch();	
       
   411 		}
       
   412 	else
       
   413 		{
       
   414 		CleanupStack::PopAndDestroy(2, &file); //view1 and file
       
   415 		}
       
   416 	CleanupStack::PopAndDestroy(3, &fs); //cmdArgs, console, fs
       
   417 	}
   486 	}
       
   487 
   418 	
   488 	
   419 
   489 
   420 GLDEF_C TInt E32Main()         // main function called by E32
   490 GLDEF_C TInt E32Main()         // main function called by E32
   421    	{
   491    	{
   422 	__UHEAP_MARK;
   492 	__UHEAP_MARK;