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.

180 lines
6.2 KiB

  1. #ifndef _401INC_H_
  2. #define _401INC_H_
  3. namespace ie401
  4. {
  5. // on content upgrade, we need to check if the MUST_REVALIDATE_SZ symbol
  6. //is set in the CACHE_CONTROL_SZ list. This is now represented by the
  7. //MUST_REVALIDATE_CACHE_ENTRY flag in the CacheEntryType.
  8. #define CACHE_CONTROL_SZ "Cache-Control"
  9. #define MUST_REVALIDATE_SZ "must-revalidate"
  10. #define IE401_NOT_A_CACHE_SUBDIRECTORY 255
  11. #define IE401_EDITED_CACHE_ENTRY 0x00000008
  12. // We need to know the offset into a ie401 indexfile to find the offset
  13. //that points to the first hash table. This is at
  14. //_MEMMAP_HEADER_SMALL.dwHashTableOffset.. The following has been cut from
  15. //401 source to calculate that offset.
  16. #define DIR_NAME_SIZE 8
  17. struct CacheDir
  18. {
  19. DWORD nFileCount;
  20. CHAR sDirName[DIR_NAME_SIZE];
  21. };
  22. #define DEFAULT_MAX_DIRS 32
  23. // the ie401_ was prefixed below to prevent a collision with a #define
  24. //in the current code.
  25. #define ie401_NUM_HEADER_DATA_DWORDS 8
  26. struct _MEMMAP_HEADER_SMALL
  27. {
  28. TCHAR FileSignature[(sizeof(TEXT("Client UrlCache MMF Ver 4.7")) / sizeof(TCHAR))];
  29. DWORD FileSize;
  30. DWORD dwHashTableOffset;
  31. DWORD NumUrlInternalEntries;
  32. DWORD NumUrlEntriesAlloced;
  33. // DWORD dwGarbage; // due to /Zp8 struct alignment
  34. LONGLONG CacheLimit;
  35. LONGLONG CacheSize;
  36. LONGLONG ExemptUsage;
  37. DWORD nDirCount;
  38. CacheDir DirArray[DEFAULT_MAX_DIRS];
  39. DWORD dwHeaderData[ie401_NUM_HEADER_DATA_DWORDS];
  40. };
  41. // The rest was cut'n'pasted from 401 source to allow to define
  42. //the structures of the hash entries themselves.
  43. #define SLOT_BITS 6
  44. #define SLOT_COUNT (1 << SLOT_BITS)
  45. #define SLOT_MASK (SLOT_COUNT - 1)
  46. // With 64 slots, the 6 low bits of HASH_ITEM::dwHash are implied by the slot.
  47. // Currently, the low 3 bits are used instead as flags; the other 3 reserved.
  48. // If bit0 clear, the item indicates a URL entry.
  49. // Then bit1 set if locked, bit2 set if trailing redirect slash allowed
  50. // If bit0 set, the item is free or a redirect entry.
  51. // Then bit1 set if free item never used before
  52. // OR bit2 set if a redirect entry
  53. // hash value bits
  54. #define HASH_BIT_NOTURL 0x0001 // bit 0
  55. #define HASH_BIT_LOCK 0x0002 // bit 1
  56. #define HASH_BIT_REDIR 0x0004 // bit 2
  57. #define HASH_BIT_HASGRP 0x0008 // bit 3
  58. #define HASH_BIT_MULTGRP 0x0010 // bit 4
  59. #define HASH_BIT_RESERVED 0x0020 // bit 5
  60. // hash value flag combinations
  61. #define HASH_UNLOCKED 0 // URL entry, not locked
  62. #define HASH_FREE 1 // free item, was once in use
  63. #define HASH_LOCKED 2 // URL entry, locked
  64. #define HASH_END 3 // free item, never used before
  65. #define HASH_UNLOCKED_SLASH 4 // URL entry, not locked, trailing slash redir
  66. #define HASH_REDIR 5 // redirect entry
  67. #define HASH_LOCKED_SLASH 6 // URL entry, locked, trailing slash redir
  68. #define HASH_FLAG_MASK 7 // illegal, used to mask out hash flags
  69. struct FILEMAP_ENTRY
  70. {
  71. DWORD dwSig;
  72. DWORD nBlocks;
  73. };
  74. struct URL_FILEMAP_ENTRY : FILEMAP_ENTRY
  75. {
  76. LONGLONG LastModifiedTime;
  77. LONGLONG LastAccessedTime;
  78. LONGLONG ExpireTime;
  79. LONGLONG FileSize; // should be DWORD
  80. GROUPID GroupId; // should be list
  81. DWORD dwExemptDelta;
  82. DWORD Size; // should be WORD
  83. DWORD UrlNameOffset; // should be WORD
  84. DWORD DirIndex; // should be BYTE
  85. DWORD InternalFileNameOffset; // should be WORD
  86. DWORD CacheEntryType;
  87. DWORD HeaderInfoOffset; // should be WORD
  88. DWORD HeaderInfoSize; // should be WORD
  89. DWORD FileExtensionOffset; // should be WORD
  90. DWORD dostLastSyncTime;
  91. DWORD NumAccessed; // should be WORD
  92. DWORD NumReferences; // should be WORD
  93. DWORD dostFileCreationTime;
  94. };
  95. struct REDIR_FILEMAP_ENTRY : FILEMAP_ENTRY
  96. {
  97. DWORD dwItemOffset; // offset to hash table item of destination URL
  98. DWORD dwHashValue; // destination URL hash value (BUGBUG: collisions?)
  99. char szUrl[4]; // original URL, can occupy more bytes
  100. };
  101. struct HASH_FILEMAP_ENTRY : FILEMAP_ENTRY
  102. {
  103. DWORD dwNext; // offset to next element in list
  104. DWORD nBlock; // sequence number for this block
  105. };
  106. struct HASH_ITEM
  107. {
  108. DWORD dwHash;
  109. DWORD dwOffset;
  110. // methods on hash value flags
  111. DWORD GetValue(void) {return dwHash & ~SLOT_MASK;}
  112. void MarkFree(void) {dwHash = HASH_FREE;}
  113. void SetSlash (void) {dwHash |= HASH_BIT_REDIR;}
  114. void SetRedir (void) {dwHash |= HASH_REDIR;}
  115. BOOL IsLocked(void) {return dwHash & HASH_LOCKED;}
  116. void SetLocked(void) {dwHash |= HASH_LOCKED;}
  117. void ClearLocked(void) {dwHash &= ~HASH_LOCKED;}
  118. void MarkGroup(void) {dwHash |= HASH_BIT_HASGRP;}
  119. void ClearGroup(void) {dwHash &= ~HASH_BIT_HASGRP;}
  120. BOOL HasGroup(void) {return dwHash & HASH_BIT_HASGRP;}
  121. void MarkMultGroup(void) {dwHash |= HASH_BIT_MULTGRP | HASH_BIT_HASGRP;}
  122. void ClearMultGroup(void) {dwHash &= ~HASH_BIT_MULTGRP;}
  123. BOOL HasMultiGroup(void) {return dwHash & HASH_BIT_MULTGRP; }
  124. };
  125. // hash table parameters
  126. #define BYTES_PER_PAGE 4096
  127. #define ITEMS_PER_BUCKET ((BYTES_PER_PAGE - sizeof(HASH_FILEMAP_ENTRY))\
  128. / (SLOT_COUNT * sizeof(HASH_ITEM)))
  129. #define BYTES_PER_TABLE (sizeof(HASH_FILEMAP_ENTRY) \
  130. + SLOT_COUNT * ITEMS_PER_BUCKET * sizeof(HASH_ITEM))
  131. // HashLookupItem bits and flags
  132. #define LOOKUP_BIT_REDIR 1
  133. #define LOOKUP_BIT_CREATE 2
  134. #define LOOKUP_BIT_SPARSE 4 // enable retrieval of partial file entries
  135. #define LOOKUP_URL_NOCREATE 0 // find url entry, don't create new if not found
  136. #define LOOKUP_URL_TRANSLATE 1 // find url entry, translate through redirects
  137. #define LOOKUP_URL_CREATE 2 // find url entry, create new if not found
  138. #define LOOKUP_REDIR_CREATE 3 // find redir entry, create new if not found
  139. #define SIG_FREE 0xbadf00d
  140. #define SIG_ALLOC 0xdeadbeef
  141. #define SIG_HASH ('H'|('A'<<8)|('S'<<16)|('H'<<24))
  142. #define SIG_URL ' LRU' // URL_FILEMAP_ENTRY
  143. #define SIG_REDIR 'RDER' // REDR_FILEMAP_ENTRY
  144. }
  145. #endif