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.

327 lines
12 KiB

  1. //+------------------------------------------------------------
  2. //
  3. // Copyright (C) 1999, Microsoft Corporation
  4. //
  5. // File: catdebug.h
  6. //
  7. // Contents: Data/definitions used only for debugging
  8. //
  9. // Classes: None
  10. //
  11. // Functions:
  12. //
  13. // History:
  14. // jstamerj 1999/07/29 17:32:34: Created.
  15. //
  16. //-------------------------------------------------------------
  17. #ifndef __CATDEBUG_H__
  18. #define __CATDEBUG_H__
  19. //
  20. // This #define controls wether or not the debug list checking is enabled
  21. // Currently, enable it in RTL and DBG builds
  22. //
  23. #define CATDEBUGLIST
  24. //
  25. // A handy macro for declaring classes that use the debug list
  26. //
  27. #define CatDebugClass(ClassName) class ClassName : public CCatDLO<ClassName##_didx>
  28. //
  29. // An alternative to calling DbgBreakPoint (since DbgBreakPoint breaks
  30. // DogFood into the kernel debugger)
  31. //
  32. VOID CatDebugBreakPoint();
  33. //
  34. // Debug data types
  35. //
  36. typedef struct _tagDebugObjectList {
  37. DWORD dwCount;
  38. LIST_ENTRY listhead;
  39. SPIN_LOCK spinlock;
  40. } DEBUGOBJECTLIST, *PDEBUGOBJECTLIST;
  41. //
  42. // Enumeation of all the class types that use the debug list
  43. //
  44. typedef enum _tagDebugObjectId {
  45. // Hex offset
  46. CABContext_didx = 0, // 0x00
  47. CSMTPCategorizer_didx, // 0x01
  48. CCategorizer_didx, // 0x02
  49. CCatSender_didx, // 0x03
  50. CCatRecip_didx, // 0x04
  51. CCatDLRecip_didx, // 0x05
  52. CMembersInsertionRequest_didx, // 0x06
  53. CSinkInsertionRequest_didx, // 0x07
  54. CTopLevelInsertionRequest_didx, // 0x08
  55. CICategorizerListResolveIMP_didx, // 0x09
  56. CICategorizerDLListResolveIMP_didx, // 0x0A
  57. CICategorizerParametersIMP_didx, // 0x0B
  58. CICategorizerRequestedAttributesIMP_didx, // 0x0C
  59. //
  60. // asyncctx
  61. //
  62. CSearchRequestBlock_didx, // 0x0D
  63. CStoreListResolveContext_didx, // 0x0E
  64. CSingleSearchReinsertionRequest_didx, // 0x0F
  65. //
  66. // cnfgmgr
  67. //
  68. CLdapCfgMgr_didx, // 0x10
  69. CLdapCfg_didx, // 0x11
  70. CLdapServerCfg_didx, // 0x12
  71. //
  72. // icatasync
  73. //
  74. CICategorizerAsyncContextIMP_didx, // 0x13
  75. //
  76. // icatitemattr
  77. //
  78. CLdapResultWrap_didx, // 0x14
  79. CICategorizerItemAttributesIMP_didx, // 0x15
  80. //
  81. // icatqueries
  82. //
  83. CICategorizerQueriesIMP_didx, // 0x16
  84. //
  85. // ldapconn
  86. //
  87. CLdapConnection_didx, // 0x17
  88. //
  89. // ldapstor
  90. //
  91. CMembershipPageInsertionRequest_didx, // 0x18
  92. CDynamicDLSearchInsertionRequest_didx, // 0x19
  93. CEmailIDLdapStore_didx, // 0x1A
  94. //
  95. // pldapwrap
  96. //
  97. CPLDAPWrap_didx, // 0x1B
  98. //
  99. // The number of debug objects to support
  100. //
  101. NUM_DEBUG_LIST_OBJECTS
  102. } DEBUGOBJECTID, *PDEBUGOBJECTID;
  103. //
  104. // Global array of lists
  105. //
  106. extern DEBUGOBJECTLIST g_rgDebugObjectList[NUM_DEBUG_LIST_OBJECTS];
  107. //
  108. // Debug Global init/deinit
  109. //
  110. VOID CatInitDebugObjectList();
  111. VOID CatVrfyEmptyDebugObjectList();
  112. //
  113. // Class CCatDLO (Debug List Object): an object that adds and removes
  114. // itself from a global list in its constructor/destructor (in debug
  115. // builds)
  116. //
  117. template <DEBUGOBJECTID didx> class CCatDLO
  118. {
  119. #ifdef CATDEBUGLIST
  120. public:
  121. CCatDLO()
  122. {
  123. _ASSERT(didx < NUM_DEBUG_LIST_OBJECTS);
  124. AcquireSpinLock(&(g_rgDebugObjectList[didx].spinlock));
  125. g_rgDebugObjectList[didx].dwCount++;
  126. InsertTailList(&(g_rgDebugObjectList[didx].listhead),
  127. &m_le);
  128. ReleaseSpinLock(&(g_rgDebugObjectList[didx].spinlock));
  129. }
  130. virtual ~CCatDLO()
  131. {
  132. AcquireSpinLock(&(g_rgDebugObjectList[didx].spinlock));
  133. g_rgDebugObjectList[didx].dwCount--;
  134. RemoveEntryList(&m_le);
  135. ReleaseSpinLock(&(g_rgDebugObjectList[didx].spinlock));
  136. }
  137. private:
  138. LIST_ENTRY m_le;
  139. #endif // CATDEBUGLIST
  140. };
  141. //
  142. // Handy Macros
  143. // Cat Funct Entry/Exit (mirrors regtrace)
  144. //
  145. #define CatFunctEnterEx( lParam, sz ) \
  146. char *__CatFuncName = sz; \
  147. TraceFunctEnterEx( lParam, sz )
  148. #define CatFunctEnter( sz ) CatFunctEnterEx( (LPARAM)0, sz)
  149. #define CatFunctLeaveEx( lParam ) \
  150. TraceFunctLeaveEx( lParam );
  151. #define CatFunctLeave() CatFunctLeaveEx( (LPARAM)0 )
  152. //
  153. // LOGGING macros --
  154. // These should be used for failures that can result in
  155. // NDRs/CatFailures. It should not be used for functions that may
  156. // fail in normal operation (for example, GetProperty() failing with
  157. // MAILMSG_E_PROPNOTFOUND on a property that is not normally set
  158. // should not be logged!).
  159. //
  160. //
  161. // ERROR_LOG --
  162. // regtrace and eventlog an error (at FILED_ENGINEERING level)
  163. //
  164. #define ERROR_LOG(SzFuncName) { \
  165. ErrorTrace((LPARAM)this, SzFuncName " failed hr %08lx", hr); \
  166. CatLogFuncFailure( \
  167. GetISMTPServerEx(), \
  168. NULL, \
  169. __CatFuncName, \
  170. SzFuncName, \
  171. hr, \
  172. __FILE__, \
  173. __LINE__); \
  174. }
  175. #define ERROR_LOG_STATIC(SzFuncName, Param, pISMTPServerEx) { \
  176. ErrorTrace((LPARAM)Param, SzFuncName " failed hr %08lx", hr); \
  177. CatLogFuncFailure( \
  178. pISMTPServerEx, \
  179. NULL, \
  180. __CatFuncName, \
  181. SzFuncName, \
  182. hr, \
  183. __FILE__, \
  184. __LINE__); \
  185. }
  186. //
  187. // ERROR_CLEANUP_LOG --
  188. // if(FAILED(hr)), regtrace/eventlog an error and goto CLEANUP
  189. //
  190. #define ERROR_CLEANUP_LOG(SzFuncName) \
  191. if(FAILED(hr)) { \
  192. ErrorTrace((LPARAM)this, SzFuncName " failed hr %08lx", hr); \
  193. CatLogFuncFailure( \
  194. GetISMTPServerEx(), \
  195. NULL, \
  196. __CatFuncName, \
  197. SzFuncName, \
  198. hr, \
  199. __FILE__, \
  200. __LINE__); \
  201. goto CLEANUP; \
  202. }
  203. #define ERROR_CLEANUP_LOG_STATIC(SzFuncName, Param, pISMTPServerEx) \
  204. if(FAILED(hr)) { \
  205. ErrorTrace((LPARAM)Param, SzFuncName " failed hr %08lx", hr); \
  206. CatLogFuncFailure( \
  207. pISMTPServerEx, \
  208. NULL, \
  209. __CatFuncName, \
  210. SzFuncName, \
  211. hr, \
  212. __FILE__, \
  213. __LINE__); \
  214. goto CLEANUP; \
  215. }
  216. //
  217. // ERROR_LOG_ADDR
  218. // regtrace/eventlog an error. In the eventlog,
  219. // include the email address correspoding to pItemProps if
  220. // available.
  221. //
  222. #define ERROR_LOG_ADDR(pAddr, SzFuncName) { \
  223. ErrorTrace((LPARAM)this, SzFuncName " failed hr %08lx", hr); \
  224. CatLogFuncFailure( \
  225. GetISMTPServerEx(), \
  226. pAddr, \
  227. __CatFuncName, \
  228. SzFuncName, \
  229. hr, \
  230. __FILE__, \
  231. __LINE__); \
  232. }
  233. #define ERROR_LOG_ADDR_STATIC(pAddr, SzFuncName, Param, pISMTPServerEx) { \
  234. ErrorTrace((LPARAM)Param, SzFuncName " failed hr %08lx", hr); \
  235. CatLogFuncFailure( \
  236. pISMTPServerEx, \
  237. pAddr, \
  238. __CatFuncName, \
  239. SzFuncName, \
  240. hr, \
  241. __FILE__, \
  242. __LINE__); \
  243. }
  244. //
  245. // ERROR_CLEANUP_LOG_ADDR
  246. // if(FAILED(hr)), regtrace/eventlog an error and goto CLEANUP. In
  247. // the eventlog, include the email address correspoding to
  248. // pItemProps if available.
  249. //
  250. #define ERROR_CLEANUP_LOG_ADDR(pAddr, SzFuncName) \
  251. if(FAILED(hr)) { \
  252. ErrorTrace((LPARAM)this, SzFuncName " failed hr %08lx", hr); \
  253. CatLogFuncFailure( \
  254. GetISMTPServerEx(), \
  255. pAddr, \
  256. __CatFuncName, \
  257. SzFuncName, \
  258. hr, \
  259. __FILE__, \
  260. __LINE__); \
  261. goto CLEANUP; \
  262. }
  263. #define ERROR_CLEANUP_LOG_ADDR_STATIC(pAddr, SzFuncName, Param, pISMTPServerEx) \
  264. if(FAILED(hr)) { \
  265. ErrorTrace((LPARAM)Param, SzFuncName " failed hr %08lx", hr); \
  266. CatLogFuncFailure( \
  267. pISMTPServerEx, \
  268. pAddr, \
  269. __CatFuncName, \
  270. SzFuncName, \
  271. hr, \
  272. __FILE__, \
  273. __LINE__); \
  274. goto CLEANUP; \
  275. }
  276. VOID CatLogFuncFailure(
  277. IN ISMTPServerEx *pISMTPServerEx,
  278. IN ICategorizerItem *pICatItem,
  279. IN LPSTR pszFuncNameCaller,
  280. IN LPSTR pszFuncNameCallee,
  281. IN HRESULT hrFailure,
  282. IN LPSTR pszFileName,
  283. IN DWORD dwLineNumber);
  284. HRESULT HrGetAddressStringFromICatItem(
  285. IN ICategorizerItem *pICatItem,
  286. IN DWORD dwcAddressType,
  287. OUT LPSTR pszAddressType,
  288. IN DWORD dwcAddress,
  289. OUT LPSTR pszAddress);
  290. #endif //__CATDEBUG_H__