Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1457 lines
43 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: log.cxx
  4. //
  5. // Contents: The code for the logging servers client logging methods
  6. //
  7. // Functions: Log::Log()
  8. // Log::Log(int, char *[])
  9. // Log::Log(PCHAR, PCHAR, PCHAR, PCHAR, PCHAR)
  10. // Log::Log(LPWSTR, LPWSTR, LPWSTR, LPWSTR, LPWSTR)
  11. // Log::~Log()
  12. // Log::Info(inc, char *[])
  13. // Log::WriteVar(PCHAR, USHORT, PCHAR, ...)
  14. // Log::WriteVar(LPWSTR, USHORT, LPWSTR, ...)
  15. // Log::WriteVar(PCHAR, USHORT, USHORT, PVOID, PCHAR, ...)
  16. // Log::WriteVar(LPWSTR, USHORT, USHORT, PVOID, LPWSTR, ...)
  17. // Log::WriteVarList(PCHAR, USHORT, PCHAR, va_list)
  18. // Log::WriteVarList(LPWSTR, USHORT, LPWSTR, va_list)
  19. // Log::WriteVarList(PCHAR, USHORT, USHORT, PVOID, PCHAR, va_list)
  20. // Log::WriteVarList(LPWSTR, USHORT, USHORT, PVOID,
  21. // LPWSTR, va_list)
  22. // Log::WriteData(PCHAR, ...)
  23. // Log::WriteData(LPWSTR, ...)
  24. // Log::WriteData(USHORT, PVOID, PCHAR, ...)
  25. // Log::WriteData(USHORT, PVOID, LPWSTR, ...)
  26. // Log::WriteDataList(PCHAR, va_list)
  27. // Log::WriteDataList(LPWSTR, va_list)
  28. // Log::WriteDataList(USHORT, PVOID, PCHAR, va_list)
  29. // Log::WriteDataList(USHORT, PVOID, LPWSTR, va_list)
  30. //
  31. // History: 24-Sep-90 DaveWi Initial Coding
  32. // 15-Aug-91 AliceSe set local logging if error binding
  33. // 25-Sep-91 BryanT Converted to C 7.0
  34. // 17-Oct-91 SarahJ DCR 525 - changed status parm of
  35. // WriteVar methods to USHORT and validated
  36. // parm to be in expected range
  37. // 31-Oct-91 SarahJ Now takes /L or /mL for server parm
  38. // 10-Feb-92 BryanT Win32 work and cleanup
  39. // 3-Jul-92 DeanE Added WriteVarList, WriteDataList, and
  40. // changed existing WriteVar and WriteData
  41. // methods to call them
  42. // 1-Aug-92 DwightKr Renamed CPCHAR as CPPSZ. CPCHAR
  43. // conflicted with the 297 version of
  44. // windows.h
  45. // 31-Oct-92 SarahJ Removed references to tester name
  46. //
  47. //--------------------------------------------------------------------
  48. #include <pch.cxx>
  49. // BUGBUG Precompiled header does not work on Alpha for some unknown reason and
  50. // so we temporarily remove it.
  51. // #pragma hdrstop
  52. // Set up a table of the status text values
  53. const char * aStatus[] = { LOG_PASS_TXT,
  54. LOG_FAIL_TXT,
  55. LOG_WARN_TXT,
  56. LOG_ABORT_TXT,
  57. LOG_INFO_TXT,
  58. LOG_START_TXT,
  59. LOG_DONE_TXT };
  60. LPWSTR waStatus[] = { wLOG_PASS_TXT,
  61. wLOG_FAIL_TXT,
  62. wLOG_WARN_TXT,
  63. wLOG_ABORT_TXT,
  64. wLOG_INFO_TXT,
  65. wLOG_START_TXT,
  66. wLOG_DONE_TXT };
  67. //+----------------------------------------------------------------------------
  68. //
  69. // Function: IncLogStats(), static
  70. //
  71. // Synopsis: Increments the appropriate member of the passed-in LogStats
  72. // struct based on value of the usStatus passed in.
  73. //
  74. // Effects: Maintains correct status of the LogStats struct so we can
  75. // keep a running count of the log records written.
  76. //
  77. // Arguments: [out] LogStats& stStats - structure to modify
  78. // [in] ULONG usStat - code tells which field to increment
  79. //
  80. // Returns: nothing
  81. //
  82. // Modifies: stStats
  83. //
  84. // History: 11-Jun-92 DonCl first version
  85. //
  86. // Notes: Used by different overloaded versions of WriteVar()
  87. //
  88. //-----------------------------------------------------------------------------
  89. static VOID IncLogStats(LogStats& stStats, USHORT usStats)
  90. {
  91. switch(usStats)
  92. {
  93. case LOG_PASS:
  94. stStats.ulPass++;
  95. break;
  96. case LOG_FAIL:
  97. stStats.ulFail++;
  98. break;
  99. case LOG_WARN:
  100. stStats.ulWarn++;
  101. break;
  102. case LOG_ABORT:
  103. stStats.ulAbort++;
  104. break;
  105. case LOG_INFO:
  106. stStats.ulInfo++;
  107. break;
  108. case LOG_START:
  109. stStats.ulStart++;
  110. break;
  111. case LOG_DONE:
  112. stStats.ulDone++;
  113. break;
  114. //
  115. // No default, if code is unrecognized, there is no appropriate error
  116. // action to take.
  117. //
  118. }
  119. }
  120. //+-------------------------------------------------------------------
  121. //
  122. // Member: Log::Log(DWORD)
  123. //
  124. // Synopsis: The log file is not opened if this constructor is used -
  125. // the user must subsequently call the Info() method.
  126. //
  127. // Arguments: [fUseUnicode] - whether we should use WCHARs
  128. //
  129. // Modifies: fInfoSet
  130. //
  131. // History: ??-???-?? ???????? Created
  132. //
  133. //--------------------------------------------------------------------
  134. Log :: Log(DWORD dwCharType) : fInfoSet(FALSE), ulLastError(NO_ERROR)
  135. {
  136. if(LOG_ANSI == dwCharType)
  137. {
  138. fIsUnicode = FALSE;
  139. }
  140. else if(LOG_UNICODE == dwCharType)
  141. {
  142. fIsUnicode = TRUE;
  143. }
  144. else
  145. {
  146. ulLastError = (ULONG) E_INVALIDARG;
  147. return;
  148. }
  149. //
  150. // zero out the _LogStats member
  151. //
  152. memset((VOID *)(&_stLogStats), 0, sizeof(LogStats));
  153. }
  154. //+-------------------------------------------------------------------
  155. //
  156. // Member: Log::Log(int, char *[], DWORD)
  157. //
  158. // Synopsis: Log constructor with command line data given
  159. //
  160. // Arguments: [argc] - Argument count
  161. // [argv] - Argument array
  162. // [fUseUnicode] - whether we should use WCHARs
  163. //
  164. // Returns: Results from Info()
  165. //
  166. // History: ??-???-?? ???????? Created
  167. // Jun-11-92 DonCl added line to zero out LogStats struct
  168. //
  169. //--------------------------------------------------------------------
  170. Log :: Log(int argc, char *argv[], DWORD dwCharType) :
  171. fInfoSet(FALSE),
  172. ulLastError(NO_ERROR)
  173. {
  174. if(LOG_ANSI == dwCharType)
  175. {
  176. fIsUnicode = FALSE;
  177. }
  178. else if(LOG_UNICODE == dwCharType)
  179. {
  180. fIsUnicode = TRUE;
  181. }
  182. else
  183. {
  184. ulLastError = (ULONG) E_INVALIDARG;
  185. return;
  186. }
  187. //
  188. // zero out the _LogStats member
  189. //
  190. memset((VOID *)(&_stLogStats), 0, sizeof(LogStats));
  191. ulLastError = Info(argc, argv);
  192. }
  193. //+-------------------------------------------------------------------
  194. //
  195. // Member: Log::Log(PCHAR, PCHAR, PCHAR, PCHAR, PCHAR)
  196. //
  197. // Synopsis: Log constructor with internal data given
  198. //
  199. // Arguments: [pszSrvr] - Name of logging server
  200. // [pszTest] - Name of this test
  201. // [pszName] - Name of test runner
  202. // [pszSubPath] - Users log file qualifer
  203. // [pszObject] - Name of invoking object
  204. //
  205. // Returns:
  206. //
  207. // Modifies:
  208. //
  209. // History: ??-???-?? ???????? Created
  210. // Jun-11-92 DonCl added line to zero out LogStats struct
  211. //
  212. // BUGBUG wszName unused - left until all components can co-ordinate
  213. // with this. SarahJ
  214. //--------------------------------------------------------------------
  215. Log :: Log(PCHAR pszSrvr,
  216. PCHAR pszTest,
  217. PCHAR pszName,
  218. PCHAR pszSubPath,
  219. PCHAR pszObject) : fIsUnicode(FALSE), ulLastError(NO_ERROR)
  220. {
  221. memset((VOID *)(&_stLogStats), 0, sizeof(LogStats)); // zero out
  222. InitLogging();
  223. // Print warning if server name given
  224. if(NULL != pszSrvr)
  225. {
  226. fprintf(stderr, "Remote server not supported with this version of "
  227. "log.lib. Continuing.\n");
  228. }
  229. ulLastError = SetInfo(NULL, pszTest, pszSubPath, pszObject);
  230. if(ulLastError == NO_ERROR)
  231. {
  232. ulLastError = LogOpen() || WriteVar((PCHAR) NULL, LOG_START);
  233. }
  234. }
  235. //+-------------------------------------------------------------------
  236. //
  237. // Member: Log::Log(LPWSTR, LPWSTR, LPWSTR, LPWSTR, LPWSTR)
  238. //
  239. // Synopsis: Log constructor with internal data given
  240. //
  241. // Arguments: [wszSrvr] - Name of logging server
  242. // [wszTest] - Name of this test
  243. // [wszName] - Name of test runner
  244. // [wszSubPath] - Users log file qualifer
  245. // [wszObject] - Name of invoking object
  246. //
  247. // Returns:
  248. //
  249. // Modifies:
  250. //
  251. // History: ??-???-?? ???????? Created
  252. // Jun-11-92 DonCl added line to zero out LogStats struct
  253. //
  254. // BUGBUG wszName unused - left until all components can co-ordinate
  255. // with this. SarahJ
  256. //--------------------------------------------------------------------
  257. Log :: Log(LPWSTR wszSrvr,
  258. LPWSTR wszTest,
  259. LPWSTR wszName,
  260. LPWSTR wszSubPath,
  261. LPWSTR wszObject) : fIsUnicode(TRUE), ulLastError(NO_ERROR)
  262. {
  263. memset((VOID *)(&_stLogStats), 0, sizeof(LogStats)); // zero out
  264. InitLogging();
  265. // Print warning if server name given
  266. if(NULL != wszSrvr)
  267. {
  268. fprintf(stderr, "Remote server not supported with this version of "
  269. "log.lib. Continuing.\n");
  270. }
  271. ulLastError = SetInfo(NULL, wszTest, wszSubPath, wszObject);
  272. if (ulLastError == NO_ERROR)
  273. {
  274. ulLastError = LogOpen() || WriteVar((LPWSTR) NULL, LOG_START);
  275. }
  276. }
  277. //+-------------------------------------------------------------------
  278. //
  279. // Member: Log::~Log()
  280. //
  281. // Synopsis: Destroy the Log Object
  282. //
  283. // History: ??-???-?? ???????? Created
  284. //
  285. //--------------------------------------------------------------------
  286. Log :: ~Log()
  287. {
  288. if(fInfoSet != FALSE)
  289. {
  290. if(FALSE == fIsUnicode)
  291. {
  292. if(WriteVar((PCHAR) NULL, LOG_DONE) != NO_ERROR)
  293. {
  294. LogPrintf(stderr, "ERROR: Failed to log \"%s\" status\n",
  295. LOG_DONE_TXT);
  296. }
  297. }
  298. else
  299. {
  300. if(WriteVar((LPWSTR) NULL, LOG_DONE) != NO_ERROR)
  301. {
  302. LogPrintf(stderr, "ERROR: Failed to log \"%ls\" status\n",
  303. wLOG_DONE_TXT);
  304. }
  305. }
  306. FreeLogging(); // Make sure memory is freed & file closed
  307. }
  308. }
  309. //+-------------------------------------------------------------------
  310. //
  311. // Member: Log::Info(int, char *[])
  312. //
  313. // Synopsis: Parse the command line and set the appropriate member variables
  314. //
  315. // Arguments: [argc] - Argument count
  316. // [argv] - Argument vector
  317. //
  318. // Returns:
  319. //
  320. // Modifies:
  321. //
  322. // History: ??-???-?? ???????? Created
  323. // 30-Oct-92 SarahJ Updated parms to SetInfo
  324. //
  325. //--------------------------------------------------------------------
  326. ULONG Log :: Info(int argc, char *argv[])
  327. {
  328. USHORT usNdx; // Index into cmnd line args
  329. PCHAR pszTest = NULL; // Name of this test
  330. PCHAR pszSubPath = NULL; // Users log file qualifer
  331. PCHAR pszObject = NULL; // Name of invoking object
  332. PCHAR pch; // Temporary pointer into a string
  333. InitLogging();
  334. // All the argv processing is still done in CHARs
  335. if(ulLastError == NO_ERROR)
  336. {
  337. //
  338. // For every command line switch, check its validity and parse its
  339. // value. This version allows / or - for switches. If there are
  340. // no command line switches, this loop is skipped. This is for the
  341. // case when Log() is called with no messages.
  342. //
  343. for(usNdx = 1; usNdx < (unsigned short) argc; ++usNdx)
  344. {
  345. char *szArg = argv[ usNdx];
  346. pch = szArg;
  347. // check for / -
  348. if(*szArg == '/' || *szArg == '-')
  349. {
  350. register int i = 1;
  351. pch++;
  352. //
  353. // Check if next char is m, ie handed down from manager code.
  354. // If so skip m
  355. //
  356. if (*pch == 'm' || *pch == 'M')
  357. {
  358. pch++;
  359. i++;
  360. }
  361. ++pch; // Skip next char and check for :
  362. if(*pch++ == ':')
  363. {
  364. switch(toupper(szArg[i]))
  365. {
  366. case 'O': // Object name found
  367. pszObject = (PCHAR)pch;
  368. break;
  369. case 'P': // Directory Path switch found
  370. pszSubPath = (PCHAR)pch;
  371. break;
  372. case 'L': // Logging server name found
  373. fprintf(stderr, "Logging server not supported with "
  374. "this version of log.lib. Continuing.\n");
  375. break;
  376. case 'T': // Test name found
  377. pszTest = (PCHAR)pch;
  378. break;
  379. default: // Skip this unknown argument
  380. break;
  381. }
  382. }
  383. }
  384. }
  385. // If no test name was given, set pszTest to the apps base name.
  386. char szName[_MAX_FNAME];
  387. if(pszTest == NULL || *pszTest == NULLTERM)
  388. {
  389. _splitpath(argv[0], NULL, NULL, szName, NULL);
  390. pszTest = szName;
  391. }
  392. // Here is where the WCHAR additions are
  393. if(FALSE == fIsUnicode)
  394. {
  395. ulLastError = SetInfo(NULL, pszTest, pszSubPath, pszObject);
  396. }
  397. else
  398. {
  399. // Convert the PCHARs to LPWSTRs
  400. // This one is guaranteed to be set to something
  401. LPWSTR wszTest = MbNameToWcs(pszTest);
  402. LPWSTR wszSubPath = MbNameToWcs(pszSubPath);
  403. LPWSTR wszObject = MbNameToWcs(pszObject);
  404. if(NO_ERROR == ulLastError)
  405. {
  406. ulLastError = SetInfo(NULL, wszTest, wszSubPath, wszObject);
  407. }
  408. delete wszTest;
  409. delete wszSubPath;
  410. delete wszObject;
  411. }
  412. }
  413. // This was not here before, but it seems the log should be opened by now
  414. if(NO_ERROR == ulLastError)
  415. {
  416. ulLastError = LogOpen() || (FALSE == fIsUnicode) ?
  417. WriteVar((PCHAR) NULL, LOG_START) :
  418. WriteVar((LPWSTR) NULL, LOG_START);
  419. }
  420. return ulLastError;
  421. }
  422. //+-------------------------------------------------------------------
  423. //
  424. // Member: Log::WriteVarList(PCHAR, USHORT, PCHAR, va_list)
  425. //
  426. // Synopsis: The WriteVar and WriteData methods allow the user to log
  427. // info in various forms.
  428. //
  429. // Arguments: [pszVar] - Variation
  430. // [usStat] - Status
  431. // [pszFormat] - Format string (like printf)
  432. // [vaArgs] - Data for pszStrFmt
  433. //
  434. // Returns: NO_ERROR if successful or ERROR_INVALID_DATA otherwise
  435. //
  436. // Modifies: ulLastError
  437. //
  438. // History: ??-???-?? ???????? Created
  439. // 17-Oct-91 SarahJ Added check for LOG_MAX_STATUS
  440. // 11-Jun-92 DonCl Added call to IncLogStats()
  441. // 3-Jul-92 DeanE Stolen from WriteVar method, renamed,
  442. // made to operate on va_lists.
  443. //
  444. //--------------------------------------------------------------------
  445. ULONG Log :: WriteVarList(PCHAR pszVar,
  446. USHORT usStat,
  447. PCHAR pszFormat,
  448. va_list vaArgs)
  449. {
  450. CHK_UNICODE(FALSE);
  451. #if defined(WIN32)
  452. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  453. #endif
  454. ulLastError = NO_ERROR;
  455. IncLogStats(_stLogStats, usStat);
  456. if(ulLastError == NO_ERROR)
  457. {
  458. if(fInfoSet)
  459. {
  460. // verify that the status is in allowed range
  461. if(usStat > LOG_MAX_STATUS)
  462. {
  463. LogPrintf(stderr,
  464. "ERROR: Illegal status parameter %u for "
  465. "Variation %s\n",
  466. usStat,
  467. pszVar);
  468. ulLastError = ERROR_INVALID_DATA;
  469. return ulLastError;
  470. }
  471. ulLastError =
  472. SetStrData(pszFormat, vaArgs) ||
  473. SetVariation((const char *)pszVar) ||
  474. SetStatus(aStatus[usStat]) ||
  475. SetBinData(0, (PVOID)NULL);
  476. if(ulLastError == NO_ERROR)
  477. {
  478. ulLastError = LogData(); // Send data to the log file
  479. }
  480. }
  481. else
  482. {
  483. ulLastError = ERROR_INVALID_DATA;
  484. }
  485. }
  486. return ulLastError;
  487. }
  488. //+-------------------------------------------------------------------
  489. //
  490. // Member: Log::WriteVarList(LPWSTR, USHORT, LPWSTR, va_list)
  491. //
  492. // Synopsis: The WriteVar and WriteData methods allow the user to log
  493. // info in various forms.
  494. //
  495. // Arguments: [wszVar] - Variation
  496. // [usStat] - Status
  497. // [wszFormat] - Format string (like printf)
  498. // [vaArgs] - Data for pszStrFmt
  499. //
  500. // Returns: NO_ERROR if successful or ERROR_INVALID_DATA otherwise
  501. //
  502. // Modifies: ulLastError
  503. //
  504. // History: ??-???-?? ???????? Created
  505. // 17-Oct-91 SarahJ Added check for LOG_MAX_STATUS
  506. // 11-Jun-92 DonCl Added call to IncLogStats()
  507. // 3-Jul-92 DeanE Stolen from WriteVar method, renamed,
  508. // made to operate on va_lists.
  509. //
  510. //--------------------------------------------------------------------
  511. ULONG Log :: WriteVarList(LPWSTR wszVar,
  512. USHORT usStat,
  513. LPWSTR wszFormat,
  514. va_list vaArgs)
  515. {
  516. CHK_UNICODE(TRUE);
  517. #if defined(WIN32)
  518. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  519. #endif
  520. ulLastError = NO_ERROR;
  521. IncLogStats(_stLogStats, usStat);
  522. if(ulLastError == NO_ERROR)
  523. {
  524. if(fInfoSet)
  525. {
  526. // verify that the status is in allowed range
  527. if(usStat > LOG_MAX_STATUS)
  528. {
  529. LogPrintf(stderr, L"ERROR: Illegal status parameter %u "
  530. L"for Variation %ls\n",
  531. usStat, wszVar);
  532. ulLastError = ERROR_INVALID_DATA;
  533. return ulLastError;
  534. }
  535. ulLastError = SetStrData(wszFormat, vaArgs)
  536. || SetVariation((LPCWSTR) wszVar)
  537. || SetStatus(waStatus[usStat])
  538. || SetBinData(0, (PVOID) NULL);
  539. if(ulLastError == NO_ERROR)
  540. {
  541. ulLastError = LogData(); // Send data to the log file
  542. }
  543. }
  544. else
  545. {
  546. ulLastError = ERROR_INVALID_DATA;
  547. }
  548. }
  549. return ulLastError;
  550. }
  551. //+-------------------------------------------------------------------
  552. //
  553. // Member: Log::WriteVar(PCHAR, USHORT, PCHAR, ...)
  554. //
  555. // Synopsis: The WriteVar and WriteData methods allow the user to log
  556. // info in various forms.
  557. //
  558. // Arguments: [pszVar] - Variation
  559. // [usStat] - Status
  560. // [pszFormat] - Format string (like printf)
  561. // [...] - Data for pszStrFmt
  562. //
  563. // Returns: NO_ERROR if successful or ERROR_INVALID_DATA otherwise
  564. //
  565. // Modifies: ulLastError
  566. //
  567. // History: ??-???-?? ???????? Created
  568. // 17-Oct-91 SarahJ Added check for LOG_MAX_STATUS
  569. // 11-Jun-92 DonCl Added call to IncLogStats()
  570. // 3-Jul-92 DeanE Modified to call WriteVarList
  571. //
  572. //--------------------------------------------------------------------
  573. ULONG Log :: WriteVar(PCHAR pszVar, USHORT usStat, PCHAR pszFormat, ...)
  574. {
  575. CHK_UNICODE(FALSE);
  576. va_list pMarker;
  577. if(pszFormat != NULL)
  578. {
  579. va_start(pMarker, pszFormat);
  580. }
  581. ulLastError = WriteVarList(pszVar, usStat, pszFormat, pMarker);
  582. if(pszFormat != NULL)
  583. {
  584. va_end(pMarker);
  585. }
  586. return ulLastError;
  587. }
  588. //+-------------------------------------------------------------------
  589. //
  590. // Member: Log::WriteVar(LPWSTR, USHORT, LPWSTR, ...)
  591. //
  592. // Synopsis: The WriteVar and WriteData methods allow the user to log
  593. // info in various forms.
  594. //
  595. // Arguments: [wszVar] - Variation
  596. // [usStat] - Status
  597. // [wszFormat] - Format string (like printf)
  598. // [...] - Data for pszStrFmt
  599. //
  600. // Returns: NO_ERROR if successful or ERROR_INVALID_DATA otherwise
  601. //
  602. // Modifies: ulLastError
  603. //
  604. // History: ??-???-?? ???????? Created
  605. // 17-Oct-91 SarahJ Added check for LOG_MAX_STATUS
  606. // 11-Jun-92 DonCl Added call to IncLogStats()
  607. // 3-Jul-92 DeanE Modified to call WriteVarList
  608. //
  609. //--------------------------------------------------------------------
  610. ULONG Log :: WriteVar(LPWSTR wszVar, USHORT usStat, LPWSTR wszFormat, ...)
  611. {
  612. CHK_UNICODE(TRUE);
  613. va_list pMarker;
  614. if(wszFormat != NULL)
  615. {
  616. va_start(pMarker, wszFormat);
  617. }
  618. ulLastError = WriteVarList(wszVar, usStat, wszFormat, pMarker);
  619. if(wszFormat != NULL)
  620. {
  621. va_end(pMarker);
  622. }
  623. return ulLastError;
  624. }
  625. //+-------------------------------------------------------------------
  626. //
  627. // Member: Log::WriteVarList(PCHAR, USHORT, USHORT, PVOID, PCHAR, va_list)
  628. //
  629. // Synopsis: Write data to the log file that contains binary data with
  630. // or without an accompanying string.
  631. //
  632. // Arguments: [pszVar] - Variation
  633. // [usStat] - Status code
  634. // [usBytes] - #bytes binary data
  635. // [pvData] - The binary data
  636. // [pszFormat] - printf style format
  637. // [vaArgs] - Data for pszStrFmt
  638. //
  639. // Returns:
  640. //
  641. // History: ??-???-?? ???????? Created
  642. // 11-Jun-92 DonCl Added call to IncLogStats()
  643. // 3-Jul-92 DeanE Stolen from WriteVar, renamed, supports
  644. // va_list type now.
  645. //
  646. //--------------------------------------------------------------------
  647. ULONG Log :: WriteVarList(PCHAR pszVar,
  648. USHORT usStat,
  649. USHORT usBytes,
  650. PVOID pvData,
  651. PCHAR pszFormat,
  652. va_list vaArgs )
  653. {
  654. CHK_UNICODE(FALSE);
  655. #if defined(WIN32)
  656. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  657. #endif
  658. ulLastError = NO_ERROR;
  659. IncLogStats(_stLogStats, usStat);
  660. if (ulLastError == NO_ERROR)
  661. {
  662. if (fInfoSet)
  663. {
  664. // verify that the status is in allowed range
  665. if (usStat > LOG_MAX_STATUS)
  666. {
  667. LogPrintf(stderr,
  668. "ERROR: Illegal status parameter %u for "
  669. "Variation %s\n",
  670. usStat,
  671. pszVar);
  672. ulLastError = ERROR_INVALID_DATA;
  673. return ulLastError;
  674. }
  675. // Note if pszFormat is NULL, SetStrData will ignore vaArgs
  676. ulLastError = SetStrData(pszFormat, vaArgs);
  677. if (ulLastError == NO_ERROR)
  678. {
  679. ulLastError = SetVariation((const char *) pszVar)
  680. || SetStatus(aStatus[usStat])
  681. || SetBinData(usBytes, pvData);
  682. if (ulLastError == NO_ERROR)
  683. {
  684. ulLastError = LogData(); // Send data to the log file
  685. }
  686. }
  687. }
  688. else
  689. {
  690. ulLastError = ERROR_INVALID_DATA;
  691. }
  692. }
  693. return ulLastError;
  694. }
  695. //+-------------------------------------------------------------------
  696. //
  697. // Member: Log::WriteVarList(LPWSTR, USHORT, USHORT, PVOID,
  698. // LPWSTR, va_list)
  699. //
  700. // Synopsis: Write data to the log file that contains binary data with
  701. // or without an accompanying string.
  702. //
  703. // Arguments: [wszVar] - Variation
  704. // [usStat] - Status code
  705. // [usBytes] - #bytes binary data
  706. // [pvData] - The binary data
  707. // [wszFormat] - printf style format
  708. // [vaArgs] - Data for pszStrFmt
  709. //
  710. // Returns:
  711. //
  712. // History: ??-???-?? ???????? Created
  713. // 11-Jun-92 DonCl Added call to IncLogStats()
  714. // 3-Jul-92 DeanE Stolen from WriteVar, renamed, supports
  715. // va_list type now.
  716. //
  717. //--------------------------------------------------------------------
  718. ULONG Log :: WriteVarList(LPWSTR wszVar,
  719. USHORT usStat,
  720. USHORT usBytes,
  721. PVOID pvData,
  722. LPWSTR wszFormat,
  723. va_list vaArgs )
  724. {
  725. CHK_UNICODE(TRUE);
  726. #if defined(WIN32)
  727. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  728. #endif
  729. ulLastError = NO_ERROR;
  730. IncLogStats(_stLogStats, usStat);
  731. if(ulLastError == NO_ERROR)
  732. {
  733. if(fInfoSet)
  734. {
  735. // verify that the status is in allowed range
  736. if(usStat > LOG_MAX_STATUS)
  737. {
  738. LogPrintf(stderr, L"ERROR: Illegal status parameter %u "
  739. L"for Variation %ls\n",
  740. usStat, wszVar);
  741. ulLastError = ERROR_INVALID_DATA;
  742. return ulLastError;
  743. }
  744. // Note if wszFormat is NULL, SetStrData will ignore vaArgs
  745. ulLastError = SetStrData(wszFormat, vaArgs);
  746. if(ulLastError == NO_ERROR)
  747. {
  748. ulLastError =
  749. SetVariation((LPCWSTR) wszVar) ||
  750. SetStatus(waStatus[usStat]) ||
  751. SetBinData(usBytes, pvData);
  752. if(ulLastError == NO_ERROR)
  753. {
  754. ulLastError = LogData(); // Send data to the log file
  755. }
  756. }
  757. }
  758. else
  759. {
  760. ulLastError = ERROR_INVALID_DATA;
  761. }
  762. }
  763. return ulLastError;
  764. }
  765. //+-------------------------------------------------------------------
  766. //
  767. // Member: Log::WriteVar(PCHAR, USHORT, USHORT, PVOID, PCHAR, ...)
  768. //
  769. // Synopsis: Write data to the log file that contains binary data with
  770. // or without an accompanying string.
  771. //
  772. // Arguments: [pszVar] - Variation
  773. // [usStat] - Status code
  774. // [usBytes] - #bytes binary data
  775. // [pvData] - The binary data
  776. // [pszFormat] - printf style format
  777. // [...] - Data for pszStrFmt
  778. //
  779. // Returns:
  780. //
  781. // History: ??-???-?? ???????? Created
  782. // 11-Jun-92 DonCl Added call to IncLogStats()
  783. // 3-Jul-92 DeanE Modified to call WriteVarList
  784. //
  785. //--------------------------------------------------------------------
  786. ULONG Log :: WriteVar(PCHAR pszVar,
  787. USHORT usStat,
  788. USHORT usBytes,
  789. PVOID pvData,
  790. PCHAR pszFormat,
  791. ... )
  792. {
  793. CHK_UNICODE(FALSE);
  794. va_list pMarker;
  795. if(pszFormat != NULL)
  796. {
  797. va_start(pMarker, pszFormat);
  798. }
  799. ulLastError = WriteVarList(pszVar,
  800. usStat,
  801. usBytes,
  802. pvData,
  803. pszFormat,
  804. pMarker);
  805. if(pszFormat != NULL)
  806. {
  807. va_end(pMarker);
  808. }
  809. return ulLastError;
  810. }
  811. //+-------------------------------------------------------------------
  812. //
  813. // Member: Log::WriteVar(LPWSTR, USHORT, USHORT, PVOID, LPWSTR, ...)
  814. //
  815. // Synopsis: Write data to the log file that contains binary data with
  816. // or without an accompanying string.
  817. //
  818. // Arguments: [wszVar] - Variation
  819. // [usStat] - Status code
  820. // [usBytes] - #bytes binary data
  821. // [pvData] - The binary data
  822. // [wszFormat] - printf style format
  823. // [...] - Data for pszStrFmt
  824. //
  825. // Returns:
  826. //
  827. // History: ??-???-?? ???????? Created
  828. // 11-Jun-92 DonCl Added call to IncLogStats()
  829. // 3-Jul-92 DeanE Modified to call WriteVarList
  830. //
  831. //--------------------------------------------------------------------
  832. ULONG Log :: WriteVar(LPWSTR wszVar,
  833. USHORT usStat,
  834. USHORT usBytes,
  835. PVOID pvData,
  836. LPWSTR wszFormat,
  837. ... )
  838. {
  839. CHK_UNICODE(TRUE);
  840. va_list pMarker;
  841. if(wszFormat != NULL)
  842. {
  843. va_start(pMarker, wszFormat);
  844. }
  845. ulLastError = WriteVarList(wszVar,
  846. usStat,
  847. usBytes,
  848. pvData,
  849. wszFormat,
  850. pMarker);
  851. if(wszFormat != NULL)
  852. {
  853. va_end(pMarker);
  854. }
  855. return ulLastError;
  856. }
  857. //+-------------------------------------------------------------------
  858. //
  859. // Member: Log::WriteDataList(PCHAR, va_list)
  860. //
  861. // Synopsis: Write a string to the Log file.
  862. //
  863. // Arguments: [pszFormat] - a printf-like format string
  864. // [vaArgs] - The data to print out.
  865. //
  866. // Returns: NO_ERROR if successful
  867. // ERROR_INVALID_DATA
  868. // Any error code from Log::SetStrData() or Log::LogData
  869. //
  870. // Modifies: ulLastError
  871. //
  872. // History: ??-???-?? ???????? Created
  873. // 3-Jul-92 DeanE Stolen from WriteData, renamed, made
  874. // to work on a va_list
  875. //
  876. //--------------------------------------------------------------------
  877. ULONG Log :: WriteDataList(PCHAR pszFormat, va_list vaArgs)
  878. {
  879. CHK_UNICODE(FALSE);
  880. #if defined(WIN32)
  881. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  882. #endif
  883. ulLastError = NO_ERROR;
  884. if (ulLastError == NO_ERROR)
  885. {
  886. if (fInfoSet)
  887. {
  888. // Note if pszFormat is NULL, SetStrData will ignore vaArgs
  889. ulLastError = SetStrData(pszFormat, vaArgs);
  890. if (ulLastError == NO_ERROR)
  891. {
  892. ulLastError = LogData(); // Send data to the log file
  893. }
  894. }
  895. else
  896. {
  897. ulLastError = ERROR_INVALID_DATA;
  898. }
  899. }
  900. return(ulLastError);
  901. }
  902. //+-------------------------------------------------------------------
  903. //
  904. // Member: Log::WriteDataList(LPWSTR, va_list)
  905. //
  906. // Synopsis: Write a string to the Log file.
  907. //
  908. // Arguments: [wszFormat] - a printf-like format string
  909. // [vaArgs] - The data to print out.
  910. //
  911. // Returns: NO_ERROR if successful
  912. // ERROR_INVALID_DATA
  913. // Any error code from Log::SetStrData() or Log::LogData
  914. //
  915. // Modifies: ulLastError
  916. //
  917. // History: ??-???-?? ???????? Created
  918. // 3-Jul-92 DeanE Stolen from WriteData, renamed, made
  919. // to work on a va_list
  920. //
  921. //--------------------------------------------------------------------
  922. ULONG Log :: WriteDataList(LPWSTR wszFormat, va_list vaArgs)
  923. {
  924. CHK_UNICODE(TRUE);
  925. #if defined(WIN32)
  926. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  927. #endif
  928. ulLastError = NO_ERROR;
  929. if(ulLastError == NO_ERROR)
  930. {
  931. if(fInfoSet)
  932. {
  933. // Note if wszFormat is NULL, SetStrData will ignore vaArgs
  934. ulLastError = SetStrData(wszFormat, vaArgs);
  935. if(ulLastError == NO_ERROR)
  936. {
  937. ulLastError = LogData(); // Send data to the log file
  938. }
  939. }
  940. else
  941. {
  942. ulLastError = ERROR_INVALID_DATA;
  943. }
  944. }
  945. return ulLastError;
  946. }
  947. //+-------------------------------------------------------------------
  948. //
  949. // Member: Log::WriteData(PCHAR, ...)
  950. //
  951. // Synopsis: Write a string to the Log file.
  952. //
  953. // Arguments: [pszFormat] - a printf-like format string
  954. // [...] - The data to print out.
  955. //
  956. // Returns: NO_ERROR if successful
  957. // ERROR_INVALID_DATA
  958. // Any error code from Log::SetStrData() or Log::LogData
  959. //
  960. // Modifies: ulLastError
  961. //
  962. // History: ??-???-?? ???????? Created
  963. // 3-Jul-92 DeanE Modified to call WriteDataList
  964. //
  965. //--------------------------------------------------------------------
  966. ULONG Log :: WriteData(PCHAR pszFormat, ...)
  967. {
  968. CHK_UNICODE(FALSE);
  969. va_list pMarker;
  970. if (pszFormat != NULL)
  971. {
  972. va_start(pMarker, pszFormat);
  973. }
  974. ulLastError = WriteDataList(pszFormat, pMarker);
  975. if (pszFormat != NULL)
  976. {
  977. va_end(pMarker);
  978. }
  979. return(ulLastError);
  980. }
  981. //+-------------------------------------------------------------------
  982. //
  983. // Member: Log::WriteData(LPWSTR, ...)
  984. //
  985. // Synopsis: Write a string to the Log file.
  986. //
  987. // Arguments: [wszFormat] - a printf-like format string
  988. // [...] - The data to print out.
  989. //
  990. // Returns: NO_ERROR if successful
  991. // ERROR_INVALID_DATA
  992. // Any error code from Log::SetStrData() or Log::LogData
  993. //
  994. // Modifies: ulLastError
  995. //
  996. // History: ??-???-?? ???????? Created
  997. // 3-Jul-92 DeanE Modified to call WriteDataList
  998. //
  999. //--------------------------------------------------------------------
  1000. ULONG Log :: WriteData(LPWSTR wszFormat, ...)
  1001. {
  1002. CHK_UNICODE(TRUE);
  1003. va_list pMarker;
  1004. if(wszFormat != NULL)
  1005. {
  1006. va_start(pMarker, wszFormat);
  1007. }
  1008. ulLastError = WriteDataList(wszFormat, pMarker);
  1009. if(wszFormat != NULL)
  1010. {
  1011. va_end(pMarker);
  1012. }
  1013. return ulLastError;
  1014. }
  1015. //+-------------------------------------------------------------------
  1016. //
  1017. // Member: Log::WriteDataList(USHORT, PVOID, PCHAR, va_list)
  1018. //
  1019. // Synopsis: Write data to the log file that contains binary data
  1020. // and possibly a string.
  1021. //
  1022. // Arguments: [usBytes] - #bytes binary data
  1023. // [pvData] - The binary data
  1024. // [pszFormat] - printf style format
  1025. // [vaArgs] - Data for pszStrFmt
  1026. //
  1027. // Returns: NO_ERROR If successful
  1028. // ERROR_INVALID_DATA
  1029. // Any error code from Log::SetSetData, Log::SetBinData, or
  1030. // Log::LogData
  1031. //
  1032. // Modifies: ulLastError
  1033. //
  1034. // History: ??-???-?? ???????? Created
  1035. // 3-Jul-92 DeanE Stolen from WriteData, renamed, made
  1036. // to support va_list
  1037. //
  1038. //--------------------------------------------------------------------
  1039. ULONG Log :: WriteDataList(USHORT usBytes,
  1040. PVOID pvData,
  1041. PCHAR pszFormat,
  1042. va_list vaArgs)
  1043. {
  1044. CHK_UNICODE(FALSE);
  1045. #if defined(WIN32)
  1046. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  1047. #endif
  1048. ulLastError = NO_ERROR;
  1049. if (ulLastError == NO_ERROR)
  1050. {
  1051. if (fInfoSet)
  1052. {
  1053. // Set up to log the string data
  1054. // Note if pszFormat is NULL, SetStrData will ignore vaArgs
  1055. ulLastError = SetStrData(pszFormat, vaArgs);
  1056. if (ulLastError == NO_ERROR)
  1057. {
  1058. // Set up to log the binary data
  1059. ulLastError = SetBinData(usBytes, pvData);
  1060. if (ulLastError == NO_ERROR)
  1061. {
  1062. ulLastError = LogData(); // Send data to the log file
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. ulLastError = ERROR_INVALID_DATA;
  1069. }
  1070. }
  1071. return(ulLastError);
  1072. }
  1073. //+-------------------------------------------------------------------
  1074. //
  1075. // Member: Log::WriteDataList(USHORT, PVOID, LPWSTR, va_list)
  1076. //
  1077. // Synopsis: Write data to the log file that contains binary data
  1078. // and possibly a string.
  1079. //
  1080. // Arguments: [usBytes] - #bytes binary data
  1081. // [pvData] - The binary data
  1082. // [wszFormat] - printf style format
  1083. // [vaArgs] - Data for pszStrFmt
  1084. //
  1085. // Returns: NO_ERROR If successful
  1086. // ERROR_INVALID_DATA
  1087. // Any error code from Log::SetSetData, Log::SetBinData, or
  1088. // Log::LogData
  1089. //
  1090. // Modifies: ulLastError
  1091. //
  1092. // History: ??-???-?? ???????? Created
  1093. // 3-Jul-92 DeanE Stolen from WriteData, renamed, made
  1094. // to support va_list
  1095. //
  1096. //--------------------------------------------------------------------
  1097. ULONG Log :: WriteDataList(USHORT usBytes,
  1098. PVOID pvData,
  1099. LPWSTR wszFormat,
  1100. va_list vaArgs)
  1101. {
  1102. CHK_UNICODE(TRUE);
  1103. #if defined(WIN32)
  1104. CTCLock clMemLock (hMtxSerialize); // Serialize access to this object
  1105. #endif
  1106. ulLastError = NO_ERROR;
  1107. if(ulLastError == NO_ERROR)
  1108. {
  1109. if(fInfoSet)
  1110. {
  1111. // Set up to log the string data
  1112. // Note if wszFormat is NULL, SetStrData will ignore vaArgs
  1113. ulLastError = SetStrData(wszFormat, vaArgs);
  1114. if(ulLastError == NO_ERROR)
  1115. {
  1116. // Set up to log the binary data
  1117. ulLastError = SetBinData(usBytes, pvData);
  1118. if(ulLastError == NO_ERROR)
  1119. {
  1120. ulLastError = LogData(); // Send data to the log file
  1121. }
  1122. }
  1123. }
  1124. else
  1125. {
  1126. ulLastError = ERROR_INVALID_DATA;
  1127. }
  1128. }
  1129. return ulLastError;
  1130. }
  1131. //+-------------------------------------------------------------------
  1132. //
  1133. // Member: Log::WriteData(USHORT, PVOID, PCHAR, ...)
  1134. //
  1135. // Synopsis: Write data to the log file that contains binary data
  1136. // and possibly a string.
  1137. //
  1138. // Arguments: [usBytes] - #bytes binary data
  1139. // [pvData] - The binary data
  1140. // [pszFormat] - printf style format
  1141. // [...] - Data for pszStrFmt
  1142. //
  1143. // Returns: NO_ERROR If successful
  1144. // ERROR_INVALID_DATA
  1145. // Any error code from Log::SetSetData, Log::SetBinData, or
  1146. // Log::LogData
  1147. //
  1148. // Modifies: ulLastError
  1149. //
  1150. // History: ??-???-?? ???????? Created
  1151. // 3-Jul-92 DeanE Modified to call WriteDataList
  1152. //
  1153. //--------------------------------------------------------------------
  1154. ULONG Log :: WriteData(USHORT usBytes, PVOID pvData, PCHAR pszFormat, ...)
  1155. {
  1156. CHK_UNICODE(FALSE);
  1157. va_list pMarker;
  1158. if (pszFormat != NULL)
  1159. {
  1160. va_start(pMarker, pszFormat);
  1161. }
  1162. ulLastError = WriteDataList(usBytes, pvData, pszFormat, pMarker);
  1163. if (pszFormat != NULL)
  1164. {
  1165. va_end(pMarker);
  1166. }
  1167. return(ulLastError);
  1168. }
  1169. //+-------------------------------------------------------------------
  1170. //
  1171. // Member: Log::WriteData(USHORT, PVOID, LPWSTR, ...)
  1172. //
  1173. // Synopsis: Write data to the log file that contains binary data
  1174. // and possibly a string.
  1175. //
  1176. // Arguments: [usBytes] - #bytes binary data
  1177. // [pvData] - The binary data
  1178. // [wszFormat] - printf style format
  1179. // [...] - Data for pszStrFmt
  1180. //
  1181. // Returns: NO_ERROR If successful
  1182. // ERROR_INVALID_DATA
  1183. // Any error code from Log::SetSetData, Log::SetBinData, or
  1184. // Log::LogData
  1185. //
  1186. // Modifies: ulLastError
  1187. //
  1188. // History: ??-???-?? ???????? Created
  1189. // 3-Jul-92 DeanE Modified to call WriteDataList
  1190. //
  1191. //--------------------------------------------------------------------
  1192. ULONG Log :: WriteData(USHORT usBytes, PVOID pvData, LPWSTR wszFormat, ...)
  1193. {
  1194. CHK_UNICODE(TRUE);
  1195. va_list pMarker;
  1196. if(wszFormat != NULL)
  1197. {
  1198. va_start(pMarker, wszFormat);
  1199. }
  1200. ulLastError = WriteDataList(usBytes, pvData, wszFormat, pMarker);
  1201. if(wszFormat != NULL)
  1202. {
  1203. va_end(pMarker);
  1204. }
  1205. return ulLastError;
  1206. }
  1207. //+----------------------------------------------------------------------------
  1208. //
  1209. // Member: Log::GetLogStats(), public
  1210. //
  1211. // Synopsis: returns _stLogStats structure inside log object
  1212. //
  1213. // Effects: Returns actual reference to the real thing.
  1214. //
  1215. // Arguments: [out] LogStats& stStats - structure to fill in.
  1216. //
  1217. // Returns: nothing, except stStats now is value of structure.
  1218. //
  1219. // Modifies: stStats
  1220. //
  1221. // History: 11 Jun 92 DonCl first version
  1222. //
  1223. // Notes:
  1224. //
  1225. //-----------------------------------------------------------------------------
  1226. VOID Log::GetLogStats(LogStats& stStats)
  1227. {
  1228. stStats = _stLogStats;
  1229. }
  1230. //+-------------------------------------------------------------------
  1231. //
  1232. // Function: MbNametoWcs(PCHAR *)
  1233. //
  1234. // Synopsis: Given a pointer to a CHAR string, return a WCHAR copy
  1235. //
  1236. // Arguments: [pszName] CHAR string to copy
  1237. //
  1238. // Returns: <nothing>
  1239. //
  1240. // History: ??-???-?? ???????? Created
  1241. //
  1242. //--------------------------------------------------------------------
  1243. LPWSTR Log :: MbNameToWcs(PCHAR pszName)
  1244. {
  1245. LPWSTR wszName = NULL;
  1246. if(pszName != NULL)
  1247. {
  1248. size_t sizLen = strlen(pszName);
  1249. if((wszName = new WCHAR[sizLen + 1]) == NULL)
  1250. {
  1251. ulLastError = ERROR_NOT_ENOUGH_MEMORY;
  1252. }
  1253. else
  1254. {
  1255. if (mbstowcs(wszName, pszName, sizLen) == (size_t)0)
  1256. {
  1257. delete[] wszName;
  1258. ulLastError = ERROR_INVALID_DATA;
  1259. }
  1260. wszName[sizLen] = wNULLTERM;
  1261. }
  1262. }
  1263. return wszName;
  1264. }