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.

152 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. sdpspdbg.c
  5. Abstract:
  6. This module contains the debugging support for the multicast conference
  7. service provider.
  8. Author:
  9. Mu Han (muhan) 26-March-1997
  10. --*/
  11. #include "stdafx.h"
  12. #include "confdbg.h"
  13. #include <stdio.h>
  14. #ifdef DBG
  15. #define MAXDEBUGSTRINGLEN 2048
  16. #define MAXPATHLEN 255
  17. VOID
  18. DbgPrt(
  19. IN int DbgLevel,
  20. IN PCHAR lpszFormat,
  21. IN ...
  22. )
  23. /*++
  24. Routine Description:
  25. Formats the incoming debug message & calls DbgPrint
  26. Arguments:
  27. DbgLevel - level of message verboseness
  28. DbgMessage - printf-style format string, followed by appropriate
  29. list of arguments
  30. Return Value:
  31. --*/
  32. {
  33. const TCHAR gszTSPKey[] =
  34. "Software\\Microsoft\\Windows\\CurrentVersion\\IPConfTSP";
  35. static FILE *log = NULL;
  36. static int DebugLevel = -1;
  37. if (DebugLevel == -1)
  38. {
  39. HKEY hTSPKey;
  40. DWORD dwDataSize = sizeof (int), dwDataType;
  41. const TCHAR szTSPDebugLevel[] = "DebugLevel";
  42. const TCHAR szTSPLogFile[] = "LogFile";
  43. DebugLevel=0;
  44. if (RegOpenKeyEx(
  45. HKEY_LOCAL_MACHINE,
  46. gszTSPKey,
  47. 0,
  48. KEY_READ,
  49. &hTSPKey
  50. ) == ERROR_SUCCESS)
  51. {
  52. if (RegQueryValueEx(
  53. hTSPKey,
  54. szTSPDebugLevel,
  55. 0,
  56. &dwDataType,
  57. (LPBYTE) &DebugLevel,
  58. &dwDataSize
  59. ) == ERROR_SUCCESS)
  60. {
  61. char szFileName[MAXPATHLEN + 1];
  62. dwDataSize = MAXPATHLEN;
  63. if (RegQueryValueEx(
  64. hTSPKey,
  65. szTSPLogFile,
  66. 0,
  67. &dwDataType,
  68. (LPBYTE) &szFileName,
  69. &dwDataSize
  70. ) == ERROR_SUCCESS)
  71. {
  72. log = fopen(szFileName, "w");
  73. }
  74. }
  75. RegCloseKey (hTSPKey);
  76. }
  77. }
  78. if (DbgLevel <= DebugLevel)
  79. {
  80. char buf[MAXDEBUGSTRINGLEN + 1];
  81. char *message[5] =
  82. {
  83. "FAIL: ",
  84. "WARN: ",
  85. "INFO: ",
  86. "TRCE: ",
  87. "ELSE: "
  88. };
  89. va_list ap;
  90. if (DbgLevel > 5)
  91. {
  92. DbgLevel = 5;
  93. }
  94. SYSTEMTIME SystemTime;
  95. // retrieve local time
  96. GetLocalTime(&SystemTime);
  97. wsprintfA(buf, "IPCONF:[%02u:%02u:%02u.%03u,tid=%x:]%s",
  98. SystemTime.wHour,
  99. SystemTime.wMinute,
  100. SystemTime.wSecond,
  101. SystemTime.wMilliseconds,
  102. GetCurrentThreadId(),
  103. message[DbgLevel - 1]
  104. );
  105. va_start(ap, lpszFormat);
  106. _vsnprintf(&buf[strlen(buf)],
  107. MAXDEBUGSTRINGLEN - strlen(buf), lpszFormat, ap);
  108. lstrcatA (buf, "\n");
  109. OutputDebugStringA (buf);
  110. if (log != NULL)
  111. {
  112. fprintf(log, "%s", buf);
  113. fflush(log);
  114. }
  115. va_end(ap);
  116. }
  117. }
  118. #endif //DBG