1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/plugins/version_2beta/encrypt/t_enchook.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,254 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\plugins\encrypt\t_enchook.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "t_enchook.h"
1.22 +#include <f32pluginutils.h>
1.23 +#include "encrypt.h"
1.24 +
1.25 +_LIT(KEncryptionPluginName, "This is a test encryption plugin");
1.26 +
1.27 +
1.28 +/**
1.29 +Leaving New function for the plugin
1.30 +@internalComponent
1.31 +*/
1.32 +CTestEncryptionHook* CTestEncryptionHook::NewL()
1.33 + {
1.34 + return new(ELeave) CTestEncryptionHook;
1.35 + }
1.36 +
1.37 +
1.38 +/**
1.39 +Constructor for the plugin
1.40 +@internalComponent
1.41 +*/
1.42 +CTestEncryptionHook::CTestEncryptionHook()
1.43 + {
1.44 + }
1.45 +
1.46 +
1.47 +/**
1.48 +The destructor for the test encryptplugin hook. This would
1.49 +not be a part of a normal encryption plugin implementation as
1.50 +normal encryption plugins cannot be unloaded - it must be
1.51 +provided in the test encryption plugin server so that it can
1.52 +be tested with the F32 test suite.
1.53 +@internalComponent
1.54 +*/
1.55 +CTestEncryptionHook::~CTestEncryptionHook()
1.56 + {
1.57 + iFs.Close();
1.58 + }
1.59 +
1.60 +/**
1.61 +Initialise the encryption plugin.
1.62 +@internalComponent
1.63 +*/
1.64 +void CTestEncryptionHook::InitialiseL()
1.65 + {
1.66 + User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept));
1.67 + User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
1.68 +// User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
1.69 +
1.70 + User::LeaveIfError(iFs.Connect());
1.71 + }
1.72 +
1.73 +/**
1.74 +@internalComponent
1.75 +*/
1.76 +TInt CTestEncryptionHook::DoRequestL(TFsPluginRequest& aRequest)
1.77 + {
1.78 + TInt err = KErrNotSupported;
1.79 +
1.80 + TInt function = aRequest.Function();
1.81 +
1.82 + iDrvNumber = aRequest.DriveNumber();
1.83 +
1.84 + switch(function)
1.85 + {
1.86 + case EFsFileOpen:
1.87 + err = EncFileOpen(aRequest);
1.88 + break;
1.89 +
1.90 + case EFsFileRead:
1.91 + // Post intercept does nothing except prove that it is possible and that no deadlock occurs.
1.92 + // In fact as this plugin always calls FileRead() when receiving a EFsFileRead, the file
1.93 + // server should never call this plugin in post-intercept mode as deadlock would result).
1.94 + if (aRequest.IsPostOperation())
1.95 + ASSERT(0);
1.96 + else
1.97 + err = EncFileRead(aRequest);
1.98 + break;
1.99 +
1.100 + default:
1.101 + break;
1.102 + }
1.103 +
1.104 + return err;
1.105 + }
1.106 +
1.107 +
1.108 +/**
1.109 +@internalComponent
1.110 +*/
1.111 +TInt CTestEncryptionHook::EncFileOpen(TFsPluginRequest& aRequest)
1.112 + {
1.113 + TFileName fileName;
1.114 +
1.115 +
1.116 +
1.117 +// TInt driveNumber = aRequest.DriveNumber();
1.118 +
1.119 + TInt err = GetName(&aRequest, fileName);
1.120 + if(err != KErrNone)
1.121 + return(err);
1.122 +
1.123 +// err = ScanFile(fileName);
1.124 +
1.125 + return err;
1.126 + }
1.127 +
1.128 +
1.129 +/**
1.130 +@internalComponent
1.131 +*/
1.132 +TInt CTestEncryptionHook::EncFileRead(TFsPluginRequest& aRequest)
1.133 + {
1.134 + TFileName fileName;
1.135 +
1.136 +// TInt driveNumber = aRequest.DriveNumber();
1.137 +
1.138 + TInt r = GetName(&aRequest, fileName);
1.139 + if(r != KErrNone)
1.140 + return(r);
1.141 +
1.142 + TInt len, pos;
1.143 + r = GetFileAccessInfo(&aRequest, len, pos);
1.144 + if (r != KErrNone)
1.145 + return r;
1.146 +
1.147 + TInt offset = 0;
1.148 + while(len > 0)
1.149 + {
1.150 + TInt readLen = Min(len, iFileBuf.MaxLength());
1.151 + // read from file
1.152 + TPtr8 ptr((TUint8*) iFileBuf.Ptr(), readLen, readLen);
1.153 + r = FileRead(aRequest, ptr, pos);
1.154 + if (r != KErrNone)
1.155 + return r;
1.156 + readLen = ptr.Length();
1.157 + if (readLen == 0)
1.158 + return KErrCompletion;
1.159 +
1.160 + Decrypt(ptr);
1.161 +
1.162 + // write back to client (may be an app or another plugin)
1.163 + r = ClientWrite(aRequest, ptr, offset);
1.164 + offset+= readLen;
1.165 + len-= readLen;
1.166 + pos+= readLen;
1.167 + }
1.168 +
1.169 + return KErrCompletion;
1.170 + }
1.171 +
1.172 +
1.173 +
1.174 +/**
1.175 +@internalComponent
1.176 +*/
1.177 +TInt CTestEncryptionHook::EncryptionPluginName(TDes& aName)
1.178 + {
1.179 + aName = KEncryptionPluginName;
1.180 + return KErrNone;
1.181 + }
1.182 +
1.183 +
1.184 +
1.185 +
1.186 +//factory functions
1.187 +
1.188 +class CEncHookFactory : public CFsPluginFactory
1.189 + {
1.190 +public:
1.191 + CEncHookFactory();
1.192 + virtual TInt Install();
1.193 + virtual CFsPlugin* NewPluginL();
1.194 + virtual CFsPlugin* NewPluginConnL();
1.195 + virtual TInt UniquePosition();
1.196 + };
1.197 +
1.198 +/**
1.199 +Constructor for the plugin factory
1.200 +@internalComponent
1.201 +*/
1.202 +CEncHookFactory::CEncHookFactory()
1.203 + {
1.204 + }
1.205 +
1.206 +/**
1.207 +Install function for the plugin factory
1.208 +@internalComponent
1.209 +*/
1.210 +TInt CEncHookFactory::Install()
1.211 + {
1.212 + iSupportedDrives = KPluginAutoAttach;
1.213 +
1.214 + _LIT(KEncHookName,"EncHook");
1.215 + return(SetName(&KEncHookName));
1.216 + }
1.217 +
1.218 +/**
1.219 +@internalComponent
1.220 +*/
1.221 +TInt CEncHookFactory::UniquePosition()
1.222 + {
1.223 + return(0x4CC);
1.224 + }
1.225 +
1.226 +/**
1.227 +Plugin factory function
1.228 +@internalComponent
1.229 +*/
1.230 +CFsPlugin* CEncHookFactory::NewPluginL()
1.231 +
1.232 + {
1.233 + return CTestEncryptionHook::NewL();
1.234 + }
1.235 +
1.236 +/**
1.237 +Plugin factory function
1.238 +@internalComponent
1.239 +*/
1.240 +CFsPlugin* CEncHookFactory::NewPluginConnL()
1.241 +
1.242 + {
1.243 + return CTestEncryptionHook::NewL();
1.244 + }
1.245 +
1.246 +/**
1.247 +Create a new Plugin
1.248 +@internalComponent
1.249 +*/
1.250 +extern "C" {
1.251 +
1.252 +EXPORT_C CFsPluginFactory* CreateFileSystem()
1.253 + {
1.254 + return(new CEncHookFactory());
1.255 + }
1.256 +}
1.257 +