FileZillaIntf.h 9.0 KB

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