terminalsecurity/SCP/SCPPatternPlugin/src/SCPPatternPlugin.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 #include <featmgr.h>
       
    25 
       
    26 #include "SCPPatternPlugin.h"
       
    27 #include <SCPPatternPluginLang.rsg>
       
    28 #include "SCP_IDs.h"
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 // ============================= LOCAL FUNCTIONS  =============================
       
    34 
       
    35 // ============================= MEMBER FUNCTIONS =============================
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CSCPPatternPlugin::NewL
       
    39 // Two-phased contructor
       
    40 // (static, may leave)
       
    41 // Status : Approved
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CSCPPatternPlugin* CSCPPatternPlugin::NewL()
       
    45     {
       
    46 	CSCPPatternPlugin* self = new ( ELeave ) CSCPPatternPlugin();
       
    47 	CleanupStack::PushL( self );
       
    48 	self->ConstructL();
       
    49 	CleanupStack::Pop( self );
       
    50 	
       
    51     Dprint ( ( _L( "( 0x%x ) CSCPPatternPlugin::NewL()" ), self ) );
       
    52 
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CSCPPatternPlugin::CSCPPatternPlugin
       
    58 // Constructor
       
    59 // Status : Approved
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 CSCPPatternPlugin::CSCPPatternPlugin()   
       
    63     {
       
    64     Dprint ( ( _L( "CSCPPatternPlugin::CSCPPatternPlugin()" ) ) );
       
    65     return;
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CSCPPatternPlugin::ConstructL
       
    70 // 2nd phase construction
       
    71 // (may leave)
       
    72 // Status : Approved
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 void CSCPPatternPlugin::ConstructL()
       
    76     {       
       
    77     FeatureManager::InitializeLibL();
       
    78 	if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
    79 	{
       
    80     	FeatureManager::UnInitializeLib();
       
    81    		User::Leave( KErrNotSupported );
       
    82   	}
       
    83    	FeatureManager::UnInitializeLib();    
       
    84     Dprint ( ( _L( "CSCPPatternPlugin::ConstructL()" ) ) );
       
    85     return;
       
    86     }
       
    87     
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CSCPPatternPlugin::GetResource
       
    91 // GetResource, opens the localisation filesystem
       
    92 // Status : Approved
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 TInt CSCPPatternPlugin::GetResource()
       
    96     {
       
    97  	Dprint( (_L("CSCPPatternPlugin::GetResource()") ));
       
    98 	// The resource has to be loaded manually since it is not an application.        
       
    99 	
       
   100 	if ( iFs == NULL )
       
   101 	    {
       
   102 	    return KErrNotReady;
       
   103 	    }
       
   104 
       
   105     // can't use resource here because it is not added yet....
       
   106     TFileName resourceFile;
       
   107     resourceFile.Append( KDriveZ );
       
   108     resourceFile.Append( SCPPatternPluginSrcFile );
       
   109     BaflUtils::NearestLanguageFile( *iFs, resourceFile );
       
   110     
       
   111     TRAPD( err, 
       
   112         iRf.OpenL( *iFs, resourceFile );
       
   113         iRf.ConfirmSignatureL();
       
   114         );
       
   115         
       
   116     return err;
       
   117     }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // CSCPPatternPlugin::LoadResourceLC
       
   121 // LoadResourceLC, loads the localisation resource
       
   122 // Status : Approved
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 HBufC16* CSCPPatternPlugin::LoadResourceLC( TInt aResId )
       
   126     {
       
   127 	Dprint ( ( _L( "CSCPPatternPlugin::LoadResourceLC()" ) ) );
       
   128 
       
   129 	// load the actual resource
       
   130     HBufC8* readBuffer = iRf.AllocReadLC( aResId );
       
   131     // as we are expecting HBufC16...
       
   132     const TPtrC16 ptrReadBuffer( (TText16*) readBuffer->Ptr(),
       
   133                                  ( readBuffer->Length() + 1 ) >> 1 );
       
   134     HBufC16* textBuffer=HBufC16::NewL( ptrReadBuffer.Length() );    
       
   135     *textBuffer=ptrReadBuffer;
       
   136     CleanupStack::PopAndDestroy( readBuffer ); // readBuffer
       
   137     CleanupStack::PushL( textBuffer );
       
   138   	return textBuffer;
       
   139     }
       
   140 
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CSCPPatternPlugin::~CSCPPatternPlugin
       
   144 // Destructor
       
   145 // Status : Approved
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 CSCPPatternPlugin::~CSCPPatternPlugin()
       
   149     {
       
   150     Dprint( ( _L( "CSCPPatternPlugin::~CSCPPatternPlugin()" ) ) ) ;
       
   151     
       
   152 	// Closes the resource file reader. 
       
   153 	// This function is called after finishing reading all resources
       
   154     iRf.Close();   
       
   155 	
       
   156     return;
       
   157     }
       
   158 // ----------------------------------------------------------------------------
       
   159 // CSCPPatternPlugin::HandleEvent
       
   160 // 
       
   161 // 
       
   162 // Status : Approved
       
   163 // ----------------------------------------------------------------------------
       
   164 //    
       
   165 CSCPParamObject* CSCPPatternPlugin::HandleEvent( TInt aID, CSCPParamObject& aParam )
       
   166 	{	
       
   167 	
       
   168 	Dprint ( ( _L( "CSCPPatternPlugin::HandleEvent()" ) ) );
       
   169 	
       
   170 	// Make the ParamObject for success ack, Delete later
       
   171 	CSCPParamObject* retParams = NULL;
       
   172 		
       
   173 	TBool errRaised;
       
   174 	errRaised = EFalse;
       
   175 	
       
   176 	TBool isInvalid = EFalse;
       
   177 	
       
   178 	// check for Case
       
   179     switch ( aID )
       
   180         {
       
   181         case ( KSCPEventValidate ):
       
   182             {
       
   183 		     // Get required params for bounds
       
   184 			CSCPParamObject& config = iEventHandler->GetParameters();	
       
   185 
       
   186 			TBool argumentError = EFalse;
       
   187 			
       
   188 			// These are the dault values for ThisPlugIn's functions
       
   189 			TInt passcodeminlength, passcodemaxlength, passcodemaxrepeatedcharacters, passcodeminspecialcharacters;
       
   190 			TBool passcoderequireupperandlower, passcoderequirecharsandnumbers, passcodeconsecutivenumbers, passcodedisallowsimple;
       
   191 			
       
   192 			// Get Values with ID's
       
   193 			if ( config.Get( ( RTerminalControl3rdPartySession::EPasscodeMinLength), 
       
   194 				passcodeminlength ) !=  KErrNone )
       
   195 					passcodeminlength = KSCPPasscodeMinLength;
       
   196 			
       
   197 			if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeMaxLength),
       
   198 				 passcodemaxlength ) !=  KErrNone )
       
   199 					passcodemaxlength = KSCPPasscodeMaxLength;
       
   200 			
       
   201 			if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeMaxRepeatedCharacters), 
       
   202 				 passcodemaxrepeatedcharacters	 ) !=  KErrNone )
       
   203 					passcodemaxrepeatedcharacters = 0;
       
   204 			
       
   205 			if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeRequireCharsAndNumbers), 
       
   206 				 passcoderequirecharsandnumbers ) !=  KErrNone )
       
   207 					passcoderequirecharsandnumbers = EFalse;
       
   208 
       
   209 			if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeRequireUpperAndLower), 
       
   210 				 passcoderequireupperandlower ) !=  KErrNone )
       
   211 					passcoderequireupperandlower = EFalse;
       
   212 					
       
   213 			if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeConsecutiveNumbers), 
       
   214 				 passcodeconsecutivenumbers ) !=  KErrNone )
       
   215 					passcodeconsecutivenumbers = EFalse;
       
   216 					
       
   217             if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeMinSpecialCharacters), 
       
   218                  passcodeminspecialcharacters   ) !=  KErrNone )
       
   219                     passcodeminspecialcharacters = 0;
       
   220             		
       
   221             if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeDisallowSimple), 
       
   222                  passcodedisallowsimple ) !=  KErrNone )
       
   223                     passcodedisallowsimple = EFalse;
       
   224 			
       
   225             // Get the password from the paramObject
       
   226             TBuf<KSCPPasscodeMaxLength> password;
       
   227             if ( aParam.Get( KSCPParamPassword, password ) != KErrNone )
       
   228                 {
       
   229                 // Nothing to do anymore
       
   230                 break;
       
   231                 }            
       
   232             
       
   233         	// The first rule is to check if securitycode has any
       
   234         	// forbidden chars, like WhiteSpace etc...
       
   235         	// If so, there is a problem >> KErrArgument
       
   236 			for (TInt c1=0; c1 < password.Length(); c1++)
       
   237 			    {
       
   238 			  TChar ch = static_cast<TChar>( password[c1] );
       
   239 			  TChar::TCategory chCat = ch.GetCategory();
       
   240 			  if ( ch.IsSpace() )
       
   241 				    {   
       
   242 					TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   243 					if ( err == KErrNone )
       
   244 					    {
       
   245 					    retParams->Set( KSCPParamStatus, KErrArgument );    
       
   246 					    }
       
   247 					    					    
       
   248 					argumentError = ETrue;
       
   249 					break;
       
   250 				    }
       
   251 			    }			 
       
   252 						
       
   253 			// Argument failure, not supposed to be! Out!
       
   254         	if (argumentError) break;
       
   255         	
       
   256         
       
   257 			// if all required bounds are zero, there is nothing to do.
       
   258 			if ( passcodemaxlength != 0 || 
       
   259 				 passcodeminlength != 0 ||
       
   260 				 passcodemaxrepeatedcharacters != 0 ||
       
   261 				 passcoderequireupperandlower ||
       
   262 				 passcoderequirecharsandnumbers || 
       
   263 				 passcodeconsecutivenumbers ||
       
   264 				 passcodeminspecialcharacters != 0 ||
       
   265 				 passcodedisallowsimple)
       
   266 			    {			
       
   267 				// Get the filesystem for Resource
       
   268 				// If fail, bail out
       
   269 				TInt errgGR = GetResource();
       
   270 				if (errgGR != KErrNone)
       
   271 				    {
       
   272 					errRaised = ETrue;
       
   273 					break; // Break out 
       
   274 				    }
       
   275 
       
   276 				// Declare the Check flags										
       
   277 				TBool istoosimilar = EFalse;					
       
   278 				TBool consecutively = EFalse;
       
   279 				TBool consecutivechars = ETrue;
       
   280 				TBool singlerepeat = ETrue;
       
   281 						
       
   282 				TInt digitCount = 0;	// for passcoderequirecharsandnumbers
       
   283 				TInt lowerCount = 0;	// for passcoderequireupperandlower
       
   284 				TInt upperCount = 0;	// for passcoderequireupperandlower
       
   285 				TInt alphaCount = 0;	// for passcoderequirecharsandnumbers
       
   286 				TInt specialCount = 0;  // for passcodeminspecialcharacters
       
   287 				TChar temp = '1';
       
   288 			
       
   289 
       
   290 				// Prompt buf, iNote can show only 97 chars,
       
   291 				// without ... markings.
       
   292 				HBufC* hbuf = NULL;
       
   293 				
       
   294 			 	 // Check for required check or not.
       
   295 	        	if (passcodeminlength != 0)
       
   296 	        	    {
       
   297 		        	// check for Min lenght
       
   298 		            if (  password.Length() < passcodeminlength )
       
   299 		                {
       
   300 		                isInvalid = ETrue;
       
   301 		                TRAP_IGNORE(
       
   302 		                    hbuf = LoadAndFormatResL( R_SET_SEC_CODE_MIN, &passcodeminlength ) 
       
   303 		                    );
       
   304 		                }
       
   305 	                }
       
   306 
       
   307 				if (!hbuf)
       
   308 				    {
       
   309 		        	// Check for required check or not.
       
   310 		        	if (passcodemaxlength!=0)
       
   311 		        	    {
       
   312 		        		// Check for Max Lenght
       
   313 	             	    if ( password.Length() > passcodemaxlength )
       
   314 		             	    {
       
   315 		                    isInvalid = ETrue;
       
   316 		                    TRAP_IGNORE(
       
   317 		                        hbuf = LoadAndFormatResL( R_SET_SEC_CODE_MAX, &passcodemaxlength );
       
   318 		                        );
       
   319 		             	    }
       
   320 		           	    }
       
   321 				    }
       
   322  	
       
   323 				if (!hbuf)
       
   324 				    {
       
   325 		  			// Check for required check or not.
       
   326 		  			if ( passcodemaxrepeatedcharacters != 0 )
       
   327 		  			    {
       
   328 			  			// Check for TooManySameChars
       
   329 			  			TRAPD( err, istoosimilar = TooManySameCharsL(password,passcodemaxrepeatedcharacters) );
       
   330 					  	if ( ( err == KErrNone ) && ( istoosimilar ) )
       
   331 					  	    {					  		
       
   332 					  		if ( passcodemaxrepeatedcharacters > 1 )
       
   333 					  		    {
       
   334 		                        isInvalid = ETrue;
       
   335 		                        TRAP_IGNORE(
       
   336 		                            hbuf = LoadAndFormatResL( R_SET_SEC_CODE_REPEATED,
       
   337 					  		                              &passcodemaxrepeatedcharacters );
       
   338 		                            );						  		    						  		    					  		    
       
   339 					  		    }
       
   340 					  		else // passcodemaxrepeatedcharacters == 1
       
   341 					  		    {
       
   342 		                        isInvalid = ETrue;
       
   343 		                        TRAP_IGNORE(
       
   344 		                            hbuf = LoadAndFormatResL( R_SET_SEC_CODE_REPEATED_ONCE );
       
   345 		                            );					  		   
       
   346 					  		    }						  								  				  						
       
   347 					  	    }						  		
       
   348 				  	    }
       
   349 				    }
       
   350 				    
       
   351    		   		if (!hbuf)
       
   352 				    {
       
   353 	   				// Check for Alphadigit
       
   354 	   				if ( passcoderequirecharsandnumbers)
       
   355 	   				    {
       
   356 	   					for (TInt adcounter=0; adcounter < password.Length(); adcounter++)
       
   357 			  			    {						
       
   358 							if ( static_cast<TChar>( password[adcounter] ).IsDigit() ) 
       
   359 						  		digitCount++;
       
   360 							
       
   361 							if ( static_cast<TChar>( password[adcounter] ).IsAlpha() )
       
   362 						  		alphaCount++;
       
   363 						    }
       
   364 						
       
   365 		  				if (digitCount >= password.Length() || alphaCount >= password.Length()
       
   366 		  				           || digitCount == 0 || alphaCount == 0 )
       
   367 		  				    {
       
   368 		                    isInvalid = ETrue;
       
   369 		                    TRAP_IGNORE(
       
   370 		                        hbuf = LoadAndFormatResL( R_SET_SEC_CODE_LETTERS_NUMBERS );
       
   371 		                        );		  				    				  				
       
   372 		  				    }
       
   373 	   				    }	// End of Alphadigit Check
       
   374 				    }
       
   375 				  	
       
   376 				  							
       
   377 				if (!hbuf)
       
   378 			    	{
       
   379 					// passcodeconsecutivenumbers
       
   380 					if (passcodeconsecutivenumbers)
       
   381 					    {
       
   382 						consecutively = consecutivelyCheck(password);
       
   383 
       
   384 						if ( consecutively )
       
   385 						    {
       
   386 		                    isInvalid = ETrue;
       
   387 		                    TRAP_IGNORE(
       
   388 		                        hbuf = LoadAndFormatResL( R_SET_SEC_CODE_CONSECUTIVE );
       
   389 		                        );	
       
   390 						    }
       
   391 					    } 
       
   392 				    }
       
   393         
       
   394         		/*
       
   395         		if (!hbuf)
       
   396 				    {
       
   397 		        	// Check for required check or not.
       
   398 		        	if (passcoderequireupperandlower)
       
   399 		        	    {				        	
       
   400 		        		// Count the IsDigits first and miinus them from the lenghth!
       
   401 		        		// Count the possible NUM's count first!
       
   402 		        		for (TInt numcounter=0; numcounter < password.Length(); numcounter++)
       
   403 			  			    {
       
   404 			  				if ( static_cast<TChar>( password[numcounter] ).IsDigit() )
       
   405 						  		numberCount++;
       
   406 			  			    }
       
   407 
       
   408 		   			// Check for Caps, both
       
   409 		  			for (TInt capscounter=0; capscounter < password.Length(); capscounter++)
       
   410 		  			    {
       
   411 						if ( static_cast<TChar>( password[capscounter] ).IsUpper() )
       
   412 					  		upperCount++;
       
   413 						
       
   414 						if ( static_cast<TChar>( password[capscounter] ).IsLower() )
       
   415 					  		lowerCount++;
       
   416 		  			    }
       
   417 		  			    					  								  			
       
   418                         if (upperCount >= (password.Length()-numberCount ) )
       
   419                         	isallcaps = ETrue;
       
   420 				  			
       
   421 		  				if (lowerCount >= (password.Length() -numberCount) )
       
   422 		  					isallsmall = ETrue;				  			
       
   423 				
       
   424 						if (isallsmall || isallcaps)
       
   425 						    {	  
       
   426 		                    isInvalid = ETrue;
       
   427 		                    TRAP_IGNORE(
       
   428 		                        hbuf = LoadAndFormatResL( R_SET_SEC_CODE_UPPER_LOWER );
       
   429 		                        );			                          							    	  							    
       
   430 						    }	  							    	  							    		
       
   431 			        	}	// End of Caps check
       
   432 				    }
       
   433 				 */	   		   		
       
   434 
       
   435         		if (!hbuf)
       
   436 				    {
       
   437 		        	// Check for required check or not.
       
   438 		        	if (passcoderequireupperandlower)
       
   439 		        	    {
       
   440 		        	    for (TInt counter=0; counter < password.Length(); counter++)
       
   441 		  			    {
       
   442 						if ( static_cast<TChar>( password[counter] ).IsAlpha() )
       
   443 							{
       
   444 							if ( static_cast<TChar>( password[counter] ).IsUpper() )
       
   445 					  		upperCount++;
       
   446 						
       
   447 							if ( static_cast<TChar>( password[counter] ).IsLower() )
       
   448 					  		lowerCount++;
       
   449 							}
       
   450 		  			    }
       
   451 		  			    
       
   452 		  			    if ( upperCount == 0 || lowerCount == 0)
       
   453 		  			    	{
       
   454 		  			    	isInvalid = ETrue;
       
   455 		                    TRAP_IGNORE(
       
   456 		                        hbuf = LoadAndFormatResL( R_SET_SEC_CODE_UPPER_LOWER );
       
   457 		                        );		
       
   458 		  			    	}
       
   459 		        	    }
       
   460 				    }
       
   461 		        	    
       
   462 		        	    				        	
       
   463         		
       
   464         		if (!hbuf)
       
   465         		   {
       
   466                     // Check for required check or not.
       
   467                     if (passcodeminspecialcharacters != 0)
       
   468                         {
       
   469                         for (TInt specialcounter=0; specialcounter< password.Length(); specialcounter++)
       
   470                             {
       
   471                             if ( ! (static_cast<TChar>( password[specialcounter] ).IsAlpha() ) )
       
   472                                 specialCount++;
       
   473                             }
       
   474                         
       
   475                         if ( specialCount < passcodeminspecialcharacters )
       
   476                             {
       
   477                             isInvalid = ETrue;
       
   478                             TRAP_IGNORE(
       
   479                                     hbuf = LoadAndFormatResL( R_SET_SEC_CODE_MIN_SPECIAL_CHARS, 
       
   480                                     &passcodeminspecialcharacters );
       
   481                             );
       
   482                             }
       
   483                         
       
   484                     	}
       
   485         		   }
       
   486         		                
       
   487         		if (!hbuf)
       
   488         		   {
       
   489                     if (passcodedisallowsimple)
       
   490                         {
       
   491                         for (TInt counter=0; counter< (password.Length()-1); counter++)
       
   492                             {
       
   493                             if ( (static_cast<TChar>(password[counter])) != (static_cast<TChar>(password[counter+1])) )
       
   494                                 {
       
   495                                 singlerepeat = EFalse;
       
   496                                 break;
       
   497                                 }
       
   498                             }
       
   499                         if (singlerepeat)
       
   500                             {
       
   501                             isInvalid = ETrue;
       
   502                             TRAP_IGNORE(
       
   503                                     hbuf = LoadAndFormatResL( R_SET_SEC_CODE_SINGLE_REPEAT ) );                            
       
   504                             }
       
   505                         if (!hbuf)
       
   506                             {
       
   507                             for (TInt counter=0; counter< (password.Length()-1); counter++)
       
   508                                 {
       
   509                                 //The consecutivity to be checked with only Alphanumeric characters.
       
   510                                 //The check is being made for only the increasing order. Decreasing order is left for
       
   511                                 //future implementation if needed. Right now it is left out as this will hit the
       
   512                                 //usability of device lock a lot.
       
   513                                 if ( (static_cast<TChar>( password[counter] ).IsAlphaDigit())
       
   514                                         && (static_cast<TChar>( password[counter+1] ).IsAlphaDigit()))
       
   515                                     {
       
   516                                     if ( (static_cast<TChar>(password[counter+1])) - (static_cast<TChar>(password[counter])) != 1 )                      
       
   517                                         {
       
   518                                         consecutivechars = EFalse;
       
   519                                         break;
       
   520                                         }
       
   521                                     }
       
   522                                 else
       
   523                                     {
       
   524                                     consecutivechars = EFalse;
       
   525                                     break;
       
   526                                     }
       
   527                                 }
       
   528                             if (consecutivechars)
       
   529                                 {
       
   530                                 isInvalid = ETrue;
       
   531                                 TRAP_IGNORE(
       
   532                                         hbuf = LoadAndFormatResL( R_SET_SEC_CODE_CONSECUTIVE_CHARS ) );
       
   533                                 }
       
   534                             }
       
   535                         }
       
   536                     }
       
   537 				  	
       
   538 			  	
       
   539 				if ( isInvalid )
       
   540 				    {	    							
       
   541 			    	// Create the result-object to return
       
   542 				    TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   543                     
       
   544                     if ( err == KErrNone )
       
   545 				        {
       
   546 			            retParams->Set( KSCPParamStatus, KErrSCPInvalidCode );
       
   547     		            retParams->Set( KSCPParamAction, KSCPActionShowUI );
       
   548 	    	            retParams->Set( KSCPParamUIMode, KSCPUINote );
       
   549 		                
       
   550 		                if ( hbuf != NULL )
       
   551 		                    {
       
   552 		                    FormatResourceString(*hbuf);	
       
   553 		                    TPtr ptr = hbuf->Des();
       
   554 		                    retParams->Set( KSCPParamPromptText, ptr );
       
   555 		                    delete hbuf;
       
   556 		                    }
       
   557 				        }
       
   558 				    }
       
   559 				    
       
   560                 } // end of All Zero check
       
   561 		    // All params were zero! no check!
       
   562             else 
       
   563                 {
       
   564                 retParams = NULL;
       
   565                 }
       
   566                 			
       
   567             break;  
       
   568             } // KSCPEventValidate
       
   569                 
       
   570         case ( KSCPEventConfigurationQuery ):
       
   571             {            
       
   572             TInt paramID = -1; 
       
   573             
       
   574             // Get the ID from the paramObject      
       
   575             if ( aParam.Get( KSCPParamID, paramID ) != KErrNone )
       
   576                 {
       
   577                 // Nothing to do anymore
       
   578                 break;
       
   579                 }            
       
   580             
       
   581             if ( paramID == (RTerminalControl3rdPartySession::EPasscodeMinLength)
       
   582 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeMaxLength)
       
   583 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeRequireUpperAndLower)
       
   584 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeRequireCharsAndNumbers)
       
   585 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeMaxRepeatedCharacters)
       
   586 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeConsecutiveNumbers )
       
   587 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeMinSpecialCharacters)
       
   588 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeDisallowSimple))
       
   589                 {
       
   590                 
       
   591                 // OK, we're interested, check that the value is valid
       
   592                 TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   593                 
       
   594                 if ( err != KErrNone )
       
   595                     {
       
   596                     break; // Fatal, cannot create paramObject
       
   597                     }
       
   598                 
       
   599                 // All of our params are TInts
       
   600                 TInt paramValue;
       
   601                 if ( aParam.Get( KSCPParamValue, paramValue ) != KErrNone )
       
   602                     {
       
   603                     retParams->Set( KSCPParamStatus, KErrGeneral );
       
   604                     break;
       
   605                     }
       
   606                                 
       
   607                 TInt retStatus = KErrNone;
       
   608                 switch ( paramID )
       
   609                     {
       
   610                         case ( RTerminalControl3rdPartySession::EPasscodeMinLength ):
       
   611                         
       
   612                         	{
       
   613                         		TInt passcodemaxlength;  
       
   614                         		CSCPParamObject& config = iEventHandler->GetParameters();
       
   615                         		if ( config.Get( ( RTerminalControl3rdPartySession::EPasscodeMaxLength), 
       
   616                                              passcodemaxlength ) !=  KErrNone )
       
   617                                              passcodemaxlength = KSCPPasscodeMaxLength;
       
   618                                              
       
   619                         		if ( ( paramValue < KSCPPasscodeMinLength ) || 
       
   620                             	   ( paramValue > KSCPPasscodeMaxLength )|| 
       
   621                             	   ( paramValue > passcodemaxlength ) )
       
   622                         		{
       
   623                         			retStatus = KErrArgument;
       
   624                         		}
       
   625                         	}
       
   626                         break;
       
   627                         
       
   628                         case ( RTerminalControl3rdPartySession::EPasscodeMaxLength ):
       
   629                            
       
   630                            {
       
   631                            	    TInt passcodeminlength;  
       
   632                            	    CSCPParamObject& config = iEventHandler->GetParameters();
       
   633                            	    if ( config.Get( ( RTerminalControl3rdPartySession::EPasscodeMinLength), 
       
   634                                              passcodeminlength ) !=  KErrNone )
       
   635                                              passcodeminlength = KSCPPasscodeMinLength;
       
   636                                              
       
   637                                              
       
   638                         		if ( ( paramValue < KSCPPasscodeMinLength ) || 
       
   639                             	   ( paramValue > KSCPPasscodeMaxLength )|| 
       
   640                             	   ( paramValue < passcodeminlength ) )
       
   641                         		{
       
   642                         			retStatus = KErrArgument;
       
   643                         		}
       
   644                            }
       
   645                         break;
       
   646                         // Flow through: similar values
       
   647                         case ( RTerminalControl3rdPartySession::EPasscodeRequireUpperAndLower ):
       
   648                         case ( RTerminalControl3rdPartySession::EPasscodeConsecutiveNumbers ):
       
   649                         case ( RTerminalControl3rdPartySession::EPasscodeRequireCharsAndNumbers ):
       
   650                         case ( RTerminalControl3rdPartySession::EPasscodeDisallowSimple ):
       
   651                             if ( ( paramValue < 0 ) || 
       
   652                                  ( paramValue > 1 ) )                                 
       
   653                                 {
       
   654                                 // This is not a valid value
       
   655                                 retStatus = KErrArgument;
       
   656                                 }
       
   657                         break;
       
   658 
       
   659                         case ( RTerminalControl3rdPartySession::EPasscodeMaxRepeatedCharacters ):
       
   660                             if ( ( paramValue < 0 ) || 
       
   661                                  ( paramValue > KSCPMaxRepeatAmount ) ) 
       
   662                                 {
       
   663                                 // This is not a valid value
       
   664                                 retStatus = KErrArgument;
       
   665                                 }
       
   666                         break;
       
   667                         
       
   668                         case ( RTerminalControl3rdPartySession::EPasscodeMinSpecialCharacters ):
       
   669                              if ( ( paramValue < 0 ) ||
       
   670                                   ( paramValue > KSCPMinSpecialAmount ) )
       
   671                                  {
       
   672                                  // This is not a valid value
       
   673                                  retStatus = KErrArgument;
       
   674                                  }
       
   675                         break;
       
   676                     }
       
   677                 
       
   678                 retParams->Set( KSCPParamStatus, retStatus );
       
   679                 }
       
   680             else
       
   681                 {
       
   682                 retParams = NULL;
       
   683                 }
       
   684                
       
   685             break;
       
   686             } //KSCPEventConfigurationQuery                         
       
   687         } //  switch ( aID )
       
   688 
       
   689    	// Check if Any errors were raised and handle it
       
   690     if (errRaised) 
       
   691         {
       
   692         if ( retParams != NULL )
       
   693             {
       
   694             delete retParams;
       
   695             }
       
   696         retParams = NULL;
       
   697         }
       
   698         
       
   699     // The caller will own this pointer from now on   
       
   700     return retParams; 
       
   701 	}
       
   702 
       
   703 // ----------------------------------------------------------------------------
       
   704 // CSCPPatternPlugin::SetEventHandler
       
   705 // 
       
   706 // 
       
   707 // Status : Approved
       
   708 // ----------------------------------------------------------------------------
       
   709 //    
       
   710 void CSCPPatternPlugin::SetEventHandler( MSCPPluginEventHandler* aHandler )
       
   711 	{
       
   712 	Dprint( ( _L( "CSCPPatternPlugin::SetEventHandler()" ) ) ) ;
       
   713 	iEventHandler = aHandler;
       
   714 	
       
   715 	iFs = &(iEventHandler->GetFsSession());
       
   716 	}	
       
   717 
       
   718 
       
   719 
       
   720 // ========================= OTHER INTERNAL FUNCTIONS =========================
       
   721 
       
   722 // ----------------------------------------------------------------------------
       
   723 // CSCPPatternPlugin::TooManySameCharsL
       
   724 // 
       
   725 // Status : Approved
       
   726 // ----------------------------------------------------------------------------
       
   727 //
       
   728 TBool CSCPPatternPlugin::TooManySameCharsL ( TDes& aParam, TInt  aMaxRepeatedCharacters)
       
   729     {
       
   730 	Dprint( ( _L( "CSCPPatternPlugin::TooManySameChars()" ) ) );
       
   731              
       
   732     // Make a copy from param
       
   733     // find the first's index's char from the param.
       
   734     // so that the found char get counter incresed and gets 
       
   735     // replaced with KNullDesC
       
   736 
       
   737     // Make copy from securitypass
       
   738     HBufC* hbuf = HBufC::NewLC( aParam.Length());
       
   739     hbuf->Des().Copy( aParam );
       
   740     	
       
   741 	// Declare the loacl vars.
       
   742 	TChar firstChar; 		// char to search for
       
   743 	TInt charIndex = 0;		// locate() index
       
   744 	TInt found = 0;			// Count the specific char's occurenaces
       
   745 	TBool flag = EFalse;	// if there is a char's too maney, break out.
       
   746 	TBool sameCharTooMany = EFalse;
       
   747 	
       
   748 	while (hbuf->Des().Length() >= 1 )
       
   749 		{
       
   750 		// Get the first char 
       
   751 		firstChar = hbuf->Des()[0];
       
   752 			while (charIndex != KErrNotFound)
       
   753 			{
       
   754 					charIndex = hbuf->Des().Locate(firstChar);
       
   755 				    if (charIndex != KErrNotFound)
       
   756 				    {
       
   757 				    	hbuf->Des().Replace( charIndex, 1, KNullDesC );
       
   758 				    	charIndex=0;
       
   759 				    	found++;
       
   760 
       
   761 					    // So the First char is loopt through and deleted from buf
       
   762 						// Check now for immidate fail case
       
   763 					    if (found > aMaxRepeatedCharacters )
       
   764 					    {
       
   765 					    	flag = ETrue;
       
   766 					    	break;
       
   767 					    }
       
   768 				    }
       
   769 				    else if (charIndex == KErrNotFound)
       
   770 				    {
       
   771 				    	// Reset the variables to Reuse.
       
   772 				    	charIndex = 0;
       
   773 				    	found = 0;
       
   774 				    	break;
       
   775 				    } // End of IF
       
   776 				} // end of While
       
   777 					
       
   778 
       
   779 				if (flag)
       
   780 				{
       
   781 					// Rule TooManyChars occured. OUT!
       
   782 					sameCharTooMany = ETrue;
       
   783 					break;
       
   784 				}
       
   785   	  	}// End of While
       
   786 
       
   787   	// Delete the hbuf
       
   788   	CleanupStack::PopAndDestroy( hbuf );
       
   789     return sameCharTooMany;
       
   790     }
       
   791 
       
   792 // ----------------------------------------------------------------------------
       
   793 // CSCPPatternPlugin::consecutivelyCheck
       
   794 // 
       
   795 // Status : Approved
       
   796 // ----------------------------------------------------------------------------
       
   797 //
       
   798 TBool CSCPPatternPlugin::consecutivelyCheck ( TDes& aParam )
       
   799     {
       
   800 	Dprint( ( _L( "CSCPPatternPlugin::consecutivelyCheck()" ) ) );
       
   801     TBool charTooManyInRow = EFalse;
       
   802 	TInt counter = 0;
       
   803 	
       
   804     while ( counter < (aParam.Length()-1 ) )
       
   805         {
       
   806     	if ( ( static_cast<TChar>( aParam[counter] ).IsDigit() ) &&
       
   807     		  ( static_cast<TChar>( aParam[counter+1] ).IsDigit() ) ) 
       
   808     	    {
       
   809     	    charTooManyInRow = ETrue;
       
   810     		break;				
       
   811     	    }
       
   812     	    
       
   813     	counter++;
       
   814         }
       
   815         
       
   816     return charTooManyInRow;
       
   817     }
       
   818     
       
   819 
       
   820 // ----------------------------------------------------------------------------
       
   821 // CSCPPatternPlugin::LoadAndFormatResL
       
   822 // Load the given resouce, and format the string according to the TInt parameters
       
   823 // if given.
       
   824 // 
       
   825 // Status : Approved
       
   826 // ----------------------------------------------------------------------------
       
   827 //
       
   828 HBufC* CSCPPatternPlugin::LoadAndFormatResL( TInt aResId, TInt* aParam1, TInt* aParam2 )
       
   829     {
       
   830     HBufC16* resource = NULL;
       
   831     HBufC* hbuf = NULL;
       
   832     
       
   833     resource = LoadResourceLC( aResId );
       
   834     FormatResourceString(*resource);
       
   835     TInt allocLen = 0;
       
   836     if ( aParam1 != NULL )
       
   837         {
       
   838         allocLen += KSCPMaxIntLength;
       
   839         }
       
   840     if ( aParam2 != NULL )
       
   841         {
       
   842         allocLen += KSCPMaxIntLength;
       
   843         }
       
   844                 
       
   845 	hbuf = HBufC::NewL( resource->Length() + allocLen );
       
   846 	
       
   847 	if ( ( aParam1 == NULL ) && ( aParam2 == NULL ) )
       
   848 	    {
       
   849 	    hbuf->Des().Copy( resource->Des() );
       
   850 	    }
       
   851 	else
       
   852 	    {
       
   853 	    if ( aParam1 == NULL )
       
   854 	        {
       
   855 	        hbuf->Des().Format( resource->Des(), *aParam2 );
       
   856 	        }
       
   857 	    else if ( aParam2 == NULL )
       
   858 	        {
       
   859 	        hbuf->Des().Format(resource->Des(), *aParam1 );
       
   860 	        }
       
   861 	    else
       
   862 	        {
       
   863 	        hbuf->Des().Format(resource->Des(), *aParam1, *aParam2 );
       
   864 	        }	    
       
   865 	    }
       
   866 								    
       
   867 	CleanupStack::PopAndDestroy( resource );
       
   868 	return hbuf;
       
   869     }
       
   870 
       
   871 // ----------------------------------------------------------------------------
       
   872 // CSCPPatternPlugin::FormatResourceString
       
   873 // The buffer that is passed is formatted to have only %i as a format specifier instead of %N or %0N etc.
       
   874 // 
       
   875 // Status : Approved
       
   876 // ----------------------------------------------------------------------------
       
   877 //
       
   878 void CSCPPatternPlugin::FormatResourceString(HBufC16 &aResStr)
       
   879 {
       
   880 		TInt pos = 0;
       
   881 		TInt flag = 0;
       
   882         TPtr16 bufPtr = aResStr.Des();
       
   883         _LIT (mess1, "%N");
       
   884         _LIT (mess2, "%i");
       
   885         _LIT (mess3, "%0N");
       
   886         _LIT (mess4, "%1N");
       
   887                               
       
   888         while ((pos = bufPtr.Find(mess1)) !=KErrNotFound)
       
   889         {
       
   890               bufPtr.Replace(pos,2,mess2); 
       
   891               flag = 1;
       
   892               break;                    
       
   893         }
       
   894                
       
   895         if(flag == 0)
       
   896         {
       
   897               while ((pos = bufPtr.Find(mess3)) != KErrNotFound)
       
   898               {
       
   899               		bufPtr.Replace(pos,3,mess2);
       
   900               }
       
   901                		
       
   902               while ((pos = bufPtr.Find(mess4)) != KErrNotFound)
       
   903               {
       
   904                 	bufPtr.Replace(pos,3,mess2);
       
   905               }
       
   906         }	
       
   907 }    
       
   908 
       
   909 // End of File