FileZillaIntf.h 8.9 KB

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