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.

162 lines
3.4 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation
  4. //
  5. // File: DfsSiteCache.hxx
  6. //
  7. // Contents: implements the base DFS Site hash class
  8. //
  9. //
  10. // History: July. 10 2001, Author: Rohanp
  11. //
  12. //-----------------------------------------------------------------------------
  13. #ifndef __DFS_SITE_CACHE__
  14. #define __DFS_SITE_CACHE__
  15. #include <shash.h>
  16. class DfsSite;
  17. #define SITE_NOTACCESSED 0
  18. #define SITE_ACCESSED 1
  19. //
  20. // This defines the hash table entry that
  21. // maps an IP address to a DfsSite that
  22. // IP address belongs in.
  23. //
  24. typedef struct _DFS_SITE_DATA
  25. {
  26. SHASH_HEADER Header;
  27. DWORD IpAddress;
  28. ULONG FirstAccessTime;
  29. BOOLEAN InMruList;
  30. LONG Accessed;
  31. LIST_ENTRY ListEntry;
  32. DfsSite *ClientSite; // The site this referrals is coming from.
  33. } DFSSITE_DATA, *PDFSSITE_DATA;
  34. ULONG
  35. DfsHashIpAddress(
  36. void * pDfsAddress);
  37. VOID
  38. DeallocateSiteCacheData(PVOID pPointer );
  39. int
  40. CompareSiteIpAddress(void* pvKey1,
  41. void* pvKey2);
  42. class DfsSiteNameCache
  43. {
  44. public:
  45. ~ DfsSiteNameCache(void)
  46. {
  47. if(m_CritInit)
  48. {
  49. DeleteCriticalSection(&m_Lock);
  50. }
  51. }
  52. DFSSTATUS
  53. CreateSiteData(
  54. IN DWORD IpAddress,
  55. IN DfsSite *pNewSite,
  56. OUT PDFSSITE_DATA *ppSiteData);
  57. PSHASH_HEADER
  58. LookupIpInHash(DWORD IpAddress);
  59. void
  60. ReleaseSiteCacheData(PDFSSITE_DATA pData);
  61. DFSSTATUS
  62. StoreSiteInCache(
  63. DWORD IpAddress,
  64. DfsSite *ppSite,
  65. BOOLEAN IsRefresh = FALSE);
  66. DFSSTATUS
  67. DfsInitializeSiteCache(void);
  68. BOOLEAN
  69. IsTimeToRefresh(PDFSSITE_DATA pSiteData);
  70. DFSSTATUS
  71. DfsGetSiteForClient(PDFSSITE_DATA pSiteData,
  72. LPWSTR **SiteNamesArray);
  73. DFSSTATUS
  74. RefreshSiteData(void);
  75. DFSSTATUS
  76. ResetSiteData(PDFSSITE_DATA pExistingData);
  77. DFSSTATUS
  78. InsertInMruList(PDFSSITE_DATA SiteStructure);
  79. DFSSTATUS
  80. MoveToFrontOfMruList(PDFSSITE_DATA SiteStructure);
  81. DFSSTATUS
  82. RemoveFromMruList(PDFSSITE_DATA SiteStructure);
  83. DFSSTATUS
  84. DeleteSiteData(PDFSSITE_DATA pSiteStructure);
  85. DFSSTATUS
  86. RemoveAndDeleteSiteData(PDFSSITE_DATA SiteStructure);
  87. BOOLEAN
  88. ResetSiteAccessMask(PDFSSITE_DATA SiteStructure)
  89. {
  90. LONG RetVal = SITE_NOTACCESSED;
  91. RetVal = InterlockedCompareExchange(&SiteStructure->Accessed,
  92. SITE_NOTACCESSED,
  93. SITE_ACCESSED);
  94. return (RetVal == SITE_ACCESSED) ? TRUE : FALSE;
  95. }
  96. static DfsSiteNameCache *
  97. CreateSiteHashTable(DFSSTATUS * pStatus);
  98. private:
  99. DfsSiteNameCache(DFSSTATUS * pStatus)
  100. {
  101. DFSSTATUS Status = ERROR_SUCCESS;
  102. pSiteTable = NULL;
  103. m_CritInit = FALSE;
  104. InitializeListHead(&MruList);
  105. m_CritInit = InitializeCriticalSectionAndSpinCount( &m_Lock, DFS_CRIT_SPIN_COUNT);
  106. if(!m_CritInit)
  107. {
  108. Status = GetLastError();
  109. }
  110. *pStatus = Status;
  111. }
  112. PSHASH_TABLE pSiteTable;
  113. LIST_ENTRY MruList;
  114. CRITICAL_SECTION m_Lock;
  115. BOOL m_CritInit;
  116. };
  117. #endif // __DFS_SITE_CACHE__