applayerprotocols/ftpengine/inc/PROTOCOL.H
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 /**
       
     2 * Copyright (c) 1998-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:
       
    15 * FTP Protocol header file
       
    16 * Author:	Philippe Gabriel
       
    17 * 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file protocol.h
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 #if !defined(__PROTOCOL_H__)
       
    29 #define __PROTOCOL_H__
       
    30 
       
    31 #include <e32base.h>
       
    32 #include <es_sock.h>
       
    33 #include <ftpprot.h>
       
    34 #include "FTPDEF.H"
       
    35 #include "DEBUG.H"
       
    36 #include "PICHNL.H"
       
    37 #include "DTPCHNL.H"
       
    38 #include "RESOLVER.H"
       
    39 #include "SETERROR.H"
       
    40 
       
    41 
       
    42 
       
    43 class TFTPServerAnswerParser;
       
    44 class TFtpPASVAnswerParser;
       
    45 
       
    46 NONSHARABLE_CLASS(CFtpProtocolDerived) : public CFtpProtocol,public MPIChannelNotifier,MDTPChannelNotifier,MFTPResolverNotifier,MSetErrorNotifier
       
    47 /**
       
    48 FtpEngine
       
    49 @internalComponent
       
    50 */
       
    51 	{
       
    52 friend class CDTPChannel;
       
    53 friend class CPIChannel;
       
    54 public:
       
    55 	/** Establish a connection: IP address */
       
    56 	void Connect(TSockAddr& aNetAddr);	
       
    57 	/** URL name */
       
    58 	void Connect(const THostName& aServerName);  
       
    59 	/** URL name + port */
       
    60 	void Connect(const THostName& aServerName, const TUint aPort); 
       
    61 
       
    62 	/** FTP commands, presented in the same order as RFC959: */
       
    63 	void User(const TDesC8& aParam);
       
    64 	void Pass(const TDesC8& aParam);
       
    65 	void Acct(const TDesC8& aParam);
       
    66 	void Cwd(const TDesC8& aParam);
       
    67 	void Cdup(void);
       
    68 	void Smnt(const TDesC8& aParam);
       
    69 	void Quit(void);
       
    70 	void Rein(void);
       
    71 	/** Sets the DTP port to one allocated by ESOCK */
       
    72 	void Port(void);	
       
    73 	/** Sets the DTP port to a specific one */
       
    74 	void Port(TUint aPort);	
       
    75 	void Pasv(void);
       
    76 	void Type(const TDesC8& aParam);
       
    77 	void Type(const TDesC8& aParam1, const TDesC8& aParam2);
       
    78 	void Stru(const TDesC8& aParam);
       
    79 	void Mode(const TDesC8& aParam);
       
    80 	void Retr(const TDesC8& aFileName);
       
    81 	void Stor(const TDesC8& aFileName);
       
    82 	void Stou(void);
       
    83 	void Appe(const TDesC8& aFileName);
       
    84 	void Allo(const TDesC8& aParam);
       
    85 	void Allo(const TDesC8& aParam1, const TDesC8& aParam2);
       
    86 	void Rest(const TDesC8& aParam);
       
    87 	void Rnfr(const TDesC8& aFileName);
       
    88 	void Rnto(const TDesC8& aFileName);
       
    89 	void Abor(void);
       
    90 	void Dele(const TDesC8& aFileName);
       
    91 	void Rmd(const TDesC8& aParam);
       
    92 	void Mkd(const TDesC8& aParam);
       
    93 	void Pwd(void);
       
    94 	void List(void);
       
    95 	void List(const TDesC8& aParam);
       
    96 	void Nlst(void);
       
    97 	void Nlst(const TDesC8& aParam);
       
    98 	void Site(const TDesC8& aParam);
       
    99 	void Syst(void);
       
   100 	void Stat(const TDesC8& aParam);
       
   101 	void Stat(void);
       
   102 	void Help(const TDesC8& aParam);
       
   103 	void Help(void);
       
   104 	void Noop(void);
       
   105 	/** 
       
   106 	Buffer management for transfer
       
   107 	Following functions pass a pointer to a buffer
       
   108 	to transfer data to/from the Dtp channel
       
   109 	Before an operation which cause data to transit on the 
       
   110 	DTP channel to occur (Nlst, List, Retr, Stor)
       
   111 	a Buffer must be provided with the following api
       
   112 	Also when the client is notified of a MoreData event
       
   113 	It must reissue the following operation to get the rest of
       
   114 	the data
       
   115 	*/
       
   116 	void SendBuffer(TDes8* aBuffer);
       
   117 	void RecvBuffer(TDes8* aBuffer);
       
   118 	/** Finishes the transfer initiated by a stor command */
       
   119 	void SendEOF(void); 
       
   120 	/** PI Channel Minterface */
       
   121 	void PIChannelOperationCompletion(const TPiOperationCompletion);
       
   122 	/** Notify of error performing an operation */
       
   123 	void PIChannelOperationError(const TPiOperationError);
       
   124 	/** Notify of reception */
       
   125 	void PIChannelRcvNotification(void);
       
   126 	/** Notify server has unexpectidly dropped the connection */
       
   127 	void PIChannelReset(void);
       
   128 	/** DTP Channel Minterface */
       
   129 	/** Notify of normal completion of an operation */
       
   130 	void DTPChannelOperationCompletion(const TDtpOperationCompletion);
       
   131 	/** Notify of error performing an operation */
       
   132 	void DTPChannelOperationError(const TDtpOperationError);
       
   133 	/** Notify of reception */
       
   134 	void DTPChannelXferNotification(const TDtpOperationCompletion);
       
   135 	/** FTP DNS resolver Minterface */
       
   136 	void FTPResolverNotifier(const TFTPResolverNotificationCode);
       
   137 	/** Copies the 3 digits answer received from the FTP server */
       
   138 	void FTPServerAnswer(TDes& aServerAnswer){aServerAnswer.Copy(iAnswer);}
       
   139 	/** Define the CFTPSetError callback notifier */
       
   140 	void SetErrorNotifier(const TInt);
       
   141 
       
   142 	void UserCancel(void);
       
   143 	~CFtpProtocolDerived();
       
   144 	static CFtpProtocolDerived *NewL(MFtpProtocolNotifier*);
       
   145 
       
   146 protected:
       
   147 	CFtpProtocolDerived(MFtpProtocolNotifier* aNotifier);
       
   148 
       
   149     void ConstructL(void);
       
   150 	/** Address of the remote FTP server */
       
   151 	TInetAddr iRemoteAddress; 
       
   152 	/** A Buffer to receive server answers */
       
   153 	TBuf8<512> iServerAnswerBuffer; 
       
   154 private:
       
   155 	enum TState 
       
   156 		{
       
   157 	EIdle,
       
   158 	ELookingUp,
       
   159 	EConnecting,
       
   160 	EPerformingUser,EPerformingPass,EPerformingAcct,EPerformingCwd,EPerformingCdup,
       
   161 	EPerformingSmnt,EPerformingQuit,EPerformingRein,EPerformingPort,
       
   162 	EPerformingPasv,EPerformingType,EPerformingStru,EPerformingMode,EPerformingRetr,
       
   163 	EPerformingStor,EPerformingStou,EPerformingAppe,EPerformingAllo,EPerformingRest,
       
   164 	EPerformingRnfr,EPerformingRnto,EPerformingDele,EPerformingRmd,
       
   165 	EPerformingMkd,EPerformingPwd,EPerformingList,EPerformingNlst,EPerformingSite,
       
   166 	EPerformingSyst,EPerformingStat,EPerformingHelp,EPerformingNoop,
       
   167 	EPerformingAbor
       
   168 		};
       
   169 	enum TInternalEvents
       
   170 		{
       
   171 		EFtpCodeReply,
       
   172 		EDtpChannelConnected,
       
   173 		EDtpChannelClosed,
       
   174 		EPiChannelConnectComplete,
       
   175 		EPiChannelSendComplete,
       
   176 		EPacketReceived,
       
   177 		/** Error events
       
   178 		*/
       
   179 		EPiReset,
       
   180 		EDtpReset,
       
   181 		};
       
   182 	enum TPanic 
       
   183 		{
       
   184 		EPIPanicParserFailure = -1,
       
   185 		EPIPanicMegaOI = -2,
       
   186 		EAddressFamily = -3
       
   187 		};
       
   188 	void InitCommL(void);
       
   189 	//void FTPReply(void);
       
   190 	void UpdateState(const TInternalEvents aEvent);
       
   191 	TInt	iState;
       
   192 	MFtpProtocolNotifier*	iNotifier;
       
   193 	TFTPServerAnswerParser*	iFTPServerAnswerParser;
       
   194 	TFtpPASVAnswerParser*	iFtpPASVAnswerParser;
       
   195 	CPIChannel* iPiChannel;
       
   196 	CDTPChannel* iDtpChannel;
       
   197 	CFTPResolver* iResolver;
       
   198 	/** A pointer to the CFTPSetError object */
       
   199 	CFTPSetError*	iCFTPSetError;
       
   200 	/** A socket server to be used for */
       
   201 	RSocketServ iSockServ;	
       
   202 	/** all socket operations */
       
   203 	/** my local address (to advertise to the server) */
       
   204 	TInetAddr iLocalAddress; 
       
   205 	/** FTP Connection can be passive (server connects on one of my ports) */
       
   206 	TBool iPASVMode;
       
   207 	/** Port number for the DTP Channel (to advertise to the server)
       
   208 		or active, FTP server gives me an address to connect to */
       
   209 	TUint	iPort; 
       
   210 	/** Address of the FTP channel (note: RFC says this 
       
   211 	    IP address can be different than the PI Channel IP address */
       
   212 	TInetAddr iFTPDTPAddress; 
       
   213 	/** Placeholder for the answer I got from the FTP server */
       
   214 	TBuf8<3> iAnswer;	
       
   215 	/** A Buffer to construct FTP commands */
       
   216 	TBuf8<256> iFTPCmdBuffer; 
       
   217 	/** A Buffer to construct FTP commands */
       
   218 	TDes8* iIOBuffer; 
       
   219 	/** helper to Port() */
       
   220 	void BuildPORTCommand(); 
       
   221 	/** helper to Port() */
       
   222 	void BuildEPRTCommand(); 
       
   223 	};
       
   224 #endif //__PROTOCOL_H__