SessionInfo.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 { laUpload, laDownload, laTouch, laChmod, laMkdir, laRm, laMv, laCall, laLs, laStat };
  73. //---------------------------------------------------------------------------
  74. enum TCaptureOutputType { cotOutput, cotError, cotExitCode };
  75. typedef void __fastcall (__closure *TCaptureOutputEvent)(
  76. const UnicodeString & Str, TCaptureOutputType OutputType);
  77. typedef void __fastcall (__closure *TCalculatedChecksumEvent)(
  78. const UnicodeString & FileName, const UnicodeString & Alg, const UnicodeString & Hash);
  79. //---------------------------------------------------------------------------
  80. class TSessionActionRecord;
  81. class TActionLog;
  82. //---------------------------------------------------------------------------
  83. class TSessionAction
  84. {
  85. public:
  86. __fastcall TSessionAction(TActionLog * Log, TLogAction Action);
  87. __fastcall ~TSessionAction();
  88. void __fastcall Restart();
  89. void __fastcall Commit();
  90. void __fastcall Rollback(Exception * E = NULL);
  91. void __fastcall Cancel();
  92. protected:
  93. TSessionActionRecord * FRecord;
  94. };
  95. //---------------------------------------------------------------------------
  96. class TFileSessionAction : public TSessionAction
  97. {
  98. public:
  99. __fastcall TFileSessionAction(TActionLog * Log, TLogAction Action);
  100. __fastcall TFileSessionAction(TActionLog * Log, TLogAction Action, const UnicodeString & FileName);
  101. void __fastcall FileName(const UnicodeString & FileName);
  102. };
  103. //---------------------------------------------------------------------------
  104. class TFileLocationSessionAction : public TFileSessionAction
  105. {
  106. public:
  107. __fastcall TFileLocationSessionAction(TActionLog * Log, TLogAction Action);
  108. __fastcall TFileLocationSessionAction(TActionLog * Log, TLogAction Action, const UnicodeString & FileName);
  109. void __fastcall Destination(const UnicodeString & Destination);
  110. };
  111. //---------------------------------------------------------------------------
  112. class TUploadSessionAction : public TFileLocationSessionAction
  113. {
  114. public:
  115. __fastcall TUploadSessionAction(TActionLog * Log);
  116. };
  117. //---------------------------------------------------------------------------
  118. class TDownloadSessionAction : public TFileLocationSessionAction
  119. {
  120. public:
  121. __fastcall TDownloadSessionAction(TActionLog * Log);
  122. };
  123. //---------------------------------------------------------------------------
  124. class TRights;
  125. //---------------------------------------------------------------------------
  126. class TChmodSessionAction : public TFileSessionAction
  127. {
  128. public:
  129. __fastcall TChmodSessionAction(TActionLog * Log, const UnicodeString & FileName);
  130. __fastcall TChmodSessionAction(TActionLog * Log, const UnicodeString & FileName,
  131. const TRights & Rights);
  132. void __fastcall Rights(const TRights & Rights);
  133. void __fastcall Recursive();
  134. };
  135. //---------------------------------------------------------------------------
  136. class TTouchSessionAction : public TFileSessionAction
  137. {
  138. public:
  139. __fastcall TTouchSessionAction(TActionLog * Log, const UnicodeString & FileName,
  140. const TDateTime & Modification);
  141. };
  142. //---------------------------------------------------------------------------
  143. class TMkdirSessionAction : public TFileSessionAction
  144. {
  145. public:
  146. __fastcall TMkdirSessionAction(TActionLog * Log, const UnicodeString & FileName);
  147. };
  148. //---------------------------------------------------------------------------
  149. class TRmSessionAction : public TFileSessionAction
  150. {
  151. public:
  152. __fastcall TRmSessionAction(TActionLog * Log, const UnicodeString & FileName);
  153. void __fastcall Recursive();
  154. };
  155. //---------------------------------------------------------------------------
  156. class TMvSessionAction : public TFileLocationSessionAction
  157. {
  158. public:
  159. __fastcall TMvSessionAction(TActionLog * Log, const UnicodeString & FileName,
  160. const UnicodeString & Destination);
  161. };
  162. //---------------------------------------------------------------------------
  163. class TCallSessionAction : public TSessionAction
  164. {
  165. public:
  166. __fastcall TCallSessionAction(TActionLog * Log, const UnicodeString & Command,
  167. const UnicodeString & Destination);
  168. void __fastcall AddOutput(const UnicodeString & Output, bool StdError);
  169. void __fastcall AddExitCode(int ExitCode);
  170. };
  171. //---------------------------------------------------------------------------
  172. class TLsSessionAction : public TSessionAction
  173. {
  174. public:
  175. __fastcall TLsSessionAction(TActionLog * Log, const UnicodeString & Destination);
  176. void __fastcall FileList(TRemoteFileList * FileList);
  177. };
  178. //---------------------------------------------------------------------------
  179. class TStatSessionAction : public TFileSessionAction
  180. {
  181. public:
  182. __fastcall TStatSessionAction(TActionLog * Log, const UnicodeString & FileName);
  183. void __fastcall File(TRemoteFile * File);
  184. };
  185. //---------------------------------------------------------------------------
  186. class TSessionLog : protected TStringList
  187. {
  188. public:
  189. __fastcall TSessionLog(TSessionUI* UI, TSessionData * SessionData,
  190. TConfiguration * Configuration);
  191. __fastcall ~TSessionLog();
  192. HIDESBASE void __fastcall Add(TLogLineType Type, const UnicodeString & Line);
  193. void __fastcall AddSystemInfo();
  194. void __fastcall AddStartupInfo();
  195. void __fastcall AddException(Exception * E);
  196. void __fastcall AddSeparator();
  197. virtual void __fastcall Clear();
  198. void __fastcall ReflectSettings();
  199. void __fastcall Lock();
  200. void __fastcall Unlock();
  201. __property TSessionLog * Parent = { read = FParent, write = FParent };
  202. __property bool Logging = { read = FLogging };
  203. __property int BottomIndex = { read = GetBottomIndex };
  204. __property UnicodeString Line[int Index] = { read=GetLine };
  205. __property TLogLineType Type[int Index] = { read=GetType };
  206. __property OnChange;
  207. __property TNotifyEvent OnStateChange = { read = FOnStateChange, write = FOnStateChange };
  208. __property UnicodeString CurrentFileName = { read = FCurrentFileName };
  209. __property bool LoggingToFile = { read = GetLoggingToFile };
  210. __property int TopIndex = { read = FTopIndex };
  211. __property UnicodeString SessionName = { read = GetSessionName };
  212. __property UnicodeString Name = { read = FName, write = FName };
  213. __property Count;
  214. protected:
  215. void __fastcall CloseLogFile();
  216. bool __fastcall LogToFile();
  217. private:
  218. TConfiguration * FConfiguration;
  219. TSessionLog * FParent;
  220. TCriticalSection * FCriticalSection;
  221. bool FLogging;
  222. void * FFile;
  223. UnicodeString FCurrentLogFileName;
  224. UnicodeString FCurrentFileName;
  225. int FLoggedLines;
  226. int FTopIndex;
  227. TSessionUI * FUI;
  228. TSessionData * FSessionData;
  229. UnicodeString FName;
  230. bool FClosed;
  231. TNotifyEvent FOnStateChange;
  232. UnicodeString __fastcall GetLine(int Index);
  233. TLogLineType __fastcall GetType(int Index);
  234. void __fastcall DeleteUnnecessary();
  235. void __fastcall StateChange();
  236. void __fastcall OpenLogFile();
  237. int __fastcall GetBottomIndex();
  238. UnicodeString __fastcall GetLogFileName();
  239. bool __fastcall GetLoggingToFile();
  240. UnicodeString __fastcall GetSessionName();
  241. void __fastcall DoAdd(TLogLineType Type, UnicodeString Line,
  242. void __fastcall (__closure *f)(TLogLineType Type, const UnicodeString & Line));
  243. void __fastcall DoAddToParent(TLogLineType aType, const UnicodeString & aLine);
  244. void __fastcall DoAddToSelf(TLogLineType aType, const UnicodeString & aLine);
  245. void __fastcall AddStartupInfo(bool System);
  246. void __fastcall DoAddStartupInfo(TSessionData * Data);
  247. UnicodeString __fastcall GetTlsVersionName(TTlsVersion TlsVersion);
  248. UnicodeString __fastcall LogSensitive(const UnicodeString & Str);
  249. };
  250. //---------------------------------------------------------------------------
  251. class TActionLog
  252. {
  253. friend class TSessionAction;
  254. friend class TSessionActionRecord;
  255. public:
  256. __fastcall TActionLog(TSessionUI* UI, TSessionData * SessionData,
  257. TConfiguration * Configuration);
  258. __fastcall TActionLog(TConfiguration * Configuration);
  259. __fastcall ~TActionLog();
  260. void __fastcall ReflectSettings();
  261. void __fastcall AddFailure(Exception * E);
  262. void __fastcall AddFailure(TStrings * Messages);
  263. void __fastcall BeginGroup(UnicodeString Name);
  264. void __fastcall EndGroup();
  265. __property UnicodeString CurrentFileName = { read = FCurrentFileName };
  266. __property bool Enabled = { read = FEnabled, write = SetEnabled };
  267. protected:
  268. void __fastcall CloseLogFile();
  269. inline void __fastcall AddPendingAction(TSessionActionRecord * Action);
  270. void __fastcall RecordPendingActions();
  271. void __fastcall Add(const UnicodeString & Line);
  272. void __fastcall AddIndented(const UnicodeString & Line);
  273. void __fastcall AddMessages(UnicodeString Indent, TStrings * Messages);
  274. void __fastcall Init(TSessionUI * UI, TSessionData * SessionData,
  275. TConfiguration * Configuration);
  276. private:
  277. TConfiguration * FConfiguration;
  278. TCriticalSection * FCriticalSection;
  279. bool FLogging;
  280. void * FFile;
  281. UnicodeString FCurrentLogFileName;
  282. UnicodeString FCurrentFileName;
  283. TSessionUI * FUI;
  284. TSessionData * FSessionData;
  285. TList * FPendingActions;
  286. bool FClosed;
  287. bool FInGroup;
  288. UnicodeString FIndent;
  289. bool FEnabled;
  290. void __fastcall OpenLogFile();
  291. UnicodeString __fastcall GetLogFileName();
  292. void __fastcall SetEnabled(bool value);
  293. };
  294. //---------------------------------------------------------------------------
  295. #endif