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.

244 lines
4.5 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. W3_STATE_HANDLE_REQUEST::W3_STATE_HANDLE_REQUEST()
  22. {
  23. BOOL fStaticInit = FALSE;
  24. BOOL fCGIInit = FALSE;
  25. BOOL fTraceInit = FALSE;
  26. BOOL fISAPIInit = FALSE;
  27. BOOL fDAVInit = FALSE;
  28. BOOL fGeneralInit = FALSE;
  29. //
  30. // Initialize static file handler
  31. //
  32. _hr = W3_STATIC_FILE_HANDLER::Initialize();
  33. if ( FAILED( _hr ) )
  34. {
  35. goto Failure;
  36. }
  37. fStaticInit = TRUE;
  38. //
  39. // Initialize ISAPI handler
  40. //
  41. _hr = W3_ISAPI_HANDLER::Initialize();
  42. if ( FAILED( _hr ) )
  43. {
  44. goto Failure;
  45. }
  46. fISAPIInit = TRUE;
  47. //
  48. // Initialize CGI handler
  49. //
  50. _hr = W3_CGI_HANDLER::Initialize();
  51. if ( FAILED( _hr ) )
  52. {
  53. goto Failure;
  54. }
  55. fCGIInit = TRUE;
  56. //
  57. // Initialize Trace handler
  58. //
  59. _hr = W3_TRACE_HANDLER::Initialize();
  60. if ( FAILED( _hr ) )
  61. {
  62. goto Failure;
  63. }
  64. fTraceInit = TRUE;
  65. //
  66. // Initialize DAV handler
  67. //
  68. _hr = W3_DAV_HANDLER::Initialize();
  69. if ( FAILED( _hr ) )
  70. {
  71. goto Failure;
  72. }
  73. fDAVInit = TRUE;
  74. //
  75. // Initialize general handler
  76. //
  77. _hr = W3_GENERAL_HANDLER::Initialize();
  78. if ( FAILED( _hr ) )
  79. {
  80. goto Failure;
  81. }
  82. fGeneralInit = TRUE;
  83. return;
  84. Failure:
  85. if ( fGeneralInit )
  86. {
  87. W3_GENERAL_HANDLER::Terminate();
  88. }
  89. if ( fDAVInit )
  90. {
  91. W3_DAV_HANDLER::Terminate();
  92. }
  93. if ( fCGIInit )
  94. {
  95. W3_CGI_HANDLER::Terminate();
  96. }
  97. if ( fISAPIInit )
  98. {
  99. W3_ISAPI_HANDLER::Terminate();
  100. }
  101. if ( fStaticInit )
  102. {
  103. W3_STATIC_FILE_HANDLER::Terminate();
  104. }
  105. }
  106. W3_STATE_HANDLE_REQUEST::~W3_STATE_HANDLE_REQUEST()
  107. {
  108. if ( FAILED( _hr ) )
  109. {
  110. return;
  111. }
  112. W3_STATIC_FILE_HANDLER::Terminate();
  113. W3_ISAPI_HANDLER::Terminate();
  114. W3_CGI_HANDLER::Terminate();
  115. W3_DAV_HANDLER::Terminate();
  116. W3_GENERAL_HANDLER::Terminate();
  117. }
  118. CONTEXT_STATUS
  119. W3_STATE_HANDLE_REQUEST::DoWork(
  120. W3_MAIN_CONTEXT * pMainContext,
  121. DWORD cbCompletion,
  122. DWORD dwCompletionStatus
  123. )
  124. /*++
  125. Routine Description:
  126. Handle the request.
  127. This routine should determine and invoke the appropriate request
  128. handler.
  129. Arguments:
  130. pMainContext - Mainline context
  131. cbCompletion - Bytes of completion
  132. dwCompletionStatus - Completion status
  133. Return Value:
  134. CONTEXT_STATUS_PENDING if async pending, else CONTEXT_STATUS_CONTINUE
  135. --*/
  136. {
  137. HRESULT hr = NO_ERROR;
  138. BOOL fImmediateFinish = FALSE;
  139. //
  140. // We must NOT allow any handlers to store state with the context
  141. // (that would screw up child execution)
  142. //
  143. DBG_ASSERT( pMainContext->QueryContextState() == NULL );
  144. //
  145. // We must have a user by now!
  146. //
  147. DBG_ASSERT( pMainContext->QueryUserContext() != NULL );
  148. //
  149. // What handler should handle this request?
  150. //
  151. hr = pMainContext->DetermineHandler( TRUE );
  152. if ( FAILED( hr ) )
  153. {
  154. goto Failure;
  155. }
  156. //
  157. // If we were successful, but no handler was set, then there must
  158. // be an error for us to send
  159. //
  160. if ( pMainContext->QueryHandler() == NULL )
  161. {
  162. DBG_ASSERT( pMainContext->QueryResponse()->QueryStatusCode() != 200 );
  163. hr = pMainContext->SendResponse( W3_FLAG_ASYNC );
  164. }
  165. else
  166. {
  167. hr = pMainContext->ExecuteHandler( W3_FLAG_ASYNC,
  168. &fImmediateFinish );
  169. }
  170. //
  171. // If the execution succeeded, then we expect a completion so bail
  172. //
  173. if ( SUCCEEDED( hr ) )
  174. {
  175. if ( fImmediateFinish )
  176. {
  177. return CONTEXT_STATUS_CONTINUE;
  178. }
  179. else
  180. {
  181. return CONTEXT_STATUS_PENDING;
  182. }
  183. }
  184. Failure:
  185. pMainContext->SetErrorStatus( hr );
  186. pMainContext->QueryResponse()->SetStatus( HttpStatusServerError );
  187. pMainContext->SetFinishedResponse();
  188. return CONTEXT_STATUS_CONTINUE;
  189. }