Source code of Windows XP (NT5)
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.

143 lines
3.7 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. DISCONNECT_EVENT,
  49. RECONNECT_EVENT,
  50. RETRY_AUTH_EVENT,
  51. CALLBACK_NUMBER_EVENT,
  52. PASSWORD_EXPIRED_EVENT,
  53. PASSWORD_RESET_EVENT,
  54. CUSTOM_BUTTON_EVENT,
  55. ONCANCEL_EVENT,
  56. ONERROR_EVENT,
  57. CLEAR_LOG_EVENT,
  58. DISCONNECT_EXT,
  59. DISCONNECT_INT_MANUAL,
  60. DISCONNECT_INT_AUTO,
  61. DISCONNECT_EXT_LOST_CONN,
  62. PB_DOWNLOAD_SUCCESS,
  63. PB_DOWNLOAD_FAILURE,
  64. PB_UPDATE_SUCCESS,
  65. PB_UPDATE_FAILURE_PBS,
  66. PB_UPDATE_FAILURE_CMPBK,
  67. PB_ABORTED,
  68. USER_FORMATTED = 99,
  69. };
  70. //
  71. // Use this macro for all string args that may be null or empty.
  72. //
  73. #define SAFE_LOG_ARG(x) ( (!(x) || !(*(x))) ? TEXT("(none)") : (x) )
  74. // ----------------------------------------------------------------------------
  75. //
  76. // Implementor's section (from here to end)
  77. //
  78. class CMLOG_CLASS CmLogFile
  79. {
  80. public:
  81. CmLogFile();
  82. ~CmLogFile();
  83. //
  84. // Initialization/termination functions
  85. //
  86. HRESULT Init(HINSTANCE hInst, BOOL fAllUser, LPCWSTR szLongServiceName);
  87. HRESULT Init(HINSTANCE hInst, BOOL fAllUser, LPCSTR szLongServiceName);
  88. HRESULT SetParams(BOOL fEnabled, DWORD dwMaxFileSize, LPCWSTR pszLogFileDir);
  89. HRESULT SetParams(BOOL fEnabled, DWORD dwMaxFileSize, LPCSTR pszLogFileDir);
  90. HRESULT Start(BOOL fBanner);
  91. HRESULT Stop();
  92. HRESULT DeInit();
  93. //
  94. // Work functions
  95. //
  96. void Banner();
  97. void Clear(BOOL fWriteBannerAfterwards = TRUE);
  98. void Log(_CMLOG_ITEM eLogItem, ...);
  99. //
  100. // Status inquiries
  101. //
  102. BOOL IsEnabled() { return m_fEnabled; }
  103. LPCWSTR GetLogFilePath() { return m_pszLogFile; }
  104. private:
  105. HRESULT OpenFile();
  106. HRESULT CloseFile();
  107. void FormatWrite(_CMLOG_ITEM eItem, LPWSTR szArgs);
  108. HRESULT Write(LPWSTR sz);
  109. HANDLE m_hfile; // file handle for logfile
  110. DWORD m_dwSize; // current size of log file
  111. LPWSTR m_pszServiceName; // name of connectoid (used as filename)
  112. WCHAR m_szModule[13]; // cached module name (13 = 8 + '.' + 3 + null)
  113. DWORD m_dwMaxSize; // max size of log file
  114. LPWSTR m_pszLogFileDir; // log file directory
  115. BOOL m_fAllUser; // is this an All-User profile?
  116. LPWSTR m_pszLogFile; // this is the currently-opened log file (full path)
  117. // state variables
  118. BOOL m_fInitialized; // set after Init() has been called
  119. BOOL m_fEnabled; // set after GetParams() finds logging is enabled (FROM CMS)
  120. };