sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\plugins\encrypt\t_enchook.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "t_enchook.h"
|
sl@0
|
19 |
#include <f32pluginutils.h>
|
sl@0
|
20 |
#include "encrypt.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KEncryptionPluginName, "This is a test encryption plugin");
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
Leaving New function for the plugin
|
sl@0
|
27 |
@internalComponent
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
CTestEncryptionHook* CTestEncryptionHook::NewL()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
return new(ELeave) CTestEncryptionHook;
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
Constructor for the plugin
|
sl@0
|
37 |
@internalComponent
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
CTestEncryptionHook::CTestEncryptionHook()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
/**
|
sl@0
|
45 |
The destructor for the test encryptplugin hook. This would
|
sl@0
|
46 |
not be a part of a normal encryption plugin implementation as
|
sl@0
|
47 |
normal encryption plugins cannot be unloaded - it must be
|
sl@0
|
48 |
provided in the test encryption plugin server so that it can
|
sl@0
|
49 |
be tested with the F32 test suite.
|
sl@0
|
50 |
@internalComponent
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
CTestEncryptionHook::~CTestEncryptionHook()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
iFs.Close();
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
/**
|
sl@0
|
58 |
Initialise the encryption plugin.
|
sl@0
|
59 |
@internalComponent
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
void CTestEncryptionHook::InitialiseL()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept));
|
sl@0
|
64 |
User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
|
sl@0
|
65 |
// User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
|
sl@0
|
66 |
|
sl@0
|
67 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
/**
|
sl@0
|
71 |
@internalComponent
|
sl@0
|
72 |
*/
|
sl@0
|
73 |
TInt CTestEncryptionHook::DoRequestL(TFsPluginRequest& aRequest)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
TInt err = KErrNotSupported;
|
sl@0
|
76 |
|
sl@0
|
77 |
TInt function = aRequest.Function();
|
sl@0
|
78 |
|
sl@0
|
79 |
iDrvNumber = aRequest.DriveNumber();
|
sl@0
|
80 |
|
sl@0
|
81 |
switch(function)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
case EFsFileOpen:
|
sl@0
|
84 |
err = EncFileOpen(aRequest);
|
sl@0
|
85 |
break;
|
sl@0
|
86 |
|
sl@0
|
87 |
case EFsFileRead:
|
sl@0
|
88 |
// Post intercept does nothing except prove that it is possible and that no deadlock occurs.
|
sl@0
|
89 |
// In fact as this plugin always calls FileRead() when receiving a EFsFileRead, the file
|
sl@0
|
90 |
// server should never call this plugin in post-intercept mode as deadlock would result).
|
sl@0
|
91 |
if (aRequest.IsPostOperation())
|
sl@0
|
92 |
ASSERT(0);
|
sl@0
|
93 |
else
|
sl@0
|
94 |
err = EncFileRead(aRequest);
|
sl@0
|
95 |
break;
|
sl@0
|
96 |
|
sl@0
|
97 |
default:
|
sl@0
|
98 |
break;
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
return err;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
|
sl@0
|
105 |
/**
|
sl@0
|
106 |
@internalComponent
|
sl@0
|
107 |
*/
|
sl@0
|
108 |
TInt CTestEncryptionHook::EncFileOpen(TFsPluginRequest& aRequest)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TFileName fileName;
|
sl@0
|
111 |
|
sl@0
|
112 |
|
sl@0
|
113 |
|
sl@0
|
114 |
// TInt driveNumber = aRequest.DriveNumber();
|
sl@0
|
115 |
|
sl@0
|
116 |
TInt err = GetName(&aRequest, fileName);
|
sl@0
|
117 |
if(err != KErrNone)
|
sl@0
|
118 |
return(err);
|
sl@0
|
119 |
|
sl@0
|
120 |
// err = ScanFile(fileName);
|
sl@0
|
121 |
|
sl@0
|
122 |
return err;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
|
sl@0
|
126 |
/**
|
sl@0
|
127 |
@internalComponent
|
sl@0
|
128 |
*/
|
sl@0
|
129 |
TInt CTestEncryptionHook::EncFileRead(TFsPluginRequest& aRequest)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
TFileName fileName;
|
sl@0
|
132 |
|
sl@0
|
133 |
// TInt driveNumber = aRequest.DriveNumber();
|
sl@0
|
134 |
|
sl@0
|
135 |
TInt r = GetName(&aRequest, fileName);
|
sl@0
|
136 |
if(r != KErrNone)
|
sl@0
|
137 |
return(r);
|
sl@0
|
138 |
|
sl@0
|
139 |
TInt len, pos;
|
sl@0
|
140 |
r = GetFileAccessInfo(&aRequest, len, pos);
|
sl@0
|
141 |
if (r != KErrNone)
|
sl@0
|
142 |
return r;
|
sl@0
|
143 |
|
sl@0
|
144 |
TInt offset = 0;
|
sl@0
|
145 |
while(len > 0)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
TInt readLen = Min(len, iFileBuf.MaxLength());
|
sl@0
|
148 |
// read from file
|
sl@0
|
149 |
TPtr8 ptr((TUint8*) iFileBuf.Ptr(), readLen, readLen);
|
sl@0
|
150 |
r = FileRead(aRequest, ptr, pos);
|
sl@0
|
151 |
if (r != KErrNone)
|
sl@0
|
152 |
return r;
|
sl@0
|
153 |
readLen = ptr.Length();
|
sl@0
|
154 |
if (readLen == 0)
|
sl@0
|
155 |
return KErrCompletion;
|
sl@0
|
156 |
|
sl@0
|
157 |
Decrypt(ptr);
|
sl@0
|
158 |
|
sl@0
|
159 |
// write back to client (may be an app or another plugin)
|
sl@0
|
160 |
r = ClientWrite(aRequest, ptr, offset);
|
sl@0
|
161 |
offset+= readLen;
|
sl@0
|
162 |
len-= readLen;
|
sl@0
|
163 |
pos+= readLen;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
return KErrCompletion;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
/**
|
sl@0
|
172 |
@internalComponent
|
sl@0
|
173 |
*/
|
sl@0
|
174 |
TInt CTestEncryptionHook::EncryptionPluginName(TDes& aName)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
aName = KEncryptionPluginName;
|
sl@0
|
177 |
return KErrNone;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
|
sl@0
|
181 |
|
sl@0
|
182 |
|
sl@0
|
183 |
//factory functions
|
sl@0
|
184 |
|
sl@0
|
185 |
class CEncHookFactory : public CFsPluginFactory
|
sl@0
|
186 |
{
|
sl@0
|
187 |
public:
|
sl@0
|
188 |
CEncHookFactory();
|
sl@0
|
189 |
virtual TInt Install();
|
sl@0
|
190 |
virtual CFsPlugin* NewPluginL();
|
sl@0
|
191 |
virtual CFsPlugin* NewPluginConnL();
|
sl@0
|
192 |
virtual TInt UniquePosition();
|
sl@0
|
193 |
};
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
Constructor for the plugin factory
|
sl@0
|
197 |
@internalComponent
|
sl@0
|
198 |
*/
|
sl@0
|
199 |
CEncHookFactory::CEncHookFactory()
|
sl@0
|
200 |
{
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
/**
|
sl@0
|
204 |
Install function for the plugin factory
|
sl@0
|
205 |
@internalComponent
|
sl@0
|
206 |
*/
|
sl@0
|
207 |
TInt CEncHookFactory::Install()
|
sl@0
|
208 |
{
|
sl@0
|
209 |
iSupportedDrives = KPluginAutoAttach;
|
sl@0
|
210 |
|
sl@0
|
211 |
_LIT(KEncHookName,"EncHook");
|
sl@0
|
212 |
return(SetName(&KEncHookName));
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
/**
|
sl@0
|
216 |
@internalComponent
|
sl@0
|
217 |
*/
|
sl@0
|
218 |
TInt CEncHookFactory::UniquePosition()
|
sl@0
|
219 |
{
|
sl@0
|
220 |
return(0x4CC);
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
/**
|
sl@0
|
224 |
Plugin factory function
|
sl@0
|
225 |
@internalComponent
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
CFsPlugin* CEncHookFactory::NewPluginL()
|
sl@0
|
228 |
|
sl@0
|
229 |
{
|
sl@0
|
230 |
return CTestEncryptionHook::NewL();
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
/**
|
sl@0
|
234 |
Plugin factory function
|
sl@0
|
235 |
@internalComponent
|
sl@0
|
236 |
*/
|
sl@0
|
237 |
CFsPlugin* CEncHookFactory::NewPluginConnL()
|
sl@0
|
238 |
|
sl@0
|
239 |
{
|
sl@0
|
240 |
return CTestEncryptionHook::NewL();
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
/**
|
sl@0
|
244 |
Create a new Plugin
|
sl@0
|
245 |
@internalComponent
|
sl@0
|
246 |
*/
|
sl@0
|
247 |
extern "C" {
|
sl@0
|
248 |
|
sl@0
|
249 |
EXPORT_C CFsPluginFactory* CreateFileSystem()
|
sl@0
|
250 |
{
|
sl@0
|
251 |
return(new CEncHookFactory());
|
sl@0
|
252 |
}
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|