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.

298 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. hash.h
  5. Abstract:
  6. The public definition of response cache hash table.
  7. Author:
  8. Alex Chen (alexch) 28-Mar-2001
  9. Revision History:
  10. --*/
  11. #ifndef _HASH_H_
  12. #define _HASH_H_
  13. #include "cachep.h"
  14. //
  15. // Hash Table definitions
  16. //
  17. typedef struct _HASH_BUCKET *PHASHBUCKET;
  18. typedef struct _HASH_TABLE
  19. {
  20. ULONG Signature; //UL_HASH_TABLE_POOL_TAG
  21. POOL_TYPE PoolType;
  22. SIZE_T NumberOfBytes;
  23. PHASHBUCKET pAllocMem;
  24. PHASHBUCKET pBuckets;
  25. } HASHTABLE, *PHASHTABLE;
  26. #define IS_VALID_HASHTABLE(pHashTable) \
  27. (HAS_VALID_SIGNATURE(pHashTable, UL_HASH_TABLE_POOL_TAG) \
  28. && NULL != (pHashTable)->pAllocMem)
  29. /***************************************************************************++
  30. Routine Description:
  31. Wrapper around RtlEqualUnicodeString
  32. Return Value:
  33. TRUE - Equal
  34. FALSE - NOT Equal
  35. --***************************************************************************/
  36. __inline
  37. BOOLEAN
  38. UlEqualUnicodeString(
  39. IN PWSTR pString1,
  40. IN PWSTR pString2,
  41. IN ULONG StringLength,
  42. IN BOOLEAN CaseInSensitive
  43. )
  44. {
  45. UNICODE_STRING UnicodeString1, UnicodeString2;
  46. ASSERT(StringLength < UNICODE_STRING_MAX_BYTES);
  47. UnicodeString1.Length = (USHORT) StringLength;
  48. UnicodeString2.Length = (USHORT) StringLength;
  49. UnicodeString1.MaximumLength = (USHORT) StringLength + sizeof(WCHAR);
  50. UnicodeString2.MaximumLength = (USHORT) StringLength + sizeof(WCHAR);
  51. UnicodeString1.Buffer = pString1;
  52. UnicodeString2.Buffer = pString2;
  53. return RtlEqualUnicodeString(
  54. &UnicodeString1,
  55. &UnicodeString2,
  56. CaseInSensitive
  57. );
  58. } // UlEqualUnicodeString
  59. /***************************************************************************++
  60. Routine Description:
  61. Similar to UlEqualUnicodeString but the source string is the concatenation
  62. of the two strings.
  63. Return Value:
  64. TRUE - if s1 + s2 == s3
  65. FALSE - NOT Equal
  66. --***************************************************************************/
  67. __inline
  68. BOOLEAN
  69. UlEqualUnicodeStringEx(
  70. IN PWSTR pString1,
  71. IN ULONG String1Length,
  72. IN PWSTR pString2,
  73. IN ULONG String2Length,
  74. IN PWSTR pString3,
  75. IN BOOLEAN CaseInSensitive
  76. )
  77. {
  78. UNICODE_STRING UnicodeString1, UnicodeString2, UnicodeString3;
  79. ASSERT(String1Length < UNICODE_STRING_MAX_BYTES);
  80. ASSERT(String2Length < UNICODE_STRING_MAX_BYTES);
  81. ASSERT((String1Length + String2Length) < UNICODE_STRING_MAX_BYTES);
  82. UnicodeString1.Length = (USHORT) String1Length;
  83. UnicodeString2.Length = (USHORT) String2Length;
  84. UnicodeString3.Length = (USHORT) (String1Length + String2Length);
  85. UnicodeString1.MaximumLength = UnicodeString1.Length + sizeof(WCHAR);
  86. UnicodeString2.MaximumLength = UnicodeString2.Length + sizeof(WCHAR);
  87. UnicodeString3.MaximumLength = UnicodeString3.Length + sizeof(WCHAR);
  88. UnicodeString1.Buffer = pString1;
  89. UnicodeString2.Buffer = pString2;
  90. UnicodeString3.Buffer = pString3;
  91. if (RtlPrefixUnicodeString(
  92. &UnicodeString1,
  93. &UnicodeString3,
  94. CaseInSensitive
  95. ))
  96. {
  97. UNICODE_STRING UnicodeString;
  98. UnicodeString.Length = (USHORT) String2Length;
  99. UnicodeString.MaximumLength = (USHORT) String2Length + sizeof(WCHAR);
  100. UnicodeString.Buffer = (PWSTR) &pString3[String1Length/sizeof(WCHAR)];
  101. //
  102. // Prefix matched see if the rest matches too.
  103. //
  104. return RtlEqualUnicodeString(
  105. &UnicodeString2,
  106. &UnicodeString,
  107. CaseInSensitive
  108. );
  109. }
  110. return FALSE;
  111. } // UlEqualUnicodeStringEx
  112. /***************************************************************************++
  113. Routine Description:
  114. Wrapper around RtlPrefixUnicodeString
  115. Return Value:
  116. TRUE - s1 is Equal of prefix of s2
  117. FALSE - s1 is NOT Equal of prefix of s2.
  118. --***************************************************************************/
  119. __inline
  120. BOOLEAN
  121. UlPrefixUnicodeString(
  122. IN PWSTR pString1,
  123. IN PWSTR pString2,
  124. IN ULONG StringLength,
  125. IN BOOLEAN CaseInSensitive
  126. )
  127. {
  128. UNICODE_STRING UnicodeString1, UnicodeString2;
  129. ASSERT(StringLength < UNICODE_STRING_MAX_BYTES);
  130. UnicodeString1.Length = (USHORT) StringLength;
  131. UnicodeString2.Length = (USHORT) StringLength;
  132. UnicodeString1.MaximumLength = (USHORT) StringLength + sizeof(WCHAR);
  133. UnicodeString2.MaximumLength = (USHORT) StringLength + sizeof(WCHAR);
  134. UnicodeString1.Buffer = pString1;
  135. UnicodeString2.Buffer = pString2;
  136. return RtlPrefixUnicodeString(
  137. &UnicodeString1,
  138. &UnicodeString2,
  139. CaseInSensitive
  140. );
  141. } // UlPrefixUnicodeString
  142. /***************************************************************************++
  143. Routine Description:
  144. Compare two URI_KEYS that have identical URIs upto N character. But not
  145. necessarily have the identical hashes. (case-insensitively)
  146. Arguments:
  147. pUriKey1 : The key that holds the > shortest < length. I.e. the virtual
  148. directory that holds the app.
  149. pUriKey2 : The key that holds the longer (or equal) length. I.e the app
  150. which is under the above virtual directory.
  151. Return Value:
  152. BOOLEAN - TRUE If Key2 is prefix of Key1, otherwise FALSE.
  153. --***************************************************************************/
  154. __inline
  155. BOOLEAN
  156. UlPrefixUriKeys(
  157. IN PURI_KEY pUriKey1,
  158. IN PURI_KEY pUriKey2
  159. )
  160. {
  161. //
  162. // Hash field inside the UriKey is discarded.
  163. //
  164. return ( UlPrefixUnicodeString(
  165. pUriKey1->pUri,
  166. pUriKey2->pUri,
  167. pUriKey1->Length,
  168. TRUE
  169. )
  170. );
  171. }
  172. NTSTATUS
  173. UlInitializeHashTable(
  174. IN OUT PHASHTABLE pHashTable,
  175. IN POOL_TYPE PoolType,
  176. IN LONG HashTableBits
  177. );
  178. VOID
  179. UlTerminateHashTable(
  180. IN PHASHTABLE pHashTable
  181. );
  182. PUL_URI_CACHE_ENTRY
  183. UlGetFromHashTable(
  184. IN PHASHTABLE pHashTable,
  185. IN PVOID pSearchKey
  186. );
  187. PUL_URI_CACHE_ENTRY
  188. UlDeleteFromHashTable(
  189. IN PHASHTABLE pHashTable,
  190. IN PURI_KEY pUriKey,
  191. IN PUL_APP_POOL_PROCESS pProcess
  192. );
  193. NTSTATUS
  194. UlAddToHashTable(
  195. IN PHASHTABLE pHashTable,
  196. IN PUL_URI_CACHE_ENTRY pUriCacheEntry
  197. );
  198. ULONG
  199. UlFilterFlushHashTable(
  200. IN PHASHTABLE pHashTable,
  201. IN PUL_URI_FILTER pFilterRoutine,
  202. IN PVOID pContext
  203. );
  204. VOID
  205. UlClearHashTable(
  206. IN PHASHTABLE pHashTable
  207. );
  208. // For scavenger
  209. ULONG_PTR
  210. UlGetHashTablePages(
  211. VOID
  212. );
  213. #endif // _HASH_H_