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.

118 lines
3.1 KiB

  1. #include "stdafx.h"
  2. INT g_iDebugOutputLevel = 0;
  3. DWORD g_dwInetmgrParamFlags = 0;
  4. void DebugTrace(LPTSTR lpszFormat, ...)
  5. {
  6. // Only do this if the flag is set.
  7. if (0 != g_iDebugOutputLevel)
  8. {
  9. int nBuf;
  10. TCHAR szBuffer[_MAX_PATH];
  11. va_list args;
  12. va_start(args, lpszFormat);
  13. nBuf = _vsntprintf(szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0]), lpszFormat, args);
  14. szBuffer[_MAX_PATH - 1] = L'\0'; // null terminate the string
  15. ASSERT(nBuf < sizeof(szBuffer)/sizeof(szBuffer[0])); //Output truncated as it was > sizeof(szBuffer)
  16. OutputDebugString(szBuffer);
  17. va_end(args);
  18. // if it does not end if '\r\n' then make one.
  19. int nLen = _tcslen(szBuffer);
  20. if (szBuffer[nLen-1] != _T('\n')){OutputDebugString(_T("\r\n"));}
  21. }
  22. }
  23. void WinHelpDebug(DWORD_PTR dwWinHelpID)
  24. {
  25. if (DEBUG_FLAG_HELP & g_iDebugOutputLevel)
  26. {
  27. TCHAR szBuffer[30];
  28. _stprintf(szBuffer,_T("WinHelp:0x%x,%d\r\n"),dwWinHelpID,dwWinHelpID);
  29. DebugTrace(szBuffer);
  30. }
  31. return;
  32. }
  33. void GetOutputDebugFlag(void)
  34. {
  35. DWORD rc, err, size, type;
  36. HKEY hkey;
  37. err = RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\InetMgr"), &hkey);
  38. if (err != ERROR_SUCCESS) {return;}
  39. size = sizeof(DWORD);
  40. err = RegQueryValueEx(hkey,_T("OutputDebugFlag"),0,&type,(LPBYTE)&rc,&size);
  41. if (err != ERROR_SUCCESS || type != REG_DWORD) {rc = 0;}
  42. RegCloseKey(hkey);
  43. if (rc < 0xffffffff)
  44. {
  45. // Defined in inc\DebugDefs.h
  46. g_iDebugOutputLevel = rc;
  47. }
  48. return;
  49. }
  50. void GetInetmgrParamFlag(void)
  51. {
  52. DWORD rc, size, type;
  53. HKEY hkey;
  54. g_dwInetmgrParamFlags = 0;
  55. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\InetMgr\\Parameters"), &hkey))
  56. {
  57. size = sizeof(DWORD);
  58. if (ERROR_SUCCESS == RegQueryValueEx(hkey,_T("InetMgrFlags"),0,&type,(LPBYTE)&rc,&size))
  59. {
  60. if (type == REG_DWORD)
  61. {
  62. // Defined in inc\DebugDefs.h
  63. g_dwInetmgrParamFlags = rc;
  64. }
  65. }
  66. RegCloseKey(hkey);
  67. }
  68. #if defined(_DEBUG) || DBG
  69. DebugTrace(_T("g_dwInetmgrParamFlags=0x%x\r\n"),g_dwInetmgrParamFlags);
  70. #endif
  71. }
  72. BOOL SetInetmgrParamFlag(DWORD dwFlagToSet,BOOL bState)
  73. {
  74. BOOL bSuccessfullyWrote = FALSE;
  75. HKEY hKey = NULL;
  76. // Grab the existing params
  77. // and change only our settings
  78. if (bState)
  79. {
  80. // ON the setting
  81. g_dwInetmgrParamFlags |= dwFlagToSet;
  82. }
  83. else
  84. {
  85. // OFF the setting
  86. g_dwInetmgrParamFlags &= ~dwFlagToSet;
  87. }
  88. if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\InetMgr\\Parameters"), 0, KEY_WRITE, &hKey ))
  89. {
  90. if (ERROR_SUCCESS == RegSetValueEx( hKey, _T("InetMgrFlags"), 0, REG_DWORD, (BYTE *) &g_dwInetmgrParamFlags, sizeof( DWORD ) ))
  91. {
  92. bSuccessfullyWrote = TRUE;
  93. }
  94. if( NULL != hKey )
  95. {
  96. RegCloseKey( hKey );
  97. hKey = NULL;
  98. }
  99. }
  100. #if defined(_DEBUG) || DBG
  101. DebugTrace(_T("SetInetmgrParamFlag:g_dwInetmgrParamFlags=0x%x\r\n"),g_dwInetmgrParamFlags);
  102. #endif
  103. return bSuccessfullyWrote;
  104. }