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.

106 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name: hashutil.hxx
  4. Abstract:
  5. Interfaces to hashing functions. Assumes access is serialized.
  6. HashLookupItem - finds and validates URL entry
  7. HashGetNextItem - enumerates but does not validate URL entries
  8. Author:
  9. Rajeev Dujari (rajeevd) 04-Nov-1996
  10. --*/
  11. #define SLOT_BITS 6
  12. #define SLOT_COUNT (1 << SLOT_BITS)
  13. #define SLOT_MASK (SLOT_COUNT - 1)
  14. // With 64 slots, the 6 low bits of HASH_ITEM::dwHash are implied by the slot.
  15. // Currently, the low 3 bits are used instead as flags; the other 3 reserved.
  16. // If bit0 clear, the item indicates a URL entry.
  17. // Then bit1 set if locked, bit2 set if trailing redirect slash allowed
  18. // If bit0 set, the item is free or a redirect entry.
  19. // Then bit1 set if free item never used before
  20. // OR bit2 set if a redirect entry
  21. // hash value bits
  22. #define HASH_BIT_NOTURL 0x0001 // bit 0
  23. #define HASH_BIT_LOCK 0x0002 // bit 1
  24. #define HASH_BIT_REDIR 0x0004 // bit 2
  25. #define HASH_BIT_HASGRP 0x0008 // bit 3
  26. #define HASH_BIT_MULTGRP 0x0010 // bit 4
  27. #define HASH_BIT_RESERVED 0x0020 // bit 5
  28. // hash value flag combinations
  29. #define HASH_UNLOCKED 0 // URL entry, not locked
  30. #define HASH_FREE 1 // free item, was once in use
  31. #define HASH_LOCKED 2 // URL entry, locked
  32. #define HASH_END 3 // free item, never used before
  33. #define HASH_UNLOCKED_SLASH 4 // URL entry, not locked, trailing slash redir
  34. #define HASH_REDIR 5 // redirect entry
  35. #define HASH_LOCKED_SLASH 6 // URL entry, locked, trailing slash redir
  36. #define HASH_FLAG_MASK 7 // illegal, used to mask out hash flags
  37. struct HASH_ITEM
  38. {
  39. DWORD dwHash;
  40. DWORD dwOffset;
  41. // methods on hash value flags
  42. DWORD GetValue(void) {return dwHash & ~SLOT_MASK;}
  43. void MarkFree(void) {dwHash = HASH_FREE;}
  44. void SetSlash (void) {dwHash |= HASH_BIT_REDIR;}
  45. void SetRedir (void) {dwHash |= HASH_REDIR;}
  46. BOOL IsLocked(void) {return dwHash & HASH_LOCKED;}
  47. void SetLocked(void) {dwHash |= HASH_LOCKED;}
  48. void ClearLocked(void) {dwHash &= ~HASH_LOCKED;}
  49. void MarkGroup(void) {dwHash |= HASH_BIT_HASGRP;}
  50. void ClearGroup(void) {dwHash &= ~HASH_BIT_HASGRP;}
  51. BOOL HasGroup(void) {return dwHash & HASH_BIT_HASGRP;}
  52. void MarkMultGroup(void) {dwHash |= HASH_BIT_MULTGRP | HASH_BIT_HASGRP;}
  53. void ClearMultGroup(void) {dwHash &= ~HASH_BIT_MULTGRP;}
  54. BOOL HasMultiGroup(void) {return dwHash & HASH_BIT_MULTGRP; }
  55. };
  56. // HashLookupItem bits and flags
  57. #define LOOKUP_BIT_REDIR 1
  58. #define LOOKUP_BIT_CREATE 2
  59. #define LOOKUP_BIT_SPARSE 4 // enable retrieval of partial file entries
  60. #define LOOKUP_BIT_DONT_FOLLOW 8 // look up only once
  61. #define LOOKUP_URL_NOCREATE 0 // find url entry, don't create new if not found
  62. #define LOOKUP_URL_TRANSLATE 1 // find url entry, translate through redirects
  63. #define LOOKUP_URL_CREATE 2 // find url entry, create new if not found
  64. #define LOOKUP_REDIR_CREATE 3 // find redir entry, create new if not found
  65. #define LOOKUP_URL_DONT_FOLLOW 8 // find the 0-entry for the url
  66. BOOL // returns TRUE if found
  67. PUBLIC
  68. HashLookupItem
  69. (
  70. IN LPVOID pAllocObj, // allocator object
  71. IN LPBYTE pBase, // base for all offsets
  72. IN OUT LPDWORD pdwTableOffset, // offset of first hash table section
  73. IN LPCSTR pszKey, // key to search for
  74. IN DWORD dwFlags, // flags as defined above
  75. /////////////////////////////////////////////////////////////////////////////
  76. // WARNING: if LOOKUP_*_CREATE set, the file might be grown and remapped //
  77. // so all pointers into the file must be recalculated from their offsets! //
  78. /////////////////////////////////////////////////////////////////////////////
  79. OUT HASH_ITEM** ppItem // item if found or free slot
  80. );
  81. HASH_ITEM*
  82. PUBLIC
  83. HashGetNextItem
  84. (
  85. IN LPVOID pAllocObj, // allocator object
  86. IN LPBYTE pBase, // base for all offsets
  87. IN OUT LPDWORD pdwItemOffset, // current item offset
  88. IN DWORD dwFlags // include redirects?
  89. );