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.

270 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name :
  4. handlerequest.cxx
  5. Abstract:
  6. Handle request state
  7. Author:
  8. Bilal Alam (balam) 10-Jan-2000
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. ULW3.DLL
  13. --*/
  14. #include "precomp.hxx"
  15. #include "staticfile.hxx"
  16. #include "isapi_handler.h"
  17. #include "cgi_handler.h"
  18. #include "trace_handler.h"
  19. #include "dav_handler.h"
  20. #include "generalhandler.hxx"
  21. #include "redirectionhandler.hxx"
  22. W3_STATE_HANDLE_REQUEST::W3_STATE_HANDLE_REQUEST()
  23. {
  24. BOOL fStaticInit = FALSE;
  25. BOOL fCGIInit = FALSE;
  26. BOOL fTraceInit = FALSE;
  27. BOOL fISAPIInit = FALSE;
  28. BOOL fDAVInit = FALSE;
  29. BOOL fGeneralInit = FALSE;
  30. BOOL fRedirectionInit = FALSE;
  31. //
  32. // Initialize static file handler
  33. //
  34. _hr = W3_STATIC_FILE_HANDLER::Initialize();
  35. if ( FAILED( _hr ) )
  36. {
  37. goto Failure;
  38. }
  39. fStaticInit = TRUE;
  40. //
  41. // Initialize ISAPI handler
  42. //
  43. _hr = W3_ISAPI_HANDLER::Initialize();
  44. if ( FAILED( _hr ) )
  45. {
  46. goto Failure;
  47. }
  48. fISAPIInit = TRUE;
  49. //
  50. // Initialize CGI handler
  51. //
  52. _hr = W3_CGI_HANDLER::Initialize();
  53. if ( FAILED( _hr ) )
  54. {
  55. goto Failure;
  56. }
  57. fCGIInit = TRUE;
  58. //
  59. // Initialize Trace handler
  60. //
  61. _hr = W3_TRACE_HANDLER::Initialize();
  62. if ( FAILED( _hr ) )
  63. {
  64. goto Failure;
  65. }
  66. fTraceInit = TRUE;
  67. //
  68. // Initialize DAV handler
  69. //
  70. _hr = W3_DAV_HANDLER::Initialize();
  71. if ( FAILED( _hr ) )
  72. {
  73. goto Failure;
  74. }
  75. fDAVInit = TRUE;
  76. //
  77. // Initialize general handler
  78. //
  79. _hr = W3_GENERAL_HANDLER::Initialize();
  80. if ( FAILED( _hr ) )
  81. {
  82. goto Failure;
  83. }
  84. fGeneralInit = TRUE;
  85. _hr = W3_REDIRECTION_HANDLER::Initialize();
  86. if ( FAILED( _hr ) )
  87. {
  88. goto Failure;
  89. }
  90. fRedirectionInit = TRUE;
  91. return;
  92. Failure:
  93. if ( fRedirectionInit )
  94. {
  95. W3_REDIRECTION_HANDLER::Terminate();
  96. }
  97. if ( fGeneralInit )
  98. {
  99. W3_GENERAL_HANDLER::Terminate();
  100. }
  101. if ( fDAVInit )
  102. {
  103. W3_DAV_HANDLER::Terminate();
  104. }
  105. if ( fCGIInit )
  106. {
  107. W3_CGI_HANDLER::Terminate();
  108. }
  109. if ( fISAPIInit )
  110. {
  111. W3_ISAPI_HANDLER::Terminate();
  112. }
  113. if ( fStaticInit )
  114. {
  115. W3_STATIC_FILE_HANDLER::Terminate();
  116. }
  117. }
  118. W3_STATE_HANDLE_REQUEST::~W3_STATE_HANDLE_REQUEST()
  119. {
  120. if ( FAILED( _hr ) )
  121. {
  122. return;
  123. }
  124. W3_STATIC_FILE_HANDLER::Terminate();
  125. W3_ISAPI_HANDLER::Terminate();
  126. W3_CGI_HANDLER::Terminate();
  127. W3_DAV_HANDLER::Terminate();
  128. W3_GENERAL_HANDLER::Terminate();
  129. W3_REDIRECTION_HANDLER::Terminate();
  130. }
  131. CONTEXT_STATUS
  132. W3_STATE_HANDLE_REQUEST::DoWork(
  133. W3_MAIN_CONTEXT * pMainContext,
  134. DWORD cbCompletion,
  135. DWORD dwCompletionStatus
  136. )
  137. /*++
  138. Routine Description:
  139. Handle the request.
  140. This routine should determine and invoke the appropriate request
  141. handler.
  142. Arguments:
  143. pMainContext - Mainline context
  144. cbCompletion - Bytes of completion
  145. dwCompletionStatus - Completion status
  146. Return Value:
  147. CONTEXT_STATUS_PENDING if async pending, else CONTEXT_STATUS_CONTINUE
  148. --*/
  149. {
  150. HRESULT hr = NO_ERROR;
  151. BOOL fImmediateFinish = FALSE;
  152. W3_TRACE_LOG * pTraceLog;
  153. //
  154. // We must NOT allow any handlers to store state with the context
  155. // (that would screw up child execution)
  156. //
  157. DBG_ASSERT( pMainContext->QueryContextState() == NULL );
  158. //
  159. // We must have a user by now!
  160. //
  161. DBG_ASSERT( pMainContext->QueryUserContext() != NULL );
  162. pTraceLog = pMainContext->QueryTraceLog();
  163. if ( pTraceLog != NULL )
  164. {
  165. pTraceLog->Trace( L"%I64x: Successfully authenticated request as user '%s', type %d\n",
  166. pMainContext->QueryRequest()->QueryRequestId(),
  167. pMainContext->QueryUserContext()->QueryUserName(),
  168. pMainContext->QueryUserContext()->QueryAuthType() );
  169. }
  170. //
  171. // What handler should handle this request?
  172. //
  173. hr = pMainContext->DetermineHandler();
  174. if ( FAILED( hr ) )
  175. {
  176. goto Failure;
  177. }
  178. //
  179. // If we were successful, but no handler was set, then there must
  180. // be an error for us to send
  181. //
  182. if ( pMainContext->QueryHandler() == NULL )
  183. {
  184. DBG_ASSERT( pMainContext->QueryResponse()->QueryStatusCode() != 200 );
  185. hr = pMainContext->SendResponse( W3_FLAG_ASYNC );
  186. }
  187. else
  188. {
  189. hr = pMainContext->ExecuteHandler( W3_FLAG_ASYNC,
  190. &fImmediateFinish );
  191. }
  192. //
  193. // If the execution succeeded, then we expect a completion so bail
  194. //
  195. if ( SUCCEEDED( hr ) )
  196. {
  197. if ( fImmediateFinish )
  198. {
  199. return CONTEXT_STATUS_CONTINUE;
  200. }
  201. else
  202. {
  203. return CONTEXT_STATUS_PENDING;
  204. }
  205. }
  206. Failure:
  207. pMainContext->SetErrorStatus( hr );
  208. pMainContext->QueryResponse()->SetStatus( HttpStatusServerError );
  209. pMainContext->SetFinishedResponse();
  210. return CONTEXT_STATUS_CONTINUE;
  211. }