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.

150 lines
4.0 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cmlog.h
  4. //
  5. // Module: cmutil.dll, cmdial32.dll etc
  6. //
  7. // Synopsis: Connection Manager Logging
  8. //
  9. // Copyright (c) 1998-2000 Microsoft Corporation
  10. //
  11. // Author: 04-May-2000 SumitC Created
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifdef CMLOG_IMPLEMENTATION
  15. #define CMLOG_CLASS __declspec(dllexport)
  16. #else
  17. #define CMLOG_CLASS __declspec(dllimport)
  18. #endif
  19. // the following values follow the defaults for RAS/PPP logging (using rtutils.dll)
  20. //
  21. const BOOL c_fEnableLogging = TRUE;
  22. const DWORD c_dwMaxFileSize = 0x64; // 100K = 102,400 bytes
  23. const LPTSTR c_szLogFileDirectory = TEXT("%Temp%");
  24. //
  25. // #define constants
  26. //
  27. #define BYTE_ORDER_MARK 0xFEFF
  28. //
  29. // List of CM/CPS events that can be logged
  30. //
  31. //
  32. // NOTE that this list must correspond with the s_aCmLogItems array in cmlog.cpp
  33. //
  34. enum _CMLOG_ITEM
  35. {
  36. UNKNOWN_LOG_ITEM, // guard item. DO NOT USE WHEN CALLING CMLOG() !!
  37. LOGGING_ENABLED_EVENT,
  38. LOGGING_DISABLED_EVENT,
  39. PREINIT_EVENT,
  40. PRECONNECT_EVENT,
  41. PREDIAL_EVENT,
  42. PRETUNNEL_EVENT,
  43. CONNECT_EVENT,
  44. CUSTOMACTIONDLL,
  45. CUSTOMACTIONEXE,
  46. CUSTOMACTION_NOT_ALLOWED,
  47. CUSTOMACTION_WONT_RUN,
  48. CUSTOMACTION_SKIPPED,
  49. DISCONNECT_EVENT,
  50. RECONNECT_EVENT,
  51. RETRY_AUTH_EVENT,
  52. CALLBACK_NUMBER_EVENT,
  53. PASSWORD_EXPIRED_EVENT,
  54. PASSWORD_RESET_EVENT,
  55. CUSTOM_BUTTON_EVENT,
  56. ONCANCEL_EVENT,
  57. ONERROR_EVENT,
  58. CLEAR_LOG_EVENT,
  59. DISCONNECT_EXT,
  60. DISCONNECT_INT_MANUAL,
  61. DISCONNECT_INT_AUTO,
  62. DISCONNECT_EXT_LOST_CONN,
  63. PB_DOWNLOAD_SUCCESS,
  64. PB_DOWNLOAD_FAILURE,
  65. PB_UPDATE_SUCCESS,
  66. PB_UPDATE_FAILURE_PBS,
  67. PB_UPDATE_FAILURE_CMPBK,
  68. PB_ABORTED,
  69. VPN_DOWNLOAD_SUCCESS,
  70. VPN_DOWNLOAD_FAILURE,
  71. VPN_UPDATE_SUCCESS,
  72. VPN_UPDATE_FAILURE,
  73. ONERROR_EVENT_W_SAFENET,
  74. SN_ADAPTER_CHANGE_EVENT,
  75. USER_FORMATTED = 99,
  76. };
  77. //
  78. // Use this macro for all string args that may be null or empty.
  79. //
  80. #define SAFE_LOG_ARG(x) ( (!(x) || !(*(x))) ? TEXT("(none)") : (x) )
  81. // ----------------------------------------------------------------------------
  82. //
  83. // Implementor's section (from here to end)
  84. //
  85. class CMLOG_CLASS CmLogFile
  86. {
  87. public:
  88. CmLogFile();
  89. ~CmLogFile();
  90. //
  91. // Initialization/termination functions
  92. //
  93. HRESULT Init(HINSTANCE hInst, BOOL fAllUser, LPCWSTR szLongServiceName);
  94. HRESULT Init(HINSTANCE hInst, BOOL fAllUser, LPCSTR szLongServiceName);
  95. HRESULT SetParams(BOOL fEnabled, DWORD dwMaxFileSize, LPCWSTR pszLogFileDir);
  96. HRESULT SetParams(BOOL fEnabled, DWORD dwMaxFileSize, LPCSTR pszLogFileDir);
  97. HRESULT Start(BOOL fBanner);
  98. HRESULT Stop();
  99. HRESULT DeInit();
  100. //
  101. // Work functions
  102. //
  103. void Banner();
  104. void Clear(BOOL fWriteBannerAfterwards = TRUE);
  105. void Log(_CMLOG_ITEM eLogItem, ...);
  106. //
  107. // Status inquiries
  108. //
  109. BOOL IsEnabled() { return m_fEnabled; }
  110. LPCWSTR GetLogFilePath() { return m_pszLogFile; }
  111. private:
  112. HRESULT OpenFile();
  113. HRESULT CloseFile();
  114. void FormatWrite(_CMLOG_ITEM eItem, LPWSTR szArgs);
  115. HRESULT Write(LPWSTR sz);
  116. HANDLE m_hfile; // file handle for logfile
  117. DWORD m_dwSize; // current size of log file
  118. LPWSTR m_pszServiceName; // name of connectoid (used as filename)
  119. WCHAR m_szModule[13]; // cached module name (13 = 8 + '.' + 3 + null)
  120. DWORD m_dwMaxSize; // max size of log file
  121. LPWSTR m_pszLogFileDir; // log file directory
  122. BOOL m_fAllUser; // is this an All-User profile?
  123. LPWSTR m_pszLogFile; // this is the currently-opened log file (full path)
  124. // state variables
  125. BOOL m_fInitialized; // set after Init() has been called
  126. BOOL m_fEnabled; // set after GetParams() finds logging is enabled (FROM CMS)
  127. };