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.

192 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. pastdbg.c
  5. Abstract:
  6. This module contains code for the PAST transparent proxy's DEBUG
  7. outputing code.
  8. Author:
  9. Savas Guven (savasg) 25-Jul-2000
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. extern ULONG NhpTraceId;
  14. //****************************************************************************
  15. // Global Parameters
  16. //****************************************************************************
  17. TCHAR g_tszDebugKey[] = _T("SOFTWARE\\Microsoft\\Tracing\\ICQPRX\\Debug");
  18. DEBUG_MODULE_INFO gDebugInfo[] = {
  19. {TM_DEFAULT, TL_DUMP, _T("<default>"), _T("DebugLevel")}, // 0
  20. {TM_BUF, TL_INFO, _T("BUF"), _T("BufDebugLevel")}, // 1
  21. {TM_API, TL_INFO, _T("API"), _T("ApiDebugLevel")}, // 2
  22. {TM_IO, TL_INFO, _T("IO"), _T("IoDebugLevel")}, // 3
  23. {TM_MSG, TL_INFO, _T("MSG"), _T("MsgDebugLevel")},// 4
  24. {TM_REF, TL_INFO, _T("REF"), _T("RefDebugLevel")},// 5
  25. {TM_TEST, TL_INFO, _T("TEST"), _T("TestDebugLevel")},// 6
  26. {TM_CON, TL_INFO, _T("CON"), _T("ConDebugLevel")}, // 7
  27. {TM_IF, TL_INFO, _T("IF"), _T("IfDebugLevel")}, //8
  28. {TM_PRX, TL_INFO, _T("PRX"), _T("PrxDebugLevel")}, //9
  29. {TM_SYNC, TL_INFO, _T("SYNC"), _T("SyncDebugLevel")}, // 10
  30. {TM_DISP, TL_INFO, _T("DISP"), _T("DispDebugLevel")},
  31. {TM_SOCK, TL_INFO, _T("SOCK"), _T("SockDebugLevel")},
  32. {TM_LIST, TL_INFO, _T("LIST"), _T("ListDebugLevel")}, // 13
  33. {TM_PROF, TL_INFO, _T("PROFILE"), _T("ProfileDebugLevel")}, // 14
  34. {TM_TIMER, TL_INFO, _T("TIMER"), _T("TimerDebugLevel")} // 15
  35. };
  36. char g_szModule[] = SZ_MODULE;
  37. HANDLE g_EventLogHandle = NULL;
  38. ULONG g_TraceId = INVALID_TRACEID;
  39. void DestroyDebuger(VOID) {
  40. TraceDeregister(g_TraceId);
  41. g_TraceId = INVALID_TRACEID;
  42. }
  43. //****************************************************************************
  44. // VOID GetDebugLevel()
  45. //
  46. // This function gets the current debug level from the registry
  47. //
  48. //****************************************************************************
  49. void InitDebuger()
  50. /*++
  51. Routine Description:
  52. R
  53. Arguments:
  54. A
  55. Return Value:
  56. R
  57. Notes:
  58. N
  59. --*/
  60. {
  61. HKEY hkey;
  62. DWORD dwType, cb;
  63. DWORD dwLevel;
  64. int iModule;
  65. int nModules;
  66. // Init the Trace Manager
  67. g_TraceId = TraceRegisterA("ICQPRX");
  68. //
  69. // Open the registry key that contains the debug configuration info
  70. //
  71. if (RegOpenKeyEx((HKEY) HKEY_LOCAL_MACHINE,
  72. g_tszDebugKey,
  73. 0,
  74. KEY_READ,
  75. &hkey) == ERROR_SUCCESS)
  76. {
  77. cb = sizeof(dwLevel);
  78. //
  79. // Initialize all the modules to the base value or their custom value
  80. //
  81. nModules = (sizeof(gDebugInfo)/sizeof(DEBUG_MODULE_INFO));
  82. for (iModule = 0; iModule < nModules; iModule++)
  83. {
  84. //
  85. // Open each custom debug level if present
  86. //
  87. if ((RegQueryValueEx(hkey,
  88. gDebugInfo[iModule].szDebugKey,
  89. NULL,
  90. &dwType,
  91. (PUCHAR)
  92. &dwLevel,
  93. &cb) == ERROR_SUCCESS) && (dwType == REG_DWORD))
  94. {
  95. gDebugInfo[iModule].dwLevel = dwLevel;
  96. }
  97. else
  98. {
  99. //gDebugInfo[iModule].dwLevel = gDebugInfo[TM_DEFAULT].dwLevel;
  100. }
  101. #ifndef _UNICODE
  102. DBG_TRACE(TM_IF, TL_INFO, ("ModuleKey: %s, DebugLevel: %d",
  103. gDebugInfo[iModule].szModuleName,
  104. gDebugInfo[iModule].dwLevel));
  105. #endif
  106. }
  107. RegCloseKey(hkey);
  108. }
  109. else
  110. {
  111. // NhTrace(TRACE_FLAG_PAST, "Couldn't open Reg\n");
  112. printf("DEBUG key doesn't exist\n");
  113. }
  114. return;
  115. }
  116. void DbgPrintX(LPCSTR pszMsg, ...)
  117. {
  118. va_list VaList;
  119. /*
  120. char temp[100];
  121. char msg[1024];
  122. int len = 0;
  123. len = sprintf(temp, "%s ", g_szModule);
  124. lstrcpy(msg, temp);
  125. wvsprintf(&msg[len], pszMsg, (va_list)(&pszMsg + 1));
  126. lstrcat(msg,"\r\n");
  127. OutputDebugString(msg);
  128. */
  129. if(g_TraceId is INVALID_TRACEID)
  130. InitDebuger();
  131. va_start(VaList, pszMsg);
  132. TraceVprintfExA(g_TraceId,
  133. TRACE_FLAG_ICQ,
  134. pszMsg,
  135. VaList);
  136. va_end(VaList);
  137. }
  138. // DBG_TRACE(TM_MSG, TL_INFO, ("nvnat_control_one > xtcp_port\n"));