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.

391 lines
9.4 KiB

  1. //
  2. // ccat.h -- This file contains the class definations for:
  3. // CCategorizer
  4. // CAttributes
  5. // CCIRCULAR_DETECT
  6. //
  7. // Created:
  8. // Sep 3, 1996 -- Alex Wetmore (awetmore)
  9. // Changes:
  10. //// jstamerj 980227 14:13:42: Modified for Platinum categorizer
  11. #ifndef __CCAT_H__
  12. #define __CCAT_H__
  13. #include <windows.h>
  14. #include <transmem.h>
  15. #include <listmacr.h>
  16. #include "cat.h"
  17. #include "cattype.h"
  18. #include "idstore.h"
  19. #include "catdefs.h"
  20. #include "spinlock.h"
  21. #include "catperf.h"
  22. #define DEFAULT_VIRTUAL_SERVER_INSTANCES 10
  23. #define MAX_FULL_EMAIL CAT_MAX_INTERNAL_FULL_EMAIL
  24. #define MAX_ENUM_RESULT 100
  25. // maximum number of times to resolve forwarding addresses on a given address
  26. // before giving up and realizing that its a loop
  27. #define MAX_FORWARD_ITERATIONS 25
  28. #define AB_HASHFILENAME "route.hsh"
  29. VOID AsyncResolveCompletion(LPVOID pContext);
  30. VOID AsyncIMsgCatCompletion(LPVOID pContext);
  31. #define NUM_SYSTEM_CCATADDR_PROPIDS 2
  32. BOOL FIsHResultRetryable(IN HRESULT hr);
  33. //
  34. // the address book
  35. //
  36. CatDebugClass(CCategorizer)
  37. {
  38. public:
  39. CCategorizer();
  40. ~CCategorizer();
  41. //
  42. // Lifetime refcounting functions
  43. //
  44. LONG AddRef();
  45. LONG Release();
  46. VOID ReleaseAndWaitForDestruction();
  47. //
  48. // Initialize
  49. //
  50. HRESULT Initialize(
  51. PCCATCONFIGINFO pConfigInfo,
  52. DWORD dwICatItemPropIDs,
  53. DWORD dwICatListResolvePropIDs);
  54. //
  55. // Simple method to make sure the string terminates before
  56. // the max length, and the string points to readable memory.
  57. //
  58. BOOL VerifyStringLength(LPSTR szString, DWORD dwMaxLength);
  59. HRESULT AsyncResolveIMsg(IUnknown *pImsg,
  60. PFNCAT_COMPLETION pfnCatCompletion,
  61. LPVOID pContext);
  62. HRESULT AsyncResolveDLs( IUnknown *pImsg,
  63. PFNCAT_COMPLETION pfnCatCompletion,
  64. LPVOID pContext,
  65. BOOL fMatchOnly,
  66. PBOOL pfMatch,
  67. CAT_ADDRESS_TYPE CAType,
  68. LPSTR pszAddress);
  69. //
  70. // cancel all outstanding long running calls on other threads
  71. //
  72. void Cancel();
  73. //
  74. // Shutdown the address book
  75. //
  76. HRESULT Shutdown(void);
  77. //
  78. // Method to access EmailIDStore
  79. //
  80. CEmailIDStore<CCatAddr> *GetEmailIDStore() {
  81. return m_pStore;
  82. }
  83. //
  84. // Method to access our default SMTP domain
  85. //
  86. LPSTR GetDefaultSMTPDomain() {
  87. return m_ConfigInfo.pszDefaultDomain;
  88. }
  89. VOID CatCompletion(
  90. PFNCAT_COMPLETION pfnCatCOmpletion,
  91. HRESULT hr,
  92. LPVOID pContext,
  93. IUnknown *pIMsg,
  94. IUnknown **rgpIMsg);
  95. VOID GetPerfCounters(
  96. PCATPERFBLOCK pCatPerfBlock)
  97. {
  98. //
  99. // Fill in the global LDAP perf counters on demand
  100. //
  101. CopyMemory(&(GetPerfBlock()->LDAPPerfBlock), &g_LDAPPerfBlock, sizeof(CATLDAPPERFBLOCK));
  102. CopyMemory(pCatPerfBlock, GetPerfBlock(), sizeof(CATPERFBLOCK));
  103. }
  104. VOID SetNextCCategorizer(
  105. CCategorizer *pCCat)
  106. {
  107. _ASSERT(m_pCCatNext == NULL);
  108. m_pCCatNext = pCCat;
  109. m_pCCatNext->AddRef();
  110. }
  111. VOID PrepareForShutdown()
  112. {
  113. m_fPrepareForShutdown = TRUE;
  114. Cancel();
  115. }
  116. private:
  117. //
  118. // make sure that an email address is valid
  119. //
  120. BOOL VerifyEmailAddress(LPSTR szEmail);
  121. BOOL VerifyDomainName(LPSTR szDomain);
  122. //
  123. // Do the default processing of OnCatRegister
  124. //
  125. HRESULT Register();
  126. //
  127. // Helper routine to set all schema parameters in ICatParams based
  128. // on a particular schema type
  129. //
  130. HRESULT RegisterSchemaParameters(LPSTR pszSchema);
  131. //
  132. // Routine to retrieve the ICatItem propID reserved for ptr to a
  133. // CCatAddr
  134. //
  135. DWORD GetICatItemCCatAddrPropId()
  136. {
  137. return m_dwICatParamSystemProp_CCatAddr;
  138. }
  139. //
  140. // PropId we use to build a list of CCatAddr prior to the first
  141. // resolution (we can't resolve as we go because asyncctx needs to
  142. // be pre-initialized with the number of top level resolves
  143. //
  144. DWORD GetICatItemChainPropId()
  145. {
  146. return m_dwICatParamSystemProp_CCatAddr + 1;
  147. }
  148. //
  149. // Routine to retrieve ISMTPServer for this virtual server
  150. //
  151. ISMTPServer *GetISMTPServer()
  152. {
  153. return m_ConfigInfo.pISMTPServer;
  154. }
  155. ISMTPServerEx *GetISMTPServerEx()
  156. {
  157. return m_pISMTPServerEx;
  158. }
  159. //
  160. // Routine to retrieve the domain config interface for this virtual server
  161. //
  162. ICategorizerDomainInfo *GetIDomainInfo()
  163. {
  164. return m_ConfigInfo.pIDomainInfo;
  165. }
  166. //
  167. // Retrieve the cat flags for this virtual server
  168. //
  169. DWORD GetCatFlags()
  170. {
  171. return m_ConfigInfo.dwCatFlags;
  172. }
  173. public:
  174. //
  175. // A special DWORD that enables/disables cat for this VS
  176. //
  177. BOOL IsCatEnabled()
  178. {
  179. //
  180. // Check the enable/disable DWORD (DsUseCat) as well as
  181. // dwCatFlags (at least one flag must be set or we're still
  182. // disabled)
  183. //
  184. return ((m_ConfigInfo.dwEnable != 0) &&
  185. (m_ConfigInfo.dwCatFlags != 0));
  186. }
  187. private:
  188. //
  189. // Copy in a config structure during initialization
  190. //
  191. HRESULT CopyCCatConfigInfo(PCCATCONFIGINFO pConfigInfo);
  192. //
  193. // Releae all memory and interfaces held by the ConfigInfo struct
  194. //
  195. VOID ReleaseConfigInfo();
  196. //
  197. // Helper routine to copy paramters
  198. //
  199. HRESULT SetICatParamsFromConfigInfo();
  200. //
  201. // Access to our config struct
  202. //
  203. PCCATCONFIGINFO GetCCatConfigInfo()
  204. {
  205. return &m_ConfigInfo;
  206. }
  207. ICategorizerParametersEx *GetICatParams()
  208. {
  209. return m_pICatParams;
  210. }
  211. DWORD GetNumCatItemProps()
  212. {
  213. return m_cICatParamProps;
  214. }
  215. DWORD GetNumCatListResolveProps()
  216. {
  217. return m_cICatListResolveProps;
  218. }
  219. //
  220. // Delayed initialize function
  221. //
  222. HRESULT DelayedInitialize();
  223. //
  224. // Do delayed initialize if not already done
  225. //
  226. HRESULT DelayedInitializeIfNecessary();
  227. PCATPERFBLOCK GetPerfBlock()
  228. {
  229. return &m_PerfBlock;
  230. }
  231. #define SIGNATURE_CCAT ((DWORD)'tacC')
  232. #define SIGNATURE_CCAT_INVALID ((DWORD)'XacC')
  233. DWORD m_dwSignature;
  234. //
  235. // Increment completion counters based on the list resolve status
  236. //
  237. HRESULT HrAdjustCompletionCounters(
  238. HRESULT hrListResolveStatus,
  239. IUnknown *pIMsg,
  240. IUnknown **rgpIMsg);
  241. BOOL fIsShuttingDown()
  242. {
  243. return m_fPrepareForShutdown;
  244. }
  245. //
  246. // ref count
  247. //
  248. LONG m_lRefCount;
  249. LONG m_lDestructionWaiters;
  250. BOOL m_fPrepareForShutdown;
  251. HANDLE m_hShutdownEvent;
  252. //
  253. // this is the pointer to the underlying EmailID store object.
  254. //
  255. CEmailIDStore<CCatAddr> *m_pStore;
  256. //
  257. // ICategorizerParametersEx -- configuration information for this
  258. // virtual server
  259. //
  260. ICategorizerParametersEx *m_pICatParams;
  261. //
  262. // Number of properties we need to allocate in each ICatParams
  263. //
  264. DWORD m_cICatParamProps;
  265. //
  266. // Number of properties we need to allocate in each ICatListResolve
  267. //
  268. DWORD m_cICatListResolveProps;
  269. //
  270. // The property ID in an ICategorizerItem used for CCatAddr *
  271. //
  272. DWORD m_dwICatParamSystemProp_CCatAddr;
  273. //
  274. // Configuration parameters passed in
  275. //
  276. CCATCONFIGINFO m_ConfigInfo;
  277. //
  278. // One of the following values:
  279. // CAT_S_NOT_INITIALIED: Delayed initialize has not yet been done
  280. // CAT_E_INIT_FAILED: Delayed initialize failed
  281. // S_OK: Initialized okay
  282. //
  283. HRESULT m_hrDelayedInit;
  284. //
  285. // Keep track of what we have initialized
  286. //
  287. DWORD m_dwInitFlags;
  288. #define INITFLAG_REGISTER 0x0001
  289. #define INITFLAG_REGISTEREVENT 0x0002
  290. #define INITFLAG_STORE 0x0004
  291. CRITICAL_SECTION m_csInit;
  292. //
  293. // A list to keep track of all outstanding list resolves
  294. //
  295. SPIN_LOCK m_PendingResolveListLock;
  296. LIST_ENTRY m_ListHeadPendingResolves;
  297. //
  298. // Refcounted pointer to a CCategorizer with a newer config
  299. //
  300. CCategorizer *m_pCCatNext;
  301. //
  302. // ISMTPServerEx interface pointer; if available
  303. //
  304. ISMTPServerEx *m_pISMTPServerEx;
  305. //
  306. // Performance counters
  307. //
  308. CATPERFBLOCK m_PerfBlock;
  309. VOID RemovePendingListResolve(
  310. CICategorizerListResolveIMP *pListResolve);
  311. VOID AddPendingListResolve(
  312. CICategorizerListResolveIMP *pListResolve);
  313. VOID CancelAllPendingListResolves(
  314. HRESULT hrReason = HRESULT_FROM_WIN32(ERROR_CANCELLED));
  315. friend VOID AsyncIMsgCatCompletion(LPVOID pContext);
  316. friend HRESULT MailTransport_Default_CatRegister(
  317. HRESULT hrStatus,
  318. PVOID pvContext);
  319. friend class CICategorizerListResolveIMP;
  320. friend class CICategorizerDLListResolveIMP;
  321. friend class CCatAddr;
  322. friend class CABContext;
  323. };
  324. #endif //__CCAT_H__