SessionInfo.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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, 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. void __fastcall TSessionLog::DoAddStartupInfo(TSessionData * Data)
  829. {
  830. TGuard Guard(FCriticalSection);
  831. BeginUpdate();
  832. try
  833. {
  834. #define ADF(S, F) DoAdd(llMessage, FORMAT(S, F), DoAddToSelf);
  835. if (Data == NULL)
  836. {
  837. AddSeparator();
  838. ADF(L"WinSCP %s (OS %s)", (FConfiguration->VersionStr, FConfiguration->OSVersionStr));
  839. THierarchicalStorage * Storage = FConfiguration->CreateScpStorage(false);
  840. try
  841. {
  842. ADF(L"Configuration: %s", (Storage->Source));
  843. }
  844. __finally
  845. {
  846. delete Storage;
  847. }
  848. typedef BOOL WINAPI (* TGetUserNameEx)(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize);
  849. HINSTANCE Secur32 = LoadLibrary(L"secur32.dll");
  850. TGetUserNameEx GetUserNameEx =
  851. (Secur32 != NULL) ? (TGetUserNameEx)GetProcAddress(Secur32, "GetUserNameExW") : NULL;
  852. wchar_t UserName[UNLEN + 1];
  853. unsigned long UserNameSize = LENOF(UserName);
  854. if ((GetUserNameEx == NULL) || !GetUserNameEx(NameSamCompatible, UserName, &UserNameSize))
  855. {
  856. wcscpy(UserName, L"<Failed to retrieve username>");
  857. }
  858. ADF(L"Local account: %s", (UserName));
  859. ADF(L"Working directory: %s", (GetCurrentDir()));
  860. ADF(L"Process ID: %d", (int(GetCurrentProcessId())));
  861. ADF(L"Command-line: %s", (CmdLine));
  862. ADF(L"Time zone: %s", (GetTimeZoneLogString()));
  863. ADF(L"Login time: %s", (FormatDateTime(L"dddddd tt", Now())));
  864. AddSeparator();
  865. }
  866. else
  867. {
  868. ADF(L"Session name: %s (%s)", (Data->SessionName, Data->Source));
  869. ADF(L"Host name: %s (Port: %d)", (Data->HostNameExpanded, Data->PortNumber));
  870. ADF(L"User name: %s (Password: %s, Key file: %s)",
  871. (Data->UserNameExpanded, BooleanToEngStr(!Data->Password.IsEmpty()),
  872. BooleanToEngStr(!Data->PublicKeyFile.IsEmpty())))
  873. ADF(L"Tunnel: %s", (BooleanToEngStr(Data->Tunnel)));
  874. if (Data->Tunnel)
  875. {
  876. ADF(L"Tunnel: Host name: %s (Port: %d)", (Data->TunnelHostName, Data->TunnelPortNumber));
  877. ADF(L"Tunnel: User name: %s (Password: %s, Key file: %s)",
  878. (Data->TunnelUserName, BooleanToEngStr(!Data->TunnelPassword.IsEmpty()),
  879. BooleanToEngStr(!Data->TunnelPublicKeyFile.IsEmpty())))
  880. ADF(L"Tunnel: Local port number: %d", (Data->TunnelLocalPortNumber));
  881. }
  882. ADF(L"Transfer Protocol: %s", (Data->FSProtocolStr));
  883. wchar_t * PingTypes = L"-NC";
  884. TPingType PingType;
  885. int PingInterval;
  886. if (Data->FSProtocol == fsFTP)
  887. {
  888. PingType = Data->FtpPingType;
  889. PingInterval = Data->FtpPingInterval;
  890. }
  891. else
  892. {
  893. PingType = Data->PingType;
  894. PingInterval = Data->PingInterval;
  895. }
  896. ADF(L"Ping type: %s, Ping interval: %d sec; Timeout: %d sec",
  897. (UnicodeString(PingTypes[PingType]), PingInterval, Data->Timeout));
  898. ADF(L"Proxy: %s", (ProxyMethodList[Data->ProxyMethod]));
  899. if (Data->ProxyMethod != ::pmNone)
  900. {
  901. ADF(L"HostName: %s (Port: %d); Username: %s; Passwd: %s",
  902. (Data->ProxyHost, Data->ProxyPort,
  903. Data->ProxyUsername, BooleanToEngStr(!Data->ProxyPassword.IsEmpty())));
  904. if (Data->ProxyMethod == pmTelnet)
  905. {
  906. ADF(L"Telnet command: %s", (Data->ProxyTelnetCommand));
  907. }
  908. if (Data->ProxyMethod == pmCmd)
  909. {
  910. ADF(L"Local command: %s", (Data->ProxyLocalCommand));
  911. }
  912. }
  913. wchar_t const * BugFlags = L"+-A";
  914. if (Data->UsesSsh)
  915. {
  916. ADF(L"SSH protocol version: %s; Compression: %s",
  917. (Data->SshProtStr, BooleanToEngStr(Data->Compression)));
  918. ADF(L"Bypass authentication: %s",
  919. (BooleanToEngStr(Data->SshNoUserAuth)));
  920. ADF(L"Try agent: %s; Agent forwarding: %s; TIS/CryptoCard: %s; KI: %s; GSSAPI: %s",
  921. (BooleanToEngStr(Data->TryAgent), BooleanToEngStr(Data->AgentFwd), BooleanToEngStr(Data->AuthTIS),
  922. BooleanToEngStr(Data->AuthKI), BooleanToEngStr(Data->AuthGSSAPI)));
  923. if (Data->AuthGSSAPI)
  924. {
  925. ADF(L"GSSAPI: Forwarding: %s; Server realm: %s",
  926. (BooleanToEngStr(Data->GSSAPIFwdTGT), Data->GSSAPIServerRealm));
  927. }
  928. ADF(L"Ciphers: %s; Ssh2DES: %s",
  929. (Data->CipherList, BooleanToEngStr(Data->Ssh2DES)));
  930. UnicodeString Bugs;
  931. for (int Index = 0; Index < BUG_COUNT; Index++)
  932. {
  933. Bugs += UnicodeString(BugFlags[Data->Bug[(TSshBug)Index]])+(Index<BUG_COUNT-1?L",":L"");
  934. }
  935. ADF(L"SSH Bugs: %s", (Bugs));
  936. ADF(L"Return code variable: %s; Lookup user groups: %s",
  937. ((Data->DetectReturnVar ? UnicodeString(L"Autodetect") : Data->ReturnVar),
  938. BugFlags[Data->LookupUserGroups]));
  939. ADF(L"Shell: %s", ((Data->Shell.IsEmpty()? UnicodeString(L"default") : Data->Shell)));
  940. ADF(L"EOL: %d, UTF: %d", (Data->EOLType, Data->NotUtf));
  941. ADF(L"Clear aliases: %s, Unset nat.vars: %s, Resolve symlinks: %s",
  942. (BooleanToEngStr(Data->ClearAliases), BooleanToEngStr(Data->UnsetNationalVars),
  943. BooleanToEngStr(Data->ResolveSymlinks)));
  944. ADF(L"LS: %s, Ign LS warn: %s, Scp1 Comp: %s",
  945. (Data->ListingCommand,
  946. BooleanToEngStr(Data->IgnoreLsWarnings),
  947. BooleanToEngStr(Data->Scp1Compatibility)));
  948. }
  949. if (Data->FSProtocol == fsSFTP)
  950. {
  951. UnicodeString Bugs;
  952. for (int Index = 0; Index < SFTP_BUG_COUNT; Index++)
  953. {
  954. Bugs += UnicodeString(BugFlags[Data->SFTPBug[(TSftpBug)Index]])+(Index<SFTP_BUG_COUNT-1?L",":L"");
  955. }
  956. ADF(L"SFTP Bugs: %s", (Bugs));
  957. ADF(L"SFTP Server: %s", ((Data->SftpServer.IsEmpty()? UnicodeString(L"default") : Data->SftpServer)));
  958. }
  959. if (Data->FSProtocol == fsFTP)
  960. {
  961. UnicodeString Ftps;
  962. switch (Data->Ftps)
  963. {
  964. case ftpsImplicit:
  965. Ftps = L"Implicit SSL/TLS";
  966. break;
  967. case ftpsExplicitSsl:
  968. Ftps = L"Explicit SSL";
  969. break;
  970. case ftpsExplicitTls:
  971. Ftps = L"Explicit TLS";
  972. break;
  973. default:
  974. assert(Data->Ftps == ftpsNone);
  975. Ftps = L"None";
  976. break;
  977. }
  978. ADF(L"FTP: FTPS: %s; Passive: %s [Force IP: %s]; MLSD: %s [List all: %s]",
  979. (Ftps, BooleanToEngStr(Data->FtpPasvMode),
  980. BugFlags[Data->FtpForcePasvIp],
  981. BugFlags[Data->FtpUseMlsd],
  982. BugFlags[Data->FtpListAll]));
  983. if (Data->Ftps != ftpsNone)
  984. {
  985. ADF(L"Session reuse: %s", (BooleanToEngStr(Data->SslSessionReuse)));
  986. }
  987. }
  988. ADF(L"Local directory: %s, Remote directory: %s, Update: %s, Cache: %s",
  989. ((Data->LocalDirectory.IsEmpty() ? UnicodeString(L"default") : Data->LocalDirectory),
  990. (Data->RemoteDirectory.IsEmpty() ? UnicodeString(L"home") : Data->RemoteDirectory),
  991. BooleanToEngStr(Data->UpdateDirectories),
  992. BooleanToEngStr(Data->CacheDirectories)));
  993. ADF(L"Cache directory changes: %s, Permanent: %s",
  994. (BooleanToEngStr(Data->CacheDirectoryChanges),
  995. BooleanToEngStr(Data->PreserveDirectoryChanges)));
  996. int TimeDifferenceMin = TimeToMinutes(Data->TimeDifference);
  997. ADF(L"DST mode: %d; Timezone offset: %dh %dm", (int(Data->DSTMode), (TimeDifferenceMin / MinsPerHour), (TimeDifferenceMin % MinsPerHour)));
  998. if (Data->FSProtocol == fsWebDAV)
  999. {
  1000. ADF(L"Compression: %s",
  1001. (BooleanToEngStr(Data->Compression)));
  1002. }
  1003. AddSeparator();
  1004. }
  1005. #undef ADF
  1006. }
  1007. __finally
  1008. {
  1009. DeleteUnnecessary();
  1010. EndUpdate();
  1011. }
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TSessionLog::AddSeparator()
  1015. {
  1016. Add(llMessage, L"--------------------------------------------------------------------------");
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. int __fastcall TSessionLog::GetBottomIndex()
  1020. {
  1021. return (Count > 0 ? (TopIndex + Count - 1) : -1);
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. bool __fastcall TSessionLog::GetLoggingToFile()
  1025. {
  1026. assert((FFile == NULL) || LogToFile());
  1027. return (FFile != NULL);
  1028. }
  1029. //---------------------------------------------------------------------------
  1030. void __fastcall TSessionLog::Clear()
  1031. {
  1032. TGuard Guard(FCriticalSection);
  1033. FTopIndex += Count;
  1034. TStringList::Clear();
  1035. }
  1036. //---------------------------------------------------------------------------
  1037. //---------------------------------------------------------------------------
  1038. __fastcall TActionLog::TActionLog(TSessionUI* UI, TSessionData * SessionData,
  1039. TConfiguration * Configuration)
  1040. {
  1041. FCriticalSection = new TCriticalSection;
  1042. FConfiguration = Configuration;
  1043. FUI = UI;
  1044. FSessionData = SessionData;
  1045. FFile = NULL;
  1046. FCurrentLogFileName = L"";
  1047. FCurrentFileName = L"";
  1048. FLogging = false;
  1049. FClosed = false;
  1050. FPendingActions = new TList();
  1051. FIndent = L" ";
  1052. FInGroup = false;
  1053. FEnabled = true;
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. __fastcall TActionLog::~TActionLog()
  1057. {
  1058. assert(FPendingActions->Count == 0);
  1059. delete FPendingActions;
  1060. FClosed = true;
  1061. ReflectSettings();
  1062. assert(FFile == NULL);
  1063. delete FCriticalSection;
  1064. }
  1065. //---------------------------------------------------------------------------
  1066. void __fastcall TActionLog::Add(const UnicodeString & Line)
  1067. {
  1068. assert(FConfiguration);
  1069. if (FLogging)
  1070. {
  1071. try
  1072. {
  1073. TGuard Guard(FCriticalSection);
  1074. if (FFile == NULL)
  1075. {
  1076. OpenLogFile();
  1077. }
  1078. if (FFile != NULL)
  1079. {
  1080. UTF8String UtfLine = UTF8String(Line);
  1081. fwrite(UtfLine.c_str(), 1, UtfLine.Length(), (FILE *)FFile);
  1082. fwrite("\n", 1, 1, (FILE *)FFile);
  1083. }
  1084. }
  1085. catch (Exception &E)
  1086. {
  1087. // We failed logging, turn it off and notify user.
  1088. FConfiguration->LogActions = false;
  1089. try
  1090. {
  1091. throw ExtException(&E, LOG_GEN_ERROR);
  1092. }
  1093. catch (Exception &E)
  1094. {
  1095. FUI->HandleExtendedException(&E);
  1096. }
  1097. }
  1098. }
  1099. }
  1100. //---------------------------------------------------------------------------
  1101. void __fastcall TActionLog::AddIndented(const UnicodeString & Line)
  1102. {
  1103. Add(FIndent + Line);
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TActionLog::AddFailure(TStrings * Messages)
  1107. {
  1108. AddIndented(L"<failure>");
  1109. AddMessages(L" ", Messages);
  1110. AddIndented(L"</failure>");
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. void __fastcall TActionLog::AddFailure(Exception * E)
  1114. {
  1115. TStrings * Messages = ExceptionToMoreMessages(E);
  1116. if (Messages != NULL)
  1117. {
  1118. try
  1119. {
  1120. AddFailure(Messages);
  1121. }
  1122. __finally
  1123. {
  1124. delete Messages;
  1125. }
  1126. }
  1127. }
  1128. //---------------------------------------------------------------------------
  1129. void __fastcall TActionLog::AddMessages(UnicodeString Indent, TStrings * Messages)
  1130. {
  1131. for (int Index = 0; Index < Messages->Count; Index++)
  1132. {
  1133. AddIndented(
  1134. FORMAT(Indent + L"<message>%s</message>", (XmlEscape(Messages->Strings[Index]))));
  1135. }
  1136. }
  1137. //---------------------------------------------------------------------------
  1138. void __fastcall TActionLog::ReflectSettings()
  1139. {
  1140. TGuard Guard(FCriticalSection);
  1141. bool ALogging =
  1142. !FClosed && FConfiguration->LogActions && Enabled;
  1143. if (ALogging && !FLogging)
  1144. {
  1145. FLogging = true;
  1146. Add(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  1147. Add(FORMAT(L"<session xmlns=\"http://winscp.net/schema/session/1.0\" name=\"%s\" start=\"%s\">",
  1148. (XmlAttributeEscape(FSessionData->SessionName), StandardTimestamp())));
  1149. }
  1150. else if (!ALogging && FLogging)
  1151. {
  1152. if (FInGroup)
  1153. {
  1154. EndGroup();
  1155. }
  1156. // do not try to close the file, if it has not been opened, to avoid recursion
  1157. if (FFile != NULL)
  1158. {
  1159. Add(L"</session>");
  1160. }
  1161. CloseLogFile();
  1162. FLogging = false;
  1163. }
  1164. }
  1165. //---------------------------------------------------------------------------
  1166. void __fastcall TActionLog::CloseLogFile()
  1167. {
  1168. if (FFile != NULL)
  1169. {
  1170. fclose((FILE *)FFile);
  1171. FFile = NULL;
  1172. }
  1173. FCurrentLogFileName = L"";
  1174. FCurrentFileName = L"";
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TActionLog::OpenLogFile()
  1178. {
  1179. try
  1180. {
  1181. assert(FFile == NULL);
  1182. assert(FConfiguration != NULL);
  1183. FCurrentLogFileName = FConfiguration->ActionsLogFileName;
  1184. FFile = OpenFile(FCurrentLogFileName, FSessionData, false, FCurrentFileName);
  1185. }
  1186. catch (Exception & E)
  1187. {
  1188. // We failed logging to file, turn it off and notify user.
  1189. FCurrentLogFileName = L"";
  1190. FCurrentFileName = L"";
  1191. FConfiguration->LogActions = false;
  1192. try
  1193. {
  1194. throw ExtException(&E, LoadStr(LOG_GEN_ERROR));
  1195. }
  1196. catch (Exception & E)
  1197. {
  1198. FUI->HandleExtendedException(&E);
  1199. }
  1200. }
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TActionLog::AddPendingAction(TSessionActionRecord * Action)
  1204. {
  1205. FPendingActions->Add(Action);
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TActionLog::RecordPendingActions()
  1209. {
  1210. while ((FPendingActions->Count > 0) &&
  1211. static_cast<TSessionActionRecord *>(FPendingActions->Items[0])->Record())
  1212. {
  1213. FPendingActions->Delete(0);
  1214. }
  1215. }
  1216. //---------------------------------------------------------------------------
  1217. void __fastcall TActionLog::BeginGroup(UnicodeString Name)
  1218. {
  1219. assert(!FInGroup);
  1220. FInGroup = true;
  1221. assert(FIndent == L" ");
  1222. AddIndented(FORMAT("<group name=\"%s\" start=\"%s\">",
  1223. (XmlAttributeEscape(Name), StandardTimestamp())));
  1224. FIndent = L" ";
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TActionLog::EndGroup()
  1228. {
  1229. assert(FInGroup);
  1230. FInGroup = false;
  1231. assert(FIndent == L" ");
  1232. FIndent = L" ";
  1233. // this is called from ReflectSettings that in turn is called when logging fails,
  1234. // so do not try to close the group, if it has not been opened, to avoid recursion
  1235. if (FFile != NULL)
  1236. {
  1237. AddIndented("</group>");
  1238. }
  1239. }
  1240. //---------------------------------------------------------------------------
  1241. void __fastcall TActionLog::SetEnabled(bool value)
  1242. {
  1243. if (Enabled != value)
  1244. {
  1245. FEnabled = value;
  1246. ReflectSettings();
  1247. }
  1248. }