Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\plugins\encrypt\t_enchook.cpp
18 #include "t_enchook.h"
19 #include <f32pluginutils.h>
22 _LIT(KEncryptionPluginName, "This is a test encryption plugin");
26 Leaving New function for the plugin
29 CTestEncryptionHook* CTestEncryptionHook::NewL()
31 return new(ELeave) CTestEncryptionHook;
36 Constructor for the plugin
39 CTestEncryptionHook::CTestEncryptionHook()
45 The destructor for the test encryptplugin hook. This would
46 not be a part of a normal encryption plugin implementation as
47 normal encryption plugins cannot be unloaded - it must be
48 provided in the test encryption plugin server so that it can
49 be tested with the F32 test suite.
52 CTestEncryptionHook::~CTestEncryptionHook()
58 Initialise the encryption plugin.
61 void CTestEncryptionHook::InitialiseL()
63 User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept));
64 User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
65 // User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
67 User::LeaveIfError(iFs.Connect());
73 TInt CTestEncryptionHook::DoRequestL(TFsPluginRequest& aRequest)
75 TInt err = KErrNotSupported;
77 TInt function = aRequest.Function();
79 iDrvNumber = aRequest.DriveNumber();
84 err = EncFileOpen(aRequest);
88 // Post intercept does nothing except prove that it is possible and that no deadlock occurs.
89 // In fact as this plugin always calls FileRead() when receiving a EFsFileRead, the file
90 // server should never call this plugin in post-intercept mode as deadlock would result).
91 if (aRequest.IsPostOperation())
94 err = EncFileRead(aRequest);
108 TInt CTestEncryptionHook::EncFileOpen(TFsPluginRequest& aRequest)
114 // TInt driveNumber = aRequest.DriveNumber();
116 TInt err = GetName(&aRequest, fileName);
120 // err = ScanFile(fileName);
129 TInt CTestEncryptionHook::EncFileRead(TFsPluginRequest& aRequest)
133 // TInt driveNumber = aRequest.DriveNumber();
135 TInt r = GetName(&aRequest, fileName);
140 r = GetFileAccessInfo(&aRequest, len, pos);
147 TInt readLen = Min(len, iFileBuf.MaxLength());
149 TPtr8 ptr((TUint8*) iFileBuf.Ptr(), readLen, readLen);
150 r = FileRead(aRequest, ptr, pos);
153 readLen = ptr.Length();
155 return KErrCompletion;
159 // write back to client (may be an app or another plugin)
160 r = ClientWrite(aRequest, ptr, offset);
166 return KErrCompletion;
174 TInt CTestEncryptionHook::EncryptionPluginName(TDes& aName)
176 aName = KEncryptionPluginName;
185 class CEncHookFactory : public CFsPluginFactory
189 virtual TInt Install();
190 virtual CFsPlugin* NewPluginL();
191 virtual CFsPlugin* NewPluginConnL();
192 virtual TInt UniquePosition();
196 Constructor for the plugin factory
199 CEncHookFactory::CEncHookFactory()
204 Install function for the plugin factory
207 TInt CEncHookFactory::Install()
209 iSupportedDrives = KPluginAutoAttach;
211 _LIT(KEncHookName,"EncHook");
212 return(SetName(&KEncHookName));
218 TInt CEncHookFactory::UniquePosition()
224 Plugin factory function
227 CFsPlugin* CEncHookFactory::NewPluginL()
230 return CTestEncryptionHook::NewL();
234 Plugin factory function
237 CFsPlugin* CEncHookFactory::NewPluginConnL()
240 return CTestEncryptionHook::NewL();
249 EXPORT_C CFsPluginFactory* CreateFileSystem()
251 return(new CEncHookFactory());