SessionInfo.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. //---------------------------------------------------------------------------
  2. #ifndef SessionInfoH
  3. #define SessionInfoH
  4. #include "SessionData.h"
  5. #include "Interface.h"
  6. //---------------------------------------------------------------------------
  7. enum TSessionStatus { ssClosed, ssOpening, ssOpened };
  8. //---------------------------------------------------------------------------
  9. struct TSessionInfo
  10. {
  11. TSessionInfo();
  12. TDateTime LoginTime;
  13. UnicodeString ProtocolBaseName;
  14. UnicodeString ProtocolName;
  15. UnicodeString SecurityProtocolName;
  16. UnicodeString CSCipher;
  17. UnicodeString CSCompression;
  18. UnicodeString SCCipher;
  19. UnicodeString SCCompression;
  20. UnicodeString SshVersionString;
  21. UnicodeString SshImplementation;
  22. UnicodeString HostKeyFingerprintSHA256;
  23. UnicodeString HostKeyFingerprintMD5;
  24. UnicodeString CertificateFingerprintSHA1;
  25. UnicodeString CertificateFingerprintSHA256;
  26. UnicodeString Certificate;
  27. bool CertificateVerifiedManually;
  28. };
  29. //---------------------------------------------------------------------------
  30. enum TFSCapability { fcUserGroupListing, fcModeChanging, fcAclChangingFiles, fcGroupChanging,
  31. fcOwnerChanging, fcGroupOwnerChangingByID, fcAnyCommand, fcHardLink,
  32. fcSymbolicLink,
  33. // With WebDAV this is always true, to avoid double-click on
  34. // file try to open the file as directory. It does no harm atm as
  35. // WebDAV never produce a symlink in listing.
  36. fcResolveSymlink,
  37. fcTextMode, fcRename, fcNativeTextMode, fcNewerOnlyUpload, fcRemoteCopy,
  38. fcTimestampChanging, fcRemoteMove, fcLoadingAdditionalProperties,
  39. fcCheckingSpaceAvailable, fcIgnorePermErrors, fcCalculatingChecksum,
  40. fcModeChangingUpload, fcPreservingTimestampUpload, fcShellAnyCommand,
  41. fcSecondaryShell, fcRemoveCtrlZUpload, fcRemoveBOMUpload, fcMoveToQueue,
  42. fcLocking, fcPreservingTimestampDirs, fcResumeSupport,
  43. fcChangePassword, fcSkipTransfer,
  44. fcParallelTransfers, fcParallelFileTransfers,
  45. fcBackgroundTransfers,
  46. fcTransferOut, fcTransferIn,
  47. fcMoveOverExistingFile,
  48. fcTags,
  49. fcCount };
  50. //---------------------------------------------------------------------------
  51. struct TFileSystemInfo
  52. {
  53. TFileSystemInfo();
  54. UnicodeString ProtocolBaseName;
  55. UnicodeString ProtocolName;
  56. UnicodeString RemoteSystem;
  57. UnicodeString AdditionalInfo;
  58. bool IsCapable[fcCount];
  59. };
  60. //---------------------------------------------------------------------------
  61. class TSessionUI
  62. {
  63. public:
  64. virtual __fastcall ~TSessionUI() {}
  65. virtual void __fastcall Information(const UnicodeString & Str) = 0;
  66. virtual unsigned int __fastcall QueryUser(const UnicodeString Query,
  67. TStrings * MoreMessages, unsigned int Answers, const TQueryParams * Params,
  68. TQueryType QueryType = qtConfirmation) = 0;
  69. virtual unsigned int __fastcall QueryUserException(const UnicodeString Query,
  70. Exception * E, unsigned int Answers, const TQueryParams * Params,
  71. TQueryType QueryType = qtConfirmation) = 0;
  72. virtual bool __fastcall PromptUser(TSessionData * Data, TPromptKind Kind,
  73. UnicodeString Name, UnicodeString Instructions, TStrings * Prompts,
  74. TStrings * Results) = 0;
  75. virtual void __fastcall DisplayBanner(const UnicodeString & Banner) = 0;
  76. virtual void __fastcall FatalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"") = 0;
  77. virtual void __fastcall HandleExtendedException(Exception * E) = 0;
  78. virtual void __fastcall Closed() = 0;
  79. virtual void __fastcall ProcessGUI() = 0;
  80. };
  81. //---------------------------------------------------------------------------
  82. enum TLogLineType { llOutput, llInput, llStdError, llMessage, llException };
  83. enum TLogAction
  84. {
  85. laUpload, laDownload, laTouch, laChmod, laMkdir, laRm, laMv, laCp, laCall, laLs,
  86. laStat, laChecksum, laCwd, laDifference
  87. };
  88. //---------------------------------------------------------------------------
  89. enum TCaptureOutputType { cotOutput, cotError, cotExitCode };
  90. typedef void __fastcall (__closure *TCaptureOutputEvent)(
  91. const UnicodeString & Str, TCaptureOutputType OutputType);
  92. typedef void __fastcall (__closure *TCalculatedChecksumEvent)(
  93. const UnicodeString & FileName, const UnicodeString & Alg, const UnicodeString & Hash);
  94. //---------------------------------------------------------------------------
  95. class TSessionActionRecord;
  96. class TActionLog;
  97. //---------------------------------------------------------------------------
  98. class TSessionAction
  99. {
  100. public:
  101. __fastcall TSessionAction(TActionLog * Log, TLogAction Action);
  102. __fastcall ~TSessionAction();
  103. void __fastcall Restart();
  104. void __fastcall Rollback(Exception * E = NULL);
  105. void __fastcall Cancel();
  106. bool __fastcall IsValid();
  107. protected:
  108. TSessionActionRecord * FRecord;
  109. bool FCancelled;
  110. };
  111. //---------------------------------------------------------------------------
  112. class TFileSessionAction : public TSessionAction
  113. {
  114. public:
  115. __fastcall TFileSessionAction(TActionLog * Log, TLogAction Action);
  116. __fastcall TFileSessionAction(TActionLog * Log, TLogAction Action, const UnicodeString & FileName);
  117. void __fastcall FileName(const UnicodeString & FileName);
  118. };
  119. //---------------------------------------------------------------------------
  120. class TFileLocationSessionAction : public TFileSessionAction
  121. {
  122. public:
  123. __fastcall TFileLocationSessionAction(TActionLog * Log, TLogAction Action);
  124. __fastcall TFileLocationSessionAction(TActionLog * Log, TLogAction Action, const UnicodeString & FileName);
  125. void __fastcall Destination(const UnicodeString & Destination);
  126. };
  127. //---------------------------------------------------------------------------
  128. class TTransferSessionAction : public TFileLocationSessionAction
  129. {
  130. public:
  131. TTransferSessionAction(TActionLog * Log, TLogAction Action);
  132. void Size(__int64 Size);
  133. };
  134. //---------------------------------------------------------------------------
  135. class TUploadSessionAction : public TTransferSessionAction
  136. {
  137. public:
  138. __fastcall TUploadSessionAction(TActionLog * Log);
  139. };
  140. //---------------------------------------------------------------------------
  141. class TDownloadSessionAction : public TTransferSessionAction
  142. {
  143. public:
  144. __fastcall TDownloadSessionAction(TActionLog * Log);
  145. };
  146. //---------------------------------------------------------------------------
  147. class TRights;
  148. //---------------------------------------------------------------------------
  149. class TChmodSessionAction : public TFileSessionAction
  150. {
  151. public:
  152. __fastcall TChmodSessionAction(TActionLog * Log, const UnicodeString & FileName);
  153. __fastcall TChmodSessionAction(TActionLog * Log, const UnicodeString & FileName,
  154. const TRights & Rights);
  155. void __fastcall Rights(const TRights & Rights);
  156. void __fastcall Recursive();
  157. };
  158. //---------------------------------------------------------------------------
  159. class TTouchSessionAction : public TFileSessionAction
  160. {
  161. public:
  162. __fastcall TTouchSessionAction(TActionLog * Log, const UnicodeString & FileName,
  163. const TDateTime & Modification);
  164. };
  165. //---------------------------------------------------------------------------
  166. class TMkdirSessionAction : public TFileSessionAction
  167. {
  168. public:
  169. __fastcall TMkdirSessionAction(TActionLog * Log, const UnicodeString & FileName);
  170. };
  171. //---------------------------------------------------------------------------
  172. class TRmSessionAction : public TFileSessionAction
  173. {
  174. public:
  175. __fastcall TRmSessionAction(TActionLog * Log, const UnicodeString & FileName);
  176. void __fastcall Recursive();
  177. };
  178. //---------------------------------------------------------------------------
  179. class TMvSessionAction : public TFileLocationSessionAction
  180. {
  181. public:
  182. __fastcall TMvSessionAction(TActionLog * Log, const UnicodeString & FileName,
  183. const UnicodeString & Destination);
  184. };
  185. //---------------------------------------------------------------------------
  186. class TCpSessionAction : public TFileLocationSessionAction
  187. {
  188. public:
  189. __fastcall TCpSessionAction(TActionLog * Log, const UnicodeString & FileName,
  190. const UnicodeString & Destination);
  191. };
  192. //---------------------------------------------------------------------------
  193. class TCallSessionAction : public TSessionAction
  194. {
  195. public:
  196. __fastcall TCallSessionAction(TActionLog * Log, const UnicodeString & Command,
  197. const UnicodeString & Destination);
  198. void __fastcall AddOutput(const UnicodeString & Output, bool StdError);
  199. void __fastcall ExitCode(int ExitCode);
  200. };
  201. //---------------------------------------------------------------------------
  202. class TLsSessionAction : public TSessionAction
  203. {
  204. public:
  205. __fastcall TLsSessionAction(TActionLog * Log, const UnicodeString & Destination);
  206. void __fastcall FileList(TRemoteFileList * FileList);
  207. };
  208. //---------------------------------------------------------------------------
  209. class TStatSessionAction : public TFileSessionAction
  210. {
  211. public:
  212. __fastcall TStatSessionAction(TActionLog * Log, const UnicodeString & FileName);
  213. void __fastcall File(TRemoteFile * File);
  214. };
  215. //---------------------------------------------------------------------------
  216. class TChecksumSessionAction : public TFileSessionAction
  217. {
  218. public:
  219. __fastcall TChecksumSessionAction(TActionLog * Log);
  220. void __fastcall Checksum(const UnicodeString & Alg, const UnicodeString & Checksum);
  221. };
  222. //---------------------------------------------------------------------------
  223. class TCwdSessionAction : public TSessionAction
  224. {
  225. public:
  226. __fastcall TCwdSessionAction(TActionLog * Log, const UnicodeString & Path);
  227. };
  228. //---------------------------------------------------------------------------
  229. class TDifferenceSessionAction : public TSessionAction
  230. {
  231. public:
  232. __fastcall TDifferenceSessionAction(TActionLog * Log, const TSynchronizeChecklist::TItem * Item);
  233. };
  234. //---------------------------------------------------------------------------
  235. typedef void __fastcall (__closure *TAddLogEntryEvent)(const UnicodeString & S);
  236. //---------------------------------------------------------------------------
  237. class TSessionLog
  238. {
  239. friend class TApplicationLog;
  240. public:
  241. __fastcall TSessionLog(TSessionUI* UI, TDateTime Started, TSessionData * SessionData,
  242. TConfiguration * Configuration);
  243. __fastcall ~TSessionLog();
  244. void __fastcall SetParent(TSessionLog * Parent, const UnicodeString & Name);
  245. void __fastcall Add(TLogLineType Type, const UnicodeString & Line);
  246. void __fastcall AddSystemInfo();
  247. void __fastcall AddStartupInfo();
  248. void __fastcall AddException(Exception * E);
  249. static UnicodeString GetSeparator();
  250. void __fastcall AddSeparator();
  251. void __fastcall ReflectSettings();
  252. __property bool Logging = { read = FLogging };
  253. __property UnicodeString Name = { read = FName };
  254. protected:
  255. void __fastcall CloseLogFile();
  256. bool __fastcall LogToFile();
  257. static void __fastcall DoAddStartupInfo(TAddLogEntryEvent AddLogEntry, TConfiguration * AConfiguration, bool DoNotMaskPaswords);
  258. private:
  259. TConfiguration * FConfiguration;
  260. TSessionLog * FParent;
  261. TCriticalSection * FCriticalSection;
  262. bool FLogging;
  263. void * FFile;
  264. UnicodeString FCurrentLogFileName;
  265. UnicodeString FCurrentFileName;
  266. __int64 FCurrentFileSize;
  267. TSessionUI * FUI;
  268. TSessionData * FSessionData;
  269. TDateTime FStarted;
  270. UnicodeString FName;
  271. bool FClosed;
  272. void __fastcall OpenLogFile();
  273. UnicodeString __fastcall GetLogFileName();
  274. void __fastcall DoAdd(TLogLineType Type, UnicodeString Line,
  275. void __fastcall (__closure *f)(TLogLineType Type, const UnicodeString & Line));
  276. void __fastcall DoAddToParent(TLogLineType aType, const UnicodeString & aLine);
  277. void __fastcall DoAddToSelf(TLogLineType aType, const UnicodeString & aLine);
  278. void __fastcall AddStartupInfo(bool System);
  279. void __fastcall DoAddStartupInfo(TSessionData * Data);
  280. UnicodeString __fastcall LogSensitive(const UnicodeString & Str);
  281. static UnicodeString __fastcall GetCmdLineLog(TConfiguration * AConfiguration);
  282. void __fastcall CheckSize(__int64 Addition);
  283. UnicodeString __fastcall LogPartFileName(const UnicodeString & BaseName, int Index);
  284. void __fastcall DoAddStartupInfoEntry(const UnicodeString & S);
  285. };
  286. //---------------------------------------------------------------------------
  287. class TActionLog
  288. {
  289. friend class TSessionAction;
  290. friend class TSessionActionRecord;
  291. public:
  292. __fastcall TActionLog(TSessionUI* UI, TDateTime Started, TSessionData * SessionData,
  293. TConfiguration * Configuration);
  294. // For fatal failures for .NET assembly
  295. __fastcall TActionLog(TDateTime Started, TConfiguration * Configuration);
  296. __fastcall ~TActionLog();
  297. void __fastcall ReflectSettings();
  298. void __fastcall AddFailure(Exception * E);
  299. void __fastcall AddFailure(TStrings * Messages);
  300. void __fastcall BeginGroup(UnicodeString Name);
  301. void __fastcall EndGroup();
  302. __property UnicodeString CurrentFileName = { read = FCurrentFileName };
  303. __property bool Enabled = { read = FEnabled, write = SetEnabled };
  304. protected:
  305. void __fastcall CloseLogFile();
  306. inline void __fastcall AddPendingAction(TSessionActionRecord * Action);
  307. void __fastcall RecordPendingActions();
  308. void __fastcall Add(const UnicodeString & Line);
  309. void __fastcall AddIndented(const UnicodeString & Line);
  310. void __fastcall AddMessages(UnicodeString Indent, TStrings * Messages);
  311. void __fastcall Init(TSessionUI * UI, TDateTime Started, TSessionData * SessionData,
  312. TConfiguration * Configuration);
  313. private:
  314. TConfiguration * FConfiguration;
  315. TCriticalSection * FCriticalSection;
  316. bool FLogging;
  317. void * FFile;
  318. UnicodeString FCurrentLogFileName;
  319. UnicodeString FCurrentFileName;
  320. TSessionUI * FUI;
  321. TSessionData * FSessionData;
  322. TDateTime FStarted;
  323. TList * FPendingActions;
  324. bool FFailed;
  325. bool FClosed;
  326. bool FInGroup;
  327. UnicodeString FIndent;
  328. bool FEnabled;
  329. void __fastcall OpenLogFile();
  330. UnicodeString __fastcall GetLogFileName();
  331. void __fastcall SetEnabled(bool value);
  332. };
  333. //---------------------------------------------------------------------------
  334. class TApplicationLog
  335. {
  336. public:
  337. TApplicationLog();
  338. ~TApplicationLog();
  339. void Enable(const UnicodeString & Path);
  340. void AddStartupInfo();
  341. void __fastcall Log(const UnicodeString & S);
  342. __property bool Logging = { read = FLogging };
  343. __property UnicodeString Path = { read = FPath };
  344. private:
  345. UnicodeString FPath;
  346. void * FFile;
  347. bool FLogging;
  348. TDateTime FLastMemoryCheck;
  349. size_t FPeekReservedMemory;
  350. size_t FPeekCommittedMemory;
  351. std::unique_ptr<TCriticalSection> FCriticalSection;
  352. };
  353. //---------------------------------------------------------------------------
  354. UnicodeString __fastcall XmlEscape(UnicodeString Str);
  355. //---------------------------------------------------------------------------
  356. #endif