SessionInfo.cpp 39 KB

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