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.

421 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. HttpIo.c
  5. Abstract:
  6. User-mode interface to HTTP.SYS: Server-side I/O handler.
  7. Author:
  8. Keith Moore (keithmo) 15-Dec-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. //
  13. // Private macros.
  14. //
  15. //
  16. // Private prototypes.
  17. //
  18. //
  19. // Public functions.
  20. //
  21. /***************************************************************************++
  22. Routine Description:
  23. Waits for an incoming HTTP request from HTTP.SYS.
  24. Arguments:
  25. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  26. as returned from either HttpCreateAppPool() or
  27. HttpOpenAppPool().
  28. RequestId - Supplies an opaque identifier to receive a specific
  29. request. If this value is HTTP_NULL_ID, then receive any request.
  30. Flags - Currently unused and must be zero.
  31. pRequestBuffer - Supplies a pointer to the request buffer to be filled
  32. in by HTTP.SYS.
  33. RequestBufferLength - Supplies the length of pRequestBuffer.
  34. pBytesReturned - Optionally supplies a pointer to a ULONG which will
  35. receive the actual length of the data returned in the request buffer
  36. if this request completes synchronously (in-line).
  37. pOverlapped - Optionally supplies an OVERLAPPED structure for the
  38. request.
  39. Return Value:
  40. ULONG - Completion status.
  41. --***************************************************************************/
  42. ULONG
  43. WINAPI
  44. HttpReceiveHttpRequest(
  45. IN HANDLE AppPoolHandle,
  46. IN HTTP_REQUEST_ID RequestId,
  47. IN ULONG Flags,
  48. OUT PHTTP_REQUEST pRequestBuffer,
  49. IN ULONG RequestBufferLength,
  50. OUT PULONG pBytesReturned OPTIONAL,
  51. IN LPOVERLAPPED pOverlapped OPTIONAL
  52. )
  53. {
  54. HTTP_RECEIVE_REQUEST_INFO ReceiveInfo;
  55. #if DBG
  56. if (pRequestBuffer)
  57. {
  58. RtlFillMemory( pRequestBuffer, RequestBufferLength, (UCHAR)'\xc' );
  59. }
  60. #endif
  61. ReceiveInfo.RequestId = RequestId;
  62. ReceiveInfo.Flags = Flags;
  63. //
  64. // Make the request.
  65. //
  66. return HttpApiDeviceControl(
  67. AppPoolHandle, // FileHandle
  68. pOverlapped, // pOverlapped
  69. IOCTL_HTTP_RECEIVE_HTTP_REQUEST, // IoControlCode
  70. &ReceiveInfo, // pInputBuffer
  71. sizeof(ReceiveInfo), // InputBufferLength
  72. pRequestBuffer, // pOutputBuffer
  73. RequestBufferLength, // OutputBufferLength
  74. pBytesReturned // pBytesTransferred
  75. );
  76. } // HttpReceiveHttpRequest
  77. /***************************************************************************++
  78. Routine Description:
  79. Receives entity body for a request already read via ReceiveHttpRequest.
  80. Arguments:
  81. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  82. as returned from either HttpCreateAppPool() or
  83. HttpOpenAppPool().
  84. RequestId - Supplies an opaque identifier to receive a specific
  85. request. If this value is HTTP_NULL_ID, then receive any request.
  86. pEntityBodyBuffer - Supplies a pointer to the request buffer to be filled
  87. in by HTTP.SYS.
  88. EntityBufferLength - Supplies the length of pEntityBuffer.
  89. pBytesReturned - Optionally supplies a pointer to a ULONG which will
  90. receive the actual length of the data returned in the request buffer
  91. if this request completes synchronously (in-line).
  92. pOverlapped - Optionally supplies an OVERLAPPED structure for the
  93. request.
  94. Return Value:
  95. ULONG - Completion status.
  96. --***************************************************************************/
  97. ULONG
  98. WINAPI
  99. HttpReceiveRequestEntityBody(
  100. IN HANDLE AppPoolHandle,
  101. IN HTTP_REQUEST_ID RequestId,
  102. IN ULONG Flags,
  103. OUT PVOID pEntityBuffer,
  104. IN ULONG EntityBufferLength,
  105. OUT PULONG pBytesReturned,
  106. IN LPOVERLAPPED pOverlapped OPTIONAL
  107. )
  108. {
  109. HTTP_RECEIVE_REQUEST_INFO ReceiveInfo;
  110. #if DBG
  111. if (pEntityBuffer != NULL)
  112. {
  113. RtlFillMemory( pEntityBuffer, EntityBufferLength, (UCHAR)'\xc' );
  114. }
  115. #endif
  116. ReceiveInfo.RequestId = RequestId;
  117. ReceiveInfo.Flags = Flags;
  118. //
  119. // Make the request.
  120. //
  121. return HttpApiDeviceControl(
  122. AppPoolHandle, // FileHandle
  123. pOverlapped, // pOverlapped
  124. IOCTL_HTTP_RECEIVE_ENTITY_BODY, // IoControlCode
  125. &ReceiveInfo, // pInputBuffer
  126. sizeof(ReceiveInfo), // InputBufferLength
  127. pEntityBuffer, // pOutputBuffer
  128. EntityBufferLength, // OutputBufferLength
  129. pBytesReturned // pBytesTransferred
  130. );
  131. } // HttpReceiveRequestEntityBody
  132. /***************************************************************************++
  133. Routine Description:
  134. Sends an HTTP response on the specified connection.
  135. Arguments:
  136. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  137. as returned from either HttpCreateAppPool() or
  138. HttpOpenAppPool().
  139. RequestId - Supplies an opaque identifier specifying the request
  140. the response is for.
  141. Flags - Supplies zero or more HTTP_SEND_RESPONSE_FLAG_* control flags.
  142. pHttpResponse - Supplies the HTTP response.
  143. pCachePolicy - Supplies caching policy for the response.
  144. pBytesSent - Optionally supplies a pointer to a ULONG which will
  145. receive the actual length of the data sent if this request
  146. completes synchronously (in-line).
  147. pOverlapped - Optionally supplies an OVERLAPPED structure.
  148. Return Value:
  149. ULONG - Completion status.
  150. --***************************************************************************/
  151. ULONG
  152. WINAPI
  153. HttpSendHttpResponse(
  154. IN HANDLE AppPoolHandle,
  155. IN HTTP_REQUEST_ID RequestId,
  156. IN ULONG Flags,
  157. IN PHTTP_RESPONSE pHttpResponse,
  158. IN PHTTP_CACHE_POLICY pCachePolicy OPTIONAL,
  159. OUT PULONG pBytesSent OPTIONAL,
  160. OUT PHTTP_REQUEST pRequestBuffer OPTIONAL,
  161. IN ULONG RequestBufferLength OPTIONAL,
  162. IN LPOVERLAPPED pOverlapped OPTIONAL,
  163. IN PHTTP_LOG_FIELDS_DATA pLogData OPTIONAL
  164. )
  165. {
  166. HTTP_SEND_HTTP_RESPONSE_INFO responseInfo;
  167. //
  168. // Build the response structure.
  169. //
  170. RtlZeroMemory(&responseInfo, sizeof(responseInfo));
  171. responseInfo.pHttpResponse = pHttpResponse;
  172. responseInfo.EntityChunkCount = pHttpResponse->EntityChunkCount;
  173. responseInfo.pEntityChunks = pHttpResponse->pEntityChunks;
  174. if (pCachePolicy != NULL)
  175. {
  176. responseInfo.CachePolicy = *pCachePolicy;
  177. } else {
  178. responseInfo.CachePolicy.Policy = HttpCachePolicyNocache;
  179. responseInfo.CachePolicy.SecondsToLive = 0;
  180. }
  181. responseInfo.RequestId = RequestId;
  182. responseInfo.Flags = Flags;
  183. responseInfo.pLogData = pLogData;
  184. if (pRequestBuffer)
  185. {
  186. pRequestBuffer->RequestId = HTTP_NULL_ID;
  187. }
  188. //
  189. // Make the request.
  190. //
  191. return HttpApiDeviceControl(
  192. AppPoolHandle, // FileHandle
  193. pOverlapped, // pOverlapped
  194. IOCTL_HTTP_SEND_HTTP_RESPONSE, // IoControlCode
  195. &responseInfo, // pInputBuffer
  196. sizeof(responseInfo), // InputBufferLength
  197. pRequestBuffer, // pOutputBuffer
  198. RequestBufferLength, // OutputBufferLength
  199. pBytesSent // pBytesTransferred
  200. );
  201. } // HttpSendHttpResponse
  202. /***************************************************************************++
  203. Routine Description:
  204. Sends an HTTP response on the specified connection.
  205. Arguments:
  206. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  207. as returned from either HttpCreateAppPool() or
  208. HttpOpenAppPool().
  209. RequestId - Supplies an opaque identifier specifying the request
  210. the response is for.
  211. Flags - Supplies zero or more HTTP_SEND_RESPONSE_FLAG_* control flags.
  212. pBytesSent - Optionally supplies a pointer to a ULONG which will
  213. receive the actual length of the data sent if this request
  214. completes synchronously (in-line).
  215. pOverlapped - Optionally supplies an OVERLAPPED structure.
  216. Return Value:
  217. ULONG - Completion status.
  218. --***************************************************************************/
  219. ULONG
  220. WINAPI
  221. HttpSendResponseEntityBody(
  222. IN HANDLE AppPoolHandle,
  223. IN HTTP_REQUEST_ID RequestId,
  224. IN ULONG Flags,
  225. IN USHORT EntityChunkCount OPTIONAL,
  226. IN PHTTP_DATA_CHUNK pEntityChunks OPTIONAL,
  227. OUT PULONG pBytesSent OPTIONAL,
  228. OUT PHTTP_REQUEST pRequestBuffer OPTIONAL,
  229. IN ULONG RequestBufferLength OPTIONAL,
  230. IN LPOVERLAPPED pOverlapped OPTIONAL,
  231. IN PHTTP_LOG_FIELDS_DATA pLogData OPTIONAL
  232. )
  233. {
  234. HTTP_SEND_HTTP_RESPONSE_INFO responseInfo;
  235. //
  236. // Build the response structure.
  237. //
  238. RtlZeroMemory(&responseInfo, sizeof(responseInfo));
  239. responseInfo.EntityChunkCount = EntityChunkCount;
  240. responseInfo.pEntityChunks = pEntityChunks;
  241. responseInfo.RequestId = RequestId;
  242. responseInfo.Flags = Flags;
  243. responseInfo.pLogData = pLogData;
  244. if (pRequestBuffer)
  245. {
  246. pRequestBuffer->RequestId = HTTP_NULL_ID;
  247. }
  248. //
  249. // Make the request.
  250. //
  251. return HttpApiDeviceControl(
  252. AppPoolHandle, // FileHandle
  253. pOverlapped, // pOverlapped
  254. IOCTL_HTTP_SEND_ENTITY_BODY, // IoControlCode
  255. &responseInfo, // pInputBuffer
  256. sizeof(responseInfo), // InputBufferLength
  257. pRequestBuffer, // pOutputBuffer
  258. RequestBufferLength, // OutputBufferLength
  259. pBytesSent // pBytesTransferred
  260. );
  261. } // HttpSendResponseEntityBody
  262. /***************************************************************************++
  263. Routine Description:
  264. Wait for the client to initiate a disconnect.
  265. Arguments:
  266. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  267. as returned from either HttpCreateAppPool() or
  268. HttpOpenAppPool().
  269. ConnectionId - Supplies an opaque identifier specifying the connection.
  270. pOverlapped - Optionally supplies an OVERLAPPED structure.
  271. Return Value:
  272. ULONG - Completion status.
  273. --***************************************************************************/
  274. ULONG
  275. WINAPI
  276. HttpWaitForDisconnect(
  277. IN HANDLE AppPoolHandle,
  278. IN HTTP_CONNECTION_ID ConnectionId,
  279. IN LPOVERLAPPED pOverlapped OPTIONAL
  280. )
  281. {
  282. HTTP_WAIT_FOR_DISCONNECT_INFO waitInfo;
  283. //
  284. // Build the structure.
  285. //
  286. waitInfo.ConnectionId = ConnectionId;
  287. //
  288. // Make the request.
  289. //
  290. return HttpApiDeviceControl(
  291. AppPoolHandle, // FileHandle
  292. pOverlapped, // pOverlapped
  293. IOCTL_HTTP_WAIT_FOR_DISCONNECT, // IoControlCode
  294. &waitInfo, // pInputBuffer
  295. sizeof(waitInfo), // InputBufferLength
  296. NULL, // pOutputBuffer
  297. 0, // OutputBufferLength
  298. NULL // pBytesTransferred
  299. );
  300. } // HttpWaitForDisconnect
  301. //
  302. // Private functions.
  303. //