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.

876 lines
25 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: NT Event logging
  6. File: Eventlog.cpp
  7. Owner: Jhittle
  8. This file contains general event logging routines for Denali.
  9. ===================================================================*/
  10. #include "denpre.h"
  11. #pragma hdrstop
  12. #include <direct.h>
  13. #include <iismsg.h>
  14. #include "memchk.h"
  15. extern HINSTANCE g_hinstDLL;
  16. extern CRITICAL_SECTION g_csEventlogLock;
  17. /*===================================================================
  18. STDAPI UnRegisterEventLog( void )
  19. UnRegister the event log.
  20. Returns:
  21. HRESULT S_OK or E_FAIL
  22. Side effects:
  23. Removes denali NT eventlog entries from the registry
  24. ===================================================================*/
  25. STDAPI UnRegisterEventLog( void )
  26. {
  27. HKEY hkey = NULL;
  28. DWORD iKey;
  29. CHAR szKeyName[255];
  30. DWORD cbKeyName;
  31. static const char szDenaliKey[] = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\Active Server Pages";
  32. // Open the HKEY_CLASSES_ROOT\CLSID\{...} key so we can delete its subkeys
  33. if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, szDenaliKey, 0, KEY_READ | KEY_WRITE, &hkey) != ERROR_SUCCESS)
  34. goto LErrExit;
  35. // Enumerate all its subkeys, and delete them
  36. for (iKey=0;;iKey++)
  37. {
  38. cbKeyName = sizeof(szKeyName);
  39. if (RegEnumKeyExA(hkey, iKey, szKeyName, &cbKeyName, 0, NULL, 0, NULL) != ERROR_SUCCESS)
  40. break;
  41. if (RegDeleteKeyA(hkey, szKeyName) != ERROR_SUCCESS)
  42. goto LErrExit;
  43. }
  44. // Close the key, and then delete it
  45. if (RegCloseKey(hkey) != ERROR_SUCCESS)
  46. return E_FAIL;
  47. if (RegDeleteKeyA(HKEY_LOCAL_MACHINE, szDenaliKey) != ERROR_SUCCESS)
  48. return E_FAIL;
  49. return S_OK;
  50. LErrExit:
  51. RegCloseKey(hkey);
  52. return E_FAIL;
  53. }
  54. /*===================================================================
  55. STDAPI RegisterEventLog(void)
  56. Register the NT event log.
  57. Returns:
  58. HRESULT S_OK or E_FAIL
  59. Side effects:
  60. Sets up denali dll in the Eventlog registry for resolution of
  61. NT eventlog message strings
  62. ===================================================================*/
  63. STDAPI RegisterEventLog( void )
  64. {
  65. HKEY hk; // registry key handle
  66. DWORD dwData;
  67. BOOL bSuccess;
  68. //char szMsgDLL[MAX_PATH];
  69. char szPath[MAX_PATH];
  70. char *pch;
  71. // Get the path and name of Denali
  72. if (!GetModuleFileNameA(g_hinstDLL, szPath, sizeof(szPath)/sizeof(char)))
  73. return E_FAIL;
  74. // BUG FIX: 102010 DBCS code changes
  75. //
  76. //for (pch = szPath + lstrlen(szPath); pch > szPath && *pch != TEXT('\\'); pch--)
  77. // ;
  78. //
  79. //if (pch == szPath)
  80. // return E_FAIL;
  81. pch = (char*) _mbsrchr((const unsigned char*)szPath, '\\');
  82. if (pch == NULL)
  83. return E_FAIL;
  84. strcpy(pch + 1, IIS_RESOURCE_DLL_NAME_A);
  85. // When an application uses the RegisterEventSource or OpenEventLog
  86. // function to get a handle of an event log, the event loggging service
  87. // searches for the specified source name in the registry. You can add a
  88. // new source name to the registry by opening a new registry subkey
  89. // under the Application key and adding registry values to the new
  90. // subkey.
  91. // Create a new key for our application
  92. bSuccess = RegCreateKeyA(HKEY_LOCAL_MACHINE,
  93. "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\Active Server Pages", &hk);
  94. if(bSuccess != ERROR_SUCCESS)
  95. return E_FAIL;
  96. // Add the Event-ID message-file name to the subkey.
  97. bSuccess = RegSetValueExA(hk, // subkey handle
  98. "EventMessageFile", // value name
  99. 0, // must be zero
  100. REG_EXPAND_SZ, // value type
  101. (LPBYTE) szPath, // address of value data
  102. strlen(szPath) + 1); // length of value data
  103. if(bSuccess != ERROR_SUCCESS)
  104. goto LT_ERROR;
  105. // Set the supported types flags and addit to the subkey.
  106. dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
  107. bSuccess = RegSetValueExA(hk, // subkey handle
  108. "TypesSupported", // value name
  109. 0, // must be zero
  110. REG_DWORD, // value type
  111. (LPBYTE) &dwData, // address of value data
  112. sizeof(DWORD)); // length of value data
  113. if(bSuccess != ERROR_SUCCESS)
  114. goto LT_ERROR;
  115. RegCloseKey(hk);
  116. return S_OK;
  117. LT_ERROR:
  118. RegCloseKey(hk);
  119. return E_FAIL;
  120. }
  121. /*===================================================================
  122. STDAPI ReportAnEvent
  123. Register report an event to the NT event log
  124. INPUT:
  125. the event ID to report in the log, the number of insert
  126. strings, and an array of null-terminated insert strings
  127. Returns:
  128. HRESULT S_OK or E_FAIL
  129. Side effects:
  130. Addes an entry in the NT event log
  131. ===================================================================*/
  132. STDAPI ReportAnEvent(DWORD dwIdEvent, WORD wEventlog_Type, WORD cStrings, LPCSTR *pszStrings,
  133. DWORD dwBinDataSize, LPVOID pData)
  134. {
  135. HANDLE hAppLog;
  136. BOOL bSuccess;
  137. HRESULT hr = S_OK;
  138. HANDLE hCurrentUser = INVALID_HANDLE_VALUE;
  139. AspDoRevertHack( &hCurrentUser );
  140. // Get a handle to the Application event log
  141. hAppLog = RegisterEventSourceA(NULL, // use local machine
  142. "Active Server Pages"); // source name
  143. if(hAppLog == NULL) {
  144. hr = E_FAIL;
  145. goto LExit;
  146. }
  147. // Now report the event, which will add this event to the event log
  148. bSuccess = ReportEventA(hAppLog, // event-log handle
  149. wEventlog_Type, // event type
  150. 0, // category zero
  151. dwIdEvent, // event ID
  152. NULL, // no user SID
  153. cStrings, // number of substitution strings
  154. dwBinDataSize, // binary data
  155. pszStrings, // string array
  156. dwBinDataSize ? pData : NULL); // address of data
  157. if(!bSuccess)
  158. hr = E_FAIL;
  159. DeregisterEventSource(hAppLog);
  160. LExit:
  161. AspUndoRevertHack( &hCurrentUser );
  162. return hr;
  163. }
  164. /*===================================================================
  165. STDAPI ReportAnEvent
  166. Register report an event to the NT event log
  167. INPUT:
  168. the event ID to report in the log, the number of insert
  169. strings, and an array of null-terminated insert strings
  170. Returns:
  171. HRESULT S_OK or E_FAIL
  172. Side effects:
  173. Addes an entry in the NT event log
  174. ===================================================================*/
  175. STDAPI ReportAnEventW(DWORD dwIdEvent, WORD wEventlog_Type, WORD cStrings, LPCWSTR *pszStrings)
  176. {
  177. HANDLE hAppLog;
  178. BOOL bSuccess;
  179. HRESULT hr = S_OK;
  180. HANDLE hCurrentUser = INVALID_HANDLE_VALUE;
  181. AspDoRevertHack( &hCurrentUser );
  182. // Get a handle to the Application event log
  183. hAppLog = RegisterEventSourceW(NULL, // use local machine
  184. L"Active Server Pages"); // source name
  185. if(hAppLog == NULL) {
  186. hr = E_FAIL;
  187. goto LExit;
  188. }
  189. // Now report the event, which will add this event to the event log
  190. bSuccess = ReportEventW(hAppLog, // event-log handle
  191. wEventlog_Type, // event type
  192. 0, // category zero
  193. dwIdEvent, // event ID
  194. NULL, // no user SID
  195. cStrings, // number of substitution strings
  196. 0, // no binary data
  197. pszStrings, // string array
  198. NULL); // address of data
  199. if(!bSuccess)
  200. hr = E_FAIL;
  201. DeregisterEventSource(hAppLog);
  202. LExit:
  203. AspUndoRevertHack( &hCurrentUser );
  204. return hr;
  205. }
  206. /*===================================================================
  207. void MSG_Error
  208. report an event to the NT event log
  209. INPUT:
  210. ptr to null-terminated string
  211. Returns:
  212. None
  213. Side effects:
  214. Addes an entry in the NT event log
  215. ===================================================================*/
  216. void MSG_Error( LPCSTR strSource )
  217. {
  218. static char szLastError[MAX_MSG_LENGTH] = {0};
  219. EnterCriticalSection(&g_csEventlogLock);
  220. if (strcmp(strSource, szLastError) == 0)
  221. {
  222. LeaveCriticalSection(&g_csEventlogLock);
  223. return;
  224. }
  225. strncpy(szLastError,strSource, MAX_MSG_LENGTH);
  226. szLastError[MAX_MSG_LENGTH-1] = '\0';
  227. LeaveCriticalSection(&g_csEventlogLock);
  228. ReportAnEvent( (DWORD) MSG_DENALI_ERROR_1, (WORD) EVENTLOG_ERROR_TYPE, (WORD) 1, &strSource /*aInsertStrs*/ );
  229. }
  230. /*===================================================================
  231. void MSG_Error
  232. report an event to the NT event log
  233. INPUT:
  234. string table string ID
  235. Returns:
  236. None
  237. Side effects:
  238. Addes an entry in the NT event log
  239. ===================================================================*/
  240. void MSG_Error( UINT SourceID1 )
  241. {
  242. static unsigned int nLastSourceID1 = 0;
  243. // if this is a repeat of the last reported message then return
  244. /// without posting an error.
  245. EnterCriticalSection(&g_csEventlogLock);
  246. if (SourceID1 == nLastSourceID1)
  247. {
  248. LeaveCriticalSection(&g_csEventlogLock);
  249. return;
  250. }
  251. nLastSourceID1 = SourceID1;
  252. LeaveCriticalSection(&g_csEventlogLock);
  253. DWORD cch;
  254. char strSource[MAX_MSG_LENGTH];
  255. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  256. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  257. Assert(cch > 0);
  258. aInsertStrs[0] = (char*) strSource;
  259. ReportAnEvent( (DWORD) MSG_DENALI_ERROR_1, (WORD) EVENTLOG_ERROR_TYPE, (WORD) 1, (LPCSTR *) aInsertStrs );
  260. return;
  261. }
  262. /*===================================================================
  263. void MSG_Error
  264. report an event to the NT event log
  265. INPUT:
  266. string table string ID
  267. Returns:
  268. None
  269. Side effects:
  270. Addes an entry in the NT event log
  271. ===================================================================*/
  272. void MSG_Error( UINT SourceID1, PCSTR pszSource2, UINT SourceID3, DWORD dwData )
  273. {
  274. static unsigned int nLastSourceID1 = 0;
  275. static char szLastSource2[MAX_MSG_LENGTH] = {0};
  276. static unsigned int nLastSourceID3 = 0;
  277. // if this is a repeat of the last reported message then return
  278. /// without posting an error.
  279. EnterCriticalSection(&g_csEventlogLock);
  280. if ((SourceID1 == nLastSourceID1) &&
  281. (strcmp(pszSource2, szLastSource2) == 0) &&
  282. (SourceID3 == nLastSourceID3))
  283. {
  284. LeaveCriticalSection(&g_csEventlogLock);
  285. return;
  286. }
  287. nLastSourceID1 = SourceID1;
  288. strncpy(szLastSource2,pszSource2, MAX_MSG_LENGTH);
  289. szLastSource2[MAX_MSG_LENGTH-1] = '\0';
  290. nLastSourceID3 = SourceID3;
  291. LeaveCriticalSection(&g_csEventlogLock);
  292. // load the strings
  293. DWORD cch;
  294. char strSource1[MAX_MSG_LENGTH];
  295. cch = CchLoadStringOfId(SourceID1, strSource1, MAX_MSG_LENGTH);
  296. Assert(cch > 0);
  297. char strSource3[MAX_MSG_LENGTH];
  298. cch = CchLoadStringOfId(SourceID3, strSource3, MAX_MSG_LENGTH);
  299. Assert(cch > 0);
  300. // construct the msg
  301. char strSource[MAX_MSG_LENGTH];
  302. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  303. WORD numStrs = 1;
  304. aInsertStrs[0] = (char*) strSource;
  305. if (_snprintf(strSource, MAX_MSG_LENGTH, strSource1, pszSource2, strSource3) <= 0)
  306. {
  307. // the string is too long. this should never happen, and we have the assert here,
  308. // but if we got to this point in production, at least we get an unformated log entry
  309. Assert(0);
  310. numStrs = 3;
  311. aInsertStrs[0] = strSource1;
  312. aInsertStrs[1] = (char*)pszSource2;
  313. aInsertStrs[2] = strSource3;
  314. }
  315. strSource[MAX_MSG_LENGTH-1] = '\0';
  316. ReportAnEvent( (DWORD) (numStrs == 1 ? MSG_DENALI_ERROR_1 : MSG_DENALI_ERROR_3),
  317. (WORD) EVENTLOG_ERROR_TYPE,
  318. numStrs,
  319. (LPCSTR *) aInsertStrs,
  320. dwData ? sizeof(dwData) : 0,
  321. dwData ? &dwData : NULL );
  322. return;
  323. }
  324. /*===================================================================
  325. void MSG_Error
  326. report an event to the NT event log
  327. INPUT:
  328. two part message of string table string ID's
  329. Returns:
  330. None
  331. Side effects:
  332. Addes an entry in the NT event log
  333. ===================================================================*/
  334. void MSG_Error( UINT SourceID1, UINT SourceID2 )
  335. {
  336. static unsigned int nLastSourceID1 = 0;
  337. static unsigned int nLastSourceID2 = 0;
  338. // if this is a repeat of the last reported message then return
  339. // without posting an error.
  340. EnterCriticalSection(&g_csEventlogLock);
  341. if (SourceID1 == nLastSourceID1 && SourceID2 == nLastSourceID2)
  342. {
  343. LeaveCriticalSection(&g_csEventlogLock);
  344. return;
  345. }
  346. nLastSourceID1 = SourceID1;
  347. nLastSourceID2 = SourceID2;
  348. LeaveCriticalSection(&g_csEventlogLock);
  349. DWORD cch;
  350. char strSource[MAX_MSG_LENGTH];
  351. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  352. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  353. Assert(cch > 0);
  354. aInsertStrs[0] = (char*) strSource;
  355. cch = CchLoadStringOfId(SourceID2, strSource, MAX_MSG_LENGTH);
  356. Assert(cch > 0);
  357. aInsertStrs[1] = (char*) strSource;
  358. ReportAnEvent( (DWORD) MSG_DENALI_ERROR_2, (WORD) EVENTLOG_ERROR_TYPE, (WORD) 2, (LPCSTR *) aInsertStrs );
  359. return;
  360. }
  361. /*===================================================================
  362. void MSG_Error
  363. report an event to the NT event log
  364. INPUT:
  365. three part message string
  366. Returns:
  367. None
  368. Side effects:
  369. Addes an entry in the NT event log
  370. ===================================================================*/
  371. void MSG_Error( UINT SourceID1, UINT SourceID2, UINT SourceID3 )
  372. {
  373. static unsigned int nLastSourceID1 = 0;
  374. static unsigned int nLastSourceID2 = 0;
  375. static unsigned int nLastSourceID3 = 0;
  376. // if this is a repeat of the last reported message then return
  377. /// without posting an error.
  378. EnterCriticalSection(&g_csEventlogLock);
  379. if (SourceID1 == nLastSourceID1 && SourceID2 == nLastSourceID2 && SourceID3 == nLastSourceID3)
  380. {
  381. LeaveCriticalSection(&g_csEventlogLock);
  382. return;
  383. }
  384. nLastSourceID1 = SourceID1;
  385. nLastSourceID2 = SourceID2;
  386. nLastSourceID3 = SourceID3;
  387. LeaveCriticalSection(&g_csEventlogLock);
  388. DWORD cch;
  389. char strSource[MAX_MSG_LENGTH];
  390. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  391. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  392. Assert(cch > 0);
  393. aInsertStrs[0] = (char*) strSource;
  394. cch = CchLoadStringOfId(SourceID2, strSource, MAX_MSG_LENGTH);
  395. Assert(cch > 0);
  396. aInsertStrs[1] = (char*) strSource;
  397. cch = CchLoadStringOfId(SourceID3, strSource, MAX_MSG_LENGTH);
  398. Assert(cch > 0);
  399. aInsertStrs[2] = (char*) strSource;
  400. ReportAnEvent( (DWORD) MSG_DENALI_ERROR_3, (WORD) EVENTLOG_ERROR_TYPE, (WORD) 3, (LPCSTR *) aInsertStrs );
  401. return;
  402. }
  403. /*===================================================================
  404. void MSG_Error
  405. report an event to the NT event log
  406. INPUT:
  407. four String table ID's
  408. Returns:
  409. None
  410. Side effects:
  411. Addes an entry in the NT event log
  412. ===================================================================*/
  413. void MSG_Error( UINT SourceID1, UINT SourceID2, UINT SourceID3, UINT SourceID4 )
  414. {
  415. static unsigned int nLastSourceID1 = 0;
  416. static unsigned int nLastSourceID2 = 0;
  417. static unsigned int nLastSourceID3 = 0;
  418. static unsigned int nLastSourceID4 = 0;
  419. // if this is a repeat of the last reported message then return
  420. /// without posting an error.
  421. EnterCriticalSection(&g_csEventlogLock);
  422. if (SourceID1 == nLastSourceID1 && SourceID2 == nLastSourceID2 && SourceID3 == nLastSourceID3 && SourceID4 == nLastSourceID4)
  423. {
  424. LeaveCriticalSection(&g_csEventlogLock);
  425. return;
  426. }
  427. nLastSourceID1 = SourceID1;
  428. nLastSourceID2 = SourceID2;
  429. nLastSourceID3 = SourceID3;
  430. nLastSourceID4 = SourceID4;
  431. LeaveCriticalSection(&g_csEventlogLock);
  432. DWORD cch;
  433. char strSource[MAX_MSG_LENGTH];
  434. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  435. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  436. Assert(cch > 0);
  437. aInsertStrs[0] = (char*) strSource;
  438. cch = CchLoadStringOfId(SourceID2, strSource, MAX_MSG_LENGTH);
  439. Assert(cch > 0);
  440. aInsertStrs[1] = (char*) strSource;
  441. cch = CchLoadStringOfId(SourceID3, strSource, MAX_MSG_LENGTH);
  442. Assert(cch > 0);
  443. aInsertStrs[2] = (char*) strSource;
  444. cch = CchLoadStringOfId(SourceID4, strSource, MAX_MSG_LENGTH);
  445. Assert(cch > 0);
  446. aInsertStrs[3] = (char*) strSource;
  447. ReportAnEvent( (DWORD) MSG_DENALI_ERROR_4, (WORD) EVENTLOG_ERROR_TYPE, (WORD) 4, (LPCSTR *) aInsertStrs );
  448. return;
  449. }
  450. /*===================================================================
  451. void MSG_Error
  452. report an event to the NT event log
  453. INPUT:
  454. ErrId - ID of error description in Message File
  455. cItem - count of strings in szItems array
  456. szItems - array of string points
  457. Returns:
  458. None
  459. Side effects:
  460. Addes an entry in the NT event log
  461. ===================================================================*/
  462. void MSG_Error( DWORD ErrId, LPCWSTR pwszItem )
  463. {
  464. static unsigned int LastErrId = 0;
  465. static WCHAR szLastStr[MAX_MSG_LENGTH] = {0};
  466. // if this is a repeat of the last reported message then return
  467. /// without posting an error.
  468. EnterCriticalSection(&g_csEventlogLock);
  469. if ((ErrId == LastErrId) && !wcscmp(szLastStr, pwszItem))
  470. {
  471. LeaveCriticalSection(&g_csEventlogLock);
  472. return;
  473. }
  474. LastErrId = ErrId;
  475. wcsncpy(szLastStr, pwszItem, MAX_MSG_LENGTH);
  476. szLastStr[MAX_MSG_LENGTH-1] = L'\0';
  477. LeaveCriticalSection(&g_csEventlogLock);
  478. ReportAnEventW( ErrId, (WORD) EVENTLOG_ERROR_TYPE, 1, &pwszItem );
  479. }
  480. /*===================================================================
  481. void MSG_Warning
  482. report an event to the NT event log
  483. INPUT:
  484. ptr to null-terminated string
  485. Returns:
  486. None
  487. Side effects:
  488. Addes an entry in the NT event log
  489. ===================================================================*/
  490. void MSG_Warning( LPCSTR strSource )
  491. {
  492. static char szLastError[MAX_MSG_LENGTH] = {0};
  493. EnterCriticalSection(&g_csEventlogLock);
  494. if (strcmp(strSource, szLastError) == 0)
  495. {
  496. LeaveCriticalSection(&g_csEventlogLock);
  497. return;
  498. }
  499. szLastError[0] = '\0';
  500. strncat(szLastError,strSource, MAX_MSG_LENGTH-1);
  501. LeaveCriticalSection(&g_csEventlogLock);
  502. ReportAnEvent( (DWORD) MSG_DENALI_WARNING_1, (WORD) EVENTLOG_WARNING_TYPE, (WORD) 1, &strSource /*aInsertStrs*/ );
  503. }
  504. /*===================================================================
  505. void MSG_Warning
  506. report an event to the NT event log
  507. INPUT:
  508. String table message ID
  509. Returns:
  510. None
  511. Side effects:
  512. Addes an entry in the NT event log
  513. ===================================================================*/
  514. void MSG_Warning( UINT SourceID1 )
  515. {
  516. static unsigned int nLastSourceID1 = 0;
  517. // if this is a repeat of the last reported message then return
  518. /// without posting an error.
  519. EnterCriticalSection(&g_csEventlogLock);
  520. if (SourceID1 == nLastSourceID1)
  521. {
  522. LeaveCriticalSection(&g_csEventlogLock);
  523. return;
  524. }
  525. nLastSourceID1 = SourceID1;
  526. LeaveCriticalSection(&g_csEventlogLock);
  527. DWORD cch;
  528. char strSource[MAX_MSG_LENGTH];
  529. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  530. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  531. Assert(cch > 0);
  532. aInsertStrs[0] = (char*) strSource;
  533. ReportAnEvent( (DWORD) MSG_DENALI_WARNING_1, (WORD) EVENTLOG_WARNING_TYPE, (WORD) 1, (LPCSTR *) aInsertStrs );
  534. return;
  535. }
  536. /*===================================================================
  537. void MSG_Warning
  538. report an event to the NT event log
  539. INPUT:
  540. two string tabel message ID's
  541. Returns:
  542. None
  543. Side effects:
  544. Addes an entry in the NT event log
  545. ===================================================================*/
  546. void MSG_Warning( UINT SourceID1, UINT SourceID2 )
  547. {
  548. static unsigned int nLastSourceID1 = 0;
  549. static unsigned int nLastSourceID2 = 0;
  550. // if this is a repeat of the last reported message then return
  551. /// without posting an error.
  552. EnterCriticalSection(&g_csEventlogLock);
  553. if (SourceID1 == nLastSourceID1 && SourceID2 == nLastSourceID2)
  554. {
  555. LeaveCriticalSection(&g_csEventlogLock);
  556. return;
  557. }
  558. nLastSourceID1 = SourceID1;
  559. nLastSourceID2 = SourceID2;
  560. LeaveCriticalSection(&g_csEventlogLock);
  561. DWORD cch;
  562. char strSource[MAX_MSG_LENGTH];
  563. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  564. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  565. Assert(cch > 0);
  566. aInsertStrs[0] = (char*) strSource;
  567. cch = CchLoadStringOfId(SourceID2, strSource, MAX_MSG_LENGTH);
  568. Assert(cch > 0);
  569. aInsertStrs[1] = (char*) strSource;
  570. ReportAnEvent( (DWORD) MSG_DENALI_WARNING_2, (WORD) EVENTLOG_WARNING_TYPE, (WORD) 2, (LPCSTR *) aInsertStrs );
  571. return;
  572. }
  573. /*===================================================================
  574. void MSG_Warning
  575. report an event to the NT event log
  576. INPUT:
  577. three string table message ID's
  578. Returns:
  579. None
  580. Side effects:
  581. Addes an entry in the NT event log
  582. ===================================================================*/
  583. void MSG_Warning( UINT SourceID1, UINT SourceID2, UINT SourceID3)
  584. {
  585. static unsigned int nLastSourceID1 = 0;
  586. static unsigned int nLastSourceID2 = 0;
  587. static unsigned int nLastSourceID3 = 0;
  588. // if this is a repeat of the last reported message then return
  589. /// without posting an error.
  590. EnterCriticalSection(&g_csEventlogLock);
  591. if (SourceID1 == nLastSourceID1 && SourceID2 == nLastSourceID2 && SourceID3 == nLastSourceID3)
  592. {
  593. LeaveCriticalSection(&g_csEventlogLock);
  594. return;
  595. }
  596. nLastSourceID1 = SourceID1;
  597. nLastSourceID2 = SourceID2;
  598. nLastSourceID3 = SourceID3;
  599. LeaveCriticalSection(&g_csEventlogLock);
  600. DWORD cch;
  601. char strSource[MAX_MSG_LENGTH];
  602. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  603. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  604. Assert(cch > 0);
  605. aInsertStrs[0] = (char*) strSource;
  606. cch = CchLoadStringOfId(SourceID2, strSource, MAX_MSG_LENGTH);
  607. Assert(cch > 0);
  608. aInsertStrs[1] = (char*) strSource;
  609. cch = CchLoadStringOfId(SourceID3, strSource, MAX_MSG_LENGTH);
  610. Assert(cch > 0);
  611. aInsertStrs[2] = (char*) strSource;
  612. ReportAnEvent( (DWORD) MSG_DENALI_WARNING_3, (WORD) EVENTLOG_WARNING_TYPE, (WORD) 3, (LPCSTR *) aInsertStrs );
  613. return;
  614. }
  615. /*===================================================================
  616. void MSG_Warning
  617. report an event to the NT event log
  618. INPUT:
  619. four String table message ID's
  620. Returns:
  621. None
  622. Side effects:
  623. Addes an entry in the NT event log
  624. ===================================================================*/
  625. void MSG_Warning( UINT SourceID1, UINT SourceID2, UINT SourceID3, UINT SourceID4 )
  626. {
  627. static unsigned int nLastSourceID1 = 0;
  628. static unsigned int nLastSourceID2 = 0;
  629. static unsigned int nLastSourceID3 = 0;
  630. static unsigned int nLastSourceID4 = 0;
  631. // if this is a repeat of the last reported message then return
  632. /// without posting an error.
  633. EnterCriticalSection(&g_csEventlogLock);
  634. if (SourceID1 == nLastSourceID1 && SourceID2 == nLastSourceID2 && SourceID3 == nLastSourceID3 && SourceID4 == nLastSourceID4)
  635. {
  636. LeaveCriticalSection(&g_csEventlogLock);
  637. return;
  638. }
  639. nLastSourceID1 = SourceID1;
  640. nLastSourceID2 = SourceID2;
  641. nLastSourceID3 = SourceID3;
  642. nLastSourceID4 = SourceID4;
  643. LeaveCriticalSection(&g_csEventlogLock);
  644. DWORD cch;
  645. char strSource[MAX_MSG_LENGTH];
  646. char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  647. cch = CchLoadStringOfId(SourceID1, strSource, MAX_MSG_LENGTH);
  648. Assert(cch > 0);
  649. aInsertStrs[0] = (char*) strSource;
  650. cch = CchLoadStringOfId(SourceID2, strSource, MAX_MSG_LENGTH);
  651. Assert(cch > 0);
  652. aInsertStrs[1] = (char*) strSource;
  653. cch = CchLoadStringOfId(SourceID3, strSource, MAX_MSG_LENGTH);
  654. Assert(cch > 0);
  655. aInsertStrs[2] = (char*) strSource;
  656. cch = CchLoadStringOfId(SourceID4, strSource, MAX_MSG_LENGTH);
  657. Assert(cch > 0);
  658. aInsertStrs[3] = (char*) strSource;
  659. ReportAnEvent( (DWORD) MSG_DENALI_WARNING_4, (WORD) EVENTLOG_WARNING_TYPE, (WORD) 4, (LPCSTR *) aInsertStrs );
  660. return;
  661. }
  662. /*===================================================================
  663. void MSG_Warning
  664. report an event to the NT event log
  665. INPUT:
  666. ErrId - ID of error description in Message File
  667. pwszI1
  668. pwszI2
  669. Returns:
  670. None
  671. Side effects:
  672. Addes an entry in the NT event log
  673. ===================================================================*/
  674. void MSG_Warning( DWORD ErrId, LPCWSTR pwszI1, LPCWSTR pwszI2 )
  675. {
  676. static unsigned int LastErrId = 0;
  677. static WCHAR szLastStr1[MAX_MSG_LENGTH] = {0};
  678. static WCHAR szLastStr2[MAX_MSG_LENGTH] = {0};
  679. // if this is a repeat of the last reported message then return
  680. /// without posting an error.
  681. EnterCriticalSection(&g_csEventlogLock);
  682. if ((ErrId == LastErrId) && !wcscmp(szLastStr1, pwszI1) && !wcscmp(szLastStr2, pwszI2))
  683. {
  684. LeaveCriticalSection(&g_csEventlogLock);
  685. return;
  686. }
  687. LastErrId = ErrId;
  688. wcsncpy(szLastStr1, pwszI1, MAX_MSG_LENGTH);
  689. szLastStr1[MAX_MSG_LENGTH-1] = L'\0';
  690. wcsncpy(szLastStr2, pwszI2, MAX_MSG_LENGTH);
  691. szLastStr2[MAX_MSG_LENGTH-1] = L'\0';
  692. LeaveCriticalSection(&g_csEventlogLock);
  693. LPCWSTR aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert strings
  694. aInsertStrs[0] = szLastStr1;
  695. aInsertStrs[1] = szLastStr2;
  696. ReportAnEventW( ErrId, (WORD) EVENTLOG_ERROR_TYPE, 2, aInsertStrs );
  697. }