SessionInfo.h 12 KB

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