FileZillaApi.h 10 KB

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