sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\plugins\encrypt\t_enchook.cpp sl@0: // sl@0: // sl@0: sl@0: #include "t_enchook.h" sl@0: #include sl@0: #include "encrypt.h" sl@0: sl@0: _LIT(KEncryptionPluginName, "This is a test encryption plugin"); sl@0: sl@0: sl@0: /** sl@0: Leaving New function for the plugin sl@0: @internalComponent sl@0: */ sl@0: CTestEncryptionHook* CTestEncryptionHook::NewL() sl@0: { sl@0: return new(ELeave) CTestEncryptionHook; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Constructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CTestEncryptionHook::CTestEncryptionHook() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: The destructor for the test encryptplugin hook. This would sl@0: not be a part of a normal encryption plugin implementation as sl@0: normal encryption plugins cannot be unloaded - it must be sl@0: provided in the test encryption plugin server so that it can sl@0: be tested with the F32 test suite. sl@0: @internalComponent sl@0: */ sl@0: CTestEncryptionHook::~CTestEncryptionHook() sl@0: { sl@0: iFs.Close(); sl@0: } sl@0: sl@0: /** sl@0: Initialise the encryption plugin. sl@0: @internalComponent sl@0: */ sl@0: void CTestEncryptionHook::InitialiseL() sl@0: { sl@0: User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept)); sl@0: // User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept)); sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestEncryptionHook::DoRequestL(TFsPluginRequest& aRequest) sl@0: { sl@0: TInt err = KErrNotSupported; sl@0: sl@0: TInt function = aRequest.Function(); sl@0: sl@0: iDrvNumber = aRequest.DriveNumber(); sl@0: sl@0: switch(function) sl@0: { sl@0: case EFsFileOpen: sl@0: err = EncFileOpen(aRequest); sl@0: break; sl@0: sl@0: case EFsFileRead: sl@0: // Post intercept does nothing except prove that it is possible and that no deadlock occurs. sl@0: // In fact as this plugin always calls FileRead() when receiving a EFsFileRead, the file sl@0: // server should never call this plugin in post-intercept mode as deadlock would result). sl@0: if (aRequest.IsPostOperation()) sl@0: ASSERT(0); sl@0: else sl@0: err = EncFileRead(aRequest); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestEncryptionHook::EncFileOpen(TFsPluginRequest& aRequest) sl@0: { sl@0: TFileName fileName; sl@0: sl@0: sl@0: sl@0: // TInt driveNumber = aRequest.DriveNumber(); sl@0: sl@0: TInt err = GetName(&aRequest, fileName); sl@0: if(err != KErrNone) sl@0: return(err); sl@0: sl@0: // err = ScanFile(fileName); sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestEncryptionHook::EncFileRead(TFsPluginRequest& aRequest) sl@0: { sl@0: TFileName fileName; sl@0: sl@0: // TInt driveNumber = aRequest.DriveNumber(); sl@0: sl@0: TInt r = GetName(&aRequest, fileName); sl@0: if(r != KErrNone) sl@0: return(r); sl@0: sl@0: TInt len, pos; sl@0: r = GetFileAccessInfo(&aRequest, len, pos); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: TInt offset = 0; sl@0: while(len > 0) sl@0: { sl@0: TInt readLen = Min(len, iFileBuf.MaxLength()); sl@0: // read from file sl@0: TPtr8 ptr((TUint8*) iFileBuf.Ptr(), readLen, readLen); sl@0: r = FileRead(aRequest, ptr, pos); sl@0: if (r != KErrNone) sl@0: return r; sl@0: readLen = ptr.Length(); sl@0: if (readLen == 0) sl@0: return KErrCompletion; sl@0: sl@0: Decrypt(ptr); sl@0: sl@0: // write back to client (may be an app or another plugin) sl@0: r = ClientWrite(aRequest, ptr, offset); sl@0: offset+= readLen; sl@0: len-= readLen; sl@0: pos+= readLen; sl@0: } sl@0: sl@0: return KErrCompletion; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestEncryptionHook::EncryptionPluginName(TDes& aName) sl@0: { sl@0: aName = KEncryptionPluginName; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: //factory functions sl@0: sl@0: class CEncHookFactory : public CFsPluginFactory sl@0: { sl@0: public: sl@0: CEncHookFactory(); sl@0: virtual TInt Install(); sl@0: virtual CFsPlugin* NewPluginL(); sl@0: virtual CFsPlugin* NewPluginConnL(); sl@0: virtual TInt UniquePosition(); sl@0: }; sl@0: sl@0: /** sl@0: Constructor for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: CEncHookFactory::CEncHookFactory() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Install function for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: TInt CEncHookFactory::Install() sl@0: { sl@0: iSupportedDrives = KPluginAutoAttach; sl@0: sl@0: _LIT(KEncHookName,"EncHook"); sl@0: return(SetName(&KEncHookName)); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CEncHookFactory::UniquePosition() sl@0: { sl@0: return(0x4CC); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CEncHookFactory::NewPluginL() sl@0: sl@0: { sl@0: return CTestEncryptionHook::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CEncHookFactory::NewPluginConnL() sl@0: sl@0: { sl@0: return CTestEncryptionHook::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Create a new Plugin sl@0: @internalComponent sl@0: */ sl@0: extern "C" { sl@0: sl@0: EXPORT_C CFsPluginFactory* CreateFileSystem() sl@0: { sl@0: return(new CEncHookFactory()); sl@0: } sl@0: } sl@0: