SessionInfo.h 13 KB

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