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.

417 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. httpio.c
  5. Abstract:
  6. User-mode interface to HTTP.SYS.
  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. IN PHTTP_REQUEST pRequestBuffer,
  49. IN ULONG RequestBufferLength,
  50. OUT PULONG pBytesReturned OPTIONAL,
  51. IN LPOVERLAPPED pOverlapped OPTIONAL
  52. )
  53. {
  54. NTSTATUS status;
  55. HTTP_RECEIVE_REQUEST_INFO ReceiveInfo;
  56. #if DBG
  57. RtlFillMemory( pRequestBuffer, RequestBufferLength, '\xcc' );
  58. #endif
  59. ReceiveInfo.RequestId = RequestId;
  60. ReceiveInfo.Flags = Flags;
  61. //
  62. // Make the request.
  63. //
  64. status = HttpApiDeviceControl(
  65. AppPoolHandle, // FileHandle
  66. pOverlapped, // pOverlapped
  67. IOCTL_HTTP_RECEIVE_HTTP_REQUEST, // IoControlCode
  68. &ReceiveInfo, // pInputBuffer
  69. sizeof(ReceiveInfo), // InputBufferLength
  70. pRequestBuffer, // pOutputBuffer
  71. RequestBufferLength, // OutputBufferLength
  72. pBytesReturned // pBytesTransferred
  73. );
  74. return HttpApiNtStatusToWin32Status( status );
  75. } // HttpReceiveHttpRequest
  76. /***************************************************************************++
  77. Routine Description:
  78. Receives entity body for a request already read via ReceiveHttpRequest.
  79. Arguments:
  80. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  81. as returned from either HttpCreateAppPool() or
  82. HttpOpenAppPool().
  83. RequestId - Supplies an opaque identifier to receive a specific
  84. request. If this value is HTTP_NULL_ID, then receive any request.
  85. pEntityBodyBuffer - Supplies a pointer to the request buffer to be filled
  86. in by HTTP.SYS.
  87. EntityBufferLength - Supplies the length of pEntityBuffer.
  88. pBytesReturned - Optionally supplies a pointer to a ULONG which will
  89. receive the actual length of the data returned in the request buffer
  90. if this request completes synchronously (in-line).
  91. pOverlapped - Optionally supplies an OVERLAPPED structure for the
  92. request.
  93. Return Value:
  94. ULONG - Completion status.
  95. --***************************************************************************/
  96. ULONG
  97. WINAPI
  98. HttpReceiveEntityBody(
  99. IN HANDLE AppPoolHandle,
  100. IN HTTP_REQUEST_ID RequestId,
  101. IN ULONG Flags,
  102. OUT PVOID pEntityBuffer,
  103. IN ULONG EntityBufferLength,
  104. OUT PULONG pBytesReturned,
  105. IN LPOVERLAPPED pOverlapped OPTIONAL
  106. )
  107. {
  108. NTSTATUS Status;
  109. HTTP_RECEIVE_REQUEST_INFO ReceiveInfo;
  110. #if DBG
  111. if (pEntityBuffer != NULL)
  112. {
  113. RtlFillMemory( pEntityBuffer, EntityBufferLength, '\xcc' );
  114. }
  115. #endif
  116. ReceiveInfo.RequestId = RequestId;
  117. ReceiveInfo.Flags = Flags;
  118. //
  119. // Make the request.
  120. //
  121. Status = 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. return HttpApiNtStatusToWin32Status( Status );
  132. }
  133. /***************************************************************************++
  134. Routine Description:
  135. Sends an HTTP response on the specified connection.
  136. Arguments:
  137. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  138. as returned from either HttpCreateAppPool() or
  139. HttpOpenAppPool().
  140. RequestId - Supplies an opaque identifier specifying the request
  141. the response is for.
  142. Flags - Supplies zero or more HTTP_SEND_RESPONSE_FLAG_* control flags.
  143. pHttpResponse - Supplies the HTTP response.
  144. pCachePolicy - Supplies caching policy for the response.
  145. pBytesSent - Optionally supplies a pointer to a ULONG which will
  146. receive the actual length of the data sent if this request
  147. completes synchronously (in-line).
  148. pOverlapped - Optionally supplies an OVERLAPPED structure.
  149. Return Value:
  150. ULONG - Completion status.
  151. --***************************************************************************/
  152. ULONG
  153. WINAPI
  154. HttpSendHttpResponse(
  155. IN HANDLE AppPoolHandle,
  156. IN HTTP_REQUEST_ID RequestId,
  157. IN ULONG Flags,
  158. IN PHTTP_RESPONSE pHttpResponse,
  159. IN PHTTP_CACHE_POLICY pCachePolicy OPTIONAL,
  160. OUT PULONG pBytesSent OPTIONAL,
  161. IN LPOVERLAPPED pOverlapped OPTIONAL,
  162. IN PHTTP_LOG_FIELDS_DATA pLogData OPTIONAL
  163. )
  164. {
  165. NTSTATUS status;
  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. //
  185. // Make the request.
  186. //
  187. status = HttpApiDeviceControl(
  188. AppPoolHandle, // FileHandle
  189. pOverlapped, // pOverlapped
  190. IOCTL_HTTP_SEND_HTTP_RESPONSE, // IoControlCode
  191. &responseInfo, // pInputBuffer
  192. sizeof(responseInfo), // InputBufferLength
  193. NULL, // pOutputBuffer
  194. 0, // OutputBufferLength
  195. pBytesSent // pBytesTransferred
  196. );
  197. return HttpApiNtStatusToWin32Status( status );
  198. } // HttpSendHttpResponse
  199. /***************************************************************************++
  200. Routine Description:
  201. Sends an HTTP response on the specified connection.
  202. Arguments:
  203. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  204. as returned from either HttpCreateAppPool() or
  205. HttpOpenAppPool().
  206. RequestId - Supplies an opaque identifier specifying the request
  207. the response is for.
  208. Flags - Supplies zero or more HTTP_SEND_RESPONSE_FLAG_* control flags.
  209. pBytesSent - Optionally supplies a pointer to a ULONG which will
  210. receive the actual length of the data sent if this request
  211. completes synchronously (in-line).
  212. pOverlapped - Optionally supplies an OVERLAPPED structure.
  213. Return Value:
  214. ULONG - Completion status.
  215. --***************************************************************************/
  216. ULONG
  217. WINAPI
  218. HttpSendEntityBody(
  219. IN HANDLE AppPoolHandle,
  220. IN HTTP_REQUEST_ID RequestId,
  221. IN ULONG Flags,
  222. IN ULONG EntityChunkCount OPTIONAL,
  223. IN PHTTP_DATA_CHUNK pEntityChunks OPTIONAL,
  224. OUT PULONG pBytesSent OPTIONAL,
  225. IN LPOVERLAPPED pOverlapped OPTIONAL,
  226. IN PHTTP_LOG_FIELDS_DATA pLogData OPTIONAL
  227. )
  228. {
  229. NTSTATUS status;
  230. HTTP_SEND_HTTP_RESPONSE_INFO responseInfo;
  231. //
  232. // Build the response structure.
  233. //
  234. RtlZeroMemory(&responseInfo, sizeof(responseInfo));
  235. responseInfo.EntityChunkCount = EntityChunkCount;
  236. responseInfo.pEntityChunks = pEntityChunks;
  237. responseInfo.RequestId = RequestId;
  238. responseInfo.Flags = Flags;
  239. responseInfo.pLogData = pLogData;
  240. //
  241. // Make the request.
  242. //
  243. status = HttpApiDeviceControl(
  244. AppPoolHandle, // FileHandle
  245. pOverlapped, // pOverlapped
  246. IOCTL_HTTP_SEND_ENTITY_BODY, // IoControlCode
  247. &responseInfo, // pInputBuffer
  248. sizeof(responseInfo), // InputBufferLength
  249. NULL, // pOutputBuffer
  250. 0, // OutputBufferLength
  251. pBytesSent // pBytesTransferred
  252. );
  253. return HttpApiNtStatusToWin32Status( status );
  254. } // HttpSendEntityBody
  255. /***************************************************************************++
  256. Routine Description:
  257. Wait for the client to initiate a disconnect.
  258. Arguments:
  259. AppPoolHandle - Supplies a handle to a HTTP.SYS application pool
  260. as returned from either HttpCreateAppPool() or
  261. HttpOpenAppPool().
  262. ConnectionId - Supplies an opaque identifier specifying the connection.
  263. pOverlapped - Optionally supplies an OVERLAPPED structure.
  264. Return Value:
  265. ULONG - Completion status.
  266. --***************************************************************************/
  267. ULONG
  268. WINAPI
  269. HttpWaitForDisconnect(
  270. IN HANDLE AppPoolHandle,
  271. IN HTTP_CONNECTION_ID ConnectionId,
  272. IN LPOVERLAPPED pOverlapped OPTIONAL
  273. )
  274. {
  275. NTSTATUS status;
  276. HTTP_WAIT_FOR_DISCONNECT_INFO waitInfo;
  277. //
  278. // Build the structure.
  279. //
  280. waitInfo.ConnectionId = ConnectionId;
  281. //
  282. // Make the request.
  283. //
  284. status = HttpApiDeviceControl(
  285. AppPoolHandle, // FileHandle
  286. pOverlapped, // pOverlapped
  287. IOCTL_HTTP_WAIT_FOR_DISCONNECT, // IoControlCode
  288. &waitInfo, // pInputBuffer
  289. sizeof(waitInfo), // InputBufferLength
  290. NULL, // pOutputBuffer
  291. 0, // OutputBufferLength
  292. NULL // pBytesTransferred
  293. );
  294. return HttpApiNtStatusToWin32Status( status );
  295. } // HttpWaitForDisconnect
  296. //
  297. // Private functions.
  298. //