FileZillaApi.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //---------------------------------------------------------------------------
  2. #ifndef FileZillaApiH
  3. #define FileZillaApiH
  4. //---------------------------------------------------------------------------
  5. #include "FzApiStructures.h"
  6. #include "structures.h"
  7. #include "AsyncSslSocketLayer.h"
  8. //---------------------------------------------------------------------------
  9. // This structure holds the commands which will be processed by the api.
  10. // You don't have to fill this struct, you may use the command specific
  11. // functions which is easier.
  12. // See below for a list of supported commands and their parameters.
  13. //---------------------------------------------------------------------------
  14. typedef struct
  15. {
  16. int id; // Type of command, see below
  17. CString param1; // Parameters for this command
  18. CString param2;
  19. int param4;
  20. CServerPath path;
  21. CServerPath newPath; // Used for rename
  22. t_transferfile transferfile;
  23. t_server server;
  24. } t_command;
  25. //---------------------------------------------------------------------------
  26. //Description of all api commands
  27. //---------------------------------------------------------------------------
  28. #define FZ_COMMAND_CONNECT 0x0001
  29. // Connects to the server passed in t_command::server
  30. // Possible return values:
  31. // FZ_REPLY_BUSY, FZ_REPLY_ERROR, FZ_REPLY_INVALIDPARAM,
  32. // FZ_REPLY_NOTINITIALIZED, FZ_REPLY_OK, FZ_REPLY_WOULDBLOCK
  33. //---------------------------------------------------------------------------
  34. #define FZ_COMMAND_LIST 0x0002
  35. // Lists the contents of a directory. If no parameter is given, the current
  36. // directory will be listed, else t_command::path specifies the directory
  37. // which contents will be listed. t_command::param1 may specify the name
  38. // of a direct child or parent directory (Use only the last path segment or
  39. // ".."). When the directory listing is successful, it will be sent to the
  40. // owner window (see FZ_DATA_LIST)
  41. // t_command::param4 controls the list mode. (See list modes section)
  42. // Possible return values:
  43. // FZ_REPLY_BUSY, FZ_REPLY_ERROR, FZ_REPLY_INVALIDPARAM,
  44. // FZ_REPLY_NOTCONNECTED, FZ_REPLY_NOTINITIALIZED, FZ_REPLY_OK,
  45. // FZ_REPLY_WOULDBLOCK
  46. //---------------------------------------------------------------------------
  47. #define FZ_COMMAND_FILETRANSFER 0x0004
  48. // Transfers the file specified with t_command::transferfile, see
  49. // t_transferfile for detailed information
  50. // Possible return values:
  51. // FZ_REPLY_BUSY, FZ_REPLY_ERROR, FZ_REPLY_INVALIDPARAM,
  52. // FZ_REPLY_NOTCONNECTED, FZ_REPLY_NOTINITIALIZED, FZ_REPLY_OK,
  53. // FZ_REPLY_WOULDBLOCK
  54. //---------------------------------------------------------------------------
  55. #define FZ_COMMAND_DISCONNECT 0x0008
  56. #define FZ_COMMAND_CUSTOMCOMMAND 0x0010
  57. #define FZ_COMMAND_DELETE 0x0020
  58. #define FZ_COMMAND_REMOVEDIR 0x0040
  59. #define FZ_COMMAND_RENAME 0x0080
  60. #define FZ_COMMAND_MAKEDIR 0x0100
  61. #define FZ_COMMAND_CHMOD 0x0200
  62. #define FZ_COMMAND_LISTFILE 0x0400
  63. //---------------------------------------------------------------------------
  64. #define FZ_MSG_OFFSET 16
  65. #define FZ_MSG_OFFSETMASK 0xFFFF
  66. #define FZ_MSG_ID(x) ((x >> FZ_MSG_OFFSET) & FZ_MSG_OFFSETMASK)
  67. #define FZ_MSG_PARAM(x) ( x & FZ_MSG_OFFSETMASK)
  68. #define FZ_MSG_MAKEMSG(id, param) ((((DWORD)(id & FZ_MSG_OFFSETMASK)) << FZ_MSG_OFFSET) + (param & FZ_MSG_OFFSETMASK) )
  69. //---------------------------------------------------------------------------
  70. #define FZ_MSG_REPLY 0
  71. #define FZ_MSG_LISTDATA 1
  72. #define FZ_MSG_ASYNCREQUEST 5
  73. #define FZ_MSG_STATUS 6
  74. #define FZ_MSG_TRANSFERSTATUS 7
  75. #define FZ_MSG_CAPABILITIES 9
  76. //---------------------------------------------------------------------------
  77. #define FZ_ASYNCREQUEST_OVERWRITE 1
  78. #define FZ_ASYNCREQUEST_VERIFYCERT 2
  79. #ifndef MPEXT_NO_GSS
  80. #define FZ_ASYNCREQUEST_GSS_AUTHFAILED 3
  81. #define FZ_ASYNCREQUEST_GSS_NEEDPASS 4
  82. #endif
  83. #ifndef MPEXT_NO_GSS
  84. #define FZ_ASYNCREQUEST_GSS_NEEDUSER 8
  85. #endif
  86. #define FZ_ASYNCREQUEST_NEEDPASS 10
  87. //---------------------------------------------------------------------------
  88. class CAsyncRequestData
  89. {
  90. public:
  91. CAsyncRequestData();
  92. virtual ~CAsyncRequestData();
  93. int nRequestType;
  94. __int64 nRequestID; //Unique for every request sent
  95. int nRequestResult;
  96. };
  97. //---------------------------------------------------------------------------
  98. class COverwriteRequestData : public CAsyncRequestData
  99. {
  100. public:
  101. COverwriteRequestData();
  102. virtual ~COverwriteRequestData();
  103. CString FileName1;
  104. CString FileName2;
  105. CString path1,path2;
  106. __int64 size1;
  107. __int64 size2;
  108. CTime * localtime;
  109. t_directory::t_direntry::t_date remotetime;
  110. const t_transferfile * pTransferFile;
  111. };
  112. //---------------------------------------------------------------------------
  113. class CVerifyCertRequestData : public CAsyncRequestData
  114. {
  115. public:
  116. CVerifyCertRequestData();
  117. virtual ~CVerifyCertRequestData();
  118. t_SslCertData * pCertData;
  119. };
  120. //---------------------------------------------------------------------------
  121. class CNeedPassRequestData : public CAsyncRequestData
  122. {
  123. public:
  124. CNeedPassRequestData();
  125. virtual ~CNeedPassRequestData();
  126. CString Password;
  127. int nOldOpState;
  128. };
  129. //---------------------------------------------------------------------------
  130. #ifndef MPEXT_NO_GSS
  131. class CGssNeedPassRequestData : public CAsyncRequestData
  132. {
  133. public:
  134. CGssNeedPassRequestData();
  135. virtual ~CGssNeedPassRequestData();
  136. CString pass;
  137. int nOldOpState;
  138. };
  139. //---------------------------------------------------------------------------
  140. class CGssNeedUserRequestData : public CAsyncRequestData
  141. {
  142. public:
  143. CGssNeedUserRequestData();
  144. virtual ~CGssNeedUserRequestData();
  145. CString user;
  146. int nOldOpState;
  147. };
  148. #endif
  149. //---------------------------------------------------------------------------
  150. #define FZAPI_OPTION_SHOWHIDDEN 1
  151. //---------------------------------------------------------------------------
  152. #define FTP_CONNECT 0 // SERVER USER PASS PORT
  153. #define FTP_COMMAND 1 // COMMAND - - -
  154. #define FTP_LIST 2 // - - - -
  155. #define FTP_FILETRANSFER 3 // TRANSFERFILE
  156. #define FTP_DISCONNECT 4 // - - - -
  157. #define FTP_RECONNECT 5 // - - - -
  158. #define FTP_DELETE 7 // FILENAME
  159. #define FTP_REMOVEDIR 8 // DIRNAME
  160. //---------------------------------------------------------------------------
  161. #define FZ_REPLY_OK 0x0001
  162. #define FZ_REPLY_WOULDBLOCK 0x0002
  163. #define FZ_REPLY_ERROR 0x0004
  164. #define FZ_REPLY_OWNERNOTSET 0x0008
  165. #define FZ_REPLY_INVALIDPARAM 0x0010
  166. #define FZ_REPLY_NOTCONNECTED 0x0020
  167. #define FZ_REPLY_ALREADYCONNECTED 0x0040
  168. #define FZ_REPLY_BUSY 0x0080
  169. #define FZ_REPLY_IDLE 0x0100
  170. #define FZ_REPLY_NOTINITIALIZED 0x0200
  171. #define FZ_REPLY_ALREADYINIZIALIZED 0x0400
  172. #define FZ_REPLY_CANCEL 0x0800
  173. #define FZ_REPLY_DISCONNECTED 0x1000 // Always sent when disconnected from server
  174. #define FZ_REPLY_CRITICALERROR 0x2000 // Used for FileTransfers only
  175. #define FZ_REPLY_ABORTED 0x4000 // Used for FileTransfers only
  176. #define FZ_REPLY_NOTSUPPORTED 0x8000 // Command is not supported for the current server
  177. //---------------------------------------------------------------------------
  178. // Additional replies
  179. #define FZ_REPLY_NOTBUSY FZ_REPLY_IDLE
  180. //---------------------------------------------------------------------------
  181. // Servertypes
  182. // General types
  183. #define FZ_SERVERTYPE_HIGHMASK 0xF000
  184. #define FZ_SERVERTYPE_SUBMASK 0x00FF
  185. #define FZ_SERVERTYPE_LAYERMASK 0x0FF0
  186. #define FZ_SERVERTYPE_FTP 0x1000
  187. #define FZ_SERVERTYPE_LAYER_SSL_IMPLICIT 0x0100
  188. #define FZ_SERVERTYPE_LAYER_SSL_EXPLICIT 0x0200
  189. #define FZ_SERVERTYPE_LAYER_TLS_EXPLICIT 0x0400
  190. #define FZ_SERVERTYPE_SUB_FTP_VMS 0x0001
  191. #define FZ_SERVERTYPE_SUB_FTP_SFTP 0x0002
  192. #define FZ_SERVERTYPE_SUB_FTP_WINDOWS 0x0004
  193. #define FZ_SERVERTYPE_SUB_FTP_MVS 0x0010
  194. #define FZ_SERVERTYPE_SUB_FTP_BS2000 0x0020
  195. //---------------------------------------------------------------------------
  196. // Log messages
  197. #define FZ_LOG_STATUS 0
  198. #define FZ_LOG_ERROR 1
  199. #define FZ_LOG_COMMAND 2
  200. #define FZ_LOG_REPLY 3
  201. // By calling CFileZillaApi::SetDebugLevel, the aplication can enable logging of the following messages:
  202. #define FZ_LOG_APIERROR 5
  203. #define FZ_LOG_WARNING 6
  204. #define FZ_LOG_PROGRESS 7
  205. #define FZ_LOG_INFO 8
  206. #define FZ_LOG_DEBUG 9
  207. //---------------------------------------------------------------------------
  208. class CMainThread;
  209. class CFileZillaTools;
  210. //---------------------------------------------------------------------------
  211. class CFileZillaApi
  212. {
  213. public:
  214. CFileZillaApi();
  215. virtual ~CFileZillaApi();
  216. void SetDebugLevel(int nDebugLevel);
  217. int CustomCommand(CString command);
  218. int Delete(CString FileName, const CServerPath & path, bool filenameOnly);
  219. int RemoveDir(CString DirName, const CServerPath & path = CServerPath());
  220. int Rename(CString oldName, CString newName, const CServerPath & path = CServerPath(), const CServerPath & newPath = CServerPath());
  221. int MakeDir(const CServerPath & path);
  222. // General async request reply function
  223. int SetAsyncRequestResult(int nAction, CAsyncRequestData * pData);
  224. int Disconnect();
  225. int Cancel();
  226. int Chmod(int nValue, CString FileName, const CServerPath & path = CServerPath());
  227. //Initialization
  228. int Init(TFileZillaIntern * Intern, CFileZillaTools * pTools);
  229. // Operations
  230. int Connect(const t_server & server);
  231. int List(const CServerPath & path);
  232. int ListFile(CString FileName, const CServerPath & path); //Get info about specified file
  233. int FileTransfer(const t_transferfile & TransferFile);
  234. int GetCurrentServer(t_server & server);
  235. int SetCurrentPath(CServerPath path);
  236. int GetCurrentPath(CServerPath & path);
  237. bool UsingMlsd();
  238. bool UsingUtf8();
  239. std::string GetTlsVersionStr();
  240. std::string GetCipherName();
  241. protected:
  242. CMainThread * m_pMainThread;
  243. unsigned int m_nInternalMessageID;
  244. BOOL m_bInitialized;
  245. void Destroy();
  246. int IsBusy();
  247. int IsConnected();
  248. };
  249. //---------------------------------------------------------------------------
  250. #endif // FileZillaApiH