SessionInfo.h 13 KB

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