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.

366 lines
7.5 KiB

  1. #ifndef __SSI_FILE_HXX__
  2. #define __SSI_FILE_HXX__
  3. /*++
  4. Copyright (c) 2001 Microsoft Corporation
  5. Module Name:
  6. ssi_file.hxx
  7. Abstract:
  8. This module contains the server side include processing code. We
  9. aim for support as specified by iis\spec\ssi.doc. The code is based
  10. on existing SSI support done in iis\svcs\w3\gateways\ssinc\ssinc.cxx.
  11. SSI_FILE class handles all the details file access.
  12. File cache of W3CORE is leveraged to cache STM files
  13. ( using W3CORE file cache directly doesn't necessarily conform
  14. with ISAPI rules because we use private hooks not officially
  15. exposed to ISAPIs )
  16. Author:
  17. Ming Lu (MingLu) 5-Apr-2000
  18. Revision history
  19. Jaroslad Dec-2000
  20. - modified to execute asynchronously
  21. Jaroslad Apr-2001
  22. - added VectorSend support, keepalive, split to multiple source files
  23. --*/
  24. //
  25. // Class Definitions
  26. //
  27. // class SSI_FILE
  28. //
  29. // File structure. All high level functions should use this
  30. // structure instead of dealing with handle specifics themselves.
  31. class SSI_FILE : public ASSOCIATED_FILE_OBJECT
  32. {
  33. public:
  34. static
  35. HRESULT
  36. InitializeGlobals(
  37. VOID
  38. );
  39. static
  40. VOID
  41. TerminateGlobals(
  42. VOID
  43. );
  44. static
  45. HRESULT
  46. GetReferencedInstance(
  47. IN STRU& strFilename,
  48. HANDLE hUserToken,
  49. OUT SSI_FILE ** ppSsiFile
  50. );
  51. VOID
  52. DereferenceSsiFile(
  53. VOID
  54. )
  55. {
  56. // SSI FILE is cached as associated member
  57. // of file cache item pOpenFile
  58. if ( _pFile != NULL )
  59. {
  60. //
  61. // once SSI_FILE is associated with W3_FILE_INFO
  62. // then W3_FILE_INFO controls it's lifetime
  63. // If _pFile's refcount drops to 0 there will be callback on
  64. // Cleanup() method from the file cache
  65. //
  66. _pFile->DereferenceCacheEntry();
  67. }
  68. else
  69. {
  70. //
  71. // DereferenceSsiFile() must have been called without
  72. // GetReferencedInstance() to get here. Well, this is
  73. // surely a problem
  74. //
  75. DBG_ASSERT( FALSE );
  76. }
  77. }
  78. PSECURITY_DESCRIPTOR
  79. GetSecDesc(
  80. VOID
  81. ) const;
  82. HRESULT
  83. GetResponseHeaders(
  84. OUT CHAR ** ppszResponseHeaders,
  85. OUT BOOL * pfIncludesContentLength
  86. );
  87. SSI_ELEMENT_LIST *
  88. GetSsiElementList(
  89. VOID
  90. ) const
  91. {
  92. return _pSsiElementList;
  93. }
  94. DWORD
  95. SSIGetFileAttributes(
  96. VOID
  97. )
  98. /*++
  99. Gets the attributes of a file
  100. --*/
  101. {
  102. return _pFile->QueryAttributes();
  103. }
  104. HRESULT
  105. SSIGetFileSize(
  106. OUT DWORD * pdwFileSize
  107. )
  108. /*++
  109. Gets the size of the file.
  110. --*/
  111. {
  112. ULARGE_INTEGER liSize;
  113. _pFile->QuerySize( &liSize );
  114. *pdwFileSize = liSize.LowPart;
  115. if ( liSize.HighPart != 0 )
  116. {
  117. //
  118. //we don't support files over 4GB for SSI
  119. //
  120. return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
  121. }
  122. return S_OK;
  123. }
  124. HRESULT
  125. SSIGetLastModTime(
  126. OUT FILETIME * ftTime
  127. )
  128. /*++
  129. Gets the Last modification time of a file.
  130. --*/
  131. {
  132. _pFile->QueryLastWriteTime( ftTime );
  133. return S_OK;
  134. }
  135. PBYTE
  136. SSIGetFileData(
  137. VOID
  138. )
  139. {
  140. if ( _pvMappedBase != NULL )
  141. {
  142. return reinterpret_cast<PBYTE>( _pvMappedBase );
  143. }
  144. else
  145. {
  146. return _pFile->QueryFileBuffer();
  147. }
  148. }
  149. CHAR *
  150. SSIGetFileETag(
  151. VOID
  152. )
  153. {
  154. DBG_ASSERT( _pFile != NULL );
  155. return _pFile->QueryETag();
  156. }
  157. CHAR *
  158. SSIGetLastModifiedString(
  159. VOID
  160. )
  161. {
  162. DBG_ASSERT( _pFile != NULL );
  163. return _pFile->QueryLastModifiedString();
  164. }
  165. HANDLE
  166. SSIGetFileHandle(
  167. VOID
  168. )
  169. {
  170. DBG_ASSERT( _pFile != NULL );
  171. return _pFile->QueryFileHandle();
  172. }
  173. BOOL
  174. QueryHasDirectives(
  175. VOID
  176. )
  177. {
  178. DBG_ASSERT( _pSsiElementList != NULL );
  179. return _pSsiElementList->QueryHasDirectives();
  180. }
  181. protected:
  182. virtual
  183. VOID
  184. Cleanup(
  185. VOID
  186. )
  187. /*++
  188. Routine Description:
  189. Virtual function of ASSOCIATED_FILE_OBJECT
  190. Function is supposed to take care of the cleanup of the associated
  191. file object
  192. Use DereferenceSsiFile() to cleanup SSI_FILE
  193. acquired by GetReferencedInstance()
  194. Arguments:
  195. Return Value:
  196. VOID
  197. --*/
  198. {
  199. //
  200. // refcount on cache entry dropped to zero
  201. // Associated object must go
  202. //
  203. DBG_ASSERT( CheckSignature() );
  204. delete this;
  205. }
  206. BOOL
  207. CheckSignature(
  208. VOID
  209. ) const
  210. {
  211. return _dwSignature == SSI_FILE_SIGNATURE;
  212. }
  213. private:
  214. // use GetReferencedInstance() to instantiate object
  215. SSI_FILE(
  216. IN W3_FILE_INFO * pOpenFile
  217. );
  218. // use DereferenceSsiFile() to "delete"
  219. virtual ~SSI_FILE();
  220. //
  221. // Not implemented methods
  222. // Declarations present to prevent compiler
  223. // to generate default ones.
  224. //
  225. SSI_FILE( const SSI_FILE& );
  226. SSI_FILE& operator=( const SSI_FILE& );
  227. static
  228. HRESULT
  229. CreateInstance(
  230. IN W3_FILE_INFO * pOpenFile,
  231. OUT SSI_FILE ** ppSsiFile
  232. );
  233. HRESULT
  234. Initialize(
  235. VOID
  236. );
  237. BOOL
  238. AssociateWithFileCache(
  239. VOID
  240. )
  241. /*++
  242. Routine Description:
  243. Store SSI_FILE as associated object of W3_FILE_INFO
  244. Arguments:
  245. Return Value:
  246. HRESULT
  247. --*/
  248. {
  249. DBG_ASSERT( _pFile != NULL );
  250. return _pFile->SetAssociatedObject( this ) ;
  251. }
  252. HRESULT
  253. SSICreateFileMapping(
  254. VOID
  255. );
  256. HRESULT
  257. SSIDeleteFileMapping(
  258. VOID
  259. );
  260. HRESULT
  261. AddToResponseHeaders(
  262. IN CHAR * pszHeaderChunk,
  263. IN BOOL fIncludesContentLength = FALSE
  264. );
  265. DWORD _dwSignature;
  266. //
  267. // element of the W3CORE file cache
  268. // Note: SSI uses internal API's (such as this caching)
  269. // even though it is implemented as ISAPI
  270. //
  271. W3_FILE_INFO * _pFile;
  272. // handle used for file mapping
  273. HANDLE _hMapHandle;
  274. // beginning of the file mapped to memory
  275. PVOID _pvMappedBase;
  276. // ssi element list - parsed SSI structure
  277. SSI_ELEMENT_LIST * _pSsiElementList;
  278. //
  279. // Headers to be sent to client may be cached in _strResponseHeaders
  280. //
  281. STRA _strResponseHeaders;
  282. CHAR _abResponseHeaders[ SSI_DEFAULT_RESPONSE_HEADERS_SIZE + 1 ];
  283. BOOL _fResponseHeadersIncludeContentLength;
  284. // W3CORE cache access
  285. static W3_FILE_INFO_CACHE * s_pFileCache;
  286. };
  287. #endif