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.

169 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. eventlog.c
  5. Abstract:
  6. This module contains routines that allow the simple TCP/IP services
  7. to log events.
  8. Author:
  9. David Treadwell (davidtr) 08-02-1993
  10. Revision History:
  11. --*/
  12. #include <simptcp.h>
  13. //
  14. // Private globals.
  15. //
  16. HANDLE EventSource;
  17. //
  18. // Private prototypes.
  19. //
  20. VOID
  21. LogEventWorker (
  22. DWORD Message,
  23. WORD EventType,
  24. WORD SubStringCount,
  25. CHAR *SubStrings[],
  26. DWORD ErrorCode
  27. );
  28. INT
  29. SimpInitializeEventLog (
  30. VOID
  31. )
  32. {
  33. //
  34. // Register as an event source.
  35. //
  36. EventSource = RegisterEventSource( NULL, TEXT("SimpTcp") );
  37. if( EventSource == NULL ) {
  38. return GetLastError();
  39. }
  40. return NO_ERROR;
  41. } // SimpInitializeEventLog
  42. VOID
  43. SimpTerminateEventLog(
  44. VOID
  45. )
  46. {
  47. //
  48. // Deregister as an event source.
  49. //
  50. if( EventSource != NULL )
  51. {
  52. if( !DeregisterEventSource( EventSource ) )
  53. {
  54. INT err = GetLastError();
  55. }
  56. EventSource = NULL;
  57. }
  58. } // SimpTerminateEventLog
  59. VOID
  60. SimpLogEvent(
  61. DWORD Message,
  62. WORD SubStringCount,
  63. CHAR *SubStrings[],
  64. DWORD ErrorCode
  65. )
  66. {
  67. WORD Type;
  68. //
  69. // Determine the type of event to log based on the severity field of
  70. // the message id.
  71. //
  72. if( NT_INFORMATION(Message) ) {
  73. Type = EVENTLOG_INFORMATION_TYPE;
  74. } else if( NT_WARNING(Message) ) {
  75. Type = EVENTLOG_WARNING_TYPE;
  76. } else if( NT_ERROR(Message) ) {
  77. Type = EVENTLOG_ERROR_TYPE;
  78. } else {
  79. ASSERT( FALSE );
  80. Type = EVENTLOG_ERROR_TYPE;
  81. }
  82. //
  83. // Log it!
  84. //
  85. LogEventWorker(
  86. Message,
  87. Type,
  88. SubStringCount,
  89. SubStrings,
  90. ErrorCode
  91. );
  92. } // SimpLogEvent
  93. VOID
  94. LogEventWorker(
  95. DWORD Message,
  96. WORD EventType,
  97. WORD SubStringCount,
  98. CHAR *SubStrings[],
  99. DWORD ErrorCode
  100. )
  101. {
  102. VOID *RawData = NULL;
  103. DWORD RawDataSize = 0;
  104. ASSERT( ( SubStringCount == 0 ) || ( SubStrings != NULL ) );
  105. if( ErrorCode != 0 ) {
  106. RawData = &ErrorCode;
  107. RawDataSize = sizeof(ErrorCode);
  108. }
  109. if( !ReportEvent( EventSource, // hEventSource
  110. EventType, // fwEventType
  111. 0, // fwCategory
  112. Message, // IDEvent
  113. NULL, // pUserSid,
  114. SubStringCount, // cStrings
  115. RawDataSize, // cbData
  116. (LPCTSTR *)SubStrings, // plpszStrings
  117. RawData ) ) // lpvData
  118. {
  119. INT err = GetLastError();
  120. DbgPrint( "cannot report event, error %lu\n", err );
  121. }
  122. } // LogEventWorker