1
0

SessionInfo.h 13 KB

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