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.

263 lines
6.1 KiB

  1. #ifndef __DFS_SITE__
  2. #define __DFS_SITE__
  3. #include <DfsGeneric.hxx>
  4. #include <DfsSiteCostCache.hxx>
  5. extern "C" {
  6. extern ULONG
  7. SHashComputeHashValue(void* lpv);
  8. };
  9. //+----------------------------------------------------------------------------
  10. //
  11. // Class: DfsSite
  12. //
  13. // This encapsulates the DFS notion of a Site. It knows its RDN, and given
  14. // a set of target sites, it can generate its cost matrix.
  15. //
  16. //-----------------------------------------------------------------------------
  17. class DfsSite : public DfsGeneric
  18. {
  19. private:
  20. UNICODE_STRING _SiteName; // RDN of this site
  21. DfsSiteCostSupport *_pSiteCostSupport;// Set of destination sites we know the costs for
  22. ULONG _HashValue; // Cached hash value of the sitename.
  23. //
  24. // Use the lookup-table based quick hash
  25. // that comes with the shash table. We
  26. // have a separate callback for HashFunc because
  27. // we compute this only once.
  28. //
  29. VOID
  30. CalcHash()
  31. {
  32. _HashValue = SHashComputeHashValue( (void *)&_SiteName );
  33. }
  34. public:
  35. DfsSite( VOID )
  36. : DfsGeneric( DFS_OBJECT_TYPE_SITE )
  37. {
  38. RtlInitUnicodeString( &_SiteName, NULL );
  39. _pSiteCostSupport = NULL;
  40. _HashValue = 0;
  41. InterlockedIncrement( &DfsServerGlobalData.NumDfsSites );
  42. }
  43. //
  44. // Static function meant to differentiate new operator errors
  45. // and Initialization errors.
  46. //
  47. static DfsSite *
  48. CreateDfsSite(
  49. DFSSTATUS * pStatus,
  50. PUNICODE_STRING pSiteName = NULL)
  51. {
  52. DfsSite * pSite = NULL;
  53. DFSSTATUS Status = ERROR_SUCCESS;
  54. UNICODE_STRING TempName;
  55. pSite = new DfsSite();
  56. if(pSite == NULL)
  57. {
  58. Status = ERROR_NOT_ENOUGH_MEMORY;
  59. }
  60. else
  61. {
  62. //
  63. // It's legit to get null site names.
  64. // The DfsSite will make a copy of what send,
  65. // and a NULL sitename will have get just a UNICODE_NULL
  66. //
  67. if (pSiteName == NULL)
  68. {
  69. RtlInitUnicodeString( &TempName, NULL );
  70. pSiteName = &TempName;
  71. }
  72. Status = pSite->Initialize( pSiteName );
  73. if(Status != ERROR_SUCCESS)
  74. {
  75. pSite->ReleaseReference();
  76. pSite = NULL;
  77. }
  78. }
  79. *pStatus = Status;
  80. return pSite;
  81. }
  82. DFSSTATUS
  83. Initialize(
  84. IN PUNICODE_STRING pSiteName );
  85. ~DfsSite( VOID )
  86. {
  87. // We own SiteCostSupprt exclusively, so no need to refcount it.
  88. if (_pSiteCostSupport != NULL)
  89. {
  90. delete _pSiteCostSupport;
  91. }
  92. if (_SiteName.Buffer != NULL)
  93. {
  94. RtlFreeUnicodeString( &_SiteName );
  95. RtlInitUnicodeString( &_SiteName, NULL );
  96. }
  97. InterlockedDecrement( &DfsServerGlobalData.NumDfsSites );
  98. }
  99. DFSSTATUS
  100. GetRealSiteCost(
  101. DfsSite *DestinationSite,
  102. PULONG pCost);
  103. VOID
  104. GetDefaultSiteCost(
  105. IN DfsSite *DestinationSite,
  106. OUT PULONG pCost);
  107. inline ULONG
  108. GetMaxCost(
  109. VOID )
  110. {
  111. return DFS_MAX_COST;
  112. }
  113. inline DFSSTATUS
  114. SetCost(
  115. DfsSite *DestinationSite,
  116. ULONG Cost,
  117. DWORD ValidityStatus)
  118. {
  119. DFSSTATUS Status;
  120. DfsSiteCostCache *pCache = NULL;
  121. // This path can be optimized better so that we don't
  122. // do this acquire release during cost generation (when we
  123. // have pre-acquired the reference).
  124. // xxxdfsdev
  125. Status = _pSiteCostSupport->Acquire( &pCache );
  126. if (Status != ERROR_SUCCESS)
  127. return Status;
  128. Status = pCache->SetCost( DestinationSite,
  129. Cost,
  130. ValidityStatus );
  131. _pSiteCostSupport->Release();
  132. return Status;
  133. }
  134. inline const PUNICODE_STRING
  135. SiteName( VOID )
  136. {
  137. return &_SiteName;
  138. }
  139. inline const LPWSTR
  140. SiteNameString( VOID )
  141. {
  142. LPWSTR SiteName = NULL;
  143. if (!IsEmptyString(_SiteName.Buffer))
  144. {
  145. SiteName = _SiteName.Buffer;
  146. }
  147. return SiteName;
  148. }
  149. //
  150. // return the pre-calculated hashvalue
  151. //
  152. inline ULONG
  153. Hash( VOID ) const
  154. {
  155. return _HashValue;
  156. }
  157. DFSSTATUS
  158. RefreshClientSiteName(
  159. DWORD IpAddress);
  160. //
  161. // A referral will generate a cost matrix very soon.
  162. // Take an extra reference on the SiteCost cache
  163. // until it is done with that data.
  164. //
  165. inline DFSSTATUS
  166. StartPrepareForCostGeneration( BOOLEAN DoSiteCosting )
  167. {
  168. DFSSTATUS Status = ERROR_SUCCESS;
  169. DfsSiteCostCache *pCache = NULL;
  170. if (DoSiteCosting)
  171. {
  172. Status = _pSiteCostSupport->Acquire( &pCache );
  173. }
  174. return Status;
  175. }
  176. inline VOID
  177. EndPrepareForCostGeneration( BOOLEAN DoSiteCosting )
  178. {
  179. if (DoSiteCosting)
  180. {
  181. _pSiteCostSupport->Release();
  182. }
  183. }
  184. VOID
  185. DeleteSiteCostCache( VOID )
  186. {
  187. // Release the CostCache.
  188. _pSiteCostSupport->MarkForDeletion();
  189. }
  190. BOOLEAN
  191. IsSiteCostCacheExpired( VOID )
  192. {
  193. return _pSiteCostSupport->IsExpired();
  194. }
  195. };
  196. VOID
  197. DfsIpToDfsSite(
  198. IN char * IpData,
  199. IN ULONG IpLength,
  200. IN USHORT IpFamily,
  201. OUT DfsSite **ppSite);
  202. DFSSTATUS
  203. DfsGetSiteBySiteName(
  204. IN LPWSTR SiteName,
  205. OUT DfsSite **ppSite);
  206. ULONG
  207. DfsHashDfsSite(
  208. IN PVOID pSite);
  209. int
  210. DfsCompareDfsSites(
  211. void* pvKey1,
  212. void* pvKey2);
  213. int
  214. DfsCompareSiteNames(
  215. void* pvKey1,
  216. void* pvKey2);
  217. PVOID
  218. DfsAllocateHashData(ULONG Size );
  219. VOID
  220. DfsDeallocateHashData(PVOID pPointer );
  221. #endif