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.

166 lines
6.8 KiB

  1. // ==++==
  2. //
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. //
  5. // ==--==
  6. #ifndef __DBGLOG_H_INCLUDED__
  7. #define __DBGLOG_H_INCLUDED__
  8. #include "macros.h"
  9. #include "cstrings.h"
  10. #include "list.h"
  11. //#include "debmacro.h"
  12. //#include "fusionheap.h"
  13. #define FUSION_NEW_SINGLETON(_type) new _type
  14. #define FUSION_NEW_ARRAY(_type, _n) new _type[_n]
  15. #define FUSION_DELETE_ARRAY(_ptr) delete [] _ptr
  16. #define FUSION_DELETE_SINGLETON(_ptr) delete _ptr
  17. #define NEW(_type) FUSION_NEW_SINGLETON(_type)
  18. #define ID_COL_DETAILED_LOG L"--- A detailed log follows. \n"
  19. #define ID_COL_HEADER_TEXT L"*** ClickOnce Log "
  20. #define ID_COL_RESULT_TEXT L"ClickOnce hresult, hr = 0x%x. %ws"
  21. #define ID_COL_NO_DESCRIPTION L"No description available.\n"
  22. #define ID_COL_EXECUTABLE L"Running under executable "
  23. #define ID_COL_FINAL_HR L"Final hr = 0x%x"
  24. #define MAX_URL_LENGTH 2084 // same as INTERNET_MAX_URL_LENGTH
  25. // Logging constants and globals
  26. typedef void *IApplicationContext;
  27. #define REG_VAL_FUSION_LOG_PATH TEXT("LogPath")
  28. #define REG_VAL_FUSION_LOG_DISABLE TEXT("DisableLog")
  29. #define REG_VAL_FUSION_LOG_LEVEL TEXT("LoggingLevel")
  30. #define REG_VAL_FUSION_LOG_FORCE TEXT("ForceLog")
  31. #define REG_VAL_FUSION_LOG_FAILURES TEXT("LogFailures")
  32. #define REG_VAL_FUSION_LOG_RESOURCE_BINDS TEXT("LogResourceBinds")
  33. extern DWORD g_dwDisableLog;
  34. extern DWORD g_dwLogLevel;
  35. extern DWORD g_dwForceLog;
  36. // Debug Output macros (for easy compile-time disable of logging)
  37. #define FUSION_RETAIL_LOGGING
  38. #ifdef FUSION_RETAIL_LOGGING
  39. #define DEBUGOUT(pdbglog, dwLvl, pszLogMsg) if (!g_dwDisableLog && pdbglog) { pdbglog->DebugOut(dwLvl, pszLogMsg); }
  40. #define DEBUGOUT1(pdbglog, dwLvl, pszLogMsg, param1) if (!g_dwDisableLog && pdbglog) { pdbglog->DebugOut(dwLvl, pszLogMsg, param1); }
  41. #define DEBUGOUT2(pdbglog, dwLvl, pszLogMsg, param1, param2) if (!g_dwDisableLog && pdbglog) { pdbglog->DebugOut(dwLvl, pszLogMsg, param1, param2); }
  42. #define DEBUGOUT3(pdbglog, dwLvl, pszLogMsg, param1, param2, param3) if (!g_dwDisableLog && pdbglog) { pdbglog->DebugOut(dwLvl, pszLogMsg, param1, param2, param3); }
  43. #define DEBUGOUT4(pdbglog, dwLvl, pszLogMsg, param1, param2, param3, param4) if (!g_dwDisableLog && pdbglog) { pdbglog->DebugOut(dwLvl, pszLogMsg, param1, param2, param3, param4); }
  44. #define DEBUGOUT5(pdbglog, dwLvl, pszLogMsg, param1, param2, param3, param4, param5) if (!g_dwDisableLog && pdbglog) { pdbglog->DebugOut(dwLvl, pszLogMsg, param1, param2, param3, param4, param5); }
  45. #define DUMPDEBUGLOG(pdbglog, dwLvl, hr) if (!g_dwDisableLog && pdbglog) { pdbglog->DumpDebugLog(dwLvl, hr); }
  46. #else
  47. #define DEBUGOUT(pdbglog, dwLvl, pszLogMsg)
  48. #define DEBUGOUT1(pdbglog, dwLvl, pszLogMsg, param1)
  49. #define DEBUGOUT2(pdbglog, dwLvl, pszLogMsg, param1, param2)
  50. #define DEBUGOUT3(pdbglog, dwLvl, pszLogMsg, param1, param2, param3)
  51. #define DEBUGOUT4(pdbglog, dwLvl, pszLogMsg, param1, param2, param3, param4)
  52. #define DEBUGOUT5(pdbglog, dwLvl, pszLogMsg, param1, param2, param3, param4, param5)
  53. #define DUMPDEBUGLOG(pdbglog, dwLvl, hr)
  54. #endif
  55. #define IF_FALSE_EXIT_LOG(_x, _y, pdbglog, dwLvl, pszLogMsg) \
  56. do { if ((_x) == FALSE) { DEBUGOUT(pdbglog, dwLvl, pszLogMsg); _hr = _y; ASSERT(PREDICATE); goto exit; } } while (0)
  57. #define IF_FALSE_EXIT_LOG1(_x, _y, pdbglog, dwLvl, pszLogMsg, param1) \
  58. do { if ((_x) == FALSE) { DEBUGOUT1(pdbglog, dwLvl, pszLogMsg, param1); _hr = _y; ASSERT(PREDICATE); goto exit; } } while (0)
  59. #define MAX_DBG_STR_LEN 1024
  60. #define MAX_DATE_LEN 128
  61. #define DEBUG_LOG_HTML_START L"<html><pre>\n"
  62. #define DEBUG_LOG_HTML_META_LANGUAGE L"<meta http-equiv=\"Content-Type\" content=\"charset=unicode-1-1-utf-8\">"
  63. #define DEBUG_LOG_HTML_END L"\n</pre></html>"
  64. #define DEBUG_LOG_NEW_LINE L"\n"
  65. #define PAD_DIGITS_FOR_STRING(x) (((x) > 9) ? TEXT("") : TEXT("0"))
  66. class CDebugLogElement {
  67. public:
  68. CDebugLogElement(DWORD dwDetailLvl);
  69. virtual ~CDebugLogElement();
  70. static HRESULT Create(DWORD dwDetailLvl, LPCWSTR pwzMsg,
  71. CDebugLogElement **ppLogElem);
  72. HRESULT Init(LPCWSTR pwzMsg);
  73. HRESULT Dump(HANDLE hFile);
  74. public:
  75. WCHAR *_pszMsg;
  76. DWORD _dwDetailLvl;
  77. };
  78. class CDebugLog { // : public IFusionBindLog {
  79. public:
  80. CDebugLog();
  81. // virtual ~CDebugLog();
  82. ~CDebugLog();
  83. static HRESULT Create(IApplicationContext *pAppCtx, LPCWSTR pwzAsmName,
  84. CDebugLog **ppdl);
  85. // IUnknown methods
  86. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  87. STDMETHODIMP_(ULONG) AddRef();
  88. STDMETHODIMP_(ULONG) Release();
  89. // IFusionBindLog methods
  90. STDMETHODIMP GetResultCode();
  91. STDMETHODIMP GetBindLog(DWORD dwDetailLevel, LPWSTR pwzDebugLog,
  92. DWORD *pcbDebugLog);
  93. // CDebugLog functions
  94. HRESULT SetAsmName(LPCWSTR pwzAsmName);
  95. HRESULT SetResultCode(HRESULT hr);
  96. HRESULT DebugOut(DWORD dwDetailLvl, LPWSTR pwzFormatString, ...);
  97. HRESULT LogMessage(DWORD dwDetailLvl, LPCWSTR wzDebugStr, BOOL bPrepend);
  98. HRESULT DumpDebugLog(DWORD dwDetailLvl, HRESULT hrLog);
  99. HRESULT SetDownloadType(DWORD dwFlags);
  100. HRESULT SetAppName(LPCWSTR pwzAppName);
  101. HRESULT GetLoggedMsgs(DWORD dwDetailLevel, CString& sLogMsgs );
  102. private:
  103. HRESULT CreateLogFile(HANDLE *phFile, LPCWSTR wzFileName,
  104. LPCWSTR wzEXEName, HRESULT hrLog);
  105. HRESULT CloseLogFile(HANDLE *phFile);
  106. HRESULT Init(IApplicationContext *pAppCtx, LPCWSTR pwzAsmName);
  107. private:
  108. List<CDebugLogElement *> _listDbgMsg;
  109. HRESULT _hr;
  110. long _cRef;
  111. DWORD _dwNumEntries;
  112. LPWSTR _pwzAsmName;
  113. BOOL _bLogToWininet;
  114. WCHAR _szLogPath[MAX_PATH];
  115. LPWSTR _wzEXEName;
  116. BOOL _bWroteDetails;
  117. CRITICAL_SECTION _cs;
  118. CString _sDLType;
  119. CString _sAppName;
  120. };
  121. HRESULT CreateLogObject(CDebugLog **ppdbglog, LPCWSTR szCodebase);
  122. #endif