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.

224 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. cgi_handler.h
  5. Abstract:
  6. Handler class for CGI
  7. Author:
  8. Taylor Weiss (TaylorW) 01-Feb-1999
  9. Revision History:
  10. --*/
  11. #ifndef _CGI_HANDLER_H_
  12. #define _CGI_HANDLER_H_
  13. #define MAX_CGI_BUFFERING 2048
  14. enum CGI_STATE
  15. {
  16. CgiStateStart,
  17. CgiStateProcessingRequestEntity,
  18. CgiStateProcessingResponseHeaders,
  19. CgiStateProcessingResponseEntity,
  20. CgiStateDoneWithRequest
  21. };
  22. class W3_CGI_HANDLER : public W3_HANDLER
  23. {
  24. public:
  25. W3_CGI_HANDLER( W3_CONTEXT * pW3Context,
  26. META_SCRIPT_MAP_ENTRY * pScriptMapEntry,
  27. LPSTR pszSSICommandLine = NULL )
  28. : W3_HANDLER (pW3Context, pScriptMapEntry),
  29. m_cbData (0),
  30. m_hStdOut (INVALID_HANDLE_VALUE),
  31. m_hStdIn (INVALID_HANDLE_VALUE),
  32. m_hProcess (NULL),
  33. m_hTimer (NULL),
  34. m_dwRequestState (CgiStateStart),
  35. m_fResponseRedirected (FALSE),
  36. m_bytesToSend (INFINITE),
  37. m_bytesToReceive (0),
  38. m_fEntityBodyPreloadComplete (FALSE),
  39. m_pszSSICommandLine(pszSSICommandLine),
  40. m_fIsNphCgi (FALSE)
  41. {
  42. ZeroMemory(&m_Overlapped, sizeof OVERLAPPED);
  43. InitializeListHead(&m_CgiListEntry);
  44. EnterCriticalSection(&sm_CgiListLock);
  45. InsertHeadList(&sm_CgiListHead, &m_CgiListEntry);
  46. LeaveCriticalSection(&sm_CgiListLock);
  47. // perf ctr
  48. pW3Context->QuerySite()->IncCgiReqs();
  49. if ( ETW_IS_TRACE_ON(ETW_LEVEL_CP) )
  50. {
  51. HTTP_REQUEST_ID RequestId = pW3Context->QueryRequest()->QueryRequestId();
  52. g_pEtwTracer->EtwTraceEvent( &CgiEventGuid,
  53. ETW_TYPE_START,
  54. &RequestId,
  55. sizeof(HTTP_REQUEST_ID),
  56. NULL,
  57. 0 );
  58. }
  59. if (pszSSICommandLine != NULL)
  60. {
  61. m_fIsNphCgi = TRUE;
  62. }
  63. }
  64. ~W3_CGI_HANDLER();
  65. WCHAR *QueryName()
  66. {
  67. return L"CGIHandler";
  68. }
  69. CONTEXT_STATUS DoWork();
  70. CONTEXT_STATUS OnCompletion(IN DWORD cbCompletion,
  71. IN DWORD dwCompletionStatus);
  72. static HRESULT Initialize();
  73. static VOID KillAllCgis();
  74. static VOID Terminate();
  75. private:
  76. HRESULT CGIStartProcessing();
  77. HRESULT CGIContinueOnClientCompletion();
  78. HRESULT CGIContinueOnPipeCompletion(BOOL *pfIsCgiError);
  79. HRESULT CGIReadRequestEntity(BOOL *pfIoPending);
  80. HRESULT CGIWriteResponseEntity();
  81. HRESULT CGIReadCGIOutput();
  82. HRESULT CGIWriteCGIInput();
  83. HRESULT ProcessCGIOutput();
  84. HRESULT SetupChildEnv(OUT BUFFER *pBuffer);
  85. static HRESULT SetupChildPipes(OUT HANDLE *phStdOut,
  86. OUT HANDLE *phStdIn,
  87. IN OUT STARTUPINFO *pstartupinfo);
  88. static VOID CALLBACK CGITerminateProcess(PVOID pContext,
  89. BOOLEAN);
  90. BOOL QueryIsNphCgi() const
  91. {
  92. return m_fIsNphCgi;
  93. }
  94. static VOID CALLBACK OnPipeIoCompletion(
  95. DWORD dwErrorCode,
  96. DWORD dwNumberOfBytesTransfered,
  97. LPOVERLAPPED lpOverlapped);
  98. static BOOL sm_fForwardServerEnvironmentBlock;
  99. static WCHAR * sm_pEnvString;
  100. static DWORD sm_cchEnvLength;
  101. static LIST_ENTRY sm_CgiListHead;
  102. static CRITICAL_SECTION sm_CgiListLock;
  103. //
  104. // DWORD containing the state of the current request
  105. //
  106. CGI_STATE m_dwRequestState;
  107. BOOL m_fResponseRedirected;
  108. //
  109. // The timer callback handle
  110. //
  111. HANDLE m_hTimer;
  112. //
  113. // Parent's input and output handles and child's process handle
  114. //
  115. HANDLE m_hStdOut;
  116. HANDLE m_hStdIn;
  117. HANDLE m_hProcess;
  118. //
  119. // Variable to keep track of how many more bytes of request/response left
  120. //
  121. DWORD m_bytesToSend;
  122. DWORD m_bytesToReceive;
  123. //
  124. // Buffer to do I/O to/from CGI/client
  125. //
  126. CHAR m_DataBuffer[MAX_CGI_BUFFERING];
  127. //
  128. // Buffer to store response headers
  129. //
  130. BUFFER m_bufResponseHeaders;
  131. //
  132. // Number of bytes in the buffer (m_DataBuffer or
  133. // m_bufResponseHeaders) currently
  134. //
  135. DWORD m_cbData;
  136. //
  137. // OVERLAPPED structure for async I/O
  138. //
  139. OVERLAPPED m_Overlapped;
  140. //
  141. // Store a list of active CGI requests so we can timeout bad requests
  142. //
  143. LIST_ENTRY m_CgiListEntry;
  144. //
  145. // Have we completed preloading the entity body
  146. //
  147. BOOL m_fEntityBodyPreloadComplete;
  148. //
  149. // For the SSI #EXEC CMD case, m_pszSSICommandLine contains the explicit
  150. // command to execute
  151. //
  152. // Note: CGI_HANDLER does not own this string so it doesn't need to
  153. // free it.
  154. //
  155. LPSTR m_pszSSICommandLine;
  156. //
  157. // Is this an nph CGI (or a cmd exec from SSI)
  158. //
  159. BOOL m_fIsNphCgi;
  160. };
  161. //
  162. // This is the exit code given to processes that we terminate
  163. //
  164. #define CGI_PREMATURE_DEATH_CODE 0xf1256323
  165. #endif // _CGI_HANDLER_H_