FileZillaApi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // FileZilla - a Windows ftp client
  2. // Copyright (C) 2002-2004 - Tim Kosse <[email protected]>
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. // FileZillaApi.h: Schnittstelle für die Klasse CFileZillaApi.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #if !defined(AFX_FILEZILLAAPI_H__F1970156_455F_4495_A813_4B676F0F03E5__INCLUDED_)
  18. #define AFX_FILEZILLAAPI_H__F1970156_455F_4495_A813_4B676F0F03E5__INCLUDED_
  19. #if _MSC_VER > 1000
  20. #pragma once
  21. #endif // _MSC_VER > 1000
  22. #include "FzApiStructures.h"
  23. #ifndef MPEXT_NO_SSL
  24. #include "AsyncSslSocketLayer.h"
  25. #endif
  26. //This structure holds the commands which will be processed by the api.
  27. //You don't have to fill this struct, you may use the command specific
  28. //functions which is easier.
  29. //See below for a list of supported commands and their parameters.
  30. typedef struct
  31. {
  32. int id; //Type of command, see below
  33. CString param1; //Parameters for this command
  34. CString param2;
  35. int param4;
  36. CServerPath path;
  37. CServerPath newPath; //Used for rename
  38. t_transferfile transferfile;
  39. t_server server;
  40. } t_command;
  41. //Description of all api commands
  42. #define FZ_COMMAND_CONNECT 0x0001
  43. //Connects to the server passed in t_command::server
  44. //Possible return values:
  45. //FZ_REPLY_BUSY, FZ_REPLY_ERROR, FZ_REPLY_INVALIDPARAM,
  46. //FZ_REPLY_NOTINITIALIZED, FZ_REPLY_OK, FZ_REPLY_WOULDBLOCK
  47. #define FZ_COMMAND_LIST 0x0002
  48. //Lists the contents of a directory. If no parameter is given, the current
  49. //directory will be listed, else t_command::path specifies the directory
  50. //which contents will be listed. t_command::param1 may specify the name
  51. //of a direct child or parent directory (Use only the last path segment or
  52. //".."). When the directory listing is successful, it will be sent to the
  53. //owner window (see FZ_DATA_LIST)
  54. //t_command::param4 controls the list mode. (See list modes section)
  55. //Possible return values:
  56. //FZ_REPLY_BUSY, FZ_REPLY_ERROR, FZ_REPLY_INVALIDPARAM,
  57. //FZ_REPLY_NOTCONNECTED, FZ_REPLY_NOTINITIALIZED, FZ_REPLY_OK,
  58. //FZ_REPLY_WOULDBLOCK
  59. #define FZ_COMMAND_FILETRANSFER 0x0004
  60. //Transfers the file specified with t_command::transferfile, see
  61. //t_transferfile for detailed information
  62. //Possible return values:
  63. //FZ_REPLY_BUSY, FZ_REPLY_ERROR, FZ_REPLY_INVALIDPARAM,
  64. //FZ_REPLY_NOTCONNECTED, FZ_REPLY_NOTINITIALIZED, FZ_REPLY_OK,
  65. //FZ_REPLY_WOULDBLOCK
  66. #define FZ_COMMAND_DISCONNECT 0x0008
  67. #define FZ_COMMAND_CUSTOMCOMMAND 0x0010
  68. #define FZ_COMMAND_DELETE 0x0020
  69. #define FZ_COMMAND_REMOVEDIR 0x0040
  70. #define FZ_COMMAND_RENAME 0x0080
  71. #define FZ_COMMAND_MAKEDIR 0x0100
  72. #define FZ_COMMAND_CHMOD 0x0200
  73. #ifdef MPEXT
  74. #define FZ_COMMAND_LISTFILE 0x0400
  75. #endif
  76. #define FZ_MSG_OFFSET 16
  77. #define FZ_MSG_OFFSETMASK 0xFFFF
  78. #define FZ_MSG_ID(x) ((x >> FZ_MSG_OFFSET) & FZ_MSG_OFFSETMASK)
  79. #define FZ_MSG_PARAM(x) ( x & FZ_MSG_OFFSETMASK)
  80. #define FZ_MSG_MAKEMSG(id, param) ((((DWORD)(id & FZ_MSG_OFFSETMASK)) << FZ_MSG_OFFSET) + (param & FZ_MSG_OFFSETMASK) )
  81. #define FZ_MSG_REPLY 0
  82. #define FZ_MSG_LISTDATA 1
  83. #define FZ_MSG_SOCKETSTATUS 3
  84. #define FZ_MSG_SECURESERVER 4
  85. #define FZ_MSG_ASYNCREQUEST 5
  86. #define FZ_MSG_STATUS 6
  87. #define FZ_MSG_TRANSFERSTATUS 7
  88. #define FZ_MSG_QUITCOMPLETE 8
  89. #ifdef MPEXT
  90. #define FZ_MSG_CAPABILITIES 9
  91. #endif
  92. #ifdef MPEXT
  93. #define FZ_CAPABILITIES_MFMT 0x01
  94. #endif
  95. #define FZ_ASYNCREQUEST_OVERWRITE 1
  96. #ifndef MPEXT_NO_SSL
  97. #define FZ_ASYNCREQUEST_VERIFYCERT 2
  98. #endif
  99. #ifndef MPEXT_NO_GSS
  100. #define FZ_ASYNCREQUEST_GSS_AUTHFAILED 3
  101. #define FZ_ASYNCREQUEST_GSS_NEEDPASS 4
  102. #endif
  103. #ifndef MPEXT_NO_SFTP
  104. #define FZ_ASYNCREQUEST_NEWHOSTKEY 5
  105. #define FZ_ASYNCREQUEST_CHANGEDHOSTKEY 6
  106. #define FZ_ASYNCREQUEST_KEYBOARDINTERACTIVE 7
  107. #endif
  108. #ifndef MPEXT_NO_GSS
  109. #define FZ_ASYNCREQUEST_GSS_NEEDUSER 8
  110. #endif
  111. #define FZ_ASYNCREQUEST_NEEDPASS 10
  112. class CAsyncRequestData
  113. {
  114. public:
  115. CAsyncRequestData();
  116. virtual ~CAsyncRequestData();
  117. int nRequestType;
  118. __int64 nRequestID; //Unique for every request sent
  119. int nRequestResult;
  120. };
  121. class COverwriteRequestData : public CAsyncRequestData
  122. {
  123. public:
  124. COverwriteRequestData();
  125. virtual ~COverwriteRequestData();
  126. CString FileName1;
  127. CString FileName2;
  128. CString path1,path2;
  129. __int64 size1;
  130. __int64 size2;
  131. CTime *time1;
  132. CTime *time2;
  133. const t_transferfile *pTransferFile;
  134. };
  135. #ifndef MPEXT_NO_SSL
  136. class CVerifyCertRequestData : public CAsyncRequestData
  137. {
  138. public:
  139. CVerifyCertRequestData();
  140. virtual ~CVerifyCertRequestData();
  141. t_SslCertData *pCertData;
  142. };
  143. #endif
  144. class CNeedPassRequestData : public CAsyncRequestData
  145. {
  146. public:
  147. CNeedPassRequestData();
  148. virtual ~CNeedPassRequestData();
  149. CString Password;
  150. int nOldOpState;
  151. };
  152. #ifndef MPEXT_NO_GSS
  153. class CGssNeedPassRequestData : public CAsyncRequestData
  154. {
  155. public:
  156. CGssNeedPassRequestData();
  157. virtual ~CGssNeedPassRequestData();
  158. CString pass;
  159. int nOldOpState;
  160. };
  161. class CGssNeedUserRequestData : public CAsyncRequestData
  162. {
  163. public:
  164. CGssNeedUserRequestData();
  165. virtual ~CGssNeedUserRequestData();
  166. CString user;
  167. int nOldOpState;
  168. };
  169. #endif
  170. #ifndef MPEXT_NO_SFTP
  171. class CNewHostKeyRequestData : public CAsyncRequestData
  172. {
  173. public:
  174. CNewHostKeyRequestData();
  175. virtual ~CNewHostKeyRequestData();
  176. CString Hostkey;
  177. };
  178. class CChangedHostKeyRequestData : public CAsyncRequestData
  179. {
  180. public:
  181. CChangedHostKeyRequestData();
  182. virtual ~CChangedHostKeyRequestData();
  183. CString Hostkey;
  184. };
  185. class CKeyboardInteractiveRequestData : public CAsyncRequestData
  186. {
  187. public:
  188. char data[20480];
  189. };
  190. #endif
  191. #define FZ_SOCKETSTATUS_RECV 0
  192. #define FZ_SOCKETSTATUS_SEND 1
  193. #define FZAPI_OPTION_SHOWHIDDEN 1
  194. #define FTP_CONNECT 0 // SERVER USER PASS PORT
  195. #define FTP_COMMAND 1 //COMMAND - - -
  196. #define FTP_LIST 2 //- - - -
  197. #define FTP_FILETRANSFER 3 //TRANSFERFILE
  198. #define FTP_DISCONNECT 4 //- - - -
  199. #define FTP_RECONNECT 5 //- - - -
  200. #ifndef MPEXT_NO_CACHE
  201. #define FTP_LISTCACHE 6 //- - - - Directory listing may be read from cache
  202. #endif
  203. #define FTP_DELETE 7 //FILENAME
  204. #define FTP_REMOVEDIR 8 //DIRNAME
  205. #define FZ_REPLY_OK 0x0001
  206. #define FZ_REPLY_WOULDBLOCK 0x0002
  207. #define FZ_REPLY_ERROR 0x0004
  208. #define FZ_REPLY_OWNERNOTSET 0x0008
  209. #define FZ_REPLY_INVALIDPARAM 0x0010
  210. #define FZ_REPLY_NOTCONNECTED 0x0020
  211. #define FZ_REPLY_ALREADYCONNECTED 0x0040
  212. #define FZ_REPLY_BUSY 0x0080
  213. #define FZ_REPLY_IDLE 0x0100
  214. #define FZ_REPLY_NOTINITIALIZED 0x0200
  215. #define FZ_REPLY_ALREADYINIZIALIZED 0x0400
  216. #define FZ_REPLY_CANCEL 0x0800
  217. #define FZ_REPLY_DISCONNECTED 0x1000 //Always sent when disconnected from server
  218. #define FZ_REPLY_CRITICALERROR 0x2000 //Used for FileTransfers only
  219. #define FZ_REPLY_ABORTED 0x4000 //Used for FileTransfers only
  220. #define FZ_REPLY_NOTSUPPORTED 0x8000 //Command is not supported for the current server
  221. #define FZ_LIST_USECACHE 0x0001
  222. #define FZ_LIST_FORCECACHE 0x0002
  223. #define FZ_LIST_REALCHANGE 0x0004
  224. #define FZ_LIST_EXACT 0x0008
  225. //Additional replies
  226. #define FZ_REPLY_NOTBUSY FZ_REPLY_IDLE
  227. //Servertypes
  228. //General types
  229. #define FZ_SERVERTYPE_HIGHMASK 0xF000
  230. #define FZ_SERVERTYPE_SUBMASK 0x00FF
  231. #define FZ_SERVERTYPE_LAYERMASK 0x0FF0
  232. #define FZ_SERVERTYPE_FTP 0x1000
  233. #define FZ_SERVERTYPE_LOCAL 0x2000
  234. #ifndef MPEXT_NO_SSL
  235. #define FZ_SERVERTYPE_LAYER_SSL_IMPLICIT 0x0100
  236. #define FZ_SERVERTYPE_LAYER_SSL_EXPLICIT 0x0200
  237. #define FZ_SERVERTYPE_LAYER_TLS_EXPLICIT 0x0400
  238. #endif
  239. #define FZ_SERVERTYPE_SUB_FTP_VMS 0x0001
  240. #define FZ_SERVERTYPE_SUB_FTP_SFTP 0x0002
  241. #define FZ_SERVERTYPE_SUB_FTP_WINDOWS 0x0004
  242. #define FZ_SERVERTYPE_SUB_FTP_UNKNOWN 0x0008
  243. #define FZ_SERVERTYPE_SUB_FTP_MVS 0x0010
  244. #define FZ_SERVERTYPE_SUB_FTP_BS2000 0x0020
  245. //Log messages
  246. #define FZ_LOG_STATUS 0
  247. #define FZ_LOG_ERROR 1
  248. #define FZ_LOG_COMMAND 2
  249. #define FZ_LOG_REPLY 3
  250. #define FZ_LOG_LIST 4
  251. //By calling CFileZillaApi::SetDebugLevel, the aplication can enable loggint of the following messages:
  252. #define FZ_LOG_APIERROR 5
  253. #define FZ_LOG_WARNING 6
  254. #define FZ_LOG_INFO 7
  255. #define FZ_LOG_DEBUG 8
  256. class CMainThread;
  257. class CFileZillaApi
  258. {
  259. public:
  260. BOOL IsValid() const;
  261. #ifndef MPEXT
  262. int GetOption( int nOption, int &value );
  263. int SetOption( int nOption, int value );
  264. #endif
  265. int SetDebugLevel( int nDebugLevel );
  266. int CustomCommand(CString command);
  267. int Delete(CString FileName, const CServerPath &path = CServerPath());
  268. int RemoveDir(CString DirName, const CServerPath &path = CServerPath());
  269. int Rename(CString oldName,CString newName, const CServerPath &path = CServerPath(), const CServerPath &newPath = CServerPath());
  270. int MakeDir(const CServerPath &path);
  271. //Functions to reply to async requests
  272. //General reply function
  273. int SetAsyncRequestResult(int nAction, CAsyncRequestData *pData);
  274. int Command(t_command *pCommand);
  275. int Disconnect();
  276. void Destroy();
  277. int Cancel();
  278. int Chmod(int nValue, CString FileName, const CServerPath &path = CServerPath());
  279. CFileZillaApi();
  280. virtual ~CFileZillaApi();
  281. //Initialization
  282. #ifndef MPEXT
  283. int Init(HWND hOwnerWnd, int nReplyMessageID = 0);
  284. #else
  285. int Init(CApiLog * pParent);
  286. #endif
  287. unsigned int GetMessageID();
  288. //Status
  289. int IsConnected();
  290. int IsBusy();
  291. //Operations
  292. int Connect(const t_server& server);
  293. int List(int nListMode=FZ_LIST_USECACHE); //Lists current folder
  294. int List(const CServerPath& path, int nListMode=FZ_LIST_USECACHE);
  295. int List(const CServerPath& parent, CString dirname, int nListMode=FZ_LIST_USECACHE);
  296. int ListFile(const CServerPath& path, const CString& fileName); //Get info about specified file
  297. int FileTransfer(const t_transferfile &TransferFile);
  298. int GetCurrentServer(t_server &server);
  299. #ifdef MPEXT
  300. int SetCurrentPath(CServerPath path);
  301. int GetCurrentPath(CServerPath & path);
  302. #endif
  303. #ifndef MPEXT_NO_CACHE
  304. //Debugging functions
  305. static BOOL DumpDirectoryCache(LPCTSTR pFileName);
  306. #endif
  307. protected:
  308. CMainThread* m_pMainThread;
  309. unsigned int m_nInternalMessageID;
  310. BOOL m_bInitialized;
  311. unsigned int m_nReplyMessageID;
  312. HWND m_hOwnerWnd;
  313. };
  314. #endif // !defined(AFX_FILEZILLAAPI_H__F1970156_455F_4495_A813_4B676F0F03E5__INCLUDED_)