1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of ECOM plug-in service interface providing |
|
15 * the FTP service. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef HTIFTPSERVICEPLUGIN_H__ |
|
21 #define HTIFTPSERVICEPLUGIN_H__ |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32std.h> |
|
25 #include <f32file.h> |
|
26 #include <HtiServicePluginInterface.h> |
|
27 |
|
28 // CONSTANTS |
|
29 enum TFtpCommand |
|
30 { |
|
31 EFtpSTOR = 0x02, |
|
32 EFtpSTOR_u = 0x03, |
|
33 EFtpRETR = 0x04, |
|
34 EFtpRETR_u = 0x05, |
|
35 EFtpLIST = 0x06, |
|
36 EFtpLIST_u = 0x07, |
|
37 EFtpMKD = 0x08, |
|
38 EFtpMKD_u = 0x09, |
|
39 EFtpRMD = 0x0A, |
|
40 EFtpRMD_u = 0x0B, |
|
41 EFtpDELE = 0x0C, |
|
42 EFtpDELE_u = 0x0D, |
|
43 EFtpCANCEL = 0x0E, |
|
44 EFtpFILESIZE = 0x0F, |
|
45 EFtpLISTDIR = 0x10, |
|
46 EFtpLISTDIR_u = 0x11, |
|
47 EFtpLISTSIZES = 0x12, |
|
48 EFtpLISTSIZES_u = 0x13, |
|
49 EFtpLISTDRIVES = 0x14, |
|
50 EFtpLISTDRIVES_u = 0x15, |
|
51 EFtpRENAME = 0x16, |
|
52 EFtpRENAME_u = 0x17, |
|
53 EFtpCOPY = 0x18, |
|
54 EFtpCOPY_u = 0x19, |
|
55 EFtpMOVE = 0x1A, |
|
56 EFtpMOVE_u = 0x1B, |
|
57 EFtpSETFORCE = 0x20, |
|
58 EFtpCHECKSUM = 0x30, |
|
59 EFtpCHECKSUM_u = 0x31, |
|
60 EFtpListDetail = 0x32, |
|
61 EFtpListDetail_u = 0x33, |
|
62 EFtpListDirDetail = 0x34, |
|
63 EFtpListDirDetail_u = 0x35, |
|
64 EFtpFORMAT = 0x40, |
|
65 EFtpOK = 0xF0, |
|
66 }; |
|
67 |
|
68 enum TAlgorithm |
|
69 { |
|
70 EMD5 = 0x01, |
|
71 }; |
|
72 |
|
73 _LIT(KHtiFileHlp, "HtiFileHlp.exe"); |
|
74 |
|
75 //temporary file used if file is uploaded to Tcb |
|
76 _LIT(KTmpFileName, "C:\\htitemp.bin"); |
|
77 |
|
78 //tokens used for command line for HtiFileHlp.exe |
|
79 _LIT( KHtiFileHlpDeleteCmd, "d" ); |
|
80 _LIT( KHtiFileHlpCopyCmd, "c" ); |
|
81 _LIT( KHtiFileHlpMkdCmd, "m" ); |
|
82 _LIT( KHtiFileHlpRmdCmd, "r" ); |
|
83 _LIT( KHtiFileHlpMoveCmd, "mv" ); |
|
84 _LIT( KHtiFileHlpRenameCmd, "re" ); |
|
85 _LIT( KHtiFileHlpDelim, "|" ); |
|
86 |
|
87 //tokens used to id Tcb folders |
|
88 _LIT(KHtiTcbSys, "\\sys\\"); |
|
89 _LIT(KHtiTcbResource, "\\resource\\"); |
|
90 |
|
91 //offset where first folder's backslash starts in absolute filename |
|
92 // 012 |
|
93 const static TInt KPathOffset = 2; //"C:\" |
|
94 |
|
95 // MACROS |
|
96 |
|
97 // DATA TYPES |
|
98 |
|
99 // FUNCTION PROTOTYPES |
|
100 |
|
101 // FORWARD DECLARATIONS |
|
102 class CHtiFtpBackupFakeBase; |
|
103 |
|
104 // CLASS DECLARATION |
|
105 /** |
|
106 * Callback interface for AO |
|
107 */ |
|
108 class MFtpObserverAO |
|
109 { |
|
110 public: |
|
111 virtual void FtpComplete( TInt anError) = 0; |
|
112 }; |
|
113 |
|
114 |
|
115 // CLASS DECLARATION |
|
116 /** |
|
117 * AO for async request to CFileMan and RFile |
|
118 */ |
|
119 class CFtpHandlerAO : public CActive, public MFileManObserver |
|
120 { |
|
121 public: |
|
122 CFtpHandlerAO(MFtpObserverAO* anObserver); |
|
123 ~CFtpHandlerAO(); |
|
124 |
|
125 /** Set AO active */ |
|
126 void Start(); |
|
127 |
|
128 public: //MFileManObserver |
|
129 virtual MFileManObserver::TControl NotifyFileManStarted(); |
|
130 virtual MFileManObserver::TControl NotifyFileManOperation(); |
|
131 virtual MFileManObserver::TControl NotifyFileManEnded(); |
|
132 |
|
133 protected: //from CActive |
|
134 void RunL(); |
|
135 /** |
|
136 * no direct cancel for RFile and CFileMan |
|
137 */ |
|
138 void DoCancel(); |
|
139 //TInt RunError(TInt aError); |
|
140 |
|
141 protected: |
|
142 MFtpObserverAO* iObserver; |
|
143 /** set to ERtue if CFileMan operation should be canceled */ |
|
144 TBool iCancelFileMan; |
|
145 }; |
|
146 |
|
147 |
|
148 class CProcessLogonAO : public CActive |
|
149 { |
|
150 public: |
|
151 CProcessLogonAO(MFtpObserverAO* anObserver); |
|
152 ~CProcessLogonAO(); |
|
153 |
|
154 /** Set AO active */ |
|
155 void Start(const TDesC& aCmdLine); |
|
156 |
|
157 protected: //from CActive |
|
158 void RunL(); |
|
159 void DoCancel(); |
|
160 |
|
161 protected: |
|
162 MFtpObserverAO* iObserver; |
|
163 RProcess iProcess; |
|
164 }; |
|
165 |
|
166 |
|
167 // CLASS DECLARATION |
|
168 /** |
|
169 * FTP plugin implementation |
|
170 */ |
|
171 class CHtiFtpServicePlugin : public CHTIServicePluginInterface, |
|
172 public MFtpObserverAO |
|
173 { |
|
174 protected: |
|
175 /** |
|
176 * Major states of FPT plug-in |
|
177 */ |
|
178 enum TFtpServiceState |
|
179 { |
|
180 EIdle, /** waits for a new command */ |
|
181 EListBusy, /** waits for memory to send LIST response */ |
|
182 ERmdBusy, /** outstanding request CFileMan::RmDir() */ |
|
183 EDeleBusy, /** outstanding request CFileMan::Delete() */ |
|
184 EStorWait, /** waits for data packages */ |
|
185 EStorBusy, /** outstanding request to RFile::Write() */ |
|
186 ERetrBusy, /** outstanding request to RFile::Read() */ |
|
187 ERetrWait, /** waits for memory to send data package */ |
|
188 EStorTcbBusy, /** outstandig request to HtiFileHlp.exe */ |
|
189 EDeleTcbBusy, /** outstandig request to HtiFileHlp.exe */ |
|
190 EMkdTcbBusy, /** outstandig request to HtiFileHlp.exe */ |
|
191 ERmdTcbBusy, /** outstandig request to HtiFileHlp.exe */ |
|
192 ERenameBusy, /** outstanding request CFileMan::Rename() */ |
|
193 ERenameTcbBusy, /** outstandig request to HtiFileHlp.exe */ |
|
194 ECopyBusy, /** outstanding request CFileMan::Copy() */ |
|
195 ECopyTcbBusy, /** outstandig request to HtiFileHlp.exe */ |
|
196 EMoveBusy, /** outstanding request CFileMan::Move() */ |
|
197 EMoveTcbBusy /** outstandig request to HtiFileHlp.exe */ |
|
198 }; |
|
199 public: |
|
200 |
|
201 static CHtiFtpServicePlugin* NewL(); |
|
202 |
|
203 // Interface implementation |
|
204 |
|
205 /** |
|
206 * Calculates iBufferSize based on iDispatcher->FreeMemory() value |
|
207 */ |
|
208 void InitL(); |
|
209 |
|
210 /** |
|
211 * @return ETrue when in any EXXXBusy state |
|
212 */ |
|
213 TBool IsBusy(); |
|
214 |
|
215 /** |
|
216 * Process either control or data message depending on aPriority |
|
217 * |
|
218 * @param aMessage message with commands or data |
|
219 * @param aPriority indicates type of aMessage |
|
220 */ |
|
221 void ProcessMessageL( const TDesC8& aMessage, |
|
222 THtiMessagePriority aPriority ); |
|
223 |
|
224 void NotifyMemoryChange( TInt aAvailableMemory ); |
|
225 |
|
226 public: // MFtpObserverAO |
|
227 void FtpComplete( TInt anError ); |
|
228 |
|
229 protected: |
|
230 CHtiFtpServicePlugin(); |
|
231 void ConstructL(); |
|
232 |
|
233 virtual ~CHtiFtpServicePlugin(); |
|
234 |
|
235 /** |
|
236 * Handle FTP control messages |
|
237 * |
|
238 * @param aMessage message with command |
|
239 */ |
|
240 void HandleControlMessageL( const TDesC8& aMessage ); |
|
241 |
|
242 /** |
|
243 * Handle expected CANCEL control message |
|
244 * received in EStorWait or ERetrWait state |
|
245 * If aMessage does not contain CANCEL command, |
|
246 * BUSY message is sent, otherwise current operation is canceled |
|
247 * and plugin goes to EIdle state and sends OK message. |
|
248 * |
|
249 * @param aMessage message with command |
|
250 */ |
|
251 void HandleCancelL( const TDesC8& aMessage ); |
|
252 |
|
253 /** |
|
254 * Accepts data messages for STOR command |
|
255 * |
|
256 * @param aMessage message with file data |
|
257 */ |
|
258 void HandleDataMessageL( const TDesC8& aMessage ); |
|
259 |
|
260 //command handlers |
|
261 |
|
262 /** |
|
263 * Handle STOR command request |
|
264 */ |
|
265 void HandleReceiveFileL(); |
|
266 |
|
267 /** |
|
268 * Handle RETR command request |
|
269 */ |
|
270 void HandleSendFileL(); |
|
271 |
|
272 /** |
|
273 * Reads one portion of file data during RETR command handeling. |
|
274 */ |
|
275 void ReadToBuffer(); |
|
276 |
|
277 /** |
|
278 * Sends one portion of file data during RETR command handeling. |
|
279 */ |
|
280 void SendBuffer(); |
|
281 |
|
282 /** |
|
283 * Handle LIST command |
|
284 * |
|
285 * @param aUnicodText if ETrue then response in unicode |
|
286 * @param aReadingAtt specifies what entries to read from a dir |
|
287 * @param aSizes if ETrue filesizes are included in the response |
|
288 */ |
|
289 void HandleListL( TBool aUnicodText, TUint aReadingAtt, TBool aSizes ); |
|
290 |
|
291 /** |
|
292 * Handle LIST FILES DETAIL command |
|
293 * |
|
294 * @param aUnicodText if ETrue then response in unicode |
|
295 * @param aReadingAtt specifies what entries to read from a dir |
|
296 */ |
|
297 void HandleListDetailL( TBool aUnicodText, TUint aReadingAtt); |
|
298 |
|
299 /** |
|
300 * Extracts and validate file name to iFileName |
|
301 * If error sends err msg |
|
302 * Return ETrue when filename is valid |
|
303 * @param aFilename descriptor with filename |
|
304 * @param aToUnicode flag indicates that data in aFilename |
|
305 * should be treated as an unicode string |
|
306 */ |
|
307 TBool GetFileNameL( const TDesC8& aFilename, TBool aToUnicode ); |
|
308 |
|
309 /** |
|
310 * Extracts and validates path to iFileName |
|
311 * If error sends err msg |
|
312 * Return ETrue when directory is valid |
|
313 * @param aDirname descriptor with directory name |
|
314 * @param aToUnicode flag indicates that data in aFilename |
|
315 * should be treated as an unicode string |
|
316 */ |
|
317 TBool GetDirectoryL( const TDesC8& aDirname, TBool aToUnicode ); |
|
318 |
|
319 /** |
|
320 * Helper to send short control messages |
|
321 * (e.g. OK, BUSY, FILESIZE) |
|
322 * @param aCmd command code |
|
323 * @param aMsg additional command parameters |
|
324 * @return KErrNone or Symbian error code |
|
325 */ |
|
326 TInt SendControlMsg( TFtpCommand aCmd, const TDesC8& aMsg ); |
|
327 |
|
328 /** |
|
329 * Helper to send error message |
|
330 * @return KErrNone or some system-wide error code |
|
331 */ |
|
332 inline TInt SendErrorMsg( TInt anError, const TDesC8& aMsg ); |
|
333 |
|
334 /** |
|
335 * Handle delete command |
|
336 * @param aFilename the file to delete |
|
337 */ |
|
338 void HandleDeleteL( const TDesC& aFilename ); |
|
339 |
|
340 /** |
|
341 * Handle rename command |
|
342 * @param aMessage message that contains |
|
343 * old and new file/directory names. |
|
344 * @param aToUnicode flag indicates that data in aFilename |
|
345 * should be treated as an unicode string |
|
346 */ |
|
347 void HandleRenameL( const TDesC8& aMessage, TBool aUnicode ); |
|
348 |
|
349 /** |
|
350 * Handle copy command |
|
351 * @param aMessage message that contains the file/directory to be copied |
|
352 * and the location and name of the copy. |
|
353 * @param aToUnicode flag indicates that data in aFilename |
|
354 * should be treated as an unicode string |
|
355 */ |
|
356 void HandleCopyL( const TDesC8& aMessage, TBool aUnicode ); |
|
357 |
|
358 /** |
|
359 * Handle move command |
|
360 * @param aMessage message that contains the file/directory to be moved |
|
361 * and the new location |
|
362 * @param aToUnicode flag indicates that data in aFilename |
|
363 * should be treated as an unicode string |
|
364 */ |
|
365 void HandleMoveL( const TDesC8& aMessage, TBool aUnicode ); |
|
366 |
|
367 /** |
|
368 * Safe unicode copying from 8bit descr to 16bit buffer |
|
369 * @param aTo destination descriptor |
|
370 * @param aFrom source descriptor |
|
371 */ |
|
372 void CopyUnicode( TDes& aTo, const TDesC8& aFrom ); |
|
373 |
|
374 /** |
|
375 * Check either aFilename point in a TCB directories (sys, private, resource) |
|
376 * @param aFilename the file to check |
|
377 */ |
|
378 TBool IsFileTcb( const TDesC& aFilename ); |
|
379 |
|
380 /** |
|
381 * Uses HtiFileHlp.exe to delete file from TCB directories |
|
382 * @param aFilename the file to delete |
|
383 */ |
|
384 void HandleTcbDeleteL( const TDesC& aFilename ); |
|
385 |
|
386 /** |
|
387 * Uses HtiFileHlp.exe to copy files/folders to TCB directories |
|
388 * @param aFromFilename the source path |
|
389 * @param aToFilename the destination path |
|
390 */ |
|
391 void HandleTcbCopyL( const TDesC& aFromFilename, const TDesC& aToFilename ); |
|
392 |
|
393 /** |
|
394 * Uses HtiFileHlp.exe to makedir in TCB directories |
|
395 * @param aDirname the directory to create |
|
396 */ |
|
397 void HandleTcbMkdL( const TDesC& aDirname ); |
|
398 |
|
399 /** |
|
400 * Uses HtiFileHlp.exe to delete dir in TCB directories |
|
401 * @param aDirname the directory to delete |
|
402 */ |
|
403 void HandleTcbRmdL( const TDesC& aDirname ); |
|
404 |
|
405 /** |
|
406 * Uses HtiFileHlp.exe to do rename in TCB folders |
|
407 * @param aTargetName the path to rename |
|
408 * @param aDestName the new path name |
|
409 */ |
|
410 void HandleTcbRenameL( const TDesC& aTargetName, const TDesC& aDestName ); |
|
411 |
|
412 /** |
|
413 * Uses HtiFileHlp.exe to do move to TCB folders |
|
414 * @param aTargetName the path to move |
|
415 * @param aDestName the destination path |
|
416 */ |
|
417 void HandleTcbMoveL( const TDesC& aTargetName, const TDesC& aDestName ); |
|
418 |
|
419 /** |
|
420 * Sets the faking of backup/restore operation on/off. |
|
421 * If aOn is ETrue sets backup/restore on, otherwise sets it off. |
|
422 * @return KErrNone on success, otherwise system error code |
|
423 */ |
|
424 TInt SetBURFakeState( TBool aOn ); |
|
425 |
|
426 /** |
|
427 * Calculates a checksum for the given file with the given algorithm. |
|
428 */ |
|
429 void HandleCheckSumCalcL( TAlgorithm aAlgorithm, |
|
430 const TDesC& aFilename ); |
|
431 |
|
432 /** |
|
433 * Formats a drive. |
|
434 */ |
|
435 void HandleFormat( const TUint8 aDrive, const TUint8 aMode ); |
|
436 |
|
437 /** |
|
438 * Creates a list of drives. |
|
439 */ |
|
440 void HandleListDrivesL( TBool aUnicode ); |
|
441 |
|
442 private: |
|
443 void RemoveEndBackslash( TFileName& aFileName ); |
|
444 |
|
445 protected: |
|
446 /** plugin state */ |
|
447 TFtpServiceState iState; |
|
448 /** File server */ |
|
449 RFs iFs; |
|
450 /** File manager used for RMD and DELE */ |
|
451 CFileMan* iFileMan; |
|
452 /** current file for STOR and RETR*/ |
|
453 RFile iFile; |
|
454 /** file name of iFile */ |
|
455 TFileName iFileName; |
|
456 |
|
457 /** current offset in file during STOR or RETR */ |
|
458 TInt iCurrentOffset; //mean received bytes or sent bytes |
|
459 /** the final size of iFile */ |
|
460 TInt iFileSize; |
|
461 |
|
462 /** the size of iSendBuffer, calculated in InitL() */ |
|
463 TInt iBufferSize; |
|
464 /** send buffer for RETR and LIST commands */ |
|
465 HBufC8* iSendBuffer; |
|
466 /** des of iSendBuffer, used for RETR */ |
|
467 TPtr8 iSendBufferDes; |
|
468 |
|
469 /** AO to handle current asyn request */ |
|
470 CFtpHandlerAO* iHandlerAO; |
|
471 |
|
472 /** used for HtiFileHlp.exe */ |
|
473 CProcessLogonAO* iProcessLogonAO; |
|
474 |
|
475 /** |
|
476 * Class for activating/deactivating a backup session. |
|
477 * This is used for forced operations to locked files. Activating backup |
|
478 * should release locks on files that are in use by some other application. |
|
479 */ |
|
480 CHtiFtpBackupFakeBase* iBackupFake; |
|
481 |
|
482 /** Handle to the DLL for activating/deactivating backup */ |
|
483 RLibrary iBackupFakeLib; |
|
484 }; |
|
485 |
|
486 #endif |
|
487 |
|
488 // End of File |
|