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.

389 lines
8.3 KiB

  1. #ifndef __SSI_INCLUDE_FILE_HXX__
  2. #define __SSI_INCLUDE_FILE_HXX__
  3. /*++
  4. Copyright (c) 2001 Microsoft Corporation
  5. Module Name:
  6. ssi_include_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. A STM file may include other files. Each of those files is represented
  12. by SSI_INCLUDE_FILE class instance
  13. Author:
  14. Ming Lu (MingLu) 5-Apr-2000
  15. Revision history
  16. Jaroslad Dec-2000
  17. - modified to execute asynchronously
  18. Jaroslad Apr-2001
  19. - added VectorSend support, keepalive, split to multiple source files
  20. --*/
  21. //
  22. // States of asynchronous SSI_INCLUDE_FILE processing
  23. //
  24. enum SIF_STATE
  25. {
  26. SIF_STATE_UNINITIALIZED,
  27. SIF_STATE_READY,
  28. SIF_STATE_EXEC_URL_PENDING,
  29. SIF_STATE_INCLUDE_CHILD_PENDING,
  30. SIF_STATE_VECTOR_SEND_PENDING,
  31. SIF_STATE_PROCESSING,
  32. SIF_STATE_PROCESSED,
  33. SIF_STATE_COMPLETE_PENDING,
  34. SIF_STATE_COMPLETED,
  35. SIF_STATE_UNKNOWN
  36. };
  37. class SSI_REQUEST;
  38. class SSI_FILE;
  39. class SSI_ELEMENT_LIST;
  40. class SSI_ELEMENT_ITEM;
  41. /************************************************************
  42. * Structure and Class declarations
  43. ************************************************************/
  44. /*++
  45. class SSI_INCLUDE_FILE
  46. STM file may include other files. Each include file is represented by SSI_INCLUDE_FILE
  47. Hierarchy:
  48. SSI_INCLUDE_FILE
  49. - SSI_ELEMENT_LIST
  50. - SSI_ELEMENT_ITEM
  51. --*/
  52. class SSI_REQUEST;
  53. class SSI_INCLUDE_FILE
  54. {
  55. public:
  56. ~SSI_INCLUDE_FILE( VOID );
  57. VOID *
  58. operator new(
  59. size_t size
  60. )
  61. {
  62. UNREFERENCED_PARAMETER( size );
  63. DBG_ASSERT( size == sizeof( SSI_INCLUDE_FILE ) );
  64. DBG_ASSERT( sm_pachSsiIncludeFiles != NULL );
  65. return sm_pachSsiIncludeFiles->Alloc();
  66. }
  67. VOID
  68. operator delete(
  69. VOID * pSsiIncludeFile
  70. )
  71. {
  72. DBG_ASSERT( pSsiIncludeFile != NULL );
  73. DBG_ASSERT( sm_pachSsiIncludeFiles != NULL );
  74. DBG_REQUIRE( sm_pachSsiIncludeFiles->Free( pSsiIncludeFile ) );
  75. }
  76. static
  77. HRESULT
  78. InitializeGlobals(
  79. VOID
  80. )
  81. /*++
  82. Routine Description:
  83. Global initialization routine for SSI_INCLUDE_FILE
  84. Arguments:
  85. None
  86. Return Value:
  87. HRESULT
  88. --*/
  89. {
  90. ALLOC_CACHE_CONFIGURATION acConfig;
  91. //
  92. // Setup allocation lookaside
  93. //
  94. acConfig.nConcurrency = 1;
  95. acConfig.nThreshold = 100;
  96. acConfig.cbSize = sizeof( SSI_INCLUDE_FILE );
  97. DBG_ASSERT( sm_pachSsiIncludeFiles == NULL );
  98. sm_pachSsiIncludeFiles = new ALLOC_CACHE_HANDLER( "SSI_INCLUDE_FILE",
  99. &acConfig );
  100. if ( sm_pachSsiIncludeFiles == NULL )
  101. {
  102. return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
  103. }
  104. return NO_ERROR;
  105. }
  106. static
  107. VOID
  108. TerminateGlobals(
  109. VOID
  110. )
  111. /*++
  112. Routine Description:
  113. Terminate SSI_INCLUDE_FILE globals
  114. Arguments:
  115. None
  116. Return Value:
  117. None
  118. --*/
  119. {
  120. if ( sm_pachSsiIncludeFiles != NULL )
  121. {
  122. delete sm_pachSsiIncludeFiles;
  123. sm_pachSsiIncludeFiles = NULL;
  124. }
  125. }
  126. static
  127. HRESULT
  128. CreateInstance(
  129. IN STRU & strFilename,
  130. IN STRU & strURL,
  131. IN SSI_REQUEST * pRequest,
  132. IN SSI_INCLUDE_FILE * pParent,
  133. OUT SSI_INCLUDE_FILE ** ppSsiIncludeFile
  134. );
  135. HRESULT
  136. DoWork(
  137. IN HRESULT hrLastOp,
  138. OUT BOOL * pfAsyncPending
  139. );
  140. SSI_INCLUDE_FILE *
  141. GetParent( VOID )
  142. {
  143. return _pParent;
  144. }
  145. BOOL IsCompleted( VOID )
  146. {
  147. return ( _State == SIF_STATE_COMPLETED );
  148. }
  149. private:
  150. // constructor is private
  151. SSI_INCLUDE_FILE(
  152. SSI_REQUEST * pRequest,
  153. SSI_INCLUDE_FILE * pParent
  154. )
  155. : _pRequest( pRequest ),
  156. _pParent( pParent ),
  157. _pSsiFile( NULL ),
  158. _pCurrentEntry( NULL ),
  159. _fSizeFmtBytes (SSI_DEF_SIZEFMT),
  160. _strFilename( _abFilename, sizeof(_abFilename) ),
  161. _strURL( _abURL, sizeof(_abURL) ),
  162. _strTimeFmt( _abTimeFmt, sizeof(_abTimeFmt) ),
  163. _State( SIF_STATE_UNINITIALIZED )
  164. {
  165. }
  166. //
  167. // Not implemented methods
  168. // Declarations present to prevent compiler
  169. // to generate default ones.
  170. //
  171. SSI_INCLUDE_FILE();
  172. SSI_INCLUDE_FILE( const SSI_INCLUDE_FILE& );
  173. SSI_INCLUDE_FILE& operator=( const SSI_INCLUDE_FILE& );
  174. HRESULT
  175. Initialize(
  176. IN STRU & strFilename,
  177. IN STRU & strURL
  178. );
  179. HRESULT
  180. ProcessSsiElements(
  181. BOOL * pfAsyncPending
  182. );
  183. static
  184. BOOL
  185. FindInternalVariable(
  186. IN STRA * pstrVariable,
  187. OUT PDWORD pdwID
  188. );
  189. HRESULT
  190. DoFLastMod(
  191. IN STRU * pstrFilename
  192. );
  193. HRESULT
  194. DoFSize(
  195. IN STRU * pstrFilename
  196. );
  197. HRESULT
  198. DoEchoISAPIVariable(
  199. IN STRA *
  200. );
  201. HRESULT
  202. DoEchoDocumentName(
  203. VOID
  204. );
  205. HRESULT
  206. DoEchoDocumentURI(
  207. VOID
  208. );
  209. HRESULT
  210. DoEchoQueryStringUnescaped(
  211. VOID
  212. );
  213. HRESULT
  214. DoEchoDateLocal(
  215. VOID
  216. );
  217. HRESULT
  218. DoEchoDateGMT(
  219. VOID
  220. );
  221. HRESULT
  222. DoEchoLastModified(
  223. VOID
  224. );
  225. HRESULT
  226. GetFullPath(
  227. IN SSI_ELEMENT_ITEM * pSEI,
  228. OUT STRU * pstrPath,
  229. IN DWORD dwPermission,
  230. IN STRU * pstrCurrentURL,
  231. OUT STRU * pstrURL = NULL
  232. );
  233. VOID
  234. SetState(
  235. SIF_STATE State
  236. )
  237. {
  238. _State = State;
  239. }
  240. BOOL IsValid( VOID )
  241. {
  242. return ( _State != SIF_STATE_UNINITIALIZED );
  243. }
  244. BOOL IsBaseFile( VOID )
  245. {
  246. return ( _pParent == NULL );
  247. }
  248. BOOL IsRecursiveInclude( IN STRU & strFilename )
  249. {
  250. SSI_INCLUDE_FILE * pCurrent = this;
  251. while( pCurrent != NULL )
  252. {
  253. if ( _wcsicmp( strFilename.QueryStr(),
  254. pCurrent->_strFilename.QueryStr() ) == 0 )
  255. {
  256. return TRUE;
  257. }
  258. pCurrent = pCurrent->_pParent;
  259. }
  260. return FALSE;
  261. }
  262. public:
  263. // Lifetime of the SSI_INCLUDE_FILE instances is managed
  264. // by SSI_REQUEST. The _DelayedDeleteList is used to
  265. // keep all the SSI_INCLUDE_FILE instances related to the SSI_REQUEST
  266. // around until the end of the request execution
  267. LIST_ENTRY _DelayedDeleteListEntry;
  268. private:
  269. SSI_REQUEST * _pRequest;
  270. // pParent - Parent SSI include file
  271. SSI_INCLUDE_FILE * _pParent;
  272. SSI_FILE * _pSsiFile;
  273. // Current entry in the SSI_ELEMENT_LIST that is being processed
  274. LIST_ENTRY * _pCurrentEntry;
  275. // _strFileName - File to send
  276. STRU _strFilename;
  277. WCHAR _abFilename[ SSI_DEFAULT_PATH_SIZE + 1 ];
  278. // _strURL - URL (from root) of this file
  279. STRU _strURL;
  280. WCHAR _abURL[ SSI_DEFAULT_URL_SIZE + 1 ];
  281. SIF_STATE _State;
  282. // Asynchronous child execute info
  283. HSE_EXEC_URL_INFO _ExecUrlInfo;
  284. // Size and time formating info
  285. BOOL _fSizeFmtBytes;
  286. STRA _strTimeFmt;
  287. CHAR _abTimeFmt[ SSI_DEFAULT_TIME_FMT + 1 ];
  288. // Lookaside
  289. static ALLOC_CACHE_HANDLER * sm_pachSsiIncludeFiles;
  290. };
  291. #endif