|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // f32test\plugins\encrypt\t_enchook.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "t_enchook.h" |
|
19 #include <f32pluginutils.h> |
|
20 #include "encrypt.h" |
|
21 |
|
22 _LIT(KEncryptionPluginName, "This is a test encryption plugin"); |
|
23 |
|
24 |
|
25 /** |
|
26 Leaving New function for the plugin |
|
27 @internalComponent |
|
28 */ |
|
29 CTestEncryptionHook* CTestEncryptionHook::NewL() |
|
30 { |
|
31 return new(ELeave) CTestEncryptionHook; |
|
32 } |
|
33 |
|
34 |
|
35 /** |
|
36 Constructor for the plugin |
|
37 @internalComponent |
|
38 */ |
|
39 CTestEncryptionHook::CTestEncryptionHook() |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 /** |
|
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. |
|
50 @internalComponent |
|
51 */ |
|
52 CTestEncryptionHook::~CTestEncryptionHook() |
|
53 { |
|
54 iFs.Close(); |
|
55 } |
|
56 |
|
57 /** |
|
58 Initialise the encryption plugin. |
|
59 @internalComponent |
|
60 */ |
|
61 void CTestEncryptionHook::InitialiseL() |
|
62 { |
|
63 User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept)); |
|
64 User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept)); |
|
65 // User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept)); |
|
66 |
|
67 User::LeaveIfError(iFs.Connect()); |
|
68 } |
|
69 |
|
70 /** |
|
71 @internalComponent |
|
72 */ |
|
73 TInt CTestEncryptionHook::DoRequestL(TFsPluginRequest& aRequest) |
|
74 { |
|
75 TInt err = KErrNotSupported; |
|
76 |
|
77 TInt function = aRequest.Function(); |
|
78 |
|
79 iDrvNumber = aRequest.DriveNumber(); |
|
80 |
|
81 switch(function) |
|
82 { |
|
83 case EFsFileOpen: |
|
84 err = EncFileOpen(aRequest); |
|
85 break; |
|
86 |
|
87 case EFsFileRead: |
|
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()) |
|
92 ASSERT(0); |
|
93 else |
|
94 err = EncFileRead(aRequest); |
|
95 break; |
|
96 |
|
97 default: |
|
98 break; |
|
99 } |
|
100 |
|
101 return err; |
|
102 } |
|
103 |
|
104 |
|
105 /** |
|
106 @internalComponent |
|
107 */ |
|
108 TInt CTestEncryptionHook::EncFileOpen(TFsPluginRequest& aRequest) |
|
109 { |
|
110 TFileName fileName; |
|
111 |
|
112 |
|
113 |
|
114 // TInt driveNumber = aRequest.DriveNumber(); |
|
115 |
|
116 TInt err = GetName(&aRequest, fileName); |
|
117 if(err != KErrNone) |
|
118 return(err); |
|
119 |
|
120 // err = ScanFile(fileName); |
|
121 |
|
122 return err; |
|
123 } |
|
124 |
|
125 |
|
126 /** |
|
127 @internalComponent |
|
128 */ |
|
129 TInt CTestEncryptionHook::EncFileRead(TFsPluginRequest& aRequest) |
|
130 { |
|
131 TFileName fileName; |
|
132 |
|
133 // TInt driveNumber = aRequest.DriveNumber(); |
|
134 |
|
135 TInt r = GetName(&aRequest, fileName); |
|
136 if(r != KErrNone) |
|
137 return(r); |
|
138 |
|
139 TInt len, pos; |
|
140 r = GetFileAccessInfo(&aRequest, len, pos); |
|
141 if (r != KErrNone) |
|
142 return r; |
|
143 |
|
144 TInt offset = 0; |
|
145 while(len > 0) |
|
146 { |
|
147 TInt readLen = Min(len, iFileBuf.MaxLength()); |
|
148 // read from file |
|
149 TPtr8 ptr((TUint8*) iFileBuf.Ptr(), readLen, readLen); |
|
150 r = FileRead(aRequest, ptr, pos); |
|
151 if (r != KErrNone) |
|
152 return r; |
|
153 readLen = ptr.Length(); |
|
154 if (readLen == 0) |
|
155 return KErrCompletion; |
|
156 |
|
157 Decrypt(ptr); |
|
158 |
|
159 // write back to client (may be an app or another plugin) |
|
160 r = ClientWrite(aRequest, ptr, offset); |
|
161 offset+= readLen; |
|
162 len-= readLen; |
|
163 pos+= readLen; |
|
164 } |
|
165 |
|
166 return KErrCompletion; |
|
167 } |
|
168 |
|
169 |
|
170 |
|
171 /** |
|
172 @internalComponent |
|
173 */ |
|
174 TInt CTestEncryptionHook::EncryptionPluginName(TDes& aName) |
|
175 { |
|
176 aName = KEncryptionPluginName; |
|
177 return KErrNone; |
|
178 } |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 //factory functions |
|
184 |
|
185 class CEncHookFactory : public CFsPluginFactory |
|
186 { |
|
187 public: |
|
188 CEncHookFactory(); |
|
189 virtual TInt Install(); |
|
190 virtual CFsPlugin* NewPluginL(); |
|
191 virtual CFsPlugin* NewPluginConnL(); |
|
192 virtual TInt UniquePosition(); |
|
193 }; |
|
194 |
|
195 /** |
|
196 Constructor for the plugin factory |
|
197 @internalComponent |
|
198 */ |
|
199 CEncHookFactory::CEncHookFactory() |
|
200 { |
|
201 } |
|
202 |
|
203 /** |
|
204 Install function for the plugin factory |
|
205 @internalComponent |
|
206 */ |
|
207 TInt CEncHookFactory::Install() |
|
208 { |
|
209 iSupportedDrives = KPluginAutoAttach; |
|
210 |
|
211 _LIT(KEncHookName,"EncHook"); |
|
212 return(SetName(&KEncHookName)); |
|
213 } |
|
214 |
|
215 /** |
|
216 @internalComponent |
|
217 */ |
|
218 TInt CEncHookFactory::UniquePosition() |
|
219 { |
|
220 return(0x4CC); |
|
221 } |
|
222 |
|
223 /** |
|
224 Plugin factory function |
|
225 @internalComponent |
|
226 */ |
|
227 CFsPlugin* CEncHookFactory::NewPluginL() |
|
228 |
|
229 { |
|
230 return CTestEncryptionHook::NewL(); |
|
231 } |
|
232 |
|
233 /** |
|
234 Plugin factory function |
|
235 @internalComponent |
|
236 */ |
|
237 CFsPlugin* CEncHookFactory::NewPluginConnL() |
|
238 |
|
239 { |
|
240 return CTestEncryptionHook::NewL(); |
|
241 } |
|
242 |
|
243 /** |
|
244 Create a new Plugin |
|
245 @internalComponent |
|
246 */ |
|
247 extern "C" { |
|
248 |
|
249 EXPORT_C CFsPluginFactory* CreateFileSystem() |
|
250 { |
|
251 return(new CEncHookFactory()); |
|
252 } |
|
253 } |
|
254 |