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