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.

303 lines
6.6 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. ULONG NhpEventLogCount;
  14. HANDLE NhEventLogHandle = NULL;
  15. CRITICAL_SECTION NhpEventLogLock;
  16. ULONG NhpTraceId = INVALID_TRACEID;
  17. //
  18. // FORWARD DECLARATIONS
  19. //
  20. BOOLEAN
  21. NhpIsAllowedLog(
  22. ULONG MessageId,
  23. ULONG Level
  24. );
  25. //
  26. // TRACING ROUTINES (alphabetically)
  27. //
  28. VOID
  29. NhDump(
  30. ULONG Flags,
  31. PUCHAR Buffer,
  32. ULONG BufferLength,
  33. ULONG Width
  34. )
  35. {
  36. TraceDumpEx(
  37. NhpTraceId,
  38. Flags,
  39. Buffer,
  40. BufferLength,
  41. Width,
  42. FALSE,
  43. NULL
  44. );
  45. }
  46. VOID
  47. NhInitializeTraceManagement(
  48. VOID
  49. )
  50. {
  51. NhpTraceId = TraceRegisterA("IPNATHLP");
  52. }
  53. VOID
  54. NhShutdownTraceManagement(
  55. VOID
  56. )
  57. {
  58. TraceDeregister(NhpTraceId);
  59. NhpTraceId = INVALID_TRACEID;
  60. }
  61. VOID
  62. NhTrace(
  63. ULONG Flags,
  64. PCHAR Format,
  65. ...
  66. )
  67. {
  68. va_list VaList;
  69. va_start(VaList, Format);
  70. TraceVprintfExA(NhpTraceId, Flags, Format, VaList);
  71. va_end(VaList);
  72. }
  73. //
  74. // EVENTLOGGING ROUTINES (alphabetically)
  75. //
  76. VOID
  77. NhErrorLog(
  78. ULONG MessageId,
  79. ULONG ErrorCode,
  80. PCHAR Format,
  81. ...
  82. )
  83. {
  84. HANDLE EventLogHandle;
  85. EnterCriticalSection(&NhpEventLogLock);
  86. ASSERT(NhpEventLogCount > 0);
  87. EventLogHandle = NhEventLogHandle;
  88. LeaveCriticalSection(&NhpEventLogLock);
  89. if (NULL != EventLogHandle) {
  90. va_list arglist;
  91. if (!NhpIsAllowedLog(MessageId, IPNATHLP_LOGGING_ERROR)) { return; }
  92. va_start(arglist, Format);
  93. RouterLogEventValistExA(
  94. EventLogHandle,
  95. EVENTLOG_ERROR_TYPE,
  96. ErrorCode,
  97. MessageId,
  98. Format,
  99. arglist
  100. );
  101. va_end(arglist);
  102. }
  103. }
  104. VOID
  105. NhInformationLog(
  106. ULONG MessageId,
  107. ULONG ErrorCode,
  108. PCHAR Format,
  109. ...
  110. )
  111. {
  112. HANDLE EventLogHandle;
  113. EnterCriticalSection(&NhpEventLogLock);
  114. ASSERT(NhpEventLogCount > 0);
  115. EventLogHandle = NhEventLogHandle;
  116. LeaveCriticalSection(&NhpEventLogLock);
  117. if (NULL != EventLogHandle) {
  118. va_list arglist;
  119. if (!NhpIsAllowedLog(MessageId, IPNATHLP_LOGGING_INFO)) { return; }
  120. va_start(arglist, Format);
  121. RouterLogEventValistExA(
  122. EventLogHandle,
  123. EVENTLOG_INFORMATION_TYPE,
  124. ErrorCode,
  125. MessageId,
  126. Format,
  127. arglist
  128. );
  129. va_end(arglist);
  130. }
  131. }
  132. BOOLEAN
  133. NhInitializeEventLogManagement(
  134. VOID
  135. )
  136. {
  137. BOOLEAN Succeeded = TRUE;
  138. NhpEventLogCount = 0;
  139. __try {
  140. InitializeCriticalSection(&NhpEventLogLock);
  141. } __except(EXCEPTION_EXECUTE_HANDLER) {
  142. Succeeded = FALSE;
  143. }
  144. return Succeeded;
  145. }
  146. BOOLEAN
  147. NhpIsAllowedLog(
  148. ULONG MessageId,
  149. ULONG Level
  150. )
  151. {
  152. if (MessageId > IP_AUTO_DHCP_LOG_BASE && MessageId < IP_AUTO_DHCP_LOG_END) {
  153. EnterCriticalSection(&DhcpGlobalInfoLock);
  154. if (!DhcpGlobalInfo) {
  155. LeaveCriticalSection(&DhcpGlobalInfoLock);
  156. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  157. } else if (DhcpGlobalInfo->LoggingLevel < Level) {
  158. LeaveCriticalSection(&DhcpGlobalInfoLock);
  159. return FALSE;
  160. }
  161. LeaveCriticalSection(&DhcpGlobalInfoLock);
  162. return TRUE;
  163. } else if (MessageId > IP_DNS_PROXY_LOG_BASE &&
  164. MessageId < IP_DNS_PROXY_LOG_END) {
  165. EnterCriticalSection(&DnsGlobalInfoLock);
  166. if (!DnsGlobalInfo) {
  167. LeaveCriticalSection(&DnsGlobalInfoLock);
  168. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  169. } else if (DnsGlobalInfo->LoggingLevel < Level) {
  170. LeaveCriticalSection(&DnsGlobalInfoLock);
  171. return FALSE;
  172. }
  173. LeaveCriticalSection(&DnsGlobalInfoLock);
  174. return TRUE;
  175. } else if (MessageId > IP_H323_LOG_BASE && MessageId < IP_H323_LOG_END) {
  176. EnterCriticalSection(&H323GlobalInfoLock);
  177. if (!H323GlobalInfo) {
  178. LeaveCriticalSection(&H323GlobalInfoLock);
  179. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  180. } else if (H323GlobalInfo->LoggingLevel < Level) {
  181. LeaveCriticalSection(&H323GlobalInfoLock);
  182. return FALSE;
  183. }
  184. LeaveCriticalSection(&H323GlobalInfoLock);
  185. return TRUE;
  186. } else if (MessageId > IP_NAT_LOG_BASE && MessageId < IP_NAT_LOG_END) {
  187. EnterCriticalSection(&NatGlobalInfoLock);
  188. if (!NatGlobalInfo) {
  189. LeaveCriticalSection(&NatGlobalInfoLock);
  190. return (Level == IPNATHLP_LOGGING_ERROR) ? TRUE : FALSE;
  191. } else if (NatGlobalInfo->LoggingLevel < Level) {
  192. LeaveCriticalSection(&NatGlobalInfoLock);
  193. return FALSE;
  194. }
  195. LeaveCriticalSection(&NatGlobalInfoLock);
  196. return TRUE;
  197. }
  198. return TRUE;
  199. }
  200. VOID
  201. NhWarningLog(
  202. ULONG MessageId,
  203. ULONG ErrorCode,
  204. PCHAR Format,
  205. ...
  206. )
  207. {
  208. HANDLE EventLogHandle;
  209. EnterCriticalSection(&NhpEventLogLock);
  210. ASSERT(NhpEventLogCount > 0);
  211. EventLogHandle = NhEventLogHandle;
  212. LeaveCriticalSection(&NhpEventLogLock);
  213. if (NULL != EventLogHandle) {
  214. va_list arglist;
  215. if (!NhpIsAllowedLog(MessageId, IPNATHLP_LOGGING_WARN)) { return; }
  216. va_start(arglist, Format);
  217. RouterLogEventValistExA(
  218. EventLogHandle,
  219. EVENTLOG_WARNING_TYPE,
  220. ErrorCode,
  221. MessageId,
  222. Format,
  223. arglist
  224. );
  225. va_end(arglist);
  226. }
  227. }
  228. VOID
  229. NhStartEventLog(
  230. VOID
  231. )
  232. {
  233. EnterCriticalSection(&NhpEventLogLock);
  234. NhpEventLogCount += 1;
  235. if (NULL == NhEventLogHandle) {
  236. NhEventLogHandle = RouterLogRegisterA(TARGETNAME);
  237. }
  238. LeaveCriticalSection(&NhpEventLogLock);
  239. }
  240. VOID
  241. NhStopEventLog(
  242. VOID
  243. )
  244. {
  245. EnterCriticalSection(&NhpEventLogLock);
  246. ASSERT(NhpEventLogCount > 0);
  247. NhpEventLogCount -= 1;
  248. if (0 == NhpEventLogCount && NULL != NhEventLogHandle) {
  249. RouterLogDeregister(NhEventLogHandle);
  250. NhEventLogHandle = NULL;
  251. }
  252. LeaveCriticalSection(&NhpEventLogLock);
  253. }
  254. VOID
  255. NhShutdownEventLogManagement(
  256. VOID
  257. )
  258. {
  259. DeleteCriticalSection(&NhpEventLogLock);
  260. }