SessionInfo.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <stdio.h>
  5. #include <lmcons.h>
  6. #define SECURITY_WIN32
  7. #include <sspi.h>
  8. #include <secext.h>
  9. #include "Common.h"
  10. #include "SessionInfo.h"
  11. #include "Exceptions.h"
  12. #include "TextsCore.h"
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. //---------------------------------------------------------------------------
  16. UnicodeString __fastcall DoXmlEscape(UnicodeString Str, bool NewLine)
  17. {
  18. for (int i = 1; i <= Str.Length(); i++)
  19. {
  20. const wchar_t * Repl = NULL;
  21. switch (Str[i])
  22. {
  23. case L'&':
  24. Repl = L"amp;";
  25. break;
  26. case L'>':
  27. Repl = L"gt;";
  28. break;
  29. case L'<':
  30. Repl = L"lt;";
  31. break;
  32. case L'"':
  33. Repl = L"quot;";
  34. break;
  35. case L'\n':
  36. if (NewLine)
  37. {
  38. Repl = L"#10;";
  39. }
  40. break;
  41. case L'\r':
  42. Str.Delete(i, 1);
  43. i--;
  44. break;
  45. }
  46. if (Repl != NULL)
  47. {
  48. Str[i] = L'&';
  49. Str.Insert(Repl, i + 1);
  50. i += wcslen(Repl);
  51. }
  52. }
  53. return Str;
  54. }
  55. //---------------------------------------------------------------------------
  56. UnicodeString __fastcall XmlEscape(UnicodeString Str)
  57. {
  58. return DoXmlEscape(Str, false);
  59. }
  60. //---------------------------------------------------------------------------
  61. UnicodeString __fastcall XmlAttributeEscape(UnicodeString Str)
  62. {
  63. return DoXmlEscape(Str, true);
  64. }
  65. //---------------------------------------------------------------------------
  66. //---------------------------------------------------------------------------
  67. #pragma warn -inl
  68. class TSessionActionRecord
  69. {
  70. public:
  71. __fastcall TSessionActionRecord(TActionLog * Log, TLogAction Action) :
  72. FLog(Log),
  73. FAction(Action),
  74. FState(Opened),
  75. FRecursive(false),
  76. FErrorMessages(NULL),
  77. FNames(new TStringList()),
  78. FValues(new TStringList()),
  79. FFileList(NULL),
  80. FFile(NULL)
  81. {
  82. FLog->AddPendingAction(this);
  83. }
  84. __fastcall ~TSessionActionRecord()
  85. {
  86. delete FErrorMessages;
  87. delete FNames;
  88. delete FValues;
  89. delete FFileList;
  90. delete FFile;
  91. }
  92. void __fastcall Restart()
  93. {
  94. FState = Opened;
  95. FRecursive = false;
  96. delete FErrorMessages;
  97. FErrorMessages = NULL;
  98. delete FFileList;
  99. FFileList = NULL;
  100. delete FFile;
  101. FFile = NULL;
  102. FNames->Clear();
  103. FValues->Clear();
  104. }
  105. bool __fastcall Record()
  106. {
  107. bool Result = (FState != Opened);
  108. if (Result)
  109. {
  110. if (FLog->FLogging && (FState != Cancelled))
  111. {
  112. const wchar_t * Name = ActionName();
  113. UnicodeString Attrs;
  114. if (FRecursive)
  115. {
  116. Attrs = L" recursive=\"true\"";
  117. }
  118. FLog->AddIndented(FORMAT(L"<%s%s>", (Name, Attrs)));
  119. for (int Index = 0; Index < FNames->Count; Index++)
  120. {
  121. UnicodeString Value = FValues->Strings[Index];
  122. if (Value.IsEmpty())
  123. {
  124. FLog->AddIndented(FORMAT(L" <%s />", (FNames->Strings[Index])));
  125. }
  126. else
  127. {
  128. FLog->AddIndented(FORMAT(L" <%s value=\"%s\" />",
  129. (FNames->Strings[Index], XmlAttributeEscape(Value))));
  130. }
  131. }
  132. if (FFileList != NULL)
  133. {
  134. FLog->AddIndented(L" <files>");
  135. for (int Index = 0; Index < FFileList->Count; Index++)
  136. {
  137. TRemoteFile * File = FFileList->Files[Index];
  138. FLog->AddIndented(L" <file>");
  139. FLog->AddIndented(FORMAT(L" <filename value=\"%s\" />", (XmlAttributeEscape(File->FileName))));
  140. FLog->AddIndented(FORMAT(L" <type value=\"%s\" />", (XmlAttributeEscape(File->Type))));
  141. if (!File->IsDirectory)
  142. {
  143. FLog->AddIndented(FORMAT(L" <size value=\"%s\" />", (IntToStr(File->Size))));
  144. }
  145. FLog->AddIndented(FORMAT(L" <modification value=\"%s\" />", (StandardTimestamp(File->Modification))));
  146. FLog->AddIndented(FORMAT(L" <permissions value=\"%s\" />", (XmlAttributeEscape(File->Rights->Text))));
  147. FLog->AddIndented(L" </file>");
  148. }
  149. FLog->AddIndented(L" </files>");
  150. }
  151. if (FFile != NULL)
  152. {
  153. FLog->AddIndented(L" <file>");
  154. FLog->AddIndented(FORMAT(L" <type value=\"%s\" />", (XmlAttributeEscape(FFile->Type))));
  155. if (!FFile->IsDirectory)
  156. {
  157. FLog->AddIndented(FORMAT(L" <size value=\"%s\" />", (IntToStr(FFile->Size))));
  158. }
  159. FLog->AddIndented(FORMAT(L" <modification value=\"%s\" />", (StandardTimestamp(FFile->Modification))));
  160. FLog->AddIndented(FORMAT(L" <permissions value=\"%s\" />", (XmlAttributeEscape(FFile->Rights->Text))));
  161. FLog->AddIndented(L" </file>");
  162. }
  163. if (FState == RolledBack)
  164. {
  165. if (FErrorMessages != NULL)
  166. {
  167. FLog->AddIndented(L" <result success=\"false\">");
  168. FLog->AddMessages(L" ", FErrorMessages);
  169. FLog->AddIndented(L" </result>");
  170. }
  171. else
  172. {
  173. FLog->AddIndented(L" <result success=\"false\" />");
  174. }
  175. }
  176. else
  177. {
  178. FLog->AddIndented(L" <result success=\"true\" />");
  179. }
  180. FLog->AddIndented(FORMAT(L"</%s>", (Name)));
  181. }
  182. delete this;
  183. }
  184. return Result;
  185. }
  186. void __fastcall Commit()
  187. {
  188. Close(Committed);
  189. }
  190. void __fastcall Rollback(Exception * E)
  191. {
  192. assert(FErrorMessages == NULL);
  193. FErrorMessages = ExceptionToMoreMessages(E);
  194. Close(RolledBack);
  195. }
  196. void __fastcall Cancel()
  197. {
  198. Close(Cancelled);
  199. }
  200. void __fastcall FileName(const UnicodeString & FileName)
  201. {
  202. Parameter(L"filename", FileName);
  203. }
  204. void __fastcall Destination(const UnicodeString & Destination)
  205. {
  206. Parameter(L"destination", Destination);
  207. }
  208. void __fastcall Rights(const TRights & Rights)
  209. {
  210. Parameter(L"permissions", Rights.Text);
  211. }
  212. void __fastcall Modification(const TDateTime & DateTime)
  213. {
  214. Parameter(L"modification", StandardTimestamp(DateTime));
  215. }
  216. void __fastcall Recursive()
  217. {
  218. FRecursive = true;
  219. }
  220. void __fastcall Command(const UnicodeString & Command)
  221. {
  222. Parameter(L"command", Command);
  223. }
  224. void __fastcall AddOutput(UnicodeString Output, bool StdError)
  225. {
  226. const wchar_t * Name = (StdError ? L"erroroutput" : L"output");
  227. int Index = FNames->IndexOf(Name);
  228. if (Index >= 0)
  229. {
  230. FValues->Strings[Index] = FValues->Strings[Index] + L"\r\n" + Output;
  231. }
  232. else
  233. {
  234. Parameter(Name, Output);
  235. }
  236. }
  237. void __fastcall FileList(TRemoteFileList * FileList)
  238. {
  239. if (FFileList == NULL)
  240. {
  241. FFileList = new TRemoteFileList();
  242. }
  243. FileList->DuplicateTo(FFileList);
  244. }
  245. void __fastcall File(TRemoteFile * File)
  246. {
  247. if (FFile != NULL)
  248. {
  249. delete FFile;
  250. }
  251. FFile = File->Duplicate(true);
  252. }
  253. protected:
  254. enum TState { Opened, Committed, RolledBack, Cancelled };
  255. inline void __fastcall Close(TState State)
  256. {
  257. assert(FState == Opened);
  258. FState = State;
  259. FLog->RecordPendingActions();
  260. }
  261. const wchar_t * __fastcall ActionName()
  262. {
  263. switch (FAction)
  264. {
  265. case laUpload: return L"upload";
  266. case laDownload: return L"download";
  267. case laTouch: return L"touch";
  268. case laChmod: return L"chmod";
  269. case laMkdir: return L"mkdir";
  270. case laRm: return L"rm";
  271. case laMv: return L"mv";
  272. case laCall: return L"call";
  273. case laLs: return L"ls";
  274. case laStat: return L"stat";
  275. default: assert(false); return L"";
  276. }
  277. }
  278. void __fastcall Parameter(const UnicodeString & Name, const UnicodeString & Value = L"")
  279. {
  280. FNames->Add(Name);
  281. FValues->Add(Value);
  282. }
  283. private:
  284. TActionLog * FLog;
  285. TLogAction FAction;
  286. TState FState;
  287. bool FRecursive;
  288. TStrings * FErrorMessages;
  289. TStrings * FNames;
  290. TStrings * FValues;
  291. TRemoteFileList * FFileList;
  292. TRemoteFile * FFile;
  293. };
  294. #pragma warn .inl
  295. //---------------------------------------------------------------------------
  296. //---------------------------------------------------------------------------
  297. __fastcall TSessionAction::TSessionAction(TActionLog * Log, TLogAction Action)
  298. {
  299. if (Log->FLogging)
  300. {
  301. FRecord = new TSessionActionRecord(Log, Action);
  302. }
  303. else
  304. {
  305. FRecord = NULL;
  306. }
  307. }
  308. //---------------------------------------------------------------------------
  309. __fastcall TSessionAction::~TSessionAction()
  310. {
  311. if (FRecord != NULL)
  312. {
  313. Commit();
  314. }
  315. }
  316. //---------------------------------------------------------------------------
  317. void __fastcall TSessionAction::Restart()
  318. {
  319. if (FRecord != NULL)
  320. {
  321. FRecord->Restart();
  322. }
  323. }
  324. //---------------------------------------------------------------------------
  325. void __fastcall TSessionAction::Commit()
  326. {
  327. if (FRecord != NULL)
  328. {
  329. TSessionActionRecord * Record = FRecord;
  330. FRecord = NULL;
  331. Record->Commit();
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TSessionAction::Rollback(Exception * E)
  336. {
  337. if (FRecord != NULL)
  338. {
  339. TSessionActionRecord * Record = FRecord;
  340. FRecord = NULL;
  341. Record->Rollback(E);
  342. }
  343. }
  344. //---------------------------------------------------------------------------
  345. void __fastcall TSessionAction::Cancel()
  346. {
  347. if (FRecord != NULL)
  348. {
  349. TSessionActionRecord * Record = FRecord;
  350. FRecord = NULL;
  351. Record->Cancel();
  352. }
  353. }
  354. //---------------------------------------------------------------------------
  355. //---------------------------------------------------------------------------
  356. __fastcall TFileSessionAction::TFileSessionAction(TActionLog * Log, TLogAction Action) :
  357. TSessionAction(Log, Action)
  358. {
  359. }
  360. //---------------------------------------------------------------------------
  361. __fastcall TFileSessionAction::TFileSessionAction(
  362. TActionLog * Log, TLogAction Action, const UnicodeString & AFileName) :
  363. TSessionAction(Log, Action)
  364. {
  365. FileName(AFileName);
  366. }
  367. //---------------------------------------------------------------------------
  368. void __fastcall TFileSessionAction::FileName(const UnicodeString & FileName)
  369. {
  370. if (FRecord != NULL)
  371. {
  372. FRecord->FileName(FileName);
  373. }
  374. }
  375. //---------------------------------------------------------------------------
  376. //---------------------------------------------------------------------------
  377. __fastcall TFileLocationSessionAction::TFileLocationSessionAction(
  378. TActionLog * Log, TLogAction Action) :
  379. TFileSessionAction(Log, Action)
  380. {
  381. }
  382. //---------------------------------------------------------------------------
  383. __fastcall TFileLocationSessionAction::TFileLocationSessionAction(
  384. TActionLog * Log, TLogAction Action, const UnicodeString & FileName) :
  385. TFileSessionAction(Log, Action, FileName)
  386. {
  387. }
  388. //---------------------------------------------------------------------------
  389. void __fastcall TFileLocationSessionAction::Destination(const UnicodeString & Destination)
  390. {
  391. if (FRecord != NULL)
  392. {
  393. FRecord->Destination(Destination);
  394. }
  395. }
  396. //---------------------------------------------------------------------------
  397. //---------------------------------------------------------------------------
  398. __fastcall TUploadSessionAction::TUploadSessionAction(TActionLog * Log) :
  399. TFileLocationSessionAction(Log, laUpload)
  400. {
  401. }
  402. //---------------------------------------------------------------------------
  403. //---------------------------------------------------------------------------
  404. __fastcall TDownloadSessionAction::TDownloadSessionAction(TActionLog * Log) :
  405. TFileLocationSessionAction(Log, laDownload)
  406. {
  407. }
  408. //---------------------------------------------------------------------------
  409. //---------------------------------------------------------------------------
  410. __fastcall TChmodSessionAction::TChmodSessionAction(
  411. TActionLog * Log, const UnicodeString & FileName) :
  412. TFileSessionAction(Log, laChmod, FileName)
  413. {
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TChmodSessionAction::Recursive()
  417. {
  418. if (FRecord != NULL)
  419. {
  420. FRecord->Recursive();
  421. }
  422. }
  423. //---------------------------------------------------------------------------
  424. __fastcall TChmodSessionAction::TChmodSessionAction(
  425. TActionLog * Log, const UnicodeString & FileName, const TRights & ARights) :
  426. TFileSessionAction(Log, laChmod, FileName)
  427. {
  428. Rights(ARights);
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TChmodSessionAction::Rights(const TRights & Rights)
  432. {
  433. if (FRecord != NULL)
  434. {
  435. FRecord->Rights(Rights);
  436. }
  437. }
  438. //---------------------------------------------------------------------------
  439. __fastcall TTouchSessionAction::TTouchSessionAction(
  440. TActionLog * Log, const UnicodeString & FileName, const TDateTime & Modification) :
  441. TFileSessionAction(Log, laTouch, FileName)
  442. {
  443. if (FRecord != NULL)
  444. {
  445. FRecord->Modification(Modification);
  446. }
  447. }
  448. //---------------------------------------------------------------------------
  449. __fastcall TMkdirSessionAction::TMkdirSessionAction(
  450. TActionLog * Log, const UnicodeString & FileName) :
  451. TFileSessionAction(Log, laMkdir, FileName)
  452. {
  453. }
  454. //---------------------------------------------------------------------------
  455. __fastcall TRmSessionAction::TRmSessionAction(
  456. TActionLog * Log, const UnicodeString & FileName) :
  457. TFileSessionAction(Log, laRm, FileName)
  458. {
  459. }
  460. //---------------------------------------------------------------------------
  461. void __fastcall TRmSessionAction::Recursive()
  462. {
  463. if (FRecord != NULL)
  464. {
  465. FRecord->Recursive();
  466. }
  467. }
  468. //---------------------------------------------------------------------------
  469. __fastcall TMvSessionAction::TMvSessionAction(TActionLog * Log,
  470. const UnicodeString & FileName, const UnicodeString & ADestination) :
  471. TFileLocationSessionAction(Log, laMv, FileName)
  472. {
  473. Destination(ADestination);
  474. }
  475. //---------------------------------------------------------------------------
  476. __fastcall TCallSessionAction::TCallSessionAction(TActionLog * Log,
  477. const UnicodeString & Command, const UnicodeString & Destination) :
  478. TSessionAction(Log, laCall)
  479. {
  480. if (FRecord != NULL)
  481. {
  482. FRecord->Command(Command);
  483. FRecord->Destination(Destination);
  484. }
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TCallSessionAction::AddOutput(const UnicodeString & Output, bool StdError)
  488. {
  489. if (FRecord != NULL)
  490. {
  491. FRecord->AddOutput(Output, StdError);
  492. }
  493. }
  494. //---------------------------------------------------------------------------
  495. __fastcall TLsSessionAction::TLsSessionAction(TActionLog * Log,
  496. const UnicodeString & Destination) :
  497. TSessionAction(Log, laLs)
  498. {
  499. if (FRecord != NULL)
  500. {
  501. FRecord->Destination(Destination);
  502. }
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TLsSessionAction::FileList(TRemoteFileList * FileList)
  506. {
  507. if (FRecord != NULL)
  508. {
  509. FRecord->FileList(FileList);
  510. }
  511. }
  512. //---------------------------------------------------------------------------
  513. //---------------------------------------------------------------------------
  514. __fastcall TStatSessionAction::TStatSessionAction(TActionLog * Log, const UnicodeString & FileName) :
  515. TFileSessionAction(Log, laStat, FileName)
  516. {
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TStatSessionAction::File(TRemoteFile * File)
  520. {
  521. if (FRecord != NULL)
  522. {
  523. FRecord->File(File);
  524. }
  525. }
  526. //---------------------------------------------------------------------------
  527. //---------------------------------------------------------------------------
  528. TSessionInfo::TSessionInfo()
  529. {
  530. LoginTime = Now();
  531. }
  532. //---------------------------------------------------------------------------
  533. TFileSystemInfo::TFileSystemInfo()
  534. {
  535. memset(&IsCapable, false, sizeof(IsCapable));
  536. }
  537. //---------------------------------------------------------------------------
  538. //---------------------------------------------------------------------------
  539. FILE * __fastcall OpenFile(UnicodeString LogFileName, TSessionData * SessionData, bool Append, UnicodeString & NewFileName)
  540. {
  541. FILE * Result;
  542. UnicodeString ANewFileName = GetExpandedLogFileName(LogFileName, SessionData);
  543. Result = _wfopen(ANewFileName.c_str(), (Append ? L"a" : L"w"));
  544. if (Result != NULL)
  545. {
  546. setvbuf(Result, NULL, _IONBF, BUFSIZ);
  547. NewFileName = ANewFileName;
  548. }
  549. else
  550. {
  551. throw Exception(FMTLOAD(LOG_OPENERROR, (ANewFileName)));
  552. }
  553. return Result;
  554. }
  555. //---------------------------------------------------------------------------
  556. //---------------------------------------------------------------------------
  557. const wchar_t *LogLineMarks = L"<>!.*";
  558. __fastcall TSessionLog::TSessionLog(TSessionUI* UI, TSessionData * SessionData,
  559. TConfiguration * Configuration):
  560. TStringList()
  561. {
  562. FCriticalSection = new TCriticalSection;
  563. FLogging = false;
  564. FConfiguration = Configuration;
  565. FParent = NULL;
  566. FUI = UI;
  567. FSessionData = SessionData;
  568. FFile = NULL;
  569. FLoggedLines = 0;
  570. FTopIndex = -1;
  571. FCurrentLogFileName = L"";
  572. FCurrentFileName = L"";
  573. FClosed = false;
  574. }
  575. //---------------------------------------------------------------------------
  576. __fastcall TSessionLog::~TSessionLog()
  577. {
  578. FClosed = true;
  579. ReflectSettings();
  580. assert(FFile == NULL);
  581. delete FCriticalSection;
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TSessionLog::Lock()
  585. {
  586. FCriticalSection->Enter();
  587. }
  588. //---------------------------------------------------------------------------
  589. void __fastcall TSessionLog::Unlock()
  590. {
  591. FCriticalSection->Leave();
  592. }
  593. //---------------------------------------------------------------------------
  594. UnicodeString __fastcall TSessionLog::GetSessionName()
  595. {
  596. assert(FSessionData != NULL);
  597. return FSessionData->SessionName;
  598. }
  599. //---------------------------------------------------------------------------
  600. UnicodeString __fastcall TSessionLog::GetLine(Integer Index)
  601. {
  602. return Strings[Index - FTopIndex];
  603. }
  604. //---------------------------------------------------------------------------
  605. TLogLineType __fastcall TSessionLog::GetType(int Index)
  606. {
  607. return (TLogLineType)Objects[Index - FTopIndex];
  608. }
  609. //---------------------------------------------------------------------------
  610. void __fastcall TSessionLog::DoAddToParent(TLogLineType Type, const UnicodeString & Line)
  611. {
  612. assert(FParent != NULL);
  613. FParent->Add(Type, Line);
  614. }
  615. //---------------------------------------------------------------------------
  616. void __fastcall TSessionLog::DoAddToSelf(TLogLineType Type, const UnicodeString & Line)
  617. {
  618. if (FTopIndex < 0)
  619. {
  620. FTopIndex = 0;
  621. }
  622. TStringList::AddObject(Line, (TObject*)Type);
  623. FLoggedLines++;
  624. if (LogToFile())
  625. {
  626. if (FFile == NULL)
  627. {
  628. OpenLogFile();
  629. }
  630. if (FFile != NULL)
  631. {
  632. UnicodeString Timestamp = FormatDateTime(L" yyyy-mm-dd hh:nn:ss.zzz ", Now());
  633. UTF8String UtfLine = UTF8String(UnicodeString(LogLineMarks[Type]) + Timestamp + Line + "\n");
  634. fwrite(UtfLine.c_str(), UtfLine.Length(), 1, (FILE *)FFile);
  635. }
  636. }
  637. }
  638. //---------------------------------------------------------------------------
  639. void __fastcall TSessionLog::DoAdd(TLogLineType Type, UnicodeString Line,
  640. void __fastcall (__closure *f)(TLogLineType Type, const UnicodeString & Line))
  641. {
  642. UnicodeString Prefix;
  643. if (!Name.IsEmpty())
  644. {
  645. Prefix = L"[" + Name + L"] ";
  646. }
  647. while (!Line.IsEmpty())
  648. {
  649. f(Type, Prefix + CutToChar(Line, L'\n', false));
  650. }
  651. }
  652. //---------------------------------------------------------------------------
  653. void __fastcall TSessionLog::Add(TLogLineType Type, const UnicodeString & Line)
  654. {
  655. assert(FConfiguration);
  656. if (Logging)
  657. {
  658. try
  659. {
  660. if (FParent != NULL)
  661. {
  662. DoAdd(Type, Line, DoAddToParent);
  663. }
  664. else
  665. {
  666. TGuard Guard(FCriticalSection);
  667. BeginUpdate();
  668. try
  669. {
  670. DoAdd(Type, Line, DoAddToSelf);
  671. }
  672. __finally
  673. {
  674. DeleteUnnecessary();
  675. EndUpdate();
  676. }
  677. }
  678. }
  679. catch (Exception &E)
  680. {
  681. // We failed logging, turn it off and notify user.
  682. FConfiguration->Logging = false;
  683. try
  684. {
  685. throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
  686. }
  687. catch (Exception &E)
  688. {
  689. AddException(&E);
  690. FUI->HandleExtendedException(&E);
  691. }
  692. }
  693. }
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TSessionLog::AddException(Exception * E)
  697. {
  698. if (E != NULL)
  699. {
  700. Add(llException, ExceptionLogString(E));
  701. }
  702. }
  703. //---------------------------------------------------------------------------
  704. void __fastcall TSessionLog::ReflectSettings()
  705. {
  706. TGuard Guard(FCriticalSection);
  707. bool ALogging =
  708. !FClosed &&
  709. ((FParent != NULL) || FConfiguration->Logging);
  710. if (FLogging != ALogging)
  711. {
  712. FLogging = ALogging;
  713. StateChange();
  714. }
  715. // if logging to file was turned off or log file was changed -> close current log file
  716. if ((FFile != NULL) &&
  717. (!LogToFile() || (FCurrentLogFileName != FConfiguration->LogFileName)))
  718. {
  719. CloseLogFile();
  720. }
  721. DeleteUnnecessary();
  722. }
  723. //---------------------------------------------------------------------------
  724. bool __fastcall TSessionLog::LogToFile()
  725. {
  726. return Logging && FConfiguration->LogToFile && (FParent == NULL);
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TSessionLog::CloseLogFile()
  730. {
  731. if (FFile != NULL)
  732. {
  733. fclose((FILE *)FFile);
  734. FFile = NULL;
  735. }
  736. FCurrentLogFileName = L"";
  737. FCurrentFileName = L"";
  738. StateChange();
  739. }
  740. //---------------------------------------------------------------------------
  741. void __fastcall TSessionLog::OpenLogFile()
  742. {
  743. try
  744. {
  745. assert(FFile == NULL);
  746. assert(FConfiguration != NULL);
  747. FCurrentLogFileName = FConfiguration->LogFileName;
  748. FFile = OpenFile(FCurrentLogFileName, FSessionData, FConfiguration->LogFileAppend, FCurrentFileName);
  749. }
  750. catch (Exception & E)
  751. {
  752. // We failed logging to file, turn it off and notify user.
  753. FCurrentLogFileName = L"";
  754. FCurrentFileName = L"";
  755. FConfiguration->LogFileName = UnicodeString();
  756. try
  757. {
  758. throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
  759. }
  760. catch (Exception & E)
  761. {
  762. AddException(&E);
  763. FUI->HandleExtendedException(&E);
  764. }
  765. }
  766. StateChange();
  767. }
  768. //---------------------------------------------------------------------------
  769. void __fastcall TSessionLog::StateChange()
  770. {
  771. if (FOnStateChange != NULL)
  772. {
  773. FOnStateChange(this);
  774. }
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TSessionLog::DeleteUnnecessary()
  778. {
  779. BeginUpdate();
  780. try
  781. {
  782. if (!Logging || (FParent != NULL))
  783. {
  784. Clear();
  785. }
  786. else
  787. {
  788. while (!FConfiguration->LogWindowComplete && (Count > FConfiguration->LogWindowLines))
  789. {
  790. Delete(0);
  791. FTopIndex++;
  792. }
  793. }
  794. }
  795. __finally
  796. {
  797. EndUpdate();
  798. }
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TSessionLog::AddSystemInfo()
  802. {
  803. AddStartupInfo(true);
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TSessionLog::AddStartupInfo()
  807. {
  808. AddStartupInfo(false);
  809. }
  810. //---------------------------------------------------------------------------
  811. void __fastcall TSessionLog::AddStartupInfo(bool System)
  812. {
  813. TSessionData * Data = (System ? NULL : FSessionData);
  814. if (Logging)
  815. {
  816. if (FParent != NULL)
  817. {
  818. // do not add session info for secondary session
  819. // (this should better be handled in the TSecondaryTerminal)
  820. }
  821. else
  822. {
  823. DoAddStartupInfo(Data);
  824. }
  825. }
  826. }
  827. //---------------------------------------------------------------------------
  828. UnicodeString __fastcall TSessionLog::GetTlsVersionName(TTlsVersion TlsVersion)
  829. {
  830. switch (TlsVersion)
  831. {
  832. default:
  833. FAIL;
  834. case ssl2:
  835. return "SSLv2";
  836. case ssl3:
  837. return "SSLv3";
  838. case tls10:
  839. return "TLSv1.0";
  840. case tls11:
  841. return "TLSv1.1";
  842. case tls12:
  843. return "TLSv1.2";
  844. }
  845. }
  846. //---------------------------------------------------------------------------
  847. void __fastcall TSessionLog::DoAddStartupInfo(TSessionData * Data)
  848. {
  849. TGuard Guard(FCriticalSection);
  850. BeginUpdate();
  851. try
  852. {
  853. #define ADF(S, F) DoAdd(llMessage, FORMAT(S, F), DoAddToSelf);
  854. if (Data == NULL)
  855. {
  856. AddSeparator();
  857. ADF(L"WinSCP %s (OS %s)", (FConfiguration->VersionStr, FConfiguration->OSVersionStr));
  858. THierarchicalStorage * Storage = FConfiguration->CreateScpStorage(false);
  859. try
  860. {
  861. ADF(L"Configuration: %s", (Storage->Source));
  862. }
  863. __finally
  864. {
  865. delete Storage;
  866. }
  867. wchar_t UserName[UNLEN + 1];
  868. unsigned long UserNameSize = LENOF(UserName);
  869. if (ALWAYS_FALSE(!GetUserNameEx(NameSamCompatible, UserName, &UserNameSize)))
  870. {
  871. wcscpy(UserName, L"<Failed to retrieve username>");
  872. }
  873. ADF(L"Local account: %s", (UserName));
  874. ADF(L"Working directory: %s", (GetCurrentDir()));
  875. ADF(L"Process ID: %d", (int(GetCurrentProcessId())));
  876. ADF(L"Command-line: %s", (CmdLine));
  877. ADF(L"Time zone: %s", (GetTimeZoneLogString()));
  878. ADF(L"Login time: %s", (FormatDateTime(L"dddddd tt", Now())));
  879. AddSeparator();
  880. }
  881. else
  882. {
  883. ADF(L"Session name: %s (%s)", (Data->SessionName, Data->Source));
  884. ADF(L"Host name: %s (Port: %d)", (Data->HostNameExpanded, Data->PortNumber));
  885. ADF(L"User name: %s (Password: %s, Key file: %s)",
  886. (Data->UserNameExpanded, BooleanToEngStr(!Data->Password.IsEmpty()),
  887. BooleanToEngStr(!Data->PublicKeyFile.IsEmpty())))
  888. ADF(L"Tunnel: %s", (BooleanToEngStr(Data->Tunnel)));
  889. if (Data->Tunnel)
  890. {
  891. ADF(L"Tunnel: Host name: %s (Port: %d)", (Data->TunnelHostName, Data->TunnelPortNumber));
  892. ADF(L"Tunnel: User name: %s (Password: %s, Key file: %s)",
  893. (Data->TunnelUserName, BooleanToEngStr(!Data->TunnelPassword.IsEmpty()),
  894. BooleanToEngStr(!Data->TunnelPublicKeyFile.IsEmpty())))
  895. ADF(L"Tunnel: Local port number: %d", (Data->TunnelLocalPortNumber));
  896. }
  897. ADF(L"Transfer Protocol: %s", (Data->FSProtocolStr));
  898. wchar_t * PingTypes = L"-NC";
  899. TPingType PingType;
  900. int PingInterval;
  901. if (Data->FSProtocol == fsFTP)
  902. {
  903. PingType = Data->FtpPingType;
  904. PingInterval = Data->FtpPingInterval;
  905. }
  906. else
  907. {
  908. PingType = Data->PingType;
  909. PingInterval = Data->PingInterval;
  910. }
  911. ADF(L"Ping type: %s, Ping interval: %d sec; Timeout: %d sec",
  912. (UnicodeString(PingTypes[PingType]), PingInterval, Data->Timeout));
  913. ADF(L"Proxy: %s", (ProxyMethodList[Data->ProxyMethod]));
  914. if (Data->ProxyMethod != ::pmNone)
  915. {
  916. ADF(L"HostName: %s (Port: %d); Username: %s; Passwd: %s",
  917. (Data->ProxyHost, Data->ProxyPort,
  918. Data->ProxyUsername, BooleanToEngStr(!Data->ProxyPassword.IsEmpty())));
  919. if (Data->ProxyMethod == pmTelnet)
  920. {
  921. ADF(L"Telnet command: %s", (Data->ProxyTelnetCommand));
  922. }
  923. if (Data->ProxyMethod == pmCmd)
  924. {
  925. ADF(L"Local command: %s", (Data->ProxyLocalCommand));
  926. }
  927. }
  928. wchar_t const * BugFlags = L"+-A";
  929. if (Data->UsesSsh)
  930. {
  931. ADF(L"SSH protocol version: %s; Compression: %s",
  932. (Data->SshProtStr, BooleanToEngStr(Data->Compression)));
  933. ADF(L"Bypass authentication: %s",
  934. (BooleanToEngStr(Data->SshNoUserAuth)));
  935. ADF(L"Try agent: %s; Agent forwarding: %s; TIS/CryptoCard: %s; KI: %s; GSSAPI: %s",
  936. (BooleanToEngStr(Data->TryAgent), BooleanToEngStr(Data->AgentFwd), BooleanToEngStr(Data->AuthTIS),
  937. BooleanToEngStr(Data->AuthKI), BooleanToEngStr(Data->AuthGSSAPI)));
  938. if (Data->AuthGSSAPI)
  939. {
  940. ADF(L"GSSAPI: Forwarding: %s; Server realm: %s",
  941. (BooleanToEngStr(Data->GSSAPIFwdTGT), Data->GSSAPIServerRealm));
  942. }
  943. ADF(L"Ciphers: %s; Ssh2DES: %s",
  944. (Data->CipherList, BooleanToEngStr(Data->Ssh2DES)));
  945. UnicodeString Bugs;
  946. for (int Index = 0; Index < BUG_COUNT; Index++)
  947. {
  948. Bugs += UnicodeString(BugFlags[Data->Bug[(TSshBug)Index]])+(Index<BUG_COUNT-1?L",":L"");
  949. }
  950. ADF(L"SSH Bugs: %s", (Bugs));
  951. ADF(L"Return code variable: %s; Lookup user groups: %s",
  952. ((Data->DetectReturnVar ? UnicodeString(L"Autodetect") : Data->ReturnVar),
  953. BugFlags[Data->LookupUserGroups]));
  954. ADF(L"Shell: %s", ((Data->Shell.IsEmpty()? UnicodeString(L"default") : Data->Shell)));
  955. ADF(L"EOL: %d, UTF: %d", (Data->EOLType, Data->NotUtf));
  956. ADF(L"Clear aliases: %s, Unset nat.vars: %s, Resolve symlinks: %s",
  957. (BooleanToEngStr(Data->ClearAliases), BooleanToEngStr(Data->UnsetNationalVars),
  958. BooleanToEngStr(Data->ResolveSymlinks)));
  959. ADF(L"LS: %s, Ign LS warn: %s, Scp1 Comp: %s",
  960. (Data->ListingCommand,
  961. BooleanToEngStr(Data->IgnoreLsWarnings),
  962. BooleanToEngStr(Data->Scp1Compatibility)));
  963. }
  964. if (Data->FSProtocol == fsSFTP)
  965. {
  966. UnicodeString Bugs;
  967. for (int Index = 0; Index < SFTP_BUG_COUNT; Index++)
  968. {
  969. Bugs += UnicodeString(BugFlags[Data->SFTPBug[(TSftpBug)Index]])+(Index<SFTP_BUG_COUNT-1?L",":L"");
  970. }
  971. ADF(L"SFTP Bugs: %s", (Bugs));
  972. ADF(L"SFTP Server: %s", ((Data->SftpServer.IsEmpty()? UnicodeString(L"default") : Data->SftpServer)));
  973. }
  974. if (Data->FSProtocol == fsFTP)
  975. {
  976. UnicodeString Ftps;
  977. switch (Data->Ftps)
  978. {
  979. case ftpsImplicit:
  980. Ftps = L"Implicit TLS/SSL";
  981. break;
  982. case ftpsExplicitSsl:
  983. Ftps = L"Explicit SSL";
  984. break;
  985. case ftpsExplicitTls:
  986. Ftps = L"Explicit TLS";
  987. break;
  988. default:
  989. assert(Data->Ftps == ftpsNone);
  990. Ftps = L"None";
  991. break;
  992. }
  993. ADF(L"FTP: FTPS: %s; Passive: %s [Force IP: %s]; MLSD: %s [List all: %s]",
  994. (Ftps, BooleanToEngStr(Data->FtpPasvMode),
  995. BugFlags[Data->FtpForcePasvIp],
  996. BugFlags[Data->FtpUseMlsd],
  997. BugFlags[Data->FtpListAll]));
  998. if (Data->Ftps != ftpsNone)
  999. {
  1000. ADF(L"Session reuse: %s", (BooleanToEngStr(Data->SslSessionReuse)));
  1001. ADF(L"TLS/SSL versions: %s-%s", (GetTlsVersionName(Data->MinTlsVersion), GetTlsVersionName(Data->MaxTlsVersion)));
  1002. }
  1003. }
  1004. ADF(L"Local directory: %s, Remote directory: %s, Update: %s, Cache: %s",
  1005. ((Data->LocalDirectory.IsEmpty() ? UnicodeString(L"default") : Data->LocalDirectory),
  1006. (Data->RemoteDirectory.IsEmpty() ? UnicodeString(L"home") : Data->RemoteDirectory),
  1007. BooleanToEngStr(Data->UpdateDirectories),
  1008. BooleanToEngStr(Data->CacheDirectories)));
  1009. ADF(L"Cache directory changes: %s, Permanent: %s",
  1010. (BooleanToEngStr(Data->CacheDirectoryChanges),
  1011. BooleanToEngStr(Data->PreserveDirectoryChanges)));
  1012. int TimeDifferenceMin = TimeToMinutes(Data->TimeDifference);
  1013. ADF(L"DST mode: %d; Timezone offset: %dh %dm", (int(Data->DSTMode), (TimeDifferenceMin / MinsPerHour), (TimeDifferenceMin % MinsPerHour)));
  1014. if (Data->FSProtocol == fsWebDAV)
  1015. {
  1016. ADF(L"Compression: %s",
  1017. (BooleanToEngStr(Data->Compression)));
  1018. }
  1019. AddSeparator();
  1020. }
  1021. #undef ADF
  1022. }
  1023. __finally
  1024. {
  1025. DeleteUnnecessary();
  1026. EndUpdate();
  1027. }
  1028. }
  1029. //---------------------------------------------------------------------------
  1030. void __fastcall TSessionLog::AddSeparator()
  1031. {
  1032. Add(llMessage, L"--------------------------------------------------------------------------");
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. int __fastcall TSessionLog::GetBottomIndex()
  1036. {
  1037. return (Count > 0 ? (TopIndex + Count - 1) : -1);
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. bool __fastcall TSessionLog::GetLoggingToFile()
  1041. {
  1042. assert((FFile == NULL) || LogToFile());
  1043. return (FFile != NULL);
  1044. }
  1045. //---------------------------------------------------------------------------
  1046. void __fastcall TSessionLog::Clear()
  1047. {
  1048. TGuard Guard(FCriticalSection);
  1049. FTopIndex += Count;
  1050. TStringList::Clear();
  1051. }
  1052. //---------------------------------------------------------------------------
  1053. //---------------------------------------------------------------------------
  1054. __fastcall TActionLog::TActionLog(TSessionUI* UI, TSessionData * SessionData,
  1055. TConfiguration * Configuration)
  1056. {
  1057. FCriticalSection = new TCriticalSection;
  1058. FConfiguration = Configuration;
  1059. FUI = UI;
  1060. FSessionData = SessionData;
  1061. FFile = NULL;
  1062. FCurrentLogFileName = L"";
  1063. FCurrentFileName = L"";
  1064. FLogging = false;
  1065. FClosed = false;
  1066. FPendingActions = new TList();
  1067. FIndent = L" ";
  1068. FInGroup = false;
  1069. FEnabled = true;
  1070. }
  1071. //---------------------------------------------------------------------------
  1072. __fastcall TActionLog::~TActionLog()
  1073. {
  1074. assert(FPendingActions->Count == 0);
  1075. delete FPendingActions;
  1076. FClosed = true;
  1077. ReflectSettings();
  1078. assert(FFile == NULL);
  1079. delete FCriticalSection;
  1080. }
  1081. //---------------------------------------------------------------------------
  1082. void __fastcall TActionLog::Add(const UnicodeString & Line)
  1083. {
  1084. assert(FConfiguration);
  1085. if (FLogging)
  1086. {
  1087. try
  1088. {
  1089. TGuard Guard(FCriticalSection);
  1090. if (FFile == NULL)
  1091. {
  1092. OpenLogFile();
  1093. }
  1094. if (FFile != NULL)
  1095. {
  1096. UTF8String UtfLine = UTF8String(Line);
  1097. fwrite(UtfLine.c_str(), 1, UtfLine.Length(), (FILE *)FFile);
  1098. fwrite("\n", 1, 1, (FILE *)FFile);
  1099. }
  1100. }
  1101. catch (Exception &E)
  1102. {
  1103. // We failed logging, turn it off and notify user.
  1104. FConfiguration->LogActions = false;
  1105. try
  1106. {
  1107. throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
  1108. }
  1109. catch (Exception &E)
  1110. {
  1111. FUI->HandleExtendedException(&E);
  1112. }
  1113. }
  1114. }
  1115. }
  1116. //---------------------------------------------------------------------------
  1117. void __fastcall TActionLog::AddIndented(const UnicodeString & Line)
  1118. {
  1119. Add(FIndent + Line);
  1120. }
  1121. //---------------------------------------------------------------------------
  1122. void __fastcall TActionLog::AddFailure(TStrings * Messages)
  1123. {
  1124. AddIndented(L"<failure>");
  1125. AddMessages(L" ", Messages);
  1126. AddIndented(L"</failure>");
  1127. }
  1128. //---------------------------------------------------------------------------
  1129. void __fastcall TActionLog::AddFailure(Exception * E)
  1130. {
  1131. TStrings * Messages = ExceptionToMoreMessages(E);
  1132. if (Messages != NULL)
  1133. {
  1134. try
  1135. {
  1136. AddFailure(Messages);
  1137. }
  1138. __finally
  1139. {
  1140. delete Messages;
  1141. }
  1142. }
  1143. }
  1144. //---------------------------------------------------------------------------
  1145. void __fastcall TActionLog::AddMessages(UnicodeString Indent, TStrings * Messages)
  1146. {
  1147. for (int Index = 0; Index < Messages->Count; Index++)
  1148. {
  1149. AddIndented(
  1150. FORMAT(Indent + L"<message>%s</message>", (XmlEscape(Messages->Strings[Index]))));
  1151. }
  1152. }
  1153. //---------------------------------------------------------------------------
  1154. void __fastcall TActionLog::ReflectSettings()
  1155. {
  1156. TGuard Guard(FCriticalSection);
  1157. bool ALogging =
  1158. !FClosed && FConfiguration->LogActions && Enabled;
  1159. if (ALogging && !FLogging)
  1160. {
  1161. FLogging = true;
  1162. Add(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1163. Add(FORMAT(L"<session xmlns=\"http://winscp.net/schema/session/1.0\" name=\"%s\" start=\"%s\">",
  1164. (XmlAttributeEscape(FSessionData->SessionName), StandardTimestamp())));
  1165. }
  1166. else if (!ALogging && FLogging)
  1167. {
  1168. if (FInGroup)
  1169. {
  1170. EndGroup();
  1171. }
  1172. // do not try to close the file, if it has not been opened, to avoid recursion
  1173. if (FFile != NULL)
  1174. {
  1175. Add(L"</session>");
  1176. }
  1177. CloseLogFile();
  1178. FLogging = false;
  1179. }
  1180. }
  1181. //---------------------------------------------------------------------------
  1182. void __fastcall TActionLog::CloseLogFile()
  1183. {
  1184. if (FFile != NULL)
  1185. {
  1186. fclose((FILE *)FFile);
  1187. FFile = NULL;
  1188. }
  1189. FCurrentLogFileName = L"";
  1190. FCurrentFileName = L"";
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. void __fastcall TActionLog::OpenLogFile()
  1194. {
  1195. try
  1196. {
  1197. assert(FFile == NULL);
  1198. assert(FConfiguration != NULL);
  1199. FCurrentLogFileName = FConfiguration->ActionsLogFileName;
  1200. FFile = OpenFile(FCurrentLogFileName, FSessionData, false, FCurrentFileName);
  1201. }
  1202. catch (Exception & E)
  1203. {
  1204. // We failed logging to file, turn it off and notify user.
  1205. FCurrentLogFileName = L"";
  1206. FCurrentFileName = L"";
  1207. FConfiguration->LogActions = false;
  1208. try
  1209. {
  1210. throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
  1211. }
  1212. catch (Exception & E)
  1213. {
  1214. FUI->HandleExtendedException(&E);
  1215. }
  1216. }
  1217. }
  1218. //---------------------------------------------------------------------------
  1219. void __fastcall TActionLog::AddPendingAction(TSessionActionRecord * Action)
  1220. {
  1221. FPendingActions->Add(Action);
  1222. }
  1223. //---------------------------------------------------------------------------
  1224. void __fastcall TActionLog::RecordPendingActions()
  1225. {
  1226. while ((FPendingActions->Count > 0) &&
  1227. static_cast<TSessionActionRecord *>(FPendingActions->Items[0])->Record())
  1228. {
  1229. FPendingActions->Delete(0);
  1230. }
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TActionLog::BeginGroup(UnicodeString Name)
  1234. {
  1235. assert(!FInGroup);
  1236. FInGroup = true;
  1237. assert(FIndent == L" ");
  1238. AddIndented(FORMAT("<group name=\"%s\" start=\"%s\">",
  1239. (XmlAttributeEscape(Name), StandardTimestamp())));
  1240. FIndent = L" ";
  1241. }
  1242. //---------------------------------------------------------------------------
  1243. void __fastcall TActionLog::EndGroup()
  1244. {
  1245. assert(FInGroup);
  1246. FInGroup = false;
  1247. assert(FIndent == L" ");
  1248. FIndent = L" ";
  1249. // this is called from ReflectSettings that in turn is called when logging fails,
  1250. // so do not try to close the group, if it has not been opened, to avoid recursion
  1251. if (FFile != NULL)
  1252. {
  1253. AddIndented("</group>");
  1254. }
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. void __fastcall TActionLog::SetEnabled(bool value)
  1258. {
  1259. if (Enabled != value)
  1260. {
  1261. FEnabled = value;
  1262. ReflectSettings();
  1263. }
  1264. }