diff -r b183ec05bd8c -r 19bba8228ff0 terminalsecurity/SCP/SCPHistoryPlugin/src/SCPSpecificStringsPlugin.cpp --- a/terminalsecurity/SCP/SCPHistoryPlugin/src/SCPSpecificStringsPlugin.cpp Tue Aug 31 16:04:06 2010 +0300 +++ b/terminalsecurity/SCP/SCPHistoryPlugin/src/SCPSpecificStringsPlugin.cpp Wed Sep 01 12:27:42 2010 +0100 @@ -23,10 +23,10 @@ #include #include "SCPSpecificStringsPlugin.h" -#include +#include #include "SCP_IDs.h" #include -#include + // ============================= LOCAL FUNCTIONS ============================= // ============================= MEMBER FUNCTIONS ============================= @@ -90,12 +90,18 @@ // Status : Approved // ---------------------------------------------------------------------------- // -void CSCPSpecificStringsPlugin :: HandleEventL( TInt aID, CSCPParamObject& aParam,CSCPParamObject& aOutParam ) +CSCPParamObject* CSCPSpecificStringsPlugin::HandleEvent( TInt aID, CSCPParamObject& aParam ) { + + // Make the ParamObject for success ack, Delete later + CSCPParamObject* retParams = NULL; + + TBool errRaised; + errRaised = EFalse; if ( iFs == NULL ) { - User::Leave(KErrGeneral); + return NULL; // Eventhandler not available } // check for Case @@ -122,6 +128,7 @@ TInt errSCF = SetConfigFile (); if (errSCF != KErrNone) { + errRaised = ETrue; break; // Break out from Case! } @@ -132,6 +139,7 @@ // Nothing to do anymore Dprint( (_L("CSCPSpecificStringsPlugin::HandleEvent()\ ERROR: KSCPEventPasswordChanged/KSCPParamPassword is != KErrNone") )); + errRaised = ETrue; break; // Break out from the Case!; } @@ -140,16 +148,47 @@ TInt errCSS = CheckSpecificStrings ( securitycode, forbiddensecuritycode ); if (errCSS != KErrNone) { + errRaised = ETrue; break; // Break out from Case! } if ( forbiddensecuritycode ) { - aOutParam.Set( KSCPParamStatus, KErrSCPInvalidCode ); - Dprint ( ( _L( "EDeviceLockDisallowSpecificStrings Failed" ) ) ); - aOutParam.AddtoFailedPolices(EDeviceLockDisallowSpecificStrings); - } + // Word was blacklisted! + // Get the filesystem for Resource + // If fail, bail out! + TInt errgGR = GetResource(); + if (errgGR != KErrNone) + { + errRaised = ETrue; + break; // Break out from the For! + } + + // Prompt buf, iNote can show only 97 chars, + // without ... markings. + HBufC* hbuf = NULL; + TRAP_IGNORE( + hbuf = LoadAndFormatResL( R_SET_SEC_CODE_PERSONAL ); + ); + + // Create the result-object to return + TRAPD( err, retParams = CSCPParamObject::NewL() ); + + if ( err == KErrNone ) + { + retParams->Set( KSCPParamStatus, KErrSCPInvalidCode ); + retParams->Set( KSCPParamAction, KSCPActionShowUI ); + retParams->Set( KSCPParamUIMode, KSCPUINote ); + + if ( hbuf != NULL ) + { + TPtr ptr = hbuf->Des(); + retParams->Set( KSCPParamPromptText, ptr ); + delete hbuf; + } + } + } } // end of specificstringscheck break; @@ -173,9 +212,18 @@ || ( paramID == RTerminalControl3rdPartySession::EPasscodeAllowSpecific) || ( paramID == RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) ) { + TRAPD( err, retParams = CSCPParamObject::NewL() ); + if ( err == KErrNone ) + { Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\ Get not supported for %d" ), paramID ) ); - aOutParam.Set( KSCPParamStatus, KErrNotSupported ); + retParams->Set( KSCPParamStatus, KErrNotSupported ); + } + else + { + Dprint ( ( _L( "CSCPSpecificStringsPlugin::HandleEvent():\ + ERROR: Cannot create paramObject" ) ) ); + } } break; } @@ -196,14 +244,21 @@ || paramID == (RTerminalControl3rdPartySession::EPasscodeDisallowSpecific) || paramID == (RTerminalControl3rdPartySession::EPasscodeAllowSpecific) || paramID == (RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings) ) - { + { + // OK, we're interested + TRAPD( err, retParams = CSCPParamObject::NewL() ); + if ( err != KErrNone ) + { + break; // Nothing we can do now + } + TInt retStatus = KErrNone; if ( paramID != RTerminalControl3rdPartySession::EPasscodeCheckSpecificStrings ) { // Set the storage attribute, so the server won't save the value, // we'll do it ourselves. - aOutParam.Set( KSCPParamStorage, KSCPStoragePrivate ); + retParams->Set( KSCPParamStorage, KSCPStoragePrivate ); } switch ( paramID ) @@ -267,7 +322,9 @@ { retStatus = KErrArgument; break; // from case! - } + } + + errRaised = ETrue; break; // Break out. } break; @@ -325,6 +382,7 @@ break; // from case! } + errRaised = ETrue; break; // Break out. } @@ -334,14 +392,29 @@ case ( RTerminalControl3rdPartySession::EPasscodeClearSpecificStrings ): { // 1018, Flush the config file - - TRAP_IGNORE( FlushConfigFileL() ); + TInt paramValue; + if ( (aParam.Get( KSCPParamValue, paramValue ) != KErrNone) || + ( paramValue < 0 ) || ( paramValue > 1 ) ) + { + retStatus = KErrArgument; + } + + if (paramValue == 1 && retStatus == KErrNone) + { + TRAP_IGNORE( FlushConfigFileL() ); + } + break; } } // End of switch - aOutParam.Set( KSCPParamStatus, retStatus ); + retParams->Set( KSCPParamStatus, retStatus ); } + else + { + retParams = NULL; + } + break; } //End of KSCPEventConfigurationQuery Case @@ -354,6 +427,18 @@ } } // End of switch ( aID ) + + // Check if Any errors were raised and handle it + if (errRaised) + { + if ( retParams != NULL ) + { + delete retParams; + } + retParams = NULL; + } + + return retParams; } // ---------------------------------------------------------------------------- @@ -385,6 +470,60 @@ return; } + + +// ---------------------------------------------------------------------------- +// CSCPSpecificStringsPlugin::GetResource +// GetResource +// Status : Approved +// ---------------------------------------------------------------------------- +// + +TInt CSCPSpecificStringsPlugin::GetResource() + { + Dprint( (_L("CSCPSpecificStringsPlugin::GetResource()") )); + // The resource has to be loaded manually since it is not an application. + + TFileName resourceFile; + resourceFile.Append( KDriveZSpecific ); + resourceFile.Append( SCPSpecificStringsPluginSrcFile ); + BaflUtils::NearestLanguageFile( *iFs, resourceFile ); + TRAPD( err, iRf.OpenL( *iFs, resourceFile ) ); + + if ( err == KErrNone ) + { + TRAP( err, iRf.ConfirmSignatureL() ); + } + + return err; + } + + +// ---------------------------------------------------------------------------- +// CSCPSpecificStringsPlugin::LoadResourceLC +// GetResource +// Status : Approved +// ---------------------------------------------------------------------------- +// +HBufC16* CSCPSpecificStringsPlugin::LoadResourceLC ( TInt aResId ) + { + Dprint( (_L("CSCPSpecificStringsPlugin::LoadResourceLC()") )); + + // load the actual resource + HBufC8* readBuffer = iRf.AllocReadLC( aResId ); + // as we are expecting HBufC16... + const TPtrC16 ptrReadBuffer( (TText16*) readBuffer->Ptr(), + ( readBuffer->Length() + 1 ) >> 1 ); + HBufC16* textBuffer=HBufC16::NewL( ptrReadBuffer.Length() ); + *textBuffer=ptrReadBuffer; + CleanupStack::PopAndDestroy( readBuffer ); // readBuffer + CleanupStack::PushL( textBuffer ); + return textBuffer; + } + + + + // ---------------------------------------------------------------------------- // CSCPSpecificStringsPlugin::SetConfigFile // SetConfigFile @@ -858,4 +997,55 @@ return err; } + +// ---------------------------------------------------------------------------- +// CSCPSpecificStringsPlugin::LoadAndFormatResL +// Load the given resouce, and format the string according to the TInt parameters +// if given. +// +// Status : Approved +// ---------------------------------------------------------------------------- +// +HBufC* CSCPSpecificStringsPlugin::LoadAndFormatResL( TInt aResId, TInt* aParam1, TInt* aParam2 ) + { + HBufC16* resource = NULL; + HBufC* hbuf = NULL; + + resource = LoadResourceLC( aResId ); + TInt allocLen = 0; + if ( aParam1 != NULL ) + { + allocLen += KSCPMaxIntLength; + } + if ( aParam2 != NULL ) + { + allocLen += KSCPMaxIntLength; + } + + hbuf = HBufC::NewL( resource->Length() + allocLen ); + + if ( ( aParam1 == NULL ) && ( aParam2 == NULL ) ) + { + hbuf->Des().Copy( resource->Des() ); + } + else + { + if ( aParam1 == NULL ) + { + hbuf->Des().Format( resource->Des(), *aParam2 ); + } + else if ( aParam2 == NULL ) + { + hbuf->Des().Format(resource->Des(), *aParam1 ); + } + else + { + hbuf->Des().Format(resource->Des(), *aParam1, *aParam2 ); + } + } + + CleanupStack::PopAndDestroy( resource ); + return hbuf; + } + // End of File