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.

134 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name :
  4. trace_handler.cxx
  5. Abstract:
  6. Handle TRACE requests
  7. Author:
  8. Anil Ruia (AnilR) 15-Mar-2000
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. ULW3.DLL
  13. --*/
  14. #include "precomp.hxx"
  15. #include "trace_handler.h"
  16. CONTEXT_STATUS
  17. W3_TRACE_HANDLER::DoWork(
  18. VOID
  19. )
  20. /*++
  21. Routine Description:
  22. Do the TRACE thing
  23. Return Value:
  24. CONTEXT_STATUS_PENDING if async pending, else CONTEXT_STATUS_CONTINUE
  25. --*/
  26. {
  27. W3_CONTEXT *pW3Context = QueryW3Context();
  28. DBG_ASSERT( pW3Context != NULL );
  29. HRESULT hr = S_OK;
  30. W3_REQUEST * pRequest;
  31. W3_RESPONSE * pResponse;
  32. STACK_STRA( strTemp, 256 );
  33. DWORD cbAlreadyAvailable;
  34. PVOID pvAlreadyAvailable;
  35. pRequest = pW3Context->QueryRequest();
  36. DBG_ASSERT(pRequest != NULL);
  37. pResponse = pW3Context->QueryResponse();
  38. DBG_ASSERT(pResponse != NULL);
  39. //
  40. // If entity body with request, BAD request
  41. //
  42. pW3Context->QueryAlreadyAvailableEntity( &pvAlreadyAvailable,
  43. &cbAlreadyAvailable );
  44. if ( cbAlreadyAvailable ||
  45. pW3Context->QueryRemainingEntityFromUl() != 0 )
  46. {
  47. pResponse->SetStatus( HttpStatusBadRequest );
  48. goto Finished;
  49. }
  50. //
  51. // Build the request line
  52. //
  53. if ( FAILED( hr = pRequest->GetVerbString(&_strResponse) ) ||
  54. FAILED( hr = _strResponse.Append(" ") ) ||
  55. FAILED( hr = pRequest->GetRawUrl(&strTemp) ) ||
  56. FAILED( hr = _strResponse.Append(strTemp) ) ||
  57. FAILED( hr = _strResponse.Append(" ") ) ||
  58. FAILED( hr = pRequest->GetVersionString(&strTemp) ) ||
  59. FAILED( hr = _strResponse.Append(strTemp) ) ||
  60. FAILED( hr = _strResponse.Append("\r\n") ) )
  61. {
  62. goto Finished;
  63. }
  64. //
  65. // Echo the request headers (and trailing blank line)
  66. //
  67. strTemp.Reset();
  68. if ( FAILED( hr = pRequest->GetAllHeaders( &strTemp, FALSE ) ) ||
  69. FAILED( hr = _strResponse.Append( strTemp ) ) ||
  70. FAILED( hr = _strResponse.Append("\r\n") ) )
  71. {
  72. goto Finished;
  73. }
  74. //
  75. // Set content type as message/http
  76. //
  77. hr = pResponse->SetHeader( HttpHeaderContentType,
  78. HEADER("message/http") );
  79. if ( FAILED( hr ) )
  80. {
  81. goto Finished;
  82. }
  83. hr = pResponse->AddMemoryChunkByReference( _strResponse.QueryStr(),
  84. _strResponse.QueryCCH() );
  85. if ( FAILED( hr ) )
  86. {
  87. goto Finished;
  88. }
  89. Finished:
  90. if ( FAILED( hr ) )
  91. {
  92. pW3Context->SetErrorStatus( hr );
  93. pResponse->SetStatus( HttpStatusServerError );
  94. }
  95. hr = pW3Context->SendResponse( W3_FLAG_ASYNC );
  96. if ( FAILED( hr ) )
  97. {
  98. pW3Context->SetErrorStatus( hr );
  99. return CONTEXT_STATUS_CONTINUE;
  100. }
  101. else
  102. {
  103. return CONTEXT_STATUS_PENDING;
  104. }
  105. }