FileZillaIntf.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //---------------------------------------------------------------------------
  2. #ifndef FileZillaIntfH
  3. #define FileZillaIntfH
  4. //---------------------------------------------------------------------------
  5. #include <map>
  6. #include <time.h>
  7. #include <FileZillaOpt.h>
  8. #include <FileZillaTools.h>
  9. //---------------------------------------------------------------------------
  10. class CFileZillaApi;
  11. class TFileZillaIntern;
  12. //---------------------------------------------------------------------------
  13. struct TRemoteFileTime
  14. {
  15. int Year;
  16. int Month;
  17. int Day;
  18. int Hour;
  19. int Minute;
  20. int Second;
  21. bool HasTime;
  22. bool HasSeconds;
  23. bool HasDate;
  24. bool Utc;
  25. };
  26. //---------------------------------------------------------------------------
  27. struct TListDataEntry
  28. {
  29. const wchar_t * Name;
  30. const wchar_t * Permissions;
  31. const wchar_t * OwnerGroup;
  32. __int64 Size;
  33. bool Dir;
  34. bool Link;
  35. TRemoteFileTime Time;
  36. const wchar_t * LinkTarget;
  37. };
  38. //---------------------------------------------------------------------------
  39. struct TFtpsCertificateData
  40. {
  41. struct TContact
  42. {
  43. const wchar_t * Organization;
  44. const wchar_t * Unit;
  45. const wchar_t * CommonName;
  46. const wchar_t * Mail;
  47. const wchar_t * Country;
  48. const wchar_t * StateProvince;
  49. const wchar_t * Town;
  50. const wchar_t * Other;
  51. };
  52. TContact Subject;
  53. TContact Issuer;
  54. struct TValidityTime
  55. {
  56. int Year;
  57. int Month;
  58. int Day;
  59. int Hour;
  60. int Min;
  61. int Sec;
  62. };
  63. TValidityTime ValidFrom;
  64. TValidityTime ValidUntil;
  65. const unsigned char * Hash;
  66. static const size_t HashLen = 20;
  67. int VerificationResult;
  68. int VerificationDepth;
  69. };
  70. //---------------------------------------------------------------------------
  71. struct TNeedPassRequestData
  72. {
  73. wchar_t * Password;
  74. };
  75. //---------------------------------------------------------------------------
  76. class t_server;
  77. class TFTPServerCapabilities;
  78. //---------------------------------------------------------------------------
  79. class TFileZillaIntf : public CFileZillaTools
  80. {
  81. friend class TFileZillaIntern;
  82. public:
  83. enum TLogLevel
  84. {
  85. LOG_STATUS = 0,
  86. LOG_ERROR = 1,
  87. LOG_COMMAND = 2,
  88. LOG_REPLY = 3,
  89. LOG_LIST = 4,
  90. LOG_APIERROR = 5,
  91. LOG_WARNING = 6,
  92. LOG_INFO = 7,
  93. LOG_DEBUG = 8
  94. };
  95. enum TMessageType
  96. {
  97. MSG_OTHER = 0,
  98. MSG_TRANSFERSTATUS = 1
  99. };
  100. enum
  101. {
  102. FILEEXISTS_OVERWRITE = 0,
  103. // 1 is FILEEXISTS_OVERWRITEIFNEWER what we do not use
  104. FILEEXISTS_RESUME = 2,
  105. FILEEXISTS_RENAME = 3,
  106. FILEEXISTS_SKIP = 4,
  107. // 5 is FILEEXISTS_RESUME_ASKONFAIL what we do not use
  108. FILEEXISTS_COMPLETE = 6,
  109. };
  110. enum
  111. {
  112. REPLY_OK = 0x0001,
  113. REPLY_WOULDBLOCK = 0x0002,
  114. REPLY_ERROR = 0x0004,
  115. REPLY_OWNERNOTSET = 0x0008,
  116. REPLY_INVALIDPARAM = 0x0010,
  117. REPLY_NOTCONNECTED = 0x0020,
  118. REPLY_ALREADYCONNECTED = 0x0040,
  119. REPLY_BUSY = 0x0080,
  120. REPLY_IDLE = 0x0100,
  121. REPLY_NOTINITIALIZED = 0x0200,
  122. REPLY_ALREADYINIZIALIZED = 0x0400,
  123. REPLY_CANCEL = 0x0800,
  124. REPLY_DISCONNECTED = 0x1000, // Always sent when disconnected from server
  125. REPLY_CRITICALERROR = 0x2000, // Used for FileTransfers only
  126. REPLY_ABORTED = 0x4000, // Used for FileTransfers only
  127. REPLY_NOTSUPPORTED = 0x8000 // Command is not supported for the current server
  128. };
  129. enum
  130. {
  131. SERVER_FTP = 0x1000,
  132. SERVER_FTP_SSL_IMPLICIT = 0x1100,
  133. SERVER_FTP_SSL_EXPLICIT = 0x1200,
  134. SERVER_FTP_TLS_EXPLICIT = 0x1400
  135. };
  136. static void __fastcall Initialize();
  137. static void __fastcall Finalize();
  138. static void __fastcall SetResourceModule(void * ResourceHandle);
  139. __fastcall TFileZillaIntf();
  140. virtual __fastcall ~TFileZillaIntf();
  141. bool __fastcall Init();
  142. void __fastcall Destroying();
  143. bool __fastcall SetCurrentPath(const wchar_t * Path);
  144. bool __fastcall GetCurrentPath(wchar_t * Path, size_t MaxLen);
  145. bool __fastcall UsingMlsd();
  146. bool __fastcall UsingUtf8();
  147. std::string __fastcall GetTlsVersionStr();
  148. std::string __fastcall GetCipherName();
  149. bool __fastcall Cancel();
  150. bool __fastcall Connect(const wchar_t * Host, int Port, const wchar_t * User,
  151. const wchar_t * Pass, const wchar_t * Account, bool FwByPass,
  152. const wchar_t * Path, int ServerType, int Pasv, int TimeZoneOffset, int UTF8,
  153. int iForcePasvIp, int iUseMlsd);
  154. bool __fastcall Close(bool AllowBusy);
  155. bool __fastcall List();
  156. bool __fastcall List(const wchar_t * Path);
  157. #ifdef MPEXT
  158. bool __fastcall ListFile(const wchar_t * FullFileName);
  159. #endif
  160. bool __fastcall CustomCommand(const wchar_t * Command);
  161. bool __fastcall MakeDir(const wchar_t* Path);
  162. bool __fastcall Chmod(int Value, const wchar_t* FileName, const wchar_t* Path);
  163. bool __fastcall Delete(const wchar_t* FileName, const wchar_t* Path);
  164. bool __fastcall RemoveDir(const wchar_t* FileName, const wchar_t* Path);
  165. bool __fastcall Rename(const wchar_t* OldName, const wchar_t* NewName,
  166. const wchar_t* Path, const wchar_t* NewPath);
  167. bool __fastcall FileTransfer(const wchar_t * LocalFile, const wchar_t * RemoteFile,
  168. const wchar_t * RemotePath, bool Get, __int64 Size, int Type, void * UserData);
  169. virtual const wchar_t * __fastcall Option(int OptionID) const = 0;
  170. virtual int __fastcall OptionVal(int OptionID) const = 0;
  171. void __fastcall SetDebugLevel(TLogLevel Level);
  172. bool __fastcall HandleMessage(WPARAM wParam, LPARAM lParam);
  173. protected:
  174. bool __fastcall PostMessage(WPARAM wParam, LPARAM lParam);
  175. virtual bool __fastcall DoPostMessage(TMessageType Type, WPARAM wParam, LPARAM lParam) = 0;
  176. virtual bool __fastcall HandleStatus(const wchar_t * Status, int Type) = 0;
  177. virtual bool __fastcall HandleAsynchRequestOverwrite(
  178. wchar_t * FileName1, size_t FileName1Len, const wchar_t * FileName2,
  179. const wchar_t * Path1, const wchar_t * Path2,
  180. __int64 Size1, __int64 Size2, time_t LocalTime,
  181. bool HasLocalTime1, const TRemoteFileTime & RemoteTime, void * UserData, int & RequestResult) = 0;
  182. virtual bool __fastcall HandleAsynchRequestVerifyCertificate(
  183. const TFtpsCertificateData & Data, int & RequestResult) = 0;
  184. virtual bool __fastcall HandleAsynchRequestNeedPass(
  185. struct TNeedPassRequestData & Data, int & RequestResult) = 0;
  186. virtual bool __fastcall HandleListData(const wchar_t * Path, const TListDataEntry * Entries,
  187. unsigned int Count) = 0;
  188. virtual bool __fastcall HandleTransferStatus(bool Valid, __int64 TransferSize,
  189. __int64 Bytes, int Percent, int TimeElapsed, int TimeLeft, int TransferRate,
  190. bool FileTransfer) = 0;
  191. virtual bool __fastcall HandleReply(int Command, unsigned int Reply) = 0;
  192. virtual bool __fastcall HandleCapabilities(TFTPServerCapabilities * ServerCapabilities) = 0;
  193. virtual bool __fastcall CheckError(int ReturnCode, const wchar_t * Context);
  194. inline bool __fastcall Check(int ReturnCode, const wchar_t * Context, int Expected = -1);
  195. private:
  196. CFileZillaApi * FFileZillaApi;
  197. TFileZillaIntern * FIntern;
  198. t_server * FServer;
  199. };
  200. //---------------------------------------------------------------------------
  201. #ifdef MPEXT
  202. //---------------------------------------------------------------------------
  203. enum ftp_capabilities_t
  204. {
  205. unknown,
  206. yes,
  207. no
  208. };
  209. //---------------------------------------------------------------------------
  210. enum ftp_capability_names_t
  211. {
  212. syst_command = 1, // reply of SYST command as option
  213. feat_command,
  214. clnt_command, // set to 'yes' if CLNT should be sent
  215. utf8_command, // set to 'yes' if OPTS UTF8 ON should be sent
  216. mlsd_command,
  217. opts_mlst_command, // Arguments for OPTS MLST command
  218. mfmt_command,
  219. pret_command,
  220. mdtm_command,
  221. size_command,
  222. mode_z_support,
  223. tvfs_support, // Trivial virtual file store (RFC 3659)
  224. list_hidden_support, // LIST -a command
  225. rest_stream, // supports REST+STOR in addition to APPE
  226. };
  227. //---------------------------------------------------------------------------
  228. class TFTPServerCapabilities
  229. {
  230. public:
  231. ftp_capabilities_t GetCapability(ftp_capability_names_t Name);
  232. ftp_capabilities_t GetCapabilityString(ftp_capability_names_t Name, std::string * Option = NULL);
  233. void SetCapability(ftp_capability_names_t Name, ftp_capabilities_t Cap);
  234. void SetCapability(ftp_capability_names_t Name, ftp_capabilities_t Cap, const std::string & Option);
  235. void Clear() { FCapabilityMap.clear(); }
  236. void Assign(TFTPServerCapabilities * Source)
  237. {
  238. FCapabilityMap.clear();
  239. if (Source != NULL)
  240. {
  241. FCapabilityMap = Source->FCapabilityMap;
  242. }
  243. }
  244. protected:
  245. struct t_cap
  246. {
  247. t_cap() :
  248. cap(unknown),
  249. option(),
  250. number(0)
  251. {}
  252. ftp_capabilities_t cap;
  253. std::string option;
  254. int number;
  255. };
  256. std::map<ftp_capability_names_t, t_cap> FCapabilityMap;
  257. };
  258. #endif
  259. //---------------------------------------------------------------------------
  260. #endif // FileZillaIntfH