1
0

SessionInfo.h 13 KB

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