|
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 * EPOC32 FTP Engine header file |
|
16 * Author: Philippe Gabriel |
|
17 * Exports set of APIs simplyfying access to the FTP protocol |
|
18 * |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 @file SESSION.H |
|
26 @internalComponent |
|
27 */ |
|
28 |
|
29 #if !defined(__SESSION_H__) |
|
30 #define __SESSION_H__ |
|
31 #include <e32base.h> |
|
32 #include <es_sock.h> |
|
33 #include <f32file.h> |
|
34 #include <ftpprot.h> |
|
35 #include <ftpsess.h> |
|
36 #include "SETERROR.H" |
|
37 |
|
38 //class CFtpProtocol; |
|
39 //class CFtpSessSetError; |
|
40 |
|
41 /** |
|
42 MInterface definition to provide callback functions to the client |
|
43 */ |
|
44 |
|
45 class MSetErrorNotifier; |
|
46 NONSHARABLE_CLASS(CFTPSessionDerived) : public CFTPSession,public MFtpProtocolNotifier,MSetErrorNotifier |
|
47 /** |
|
48 The CFTPSession class |
|
49 @internalComponent |
|
50 */ |
|
51 { |
|
52 public: |
|
53 /** Define the CFTPSetError callback notifier */ |
|
54 void SetErrorNotifier(const TInt); |
|
55 /** Define the CFtpProtocol callback notifiers */ |
|
56 void ServerMessage(const TDesC8& aMessage); |
|
57 void ServerPositiveAnswerNotification(const TOpComp aStatus); |
|
58 void ServerXFerNotification(const TOpComp aStatus); |
|
59 void ServerNegativeAnswerNotification(const TOpComp aStatus); |
|
60 void ErrorNotification(const TOpComp aStatus); |
|
61 /** Construction */ |
|
62 static CFTPSessionDerived* NewL(MFtpSessionNotifier* aNotifier); |
|
63 |
|
64 /** Destruction */ |
|
65 ~CFTPSessionDerived(); |
|
66 |
|
67 /** Connection APIs */ |
|
68 |
|
69 /** Establish a connection with a server: */ |
|
70 virtual void Connect( const TSockAddr& aNetAddr, //IP address |
|
71 const TDesC8& aUserName, |
|
72 const TDesC8& aPassword, |
|
73 const TConnectionMode aConnectionMode=EActive); |
|
74 |
|
75 virtual void Connect( const THostName& aServerName, //DNS name |
|
76 const TDesC8& aUserName, |
|
77 const TDesC8& aPassword, |
|
78 const TConnectionMode aConnectionMode=EActive, |
|
79 const TUint aPort=KDefaultServerPiPort); |
|
80 |
|
81 /** Close connection with a server */ |
|
82 virtual void Close(); |
|
83 |
|
84 /** Cancel last FTP operation */ |
|
85 virtual void Cancel(); |
|
86 |
|
87 /** Restart an aborted transfer operation */ |
|
88 virtual void Restart(const TUint aTFTPRestartOffset); |
|
89 |
|
90 /** Transfer APIs */ |
|
91 |
|
92 /** Store a file on the server */ |
|
93 virtual void Store(const TDesC& aLocalFileName, |
|
94 const TDesC8& aNewRemoteFileName, |
|
95 const TBool aOverwrite = FALSE, |
|
96 const RepresentationType aRepresentationType = EBinary, |
|
97 const TransferMode aTransferMode = EStream); |
|
98 |
|
99 /** Get a file from the server */ |
|
100 virtual void Retrieve( const TDesC8& aRemoteFileName, |
|
101 const TDesC& aNewLocalFileName, |
|
102 const TOpenMode aOpenMode = EOverwrite, |
|
103 const RepresentationType aRepresentationType = EBinary, |
|
104 const TransferMode aTransferMode = EStream); |
|
105 |
|
106 /** File system management functions */ |
|
107 virtual void ChangeDirectory(const TDesC8& aDirectoryName); |
|
108 virtual void CreateDirectory(const TDesC8& aDirectoryName); |
|
109 virtual void DeleteDirectory(const TDesC8& aDirectoryName); |
|
110 virtual void GetCurrentDirectory(void); |
|
111 virtual void ListDirectory(const TDesC8& aDirectoryName, |
|
112 TDes8& aFileList); |
|
113 |
|
114 virtual void DeleteFile(const TDesC8& aFileName); |
|
115 virtual void RenameFile( const TDesC8& aRemoteFileName, |
|
116 const TDesC8& aNewRemoteFileName); |
|
117 private: |
|
118 /** C++ constructor - not exported; implicitly called from NewL() */ |
|
119 CFTPSessionDerived(void); |
|
120 /** 2nd phase construction, called by NewL() */ |
|
121 void ConstructL(MFtpSessionNotifier* aNotifier); |
|
122 void NormalTransition(void); |
|
123 void ErrorTransition(const MFtpProtocolNotifier::TOpComp); |
|
124 enum TState |
|
125 { |
|
126 EIdle, |
|
127 EConnecting,EConnected,ELoginUser,ELoginPass,EClosing, |
|
128 EGetCurrentDirectory,EChangeDirectory,ECreateDirectory, |
|
129 EDeleteDirectory,EDeleteFile,ERenameFileFrom, |
|
130 ERenameFileTo, |
|
131 EInitiateListOperation,EInitiateRetrieveOperation,EInitiateStoreOperation, |
|
132 EPerformingPortForList,EPerformingPasvForList,EPerformingList, |
|
133 EPerformingTypeForRetrieve,EPerformingTypeForStore, |
|
134 EPerformingRestForRetrieve,EPerformingRestForStore, |
|
135 EPerformingPortForRetrieve,EPerformingPasvForRetrieve,ERetrieveFile, |
|
136 EPerformingPortForStore,EPerformingPasvForStore,EStoreFile,EStoreFileSendEOF, |
|
137 EAbortingStore,EAbortingRetrieve,EAbortingList |
|
138 }; |
|
139 TState UpdateState(TState,MFtpProtocolNotifier::TOpComp); |
|
140 TInt debugInt; |
|
141 TState iState; |
|
142 /** A pointer to the set of callback notifiers */ |
|
143 MFtpSessionNotifier* iFtpSessionNotifier; |
|
144 /** A pointer to the CFTPProtocol object */ |
|
145 CFtpProtocol* iCFtpProtocol; |
|
146 /** A pointer to the CFTPSetError object */ |
|
147 CFTPSetError* iCFTPSetError; |
|
148 TBool FileServerInitialised; |
|
149 RFs iFs; |
|
150 RFile iFile; |
|
151 TBool iFileOpErrorOccured; |
|
152 /** The current representation type */ |
|
153 RepresentationType iCurrentRepresentationType; |
|
154 /** A placeholder for the parameter passed to retrieve and store functions*/ |
|
155 RepresentationType iNewRepresentationType; |
|
156 /** An offset for the FTP REST command to perform a restart */ |
|
157 TUint iRESTOffset; |
|
158 /** FTP Connection can be passive (server connects on one of my ports) */ |
|
159 TBool iPASVMode; |
|
160 /** |
|
161 A place holder buffer for my API parameters |
|
162 client can pass me pointer to params stored on its stack |
|
163 need to copy them to a safe place so I can use them latter |
|
164 when the scheduler calls my notifier |
|
165 */ |
|
166 TBuf8<512> iBuffer1; |
|
167 TBuf8<512> iBuffer2; |
|
168 TBuf8<5000> iFileXferBuffer[2]; |
|
169 TInt iCurrentXferBuffer; |
|
170 TDes8* iFileList; |
|
171 TInt iTInt1,iTInt2; |
|
172 TBool iTBool1; |
|
173 /** Placeholder for the answer I got from the FTP server */ |
|
174 TBuf<3> iServerAnswer; |
|
175 TBuf<256> iRenamedLocalFileName; |
|
176 TBool iTempStore; |
|
177 TBool iFirstRun; //first run of ServerXFerNotification |
|
178 }; |
|
179 #endif |