terminalsecurity/SCP/SCPHistoryPlugin/src/SCPHistoryPlugin.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 9 57a65a3a658c
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
    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 "SCPHistoryPlugin.h"
    25 #include "SCPHistoryPlugin.h"
    26 #include <SCPHistoryPluginLang.rsg>
    26 #include <scphistorypluginlang.rsg>
    27 #include "SCP_IDs.h"
    27 #include "SCP_IDs.h"
    28 
    28 #include <SCPServerInterface.h>
    29 
    29 
    30 // ============================= LOCAL FUNCTIONS  =============================
    30 // ============================= LOCAL FUNCTIONS  =============================
    31 
    31 
    32 // ============================= MEMBER FUNCTIONS =============================
    32 // ============================= MEMBER FUNCTIONS =============================
    33 
    33 
    82 // 
    82 // 
    83 // 
    83 // 
    84 // Status : Approved
    84 // Status : Approved
    85 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
    86 //    
    86 //    
    87 CSCPParamObject* CSCPHistoryPlugin::HandleEvent(TInt aID,
    87 void CSCPHistoryPlugin :: HandleEventL( TInt aID, CSCPParamObject& aParam, CSCPParamObject& aOutParam)
    88         CSCPParamObject& aParam)
    88 	{				
    89     {
    89 	Dprint ( ( _L( "CSCPHistoryPlugin::HandleEvent()" ) ) );
    90     Dprint((_L("CSCPHistoryPlugin::HandleEvent()")));
    90 	
    91     // Make the ParamObject for success ack, Delete later
    91 	if ( iFs == NULL )
    92     CSCPParamObject* retParams = NULL;
    92 	    {
    93 
    93 	    return ; // Eventhandler not available
    94     TBool errRaised;
    94 	    }	
    95     errRaised = EFalse;
    95 		// check for Case
    96 
    96 		
    97     TBool isInvalid = EFalse;
    97 	switch ( aID )
    98 
       
    99     if (iFs == NULL)
       
   100         {
    98         {
   101         return NULL; // Eventhandler not available
    99 
   102         }
   100         case ( KSCPEventValidate ) :
   103 
   101             {            
   104     // check for Case
   102            	// Obtain the paramValue
   105     switch (aID)
   103            	Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventValidate" ) ) );
   106         {
   104 			TInt passhistoryParamValue;
   107 
   105 			passhistoryParamValue = GetHistoryCountParamValue();
   108         case (KSCPEventValidate):
   106 			Dprint ( ( _L( "CSCPHistoryPlugin::HandleEvent passhistoryParamValue = %d" ), passhistoryParamValue ) );
   109             {
   107 			// if all required bounds are zero, there is nothing to do.
   110             // Obtain the paramValue
   108 			if ( passhistoryParamValue != 0)
   111             Dprint((_L("CSCPHistoryPlugin::KSCPEventValidate")));
   109 			    {
   112             TInt passhistoryParamValue;
   110 				// Get the configFile's path.
   113             passhistoryParamValue = GetHistoryCountParamValue();
   111 				// If this fails, there is something badly wrong(Private folder is not there)
   114             Dprint(
   112 				TInt errSCF = SetConfigFile ();
   115                     (_L(
   113 				if (errSCF != KErrNone)
   116                             "CSCPHistoryPlugin::HandleEvent passhistoryParamValue = %d"), passhistoryParamValue));
   114 				{
   117             // if all required bounds are zero, there is nothing to do.
   115 					break; // Break out from Case
   118             if (passhistoryParamValue != 0)
   116 				}
       
   117 
       
   118 				// Get the historyItemCount, If the err is raised, the file is not there
       
   119 				// This will lead to KSCPEventPasswordChanged event and new history file will
       
   120 				// be created
       
   121 				TInt historyItemCounter;
       
   122 				TInt errHC = GetHistoryItemCount( historyItemCounter );
       
   123 				Dprint ( ( _L( "CSCPHistoryPlugin::HandleEvent historyItemCounter = %d" ), historyItemCounter ) );
       
   124 				if (errHC != KErrNone)
       
   125 				{
       
   126 					break; // Break out from Case
       
   127 				}
       
   128 
       
   129 				// continue with the KSCPEventValidate Check
       
   130 
       
   131 				// Get the password from the paramObject
       
   132 				TBuf<KSCPPasscodeMaxLength> seccode;
       
   133 				if ( aParam.Get( KSCPParamPassword, seccode ) != KErrNone )
       
   134 				{
       
   135 					// Nothing to do anymore
       
   136 					Dprint( (_L("CSCPHistoryPlugin::HandleEvent()\
       
   137 					ERROR: KSCPEventValidate/KSCPParamPassword is != KErrNone") ));
       
   138 					break; // Break out from Case
       
   139 				}            
       
   140 				
       
   141 				// Hash  the securitycode	
       
   142 				TBuf<KSCPPasscodeMaxLength> securityhash;
       
   143 				iEventHandler->HashInput(seccode,securityhash);
       
   144 			
       
   145 				// get history
       
   146 				CDesCArrayFlat* array = NULL;
       
   147 				TInt errGH = KErrNone;
       
   148 				
       
   149 				array = new CDesCArrayFlat(1);			
       
   150 				if ( array != NULL )
       
   151 				    {
       
   152 				    TRAPD( err2, errGH = GetHistoryArrayL( *array ) );
       
   153 				    if ( err2 != KErrNone )
       
   154 				        {
       
   155 				        errGH = err2;
       
   156 				        }
       
   157 				    }
       
   158 				else
       
   159 				    {
       
   160 				    errGH = KErrNoMemory;
       
   161 				    }
       
   162 			
       
   163 				// If for some reason err is raised, break out
       
   164 				// If the Historyonfig file get deleted on the fly ex
       
   165 				if (errGH != KErrNone)
       
   166 				    {
       
   167 					array->Reset();
       
   168 					delete array;
       
   169 					break; // Break out from Case
       
   170 				    }
       
   171 				TInt correction;
       
   172 				correction = 0;
       
   173 
       
   174 				if ( array->Count() >=  passhistoryParamValue )
   119                 {
   175                 {
   120                 // Get the configFile's path.
   176                     correction =  array->Count() - passhistoryParamValue;
   121                 // If this fails, there is something badly wrong(Private folder is not there)
   177                 }
   122                 TInt errSCF = SetConfigFile();
   178 				// check for match
   123                 if (errSCF != KErrNone)
   179 				TBuf<KSCPPasscodeMaxLength> arrayItem;
   124                     {
   180 				
   125                     errRaised = ETrue;
   181 				// Set the historyobject
   126                     break; // Break out from Case
   182 				for (TInt i= 0 + correction; i < array->Count(); i++)
   127                     }
   183 				    {
   128 
   184 					arrayItem =  array->MdcaPoint(i);
   129                 // Get the historyItemCount, If the err is raised, the file is not there
   185 					if (arrayItem.Compare(securityhash) == KErrNone)
   130                 // This will lead to KSCPEventPasswordChanged event and new history file will
   186 					    {
   131                 // be created
   187                             aOutParam.Set( KSCPParamStatus, KErrSCPInvalidCode );
   132                 TInt historyItemCounter;
   188                             Dprint ( ( _L( "EDeviceLockHistoryBuffer Failed" ) ) );
   133                 TInt errHC = GetHistoryItemCount(historyItemCounter);
   189                             aOutParam.AddtoFailedPolices(EDeviceLockHistoryBuffer);
   134                 Dprint(
       
   135                         (_L(
       
   136                                 "CSCPHistoryPlugin::HandleEvent historyItemCounter = %d"), historyItemCounter));
       
   137                 if (errHC != KErrNone)
       
   138                     {
       
   139                     errRaised = ETrue;
       
   140                     break; // Break out from Case
       
   141                     }
       
   142 
       
   143                 // continue with the KSCPEventValidate Check
       
   144 
       
   145                 // Get the password from the paramObject
       
   146                 TBuf<KSCPPasscodeMaxLength> seccode;
       
   147                 if (aParam.Get(KSCPParamPassword, seccode) != KErrNone)
       
   148                     {
       
   149                     // Nothing to do anymore
       
   150                     Dprint(
       
   151                             (_L(
       
   152                                     "CSCPHistoryPlugin::HandleEvent()\
       
   153 					ERROR: KSCPEventValidate/KSCPParamPassword is != KErrNone")));
       
   154                     errRaised = ETrue;
       
   155                     break; // Break out from Case
       
   156                     }
       
   157 
       
   158                 // Hash  the securitycode	
       
   159                 TBuf<KSCPPasscodeMaxLength> securityhash;
       
   160                 iEventHandler->HashInput(seccode, securityhash);
       
   161 
       
   162                 // get history
       
   163                 CDesCArrayFlat* array = NULL;
       
   164                 TInt errGH = KErrNone;
       
   165 
       
   166                 array = new CDesCArrayFlat(1);
       
   167                 if (array != NULL)
       
   168                     {
       
   169                     TRAPD(err2, errGH = GetHistoryArrayL(*array));
       
   170                     if (err2 != KErrNone)
       
   171                         {
       
   172                         errGH = err2;
       
   173                         }
       
   174                     }
       
   175                 else
       
   176                     {
       
   177                     errGH = KErrNoMemory;
       
   178                     }
       
   179 
       
   180                 // If for some reason err is raised, break out
       
   181                 // If the Historyonfig file get deleted on the fly ex
       
   182                 if (errGH != KErrNone)
       
   183                     {
       
   184                     errRaised = ETrue;
       
   185                     array->Reset();
       
   186                     delete array;
       
   187                     break; // Break out from Case
       
   188                     }
       
   189                 TInt correction;
       
   190                 correction = 0;
       
   191 
       
   192                 if (array->Count() >= passhistoryParamValue)
       
   193                     {
       
   194                     correction = array->Count() - passhistoryParamValue;
       
   195                     }
       
   196                 // check for match
       
   197                 TBuf<KSCPPasscodeMaxLength> arrayItem;
       
   198 
       
   199                 // Set the historyobject
       
   200                 for (TInt i = 0 + correction; i < array->Count(); i++)
       
   201                     {
       
   202                     arrayItem = array->MdcaPoint(i);
       
   203                     if (arrayItem.Compare(securityhash) == KErrNone)
       
   204                         {
       
   205                         // Get the filesystem for Resource
       
   206                         // If fail, bail out
       
   207                         TInt errgGR = GetResource();
       
   208                         if (errgGR != KErrNone)
       
   209                             {
       
   210                             errRaised = ETrue;
       
   211                             break; // Break out from the For
       
   212                             }
       
   213 
       
   214                         // Prompt buf, iNote can show only 97 chars,
       
   215                         // without ... markings.
       
   216                         HBufC* hbuf = NULL;
       
   217 
       
   218                         if (passhistoryParamValue == 1)
       
   219                             {
       
   220                             isInvalid = ETrue;
       
   221 TRAP_IGNORE                            (
       
   222                                     hbuf = LoadAndFormatResL( R_SET_SEC_CODE_INFO_PREVIOUS );
       
   223                             );
       
   224                             }
       
   225                         else
       
   226                             {
       
   227                             isInvalid = ETrue;
       
   228                             TRAP_IGNORE(
       
   229                                     hbuf = LoadAndFormatResL(
       
   230                                             R_SET_SEC_CODE_INFO_CHECK,
       
   231                                             &passhistoryParamValue );
       
   232                             );
       
   233                             }
       
   234 
       
   235                         if ( isInvalid )
       
   236                             {
       
   237                             // Create the result-object to return
       
   238                             TRAPD( err, retParams = CSCPParamObject::NewL() );
       
   239 
       
   240                             if ( err == KErrNone )
       
   241                                 {
       
   242                                 retParams->Set( KSCPParamStatus, KErrSCPInvalidCode );
       
   243                                 retParams->Set( KSCPParamAction, KSCPActionShowUI );
       
   244                                 retParams->Set( KSCPParamUIMode, KSCPUINote );
       
   245 
       
   246                                 if ( hbuf != NULL )
       
   247                                     {
       
   248                                     TPtr ptr = hbuf->Des();
       
   249                                     retParams->Set( KSCPParamPromptText, ptr );
       
   250                                     delete hbuf;
       
   251                                     }
       
   252                                 }
       
   253 
       
   254                             break;
   190                             break;
   255                             }
       
   256 
       
   257                         } // End of compare IF
   191                         } // End of compare IF
   258                     } // End of For
   192                     } // End of For
   259 
   193 					
   260                 // kill the local
   194                 // kill the local
   261                 array->Reset();
   195                 array->Reset();
   262                 delete array;
   196                 delete array;
   263 
   197 
   264                 } // passhistoryParamValue
   198                 } // passhistoryParamValue
   265 
       
   266             else
       
   267                 {
       
   268                 retParams = NULL;
       
   269                 }
       
   270 
       
   271             break;
   199             break;
   272             } // end of KSCPEventValidate
   200             } // end of KSCPEventValidate
   273 
       
   274         // Someone has changed the Seccode and I need to include it to history
   201         // Someone has changed the Seccode and I need to include it to history
   275         case ( KSCPEventPasswordChanged ) :
   202          case ( KSCPEventPasswordChanged ) :
   276             {
   203 			{																
   277             // Get the configFile's path.
   204 			// Get the configFile's path.
   278             Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventPasswordChanged" ) ) );
   205 			Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventPasswordChanged" ) ) );
   279             TInt errSCF = SetConfigFile ();
   206 			TInt errSCF = SetConfigFile ();
   280             if (errSCF != KErrNone)
   207 			if (errSCF != KErrNone)
   281                 {
   208 			    {
   282                 errRaised = ETrue;
   209 				break; // Break out from the case
   283                 break; // Break out from the case
   210 			    }
   284                 }
   211 			
   285 
   212 			// Get the password from the paramObject
   286             // Get the password from the paramObject
   213      		TBuf<KSCPPasscodeMaxLength> securitycode;
   287             TBuf<KSCPPasscodeMaxLength> securitycode;
       
   288             if ( aParam.Get( KSCPParamPassword, securitycode ) != KErrNone )
   214             if ( aParam.Get( KSCPParamPassword, securitycode ) != KErrNone )
   289                 {
   215                 {
   290                 // Nothing to do anymore
   216             	// Nothing to do anymore
   291                 Dprint( (_L("CSCPHistoryPlugin::HandleEvent()\
   217                	Dprint( (_L("CSCPHistoryPlugin::HandleEvent()\
   292                	ERROR: KSCPEventPasswordChanged/KSCPParamPassword is  != KErrNone") ));
   218                	ERROR: KSCPEventPasswordChanged/KSCPParamPassword is  != KErrNone") ));
   293                 errRaised = ETrue;
   219 				break; // Break out from the Case
   294                 break; // Break out from the Case
   220                 }          
   295                 }
   221 
   296 
   222 			// Hash  the securitycode	
   297             // Hash  the securitycode	
   223 			TBuf<KSCPPasscodeMaxLength> securityhash;
   298             TBuf<KSCPPasscodeMaxLength> securityhash;
   224 			iEventHandler->HashInput(securitycode,securityhash);
   299             iEventHandler->HashInput(securitycode,securityhash);
   225 
   300 
   226 			// Get the historyItemCount, If error occures, File is not there yet, Make one
   301             // Get the historyItemCount, If error occures, File is not there yet, Make one
   227 			TInt historyItemCounter;
   302             TInt historyItemCounter;
   228 			TInt errHC = GetHistoryItemCount( historyItemCounter );
   303             TInt errHC = GetHistoryItemCount( historyItemCounter );
   229 			Dprint ( ( _L( "CSCPHistoryPlugin::HandleEvent historyItemCounter = %d" ), historyItemCounter ) );
   304             Dprint ( ( _L( "CSCPHistoryPlugin::HandleEvent historyItemCounter = %d" ), historyItemCounter ) );
   230 			if (errHC != KErrNone)
   305             if (errHC != KErrNone)
   231 			    {
   306                 {
   232 				// The file does not exist yet (should not happen)
   307                 // The file does not exist yet (should not happen)
   233 				// Make the ParamObject,  Set the New historyData with count of 1
   308                 // Make the ParamObject,  Set the New historyData with count of 1
   234 				CSCPParamObject* historyObject = NULL;
   309                 CSCPParamObject* historyObject = NULL;
   235 				TRAPD( err, historyObject = CSCPParamObject::NewL() );
   310                 TRAPD( err, historyObject = CSCPParamObject::NewL() );
   236 		 		if ( err == KErrNone )
   311                 if ( err == KErrNone )
   237 		 		    {
   312                     {
   238 			 		historyObject->Set(KHistoryCounterParamID,1);
   313                     historyObject->Set(KHistoryCounterParamID,1);
   239     				historyObject->Set(KHistoryItemParamBase,securityhash );
   314                     historyObject->Set(KHistoryItemParamBase,securityhash );
   240                     
   315 
       
   316                     TRAPD( errWC, historyObject->WriteToFileL( iCfgFilenamepath, iFs ) );
   241                     TRAPD( errWC, historyObject->WriteToFileL( iCfgFilenamepath, iFs ) );
   317                     if ( errWC != KErrNone )
   242 					if ( errWC != KErrNone )
   318                         {
   243     					{
   319                         Dprint( (_L("CSCPHistoryPlugin::HandleEvent(): WARNING:\
   244 						Dprint( (_L("CSCPHistoryPlugin::HandleEvent(): WARNING:\
   320 						failed to write plugin configuration: %d"), errWC ));
   245 						failed to write plugin configuration: %d"), errWC ));
   321                         errRaised = ETrue;
   246 						break; // Break out from the Case
   322                         break; // Break out from the Case
   247 	    				}
   323                         }
   248 					delete historyObject;
   324                     delete historyObject;
   249 		 		    }
   325                     }
   250 			    }
   326                 }
   251 			// There are passwords avail.
   327             // There are passwords avail.
   252 			else
   328 
   253 			    {
   329             else
   254 				// Append the new passwords
   330                 {
   255 				TInt err = KErrNone;
   331                 // Append the new passwords
   256 				TRAPD( err2, err = AppendAndWriteSecurityCodeL( securityhash  ) );
   332                 TInt err = KErrNone;
   257 				if ( ( err != KErrNone ) || ( err2 != KErrNone ) )
   333                 TRAPD( err2, err = AppendAndWriteSecurityCodeL( securityhash ) );
   258 				    {
   334                 if ( ( err != KErrNone ) || ( err2 != KErrNone ) )
   259 					break; // Break out from the Case						
   335                     {
   260 				    }										
   336                     errRaised = ETrue;
   261 			    }    					
   337                     break; // Break out from the Case						
   262 			break;
   338                     }
   263 			} // end of KSCPEventPasswordChanged
   339                 }
   264           
   340             break;
   265     	case ( KSCPEventConfigurationQuery ):
   341             } // end of KSCPEventPasswordChanged
   266             {            
   342 
       
   343         case ( KSCPEventConfigurationQuery ):
       
   344             {
       
   345             Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventConfigurationQuery" ) ) );
   267             Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventConfigurationQuery" ) ) );
   346             TInt paramID = -1;
   268         	TInt paramID = -1; 
   347             // Get the ID from the paramObject      
   269             // Get the ID from the paramObject      
   348             if ( aParam.Get( KSCPParamID, paramID ) != KErrNone )
   270             if ( aParam.Get( KSCPParamID, paramID ) != KErrNone )
   349                 {
   271                 {
   350                 // Nothing to do anymore
   272                 // Nothing to do anymore
   351                 break;
   273                 break;
   352                 }
   274                 }            
   353 
   275                     
   354             // 1011
   276             // 1011
   355             if ( paramID == (RTerminalControl3rdPartySession::EPasscodeHistoryBuffer))
   277             if ( paramID == (RTerminalControl3rdPartySession::EPasscodeHistoryBuffer))
   356                 {
   278                 {
   357                 // OK, we're interested, check that the value is valid
   279 				// All of our params are TInts
   358                 TRAPD( err, retParams = CSCPParamObject::NewL() );
   280 				TInt paramValue;
   359                 if ( err != KErrNone )
   281 				if ( aParam.Get( KSCPParamValue, paramValue ) != KErrNone )
   360                     {
   282 				    {
   361                     break; // Nothing we can do
   283 					aOutParam.Set( KSCPParamStatus, KErrGeneral );
       
   284 					break;
       
   285 				    }
       
   286             	            
       
   287 					TInt retStatus = KErrNone;
       
   288 					switch ( paramID )
       
   289 					    {
       
   290 				
       
   291 						case ( RTerminalControl3rdPartySession::EPasscodeHistoryBuffer ):
       
   292 						    {
       
   293 							// Bounds are be be
       
   294 							if ( ( paramValue < KPasscodeHistoryBufferMinValue ) 
       
   295 							|| ( paramValue > KPasscodeHistoryBufferMaxValue ) )                                 
       
   296 							    {
       
   297 								// This is not a valid valuerange
       
   298 								retStatus = KErrArgument;
       
   299 						        }     
       
   300 							           
       
   301 						    break;				
       
   302 						    } // end of case EPasscodeHistoryBuffer
       
   303 					    } // end of switch ( paramID )
       
   304 								
       
   305 			        aOutParam.Set( KSCPParamStatus, retStatus );
   362                     }
   306                     }
   363 
   307 			 break;	            
   364                 // All of our params are TInts
   308 	         } //End of KSCPEventConfigurationQuery Case
   365                 TInt paramValue;
   309             
   366                 if ( aParam.Get( KSCPParamValue, paramValue ) != KErrNone )
   310             
   367                     {
   311           case ( KSCPEventReset ):
   368                     retParams->Set( KSCPParamStatus, KErrGeneral );
   312               {
   369                     break;
   313               Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventReset" ) ) );
   370                     }
   314               // Reset the configuration for this plugin.
   371 
   315               TRAP_IGNORE( FlushConfigFileL() );
   372                 TInt retStatus = KErrNone;
   316               
   373                 switch ( paramID )
   317               break;
   374                     {
   318               }
   375 
   319                           
   376                     case ( RTerminalControl3rdPartySession::EPasscodeHistoryBuffer ):
   320           } // End of  switch ( aID )
   377                         {
       
   378                         // Bounds are be be
       
   379                         if ( ( paramValue < KPasscodeHistoryBufferMinValue )
       
   380                                 || ( paramValue > KPasscodeHistoryBufferMaxValue ) )
       
   381                             {
       
   382                             // This is not a valid valuerange
       
   383                             retStatus = KErrArgument;
       
   384                             }
       
   385 
       
   386                         break;
       
   387                         } // end of case EPasscodeHistoryBuffer
       
   388                     } // end of switch ( paramID )
       
   389 
       
   390                 retParams->Set( KSCPParamStatus, retStatus );
       
   391                 }
       
   392             else
       
   393                 {
       
   394                 retParams = NULL;
       
   395                 }
       
   396 
       
   397             break;
       
   398             } //End of KSCPEventConfigurationQuery Case
       
   399 
       
   400 
       
   401         case ( KSCPEventReset ):
       
   402             {
       
   403             Dprint ( ( _L( "CSCPHistoryPlugin::KSCPEventReset" ) ) );
       
   404             // Reset the configuration for this plugin.
       
   405             TRAP_IGNORE( FlushConfigFileL() );
       
   406 
       
   407             break;
       
   408             }
       
   409 
       
   410         } // End of  switch ( aID )
       
   411 
       
   412     // Check if Any errors were raised and handle it
       
   413     if (errRaised)
       
   414         {
       
   415         if ( retParams != NULL )
       
   416             {
       
   417             delete retParams;
       
   418             }
       
   419         retParams = NULL;
       
   420         }
       
   421 
       
   422     return retParams;
       
   423     }
   321     }
   424 
   322 
   425 // ----------------------------------------------------------------------------
   323 // ----------------------------------------------------------------------------
   426 // CSCPHistoryPlugin::SetEventHandler
   324 // CSCPHistoryPlugin::SetEventHandler
   427 // SetEventHandler
   325 // SetEventHandler
   661 	Dprint ( ( _L( "CSCPHistoryPlugin::GetHistoryCountParamValue passcodehistorycount = %d" ), passcodehistorycount ) );
   559 	Dprint ( ( _L( "CSCPHistoryPlugin::GetHistoryCountParamValue passcodehistorycount = %d" ), passcodehistorycount ) );
   662 	return passcodehistorycount;
   560 	return passcodehistorycount;
   663     }
   561     }
   664 
   562 
   665 // ----------------------------------------------------------------------------
   563 // ----------------------------------------------------------------------------
   666 // CSCPHistoryPlugin::GetResource
       
   667 // GetResource
       
   668 // Status : Approved
       
   669 // ----------------------------------------------------------------------------
       
   670 //
       
   671 
       
   672 TInt CSCPHistoryPlugin::GetResource()
       
   673     {
       
   674  	Dprint( (_L("CSCPSpecificStringsPlugin::GetResource()") ));
       
   675 	// The resource has to be loaded manually since it is not an application.
       
   676           	
       
   677 	TFileName resourceFile;
       
   678 	resourceFile.Append( KDriveZ );
       
   679 	resourceFile.Append( SCPHistoryPluginSrcFile );
       
   680 	BaflUtils::NearestLanguageFile( *iFs, resourceFile );
       
   681 	TRAPD( err, iRf.OpenL( *iFs, resourceFile ) );
       
   682 
       
   683 	if ( err == KErrNone )
       
   684 	    {
       
   685 		TRAP( err, iRf.ConfirmSignatureL() );
       
   686     	}          
       
   687     
       
   688     return err;       
       
   689     }
       
   690 
       
   691 
       
   692 // ----------------------------------------------------------------------------
       
   693 // CSCPHistoryPlugin::LoadResourceLC
       
   694 // GetResource
       
   695 // Status : Approved
       
   696 // ----------------------------------------------------------------------------
       
   697 //
       
   698 HBufC16* CSCPHistoryPlugin::LoadResourceLC ( TInt aResId )
       
   699     {
       
   700 	Dprint( (_L("CSCPHistoryPlugin::LoadResourceLC()") ));
       
   701 
       
   702 	// load the actual resource
       
   703     HBufC8* readBuffer = iRf.AllocReadLC( aResId );
       
   704     // as we are expecting HBufC16...
       
   705     const TPtrC16 ptrReadBuffer( (TText16*) readBuffer->Ptr(),
       
   706                                  ( readBuffer->Length() + 1 ) >> 1 );
       
   707                                  
       
   708     HBufC16* textBuffer=HBufC16::NewL( ptrReadBuffer.Length() );    
       
   709     *textBuffer=ptrReadBuffer;
       
   710     CleanupStack::PopAndDestroy( readBuffer ); // readBuffer
       
   711     CleanupStack::PushL( textBuffer );
       
   712   	return textBuffer;
       
   713     }
       
   714 
       
   715 
       
   716 // ----------------------------------------------------------------------------
       
   717 // CSCPHistoryPlugin::FlushConfigFile
   564 // CSCPHistoryPlugin::FlushConfigFile
   718 // Remove all the other passwords from the file, except the last one (current)
   565 // Remove all the other passwords from the file, except the last one (current)
   719 // 
   566 // 
   720 // Status : Approved
   567 // Status : Approved
   721 // ----------------------------------------------------------------------------
   568 // ----------------------------------------------------------------------------
   760 	CleanupStack::PopAndDestroy( array );
   607 	CleanupStack::PopAndDestroy( array );
   761 	
   608 	
   762 	CleanupStack::PopAndDestroy( historyObject );
   609 	CleanupStack::PopAndDestroy( historyObject );
   763 	
   610 	
   764 	return err;			
   611 	return err;			
   765     }
   612     } 
   766 
       
   767 
       
   768 // ----------------------------------------------------------------------------
       
   769 // CSCPHistoryPlugin::LoadAndFormatResL
       
   770 // Load the given resouce, and format the string according to the TInt parameters
       
   771 // if given.
       
   772 // 
       
   773 // Status : Approved
       
   774 // ----------------------------------------------------------------------------
       
   775 //
       
   776 HBufC* CSCPHistoryPlugin::LoadAndFormatResL( TInt aResId, TInt* aParam1, TInt* aParam2 )
       
   777     {
       
   778     Dprint ( ( _L( "CSCPHistoryPlugin::LoadAndFormatResL()" ) ) );
       
   779     HBufC16* resource = NULL;
       
   780     HBufC* hbuf = NULL;
       
   781     
       
   782     resource = LoadResourceLC( aResId );
       
   783     FormatResourceString (*resource);
       
   784     TInt allocLen = 0;
       
   785     if ( aParam1 != NULL )
       
   786         {
       
   787         allocLen += KSCPMaxIntLength;
       
   788         }
       
   789     if ( aParam2 != NULL )
       
   790         {
       
   791         allocLen += KSCPMaxIntLength;
       
   792         }
       
   793                 
       
   794 	hbuf = HBufC::NewL( resource->Length() + allocLen );
       
   795 	
       
   796 	if ( ( aParam1 == NULL ) && ( aParam2 == NULL ) )
       
   797 	    {
       
   798 	    hbuf->Des().Copy( resource->Des() );
       
   799 	    }
       
   800 	else
       
   801 	    {
       
   802 	    if ( aParam1 == NULL )
       
   803 	        {
       
   804 	        hbuf->Des().Format( resource->Des(), *aParam2 );
       
   805 	        }
       
   806 	    else if ( aParam2 == NULL )
       
   807 	        {
       
   808 	        hbuf->Des().Format(resource->Des(), *aParam1 );
       
   809 	        }
       
   810 	    else
       
   811 	        {
       
   812 	        hbuf->Des().Format(resource->Des(), *aParam1, *aParam2 );
       
   813 	        }	    
       
   814 	    }
       
   815 								    
       
   816 	CleanupStack::PopAndDestroy( resource );
       
   817 	return hbuf;
       
   818     }
       
   819 
       
   820 // ----------------------------------------------------------------------------
       
   821 // CSCPHistoryPlugin::FormatResourceString
       
   822 // The buffer that is passed is formatted to have only %i as a format specifier instead of %N or %0N etc.
       
   823 // 
       
   824 // Status : Approved
       
   825 // ----------------------------------------------------------------------------
       
   826 //  
       
   827 void CSCPHistoryPlugin::FormatResourceString(HBufC16 &aResStr)
       
   828 {
       
   829 		TInt pos = 0;
       
   830 		TInt flag = 0;
       
   831         TPtr16 bufPtr = aResStr.Des();
       
   832         _LIT (mess1, "%N");
       
   833         _LIT (mess2, "%i");
       
   834         _LIT (mess3, "%0N");
       
   835         _LIT (mess4, "%1N");
       
   836                               
       
   837         while ((pos = bufPtr.Find(mess1)) !=KErrNotFound)
       
   838         {
       
   839               bufPtr.Replace(pos,2,mess2); 
       
   840               flag = 1;
       
   841               break;                    
       
   842         }
       
   843                
       
   844         if(flag == 0)
       
   845         {
       
   846               while ((pos = bufPtr.Find(mess3)) != KErrNotFound)
       
   847               {
       
   848               		bufPtr.Replace(pos,3,mess2);
       
   849               }
       
   850                		
       
   851               while ((pos = bufPtr.Find(mess4)) != KErrNotFound)
       
   852               {
       
   853                 	bufPtr.Replace(pos,3,mess2);
       
   854               }
       
   855         }	
       
   856 }
       
   857   
       
   858 // End of File
   613 // End of File