SessionInfo.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. AnsiString ProtocolBaseName;
  14. AnsiString ProtocolName;
  15. AnsiString SecurityProtocolName;
  16. AnsiString CSCipher;
  17. AnsiString CSCompression;
  18. AnsiString SCCipher;
  19. AnsiString SCCompression;
  20. AnsiString SshVersionString;
  21. AnsiString SshImplementation;
  22. AnsiString HostKeyFingerprint;
  23. };
  24. //---------------------------------------------------------------------------
  25. enum TFSCapability { fcUserGroupListing, fcModeChanging, fcGroupChanging,
  26. fcOwnerChanging, fcGroupOwnerChangingByID, fcAnyCommand, fcHardLink,
  27. fcSymbolicLink, fcResolveSymlink,
  28. fcTextMode, fcRename, fcNativeTextMode, fcNewerOnlyUpload, fcRemoteCopy,
  29. fcTimestampChanging, fcRemoteMove, fcLoadingAdditionalProperties,
  30. fcCheckingSpaceAvailable, fcIgnorePermErrors, fcCalculatingChecksum,
  31. fcModeChangingUpload, fcPreservingTimestampUpload, fcShellAnyCommand,
  32. fcSecondaryShell, fcCount };
  33. //---------------------------------------------------------------------------
  34. struct TFileSystemInfo
  35. {
  36. TFileSystemInfo();
  37. AnsiString ProtocolBaseName;
  38. AnsiString ProtocolName;
  39. AnsiString RemoteSystem;
  40. AnsiString AdditionalInfo;
  41. bool IsCapable[fcCount];
  42. };
  43. //---------------------------------------------------------------------------
  44. class TSessionUI
  45. {
  46. public:
  47. virtual void __fastcall Information(const AnsiString & Str, bool Status) = 0;
  48. virtual int __fastcall QueryUser(const AnsiString Query,
  49. TStrings * MoreMessages, int Answers, const TQueryParams * Params,
  50. TQueryType QueryType = qtConfirmation) = 0;
  51. virtual int __fastcall QueryUserException(const AnsiString Query,
  52. Exception * E, int Answers, const TQueryParams * Params,
  53. TQueryType QueryType = qtConfirmation) = 0;
  54. virtual bool __fastcall PromptUser(TSessionData * Data, TPromptKind Kind,
  55. AnsiString Name, AnsiString Instructions, TStrings * Prompts,
  56. TStrings * Results) = 0;
  57. virtual void __fastcall DisplayBanner(const AnsiString & Banner) = 0;
  58. virtual void __fastcall FatalError(Exception * E, AnsiString Msg) = 0;
  59. virtual void __fastcall HandleExtendedException(Exception * E) = 0;
  60. virtual void __fastcall Closed() = 0;
  61. };
  62. //---------------------------------------------------------------------------
  63. // Duplicated in LogMemo.h for design-time-only purposes
  64. enum TLogLineType { llOutput, llInput, llStdError, llMessage, llException, llAction };
  65. enum TLogAction { laUpload, laDownload, laTouch, laChmod, laMkdir, laRm, laMv, laCall, laLs };
  66. //---------------------------------------------------------------------------
  67. typedef void __fastcall (__closure *TCaptureOutputEvent)(
  68. const AnsiString & Str, bool StdError);
  69. typedef void __fastcall (__closure *TCalculatedChecksumEvent)(
  70. const AnsiString & FileName, const AnsiString & Alg, const AnsiString & Hash);
  71. //---------------------------------------------------------------------------
  72. class TCriticalSection;
  73. class TSessionActionRecord;
  74. class TSessionLog;
  75. //---------------------------------------------------------------------------
  76. class TSessionAction
  77. {
  78. public:
  79. __fastcall TSessionAction(TSessionLog * Log, TLogAction Action);
  80. __fastcall ~TSessionAction();
  81. void __fastcall Restart();
  82. void __fastcall Commit();
  83. void __fastcall Rollback(Exception * E = NULL);
  84. void __fastcall Cancel();
  85. protected:
  86. TSessionActionRecord * FRecord;
  87. };
  88. //---------------------------------------------------------------------------
  89. class TFileSessionAction : public TSessionAction
  90. {
  91. public:
  92. __fastcall TFileSessionAction(TSessionLog * Log, TLogAction Action);
  93. __fastcall TFileSessionAction(TSessionLog * Log, TLogAction Action, const AnsiString & FileName);
  94. void __fastcall FileName(const AnsiString & FileName);
  95. };
  96. //---------------------------------------------------------------------------
  97. class TFileLocationSessionAction : public TFileSessionAction
  98. {
  99. public:
  100. __fastcall TFileLocationSessionAction(TSessionLog * Log, TLogAction Action);
  101. __fastcall TFileLocationSessionAction(TSessionLog * Log, TLogAction Action, const AnsiString & FileName);
  102. void __fastcall Destination(const AnsiString & Destination);
  103. };
  104. //---------------------------------------------------------------------------
  105. class TUploadSessionAction : public TFileLocationSessionAction
  106. {
  107. public:
  108. __fastcall TUploadSessionAction(TSessionLog * Log);
  109. };
  110. //---------------------------------------------------------------------------
  111. class TDownloadSessionAction : public TFileLocationSessionAction
  112. {
  113. public:
  114. __fastcall TDownloadSessionAction(TSessionLog * Log);
  115. };
  116. //---------------------------------------------------------------------------
  117. class TRights;
  118. //---------------------------------------------------------------------------
  119. class TChmodSessionAction : public TFileSessionAction
  120. {
  121. public:
  122. __fastcall TChmodSessionAction(TSessionLog * Log, const AnsiString & FileName);
  123. __fastcall TChmodSessionAction(TSessionLog * Log, const AnsiString & FileName,
  124. const TRights & Rights);
  125. void __fastcall Rights(const TRights & Rights);
  126. void __fastcall Recursive();
  127. };
  128. //---------------------------------------------------------------------------
  129. class TTouchSessionAction : public TFileSessionAction
  130. {
  131. public:
  132. __fastcall TTouchSessionAction(TSessionLog * Log, const AnsiString & FileName,
  133. const TDateTime & Modification);
  134. };
  135. //---------------------------------------------------------------------------
  136. class TMkdirSessionAction : public TFileSessionAction
  137. {
  138. public:
  139. __fastcall TMkdirSessionAction(TSessionLog * Log, const AnsiString & FileName);
  140. };
  141. //---------------------------------------------------------------------------
  142. class TRmSessionAction : public TFileSessionAction
  143. {
  144. public:
  145. __fastcall TRmSessionAction(TSessionLog * Log, const AnsiString & FileName);
  146. void __fastcall Recursive();
  147. };
  148. //---------------------------------------------------------------------------
  149. class TMvSessionAction : public TFileLocationSessionAction
  150. {
  151. public:
  152. __fastcall TMvSessionAction(TSessionLog * Log, const AnsiString & FileName,
  153. const AnsiString & Destination);
  154. };
  155. //---------------------------------------------------------------------------
  156. class TCallSessionAction : public TSessionAction
  157. {
  158. public:
  159. __fastcall TCallSessionAction(TSessionLog * Log, const AnsiString & Command,
  160. const AnsiString & Destination);
  161. void __fastcall AddOutput(const AnsiString & Output, bool StdError);
  162. };
  163. //---------------------------------------------------------------------------
  164. class TLsSessionAction : public TSessionAction
  165. {
  166. public:
  167. __fastcall TLsSessionAction(TSessionLog * Log, const AnsiString & Destination);
  168. void __fastcall FileList(TRemoteFileList * FileList);
  169. };
  170. //---------------------------------------------------------------------------
  171. class TSessionLog : protected TStringList
  172. {
  173. friend class TSessionAction;
  174. friend class TSessionActionRecord;
  175. public:
  176. __fastcall TSessionLog(TSessionUI* UI, TSessionData * SessionData,
  177. TConfiguration * Configuration);
  178. __fastcall ~TSessionLog();
  179. HIDESBASE void __fastcall Add(TLogLineType Type, const AnsiString & Line);
  180. void __fastcall AddStartupInfo();
  181. void __fastcall AddException(Exception * E);
  182. void __fastcall AddSeparator();
  183. virtual void __fastcall Clear();
  184. void __fastcall ReflectSettings();
  185. void __fastcall Lock();
  186. void __fastcall Unlock();
  187. __property TSessionLog * Parent = { read = FParent, write = FParent };
  188. __property bool Logging = { read = FLogging };
  189. __property int BottomIndex = { read = GetBottomIndex };
  190. __property AnsiString Line[int Index] = { read=GetLine };
  191. __property TLogLineType Type[int Index] = { read=GetType };
  192. __property OnChange;
  193. __property TNotifyEvent OnStateChange = { read = FOnStateChange, write = FOnStateChange };
  194. __property AnsiString CurrentFileName = { read = FCurrentFileName };
  195. __property bool LoggingToFile = { read = GetLoggingToFile };
  196. __property int TopIndex = { read = FTopIndex };
  197. __property AnsiString SessionName = { read = GetSessionName };
  198. __property AnsiString Name = { read = FName, write = FName };
  199. __property Count;
  200. protected:
  201. void __fastcall CloseLogFile();
  202. bool __fastcall LogToFile();
  203. inline void __fastcall AddPendingAction(TSessionActionRecord * Action);
  204. void __fastcall RecordPendingActions();
  205. private:
  206. TConfiguration * FConfiguration;
  207. TSessionLog * FParent;
  208. TCriticalSection * FCriticalSection;
  209. bool FLogging;
  210. void * FFile;
  211. AnsiString FCurrentLogFileName;
  212. AnsiString FCurrentFileName;
  213. int FLoggedLines;
  214. int FTopIndex;
  215. TSessionUI * FUI;
  216. TSessionData * FSessionData;
  217. AnsiString FName;
  218. bool FLoggingActions;
  219. bool FClosed;
  220. TList * FPendingActions;
  221. TNotifyEvent FOnStateChange;
  222. AnsiString __fastcall GetLine(int Index);
  223. TLogLineType __fastcall GetType(int Index);
  224. void DeleteUnnecessary();
  225. void StateChange();
  226. void OpenLogFile();
  227. int __fastcall GetBottomIndex();
  228. AnsiString __fastcall GetLogFileName();
  229. bool __fastcall GetLoggingToFile();
  230. AnsiString __fastcall GetSessionName();
  231. void __fastcall DoAdd(TLogLineType Type, AnsiString Line,
  232. void __fastcall (__closure *f)(TLogLineType Type, const AnsiString & Line));
  233. void __fastcall DoAddToParent(TLogLineType aType, const AnsiString & aLine);
  234. void __fastcall DoAddToSelf(TLogLineType aType, const AnsiString & aLine);
  235. void __fastcall DoAddStartupInfo(TSessionData * Data);
  236. };
  237. //---------------------------------------------------------------------------
  238. #endif