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.

132 lines
4.5 KiB

  1. /*--------------------------------------------------------
  2. ntevents.cpp
  3. Defines a generic class that can register an NT
  4. event source and log NT events on that evens source.
  5. Copyright (c) 1996-1998 Microsoft Corporation
  6. All rights reserved.
  7. Authors:
  8. rsraghav R.S. Raghavan
  9. History:
  10. 03-10-95 rsraghav Created.
  11. -------------------------------------------------------*/
  12. #include <windows.h>
  13. #include "ntevents.h"
  14. ///////////////////////////////////////////////////////////////////////////////
  15. //
  16. // Function: CNTEvent::CNTEvent
  17. //
  18. // Description: This is the constructor for the generic NT Even logging class
  19. //
  20. // Parameters: pszEventSourceName - points to a null-terminated string
  21. // representing the event source name.
  22. //
  23. //
  24. // Histroy: 03/10/96 rsraghav Created
  25. ///////////////////////////////////////////////////////////////////////////////
  26. CNTEvent::CNTEvent(const char *pszEventSourceName)
  27. {
  28. if (pszEventSourceName)
  29. {
  30. m_hEventSource = RegisterEventSource(NULL, pszEventSourceName);
  31. }
  32. }
  33. ///////////////////////////////////////////////////////////////////////////////
  34. //
  35. // Function: CNTEvent::~CNTEvent
  36. //
  37. // Description: This is the destructor for the generic NT Even logging class
  38. //
  39. // Parameters: none.
  40. //
  41. //
  42. // Histroy: 03/10/96 rsraghav Created
  43. ///////////////////////////////////////////////////////////////////////////////
  44. CNTEvent::~CNTEvent()
  45. {
  46. if (m_hEventSource)
  47. {
  48. DeregisterEventSource(m_hEventSource);
  49. m_hEventSource = NULL;
  50. }
  51. }
  52. ///////////////////////////////////////////////////////////////////////////////
  53. //
  54. // Function: CNTEvent::FLogEvent
  55. //
  56. // Description: This fucntion allows logging events to the event source
  57. // associated with this object. The function is a generic
  58. // log function that could handle upto 5 insert strings.
  59. // The string params are given the default value of NULL,
  60. // and the first NULL parameter in the argument list terminates
  61. // the insert string list.
  62. //
  63. // Parameters: wEventType - type of event to be logged (possible values
  64. // are EVENTLOG_INFORMATION_TYPE, EVENTLOG_ERROR_TYPE,
  65. // EVENTLOG_WARNING_TYPE, EVENTLOG_AUDIT_SUCCESS, and
  66. // EVENTLOG_AUDIT_FAILURE)
  67. // dwEventID - ID of the event to be logged (constants are
  68. // defined in the appropriate header files generated
  69. // by the mc compiler.
  70. // pszParamN - {N=1,2,3,4,5} represent the appropriate insert
  71. // string parameter. All have default value NULL, and the
  72. // first NULL parameter terminates the insert string list.
  73. //
  74. //
  75. // Histroy: 03/10/96 rsraghav Created
  76. ///////////////////////////////////////////////////////////////////////////////
  77. BOOL CNTEvent::FLogEvent(WORD wEventType, DWORD dwEventID, const char *pszParam1 /* = NULL */,
  78. const char *pszParam2 /* = NULL */, const char *pszParam3 /* = NULL */,
  79. const char *pszParam4 /* = NULL */, const char *pszParam5 /* = NULL */,
  80. const char *pszParam6 /* = NULL */, const char *pszParam7 /* = NULL */,
  81. const char *pszParam8 /* = NULL */, const char *pszParam9 /* = NULL */)
  82. {
  83. if (!m_hEventSource)
  84. {
  85. OutputDebugString("Can't log event, m_hEventSource is NULL\n");
  86. return FALSE;
  87. }
  88. const char *pszInsertString[10];
  89. const int cszInsertString = (sizeof(pszInsertString) / sizeof(pszInsertString[0]));
  90. WORD cInsertStrings = 0;
  91. pszInsertString[0] = pszParam1;
  92. pszInsertString[1] = pszParam2;
  93. pszInsertString[2] = pszParam3;
  94. pszInsertString[3] = pszParam4;
  95. pszInsertString[4] = pszParam5;
  96. pszInsertString[5] = pszParam6;
  97. pszInsertString[6] = pszParam7;
  98. pszInsertString[7] = pszParam8;
  99. pszInsertString[8] = pszParam9;
  100. pszInsertString[9] = NULL;
  101. for (int i = 0; i < cszInsertString; ++i)
  102. {
  103. if (pszInsertString[i])
  104. {
  105. cInsertStrings++;
  106. }
  107. else
  108. {
  109. break;
  110. }
  111. }
  112. return ReportEvent(m_hEventSource, wEventType, 0, dwEventID, NULL, cInsertStrings, 0, (const char **) pszInsertString, NULL);
  113. }