terminalsecurity/SCP/SCPHistoryPlugin/src/SCPSpecificStringsPlugin.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
child 27 5cc2995847ea
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
    21 #include <e32std.h>
    21 #include <e32std.h>
    22 #include <ecom/implementationproxy.h>
    22 #include <ecom/implementationproxy.h>
    23 #include <SCPParamObject.h>
    23 #include <SCPParamObject.h>
    24 
    24 
    25 #include "SCPSpecificStringsPlugin.h"
    25 #include "SCPSpecificStringsPlugin.h"
    26 #include <scphistorypluginlang.rsg>
    26 #include <SCPHistoryPluginLang.rsg>
    27 #include "SCP_IDs.h"
    27 #include "SCP_IDs.h"
    28 #include <featmgr.h>
    28 #include <featmgr.h>
    29 #include <SCPServerInterface.h>
    29 
    30 // ============================= LOCAL FUNCTIONS  =============================
    30 // ============================= LOCAL FUNCTIONS  =============================
    31 
    31 
    32 // ============================= MEMBER FUNCTIONS =============================
    32 // ============================= MEMBER FUNCTIONS =============================
    33 
    33 
    34 // ----------------------------------------------------------------------------
    34 // ----------------------------------------------------------------------------
    88 // 
    88 // 
    89 // 
    89 // 
    90 // Status : Approved
    90 // Status : Approved
    91 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
    92 //    
    92 //    
    93 void CSCPSpecificStringsPlugin :: HandleEventL( TInt aID, CSCPParamObject& aParam,CSCPParamObject& aOutParam )
    93 CSCPParamObject* CSCPSpecificStringsPlugin::HandleEvent( TInt aID, CSCPParamObject& aParam )
    94 	{	
    94 	{	
       
    95 	
       
    96 	// Make the ParamObject for success ack, Delete later
       
    97 	CSCPParamObject* retParams = NULL;
       
    98 
       
    99 	TBool errRaised;
       
   100 	errRaised = EFalse;
    95 		
   101 		
    96 	if ( iFs == NULL )
   102 	if ( iFs == NULL )
    97 	    {
   103 	    {
    98 	    User::Leave(KErrGeneral);
   104 	    return NULL; // Eventhandler not available
    99 	    }
   105 	    }
   100 
   106 
   101 	// check for Case
   107 	// check for Case
   102 	switch ( aID )
   108 	switch ( aID )
   103 	    {
   109 	    {
   120 				// Get the configFile's path.
   126 				// Get the configFile's path.
   121 				// If this fails, there is something badly wrong(Private folder is not there)
   127 				// If this fails, there is something badly wrong(Private folder is not there)
   122 				TInt errSCF = SetConfigFile ();
   128 				TInt errSCF = SetConfigFile ();
   123 				if (errSCF != KErrNone)
   129 				if (errSCF != KErrNone)
   124 				    {
   130 				    {
       
   131 					errRaised = ETrue;
   125 					break; // Break out from Case!
   132 					break; // Break out from Case!
   126 				    }
   133 				    }
   127 			 	
   134 			 	
   128 			 	// Get the password from the paramObject
   135 			 	// Get the password from the paramObject
   129 	     		TBuf<KSCPPasscodeMaxLength> securitycode;
   136 	     		TBuf<KSCPPasscodeMaxLength> securitycode;
   130 	            if ( aParam.Get( KSCPParamPassword, securitycode ) != KErrNone )
   137 	            if ( aParam.Get( KSCPParamPassword, securitycode ) != KErrNone )
   131                     {
   138                     {
   132                 	// Nothing to do anymore
   139                 	// Nothing to do anymore
   133                    	Dprint( (_L("CSCPSpecificStringsPlugin::HandleEvent()\
   140                    	Dprint( (_L("CSCPSpecificStringsPlugin::HandleEvent()\
   134                    	ERROR: KSCPEventPasswordChanged/KSCPParamPassword is  != KErrNone") ));
   141                    	ERROR: KSCPEventPasswordChanged/KSCPParamPassword is  != KErrNone") ));
       
   142                 	errRaised = ETrue;
   135 					break; // Break out from the Case!;
   143 					break; // Break out from the Case!;
   136                     }			 	
   144                     }			 	
   137 			 	
   145 			 	
   138 			 	TBool forbiddensecuritycode = EFalse;
   146 			 	TBool forbiddensecuritycode = EFalse;
   139 			 	
   147 			 	
   140 			 	TInt errCSS = CheckSpecificStrings ( securitycode, forbiddensecuritycode );
   148 			 	TInt errCSS = CheckSpecificStrings ( securitycode, forbiddensecuritycode );
   141 			 	if (errCSS != KErrNone)
   149 			 	if (errCSS != KErrNone)
   142 				    {
   150 				    {
       
   151 					errRaised = ETrue;
   143 					break; // Break out from Case!
   152 					break; // Break out from Case!
   144     				}
   153     				}
   145 			 	
   154 			 	
   146 			 	if ( forbiddensecuritycode )
   155 			 	if ( forbiddensecuritycode )
   147 			    	{
   156 			    	{
   148 			    	    aOutParam.Set( KSCPParamStatus, KErrSCPInvalidCode );
   157 			 		// Word was blacklisted!
   149 			    	    Dprint ( ( _L( "EDeviceLockDisallowSpecificStrings Failed" ) ) );
   158 					// Get the filesystem for Resource
   150 			    	    aOutParam.AddtoFailedPolices(EDeviceLockDisallowSpecificStrings);
   159 					// If fail, bail out!
   151 			 	    }			 	    		
   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;
   152 					
   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 			 	    }			 	    		 	
   153 			    } // end of specificstringscheck
   192 			    } // end of specificstringscheck
   154 
   193 
   155 			break;
   194 			break;
   156 		    } // End of KSCPEventValidate
   195 		    } // End of KSCPEventValidate
   157 
   196 
   171 			    
   210 			    
   172 			if ( ( paramID ==  RTerminalControl3rdPartySession::EPasscodeDisallowSpecific )
   211 			if ( ( paramID ==  RTerminalControl3rdPartySession::EPasscodeDisallowSpecific )
   173 				||  ( paramID ==  RTerminalControl3rdPartySession::EPasscodeAllowSpecific)
   212 				||  ( paramID ==  RTerminalControl3rdPartySession::EPasscodeAllowSpecific)
   174 				||  ( paramID ==  RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) )
   213 				||  ( paramID ==  RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) )
   175 			    {
   214 			    {
       
   215 	            TRAPD( err, retParams  = CSCPParamObject::NewL() );
       
   216 	            if ( err == KErrNone )
       
   217 	                {
   176 	                Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\
   218 	                Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\
   177 	                    Get not supported for %d" ), paramID ) );
   219 	                    Get not supported for %d" ), paramID ) );
   178 	                aOutParam.Set( KSCPParamStatus, KErrNotSupported );
   220 	                retParams->Set( KSCPParamStatus, KErrNotSupported );
       
   221 	                }
       
   222 	            else
       
   223 	                {
       
   224 	                Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\
       
   225 	                    ERROR: Cannot create paramObject" ) ) );
       
   226 	                }
   179 	            }
   227 	            }
   180 	        break;
   228 	        break;
   181 	        }
   229 	        }
   182 
   230 
   183 		// same for All plugins
   231 		// same for All plugins
   194 
   242 
   195 			if ( paramID == (RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings)
   243 			if ( paramID == (RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings)
   196 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeDisallowSpecific)
   244 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeDisallowSpecific)
   197 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeAllowSpecific)
   245 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeAllowSpecific)
   198 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) )
   246 				||  paramID ==  (RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) )
   199 			    {
   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                                 
   200 				TInt retStatus = KErrNone;
   255 				TInt retStatus = KErrNone;
   201 				
   256 				
   202 			    if ( paramID != RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings )
   257 			    if ( paramID != RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings )
   203 			        {
   258 			        {
   204         		    // Set the storage attribute, so the server won't save the value,
   259         		    // Set the storage attribute, so the server won't save the value,
   205         		    // we'll do it ourselves.
   260         		    // we'll do it ourselves.
   206         			aOutParam.Set( KSCPParamStorage, KSCPStoragePrivate );			        
   261         			retParams->Set( KSCPParamStorage, KSCPStoragePrivate );			        
   207 			        }
   262 			        }
   208 
   263 
   209 				switch ( paramID )
   264 				switch ( paramID )
   210 				    {
   265 				    {
   211 					case ( RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings ):
   266 					case ( RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings ):
   265 						    {
   320 						    {
   266 							if (errgPS == KErrArgument)
   321 							if (errgPS == KErrArgument)
   267 							    {
   322 							    {
   268 								retStatus = KErrArgument;
   323 								retStatus = KErrArgument;
   269 								break; // from case!
   324 								break; // from case!
   270 							    }	
   325 							    }
       
   326 	
       
   327 							errRaised = ETrue;
   271 							break; // Break out.
   328 							break; // Break out.
   272 						    } 
   329 						    } 
   273 					    break;
   330 					    break;
   274 					    }
   331 					    }
   275 					
   332 					
   323 							    {
   380 							    {
   324 							    retStatus = KErrArgument;
   381 							    retStatus = KErrArgument;
   325 								break; // from case!
   382 								break; // from case!
   326 							    }
   383 							    }
   327 	
   384 	
       
   385 							errRaised = ETrue;
   328 							break; // Break out.
   386 							break; // Break out.
   329 						    } 												
   387 						    } 												
   330 						
   388 						
   331 					    break;
   389 					    break;
   332 					    }												
   390 					    }												
   333 					
   391 					
   334 					case ( RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings ):
   392 					case ( RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings ):
   335 					    {					
   393 					    {					
   336 						// 1018, Flush the config file
   394 						// 1018, Flush the config file
   337 
   395 						TInt paramValue;
   338 					    TRAP_IGNORE( FlushConfigFileL() );
   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 						    
   339 						break;
   407 						break;
   340 					    }							
   408 					    }							
   341     				} // End of switch                          
   409     				} // End of switch                          
   342 
   410 
   343 				aOutParam.Set( KSCPParamStatus, retStatus );
   411 				retParams->Set( KSCPParamStatus, retStatus );
   344 			    }
   412 			    }
       
   413 			else
       
   414 			    {
       
   415 				retParams = NULL;
       
   416 			    }		
       
   417 		         
   345 			break;
   418 			break;
   346 		    } //End of KSCPEventConfigurationQuery Case
   419 		    } //End of KSCPEventConfigurationQuery Case
   347 
   420 
   348         case ( KSCPEventReset ):
   421         case ( KSCPEventReset ):
   349               {
   422               {
   352               
   425               
   353               break;
   426               break;
   354               }
   427               }
   355 
   428 
   356 	} // End of  switch ( aID )
   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; 
   357 	}
   442 	}
   358 
   443 
   359 // ----------------------------------------------------------------------------
   444 // ----------------------------------------------------------------------------
   360 // CSCPSpecificStringsPlugin::SetEventHandler
   445 // CSCPSpecificStringsPlugin::SetEventHandler
   361 // SetEventHandler
   446 // SetEventHandler
   382     
   467     
   383 	iRf.Close();   
   468 	iRf.Close();   
   384         	
   469         	
   385 	return;
   470 	return;
   386     }
   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 
   387 
   526 
   388 // ----------------------------------------------------------------------------
   527 // ----------------------------------------------------------------------------
   389 // CSCPSpecificStringsPlugin::SetConfigFile
   528 // CSCPSpecificStringsPlugin::SetConfigFile
   390 // SetConfigFile
   529 // SetConfigFile
   391 // Status : Approved
   530 // Status : Approved
   856 	CleanupStack::PopAndDestroy( arraycurrent );			    
   995 	CleanupStack::PopAndDestroy( arraycurrent );			    
   857  
   996  
   858 	return err;
   997 	return err;
   859     }
   998     }
   860     
   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 
   861 // End of File
  1051 // End of File