FileZillaIntf.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 HasYear;
  23. bool HasSeconds;
  24. bool HasDate;
  25. bool Utc;
  26. };
  27. //---------------------------------------------------------------------------
  28. struct TListDataEntry
  29. {
  30. const wchar_t * Name;
  31. const wchar_t * Permissions;
  32. const wchar_t * HumanPerm;
  33. const wchar_t * OwnerGroup; // deprecated, to be replaced with Owner/Group
  34. const wchar_t * Owner;
  35. const wchar_t * Group;
  36. __int64 Size;
  37. bool Dir;
  38. bool Link;
  39. TRemoteFileTime Time;
  40. const wchar_t * LinkTarget;
  41. };
  42. //---------------------------------------------------------------------------
  43. struct TFtpsCertificateData
  44. {
  45. struct TContact
  46. {
  47. const wchar_t * Organization;
  48. const wchar_t * Unit;
  49. const wchar_t * CommonName;
  50. const wchar_t * Mail;
  51. const wchar_t * Country;
  52. const wchar_t * StateProvince;
  53. const wchar_t * Town;
  54. const wchar_t * Other;
  55. };
  56. TContact Subject;
  57. TContact Issuer;
  58. struct TValidityTime
  59. {
  60. int Year;
  61. int Month;
  62. int Day;
  63. int Hour;
  64. int Min;
  65. int Sec;
  66. };
  67. TValidityTime ValidFrom;
  68. TValidityTime ValidUntil;
  69. const wchar_t * SubjectAltName;
  70. const unsigned char * HashSha1;
  71. static const size_t HashSha1Len = 20;
  72. const unsigned char * HashSha256;
  73. static const size_t HashSha256Len = 32;
  74. const unsigned char * Certificate;
  75. size_t CertificateLen;
  76. int VerificationResult;
  77. int VerificationDepth;
  78. };
  79. //---------------------------------------------------------------------------
  80. struct TNeedPassRequestData
  81. {
  82. wchar_t * Password;
  83. };
  84. //---------------------------------------------------------------------------
  85. class t_server;
  86. class TFTPServerCapabilities;
  87. typedef struct x509_st X509;
  88. typedef struct evp_pkey_st EVP_PKEY;
  89. //---------------------------------------------------------------------------
  90. class TFileZillaIntf : public CFileZillaTools
  91. {
  92. friend class TFileZillaIntern;
  93. public:
  94. enum TLogLevel
  95. {
  96. LOG_STATUS = 0,
  97. LOG_ERROR = 1,
  98. LOG_COMMAND = 2,
  99. LOG_REPLY = 3,
  100. LOG_APIERROR = 5,
  101. LOG_WARNING = 6,
  102. LOG_PROGRESS = 7,
  103. LOG_INFO = 8,
  104. LOG_DEBUG = 9
  105. };
  106. enum TMessageType
  107. {
  108. MSG_OTHER = 0,
  109. MSG_TRANSFERSTATUS = 1
  110. };
  111. enum
  112. {
  113. FILEEXISTS_OVERWRITE = 0,
  114. FILEEXISTS_RESUME = 1,
  115. FILEEXISTS_RENAME = 2,
  116. FILEEXISTS_SKIP = 3,
  117. FILEEXISTS_COMPLETE = 4,
  118. };
  119. enum
  120. {
  121. REPLY_OK = 0x0001,
  122. REPLY_WOULDBLOCK = 0x0002,
  123. REPLY_ERROR = 0x0004,
  124. REPLY_OWNERNOTSET = 0x0008,
  125. REPLY_INVALIDPARAM = 0x0010,
  126. REPLY_NOTCONNECTED = 0x0020,
  127. REPLY_ALREADYCONNECTED = 0x0040,
  128. REPLY_BUSY = 0x0080,
  129. REPLY_IDLE = 0x0100,
  130. REPLY_NOTINITIALIZED = 0x0200,
  131. REPLY_ALREADYINIZIALIZED = 0x0400,
  132. REPLY_CANCEL = 0x0800,
  133. REPLY_DISCONNECTED = 0x1000, // Always sent when disconnected from server
  134. REPLY_CRITICALERROR = 0x2000, // Used for FileTransfers only
  135. REPLY_ABORTED = 0x4000, // Used for FileTransfers only
  136. REPLY_NOTSUPPORTED = 0x8000 // Command is not supported for the current server
  137. };
  138. enum
  139. {
  140. SERVER_FTP = 0x1000,
  141. SERVER_FTP_SSL_IMPLICIT = 0x1100,
  142. SERVER_FTP_SSL_EXPLICIT = 0x1200,
  143. SERVER_FTP_TLS_EXPLICIT = 0x1400
  144. };
  145. static void __fastcall Initialize();
  146. static void __fastcall Finalize();
  147. static void __fastcall SetResourceModule(void * ResourceHandle);
  148. __fastcall TFileZillaIntf();
  149. virtual __fastcall ~TFileZillaIntf();
  150. bool __fastcall Init();
  151. void __fastcall Destroying();
  152. bool __fastcall SetCurrentPath(const wchar_t * Path);
  153. bool __fastcall GetCurrentPath(wchar_t * Path, size_t MaxLen);
  154. bool __fastcall UsingMlsd();
  155. bool __fastcall UsingUtf8();
  156. std::string __fastcall GetTlsVersionStr();
  157. std::string __fastcall GetCipherName();
  158. bool __fastcall Cancel();
  159. bool __fastcall Connect(const wchar_t * Host, int Port, const wchar_t * User,
  160. const wchar_t * Pass, const wchar_t * Account,
  161. const wchar_t * Path, int ServerType, int Pasv, int TimeZoneOffset, int UTF8,
  162. int iForcePasvIp, int iUseMlsd,
  163. X509 * Certificate, EVP_PKEY * PrivateKey);
  164. bool __fastcall Close(bool AllowBusy);
  165. bool __fastcall List(const wchar_t * Path);
  166. bool __fastcall ListFile(const wchar_t * FileName, const wchar_t * APath);
  167. bool __fastcall CustomCommand(const wchar_t * Command);
  168. bool __fastcall MakeDir(const wchar_t* Path);
  169. bool __fastcall Chmod(int Value, const wchar_t* FileName, const wchar_t* Path);
  170. bool __fastcall Delete(const wchar_t* FileName, const wchar_t* Path, bool FileNameOnly);
  171. bool __fastcall RemoveDir(const wchar_t* FileName, const wchar_t* Path);
  172. bool __fastcall Rename(const wchar_t* OldName, const wchar_t* NewName,
  173. const wchar_t* Path, const wchar_t* NewPath);
  174. bool __fastcall FileTransfer(
  175. const wchar_t * LocalFile, const wchar_t * RemoteFile,
  176. const wchar_t * RemotePath, bool Get, __int64 Size, int Type, void * UserData,
  177. TTransferOutEvent OnTransferOut, TTransferInEvent OnTransferIn);
  178. virtual const wchar_t * __fastcall Option(int OptionID) const = 0;
  179. virtual int __fastcall OptionVal(int OptionID) const = 0;
  180. void __fastcall SetDebugLevel(TLogLevel Level);
  181. bool __fastcall HandleMessage(WPARAM wParam, LPARAM lParam);
  182. protected:
  183. bool __fastcall PostMessage(WPARAM wParam, LPARAM lParam);
  184. virtual bool __fastcall DoPostMessage(TMessageType Type, WPARAM wParam, LPARAM lParam) = 0;
  185. virtual bool __fastcall HandleStatus(const wchar_t * Status, int Type) = 0;
  186. virtual bool __fastcall HandleAsynchRequestOverwrite(
  187. wchar_t * FileName1, size_t FileName1Len, const wchar_t * FileName2,
  188. const wchar_t * Path1, const wchar_t * Path2,
  189. __int64 Size1, __int64 Size2, time_t LocalTime,
  190. bool HasLocalTime1, const TRemoteFileTime & RemoteTime, void * UserData, int & RequestResult) = 0;
  191. virtual bool __fastcall HandleAsynchRequestVerifyCertificate(
  192. const TFtpsCertificateData & Data, int & RequestResult) = 0;
  193. virtual bool __fastcall HandleAsynchRequestNeedPass(
  194. struct TNeedPassRequestData & Data, int & RequestResult) = 0;
  195. virtual bool __fastcall HandleListData(const wchar_t * Path, const TListDataEntry * Entries,
  196. unsigned int Count) = 0;
  197. virtual bool __fastcall HandleTransferStatus(bool Valid, __int64 TransferSize,
  198. __int64 Bytes, bool FileTransfer) = 0;
  199. virtual bool __fastcall HandleReply(int Command, unsigned int Reply) = 0;
  200. virtual bool __fastcall HandleCapabilities(TFTPServerCapabilities * ServerCapabilities) = 0;
  201. virtual bool __fastcall CheckError(int ReturnCode, const wchar_t * Context);
  202. inline bool __fastcall Check(int ReturnCode, const wchar_t * Context, int Expected = -1);
  203. private:
  204. CFileZillaApi * FFileZillaApi;
  205. TFileZillaIntern * FIntern;
  206. t_server * FServer;
  207. };
  208. //---------------------------------------------------------------------------
  209. enum ftp_capabilities_t
  210. {
  211. unknown,
  212. yes,
  213. no
  214. };
  215. //---------------------------------------------------------------------------
  216. enum ftp_capability_names_t
  217. {
  218. syst_command = 1, // reply of SYST command as option
  219. feat_command,
  220. clnt_command, // set to 'yes' if CLNT should be sent
  221. utf8_command, // set to 'yes' if OPTS UTF8 ON should be sent
  222. mlsd_command,
  223. opts_mlst_command, // Arguments for OPTS MLST command
  224. mfmt_command,
  225. pret_command,
  226. mdtm_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. //---------------------------------------------------------------------------
  264. #endif // FileZillaIntfH