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.

126 lines
2.9 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright: Microsoft Corp. 1997-1999. All rights reserved
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. // Log.cpp : Implementation of CLog
  7. #include "stdafx.h"
  8. #include "Evntutl.h"
  9. #include "Log.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CLog
  12. STDMETHODIMP CLog::InterfaceSupportsErrorInfo(REFIID riid)
  13. {
  14. static const IID* arr[] =
  15. {
  16. &IID_ILog
  17. };
  18. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  19. {
  20. if (InlineIsEqualGUID(*arr[i],riid))
  21. return S_OK;
  22. }
  23. return S_FALSE;
  24. }
  25. /*
  26. Function: get_Events
  27. Inputs: empty variant pointer
  28. Outputs: variant dispatch pointer to a filled Events collection
  29. Purpose: provide access to IEvents interface, open an event log if not already open
  30. Notes: This op is very expensive when calling m_pEvents->Init()
  31. */
  32. STDMETHODIMP CLog::get_Events(VARIANT *pVal)
  33. {
  34. HRESULT hr = S_OK;
  35. VariantInit(pVal);
  36. IDispatch* pDisp;
  37. m_pEvents->QueryInterface (IID_IDispatch, (void**) &pDisp);
  38. pVal->vt = VT_DISPATCH;
  39. pVal->pdispVal = pDisp;
  40. // Need to open the log before users can start retreiving events.
  41. if (!m_Name) hr = E_INVALIDARG;
  42. else
  43. {
  44. if (!m_hLog) // if removed, calling Log.Events will refresh the collection
  45. {
  46. m_hLog = OpenEventLog(m_ServerName, m_Name);
  47. if (m_hLog) m_pEvents->Init(m_hLog, m_Name);
  48. else hr = E_HANDLE;
  49. }
  50. }
  51. return hr;
  52. }
  53. /*
  54. Function: get_Name
  55. Inputs: empty BSTR
  56. Outputs: BSTR containing the name of the EventLog
  57. Purpose: Allows user to access the name of the active EventLog
  58. */
  59. STDMETHODIMP CLog::get_Name(BSTR *pVal)
  60. {
  61. HRESULT hr = S_OK;
  62. if (pVal) *pVal = m_Name.copy();
  63. else hr = E_POINTER;
  64. return hr;
  65. }
  66. /*
  67. Function: get_Server
  68. Inputs: empty BSTR
  69. Outputs: BSTR containing the name of the server for the EventLog
  70. Purpose: Allows user to access the name of the active Server
  71. */
  72. STDMETHODIMP CLog::get_Server(BSTR *pVal)
  73. {
  74. HRESULT hr = S_OK;
  75. if (pVal) *pVal = m_ServerName.copy();
  76. else hr = E_POINTER;
  77. return hr;
  78. }
  79. /*
  80. Function: put_Server
  81. Inputs: BSTR containing the name of the server for the EventLog
  82. Outputs: HRESULT showing error code in case of failure, does not change input
  83. Purpose: Allows user to alter the name of the active Server
  84. */
  85. STDMETHODIMP CLog::put_Server(BSTR newVal)
  86. {
  87. m_ServerName = newVal;
  88. return S_OK;
  89. }
  90. /*
  91. Function: Clear
  92. Inputs: none
  93. Outputs: HRESULT showing error code in case of failure
  94. Purpose: Allows user to wipe EventLog clean
  95. Note: The function does NOT backup the EventLog first
  96. */
  97. STDMETHODIMP CLog::Clear()
  98. {
  99. HRESULT hr = S_OK;
  100. if (!m_hLog) m_hLog = OpenEventLog(m_ServerName, m_Name);
  101. if (m_hLog)
  102. {
  103. if (ClearEventLog(m_hLog, NULL)) m_hLog = NULL;
  104. else hr = E_FAIL;
  105. }
  106. else hr = E_HANDLE;
  107. return hr;
  108. }