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