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.

247 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1998, Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This module contains declarations for debugging-support.
  7. Author:
  8. Abolade Gbadegesin (aboladeg) 2-Mar-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. HANDLE NhEventLogHandle = NULL;
  14. ULONG NhpTraceId = INVALID_TRACEID;
  15. //
  16. // FORWARD DECLARATIONS
  17. //
  18. BOOLEAN
  19. NhpIsAllowedLog(
  20. ULONG MessageId,
  21. ULONG Level
  22. );
  23. //
  24. // TRACING ROUTINES (alphabetically)
  25. //
  26. VOID
  27. NhDump(
  28. ULONG Flags,
  29. PUCHAR Buffer,
  30. ULONG BufferLength,
  31. ULONG Width
  32. )
  33. {
  34. TraceDumpEx(
  35. NhpTraceId,
  36. Flags,
  37. Buffer,
  38. BufferLength,
  39. Width,
  40. FALSE,
  41. NULL
  42. );
  43. }
  44. VOID
  45. NhInitializeTraceManagement(
  46. VOID
  47. )
  48. {
  49. NhpTraceId = TraceRegisterA("IPNATHLP");
  50. }
  51. VOID
  52. NhShutdownTraceManagement(
  53. VOID
  54. )
  55. {
  56. TraceDeregister(NhpTraceId);
  57. NhpTraceId = INVALID_TRACEID;
  58. }
  59. VOID
  60. NhTrace(
  61. ULONG Flags,
  62. PCHAR Format,
  63. ...
  64. )
  65. {
  66. va_list VaList;
  67. va_start(VaList, Format);
  68. TraceVprintfExA(NhpTraceId, Flags, Format, VaList);
  69. va_end(VaList);
  70. }
  71. //
  72. // EVENTLOGGING ROUTINES (alphabetically)
  73. //
  74. VOID
  75. NhErrorLog(
  76. ULONG MessageId,
  77. ULONG ErrorCode,
  78. PCHAR Format,
  79. ...
  80. )
  81. {
  82. va_list arglist;
  83. if (!NhpIsAllowedLog(MessageId, IPNATHLP_LOGGING_ERROR)) { return; }
  84. va_start(arglist, Format);
  85. RouterLogEventValistExA(
  86. NhEventLogHandle,
  87. EVENTLOG_ERROR_TYPE,
  88. ErrorCode,
  89. MessageId,
  90. Format,
  91. arglist
  92. );
  93. va_end(arglist);
  94. }
  95. VOID
  96. NhInformationLog(
  97. ULONG MessageId,
  98. ULONG ErrorCode,
  99. PCHAR Format,
  100. ...
  101. )
  102. {
  103. va_list arglist;
  104. if (!NhpIsAllowedLog(MessageId, IPNATHLP_LOGGING_INFO)) { return; }
  105. va_start(arglist, Format);
  106. RouterLogEventValistExA(
  107. NhEventLogHandle,
  108. EVENTLOG_INFORMATION_TYPE,
  109. ErrorCode,
  110. MessageId,
  111. Format,
  112. arglist
  113. );
  114. va_end(arglist);
  115. }
  116. VOID
  117. NhInitializeEventLogManagement(
  118. VOID
  119. )
  120. {
  121. NhEventLogHandle = RouterLogRegisterA(TARGETNAME);
  122. }
  123. BOOLEAN
  124. NhpIsAllowedLog(
  125. ULONG MessageId,
  126. ULONG Level
  127. )
  128. {
  129. if (MessageId > IP_AUTO_DHCP_LOG_BASE && MessageId < IP_AUTO_DHCP_LOG_END) {
  130. EnterCriticalSection(&DhcpGlobalInfoLock);
  131. if (!DhcpGlobalInfo) {
  132. LeaveCriticalSection(&DhcpGlobalInfoLock);
  133. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  134. } else if (DhcpGlobalInfo->LoggingLevel < Level) {
  135. LeaveCriticalSection(&DhcpGlobalInfoLock);
  136. return FALSE;
  137. }
  138. LeaveCriticalSection(&DhcpGlobalInfoLock);
  139. return TRUE;
  140. } else if (MessageId > IP_DNS_PROXY_LOG_BASE &&
  141. MessageId < IP_DNS_PROXY_LOG_END) {
  142. EnterCriticalSection(&DnsGlobalInfoLock);
  143. if (!DnsGlobalInfo) {
  144. LeaveCriticalSection(&DnsGlobalInfoLock);
  145. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  146. } else if (DnsGlobalInfo->LoggingLevel < Level) {
  147. LeaveCriticalSection(&DnsGlobalInfoLock);
  148. return FALSE;
  149. }
  150. LeaveCriticalSection(&DnsGlobalInfoLock);
  151. return TRUE;
  152. }
  153. #ifndef NO_FTP_PROXY
  154. else if (MessageId > IP_FTP_LOG_BASE && MessageId < IP_FTP_LOG_END) {
  155. EnterCriticalSection(&FtpGlobalInfoLock);
  156. if (!FtpGlobalInfo) {
  157. LeaveCriticalSection(&FtpGlobalInfoLock);
  158. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  159. } else if (FtpGlobalInfo->LoggingLevel < Level) {
  160. LeaveCriticalSection(&FtpGlobalInfoLock);
  161. return FALSE;
  162. }
  163. LeaveCriticalSection(&FtpGlobalInfoLock);
  164. return TRUE;
  165. }
  166. #endif
  167. else if (MessageId > IP_H323_LOG_BASE && MessageId < IP_H323_LOG_END) {
  168. EnterCriticalSection(&H323GlobalInfoLock);
  169. if (!H323GlobalInfo) {
  170. LeaveCriticalSection(&H323GlobalInfoLock);
  171. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  172. } else if (H323GlobalInfo->LoggingLevel < Level) {
  173. LeaveCriticalSection(&H323GlobalInfoLock);
  174. return FALSE;
  175. }
  176. LeaveCriticalSection(&H323GlobalInfoLock);
  177. return TRUE;
  178. } else if (MessageId > IP_NAT_LOG_BASE && MessageId < IP_NAT_LOG_END) {
  179. EnterCriticalSection(&NatGlobalInfoLock);
  180. if (!NatGlobalInfo) {
  181. LeaveCriticalSection(&NatGlobalInfoLock);
  182. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  183. } else if (NatGlobalInfo->LoggingLevel < Level) {
  184. LeaveCriticalSection(&NatGlobalInfoLock);
  185. return FALSE;
  186. }
  187. LeaveCriticalSection(&NatGlobalInfoLock);
  188. return TRUE;
  189. }
  190. return TRUE;
  191. }
  192. VOID
  193. NhWarningLog(
  194. ULONG MessageId,
  195. ULONG ErrorCode,
  196. PCHAR Format,
  197. ...
  198. )
  199. {
  200. va_list arglist;
  201. if (!NhpIsAllowedLog(MessageId, IPNATHLP_LOGGING_WARN)) { return; }
  202. va_start(arglist, Format);
  203. RouterLogEventValistExA(
  204. NhEventLogHandle,
  205. EVENTLOG_WARNING_TYPE,
  206. ErrorCode,
  207. MessageId,
  208. Format,
  209. arglist
  210. );
  211. va_end(arglist);
  212. }
  213. VOID
  214. NhShutdownEventLogManagement(
  215. VOID
  216. )
  217. {
  218. RouterLogDeregister(NhEventLogHandle);
  219. }