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.

415 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. NetDebug.h
  5. Abstract:
  6. This header file declares various debug routines for use in the
  7. networking code.
  8. Author:
  9. John Rogers (JohnRo) 11-Mar-1991
  10. Environment:
  11. ifdef'ed for NT, any ANSI C environment, or none of the above (which
  12. implies nondebug). The interface is portable (Win/32).
  13. Requires ANSI C extensions: slash-slash comments, long external names.
  14. Revision History:
  15. 11-Mar-1991 JohnRo
  16. Created.
  17. 25-Mar-1991 JohnRo
  18. Added more FORMAT_ strings. Got rid of tabs in file.
  19. 28-Mar-1991 JohnRo
  20. Added FORMAT_HEX_ strings.
  21. 08-Apr-1991 JohnRo
  22. Added temporary versions of wide char stuff (FORMAT_LPTSTR, etc).
  23. 16-Apr-1991 JohnRo
  24. Added PC-LINT version of NetpAssert(), to avoid occasional constant
  25. Boolean value messages. Added wrappers for NT debug code, to avoid
  26. recompile hits from <nt.h> all over the place.
  27. 25-Apr-1991 JohnRo
  28. Created procedure version of NetpDbgHexDump().
  29. 13-May-1991 JohnRo
  30. Added FORMAT_LPVOID to replace FORMAT_POINTER. Changed nondebug
  31. definition of NetpDbgHexDump() to avoid evaluating parameters.
  32. 15-May-1991 JohnRo
  33. FORMAT_HEX_WORD was wrong.
  34. 19-May-1991 JohnRo
  35. Improve LINT handling of assertions.
  36. 21-May-1991 JohnRo
  37. Added NetpDbgReasonable() for partial hex dumps.
  38. 13-Jun-1991 JohnRo
  39. Added NetpDbgDisplay routines.
  40. Moved DBGSTATIC here from <Rxp.h>.
  41. 02-Jul-1991 JohnRo
  42. Added display routines for print job, print queue, and print dest.
  43. 05-Jul-1991 JohnRo
  44. Avoid FORMAT_WORD name (used by MIPS header files).
  45. 22-Jul-1991 JohnRo
  46. Implement downlevel NetConnectionEnum.
  47. 25-Jul-1991 JohnRo
  48. Wksta debug support.
  49. 03-Aug-1991 JohnRo
  50. Rename wksta display routine for consistency.
  51. 20-Aug-1991 JohnRo
  52. Allow use in nondebug builds.
  53. 20-Aug-1991 JohnRo
  54. Downlevel NetFile APIs.
  55. 11-Sep-1991 JohnRo
  56. Downlevel NetService APIs. Added UNICODE versions of some FORMAT_
  57. equates. Added FORMAT_ULONG for NT use.
  58. 13-Sep-1991 JohnRo
  59. Change "reasonable" debug amount to be an even number of lines.
  60. Create an equate for it. Added LPDEBUG_STRING and a FORMAT_ for that.
  61. 15-Oct-1991 JohnRo
  62. Implement remote NetSession APIs.
  63. 11-Nov-1991 JohnRo
  64. Implement remote NetWkstaUserEnum(). Added FORMAT_RPC_STATUS.
  65. 26-Dec-1991 JohnRo
  66. Added stuff for replicator APIs.
  67. 07-Jan-1992 JohnRo
  68. Added NetpDbgDisplayWStr() for UNICODE strings.
  69. Added NetpDbgDisplayTStr() to be consistent.
  70. 26-Feb-1992 JohnRo
  71. Added NetpDbgDisplayTimestamp() (seconds since 1970).
  72. 15-Apr-1992 JohnRo
  73. Moved FORMAT_ equates into /nt/private/inc/debugfmt.h (so they
  74. can be used by the service controller as well).
  75. 13-Jun-1992 JohnRo
  76. RAID 10324: net print vs. UNICODE.
  77. 16-Aug-1992 JohnRo
  78. RAID 2920: Support UTC timezone in net code.
  79. 24-Aug-1992 JohnRo
  80. Fixed free build again (misnamed repl import/export display macros).
  81. 02-Oct-1992 JohnRo
  82. RAID 3556: DosPrintQGetInfo (from downlevel) level=3 rc=124.
  83. (Added NetpDbgDisplayPrintQArray.)
  84. 05-Jan-1993 JohnRo
  85. Repl WAN support (get rid of repl name list limits).
  86. Made changes suggested by PC-LINT 5.0
  87. 04-Mar-1993 JohnRo
  88. RAID 12237: replicator tree depth exceeded (add display of FILETIME
  89. and LARGE_INTEGER time).
  90. 31-Mar-1993 JohnRo
  91. Allow others to display replicator state too.
  92. --*/
  93. #ifndef _NETDEBUG_
  94. #define _NETDEBUG_
  95. // These must be included first:
  96. #include <windef.h> // BOOL, DWORD, FALSE, LPBYTE, etc.
  97. // These may be included in any order:
  98. #include <debugfmt.h> // Most FORMAT_ equates.
  99. #include <stdarg.h>
  100. #if DBG
  101. // Normal netlib debug version. No extra includes.
  102. #else // not DBG
  103. #ifdef CDEBUG
  104. // ANSI C debug version.
  105. #include <assert.h> // assert().
  106. #include <stdio.h> // printf().
  107. #else // ndef CDEBUG
  108. // Nondebug version.
  109. #endif // ndef CDEBUG
  110. #endif // not DBG
  111. #if !DBG || defined(lint) || defined(_lint)
  112. #define DBGSTATIC static // hidden function
  113. #else
  114. #define DBGSTATIC // visible for use in debugger.
  115. #endif
  116. //
  117. // printf-style format strings for some possibly nonportable stuff...
  118. // These are passed to NetpDbgPrint(); use with other routines at your
  119. // own risk.
  120. //
  121. // Most FORMAT_ equates now reside in /nt/private/inc/debugfmt.h.
  122. //
  123. typedef LPSTR LPDEBUG_STRING;
  124. #define FORMAT_API_STATUS "%lu"
  125. #define FORMAT_LPDEBUG_STRING "%s"
  126. #ifdef __cplusplus
  127. extern "C" {
  128. #endif
  129. // NetpAssert: continue if Predicate is true; otherwise print debug message
  130. // (if possible) and hit a breakpoint (if possible). Do nothing at all if
  131. // this is a nondebug build.
  132. //
  133. // VOID
  134. // NetpAssert(
  135. // IN BOOL Predicate
  136. // );
  137. //
  138. #if DBG
  139. VOID
  140. NetpAssertFailed(
  141. IN LPDEBUG_STRING FailedAssertion,
  142. IN LPDEBUG_STRING FileName,
  143. IN DWORD LineNumber,
  144. IN LPDEBUG_STRING Message OPTIONAL
  145. );
  146. // Normal networking debug version.
  147. #define NetpAssert(Predicate) \
  148. { \
  149. /*lint -save -e506 */ /* don't complain about constant values here */ \
  150. if (!(Predicate)) \
  151. NetpAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  152. /*lint -restore */ \
  153. }
  154. #else // not DBG
  155. #ifdef CDEBUG
  156. // ANSI C debug version.
  157. #define NetpAssert(Predicate) assert(Predicate)
  158. #else // ndef CDEBUG
  159. // Nondebug version.
  160. #define NetpAssert(Predicate) /* no output; ignore arguments */
  161. #endif // ndef CDEBUG
  162. #endif // not DBG
  163. // NetpBreakPoint: if this is a debug version of some sort, cause a breakpoint
  164. // somehow. (This may just be an assertion failure in ANSI C.) Do nothing at
  165. // all in nondebug builds.
  166. //
  167. // VOID
  168. // NetpBreakPoint(
  169. // VOID
  170. // );
  171. //
  172. #if DBG
  173. // NT debug version. Calls DbgBreakPoint.
  174. VOID
  175. NetpBreakPoint(
  176. VOID
  177. );
  178. #else // not DBG
  179. #ifdef CDEBUG
  180. // ANSI C debug version.
  181. #define NetpBreakPoint NetpAssert(FALSE)
  182. #else // ndef CDEBUG
  183. // Nondebug version.
  184. #define NetpBreakPoint() /* no effect. */
  185. #endif // ndef CDEBUG
  186. #endif // not DBG
  187. #if DBG
  188. VOID
  189. NetpDbgDisplayDword(
  190. IN LPDEBUG_STRING Tag,
  191. IN DWORD Value
  192. );
  193. VOID
  194. NetpDbgDisplayLong(
  195. IN LPDEBUG_STRING Tag,
  196. IN LONG Value
  197. );
  198. VOID
  199. NetpDbgDisplayString(
  200. IN LPDEBUG_STRING Tag,
  201. IN LPTSTR Value
  202. );
  203. VOID
  204. NetpDbgDisplayTag(
  205. IN LPDEBUG_STRING Tag
  206. );
  207. VOID
  208. NetpDbgDisplayTimestamp(
  209. IN LPDEBUG_STRING Tag,
  210. IN DWORD Time // Seconds since 1970.
  211. );
  212. VOID
  213. NetpDbgDisplayTod(
  214. IN LPDEBUG_STRING Tag,
  215. IN LPVOID TimePtr // LPTIME_OF_DAY_INFO.
  216. );
  217. #else // not DBG
  218. #define NetpDbgDisplayDword(Tag,Value) /* nothing */
  219. #define NetpDbgDisplayLong(Tag,Value) /* nothing */
  220. #define NetpDbgDisplayString(Tag,Value) /* nothing */
  221. #define NetpDbgDisplayTimestamp(Tag,Time) /* nothing */
  222. #define NetpDbgDisplayTag(Tag) /* nothing */
  223. #define NetpDbgDisplayTod(Tag,Tod) /* nothing */
  224. #endif // not DBG
  225. //
  226. // NetpKdPrint() & NetpDbgPrint() are net equivalents of
  227. // KdPrint() & DbgPrint(). Suggested usage:
  228. //
  229. // NetpKdPrint() & KdPrint() - OK
  230. // NetpDbgPrint() - so,so; produces warnings in the free build
  231. // DbgPrint - bad
  232. //
  233. #if DBG
  234. #define NetpKdPrint(_x_) NetpDbgPrint _x_
  235. VOID
  236. NetpDbgPrint(
  237. IN LPDEBUG_STRING FORMATSTRING, // PRINTF()-STYLE FORMAT STRING.
  238. ... // OTHER ARGUMENTS ARE POSSIBLE.
  239. );
  240. VOID
  241. NetpHexDump(
  242. LPBYTE Buffer,
  243. DWORD BufferSize
  244. );
  245. #else // not DBG
  246. #ifdef CDEBUG
  247. // ANSI C debug version.
  248. #define NetpKdPrint(_x_) NetpDbgPrint _x_
  249. #define NetpDbgPrint (void) printf
  250. #else // ndef CDEBUG
  251. // Nondebug version. Note that NetpKdPrint() eliminates all its
  252. // arguments.
  253. #define NetpKdPrint(_x_)
  254. #endif // ndef CDEBUG
  255. #endif // not DBG
  256. // NetpDbgHexDump: do a hex dump of some number of bytes to the debug
  257. // terminal or whatever. This is a no-op in a nondebug build.
  258. #if DBG || defined(CDEBUG)
  259. VOID
  260. NetpDbgHexDump(
  261. IN LPBYTE StartAddr,
  262. IN DWORD Length
  263. );
  264. #else
  265. #define NetpDbgHexDump(StartAddr,Length) // no output; ignore arguments
  266. #endif
  267. //
  268. // Define a number of bytes to dump for partial dumps. Each line dumps
  269. // 16 bytes, so do an even number of lines.
  270. //
  271. #define REASONABLE_DUMP_SIZE (6*16)
  272. // NetpDbgReasonable: pick a number for partial hex dumps.
  273. //
  274. // DWORD
  275. // NetpDbgReasonable(
  276. // IN DWORD MaxSize
  277. // );
  278. #define NetpDbgReasonable(MaxSize) \
  279. /*lint -save -e506 */ /* don't complain about constant values here */ \
  280. ( ((MaxSize) < REASONABLE_DUMP_SIZE) ? (MaxSize) : REASONABLE_DUMP_SIZE ) \
  281. /*lint -restore */
  282. #ifdef __cplusplus
  283. }
  284. #endif
  285. //
  286. // Generic log managment funtions. Present in debug and free builds.
  287. // All logs are relative to %WINDIR%\\debug\\. DebugLog will automatically
  288. // have a .LOG appended
  289. //
  290. VOID
  291. NetpInitializeLogFile(
  292. VOID
  293. );
  294. VOID
  295. NetpShutdownLogFile(
  296. VOID
  297. );
  298. HANDLE
  299. NetpOpenDebugFile(
  300. IN LPWSTR DebugLog
  301. );
  302. VOID
  303. NetpCloseDebugFile(
  304. IN HANDLE LogHandle
  305. );
  306. //
  307. // The following functions are used by NetJoin
  308. // to facilitate the logging per tasks it performs.
  309. //
  310. void
  311. NetSetuppOpenLog();
  312. void
  313. NetSetuppCloseLog();
  314. void
  315. NetpLogPrintHelper(
  316. IN LPCSTR Format,
  317. ...);
  318. #endif // ndef _NETDEBUG_