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.

153 lines
3.4 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2001, Microsoft Corporation
  4. //
  5. // File: DfsSiteNameSupport.hxx
  6. //
  7. // Contents: implements repository for SiteName to DfsSite mappings.
  8. //
  9. //
  10. // History: November, 2001. SupW
  11. //
  12. //-----------------------------------------------------------------------------
  13. #ifndef __DFS_SITE_NAME_SUP__
  14. #define __DFS_SITE_NAME_SUP__
  15. #include <shash.h>
  16. class DfsSite;
  17. typedef struct _DFS_SITENAME_DATA
  18. {
  19. SHASH_HEADER Header;
  20. UNICODE_STRING SiteName; // hash key.
  21. ULONG FirstAccessTime;
  22. DfsSite *pDfsSite; // DfsSite corresonding to the above SiteName.
  23. } DFS_SITE_NAME_DATA, *PDFS_SITE_NAME_DATA;
  24. //
  25. // Default number of hash buckets that the sitename->DfsSite cache
  26. // uses. The assumption is that the average will have no more than 64 sites.
  27. //
  28. #define DFS_DEFAULT_SITE_NAME_SUP_BUCKETS 64
  29. //
  30. // This cache is a repository of DfsSite instances,
  31. // indexed by their site names.
  32. //
  33. class DfsSiteNameSupport
  34. {
  35. protected:
  36. PSHASH_TABLE _pSiteNameTable;
  37. DfsSiteNameSupport()
  38. {
  39. _pSiteNameTable = NULL;
  40. }
  41. virtual DFSSTATUS
  42. Initialize( ULONG NumBuckets = DFS_DEFAULT_SITE_NAME_SUP_BUCKETS );
  43. public:
  44. ~ DfsSiteNameSupport( VOID )
  45. {
  46. if (_pSiteNameTable != NULL)
  47. {
  48. //
  49. // Shash should provide a more efficient way of doing this.
  50. //
  51. InvalidateCache();
  52. ShashTerminateHashTable( _pSiteNameTable );
  53. _pSiteNameTable = NULL;
  54. }
  55. }
  56. static DfsSiteNameSupport *
  57. CreateSiteNameSupport(
  58. DFSSTATUS * pStatus,
  59. ULONG HashBuckets = DFS_DEFAULT_SITE_NAME_SUP_BUCKETS);
  60. virtual DFSSTATUS
  61. StoreSiteInCache(
  62. DfsSite *pSite);
  63. virtual PSHASH_HEADER
  64. LookupIpInHash(
  65. PUNICODE_STRING pSiteName);
  66. DFSSTATUS
  67. RemoveSiteFromCache(
  68. PUNICODE_STRING pSiteName);
  69. ULONG
  70. NumElements()
  71. {
  72. ULONG Elems = 0;
  73. if (_pSiteNameTable != NULL)
  74. {
  75. Elems = _pSiteNameTable->TotalItems;
  76. }
  77. return Elems;
  78. }
  79. VOID
  80. InvalidateCache(VOID);
  81. DFSSTATUS
  82. CreateSiteNameData(
  83. IN DfsSite *pNewSite,
  84. OUT PDFS_SITE_NAME_DATA *ppSiteData);
  85. void
  86. ReleaseSiteNameData(PDFS_SITE_NAME_DATA pData);
  87. static VOID
  88. DfsDeallocateSiteNameData(PVOID pPointer);
  89. DfsSite *
  90. StartSiteEnumerate( SHASH_ITERATOR *pIter )
  91. {
  92. PDFS_SITE_NAME_DATA pData = NULL;
  93. pData = (PDFS_SITE_NAME_DATA)SHashStartEnumerate( pIter, _pSiteNameTable );
  94. if (pData == NULL)
  95. {
  96. return NULL;
  97. }
  98. return pData->pDfsSite;
  99. }
  100. DfsSite *
  101. NextSiteEnumerate( SHASH_ITERATOR *pIter )
  102. {
  103. PDFS_SITE_NAME_DATA pData = NULL;
  104. pData = (PDFS_SITE_NAME_DATA)SHashNextEnumerate( pIter, _pSiteNameTable );
  105. if (pData == NULL)
  106. {
  107. return NULL;
  108. }
  109. return pData->pDfsSite;
  110. }
  111. VOID
  112. FinishSiteEnumerate( SHASH_ITERATOR *pIter )
  113. {
  114. SHashFinishEnumerate( pIter, _pSiteNameTable);
  115. }
  116. VOID
  117. InvalidateAgedSites( VOID );
  118. };
  119. #endif // __DFS_SITE_NAME_SUP_