Source code of Windows XP (NT5)
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.

1088 lines
28 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1994 **/
  4. /**********************************************************************/
  5. /*++
  6. tsunami.hxx
  7. Declares constants, types, and functions for the Core Cache.
  8. FILE HISTORY:
  9. MCourage 10-Dec-1997 Created
  10. --*/
  11. # ifndef _TSUNAMI_HXX_
  12. # define _TSUNAMI_HXX_
  13. extern "C" {
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <uspud.h>
  18. # include <pudebug.h>
  19. # include <reftrace.h>
  20. };
  21. #include <acache.hxx>
  22. /*
  23. * Class and struct declarations
  24. */
  25. class TSVC_CACHE;
  26. class STR;
  27. typedef struct _INETA_CACHE_STATISTICS INETA_CACHE_STATISTICS;
  28. class CFileKey;
  29. /*
  30. * Ref trace support
  31. */
  32. //
  33. // Setting TSUNAMI_REF_DEBUG to a non-zero value will enable reference
  34. // count logging.
  35. //
  36. #if DBG
  37. #define TSUNAMI_REF_DEBUG 1
  38. #else // !DBG
  39. #define TSUNAMI_REF_DEBUG 0
  40. #endif // DBG
  41. #if TSUNAMI_REF_DEBUG
  42. extern PTRACE_LOG g_pFileRefTraceLog;
  43. extern PTRACE_LOG g_pBlobRefTraceLog;
  44. #define TS_FILE_TRACE( refcount ) \
  45. if( g_pFileRefTraceLog != NULL ) { \
  46. WriteRefTraceLog( \
  47. g_pFileRefTraceLog, \
  48. (refcount), \
  49. (this) \
  50. ); \
  51. }
  52. #define TS_FILE_TRACE_EX( refcount, c1, c2, c3 ) \
  53. if( g_pFileRefTraceLog != NULL ) { \
  54. WriteRefTraceLogEx( \
  55. g_pFileRefTraceLog, \
  56. (refcount), \
  57. (this), \
  58. (c1), \
  59. (c2), \
  60. (c3) \
  61. ); \
  62. }
  63. #define TS_BLOB_TRACE( refcount ) \
  64. if( g_pBlobRefTraceLog != NULL ) { \
  65. WriteRefTraceLog( \
  66. g_pBlobRefTraceLog, \
  67. (refcount), \
  68. (this) \
  69. ); \
  70. }
  71. #define TS_BLOB_TRACE_EX( refcount, c1, c2, c3 ) \
  72. if( g_pBlobRefTraceLog != NULL ) { \
  73. WriteRefTraceLogEx( \
  74. g_pBlobRefTraceLog, \
  75. (refcount), \
  76. (this), \
  77. (c1), \
  78. (c2), \
  79. (c3) \
  80. ); \
  81. }
  82. #else // !TSUNAMI_REF_DEBUG
  83. #define TS_FILE_TRACE( refcount )
  84. #define TS_FILE_TRACE_EX( refcount, c1, c2, c3 )
  85. #define TS_BLOB_TRACE( refcount )
  86. #define TS_BLOB_TRACE_EX( refcount, c1, c2, c3 )
  87. #endif // TSUNAMI_REF_DEBUG
  88. //
  89. // Here we define some "magic" context values to more
  90. // easily read the ref logs.
  91. //
  92. #define TS_MAGIC_TIMEOUT ((PVOID)((ULONG_PTR) 0x77770001)) // timeout
  93. #define TS_MAGIC_DELETE ((PVOID)((ULONG_PTR) 0x777700dc)) // delete cached item
  94. #define TS_MAGIC_DELETE_NC ((PVOID)((ULONG_PTR) 0x777700d0)) // delete non-cached item
  95. #define TS_MAGIC_CLOSE ((PVOID)((ULONG_PTR) 0x7777000c)) // Close Handle
  96. #define TS_MAGIC_OPLOCK_2 ((PVOID)((ULONG_PTR) 0x777700b2)) // Oplock break to level 2
  97. #define TS_MAGIC_OPLOCK_0 ((PVOID)((ULONG_PTR) 0x777700b0)) // Oplock break to none
  98. #define TS_MAGIC_OPLOCK_FAIL ((PVOID)((ULONG_PTR) 0x7777008f)) // Couldn't oplock a file
  99. #define TS_MAGIC_ALLOCATE ((PVOID)((ULONG_PTR) 0x7777000a)) // allocate cache object
  100. #define TS_MAGIC_CREATE ((PVOID)((ULONG_PTR) 0x7777008c)) // Create cached file
  101. #define TS_MAGIC_CREATE_NC ((PVOID)((ULONG_PTR) 0x77770080)) // Create non-cached file
  102. #define TS_MAGIC_ACCESS_CHECK ((PVOID)((ULONG_PTR) 0x777700ac)) // Access check
  103. /*
  104. * Symbolic constants
  105. */
  106. #define TS_FILE_INFO_SIGNATURE ((DWORD)'IFST')
  107. #define TS_FREE_FILE_INFO_SIGNATURE ((DWORD)'IFSX')
  108. #define TS_BLOB_SIGNATURE ((DWORD)'BOLB')
  109. #define TS_FREE_BLOB_SIGNATURE ((DWORD)'BOLX')
  110. #define MAX_LENGTH_VIRTUAL_ROOT ( MAX_PATH + 1)
  111. #define MAX_LENGTH_ROOT_ADDR ( 50)
  112. #define INETA_MAX_OPEN_FILE TEXT("OpenFileInCache")
  113. #define INETA_DISABLE_TSUNAMI_CACHING TEXT("DisableMemoryCache")
  114. #define INETA_MAX_CACHED_FILE_SIZE TEXT("MaxCachedFileSize")
  115. #define INETA_MEM_CACHE_SIZE TEXT("MemCacheSize")
  116. #define INETA_ENABLE_SEQUENTIAL_READ TEXT("EnableSequentialRead")
  117. #define INETA_DISABLE_TSUNAMI_SPUD TEXT("DisableCacheOplocks")
  118. #define INETA_ALWAYS_CHECK_FOR_DUPLICATE_LOGON TEXT("AlwaysCheckForDuplicateLogon")
  119. #define INETA_USE_ADVAPI32_LOGON TEXT("UseAdvapi32Logon")
  120. #define INETA_CHECK_CERT_REVOCATION TEXT("CheckCertRevocation")
  121. #define TS_FILE_CACHE_SHUTDOWN_TIMEOUT (10 * 1000)
  122. //
  123. // Modifications to this name should also be made in exe\main.c
  124. //
  125. #define INETA_W3ONLY_NO_AUTH TEXT("W3OnlyNoAuth")
  126. #define INETA_MIN_DEF_FILE_HANDLE 300
  127. #define MAX_SIZE_HTTP_INFO 170
  128. #define INETA_CACHE_USE_ACCESS_CHECK TEXT("CacheSecurityDescriptor")
  129. #define INETA_DEF_CACHE_USE_ACCESS_CHECK TRUE
  130. #define INETA_DEF_MAX_CACHED_FILE_SIZE (256 * 1024)
  131. #define INETA_DEF_MEM_CACHE_SIZE ((DWORDLONG)-1)
  132. #define INETA_DEF_ENABLE_SEQUENTIAL_READ (0)
  133. #define SIZE_PRIVILEGE_SET 128
  134. #define TS_DEFAULT_PATH_SIZE 64
  135. #define SECURITY_DESC_DEFAULT_SIZE 256
  136. #define SECURITY_DESC_GRANULARITY 128
  137. #define RESERVED_DEMUX_START 0x80000000
  138. #define RESERVED_DEMUX_DIRECTORY_LISTING ( RESERVED_DEMUX_START + 1 )
  139. #define RESERVED_DEMUX_ATOMIC_DIRECTORY_GUARD ( RESERVED_DEMUX_START + 2 )
  140. #define RESERVED_DEMUX_OPEN_FILE ( RESERVED_DEMUX_START + 3 )
  141. #define RESERVED_DEMUX_URI_INFO ( RESERVED_DEMUX_START + 4 )
  142. #define RESERVED_DEMUX_PHYSICAL_OPEN_FILE ( RESERVED_DEMUX_START + 5 )
  143. #define RESERVED_DEMUX_FILE_DATA ( RESERVED_DEMUX_START + 6 )
  144. #define RESERVED_DEMUX_QUERY_CACHE ( RESERVED_DEMUX_START + 7 )
  145. #define RESERVED_DEMUX_SSI ( RESERVED_DEMUX_START + 8 )
  146. // The maxium length of an ETag is 16 bytes for the last modified time plus
  147. // one byte for the colon plus 2 bytes for the quotes plus 8 bytes for the
  148. // system change notification number plus one for the trailing NULL, for a
  149. // total of 28 bytes.
  150. #define MAX_ETAG_BUFFER_LENGTH 28
  151. #define TS_CACHING_DESIRED 0x00000001
  152. #define TS_NOT_IMPERSONATED 0x00000002
  153. #define TS_NO_ACCESS_CHECK 0x00000004
  154. #define TS_DONT_CACHE_ACCESS_TOKEN 0x00000008
  155. #define TS_USE_WIN32_CANON 0x00000010
  156. #define TS_FORBID_SHORT_NAMES 0x00000020
  157. //
  158. // Flags applicable to the different servers
  159. //
  160. #define TS_IIS_VALID_FLAGS (TS_CACHING_DESIRED | \
  161. TS_NO_ACCESS_CHECK | \
  162. TS_DONT_CACHE_ACCESS_TOKEN | \
  163. TS_NOT_IMPERSONATED | \
  164. TS_USE_WIN32_CANON | \
  165. TS_FORBID_SHORT_NAMES)
  166. #define TS_PWS_VALID_FLAGS (TS_NOT_IMPERSONATED | \
  167. TS_USE_WIN32_CANON | \
  168. TS_FORBID_SHORT_NAMES)
  169. /*
  170. * Global variables
  171. */
  172. extern BOOL g_fW3OnlyNoAuth;
  173. extern BOOL g_fAlwaysCheckForDuplicateLogon;
  174. extern BOOL g_fUseAdvapi32Logon;
  175. extern BOOL g_fCertCheckForRevocation;
  176. extern BOOL DisableTsunamiCaching;
  177. /*
  178. * Types
  179. */
  180. enum FI_STATE {
  181. FI_UNINITIALIZED,
  182. FI_OPEN,
  183. FI_FLUSHED,
  184. FI_FLUSHED_UNINIT,
  185. FI_CLOSED
  186. };
  187. /*++
  188. Class CFileKey
  189. Contains the hashtable key information for a TS_OPEN_FILE_INFO.
  190. --*/
  191. class CFileKey {
  192. public:
  193. CHAR * m_pszFileName; // The file name in upper-case
  194. DWORD m_cbFileName; // The number of bytes in the file name
  195. // We put the path name here if it fits
  196. CHAR m_achFileNameBuf[TS_DEFAULT_PATH_SIZE];
  197. };
  198. typedef BOOL ( *PCONTEXT_FREE_ROUTINE )( PVOID pvOldBlock );
  199. /*++
  200. Class TS_OPEN_FILE_INFO
  201. This class maintains the raw information related to open file handles
  202. that are cached.
  203. In addition to the file handles themselves, the file attribute information
  204. and handle for the opening user are both cached.
  205. --*/
  206. class TS_OPEN_FILE_INFO {
  207. public:
  208. TS_OPEN_FILE_INFO();
  209. ~TS_OPEN_FILE_INFO( VOID);
  210. BOOL CheckSignature( VOID ) const
  211. { return (m_Signature == TS_FILE_INFO_SIGNATURE); }
  212. BOOL SetFileName(const CHAR * pszFileName);
  213. dllexp BOOL SetHttpInfo( IN PSTR pszDate, int cL );
  214. dllexp BOOL
  215. RetrieveHttpInfo( PSTR pS, int *pcHttpInfo )
  216. {
  217. CheckSignature();
  218. if ( m_cchHttpInfo )
  219. {
  220. memcpy( pS, m_achHttpInfo, m_cchHttpInfo+1 );
  221. *pcHttpInfo = m_cchHttpInfo;
  222. return TRUE;
  223. } else {
  224. return FALSE;
  225. }
  226. }
  227. dllexp HANDLE
  228. QueryFileHandle( VOID);
  229. PBYTE
  230. QueryFileBuffer( VOID) const
  231. { return m_pFileBuffer; }
  232. HANDLE
  233. QueryUser( VOID) const
  234. { return m_hUser; }
  235. dllexp BOOL
  236. IsValid( VOID) const
  237. { return (m_hFile != INVALID_HANDLE_VALUE); }
  238. dllexp BOOL
  239. QuerySize( IN LARGE_INTEGER & liSize) const
  240. {
  241. liSize.LowPart = m_nFileSizeLow;
  242. liSize.HighPart= m_nFileSizeHigh;
  243. return (TRUE);
  244. }
  245. dllexp BOOL
  246. QuerySize( IN LPDWORD lpcbFileSizeLow,
  247. IN LPDWORD lpcbFileSizeHigh = NULL) const
  248. {
  249. if ( lpcbFileSizeLow != NULL) {
  250. *lpcbFileSizeLow = m_nFileSizeLow;
  251. }
  252. if ( lpcbFileSizeHigh != NULL) {
  253. *lpcbFileSizeHigh = m_nFileSizeHigh;
  254. }
  255. return ( TRUE);
  256. } // QuerySize()
  257. dllexp DWORD
  258. QueryAttributes( VOID) const
  259. { return m_FileAttributes; }
  260. PSECURITY_DESCRIPTOR
  261. QuerySecDesc(VOID) const
  262. { return m_pSecurityDescriptor; }
  263. //
  264. // This returns the time with a one second resolution (at best)
  265. //
  266. dllexp BOOL
  267. QueryLastWriteTime( OUT LPFILETIME lpFileTime) const
  268. {
  269. if ( lpFileTime != NULL ) {
  270. *((__int64 *) lpFileTime) = m_CastratedLastWriteTime;
  271. return ( TRUE);
  272. } else {
  273. SetLastError( ERROR_INVALID_PARAMETER);
  274. return ( FALSE);
  275. }
  276. } // QueryLastWriteTime()
  277. dllexp BOOL
  278. WeakETag( void ) const
  279. { return ( m_ETagIsWeak ); }
  280. dllexp PCHAR
  281. QueryETag( void ) const
  282. { return ( (PCHAR)m_achETag ); }
  283. dllexp VOID
  284. MakeStrongETag( void );
  285. dllexp
  286. VOID Print( VOID) const;
  287. //
  288. // Cache only functions
  289. //
  290. const CFileKey * GetKey( void ) const
  291. { return &m_FileKey; }
  292. DWORD GetTTL( void ) const
  293. { return m_TTL; }
  294. VOID DecrementTTL( void )
  295. { DBG_ASSERT(m_TTL != 0); m_TTL--; }
  296. VOID SetFileInfo(
  297. HANDLE hFile,
  298. HANDLE hUser,
  299. PSECURITY_DESCRIPTOR pSecDesc,
  300. DWORD dwSecDescSize
  301. );
  302. VOID SetFileInfo(
  303. PBYTE pFileBuff,
  304. HANDLE hCopyFile,
  305. HANDLE hFile,
  306. HANDLE hUser,
  307. PSECURITY_DESCRIPTOR pSecDesc,
  308. DWORD dwSecDescSize,
  309. PSPUD_FILE_INFORMATION pFileInfo
  310. );
  311. dllexp BOOL AccessCheck( HANDLE hUser, BOOL bCache );
  312. //
  313. // CloseHandle should NOT be called with the lock held.
  314. //
  315. dllexp VOID CloseHandle( void );
  316. VOID AddRef( VOID )
  317. {
  318. LONG cRef = InterlockedIncrement(&m_lRefCount);
  319. TS_FILE_TRACE( cRef );
  320. }
  321. LONG Deref( VOID )
  322. {
  323. TS_FILE_TRACE( m_lRefCount - 1 );
  324. return InterlockedDecrement(&m_lRefCount);
  325. }
  326. //
  327. // As a general rule you should hold the structure
  328. // lock when check these properties, however in
  329. // some situations you can get away without it.
  330. //
  331. // Cached, Flushed, and Initialized are stable. Once they
  332. // are TRUE they will never be FALSE (although
  333. // they can obviously move from FALSE to TRUE).
  334. //
  335. BOOL IsCached( void ) const
  336. { return m_bIsCached; }
  337. BOOL IsFlushed( void ) const
  338. { return ((m_state != FI_UNINITIALIZED)
  339. && (m_state != FI_OPEN)); }
  340. BOOL IsInitialized( void ) const
  341. { return ((m_state != FI_UNINITIALIZED)
  342. && (m_state != FI_FLUSHED_UNINIT)); }
  343. //
  344. // Unlike the other properties, IsCloseable is not
  345. // stable so you ALWAYS have to hold the structure
  346. // lock when you call this function.
  347. //
  348. BOOL IsCloseable( void ) const
  349. { return ((m_state == FI_FLUSHED)
  350. && (m_dwIORefCount == 0)); }
  351. //
  352. // The following functions should only be called when
  353. // the structure has been Locked.
  354. //
  355. DWORD AddRefIO( VOID )
  356. {
  357. m_dwIORefCount++;
  358. m_TTL = 1;
  359. return m_dwIORefCount;
  360. }
  361. DWORD DerefIO( VOID )
  362. {
  363. m_dwIORefCount--;
  364. return m_dwIORefCount;
  365. }
  366. DWORD GetIORefCount( VOID ) const
  367. {
  368. return m_dwIORefCount;
  369. }
  370. VOID SetCached( VOID )
  371. { m_bIsCached = TRUE; }
  372. VOID ClearCached( VOID )
  373. { m_bIsCached = FALSE; }
  374. VOID SetFlushed( VOID )
  375. {
  376. ASSERT( (m_state == FI_UNINITIALIZED)
  377. || (m_state == FI_OPEN) );
  378. if (m_state == FI_UNINITIALIZED) {
  379. m_state = FI_FLUSHED_UNINIT;
  380. } else if (m_state == FI_OPEN) {
  381. m_state = FI_FLUSHED;
  382. }
  383. }
  384. VOID SetInitialized( VOID )
  385. {
  386. ASSERT( (m_state == FI_UNINITIALIZED)
  387. || (m_state == FI_FLUSHED_UNINIT) );
  388. if (m_state == FI_UNINITIALIZED) {
  389. m_state = FI_OPEN;
  390. } else {
  391. m_state = FI_FLUSHED;
  392. }
  393. }
  394. dllexp BOOL SetContext( VOID * pvContext, PCONTEXT_FREE_ROUTINE pfnContextFree );
  395. dllexp PVOID QueryContext( VOID ) const;
  396. VOID FreeContext( VOID );
  397. //
  398. // static methods
  399. //
  400. static BOOL Initialize( DWORD dwMaxFiles );
  401. static VOID Cleanup( void );
  402. static VOID Lock( void );
  403. static VOID Unlock( void );
  404. static void * operator new (size_t s);
  405. static void operator delete(void * psi);
  406. private:
  407. //
  408. // member variables
  409. //
  410. ULONG m_Signature;
  411. //
  412. // File info data
  413. //
  414. HANDLE m_hFile;
  415. HANDLE m_hCopyFile;
  416. PBYTE m_pFileBuffer;
  417. HANDLE m_hUser;
  418. __int64 m_ftLastWriteTime;
  419. __int64 m_CastratedLastWriteTime;
  420. ULONG m_FileAttributes;
  421. ULONG m_nFileSizeLow;
  422. ULONG m_nFileSizeHigh;
  423. DWORD m_cbSecDescMaxSize;
  424. BYTE m_abSecDesc[SECURITY_DESC_DEFAULT_SIZE];
  425. PSECURITY_DESCRIPTOR m_pSecurityDescriptor;
  426. BOOL m_fSecurityDescriptor;
  427. CHAR m_achHttpInfo[MAX_SIZE_HTTP_INFO];
  428. DWORD m_cchHttpInfo;
  429. CHAR m_achETag[MAX_ETAG_BUFFER_LENGTH];
  430. DWORD m_cchETag;
  431. BOOL m_ETagIsWeak;
  432. //
  433. // Cache state
  434. //
  435. CFileKey m_FileKey;
  436. BOOL m_bIsCached;
  437. FI_STATE m_state;
  438. DWORD m_dwIORefCount;
  439. LONG m_lRefCount;
  440. DWORD m_TTL;
  441. //
  442. // SSI hooks
  443. //
  444. PVOID m_pvContext;
  445. PCONTEXT_FREE_ROUTINE m_pfnFreeRoutine;
  446. VOID
  447. TS_OPEN_FILE_INFO::SetFileInfoHelper(
  448. HANDLE hFile,
  449. HANDLE hUser,
  450. PSECURITY_DESCRIPTOR pSecDesc,
  451. DWORD dwSecDescSize
  452. );
  453. //
  454. // Static members
  455. //
  456. static ALLOC_CACHE_HANDLER * sm_pachFileInfos;
  457. static CRITICAL_SECTION sm_cs;
  458. public:
  459. LIST_ENTRY FlushList;
  460. VOID TraceCheckpoint(VOID) {
  461. TS_FILE_TRACE( -m_lRefCount );
  462. }
  463. VOID TraceCheckpointEx(PVOID c1, PVOID c2, PVOID c3) {
  464. TS_FILE_TRACE_EX( -m_lRefCount, c1, c2, c3 );
  465. }
  466. }; // class TS_OPEN_FILE_INFO
  467. typedef TS_OPEN_FILE_INFO * LPTS_OPEN_FILE_INFO;
  468. class CBlobKey;
  469. typedef BOOL ( *PUSER_FREE_ROUTINE )( PVOID pvOldBlock );
  470. class BLOB_HEADER {
  471. public:
  472. ULONG Signature;
  473. BOOL IsCached;
  474. BOOL IsFlushed;
  475. PUSER_FREE_ROUTINE pfnFreeRoutine;
  476. CBlobKey * pBlobKey;
  477. LIST_ENTRY FlushList;
  478. LONG lRefCount;
  479. DWORD TTL;
  480. VOID AddRef( VOID )
  481. {
  482. LONG cRef = InterlockedIncrement(&lRefCount);
  483. TS_BLOB_TRACE( cRef );
  484. }
  485. LONG Deref( VOID )
  486. {
  487. TS_BLOB_TRACE( lRefCount - 1 );
  488. return InterlockedDecrement(&lRefCount);
  489. }
  490. //
  491. // NOTE: I don't think I need these for URI's and dirlists
  492. //
  493. PSECURITY_DESCRIPTOR pSecDesc;
  494. HANDLE hLastSuccessAccessToken;
  495. VOID TraceCheckpoint(VOID) {
  496. TS_BLOB_TRACE( -lRefCount );
  497. }
  498. VOID TraceCheckpointEx(PVOID c1, PVOID c2, PVOID c3) {
  499. TS_BLOB_TRACE_EX( -lRefCount, c1, c2, c3 );
  500. }
  501. };
  502. typedef BLOB_HEADER * PBLOB_HEADER;
  503. /*++
  504. Class W3_URI_INFO
  505. The structure of URI Object information. This stucture contains
  506. pointers to cached meta information about a URI as well as
  507. information about the actual file to which the URI is mapped.
  508. The file information may be extracted with TsCreateFileFromURI.
  509. --*/
  510. #define EXTMAP_UNKNOWN_PTR ((PVOID)( ~0 ))
  511. class W3_URI_INFO
  512. : public BLOB_HEADER
  513. {
  514. public:
  515. BOOL bIsCached;
  516. DWORD dwFileOpenError;
  517. UINT cchName;
  518. PCHAR pszName;
  519. PCHAR pszUnmappedName;
  520. class W3_METADATA *pMetaData;
  521. BOOL bInProcOnly; // The next 2 BOOL are used to check
  522. BOOL bUseAppPathChecked; // when an URI request is runnable only
  523. // in inproc.
  524. //
  525. // private - should not be used outside of cache functions
  526. //
  527. LPTS_OPEN_FILE_INFO pOpenFileInfo;
  528. PVOID pvExtMapInfo; // cache extmap info
  529. };
  530. typedef W3_URI_INFO * PW3_URI_INFO;
  531. typedef int ( __cdecl * PFN_CMP_WIN32_FIND_DATA)
  532. (IN const void * /* PWIN32_FIND_DATA * */ pvFileInfo1,
  533. IN const void * /* PWIN32_FIND_DATA * */ pvFileInfo2);
  534. //
  535. // Following function is to be used by filter function for filtering
  536. // of the files requested. The criteria for matching is user supplied.
  537. // Arguments:
  538. // pFileInfo1 pointer to File Info object under consideration
  539. // pContext user supplied context for the Filter Function
  540. // Return values:
  541. // 0 indicates that there is no match of context to FileInfo ==> filter
  542. // 1 indicates that there is a match and hence dont filter
  543. //
  544. typedef int ( __cdecl * PFN_IS_MATCH_WIN32_FIND_DATA)
  545. (IN const WIN32_FIND_DATA * pFileInfo,
  546. IN LPVOID pContext);
  547. class TS_DIRECTORY_HEADER;
  548. //
  549. // Following function AlphaCompareFileBothDirInfo() compares the filenames,
  550. // of the two given FileInfo present in (**pvFileInfo)
  551. //
  552. int __cdecl
  553. AlphaCompareFileBothDirInfo(
  554. IN const void * /* PWIN32_FIND_DATA * */ pvFileInfo1,
  555. IN const void * /* PWIN32_FIND_DATA * */ pvFileInfo2);
  556. /*++
  557. Class TS_DIRECTORY_INFO
  558. This class provides a method to obtain directory listings.
  559. The directory listing may be optionally cached transparently.
  560. In addition this class provides methods for
  561. 1) accessing the information about files in indexed fashion
  562. 2) Sort the information about files using a generic sort function
  563. given the compare funtion
  564. 3) Filters the listing applying filters the list of files available.
  565. The strings in the File information obtained are stored as ANSI strings.
  566. --*/
  567. class TS_DIRECTORY_INFO
  568. : public BLOB_HEADER
  569. {
  570. public:
  571. TS_DIRECTORY_INFO( const TSVC_CACHE & tsCache)
  572. : m_cFilesInDirectory ( 0),
  573. m_fValid ( FALSE),
  574. m_tsCache ( tsCache),
  575. m_pTsDirectoryHeader( NULL),
  576. m_prgFileInfo ( NULL)
  577. {
  578. // the data stored may be valid after user calls GetDirectoryListing()
  579. }
  580. ~TS_DIRECTORY_INFO( VOID)
  581. { CleanupThis(); }
  582. dllexp VOID CleanupThis( VOID);
  583. BOOL IsValid( VOID) const
  584. { return ( m_fValid); }
  585. dllexp BOOL
  586. GetDirectoryListingA(
  587. IN LPCSTR pszDirectoryName,
  588. IN HANDLE hListingUser);
  589. int QueryFilesCount( VOID) const
  590. { return ( m_cFilesInDirectory); }
  591. const WIN32_FIND_DATA *
  592. operator [] ( IN int idx) const {
  593. return ( 0 <= idx && idx < QueryFilesCount()) ?
  594. GetFileInfoPointerFromIdx( idx) : NULL;
  595. }
  596. dllexp BOOL
  597. SortFileInfoPointers( IN PFN_CMP_WIN32_FIND_DATA pfnCompare);
  598. BOOL
  599. AlphabeticallySortFileInfo( VOID) {
  600. return SortFileInfoPointers( AlphaCompareFileBothDirInfo);
  601. }
  602. //
  603. // Filter functions are used to eliminate some of the file
  604. // pointers to be used in scanning ( using operator []).
  605. //
  606. //
  607. // This function uses the pfnMatch to identify the items that dont match
  608. // and filters them away from the directory listing generated.
  609. // The filter function returns TRUE on success and FALSE if any errors.
  610. //
  611. dllexp BOOL FilterFiles(IN PFN_IS_MATCH_WIN32_FIND_DATA pfnMatch,
  612. IN LPVOID pContext);
  613. # ifdef UNICODE
  614. BOOL
  615. GetDirectoryListingW(
  616. IN LPCWSTR pwszDirectoryName,
  617. IN HANDLE hListingUser);
  618. # define GetDirectoryListing GetDirectoryListingW
  619. # else
  620. # define GetDirectoryListing GetDirectoryListingA
  621. # endif // UNICODE
  622. # if DBG
  623. VOID Print( VOID) const;
  624. #else
  625. VOID Print( VOID) const
  626. { ; }
  627. # endif // DBG
  628. private:
  629. int m_cFilesInDirectory;
  630. BOOL m_fValid;
  631. const TSVC_CACHE & m_tsCache;
  632. TS_DIRECTORY_HEADER * m_pTsDirectoryHeader; // ptr to dir listing
  633. PWIN32_FIND_DATA * m_prgFileInfo;
  634. PWIN32_FIND_DATA
  635. GetFileInfoPointerFromIdx( IN int idx) const
  636. { return ( m_prgFileInfo[idx]); }
  637. }; // class TS_DIRECTORY_INFO
  638. typedef TS_DIRECTORY_INFO * PTS_DIRECTORY_INFO;
  639. /*
  640. * Function Prototypes
  641. */
  642. /*
  643. * Create and Close TS_OPEN_FILE_INFO objects.
  644. */
  645. LPTS_OPEN_FILE_INFO
  646. TsCreateFile(
  647. IN const TSVC_CACHE &TSvcCache,
  648. IN LPCSTR lpszName,
  649. IN HANDLE OpeningUser,
  650. IN DWORD dwOptions
  651. );
  652. LPTS_OPEN_FILE_INFO
  653. TsCreateFileFromURI(
  654. IN const TSVC_CACHE &TSvcCache,
  655. IN PW3_URI_INFO pURIInfo,
  656. IN HANDLE OpeningUser,
  657. IN DWORD dwOptions,
  658. IN DWORD *dwError
  659. );
  660. BOOL
  661. TsCloseHandle(
  662. IN const TSVC_CACHE &TSvcCache,
  663. IN LPTS_OPEN_FILE_INFO pOpenFile
  664. );
  665. BOOL
  666. TsCloseURIFile(
  667. IN LPTS_OPEN_FILE_INFO pOpenFile
  668. );
  669. BOOL
  670. TsDerefURIFile(
  671. IN LPTS_OPEN_FILE_INFO pOpenFile
  672. );
  673. /*
  674. * Other file info operations
  675. */
  676. BOOL
  677. TsDeleteOnClose(
  678. IN PW3_URI_INFO pURIInfo,
  679. IN HANDLE OpeningUser,
  680. OUT BOOL *fDeleted
  681. );
  682. PSECURITY_DESCRIPTOR
  683. TsGetFileSecDesc(
  684. IN LPTS_OPEN_FILE_INFO pFile
  685. );
  686. VOID
  687. TsFlushFilesWithContext(
  688. VOID
  689. );
  690. BOOL
  691. TsCreateETagFromHandle(
  692. IN HANDLE hFile,
  693. IN PCHAR ETag,
  694. IN BOOL *bWeakETag
  695. );
  696. BOOL
  697. TsLastWriteTimeFromHandle(
  698. IN HANDLE hFile,
  699. IN FILETIME *tm
  700. );
  701. /*
  702. * Create/Close URI functions
  703. */
  704. class W3_SERVER_INSTANCE;
  705. class W3_METADATA;
  706. /*
  707. * Cache Setup and Shutdown
  708. */
  709. BOOL
  710. Tsunami_Initialize( VOID );
  711. VOID
  712. Tsunami_Terminate( VOID );
  713. BOOL
  714. InitializeCacheScavenger(
  715. VOID
  716. );
  717. VOID
  718. TerminateCacheScavenger(
  719. VOID
  720. );
  721. /*
  722. * Cache Blob Memory Management
  723. */
  724. BOOL
  725. TsAllocate
  726. (
  727. IN const TSVC_CACHE &TSvcCache,
  728. IN ULONG cbSize,
  729. IN OUT PVOID * ppvNewBlock
  730. );
  731. BOOL
  732. TsAllocateEx
  733. (
  734. IN const TSVC_CACHE &TSvcCache,
  735. IN ULONG cbSize,
  736. IN OUT PVOID * ppvNewBlock,
  737. OPTIONAL PUSER_FREE_ROUTINE pfnFreeRoutine
  738. );
  739. BOOL
  740. TsFree
  741. (
  742. IN const TSVC_CACHE &TSvcCache,
  743. IN PVOID pvOldBlock
  744. );
  745. /*
  746. * Cache/decache
  747. */
  748. BOOL
  749. TsCacheDirectoryBlob(
  750. IN const TSVC_CACHE &TSvcCache,
  751. IN PCSTR pszDirectoryName,
  752. IN ULONG cchDirectoryName,
  753. IN ULONG iDemultiplexor,
  754. IN PVOID pvBlob,
  755. IN BOOLEAN bKeepCheckedOut,
  756. IN PSECURITY_DESCRIPTOR pSecDesc = NULL
  757. );
  758. BOOL
  759. TsDeCacheCachedBlob(
  760. PVOID pvBlob
  761. );
  762. /*
  763. * Check in/out
  764. */
  765. BOOL
  766. TsCheckOutCachedBlob(
  767. IN const TSVC_CACHE &TSvcCache,
  768. IN PCSTR pszDirectoryName,
  769. IN ULONG cchDirectoryName,
  770. IN ULONG iDemultiplexor,
  771. OUT PVOID * ppvBlob,
  772. IN HANDLE hAccessToken = NULL,
  773. IN BOOL fMayCacheAccessToken = FALSE,
  774. OUT PSECURITY_DESCRIPTOR* ppSecDesc = NULL
  775. );
  776. BOOL
  777. TsCheckInCachedBlob(
  778. IN PVOID pvBlob
  779. );
  780. BOOL
  781. TsCheckInOrFree
  782. (
  783. IN PVOID pvOldBlock
  784. );
  785. /*
  786. * Flush
  787. */
  788. BOOL
  789. TsCacheFlushDemux(
  790. IN ULONG iDemux
  791. );
  792. BOOL
  793. TsCacheFlush(
  794. IN DWORD dwServerMask
  795. );
  796. BOOL
  797. TsCacheFlushUser(
  798. IN HANDLE hUserToken,
  799. IN BOOL fDefer
  800. );
  801. VOID
  802. TsFlushURL(
  803. IN const TSVC_CACHE &TSvcCache,
  804. IN LPCSTR pszURL,
  805. IN DWORD dwURLLength,
  806. IN DWORD dwDemux
  807. );
  808. BOOL
  809. TsExpireCachedBlob(
  810. IN const TSVC_CACHE &TSvcCache,
  811. IN PVOID pvBlob
  812. );
  813. /*
  814. * Misc Cache Management
  815. */
  816. BOOL
  817. TsCacheQueryStatistics(
  818. IN DWORD Level,
  819. IN DWORD dwServerMask,
  820. IN INETA_CACHE_STATISTICS * pCacheCtrs
  821. );
  822. BOOL
  823. TsCacheClearStatistics(
  824. IN DWORD dwServerMask
  825. );
  826. typedef int ( __cdecl * PFN_CMP_WIN32_FIND_DATA)
  827. (IN const void * /* PWIN32_FIND_DATA * */ pvFileInfo1,
  828. IN const void * /* PWIN32_FIND_DATA * */ pvFileInfo2);
  829. dllexp
  830. BOOL __cdecl
  831. IsNameInRegExpressionA(
  832. IN LPCSTR pszExpression,
  833. IN LPCSTR pszName,
  834. IN BOOL fIgnoreCase);
  835. //
  836. // Utility function for checking to see if a short filename has a longfile
  837. // name equivalent.
  838. //
  839. dllexp
  840. DWORD
  841. CheckIfShortFileName(
  842. IN CONST UCHAR * pszName,
  843. IN HANDLE hImpersonation,
  844. OUT BOOL * pfShort
  845. );
  846. # endif _TSUNAMI_HXX_