terminalsecurity/SCP/SCPHistoryPlugin/src/SCPSpecificStringsPlugin.cpp
changeset 0 b497e44ab2fc
child 25 b183ec05bd8c
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2000 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 "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: Implementation of terminalsecurity components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32std.h>
       
    22 #include <ecom/implementationproxy.h>
       
    23 #include <SCPParamObject.h>
       
    24 
       
    25 #include "SCPSpecificStringsPlugin.h"
       
    26 #include <SCPHistoryPluginLang.rsg>
       
    27 #include "SCP_IDs.h"
       
    28 #include <featmgr.h>
       
    29 
       
    30 // ============================= LOCAL FUNCTIONS  =============================
       
    31 
       
    32 // ============================= MEMBER FUNCTIONS =============================
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CSCPSpecificStringsPlugin::NewL
       
    36 // Two-phased contructor
       
    37 // (static, may leave)
       
    38 // Status : Approved
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 CSCPSpecificStringsPlugin* CSCPSpecificStringsPlugin::NewL()
       
    42     {
       
    43 	CSCPSpecificStringsPlugin* self = new ( ELeave ) CSCPSpecificStringsPlugin();
       
    44 	CleanupStack::PushL( self );
       
    45 	self->ConstructL();
       
    46 	CleanupStack::Pop( self );
       
    47 	
       
    48     Dprint ( ( _L( "( 0x%x ) CSCPSpecificStringsPlugin::NewL()" ), self ) );
       
    49 
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CSCPSpecificStringsPlugin::CSCPSpecificStringsPlugin
       
    55 // Constructor
       
    56 // Status : Approved
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CSCPSpecificStringsPlugin::CSCPSpecificStringsPlugin()
       
    60    
       
    61     {
       
    62     Dprint ( ( _L( "CSCPSpecificStringsPlugin::CSCPSpecificStringsPlugin()" ) ) );
       
    63     return;
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CSCPSpecificStringsPlugin::ConstructL
       
    68 // 2nd phase construction
       
    69 // (may leave)
       
    70 // Status : Approved
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 void CSCPSpecificStringsPlugin::ConstructL()
       
    74     {
       
    75     
       
    76     FeatureManager::InitializeLibL();
       
    77 	if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
    78 	{
       
    79     	FeatureManager::UnInitializeLib();
       
    80    		User::Leave( KErrNotSupported );
       
    81   	}
       
    82    	FeatureManager::UnInitializeLib();
       
    83     return;
       
    84     }
       
    85     
       
    86 // ----------------------------------------------------------------------------
       
    87 // CSCPSpecificStringsPlugin::HandleEvent
       
    88 // 
       
    89 // 
       
    90 // Status : Approved
       
    91 // ----------------------------------------------------------------------------
       
    92 //    
       
    93 CSCPParamObject* CSCPSpecificStringsPlugin::HandleEvent( TInt aID, CSCPParamObject& aParam )
       
    94 	{	
       
    95 	
       
    96 	// Make the ParamObject for success ack, Delete later
       
    97 	CSCPParamObject* retParams = NULL;
       
    98 
       
    99 	TBool errRaised;
       
   100 	errRaised = EFalse;
       
   101 		
       
   102 	if ( iFs == NULL )
       
   103 	    {
       
   104 	    return NULL; // Eventhandler not available
       
   105 	    }
       
   106 
       
   107 	// check for Case
       
   108 	switch ( aID )
       
   109 	    {
       
   110 		case ( KSCPEventValidate ) :
       
   111     		{   		
       
   112 			TBool specificstringscheck;
       
   113 			
       
   114 			// Get params
       
   115 			CSCPParamObject& config = iEventHandler->GetParameters();
       
   116 			
       
   117 			// Check if validation is required.
       
   118 			if ( config.Get( ( RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings), 
       
   119 				  specificstringscheck ) !=  KErrNone )
       
   120 				   specificstringscheck = EFalse;
       
   121 
       
   122 			 if ( specificstringscheck )
       
   123 			    {
       
   124 			 	// Check for specific strings			 	
       
   125 			 	
       
   126 				// Get the configFile's path.
       
   127 				// If this fails, there is something badly wrong(Private folder is not there)
       
   128 				TInt errSCF = SetConfigFile ();
       
   129 				if (errSCF != KErrNone)
       
   130 				    {
       
   131 					errRaised = ETrue;
       
   132 					break; // Break out from Case!
       
   133 				    }
       
   134 			 	
       
   135 			 	// Get the password from the paramObject
       
   136 	     		TBuf<KSCPPasscodeMaxLength> securitycode;
       
   137 	            if ( aParam.Get( KSCPParamPassword, securitycode ) != KErrNone )
       
   138                     {
       
   139                 	// Nothing to do anymore
       
   140                    	Dprint( (_L("CSCPSpecificStringsPlugin::HandleEvent()\
       
   141                    	ERROR: KSCPEventPasswordChanged/KSCPParamPassword is  != KErrNone") ));
       
   142                 	errRaised = ETrue;
       
   143 					break; // Break out from the Case!;
       
   144                     }			 	
       
   145 			 	
       
   146 			 	TBool forbiddensecuritycode = EFalse;
       
   147 			 	
       
   148 			 	TInt errCSS = CheckSpecificStrings ( securitycode, forbiddensecuritycode );
       
   149 			 	if (errCSS != KErrNone)
       
   150 				    {
       
   151 					errRaised = ETrue;
       
   152 					break; // Break out from Case!
       
   153     				}
       
   154 			 	
       
   155 			 	if ( forbiddensecuritycode )
       
   156 			    	{
       
   157 			 		// Word was blacklisted!
       
   158 					// Get the filesystem for Resource
       
   159 					// If fail, bail out!
       
   160 					TInt errgGR = GetResource();
       
   161 					if (errgGR != KErrNone)
       
   162 					    {
       
   163 						errRaised = ETrue;
       
   164 						break; // Break out from the For!
       
   165 					    }
       
   166 			 	
       
   167 			 		// Prompt buf, iNote can show only 97 chars,
       
   168 					// without ... markings.
       
   169 					HBufC* hbuf = NULL;
       
   170 					
       
   171 					TRAP_IGNORE(
       
   172 					    hbuf = LoadAndFormatResL( R_SET_SEC_CODE_PERSONAL );
       
   173 		                );		                
       
   174 
       
   175                     // Create the result-object to return
       
   176 				    TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   177                     
       
   178                     if ( err == KErrNone )
       
   179 				        {
       
   180 			            retParams->Set( KSCPParamStatus, KErrSCPInvalidCode );
       
   181     		            retParams->Set( KSCPParamAction, KSCPActionShowUI );
       
   182 	    	            retParams->Set( KSCPParamUIMode, KSCPUINote );
       
   183 		                
       
   184 		                if ( hbuf != NULL )
       
   185 		                    {
       
   186 		                    TPtr ptr = hbuf->Des();
       
   187 		                    retParams->Set( KSCPParamPromptText, ptr );
       
   188 		                    delete hbuf;
       
   189 		                    }
       
   190 				        }    					        
       
   191 			 	    }			 	    		 	
       
   192 			    } // end of specificstringscheck
       
   193 
       
   194 			break;
       
   195 		    } // End of KSCPEventValidate
       
   196 
       
   197 	    case ( KSCPEventRetrieveConfiguration ):
       
   198 	        {
       
   199 	        // This event is sent when a client wishes to retrieve the value for the given parameter.
       
   200 	        // None of the parameters, which handle the string-buffer cannot be retrieved by anyone,
       
   201 	        // so we'll return KErrNotSupported. Note that EPasscodeCheckSpecificStrings is OK to get.
       
   202 	        
       
   203 	        // Get the ID from the paramObject   
       
   204 	        TInt paramID = -1;    
       
   205 			if ( aParam.Get( KSCPParamID, paramID ) != KErrNone )
       
   206 			    {
       
   207 				// Nothing to do anymore
       
   208 				break;
       
   209     			}   
       
   210 			    
       
   211 			if ( ( paramID ==  RTerminalControl3rdPartySession::EPasscodeDisallowSpecific )
       
   212 				||  ( paramID ==  RTerminalControl3rdPartySession::EPasscodeAllowSpecific)
       
   213 				||  ( paramID ==  RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) )
       
   214 			    {
       
   215 	            TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   216 	            if ( err == KErrNone )
       
   217 	                {
       
   218 	                Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\
       
   219 	                    Get not supported for %d" ), paramID ) );
       
   220 	                retParams->Set( KSCPParamStatus, KErrNotSupported );
       
   221 	                }
       
   222 	            else
       
   223 	                {
       
   224 	                Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\
       
   225 	                    ERROR: Cannot create paramObject" ) ) );
       
   226 	                }
       
   227 	            }
       
   228 	        break;
       
   229 	        }
       
   230 
       
   231 		// same for All plugins
       
   232 		case ( KSCPEventConfigurationQuery ):
       
   233     		{   		
       
   234 			TInt paramID = -1; 
       
   235 
       
   236 			// Get the ID from the paramObject      
       
   237 			if ( aParam.Get( KSCPParamID, paramID ) != KErrNone )
       
   238 			    {
       
   239 				// Nothing to do anymore
       
   240 				break;
       
   241 			    }            
       
   242 
       
   243 			if ( paramID == (RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings)
       
   244 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeDisallowSpecific)
       
   245 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeAllowSpecific)
       
   246 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) )
       
   247 			    {						
       
   248 				// OK, we're interested
       
   249                 TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   250                 if ( err != KErrNone )
       
   251                     {
       
   252                     break; // Nothing we can do now
       
   253                     }
       
   254                                 
       
   255 				TInt retStatus = KErrNone;
       
   256 				
       
   257 			    if ( paramID != RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings )
       
   258 			        {
       
   259         		    // Set the storage attribute, so the server won't save the value,
       
   260         		    // we'll do it ourselves.
       
   261         			retParams->Set( KSCPParamStorage, KSCPStoragePrivate );			        
       
   262 			        }
       
   263 
       
   264 				switch ( paramID )
       
   265 				    {
       
   266 					case ( RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings ):
       
   267 					    {
       
   268 						// 1015				
       
   269 						TInt paramValue;
       
   270 						if ( (aParam.Get( KSCPParamValue, paramValue ) != KErrNone) ||
       
   271 							 ( paramValue < 0 ) || 	( paramValue > 1 ) ) 
       
   272 						       retStatus = KErrArgument;
       
   273 						
       
   274 					    break;
       
   275 					    }
       
   276 					
       
   277 					// 1016
       
   278 					// Handle param change for strings to block
       
   279 					case ( RTerminalControl3rdPartySession::EPasscodeDisallowSpecific ):
       
   280 					    {
       
   281 						// Get the params value's length
       
   282 						// If param length is not correct, there's something very wrong. out
       
   283 						TInt paramlength = aParam.GetParamLength( KSCPParamValue );
       
   284 						if ( paramlength <= 0)
       
   285 						    {
       
   286 							retStatus = KErrArgument;
       
   287 							break; // from case!
       
   288 						    }
       
   289 
       
   290 						HBufC* paramvaluebuf = NULL;
       
   291 						TRAPD( err, paramvaluebuf = HBufC::NewL( paramlength ) );
       
   292 						if ( err != KErrNone )
       
   293 						    {
       
   294 						    retStatus = err;
       
   295 						    break;
       
   296 						    }
       
   297 						    
       
   298 						TPtr paramptr = paramvaluebuf->Des();
       
   299 						aParam.Get( KSCPParamValue, paramptr );
       
   300 
       
   301 						// Check for basic test
       
   302 						if ( IsNotValidWord ( paramptr ) )
       
   303 						    {
       
   304 							retStatus = KErrArgument;
       
   305 							delete paramvaluebuf;
       
   306 							break;
       
   307     						}
       
   308     						
       
   309 						// Send them to parser and store them
       
   310 						TInt errgPS = KErrNone;
       
   311 						TRAPD( err2, errgPS = ParseAndStoreL( paramptr ) );
       
   312 						if ( err2 != KErrNone )
       
   313 						    {
       
   314 						    errgPS = err2;
       
   315 						    }
       
   316 						
       
   317 						delete paramvaluebuf;
       
   318 						
       
   319 						if (errgPS != KErrNone)
       
   320 						    {
       
   321 							if (errgPS == KErrArgument)
       
   322 							    {
       
   323 								retStatus = KErrArgument;
       
   324 								break; // from case!
       
   325 							    }
       
   326 	
       
   327 							errRaised = ETrue;
       
   328 							break; // Break out.
       
   329 						    } 
       
   330 					    break;
       
   331 					    }
       
   332 					
       
   333 
       
   334 					// 1017
       
   335 					// Handle param change for strings exclude from the list
       
   336 					case ( RTerminalControl3rdPartySession::EPasscodeAllowSpecific ):
       
   337 					    {
       
   338 	
       
   339 						// Get the params value's length
       
   340 						// If param length is not correct, there's something very wrong. out
       
   341 						TInt paramlength = aParam.GetParamLength( KSCPParamValue );
       
   342 						if ( paramlength <= 0)
       
   343 						    {
       
   344 							retStatus = KErrArgument;
       
   345 							break; // from case!
       
   346 						    }
       
   347 																		
       
   348 						HBufC* paramvaluebuf = NULL;
       
   349 						TRAPD( err, paramvaluebuf = HBufC::NewL( paramlength ) );
       
   350 						if ( err != KErrNone )
       
   351 						    {
       
   352 						    retStatus = err;
       
   353 						    break;
       
   354 						    }
       
   355 						    
       
   356 						TPtr paramptr = paramvaluebuf->Des();
       
   357 						aParam.Get( KSCPParamValue, paramptr );
       
   358 
       
   359 						// Check for basic test
       
   360 						if ( IsNotValidWord ( paramptr ) )
       
   361 						    {
       
   362 							retStatus = KErrArgument;
       
   363 							delete paramvaluebuf;
       
   364 							break;
       
   365 						    }
       
   366 						    
       
   367 						// Send the word to remover and gets them off the list
       
   368 						TInt errgPR = KErrNone;
       
   369 						TRAPD( err2, errgPR = ParseAndRemoveL( paramptr ) );
       
   370 						if ( err2 != KErrNone )
       
   371 						    {
       
   372 						    errgPR = err2;
       
   373 						    }
       
   374 						
       
   375 						delete paramvaluebuf;
       
   376 						
       
   377 						if (errgPR != KErrNone)
       
   378 						    {
       
   379 							if (errgPR == KErrArgument)
       
   380 							    {
       
   381 							    retStatus = KErrArgument;
       
   382 								break; // from case!
       
   383 							    }
       
   384 	
       
   385 							errRaised = ETrue;
       
   386 							break; // Break out.
       
   387 						    } 												
       
   388 						
       
   389 					    break;
       
   390 					    }												
       
   391 					
       
   392 					case ( RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings ):
       
   393 					    {					
       
   394 						// 1018, Flush the config file
       
   395 						TInt paramValue;
       
   396 						if ( (aParam.Get( KSCPParamValue, paramValue ) != KErrNone) ||
       
   397 							 ( paramValue < 0 ) || 	( paramValue > 1 ) )
       
   398 						    {
       
   399                             retStatus = KErrArgument;
       
   400 						    }						     
       
   401 						
       
   402 						if (paramValue == 1 && retStatus == KErrNone) 
       
   403 						    {
       
   404 						    TRAP_IGNORE( FlushConfigFileL() );
       
   405 						    }
       
   406 						    
       
   407 						break;
       
   408 					    }							
       
   409     				} // End of switch                          
       
   410 
       
   411 				retParams->Set( KSCPParamStatus, retStatus );
       
   412 			    }
       
   413 			else
       
   414 			    {
       
   415 				retParams = NULL;
       
   416 			    }		
       
   417 		         
       
   418 			break;
       
   419 		    } //End of KSCPEventConfigurationQuery Case
       
   420 
       
   421         case ( KSCPEventReset ):
       
   422               {
       
   423               // Reset the configuration for this plugin.
       
   424               TRAP_IGNORE( FlushConfigFileL() );
       
   425               
       
   426               break;
       
   427               }
       
   428 
       
   429 	} // End of  switch ( aID )
       
   430 
       
   431 	// Check if Any errors were raised and handle it
       
   432 	if (errRaised) 
       
   433         {
       
   434         if ( retParams != NULL )
       
   435             {
       
   436             delete retParams;
       
   437             }
       
   438         retParams = NULL;
       
   439         }
       
   440 
       
   441 	return retParams; 
       
   442 	}
       
   443 
       
   444 // ----------------------------------------------------------------------------
       
   445 // CSCPSpecificStringsPlugin::SetEventHandler
       
   446 // SetEventHandler
       
   447 // 
       
   448 // Status : Approved
       
   449 // ----------------------------------------------------------------------------
       
   450 //    
       
   451 void CSCPSpecificStringsPlugin::SetEventHandler( MSCPPluginEventHandler* aHandler )
       
   452 	{
       
   453 	iEventHandler = aHandler;
       
   454 	
       
   455 	iFs = &(iEventHandler->GetFsSession());
       
   456 	}	
       
   457 
       
   458 // ----------------------------------------------------------------------------
       
   459 // CSCPSpecificStringsPlugin::~CSCPSpecificStringsPlugin
       
   460 // Destructor
       
   461 // Status : Approved
       
   462 // ----------------------------------------------------------------------------
       
   463 //
       
   464 CSCPSpecificStringsPlugin::~CSCPSpecificStringsPlugin()
       
   465     {
       
   466 	Dprint( (_L("CSCPSpecificStringsPlugin::~CSCPSpecificStringsPlugin()") ));
       
   467     
       
   468 	iRf.Close();   
       
   469         	
       
   470 	return;
       
   471     }
       
   472 
       
   473 
       
   474 
       
   475 // ----------------------------------------------------------------------------
       
   476 // CSCPSpecificStringsPlugin::GetResource
       
   477 // GetResource
       
   478 // Status : Approved
       
   479 // ----------------------------------------------------------------------------
       
   480 //
       
   481 
       
   482 TInt CSCPSpecificStringsPlugin::GetResource()
       
   483     {   
       
   484  	Dprint( (_L("CSCPSpecificStringsPlugin::GetResource()") ));
       
   485 	// The resource has to be loaded manually since it is not an application.
       
   486     
       
   487 	TFileName resourceFile;
       
   488 	resourceFile.Append( KDriveZSpecific );
       
   489 	resourceFile.Append( SCPSpecificStringsPluginSrcFile );
       
   490 	BaflUtils::NearestLanguageFile( *iFs, resourceFile );
       
   491 	TRAPD( err, iRf.OpenL( *iFs, resourceFile ) );
       
   492 
       
   493 	if ( err == KErrNone )
       
   494 	    {
       
   495 		TRAP( err, iRf.ConfirmSignatureL() );
       
   496 	    }          
       
   497  
       
   498     return err;       
       
   499     }
       
   500 
       
   501 
       
   502 // ----------------------------------------------------------------------------
       
   503 // CSCPSpecificStringsPlugin::LoadResourceLC
       
   504 // GetResource
       
   505 // Status : Approved
       
   506 // ----------------------------------------------------------------------------
       
   507 //
       
   508 HBufC16* CSCPSpecificStringsPlugin::LoadResourceLC ( TInt aResId )
       
   509     {
       
   510 	Dprint( (_L("CSCPSpecificStringsPlugin::LoadResourceLC()") ));
       
   511 
       
   512 	// load the actual resource
       
   513      HBufC8* readBuffer = iRf.AllocReadLC( aResId );
       
   514     // as we are expecting HBufC16...
       
   515      const TPtrC16 ptrReadBuffer( (TText16*) readBuffer->Ptr(),
       
   516                                  ( readBuffer->Length() + 1 ) >> 1 );
       
   517     HBufC16* textBuffer=HBufC16::NewL( ptrReadBuffer.Length() );    
       
   518     *textBuffer=ptrReadBuffer;
       
   519     CleanupStack::PopAndDestroy( readBuffer ); // readBuffer
       
   520     CleanupStack::PushL( textBuffer );
       
   521   	return textBuffer;
       
   522     }
       
   523 
       
   524 
       
   525 
       
   526 
       
   527 // ----------------------------------------------------------------------------
       
   528 // CSCPSpecificStringsPlugin::SetConfigFile
       
   529 // SetConfigFile
       
   530 // Status : Approved
       
   531 // ----------------------------------------------------------------------------
       
   532 //
       
   533 TInt CSCPSpecificStringsPlugin::SetConfigFile()
       
   534     {	
       
   535 	Dprint( (_L("CSCPSpecificStringsPlugin::SetConfigFile()") ));
       
   536 	TRAPD( err, iEventHandler->GetStoragePathL( iCfgFilenamepath ) );
       
   537 	if ( err != KErrNone )
       
   538         {
       
   539 		Dprint( (_L("CSCPSpecificStringsPlugin::SetConfigFile:\
       
   540 		ERROR: Failed to get storage path: %d"), err ));             
       
   541 		return err;
       
   542 	    }
       
   543 	iCfgFilenamepath.Append( KConfigFileSpecific );
       
   544 	return err;
       
   545     }
       
   546 
       
   547 // ----------------------------------------------------------------------------
       
   548 // CSCPSpecificStringsPlugin::CheckSpecificStrings
       
   549 // CheckSpecificStrings
       
   550 // Status : Approved
       
   551 // ----------------------------------------------------------------------------
       
   552 //
       
   553 TInt CSCPSpecificStringsPlugin::CheckSpecificStrings( TDes& aSecuritycode, 
       
   554 													  TBool& aForbiddenSecurityCode )
       
   555     {
       
   556 	Dprint( (_L("CSCPSpecificStringsPlugin::CheckSpecificStrings()") ));
       
   557 	// Default is not blocklistedword
       
   558 	aForbiddenSecurityCode = EFalse;
       
   559 	
       
   560 	// get GetSpecificStringsArray
       
   561 	CDesCArrayFlat*  array = new CDesCArrayFlat(1);
       
   562 	TInt err = KErrNone;
       
   563 	
       
   564 	if ( array == NULL )
       
   565 	    {
       
   566 	    err = KErrNoMemory;
       
   567 	    }
       
   568 	else
       
   569 	    {
       
   570 	    TRAPD( err2, err = GetSpecificStringsArrayL( *array ) );
       
   571 	    if ( err2 != KErrNone )
       
   572 	        {
       
   573 	        err = err2;
       
   574 	        }
       
   575 	    }
       
   576 	
       
   577 	if (err != KErrNone)
       
   578 	    {
       
   579 		// Kill local array
       
   580 		if ( array != NULL )
       
   581 		    {
       
   582 		    array->Reset();    
       
   583 		    delete array;
       
   584 		    }
       
   585 		    		
       
   586 		return err;
       
   587 	    }
       
   588 
       
   589 	// check for match
       
   590 	TBuf<KSCPPasscodeMaxLength> arrayItem;
       
   591 	// We use the uppercase version of the given string while checking
       
   592 	TBuf<KSCPPasscodeMaxLength> secCodeBuf;
       
   593 	secCodeBuf = aSecuritycode;
       
   594 	secCodeBuf.UpperCase();
       
   595 
       
   596 	// Set the historyobject
       
   597 	for (TInt i=0; i < array->Count(); i++)
       
   598     	{
       
   599 		arrayItem.Zero();
       
   600 		arrayItem = array->MdcaPoint(i);
       
   601 		arrayItem.UpperCase();
       
   602 		// Check if this string causes the password to be invalid
       
   603 		// the strings are matched by a case-insensitive substring match.
       
   604 		if ( secCodeBuf.Find( arrayItem ) != KErrNotFound )
       
   605 		    {
       
   606 			aForbiddenSecurityCode = ETrue;
       
   607 			break; // Out from for
       
   608 		    }
       
   609     	}
       
   610     	
       
   611 	// Kill local array
       
   612 	array->Reset();
       
   613 	delete array;
       
   614 	return err; 
       
   615     }
       
   616 
       
   617 // ----------------------------------------------------------------------------
       
   618 // CSCPSpecificStringsPlugin::ParseAndStoreL
       
   619 // ParseAndStore ForbiddenSecurityCodes
       
   620 // Status : Approved
       
   621 // ----------------------------------------------------------------------------
       
   622 //
       
   623 TInt CSCPSpecificStringsPlugin::ParseAndStoreL( TDes& aForbiddenSecurityCodes )
       
   624     {
       
   625 	Dprint( (_L("CSCPSpecificStringsPlugin::ParseAndStore()") ));
       
   626 	// Set The file environment
       
   627 	TInt errSC = SetConfigFile ();
       
   628 	if (errSC != KErrNone) return errSC;
       
   629 	
       
   630 
       
   631 	// Make array for data
       
   632 	CDesCArrayFlat*  array = new (ELeave) CDesCArrayFlat(1);
       
   633 	CleanupStack::PushL( array );
       
   634 
       
   635 	// Read the previous wordlist.
       
   636 	// Reading might fall for NotFound, don't care
       
   637 	TInt errGS = GetSpecificStringsArrayL( *array );
       
   638 	
       
   639 	if (errGS != KErrNone && errGS != KErrNotFound  )
       
   640 	    {
       
   641 		// Kill local array
       
   642 		array->Reset();
       
   643 		CleanupStack::PopAndDestroy( array );
       
   644 		return errGS;
       
   645 	    }
       
   646 		
       
   647 	// Parse the ; separated values into array
       
   648 	TLex16 lex (aForbiddenSecurityCodes);
       
   649 	lex.Mark();
       
   650 	while(!lex.Eos())
       
   651 	    {
       
   652 		while(lex.Peek() != ';' && !lex.Eos() ) lex.Inc();
       
   653 
       
   654 		array->AppendL(lex.MarkedToken());
       
   655 		lex.Inc();
       
   656 		lex.Mark();
       
   657 		}
       
   658 		
       
   659 		
       
   660 	// Check for duplicates!
       
   661 	RemoveDuplicateWords( *array );
       
   662 
       
   663 	// Store Array
       
   664 	// Make the ParamObject
       
   665 	CSCPParamObject* forbiddensecuritycodeobject = CSCPParamObject::NewL();
       
   666 	CleanupStack::PushL( forbiddensecuritycodeobject );
       
   667 	TBuf<KSCPPasscodeMaxLength> arrayItem;
       
   668 
       
   669 	// Append the Data 
       
   670 	for (TInt i=0 ; i < array->Count(); i++)
       
   671 		{
       
   672 		arrayItem =  array->MdcaPoint(i);
       
   673 		forbiddensecuritycodeobject->Set( KSpecificStringsParamBase+i,arrayItem);
       
   674 		arrayItem.Zero();
       
   675 		}
       
   676 
       
   677 	// Set the Counter param
       
   678 	forbiddensecuritycodeobject->Set( KSpecificStringsCounterParamID,array->Count());
       
   679 			
       
   680 	//Write
       
   681 	TRAPD( err, forbiddensecuritycodeobject->WriteToFileL( iCfgFilenamepath, iFs ) );
       
   682 	if (  err != KErrNone  )
       
   683 	    {
       
   684 		Dprint( (_L("CSCPSpecificStringsPlugin::ParseAndStore(): WARNING:\
       
   685 		failed to write plugin configuration: %d"), err )); 
       
   686     	}
       
   687 
       
   688     CleanupStack::PopAndDestroy( forbiddensecuritycodeobject );
       
   689     
       
   690     // Kill the array
       
   691 	array->Reset();
       
   692 	CleanupStack::PopAndDestroy( array );
       
   693     
       
   694 	return err;
       
   695 }
       
   696 
       
   697 
       
   698 // ----------------------------------------------------------------------------
       
   699 // CSCPSpecificStringsPlugin::FlushConfigFileL
       
   700 // FlushConfigFile
       
   701 // Status : Approved
       
   702 // ----------------------------------------------------------------------------
       
   703 //
       
   704 TInt CSCPSpecificStringsPlugin::FlushConfigFileL()
       
   705     {
       
   706 	Dprint( (_L("CSCPSpecificStringsPlugin::FlushConfigFile()") ));
       
   707 
       
   708 	SetConfigFile();
       
   709 
       
   710 	CFileMan* fileMan = CFileMan::NewL( *iFs );
       
   711 	CleanupStack::PushL( fileMan );
       
   712 
       
   713 	TInt ret= fileMan->Delete( iCfgFilenamepath, 0 );
       
   714 
       
   715 	CleanupStack::PopAndDestroy( fileMan ); // fileMan
       
   716 	return ret;
       
   717     }
       
   718 
       
   719 
       
   720 // ----------------------------------------------------------------------------
       
   721 // CSCPSpecificStringsPlugin::GetSpecificStringsArrayL
       
   722 // Reads the historyconfig file and retrieves the forbidden data
       
   723 // Status : Approved
       
   724 // ----------------------------------------------------------------------------
       
   725 //
       
   726 TInt CSCPSpecificStringsPlugin::GetSpecificStringsArrayL( CDesCArrayFlat& array )
       
   727 {   
       
   728 
       
   729 	Dprint( (_L("CSCPSpecificStringsPlugin::GetSpecificStringsArray()") ));
       
   730 	
       
   731 	 TBuf<KSCPPasscodeMaxLength> arrayItem;
       
   732 	 TInt counter;
       
   733 	 TInt err = KErrNone;
       
   734 	 
       
   735 	// Make the ParamObject
       
   736 	CSCPParamObject* forbiddensecuritycodeobject = CSCPParamObject::NewL();
       
   737 	CleanupStack::PushL( forbiddensecuritycodeobject );
       
   738 
       
   739 	TRAP( err, forbiddensecuritycodeobject->ReadFromFileL( iCfgFilenamepath, iFs ) );
       
   740 	if ( err != KErrNone ) 
       
   741 	{
       
   742 			// Reading from history fails. 
       
   743 			Dprint( (_L("CSCPHistoryPlugin::GetHistoryArray():\
       
   744 			failed to read plugin configuration: %d"), err )); 
       
   745 			CleanupStack::PopAndDestroy( forbiddensecuritycodeobject );
       
   746 			return err;
       
   747 	}
       
   748 
       
   749 	// Get the historyCount
       
   750 	forbiddensecuritycodeobject->Get(KSpecificStringsCounterParamID,counter);
       
   751 
       
   752 	// Loop them into array
       
   753 	for (TInt i = 0 ; i < counter ; i ++)
       
   754 	{
       
   755 		forbiddensecuritycodeobject->Get(KSpecificStringsParamBase+i,arrayItem);
       
   756 		array.AppendL(arrayItem);
       
   757 		arrayItem.Zero();
       
   758 	}
       
   759 
       
   760     CleanupStack::PopAndDestroy( forbiddensecuritycodeobject );
       
   761 	return err;
       
   762 	
       
   763 }
       
   764 
       
   765 // ----------------------------------------------------------------------------
       
   766 // CSCPSpecificStringsPlugin::IsNotValidWord
       
   767 // Checks wheater the given buf contains any illegal chars like ., <space>
       
   768 // ; char is granted due to a delimiter role. ETrue means buf is no good!
       
   769 // Status : Approved
       
   770 // ----------------------------------------------------------------------------
       
   771 //
       
   772 TBool CSCPSpecificStringsPlugin::IsNotValidWord ( TDes& aForbiddenSecurityCodes )
       
   773 {
       
   774 	
       
   775 	Dprint( (_L("CSCPSpecificStringsPlugin::IsNotValidWord()") ));
       
   776 	// If so, there is a problem ETrue!!
       
   777 	TBool ret;
       
   778 	TChar now,previous;		// at hand & prevous char
       
   779 	ret = EFalse;
       
   780 	now = 0;
       
   781 	previous = 0;
       
   782 	
       
   783 	// Go through the word
       
   784 	for (TInt i=0; i < aForbiddenSecurityCodes.Length(); i++)
       
   785 	{
       
   786 		
       
   787 		// Get the current Char to examine
       
   788 		now =  static_cast<TChar>( aForbiddenSecurityCodes[i] );
       
   789 		// And the previous
       
   790 		if ( i >= 1 ) 
       
   791 		    {
       
   792 		    previous = static_cast<TChar>( aForbiddenSecurityCodes[i-1] );
       
   793 		    }
       
   794 	
       
   795 		// Check for Sapce!
       
   796 		if ( now.IsSpace() || now < 1 || now > 126 )
       
   797 		{
       
   798 			// Space or Invalid character found, bad, out!
       
   799 			ret = ETrue;
       
   800 			break;
       
   801 			
       
   802 		}
       
   803 		
       
   804 		
       
   805 		/*if (! now.IsAlphaDigit() )
       
   806 		{
       
   807 				// Was not alphadigit. Anyhow ; must come through
       
   808 				if ( now != ';'  )
       
   809 				{
       
   810 					// bad, out!
       
   811 					ret = ETrue;
       
   812 					break;
       
   813 				}
       
   814 				
       
   815 				if ( now == ';' && previous == ';'  )
       
   816 				{
       
   817 					// bad, out!
       
   818 					ret = ETrue;
       
   819 					break;
       
   820 				}
       
   821 		
       
   822 		}*/
       
   823 
       
   824 	} // EOFor
       
   825 	return ret;
       
   826 }
       
   827 
       
   828 // ----------------------------------------------------------------------------
       
   829 // CSCPSpecificStringsPlugin::RemoveDuplicateWords
       
   830 // Checks wheater there are duplicate words in the array, removes them!
       
   831 // Status : Approved
       
   832 // ----------------------------------------------------------------------------
       
   833 //
       
   834 void CSCPSpecificStringsPlugin::RemoveDuplicateWords( CDesCArrayFlat& array )
       
   835 {
       
   836 	Dprint( (_L("CSCPSpecificStringsPlugin::RemoveDuplicateWords()") ));
       
   837 	// check for match
       
   838 	TBuf<KSCPPasscodeMaxLength> arrayItemAt;
       
   839 	TBuf<KSCPPasscodeMaxLength> arrayItemNext;
       
   840 	TInt arraycounter =0;
       
   841 	while (arraycounter < array.Count())
       
   842 	{
       
   843 		// Get the item from array.
       
   844 		arrayItemAt =  array.MdcaPoint(arraycounter);	
       
   845 		
       
   846 		// search the rest for match
       
   847 		for (TInt n = 1 + arraycounter ; n < array.Count() ; n++)
       
   848 		{		
       
   849 			arrayItemNext = array.MdcaPoint(n);
       
   850 			if (arrayItemAt.Compare(arrayItemNext) == KErrNone)
       
   851 			{
       
   852 				// Delete 
       
   853 				array.Delete(n);
       
   854 				n--; 
       
   855 				
       
   856 			}
       
   857 		}
       
   858 		arraycounter++;
       
   859 	
       
   860 	}
       
   861 
       
   862 }
       
   863 
       
   864 
       
   865 // ----------------------------------------------------------------------------
       
   866 // CSCPSpecificStringsPlugin::ParseAndRemoveL
       
   867 // Parses And Removes ForbiddenSecurityCodes from ini file
       
   868 // Status : Approved
       
   869 // ----------------------------------------------------------------------------
       
   870 //
       
   871 TInt CSCPSpecificStringsPlugin::ParseAndRemoveL( TDes& aForbiddenSecurityCodes )
       
   872     {
       
   873 	Dprint( (_L("CSCPSpecificStringsPlugin::ParseAndRemoveL()") ));
       
   874 	// Set The file environment
       
   875 	TInt errSC = SetConfigFile ();
       
   876 	if (errSC != KErrNone) return errSC;
       
   877 
       
   878 
       
   879 	// Make array for data
       
   880 	CDesCArrayFlat*  arraycurrent = new (ELeave) CDesCArrayFlat(1);
       
   881 	CleanupStack::PushL( arraycurrent );
       
   882 	
       
   883 	// Read the previous wordlist.
       
   884 	// Reading might fall for NotFound, get out, nothing to do.
       
   885 	if ( GetSpecificStringsArrayL( *arraycurrent ) == KErrNotFound  )
       
   886 	    {
       
   887 	    arraycurrent->Reset();
       
   888 	    CleanupStack::PopAndDestroy( arraycurrent );
       
   889 	    return KErrNone;
       
   890 	    }
       
   891 
       
   892 	// Make array for data for wordlist to be removed
       
   893 	CDesCArrayFlat*  arrayremoved = new (ELeave) CDesCArrayFlat(1);
       
   894 	CleanupStack::PushL( arrayremoved );
       
   895 	
       
   896 	// Parse the ; separated values into array from given wordlist
       
   897 	TLex16 lex (aForbiddenSecurityCodes);
       
   898 	lex.Mark();
       
   899 	while(!lex.Eos())
       
   900 	{
       
   901 		while(lex.Peek() != ';' && !lex.Eos() ) lex.Inc();
       
   902 
       
   903 			arrayremoved->AppendL(lex.MarkedToken());
       
   904 			lex.Inc();
       
   905 			lex.Mark();
       
   906 		}
       
   907 		
       
   908 	// Remove possible duplicates in wordlist
       
   909 	RemoveDuplicateWords( *arrayremoved );
       
   910 	
       
   911 	// Make the ParamObject
       
   912 	CSCPParamObject* forbiddensecuritycodeobject = CSCPParamObject::NewL();
       
   913 	CleanupStack::PushL( forbiddensecuritycodeobject );
       
   914 	
       
   915 	TBuf<KSCPPasscodeMaxLength> arrayItemcurrent;
       
   916 	TBuf<KSCPPasscodeMaxLength> arrayItemremove;
       
   917 	TInt addedcounter,removedcounter,currentItemCounter,err;
       
   918 	TBool itemremovedexlude,itemremovecurrent;
       
   919 	itemremovedexlude = EFalse;
       
   920 	itemremovecurrent = EFalse;
       
   921 	addedcounter = 0;
       
   922 	removedcounter = 0;
       
   923 	err = 0;
       
   924 	
       
   925 	// Remember the current situation before exluding.
       
   926 	currentItemCounter = arraycurrent->Count();
       
   927 	
       
   928 	// Loop the main array
       
   929 	while (addedcounter < arraycurrent->Count())
       
   930 	{
       
   931 		// Get the item from current spesific wordarray.
       
   932 		arrayItemcurrent =  arraycurrent->MdcaPoint(addedcounter);	
       
   933 		while (removedcounter < arrayremoved->Count())
       
   934 		{
       
   935 			
       
   936 			arrayItemremove =  arrayremoved->MdcaPoint(removedcounter);
       
   937 			if(arrayItemcurrent.CompareC(arrayItemremove) == KErrNone)
       
   938 			{
       
   939 				arrayremoved->Delete(removedcounter);
       
   940 				arraycurrent->Delete(addedcounter);
       
   941 				itemremovedexlude = ETrue;
       
   942 				itemremovecurrent = ETrue;
       
   943 			}
       
   944 			if (itemremovedexlude) itemremovedexlude = EFalse;
       
   945 			else removedcounter++;
       
   946 	
       
   947 		}
       
   948 	
       
   949 		if (itemremovecurrent) itemremovecurrent = EFalse;
       
   950 		else addedcounter++;
       
   951 		removedcounter = 0;
       
   952 	}
       
   953 	
       
   954 	// Check wheather there has been eny changes in the current array (removes)
       
   955 	if (currentItemCounter != arraycurrent->Count() )
       
   956 	    {
       
   957 		// All of items were removed, flush the file
       
   958 		if ( arraycurrent->Count() == 0 )
       
   959 		    {
       
   960 		    TRAP_IGNORE( FlushConfigFileL() );
       
   961 		    }
       
   962 		else
       
   963 		    {
       
   964 			// Reuse
       
   965 			arrayItemcurrent.Zero();
       
   966 			// Set the object with fixed array
       
   967 			for (TInt n = 0; n < arraycurrent->Count() ; n++)
       
   968 			{
       
   969 				// Get the item from current spesific wordarray.
       
   970 				arrayItemcurrent =  arraycurrent->MdcaPoint(n);	
       
   971 				forbiddensecuritycodeobject->Set( KSpecificStringsParamBase+n,arrayItemcurrent);
       
   972 			}
       
   973 		
       
   974 			// Set the Counter param
       
   975 			forbiddensecuritycodeobject->Set( KSpecificStringsCounterParamID,arraycurrent->Count());
       
   976 
       
   977 			//Write
       
   978 			TRAP( err, forbiddensecuritycodeobject->WriteToFileL( iCfgFilenamepath, iFs ) );
       
   979 			if (  err != KErrNone  )
       
   980 			    {
       
   981 				Dprint( (_L("CSCPSpecificStringsPlugin::ParseAndRemoveL(): WARNING:\
       
   982 				failed to write plugin configuration: %d"), err )); 
       
   983 			    }			
       
   984 		    }		
       
   985 	    }
       
   986 	
       
   987 	
       
   988 	CleanupStack::PopAndDestroy( forbiddensecuritycodeobject );
       
   989 	
       
   990 	// Kill arrays
       
   991 	arrayremoved->Reset();
       
   992 	CleanupStack::PopAndDestroy( arrayremoved );
       
   993 	
       
   994 	arraycurrent->Reset();
       
   995 	CleanupStack::PopAndDestroy( arraycurrent );			    
       
   996  
       
   997 	return err;
       
   998     }
       
   999     
       
  1000     
       
  1001 // ----------------------------------------------------------------------------
       
  1002 // CSCPSpecificStringsPlugin::LoadAndFormatResL
       
  1003 // Load the given resouce, and format the string according to the TInt parameters
       
  1004 // if given.
       
  1005 // 
       
  1006 // Status : Approved
       
  1007 // ----------------------------------------------------------------------------
       
  1008 //
       
  1009 HBufC* CSCPSpecificStringsPlugin::LoadAndFormatResL( TInt aResId, TInt* aParam1, TInt* aParam2 )
       
  1010     {
       
  1011     HBufC16* resource = NULL;
       
  1012     HBufC* hbuf = NULL;
       
  1013     
       
  1014     resource = LoadResourceLC( aResId );
       
  1015     TInt allocLen = 0;
       
  1016     if ( aParam1 != NULL )
       
  1017         {
       
  1018         allocLen += KSCPMaxIntLength;
       
  1019         }
       
  1020     if ( aParam2 != NULL )
       
  1021         {
       
  1022         allocLen += KSCPMaxIntLength;
       
  1023         }
       
  1024                 
       
  1025 	hbuf = HBufC::NewL( resource->Length() + allocLen );
       
  1026 	
       
  1027 	if ( ( aParam1 == NULL ) && ( aParam2 == NULL ) )
       
  1028 	    {
       
  1029 	    hbuf->Des().Copy( resource->Des() );
       
  1030 	    }
       
  1031 	else
       
  1032 	    {
       
  1033 	    if ( aParam1 == NULL )
       
  1034 	        {
       
  1035 	        hbuf->Des().Format( resource->Des(), *aParam2 );
       
  1036 	        }
       
  1037 	    else if ( aParam2 == NULL )
       
  1038 	        {
       
  1039 	        hbuf->Des().Format(resource->Des(), *aParam1 );
       
  1040 	        }
       
  1041 	    else
       
  1042 	        {
       
  1043 	        hbuf->Des().Format(resource->Des(), *aParam1, *aParam2 );
       
  1044 	        }	    
       
  1045 	    }
       
  1046 								    
       
  1047 	CleanupStack::PopAndDestroy( resource );
       
  1048 	return hbuf;
       
  1049     }    
       
  1050 
       
  1051 // End of File