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.

393 lines
8.0 KiB

  1. #ifndef _URLINFO_HXX_
  2. #define _URLINFO_HXX_
  3. #include "usercache.hxx"
  4. class W3_URL_INFO_KEY : public CACHE_KEY
  5. {
  6. public:
  7. W3_URL_INFO_KEY()
  8. : _strKey( _achKey, sizeof( _achKey ) ),
  9. _pszKey( NULL ),
  10. _cchKey( 0 ),
  11. _cchSitePrefix( 0 )
  12. {
  13. }
  14. HRESULT
  15. CreateCacheKey(
  16. WCHAR * pszKey,
  17. DWORD cchKey,
  18. DWORD cchSitePrefix,
  19. BOOL fCopy
  20. );
  21. BOOL
  22. QueryIsEqual(
  23. const CACHE_KEY * pCompareKey
  24. ) const
  25. {
  26. W3_URL_INFO_KEY * pUriKey = (W3_URL_INFO_KEY*) pCompareKey;
  27. DBG_ASSERT( pUriKey != NULL );
  28. return _cchKey == pUriKey->_cchKey &&
  29. !wcscmp( _pszKey, pUriKey->_pszKey );
  30. }
  31. STRU *
  32. QueryMetadataPath(
  33. VOID
  34. )
  35. {
  36. return &_strKey;
  37. }
  38. WCHAR *
  39. QueryUrl(
  40. VOID
  41. ) const
  42. {
  43. return _pszKey + _cchSitePrefix;
  44. }
  45. DWORD
  46. QueryKeyHash(
  47. VOID
  48. ) const
  49. {
  50. return HashString( _pszKey );
  51. }
  52. private:
  53. WCHAR _achKey[ 64 ];
  54. STRU _strKey;
  55. WCHAR * _pszKey;
  56. DWORD _cchSitePrefix;
  57. DWORD _cchKey;
  58. };
  59. #define W3_URL_INFO_SIGNATURE 'TIRU'
  60. #define W3_URL_INFO_FREE_SIGNATURE 'xiru'
  61. class W3_URL_INFO : public CACHE_ENTRY
  62. {
  63. public:
  64. W3_URL_INFO( OBJECT_CACHE * pObjectCache,
  65. W3_METADATA * pMetaData )
  66. : CACHE_ENTRY( pObjectCache ),
  67. _dwSignature( W3_URL_INFO_SIGNATURE ),
  68. _pMetaData( pMetaData ),
  69. _pFileInfo( NULL ),
  70. _strPhysicalPath( _achPhysicalPath, sizeof( _achPhysicalPath ) ),
  71. _strPathInfo( _achPathInfo, sizeof( _achPathInfo ) ),
  72. _strProcessedUrl( _achProcessedUrl, sizeof( _achProcessedUrl ) ),
  73. _strUrlTranslated( _achUrlTranslated, sizeof( _achUrlTranslated ) ),
  74. _pScriptMapEntry( NULL ),
  75. _Gateway( GATEWAY_UNKNOWN ),
  76. _pUrlInfoPathTranslated( NULL ),
  77. _fDefaultMimeMap( FALSE )
  78. {
  79. }
  80. CACHE_KEY *
  81. QueryCacheKey(
  82. VOID
  83. ) const
  84. {
  85. return (CACHE_KEY*) &_cacheKey;
  86. }
  87. STRU *
  88. QueryMetadataPath(
  89. VOID
  90. )
  91. {
  92. return _cacheKey.QueryMetadataPath();
  93. }
  94. BOOL
  95. QueryIsOkToFlushDirmon(
  96. WCHAR *,
  97. DWORD
  98. )
  99. {
  100. DBG_ASSERT( FALSE );
  101. return FALSE;
  102. }
  103. BOOL
  104. CheckSignature(
  105. VOID
  106. ) const
  107. {
  108. return _dwSignature == W3_URL_INFO_SIGNATURE;
  109. }
  110. HRESULT
  111. Create(
  112. STRU & strUrl,
  113. STRU & strMetadataPath
  114. );
  115. VOID *
  116. operator new(
  117. #if DBG
  118. size_t size
  119. #else
  120. size_t
  121. #endif
  122. )
  123. {
  124. DBG_ASSERT( size == sizeof( W3_URL_INFO ) );
  125. DBG_ASSERT( sm_pachW3UrlInfo != NULL );
  126. return sm_pachW3UrlInfo->Alloc();
  127. }
  128. VOID
  129. operator delete(
  130. VOID * pW3UrlInfo
  131. )
  132. {
  133. DBG_ASSERT( pW3UrlInfo != NULL );
  134. DBG_ASSERT( sm_pachW3UrlInfo != NULL );
  135. DBG_REQUIRE( sm_pachW3UrlInfo->Free( pW3UrlInfo ) );
  136. }
  137. HRESULT
  138. GetFileInfo(
  139. CACHE_USER * pOpeningUser,
  140. BOOL fDoCache,
  141. W3_FILE_INFO ** ppFileInfo,
  142. FILE_CACHE_ASYNC_CONTEXT * pAsyncContext,
  143. BOOL * pfHandledSync,
  144. BOOL fAllowNoBuffering,
  145. BOOL fCheckForExistenceOnly
  146. );
  147. W3_METADATA *
  148. QueryMetaData(
  149. VOID
  150. ) const
  151. {
  152. return _pMetaData;
  153. }
  154. STRU *
  155. QueryPhysicalPath(
  156. VOID
  157. )
  158. {
  159. return &_strPhysicalPath;
  160. }
  161. STRU *
  162. QueryProcessedUrl(
  163. VOID
  164. )
  165. {
  166. return &_strProcessedUrl;
  167. }
  168. WCHAR *
  169. QueryUrl(
  170. VOID
  171. ) const
  172. {
  173. return _cacheKey.QueryUrl();
  174. }
  175. META_SCRIPT_MAP_ENTRY *
  176. QueryScriptMapEntry(
  177. VOID
  178. ) const
  179. {
  180. return _pScriptMapEntry;
  181. }
  182. HRESULT
  183. GetPathTranslated(
  184. W3_CONTEXT * pW3Context,
  185. BOOL fUsePathInfo,
  186. STRU * pstrPathTranslated
  187. );
  188. STRU *
  189. QueryPathInfo(
  190. VOID
  191. )
  192. {
  193. return &_strPathInfo;
  194. }
  195. STRU *
  196. QueryUrlTranslated(
  197. VOID
  198. )
  199. {
  200. return &_strUrlTranslated;
  201. }
  202. STRA *
  203. QueryContentType(
  204. VOID
  205. )
  206. {
  207. return &_strContentType;
  208. }
  209. BOOL
  210. QueryDefaultMimeMap(
  211. VOID
  212. ) const
  213. {
  214. return _fDefaultMimeMap;
  215. }
  216. GATEWAY_TYPE
  217. QueryGateway(
  218. VOID
  219. ) const
  220. {
  221. return _Gateway;
  222. }
  223. HRESULT
  224. ProcessUrl(
  225. STRU & strUrl
  226. );
  227. static
  228. HRESULT
  229. Initialize(
  230. VOID
  231. );
  232. static
  233. VOID
  234. Terminate(
  235. VOID
  236. );
  237. private:
  238. ~W3_URL_INFO()
  239. {
  240. if ( _pFileInfo != NULL )
  241. {
  242. _pFileInfo->DereferenceCacheEntry();
  243. _pFileInfo = NULL;
  244. }
  245. if ( _pMetaData != NULL )
  246. {
  247. _pMetaData->DereferenceCacheEntry();
  248. _pMetaData = NULL;
  249. }
  250. if ( _pUrlInfoPathTranslated != NULL )
  251. {
  252. _pUrlInfoPathTranslated->DereferenceCacheEntry();
  253. _pUrlInfoPathTranslated = NULL;
  254. }
  255. _dwSignature = W3_URL_INFO_FREE_SIGNATURE;
  256. }
  257. DWORD _dwSignature;
  258. STRU _strPhysicalPath;
  259. WCHAR _achPhysicalPath[ 64 ];
  260. STRU _strProcessedUrl;
  261. WCHAR _achProcessedUrl[ 64 ];
  262. STRU _strPathInfo;
  263. WCHAR _achPathInfo[ 64 ];
  264. STRU _strUrlTranslated;
  265. WCHAR _achUrlTranslated[ 64 ];
  266. STRA _strContentType;
  267. META_SCRIPT_MAP_ENTRY * _pScriptMapEntry;
  268. GATEWAY_TYPE _Gateway;
  269. W3_FILE_INFO * _pFileInfo;
  270. W3_METADATA * _pMetaData;
  271. W3_URL_INFO_KEY _cacheKey;
  272. BOOL _fDefaultMimeMap;
  273. CReaderWriterLock3 _PathTranslatedLock;
  274. W3_URL_INFO * _pUrlInfoPathTranslated;
  275. //
  276. // Allocation cache for W3_URL_INFO's
  277. //
  278. static ALLOC_CACHE_HANDLER * sm_pachW3UrlInfo;
  279. //
  280. // Max dots (DoS attack protection)
  281. //
  282. static DWORD sm_cMaxDots;
  283. };
  284. #define DEFAULT_W3_URL_INFO_CACHE_TTL (30)
  285. class W3_URL_INFO_CACHE : public OBJECT_CACHE
  286. {
  287. public:
  288. W3_URL_INFO_CACHE()
  289. {
  290. _fMarkedUnhealthy = FALSE;
  291. }
  292. HRESULT
  293. GetUrlInfo(
  294. W3_CONTEXT * pW3Context,
  295. STRU & strUrl,
  296. W3_URL_INFO ** ppUriEntry
  297. );
  298. WCHAR *
  299. QueryName(
  300. VOID
  301. ) const
  302. {
  303. return L"W3_URL_INFO_CACHE";
  304. }
  305. HRESULT
  306. Initialize(
  307. VOID
  308. );
  309. VOID
  310. Terminate(
  311. VOID
  312. )
  313. {
  314. return W3_URL_INFO::Terminate();
  315. }
  316. private:
  317. W3_URL_INFO_CACHE(const W3_URL_INFO_CACHE &);
  318. void operator=(const W3_URL_INFO_CACHE &);
  319. HRESULT
  320. CreateNewUrlInfo(
  321. W3_CONTEXT * pW3Context,
  322. STRU & strUrl,
  323. STRU & strMetadataPath,
  324. W3_URL_INFO ** ppCacheEntry
  325. );
  326. BOOL _fMarkedUnhealthy;
  327. };
  328. #endif