FileZillaApi.h 11 KB

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