FileZillaApi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. #define FZ_MSG_OFFSET 16
  74. #define FZ_MSG_OFFSETMASK 0xFFFF
  75. #define FZ_MSG_ID(x) ((x >> FZ_MSG_OFFSET) & FZ_MSG_OFFSETMASK)
  76. #define FZ_MSG_PARAM(x) ( x & FZ_MSG_OFFSETMASK)
  77. #define FZ_MSG_MAKEMSG(id, param) ((((DWORD)(id & FZ_MSG_OFFSETMASK)) << FZ_MSG_OFFSET) + (param & FZ_MSG_OFFSETMASK) )
  78. #define FZ_MSG_REPLY 0
  79. #define FZ_MSG_LISTDATA 1
  80. #define FZ_MSG_SOCKETSTATUS 3
  81. #define FZ_MSG_SECURESERVER 4
  82. #define FZ_MSG_ASYNCREQUEST 5
  83. #define FZ_MSG_STATUS 6
  84. #define FZ_MSG_TRANSFERSTATUS 7
  85. #define FZ_MSG_QUITCOMPLETE 8
  86. #ifdef MPEXT
  87. #define FZ_MSG_CAPABILITIES 9
  88. #endif
  89. #ifdef MPEXT
  90. #define FZ_CAPABILITIES_MFMT 0x01
  91. #endif
  92. #define FZ_ASYNCREQUEST_OVERWRITE 1
  93. #ifndef MPEXT_NO_SSL
  94. #define FZ_ASYNCREQUEST_VERIFYCERT 2
  95. #endif
  96. #ifndef MPEXT_NO_GSS
  97. #define FZ_ASYNCREQUEST_GSS_AUTHFAILED 3
  98. #define FZ_ASYNCREQUEST_GSS_NEEDPASS 4
  99. #endif
  100. #ifndef MPEXT_NO_SFTP
  101. #define FZ_ASYNCREQUEST_NEWHOSTKEY 5
  102. #define FZ_ASYNCREQUEST_CHANGEDHOSTKEY 6
  103. #define FZ_ASYNCREQUEST_KEYBOARDINTERACTIVE 7
  104. #endif
  105. #ifndef MPEXT_NO_GSS
  106. #define FZ_ASYNCREQUEST_GSS_NEEDUSER 8
  107. #endif
  108. class CAsyncRequestData
  109. {
  110. public:
  111. CAsyncRequestData();
  112. virtual ~CAsyncRequestData();
  113. int nRequestType;
  114. __int64 nRequestID; //Unique for every request sent
  115. int nRequestResult;
  116. };
  117. class COverwriteRequestData : public CAsyncRequestData
  118. {
  119. public:
  120. COverwriteRequestData();
  121. virtual ~COverwriteRequestData();
  122. CString FileName1;
  123. CString FileName2;
  124. CString path1,path2;
  125. __int64 size1;
  126. __int64 size2;
  127. CTime *time1;
  128. CTime *time2;
  129. const t_transferfile *pTransferFile;
  130. };
  131. #ifndef MPEXT_NO_SSL
  132. class CVerifyCertRequestData : public CAsyncRequestData
  133. {
  134. public:
  135. CVerifyCertRequestData();
  136. virtual ~CVerifyCertRequestData();
  137. t_SslCertData *pCertData;
  138. };
  139. #endif
  140. #ifndef MPEXT_NO_GSS
  141. class CGssNeedPassRequestData : public CAsyncRequestData
  142. {
  143. public:
  144. CGssNeedPassRequestData();
  145. virtual ~CGssNeedPassRequestData();
  146. CString pass;
  147. int nOldOpState;
  148. };
  149. class CGssNeedUserRequestData : public CAsyncRequestData
  150. {
  151. public:
  152. CGssNeedUserRequestData();
  153. virtual ~CGssNeedUserRequestData();
  154. CString user;
  155. int nOldOpState;
  156. };
  157. #endif
  158. #ifndef MPEXT_NO_SFTP
  159. class CNewHostKeyRequestData : public CAsyncRequestData
  160. {
  161. public:
  162. CNewHostKeyRequestData();
  163. virtual ~CNewHostKeyRequestData();
  164. CString Hostkey;
  165. };
  166. class CChangedHostKeyRequestData : public CAsyncRequestData
  167. {
  168. public:
  169. CChangedHostKeyRequestData();
  170. virtual ~CChangedHostKeyRequestData();
  171. CString Hostkey;
  172. };
  173. class CKeyboardInteractiveRequestData : public CAsyncRequestData
  174. {
  175. public:
  176. char data[20480];
  177. };
  178. #endif
  179. #define FZ_SOCKETSTATUS_RECV 0
  180. #define FZ_SOCKETSTATUS_SEND 1
  181. #define FZAPI_OPTION_SHOWHIDDEN 1
  182. #define FTP_CONNECT 0 // SERVER USER PASS PORT
  183. #define FTP_COMMAND 1 //COMMAND - - -
  184. #define FTP_LIST 2 //- - - -
  185. #define FTP_FILETRANSFER 3 //TRANSFERFILE
  186. #define FTP_DISCONNECT 4 //- - - -
  187. #define FTP_RECONNECT 5 //- - - -
  188. #ifndef MPEXT_NO_CACHE
  189. #define FTP_LISTCACHE 6 //- - - - Directory listing may be read from cache
  190. #endif
  191. #define FTP_DELETE 7 //FILENAME
  192. #define FTP_REMOVEDIR 8 //DIRNAME
  193. #define FZ_REPLY_OK 0x0001
  194. #define FZ_REPLY_WOULDBLOCK 0x0002
  195. #define FZ_REPLY_ERROR 0x0004
  196. #define FZ_REPLY_OWNERNOTSET 0x0008
  197. #define FZ_REPLY_INVALIDPARAM 0x0010
  198. #define FZ_REPLY_NOTCONNECTED 0x0020
  199. #define FZ_REPLY_ALREADYCONNECTED 0x0040
  200. #define FZ_REPLY_BUSY 0x0080
  201. #define FZ_REPLY_IDLE 0x0100
  202. #define FZ_REPLY_NOTINITIALIZED 0x0200
  203. #define FZ_REPLY_ALREADYINIZIALIZED 0x0400
  204. #define FZ_REPLY_CANCEL 0x0800
  205. #define FZ_REPLY_DISCONNECTED 0x1000 //Always sent when disconnected from server
  206. #define FZ_REPLY_CRITICALERROR 0x2000 //Used for FileTransfers only
  207. #define FZ_REPLY_ABORTED 0x4000 //Used for FileTransfers only
  208. #define FZ_REPLY_NOTSUPPORTED 0x8000 //Command is not supported for the current server
  209. #define FZ_LIST_USECACHE 0x0001
  210. #define FZ_LIST_FORCECACHE 0x0002
  211. #define FZ_LIST_REALCHANGE 0x0004
  212. #define FZ_LIST_EXACT 0x0008
  213. //Additional replies
  214. #define FZ_REPLY_NOTBUSY FZ_REPLY_IDLE
  215. //Servertypes
  216. //General types
  217. #define FZ_SERVERTYPE_HIGHMASK 0xF000
  218. #define FZ_SERVERTYPE_SUBMASK 0x00FF
  219. #define FZ_SERVERTYPE_LAYERMASK 0x0FF0
  220. #define FZ_SERVERTYPE_FTP 0x1000
  221. #define FZ_SERVERTYPE_LOCAL 0x2000
  222. #ifndef MPEXT_NO_SSL
  223. #define FZ_SERVERTYPE_LAYER_SSL_IMPLICIT 0x0100
  224. #define FZ_SERVERTYPE_LAYER_SSL_EXPLICIT 0x0200
  225. #define FZ_SERVERTYPE_LAYER_TLS_EXPLICIT 0x0400
  226. #endif
  227. #define FZ_SERVERTYPE_SUB_FTP_VMS 0x0001
  228. #define FZ_SERVERTYPE_SUB_FTP_SFTP 0x0002
  229. #define FZ_SERVERTYPE_SUB_FTP_WINDOWS 0x0004
  230. #define FZ_SERVERTYPE_SUB_FTP_UNKNOWN 0x0008
  231. #define FZ_SERVERTYPE_SUB_FTP_MVS 0x0010
  232. #define FZ_SERVERTYPE_SUB_FTP_BS2000 0x0020
  233. //Log messages
  234. #define FZ_LOG_STATUS 0
  235. #define FZ_LOG_ERROR 1
  236. #define FZ_LOG_COMMAND 2
  237. #define FZ_LOG_REPLY 3
  238. #define FZ_LOG_LIST 4
  239. //By calling CFileZillaApi::SetDebugLevel, the aplication can enable loggint of the following messages:
  240. #define FZ_LOG_APIERROR 5
  241. #define FZ_LOG_WARNING 6
  242. #define FZ_LOG_INFO 7
  243. #define FZ_LOG_DEBUG 8
  244. class CMainThread;
  245. class CFileZillaApi
  246. {
  247. public:
  248. BOOL IsValid() const;
  249. #ifndef MPEXT
  250. int GetOption( int nOption, int &value );
  251. int SetOption( int nOption, int value );
  252. #endif
  253. int SetDebugLevel( int nDebugLevel );
  254. int CustomCommand(CString command);
  255. int Delete(CString FileName, const CServerPath &path = CServerPath());
  256. int RemoveDir(CString DirName, const CServerPath &path = CServerPath());
  257. int Rename(CString oldName,CString newName, const CServerPath &path = CServerPath(), const CServerPath &newPath = CServerPath());
  258. int MakeDir(const CServerPath &path);
  259. //Functions to reply to async requests
  260. //General reply function
  261. int SetAsyncRequestResult(int nAction, CAsyncRequestData *pData);
  262. int Command(t_command *pCommand);
  263. int Disconnect();
  264. void Destroy();
  265. int Cancel();
  266. int Chmod(int nValue, CString FileName, const CServerPath &path = CServerPath());
  267. CFileZillaApi();
  268. virtual ~CFileZillaApi();
  269. //Initialization
  270. #ifndef MPEXT
  271. int Init(HWND hOwnerWnd, int nReplyMessageID = 0);
  272. #else
  273. int Init(CApiLog * pParent);
  274. #endif
  275. unsigned int GetMessageID();
  276. //Status
  277. int IsConnected();
  278. int IsBusy();
  279. //Operations
  280. int Connect(const t_server& server);
  281. int List(int nListMode=FZ_LIST_USECACHE); //Lists current folder
  282. int List(const CServerPath& path, int nListMode=FZ_LIST_USECACHE);
  283. int List(const CServerPath& parent, CString dirname, int nListMode=FZ_LIST_USECACHE);
  284. int FileTransfer(const t_transferfile &TransferFile);
  285. int GetCurrentServer(t_server &server);
  286. #ifdef MPEXT
  287. int SetCurrentPath(CServerPath path);
  288. int GetCurrentPath(CServerPath & path);
  289. #endif
  290. #ifndef MPEXT_NO_CACHE
  291. //Debugging functions
  292. static BOOL DumpDirectoryCache(LPCTSTR pFileName);
  293. #endif
  294. protected:
  295. CMainThread* m_pMainThread;
  296. unsigned int m_nInternalMessageID;
  297. BOOL m_bInitialized;
  298. unsigned int m_nReplyMessageID;
  299. HWND m_hOwnerWnd;
  300. };
  301. #endif // !defined(AFX_FILEZILLAAPI_H__F1970156_455F_4495_A813_4B676F0F03E5__INCLUDED_)