FileZillaIntf.h 9.0 KB

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