terminalsecurity/SCP/SCPTimestampPlugin/src/SCPTimestampPlugin.cpp
changeset 0 b497e44ab2fc
child 2 5594fba90824
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 <SCPTimestampPluginLang.rsg>
       
    25 #include "SCP_IDs.h"
       
    26 #include <bautils.h>
       
    27 #include <hal.h>
       
    28 #include <AknGlobalNote.h>
       
    29 #include <AknGlobalConfirmationQuery.h>
       
    30 // For wipe
       
    31 #include <starterclient.h>
       
    32 #include <sysutil.h>
       
    33 #include <syslangutil.h>
       
    34 #include <rfsClient.h>
       
    35 #include "DMUtilClient.h"
       
    36 
       
    37 #include "SCPTimestampPlugin.h"
       
    38 #include <featmgr.h>
       
    39 #ifdef RD_MULTIPLE_DRIVE
       
    40 #include <driveinfo.h>
       
    41 #include <pathinfo.h>
       
    42 #include <f32file.h>
       
    43 #endif //RD_MULTIPLE_DRIVEs
       
    44 // CONSTANTS
       
    45 
       
    46 // ============================= LOCAL FUNCTIONS  =============================
       
    47 
       
    48 
       
    49 
       
    50 // ============================= MEMBER FUNCTIONS =============================
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CSCPTimestampPlugin::NewL
       
    54 // Two-phased contructor
       
    55 // 
       
    56 // Status : Approved
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CSCPTimestampPlugin* CSCPTimestampPlugin::NewL()
       
    60     {
       
    61 	CSCPTimestampPlugin* self = new ( ELeave ) CSCPTimestampPlugin();
       
    62 	CleanupStack::PushL( self );
       
    63 	self->ConstructL();
       
    64 	CleanupStack::Pop( self );
       
    65 	
       
    66     Dprint ( ( _L( "( 0x%x ) CSCPPatternPlugin::NewL()" ), self ) );
       
    67 
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CSCPTimestampPlugin::CSCPTimestampPlugin
       
    73 // Constructor
       
    74 //
       
    75 // Status : Approved
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 CSCPTimestampPlugin::CSCPTimestampPlugin()
       
    79     : iEventHandler( NULL ),
       
    80       iConfiguration( NULL ),
       
    81       iResOpen( EFalse )
       
    82     {
       
    83     Dprint ( ( _L( "CSCPTimestampPlugin::CSCPTimestampPlugin()" ) ) );
       
    84     return;
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CSCPTimestampPlugin::ConstructL
       
    89 // 2nd phase constructor
       
    90 // 
       
    91 // Status : Approved
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 void CSCPTimestampPlugin::ConstructL()
       
    95     {   
       
    96     FeatureManager::InitializeLibL();
       
    97 		if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
    98 		{
       
    99     	FeatureManager::UnInitializeLib();
       
   100    		User::Leave( KErrNotSupported );
       
   101   	}
       
   102    	FeatureManager::UnInitializeLib();  
       
   103     Dprint ( ( _L( "CSCPTimestampPlugin::ConstructL()" ) ) );    
       
   104     
       
   105     return;
       
   106     }
       
   107 
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CSCPTimestampPlugin::~CSCPTimestampPlugin
       
   111 // Destructor
       
   112 //
       
   113 // Status : Approved
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 CSCPTimestampPlugin::~CSCPTimestampPlugin()
       
   117     {
       
   118     Dprint( ( _L( "--> CSCPTimestampPlugin::~CSCPTimestampPlugin()" ) ) );
       
   119         
       
   120     iResFile.Close();
       
   121     
       
   122     if ( iConfiguration != NULL )
       
   123         {
       
   124         delete iConfiguration;
       
   125         iConfiguration = NULL;
       
   126         }
       
   127 
       
   128     Dprint( ( _L( "<-- CSCPTimestampPlugin::~CSCPTimestampPlugin()" ) ) );
       
   129     return;
       
   130     }
       
   131     
       
   132     
       
   133     
       
   134 // ----------------------------------------------------------------------------
       
   135 // CSCPTimestampPlugin::HandleEvent
       
   136 // 
       
   137 // 
       
   138 // Status : Approved
       
   139 // ----------------------------------------------------------------------------
       
   140 //    
       
   141 CSCPParamObject* CSCPTimestampPlugin::HandleEvent( TInt aID, CSCPParamObject& aParam )
       
   142 	{		
       
   143 	Dprint ( ( _L( "CSCPTimestampPlugin::HandleEvent()" ) ) );		
       
   144     	
       
   145 	CSCPParamObject* retParams = NULL;
       
   146 	
       
   147 	// Get our current functional configuration
       
   148 	if ( iEventHandler->GetParameters().Get( 
       
   149 	        RTerminalControl3rdPartySession::EPasscodeExpiration, iExpiration ) != KErrNone )
       
   150 	    {
       
   151 	    iExpiration = 0;
       
   152 	    }	    
       
   153 	if ( iEventHandler->GetParameters().Get( 
       
   154 	        RTerminalControl3rdPartySession::EPasscodeMinChangeInterval, iMinInterval) != KErrNone )
       
   155 	    {
       
   156 	    iMinInterval = 0;
       
   157 	    }
       
   158 	if ( iEventHandler->GetParameters().Get( 
       
   159 	        RTerminalControl3rdPartySession::EPasscodeMinChangeTolerance, iMinTolerance) != KErrNone )
       
   160 	    {
       
   161 	    iMinTolerance = 0;
       
   162 	    }
       
   163 	if ( iEventHandler->GetParameters().Get( 
       
   164 	        RTerminalControl3rdPartySession::EPasscodeMaxAttempts, iMaxAttempts ) != KErrNone )
       
   165 	    {
       
   166 	    iMaxAttempts = 0;
       
   167 	    }	    	    
       
   168 	    
       
   169 	if ( !iResOpen )
       
   170 	    {
       
   171 	    // Load the resource file containing the localized texts
       
   172         TInt ret = GetResource();
       
   173         if ( ret == KErrNone )
       
   174             {
       
   175             iResOpen = ETrue;
       
   176             }
       
   177         // We'll continue without the resource if required
       
   178 	    }		    
       
   179 	
       
   180 	switch ( aID )
       
   181 	    {	    	    
       
   182 	    case ( KSCPEventPasswordChangeQuery ):
       
   183 	        {
       
   184 	        if ( iMinInterval > 0 )
       
   185                 {   
       
   186 	            // Ignore errors, the plugin will stay silent on error
       
   187 	            TRAP_IGNORE( IsChangeAllowedL( aParam, retParams ) );
       
   188                 }
       
   189 	        break;
       
   190 	        }
       
   191 	    
       
   192 	    case ( KSCPEventConfigurationQuery ):
       
   193 	        {
       
   194 	        
       
   195 	        TInt paramID;	            	            
       
   196 	            	            
       
   197 	        if ( aParam.Get( KSCPParamID, paramID ) == KErrNone ) 
       
   198 	            {	                
       
   199 	            ConfigurationQuery( paramID, aParam, retParams );
       
   200 	            }
       
   201 	                	                	            
       
   202 	        break;
       
   203 	        }
       
   204 
       
   205 	    case ( KSCPEventPasswordChanged ):
       
   206 	        {	            
       
   207 	        PasswordChanged( aParam, retParams );
       
   208 	        break;
       
   209 	        }
       
   210 
       
   211         case ( KSCPEventAuthenticationAttempted ):
       
   212             {
       
   213             TInt authStatus;
       
   214             if ( aParam.Get( KSCPParamStatus, authStatus ) == KErrNone ) // Ignore errors
       
   215                 {
       
   216                 TBool isSuccess = ( authStatus == KErrNone );
       
   217                 // No return value required in any case
       
   218                 AuthenticationAttempt( isSuccess, aParam, retParams );
       
   219                 }	            
       
   220            	                
       
   221             break;
       
   222             }
       
   223             
       
   224         case ( KSCPEventReset ):
       
   225               {
       
   226               // Reset the configuration for this plugin.
       
   227               if ( ReadConfiguration() == KErrNone )
       
   228                 {
       
   229                 iConfiguration->Reset();
       
   230                 WriteConfiguration();
       
   231                 }
       
   232               
       
   233               break;
       
   234               }            
       
   235             
       
   236         default:
       
   237             // No implementation required, we're not interested in other events
       
   238         break;	            	            
       
   239 	    }	    	    
       
   240 	
       
   241     // The caller will own this pointer from now on   
       
   242     return retParams; 
       
   243 	}
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 // CSCPTimestampPlugin::HandleEvent
       
   247 // 
       
   248 // 
       
   249 // Status : Approved
       
   250 // ----------------------------------------------------------------------------
       
   251 //    
       
   252 void CSCPTimestampPlugin::SetEventHandler( MSCPPluginEventHandler* aHandler )
       
   253 	{
       
   254 	Dprint( ( _L( "CSCPPatternPlugin::SetEventHandler()" ) ) ) ;
       
   255 	iEventHandler = aHandler;
       
   256 	
       
   257 	iFsSession = &(iEventHandler->GetFsSession());	
       
   258 	}	
       
   259 
       
   260 
       
   261 // ----------------------------------------------------------------------------
       
   262 // CSCPTimestampPlugin::IsChangeAllowed()
       
   263 // 
       
   264 // 
       
   265 // Status : Approved
       
   266 // ----------------------------------------------------------------------------
       
   267 // 
       
   268 void CSCPTimestampPlugin::IsChangeAllowedL( CSCPParamObject& aParam, CSCPParamObject*& aRetParams )
       
   269     {  
       
   270     (void)aParam;
       
   271                           
       
   272     Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL()") ));                      
       
   273     TInt ret = KErrNone;
       
   274     
       
   275     if ( ReadConfiguration() != KErrNone )
       
   276         {
       
   277         Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL() ReadConfiguration() != KErrNone RETURNING") ));
       
   278         return; // Someting wrong
       
   279         }    
       
   280     
       
   281     // Check if the change is within the interval
       
   282     TInt ret2 = IsAfter( KSCPIntervalStartTime, iMinInterval, KSCPTypeHours );
       
   283             
       
   284     if ( ret2 == KSCPIsAfter )
       
   285         {
       
   286         // Interval exceeded, change OK
       
   287         Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL() KSCPIsAfter") ));
       
   288         ret = KErrNone;                    
       
   289         }
       
   290     else if ( ret2 == KSCPIsNotAfter )
       
   291         {
       
   292         // Change within the interval, check the tolerance
       
   293         Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL() KSCPIsNotAfter") )); 
       
   294         TInt tolerance = 0;
       
   295         iConfiguration->Get( KSCPUsedTolerance, tolerance ); // ignore errors
       
   296         Dprint( ( _L( "CSCPPatternPlugin::IsChangeAllowedL(): tolerance get: %d"), tolerance ) );                
       
   297         Dprint( ( _L( "CSCPPatternPlugin::IsChangeAllowedL(): iMinTolerance : %d"), iMinTolerance ) );                
       
   298         if ( tolerance >= iMinTolerance )
       
   299             {
       
   300             ret = KErrSCPCodeChangeNotAllowed;
       
   301             Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL() KErrSCPCodeChangeNotAllowed") )); 
       
   302             }
       
   303         
       
   304         // Used tolerance will increment in passwordChanged                
       
   305         }
       
   306     else 
       
   307         {
       
   308         // Error, new interval will start in passwordChanged.
       
   309         Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL() Error, new interval will start in passwordChanged") )); 
       
   310         }                                                                     
       
   311     
       
   312     if ( ret == KErrSCPCodeChangeNotAllowed )
       
   313         {
       
   314         // Code change is not allowed, send the info back to the user
       
   315         aRetParams  = CSCPParamObject::NewL();        
       
   316                         
       
   317         aRetParams->Set( KSCPParamStatus, KErrSCPCodeChangeNotAllowed );			        			        
       
   318         aRetParams->Set( KSCPParamAction, KSCPActionShowUI );
       
   319         aRetParams->Set( KSCPParamUIMode, KSCPUINote );
       
   320         aRetParams->Set( KSCPParamNoteIcon, KSCPUINoteError );
       
   321         
       
   322         HBufC16* resText = NULL;
       
   323         HBufC16* formatBuf = NULL;
       
   324                 
       
   325         Dprint( ( _L( "CSCPPatternPlugin::IsChangeAllowedL(): iMinInterval : %d"), iMinInterval ) );                
       
   326         Dprint( ( _L( "CSCPPatternPlugin::IsChangeAllowedL(): iMinTolerance : %d"), iMinTolerance ) );                 
       
   327         if ( iMinInterval > 1 )
       
   328             {
       
   329             if ( iMinTolerance >1 )
       
   330                 {
       
   331                 Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL(): iMinInterval > 1,iMinTolerance >= 1") ));                      
       
   332                 resText = LoadResourceL( R_SET_SEC_CODE_CHANGE_DAY );
       
   333                 }
       
   334             else
       
   335                 {
       
   336                 Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL(): iMinInterval > 1,iMinTolerance !>= 1") ));                      
       
   337                 resText = LoadResourceL( R_SET_SEC_CODE_CHANGE_HOURS );
       
   338                 }
       
   339             }
       
   340         else
       
   341             if ( iMinTolerance > 1 )
       
   342                 {
       
   343                 Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL(): iMinInterval !> 1,iMinTolerance >= 1") ));                      
       
   344                 resText = LoadResourceL( R_SET_SEC_CODE_CHANGE_TIMES );
       
   345                 }
       
   346             else
       
   347                 {
       
   348                 Dprint( (_L("CSCPTimestampPlugin::IsChangeAllowedL(): iMinInterval !> 1,iMinTolerance !>= 1") ));                      
       
   349                 resText = LoadResourceL( R_SET_SEC_CODE_CHANGE_ONES );
       
   350                 }         
       
   351                 
       
   352         CleanupStack::PushL( resText );
       
   353         
       
   354         formatBuf = HBufC::NewL( resText->Length() + KSCPMaxMinChangeValueLen );
       
   355 		    
       
   356 		TPtr16 bufDes = formatBuf->Des();
       
   357 		
       
   358         if ( iMinInterval > 1 )
       
   359             {
       
   360             if ( iMinTolerance > 1 )
       
   361                 {
       
   362                 bufDes.Format( resText->Des(), iMinTolerance , iMinInterval );
       
   363                 }
       
   364             else
       
   365                 {
       
   366                 bufDes.Format( resText->Des(), iMinInterval );
       
   367                 }
       
   368             }
       
   369         else
       
   370             if ( iMinTolerance > 1 )
       
   371                 {
       
   372                 bufDes.Format( resText->Des(), iMinTolerance  );
       
   373                 }
       
   374             else
       
   375                 {
       
   376                 bufDes.Format( resText->Des() );
       
   377                 }  		    	
       
   378 		            
       
   379         aRetParams->Set( KSCPParamPromptText, bufDes );
       
   380             
       
   381         delete formatBuf;
       
   382 		    
       
   383         CleanupStack::PopAndDestroy( resText );
       
   384         }
       
   385         
       
   386     // No need to write configuration changes            
       
   387     }
       
   388 
       
   389 
       
   390 // ----------------------------------------------------------------------------
       
   391 // CSCPTimestampPlugin::PasswordChanged()
       
   392 // 
       
   393 // 
       
   394 // Status : Approved
       
   395 // ----------------------------------------------------------------------------
       
   396 //    
       
   397 void CSCPTimestampPlugin::PasswordChanged( CSCPParamObject& aParam, CSCPParamObject*& aRetParams )
       
   398     {
       
   399     (void)aParam;
       
   400     (void)aRetParams;    
       
   401     Dprint( (_L("CSCPTimestampPlugin::PasswordChanged()") ));                      
       
   402     TInt err = ReadConfiguration();
       
   403     if ( err == KErrNone )
       
   404         {
       
   405         // Check if immediate expiration is set
       
   406         Dprint( (_L("CSCPTimestampPlugin::PasswordChanged() : ReadConfiguration = KErrNone") ));                      
       
   407         TInt expireNow = 0;
       
   408         if ( iConfiguration->Get( KSCPExpireOnNextCall, expireNow ) == KErrNone )
       
   409             {
       
   410             iConfiguration->Unset( KSCPExpireOnNextCall );
       
   411             }                                
       
   412         
       
   413         TBuf<KSCPMaxInt64Length> timeBuf; 
       
   414         timeBuf.Zero();       
       
   415         
       
   416         // Fetch the current time and fill the buffer
       
   417         TTime curTime;
       
   418         curTime.UniversalTime();
       
   419         
       
   420         timeBuf.AppendNum( curTime.Int64() );
       
   421         
       
   422         if ( iExpiration > 0 )
       
   423             {
       
   424             // Set the last time the password was changed, for expiration
       
   425             iConfiguration->Set( KSCPLastChangeTime, timeBuf );
       
   426             }        
       
   427         Dprint( ( _L( "CSCPPatternPlugin::PasswordChanged(): iMinInterval: %d"), iMinInterval ) );
       
   428         if ( iMinInterval > 0 )
       
   429             {
       
   430             TInt ret = IsAfter( KSCPIntervalStartTime, iMinInterval, KSCPTypeHours );
       
   431             if ( ret == KSCPIsAfter )
       
   432                 {                                                        
       
   433                 // Interval exceeded, start a new interval from here
       
   434                 Dprint( (_L("CSCPTimestampPlugin::PasswordChanged() KSCPIsAfter") ));    
       
   435                 iConfiguration->Set( KSCPIntervalStartTime, timeBuf );
       
   436                 iConfiguration->Set( KSCPUsedTolerance, 1 );
       
   437                 }
       
   438             else if ( ret == KSCPIsNotAfter )
       
   439                 {
       
   440                 // Change within the interval, increment the used tolerance
       
   441                 Dprint( (_L("CSCPTimestampPlugin::PasswordChanged() KSCPIsNotAfter") ));
       
   442                 TInt tolerance = 0;
       
   443                 iConfiguration->Get( KSCPUsedTolerance, tolerance ); //ignore errors, default to 0
       
   444                 Dprint( ( _L( "CSCPPatternPlugin::PasswordChanged(): tolerance get: %d"), tolerance ) );
       
   445                 tolerance++;        
       
   446                 iConfiguration->Set( KSCPUsedTolerance, tolerance );                
       
   447                 Dprint( ( _L( "CSCPPatternPlugin::PasswordChanged(): tolerance set: %d"), tolerance ) );                
       
   448                 }                                                                
       
   449             else // error
       
   450                 {
       
   451                 // No time set, start a new interval from here
       
   452                 Dprint( (_L("CSCPTimestampPlugin::PasswordChanged() error") ));
       
   453                 iConfiguration->Set( KSCPIntervalStartTime, timeBuf );
       
   454                 TInt tolerance = 0;
       
   455                 iConfiguration->Get( KSCPUsedTolerance, tolerance ); //ignore errors, default to 0
       
   456                 Dprint( ( _L( "CSCPPatternPlugin::PasswordChanged(): tolerance get: %d"), tolerance ) );
       
   457                 tolerance++;        
       
   458                 iConfiguration->Set( KSCPUsedTolerance, tolerance );
       
   459                 Dprint( ( _L( "CSCPPatternPlugin::PasswordChanged(): tolerance set: %d"), tolerance ) );  
       
   460                 }                       
       
   461             }        
       
   462         
       
   463         WriteConfiguration();
       
   464         }
       
   465         else
       
   466         {
       
   467             Dprint( (_L("CSCPTimestampPlugin::PasswordChanged() ReadConfiguration() != KErrNone") ));                      
       
   468             Dprint( ( _L( "CSCPPatternPlugin::PasswordChanged(): ReadConfiguration() = %d"), err ) );
       
   469         }
       
   470     }
       
   471 
       
   472 
       
   473 // ----------------------------------------------------------------------------
       
   474 // CSCPTimestampPlugin::AuthenticationAttempt()
       
   475 // 
       
   476 // 
       
   477 // Status : Approved
       
   478 // ----------------------------------------------------------------------------
       
   479 //    
       
   480 void CSCPTimestampPlugin::AuthenticationAttempt( TBool aIsSuccessful, 
       
   481                                                  CSCPParamObject& aParam,
       
   482                                                  CSCPParamObject*& aRetParams )
       
   483     {
       
   484     if ( ReadConfiguration() != KErrNone )
       
   485         {
       
   486         return;
       
   487         }
       
   488         
       
   489     // Check if immediate expiration is set
       
   490     TInt expireNow = 0;
       
   491     iConfiguration->Get( KSCPExpireOnNextCall, expireNow ); // ignore errors  
       
   492     
       
   493     if ( ( iExpiration == 0 ) && ( iMaxAttempts == 0) && ( expireNow == 0 ) )
       
   494         {
       
   495         return; // We have no interest in this call
       
   496         }                
       
   497     
       
   498     if ( aIsSuccessful )
       
   499         {
       
   500         TRAP_IGNORE( SuccessfulAuthenticationL( aParam, aRetParams ) );
       
   501         }
       
   502     else
       
   503         {
       
   504         // Failed authentication attempt
       
   505         if ( iMaxAttempts > 0 )
       
   506             {
       
   507             TInt failedCount = 0;
       
   508             iConfiguration->Get( KSCPFailedAttempts, failedCount ); // ignore errors
       
   509             failedCount++;                        
       
   510         
       
   511             if ( failedCount == iMaxAttempts - 1 )
       
   512                 {
       
   513                 // Warn the user. Only one attempt left. There's no use handling the error
       
   514                 // so we'll just stay silent at this point on failure.
       
   515                 TRAP_IGNORE(                                        
       
   516                     HBufC16* resText = NULL;
       
   517                     resText = LoadResourceL( R_SET_SEC_CODE_WARNING_ATTEMPTS_LEFT );
       
   518                     FormatResourceString(*resText);
       
   519     		        CleanupStack::PushL( resText );
       
   520     		        
       
   521     			    TPtr16 bufDes = resText->Des();
       
   522     			    
       
   523     			    CAknGlobalConfirmationQuery* note = CAknGlobalConfirmationQuery::NewLC();
       
   524     			        			    
       
   525     			    TRequestStatus status;
       
   526     			    note->ShowConfirmationQueryL(status,
       
   527     			    							 bufDes,
       
   528     			    							 R_AVKON_SOFTKEYS_OK_EMPTY,
       
   529     			    							 R_QGN_NOTE_WARNING_ANIM );
       
   530     			    User::WaitForRequest( status );
       
   531                                   			    
       
   532     			    CleanupStack::PopAndDestroy( note );
       
   533     			     
       
   534                     CleanupStack::PopAndDestroy( resText );
       
   535                     );
       
   536                 }
       
   537             else if ( failedCount >= iMaxAttempts )
       
   538                 {
       
   539                 // Try to wipe the device
       
   540                 TRAPD( err, WipeDeviceL( aRetParams ) );
       
   541                 if ( err != KErrNone )
       
   542                     {
       
   543                     Dprint( ( _L( "CSCPPatternPlugin::\
       
   544                         AuthenticationAttempt(): Wipe FAILED :%d"), err ) );
       
   545                     }
       
   546                 }
       
   547             
       
   548             iConfiguration->Set( KSCPFailedAttempts, failedCount );
       
   549             }
       
   550         }
       
   551         
       
   552     WriteConfiguration();        
       
   553     }
       
   554 
       
   555 
       
   556 // ----------------------------------------------------------------------------
       
   557 // CSCPTimestampPlugin::SuccessfulAuthentication()
       
   558 // 
       
   559 // 
       
   560 // Status : Approved
       
   561 // ----------------------------------------------------------------------------
       
   562 //
       
   563 void CSCPTimestampPlugin::SuccessfulAuthenticationL( CSCPParamObject& aParam,
       
   564                                                     CSCPParamObject*& aRetParams )
       
   565     {
       
   566     // Reset the failed attempts -counter
       
   567     if ( iMaxAttempts > 0 )
       
   568         {
       
   569         iConfiguration->Set( KSCPFailedAttempts, 0 );
       
   570         }
       
   571                     
       
   572     // Check context, if the user is already changing the password, don't force it again.
       
   573     TInt context = 0;
       
   574     aParam.Get( KSCPParamContext, context ); // ignore errors
       
   575 
       
   576     // Check if immediate expiration is set
       
   577     TInt expireNow = 0;
       
   578     iConfiguration->Get( KSCPExpireOnNextCall, expireNow ); // ignore errors    
       
   579     
       
   580     // Check if the code should be changed now    
       
   581     if ( ( context != KSCPContextChangePsw ) && 
       
   582          ( ( iExpiration > 0 ) ||  ( expireNow ) ) )
       
   583         {                    
       
   584         if ( ( IsAfter( KSCPLastChangeTime, iExpiration, KSCPTypeDays ) == KSCPIsAfter ) ||
       
   585              ( expireNow ) )
       
   586             {
       
   587             // Force password change                        
       
   588             
       
   589             HBufC16* resText = NULL;
       
   590             TRAPD( err, resText = LoadResourceL( R_SET_SEC_CODE_AGING ) );         
       
   591             FormatResourceString(*resText);        
       
   592             if ( err == KErrNone ) // If this fails, go on anyway to signal the psw change
       
   593                 {
       
   594     	        TPtr16 bufDes = resText->Des();
       
   595                 
       
   596                 TRAP_IGNORE(
       
   597                     CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
   598     		        note->ShowNoteL( EAknGlobalWarningNote, bufDes );
       
   599     		        CleanupStack::PopAndDestroy( note );
       
   600     		        );    	        
       
   601     	        
       
   602     	        // Wait here a while so the dialog won't appear on top of the note
       
   603                 User::After( KSCPNoteTimeout ); 
       
   604                 
       
   605                 delete resText;
       
   606                 }
       
   607             
       
   608             // Refill the parameters to inform the client that the password
       
   609             // should be changed.
       
   610             aRetParams = CSCPParamObject::NewL(); 
       
   611             aRetParams->Set( KSCPParamAction, KSCPActionForceChange );  
       
   612             }
       
   613         }
       
   614     }
       
   615     
       
   616     
       
   617 // ----------------------------------------------------------------------------
       
   618 // CSCPTimestampPlugin::IsAfter()
       
   619 // 
       
   620 // 
       
   621 // Status : Approved
       
   622 // ----------------------------------------------------------------------------
       
   623 //
       
   624 TInt CSCPTimestampPlugin::IsAfter( TInt aConfID, TInt aInterval, TInt aIntType )
       
   625     {
       
   626     TInt ret;
       
   627     Dprint( (_L("CSCPTimestampPlugin::IsAfter()") ));
       
   628     TTime curTime;
       
   629     curTime.UniversalTime();        
       
   630     
       
   631     TBuf<KSCPMaxInt64Length> savedTimeBuf;
       
   632     TInt64 savedTime;
       
   633     ret = iConfiguration->Get( aConfID, savedTimeBuf );
       
   634     if ( ret == KErrNone )
       
   635         {    
       
   636         Dprint( (_L("CSCPTimestampPlugin::IsAfter() iConfiguration->Get == KErrNone") ));    
       
   637         TLex lex( savedTimeBuf );
       
   638         ret = lex.Val( savedTime );
       
   639         if ( ret == KErrNone )
       
   640             {
       
   641             Dprint( (_L("CSCPTimestampPlugin::IsAfter() lex.Val( savedTime ) == KErrNone") ));
       
   642             TTime configTime( savedTime );
       
   643             switch ( aIntType )
       
   644                 {
       
   645                 case ( KSCPTypeMinutes ):
       
   646                     {
       
   647                     Dprint( (_L("CSCPTimestampPlugin::IsAfter() KSCPTypeMinutes") ));
       
   648                     TTimeIntervalMinutes interval = aInterval;
       
   649                     configTime += interval;
       
   650                     break;
       
   651                     }
       
   652                     
       
   653                 case ( KSCPTypeHours ):
       
   654                     {
       
   655                     Dprint( (_L("CSCPTimestampPlugin::IsAfter() KSCPTypeHours") ));
       
   656                     TTimeIntervalHours interval = aInterval;
       
   657                     configTime += interval;                    
       
   658                     break;
       
   659                     }  
       
   660                     
       
   661                 case ( KSCPTypeDays ):
       
   662                     {
       
   663                     Dprint( (_L("CSCPTimestampPlugin::IsAfter() KSCPTypeDays") ));
       
   664                     TTimeIntervalDays interval = aInterval;
       
   665                     configTime += interval;                    
       
   666                     break;
       
   667                     }                                         
       
   668                 }
       
   669 
       
   670             if ( curTime > configTime )
       
   671                 {
       
   672                 ret = KSCPIsAfter;
       
   673                 Dprint( (_L("CSCPTimestampPlugin::IsAfter() ret = KSCPIsAfter") ));
       
   674                 }
       
   675             else
       
   676                 {
       
   677                 ret = KSCPIsNotAfter;
       
   678                 Dprint( (_L("CSCPTimestampPlugin::IsAfter() ret = KSCPIsNotAfter") ));
       
   679                 }
       
   680             }
       
   681         }
       
   682     
       
   683     return ret;
       
   684     }
       
   685     
       
   686 // ----------------------------------------------------------------------------
       
   687 // CSCPTimestampPlugin::ConfigurationQuery()
       
   688 // 
       
   689 // 
       
   690 // Status : Approved
       
   691 // ----------------------------------------------------------------------------
       
   692 //    
       
   693 void CSCPTimestampPlugin::ConfigurationQuery(  TInt aParamID, 
       
   694                                                CSCPParamObject& aParam, 
       
   695                                                CSCPParamObject*& aRetParams )
       
   696     {
       
   697     // First check if this is our ID    
       
   698     if ( ( aParamID == RTerminalControl3rdPartySession::EPasscodeExpiration ) ||
       
   699          ( aParamID == RTerminalControl3rdPartySession::EPasscodeMinChangeTolerance ) ||
       
   700          ( aParamID == RTerminalControl3rdPartySession::EPasscodeMinChangeInterval ) ||
       
   701          ( aParamID == RTerminalControl3rdPartySession::EPasscodeMaxAttempts ) )
       
   702         {
       
   703         // OK, get the value, the parameters above should be TInt:s
       
   704         TInt ret = KErrNone;
       
   705         
       
   706         if ( ReadConfiguration() != KErrNone )
       
   707             {
       
   708             return;
       
   709             }        
       
   710         
       
   711         TInt paramValue;
       
   712         TBool setPrivateStorage = EFalse;        
       
   713         if ( aParam.Get( KSCPParamValue, paramValue ) == KErrNone )
       
   714             {
       
   715             switch ( aParamID )
       
   716                 {
       
   717                 case ( RTerminalControl3rdPartySession::EPasscodeExpiration ):
       
   718                     {
       
   719                     if ( ( paramValue < KSCPExpireImmediately ) || 
       
   720                          ( paramValue > KSCPMaxExpiration) )
       
   721                         {
       
   722                         ret = KErrArgument;
       
   723                         }
       
   724                     else if ( paramValue == 0 )
       
   725                         {
       
   726                         // Feature disabled, remove the stored data
       
   727                         iConfiguration->Unset( KSCPLastChangeTime );
       
   728                         }                        
       
   729                     else if ( paramValue == KSCPExpireImmediately )
       
   730                         {
       
   731                         // Special case, expire immediately, but retain the previous timestamp
       
   732                         iConfiguration->Set( KSCPExpireOnNextCall,  ETrue );
       
   733                         // Tell the server that this param is stored in our private storage
       
   734                         // (note that in KSCPExpireImmediately-case only..)
       
   735                         setPrivateStorage = ETrue;
       
   736                         }
       
   737                     else if ( iExpiration == 0 )
       
   738                         {
       
   739                         // Check activated, start the expiration from this time
       
   740                         Dprint ( ( _L( "CSCPTimestampPlugin::ConfigurationQuery(): Check activated" ) ) );
       
   741                         TTime curTime;
       
   742                         curTime.UniversalTime();
       
   743                         
       
   744                         TBuf<KSCPMaxInt64Length> timeBuf;
       
   745                         timeBuf.Zero();
       
   746                         timeBuf.AppendNum( curTime.Int64() );
       
   747         
       
   748                         // Set this time as the starting point for expiration
       
   749                         iConfiguration->Set( KSCPLastChangeTime, timeBuf );
       
   750                         }
       
   751                         
       
   752                     break;
       
   753                     }
       
   754                         
       
   755                 case ( RTerminalControl3rdPartySession::EPasscodeMinChangeTolerance ):
       
   756                     {
       
   757                     if ( ( paramValue < 0 ) || ( paramValue > KSCPMaxTolerance ) )
       
   758                         {
       
   759                         ret = KErrArgument;
       
   760                         }                         
       
   761 
       
   762                     break;
       
   763                     }
       
   764                         
       
   765                 case ( RTerminalControl3rdPartySession::EPasscodeMinChangeInterval ):
       
   766                     {
       
   767                     if ( ( paramValue < 0 ) || ( paramValue > KSCPMaxInterval ) )
       
   768                         {
       
   769                         ret = KErrArgument;
       
   770                         }
       
   771                    else if ( paramValue == 0 )
       
   772                         {
       
   773                         // Feature disabled, remove the stored data
       
   774                         iConfiguration->Unset( KSCPIntervalStartTime );
       
   775                         iConfiguration->Unset( KSCPUsedTolerance );
       
   776                         }                        
       
   777                         
       
   778                     break;
       
   779                     }
       
   780                         
       
   781                 case ( RTerminalControl3rdPartySession::EPasscodeMaxAttempts ):
       
   782                     {
       
   783                     if ( ( ( paramValue < KSCPMinAttempts ) || 
       
   784                            ( paramValue > KSCPMaxAttempts ) ) &&
       
   785                          ( paramValue != 0 ) )
       
   786                         {
       
   787                         ret = KErrArgument;
       
   788                         }
       
   789                     else if ( iMaxAttempts != paramValue )
       
   790                         {
       
   791                         // Remove the stored data, max attempts always restarts
       
   792                         iConfiguration->Unset( KSCPFailedAttempts );                        
       
   793                         }
       
   794                         
       
   795                     break;
       
   796                     }
       
   797                     
       
   798                 default:
       
   799                     ret = KErrGeneral; // Something is seriously wrong if this is executed
       
   800                     break;                        
       
   801                 } 
       
   802                 
       
   803             WriteConfiguration();                       
       
   804             }
       
   805         else
       
   806             {
       
   807             // Something wrong, and this is our parameter. Signal an error
       
   808             ret = KErrArgument;
       
   809             }       
       
   810         
       
   811         TRAPD( err, aRetParams = CSCPParamObject::NewL() );        
       
   812         if ( err == KErrNone ) // If we can't create a paramObject, there's nothing we can do
       
   813             {
       
   814             aRetParams->Set( KSCPParamStatus, ret );
       
   815             if ( setPrivateStorage )
       
   816                 {
       
   817                 aRetParams->Set( KSCPParamStorage, KSCPStoragePrivate );
       
   818                 }            
       
   819             }  
       
   820         }          
       
   821     }
       
   822     
       
   823     
       
   824     
       
   825 // ----------------------------------------------------------------------------
       
   826 // CSCPTimestampPlugin::WipeDeviceL()
       
   827 // 
       
   828 // 
       
   829 // Status : Approved
       
   830 // ----------------------------------------------------------------------------
       
   831 //     
       
   832 void CSCPTimestampPlugin::WipeDeviceL( CSCPParamObject*& aRetParams )
       
   833     {
       
   834     (void)aRetParams;
       
   835     
       
   836     // First try to format other local drives than C:
       
   837     RRfsClient rfsClient;
       
   838     
       
   839     TInt ret = rfsClient.Connect();
       
   840     
       
   841     if ( ret == KErrNone )
       
   842         {        
       
   843         CleanupClosePushL( rfsClient );    
       
   844  #ifndef RD_MULTIPLE_DRIVE
       
   845         
       
   846         TDriveList list;
       
   847         iFsSession->DriveList( list );
       
   848 
       
   849         TInt   i;
       
   850         TUint8 c = 'A';
       
   851 
       
   852         // Loop through the drives
       
   853         for( i = 0; i < KMaxDrives &&  c < 'I'; i++, c++ )
       
   854             {
       
   855             if( (list[i] != 0) && (c != 'C') )
       
   856                 {
       
   857                 TBuf<KSCPFormatScriptMaxLen> formatScript;
       
   858                 formatScript.Format(KSCPFormatScript, (TUint)c );
       
   859                 Dprint( ( _L( "CSCPPatternPlugin::WipeDeviceL(): Formatting %c:"), c ) );
       
   860                     
       
   861                 ret = rfsClient.RunScriptInDescriptor(formatScript);
       
   862                 
       
   863                 if ( ret != KErrNone )
       
   864                     {
       
   865                     Dprint( ( _L( "CSCPPatternPlugin::WipeDeviceL():\
       
   866                      FAILED to format %c: %d"), c, ret ) );
       
   867                     }
       
   868                 }
       
   869             }
       
   870 #else 
       
   871 		RFs fs;
       
   872     	User::LeaveIfError(fs.Connect());
       
   873    		CleanupClosePushL(fs);
       
   874 		TDriveList driveList;
       
   875  		TInt driveCount;
       
   876  		
       
   877  		//Get list of drives;
       
   878   		User::LeaveIfError( DriveInfo::GetUserVisibleDrives( fs, driveList, driveCount ) );
       
   879   		
       
   880   		TInt driveListLen( driveList.Length() ); 
       
   881   		TInt phoneMemoryDrive( EDriveC );
       
   882    		RFs::CharToDrive( PathInfo::PhoneMemoryRootPath()[0], phoneMemoryDrive );
       
   883   		TDriveNumber driveNumber;
       
   884   		
       
   885   		//Loop through all drives except phonem memory drive
       
   886   		for (TInt i(0); i<driveListLen; ++i)
       
   887   		{
       
   888   			if (driveList[i])
       
   889   			{
       
   890 		  			driveNumber = TDriveNumber(i);
       
   891 		  			if (phoneMemoryDrive != driveNumber)
       
   892 		  			{
       
   893 		  				TBuf<KSCPFormatScriptMaxLen> formatScript;
       
   894 		  				TChar driveLetter;
       
   895 		  				RFs::DriveToChar(i,driveLetter);
       
   896 		                formatScript.Format(KSCPFormatScript, (TUint)driveLetter );
       
   897 		                Dprint( ( _L( "CSCPPatternPlugin::WipeDeviceL(): Formatting %c:"), driveLetter ) );
       
   898 		                    
       
   899 		                ret = rfsClient.RunScriptInDescriptor(formatScript);
       
   900 		                
       
   901 		                if ( ret != KErrNone )
       
   902 		                    {
       
   903 		                    Dprint( ( _L( "CSCPPatternPlugin::WipeDeviceL():\
       
   904 		                     FAILED to format %c: %d"), driveLetter, ret ) );
       
   905 		                    }
       
   906 		  			}
       
   907   			}
       
   908   		}
       
   909   		
       
   910   		CleanupStack::PopAndDestroy();
       
   911 #endif  //RD_MULTIPLE_DRIVE   
       
   912         // In case of deep level RFS, set the default language code
       
   913         // here, before RFS reboot.
       
   914         TInt language( 0 );
       
   915 
       
   916         // If default language is not found, we reset anyway
       
   917         if ( SysLangUtil::GetDefaultLanguage( language ) == KErrNone )
       
   918             {
       
   919             HAL::Set( HALData::ELanguageIndex, language );
       
   920             }
       
   921         
       
   922         // Send NVD_SET_DEFAULT_REQ here, before reboot. Ignore errors.        
       
   923 
       
   924         CleanupStack::PopAndDestroy( &rfsClient );
       
   925         }       
       
   926 
       
   927     // Mark MMC card to be formatted also in bootup
       
   928 	RDMUtil util;
       
   929 	if ( util.Connect() == KErrNone )
       
   930 	    {        
       
   931         TInt err = util.MarkMMCWipe();
       
   932         if( err != KErrNone )
       
   933         	{
       
   934         	// even if not successfull we try to reset as much as possible -> continue
       
   935         	Dprint( ( _L( "CSCPPatternPlugin::WipeDeviceL(): FAILED to mark MMC wipe: %d"), err ) );        	
       
   936         	}    
       
   937         util.Close();
       
   938 	    }	
       
   939 
       
   940     // Reboot with RFS reason  
       
   941 
       
   942         RStarterSession startersession;
       
   943         if( startersession.Connect() == KErrNone )
       
   944             {
       
   945             startersession.Reset( RStarterSession::EDeepRFSReset );
       
   946             startersession.Close();
       
   947             }
       
   948                                            
       
   949     if ( ret != KErrNone )
       
   950         {
       
   951         Dprint( ( _L( "CSCPPatternPlugin::WipeDeviceL(): Rfs FAILED: %d"), ret ) );
       
   952         }                                                         
       
   953     }
       
   954     
       
   955 // ----------------------------------------------------------------------------
       
   956 // CSCPTimestampPlugin::ReadConfiguration()
       
   957 // 
       
   958 // 
       
   959 // Status : Approved
       
   960 // ----------------------------------------------------------------------------
       
   961 // 
       
   962 TInt CSCPTimestampPlugin::ReadConfiguration()
       
   963     {
       
   964     TInt ret = KErrNone;
       
   965     Dprint( (_L("CSCPTimestampPlugin::ReadConfiguration()") ));
       
   966     if ( iConfiguration == NULL )
       
   967         {
       
   968         TRAPD( err, iConfiguration = CSCPParamObject::NewL() );
       
   969         if ( err != KErrNone )
       
   970             {
       
   971             Dprint( (_L("CSCPTimestampPlugin::ReadConfiguration() err != KErrNone") ));
       
   972             return err;
       
   973             }
       
   974 
       
   975         TFileName configFile;
       
   976         TRAP( err, ret = iEventHandler->GetStoragePathL( configFile ) ); 
       
   977         
       
   978         if ( ( err != KErrNone ) && ( ret == KErrNone ) )
       
   979             {
       
   980             Dprint( (_L("CSCPTimestampPlugin::ReadConfiguration() err != KErrNone  &&  ret == KErrNone") ));
       
   981             ret = err;
       
   982             }               
       
   983         
       
   984         if ( ( err == KErrNone ) && ( ret == KErrNone ) )
       
   985             {
       
   986             configFile.Append( KSCPTSConfigFile );
       
   987             TRAP( ret, iConfiguration->ReadFromFileL( configFile, iFsSession ) );
       
   988             Dprint( (_L("CSCPTimestampPlugin::ReadConfiguration() err == KErrNone  &&  ret == KErrNone") ));
       
   989             if ( ret == KErrNotFound )
       
   990                 {
       
   991                 ret = KErrNone; // Not an error, we'll create this file
       
   992                 }
       
   993             }        
       
   994         }
       
   995     
       
   996     return ret;
       
   997     }
       
   998 
       
   999         
       
  1000 // ----------------------------------------------------------------------------
       
  1001 // CSCPTimestampPlugin::WriteConfiguration()
       
  1002 // 
       
  1003 // 
       
  1004 // Status : Approved
       
  1005 // ----------------------------------------------------------------------------
       
  1006 // 
       
  1007 TInt CSCPTimestampPlugin::WriteConfiguration()
       
  1008     {
       
  1009     TInt ret = KErrGeneral;
       
  1010 
       
  1011     if ( iConfiguration != NULL )
       
  1012         {                
       
  1013         TFileName configFile;
       
  1014         TRAPD( err, ret = iEventHandler->GetStoragePathL( configFile ) );
       
  1015         
       
  1016         if ( ( err != KErrNone ) && ( ret == KErrNone ) )
       
  1017             {
       
  1018             ret = err;
       
  1019             }
       
  1020         
       
  1021         if ( ( err == KErrNone ) && ( ret == KErrNone ) )
       
  1022             {
       
  1023             configFile.Append( KSCPTSConfigFile );
       
  1024             TRAP( ret, iConfiguration->WriteToFileL( configFile, iFsSession ) );           
       
  1025             }        
       
  1026         }    
       
  1027     
       
  1028     return ret;    
       
  1029     }
       
  1030     
       
  1031 
       
  1032 
       
  1033 // ----------------------------------------------------------------------------
       
  1034 // CSCPTimestampPlugin::GetResource
       
  1035 // GetResource
       
  1036 //
       
  1037 // Status : Approved
       
  1038 // ----------------------------------------------------------------------------
       
  1039 //
       
  1040 
       
  1041 TInt CSCPTimestampPlugin::GetResource()
       
  1042     {
       
  1043  	Dprint( (_L("CSCPTimestampPlugin::GetResource()") ));
       
  1044 	// The resource has to be loaded manually since this is not an application.
       
  1045         		    
       
  1046     // Build the resource file name and localize it
       
  1047     TFileName resourceFile;
       
  1048     resourceFile.Append( KDriveZ );
       
  1049     resourceFile.Append( KSCPTimestampPluginResFilename );
       
  1050     BaflUtils::NearestLanguageFile( *iFsSession, resourceFile ); 
       
  1051     
       
  1052     TRAPD( err, iResFile.OpenL( *iFsSession, resourceFile ) );
       
  1053 
       
  1054     if ( err == KErrNone )
       
  1055         {
       
  1056         TRAP( err, iResFile.ConfirmSignatureL() );
       
  1057         }               
       
  1058     
       
  1059     return err;
       
  1060     }
       
  1061 
       
  1062 
       
  1063 // ----------------------------------------------------------------------------
       
  1064 // CSCPTimestampPlugin::LoadResourceLC
       
  1065 // 
       
  1066 //
       
  1067 // Status : Approved
       
  1068 // ----------------------------------------------------------------------------
       
  1069 //
       
  1070 HBufC16* CSCPTimestampPlugin::LoadResourceL( TInt aResId )
       
  1071     {
       
  1072 	if ( !iResOpen )
       
  1073 	    {
       
  1074 	    User::Leave( KErrNotReady );
       
  1075 	    }
       
  1076 	    
       
  1077 	Dprint( (_L("CSCPTimestampPlugin::LoadResourceL()") ));
       
  1078 	
       
  1079 	// Load the actual resource
       
  1080     HBufC8* readBuffer = iResFile.AllocReadLC( aResId );
       
  1081     
       
  1082     // As we are expecting HBufC16    
       
  1083     const TPtrC16 ptrReadBuffer( (TText16*) readBuffer->Ptr(),
       
  1084                                  ( readBuffer->Length() + 1 ) >> 1 );
       
  1085                                  
       
  1086     HBufC16* textBuffer = HBufC16::NewL( ptrReadBuffer.Length() );
       
  1087     
       
  1088     *textBuffer = ptrReadBuffer;
       
  1089     
       
  1090     FormatResourceString(*textBuffer);
       
  1091     CleanupStack::PopAndDestroy( readBuffer );
       
  1092   	
       
  1093   	return textBuffer;
       
  1094     }
       
  1095 
       
  1096 // ----------------------------------------------------------------------------
       
  1097 // CSCPTimestampPlugin::FormatResourceString
       
  1098 // The buffer that is passed is formatted to have only %i as a format specifier instead of %N or %0N etc.
       
  1099 // 
       
  1100 // Status : Approved
       
  1101 // ----------------------------------------------------------------------------
       
  1102 //
       
  1103 void CSCPTimestampPlugin::FormatResourceString(HBufC16 &aResStr)
       
  1104 {
       
  1105 		TInt pos = 0;
       
  1106 		TInt flag = 0;
       
  1107         TPtr16 bufPtr = aResStr.Des();
       
  1108         _LIT (mess1, "%N");
       
  1109         _LIT (mess2, "%i");
       
  1110         _LIT (mess3, "%0N");
       
  1111         _LIT (mess4, "%1N");
       
  1112                               
       
  1113         while ((pos = bufPtr.Find(mess1)) !=KErrNotFound)
       
  1114         {
       
  1115               bufPtr.Replace(pos,2,mess2); 
       
  1116               flag = 1;
       
  1117               break;                    
       
  1118         }
       
  1119                
       
  1120         if(flag == 0)
       
  1121         {
       
  1122               while ((pos = bufPtr.Find(mess3)) != KErrNotFound)
       
  1123               {
       
  1124               		bufPtr.Replace(pos,3,mess2);
       
  1125               }
       
  1126                		
       
  1127               while ((pos = bufPtr.Find(mess4)) != KErrNotFound)
       
  1128               {
       
  1129                 	bufPtr.Replace(pos,3,mess2);
       
  1130               }
       
  1131         }	
       
  1132 }
       
  1133 
       
  1134 // End of File