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.

419 lines
11 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. httpconn.h
  5. Abstract:
  6. This module contains declarations for manipulation HTTP_CONNECTION
  7. objects.
  8. Author:
  9. Keith Moore (keithmo) 08-Jul-1998
  10. Revision History:
  11. --*/
  12. /*
  13. there is a bit of refcount madness going on. basically, these are the
  14. object we have.
  15. OPAQUE_ID_TABLE
  16. |
  17. |--> UL_INTERNAL_REQUEST
  18. |
  19. | o
  20. | |
  21. |--> UL_HTTP_CONNECTION
  22. |
  23. o
  24. o
  25. |
  26. UL_CONNECTION
  27. there is a circular reference from UL_CONNECTION to UL_HTTP_CONNECTION.
  28. the chain that brings down a connection starts with UlConnectionDestroyed
  29. notifcation which releases the reference from the UL_CONNECTION.
  30. at this time the opaque id's are also deleted, releasing their references.
  31. when the http_connection refcount hits 0, it releases the reference on the
  32. UL_CONNECTION and the HTTP_REQUEST's.
  33. poof. everyone is gone now.
  34. CODEWORK: think about making hardref's everywhere and adding "letgo"
  35. terminate methods
  36. */
  37. #ifndef _HTTPCONN_H_
  38. #define _HTTPCONN_H_
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. //
  43. // Refcounted structure to hold the number of conn for each Site.
  44. // Multiple connections may try to reach to the same entry thru the
  45. // the corresponding ( means the last request's happening on the connection )
  46. // cgroup. This entry get allocated when cgroup created with connection
  47. // limit is enabled.
  48. //
  49. typedef struct _UL_CONNECTION_COUNT_ENTRY {
  50. //
  51. // Signature is UL_CONNECTION_COUNT_ENTRY_POOL_TAG
  52. //
  53. ULONG Signature;
  54. //
  55. // Ref count for this Site Counter Entry
  56. //
  57. LONG RefCount;
  58. //
  59. // Current number of connections
  60. //
  61. ULONG CurConnections;
  62. //
  63. // Maximum allowed connections
  64. //
  65. ULONG MaxConnections;
  66. } UL_CONNECTION_COUNT_ENTRY, *PUL_CONNECTION_COUNT_ENTRY;
  67. #define IS_VALID_CONNECTION_COUNT_ENTRY( entry ) \
  68. ( (entry != NULL) && ((entry)->Signature == UL_CONNECTION_COUNT_ENTRY_POOL_TAG) )
  69. VOID
  70. UlDereferenceConnectionCountEntry(
  71. IN PUL_CONNECTION_COUNT_ENTRY pEntry
  72. REFERENCE_DEBUG_FORMAL_PARAMS
  73. );
  74. #define DEREFERENCE_CONNECTION_COUNT_ENTRY( pEntry ) \
  75. UlDereferenceConnectionCountEntry( \
  76. (pEntry) \
  77. REFERENCE_DEBUG_ACTUAL_PARAMS \
  78. )
  79. VOID
  80. UlReferenceConnectionCountEntry(
  81. IN PUL_CONNECTION_COUNT_ENTRY pEntry
  82. REFERENCE_DEBUG_FORMAL_PARAMS
  83. );
  84. #define REFERENCE_CONNECTION_COUNT_ENTRY( pEntry ) \
  85. UlReferenceConnectionCountEntry( \
  86. (pEntry) \
  87. REFERENCE_DEBUG_ACTUAL_PARAMS \
  88. )
  89. NTSTATUS
  90. UlCreateConnectionCountEntry(
  91. IN OUT PUL_CONFIG_GROUP_OBJECT pConfigGroup,
  92. IN ULONG MaxConnections
  93. );
  94. ULONG
  95. UlSetMaxConnections(
  96. IN OUT PULONG pCurMaxConnection,
  97. IN ULONG NewMaxConnection
  98. );
  99. VOID
  100. UlSetGlobalConnectionLimit(
  101. IN ULONG Limit
  102. );
  103. NTSTATUS
  104. UlInitGlobalConnectionLimits(
  105. VOID
  106. );
  107. BOOLEAN
  108. UlAcceptConnection(
  109. IN PULONG pMaxConnection,
  110. IN OUT PULONG pCurConnection
  111. );
  112. LONG
  113. UlDecrementConnections(
  114. IN OUT PULONG pCurConnection
  115. );
  116. BOOLEAN
  117. UlCheckSiteConnectionLimit(
  118. IN OUT PUL_HTTP_CONNECTION pConnection,
  119. IN OUT PUL_URL_CONFIG_GROUP_INFO pConfigInfo
  120. );
  121. BOOLEAN
  122. UlAcceptGlobalConnection(
  123. VOID
  124. );
  125. //
  126. // function prototypes
  127. //
  128. NTSTATUS
  129. UlCreateHttpConnection(
  130. OUT PUL_HTTP_CONNECTION *ppHttpConnection,
  131. IN PUL_CONNECTION pConnection
  132. );
  133. NTSTATUS
  134. UlCreateHttpConnectionId(
  135. IN PUL_HTTP_CONNECTION pHttpConnection
  136. );
  137. VOID
  138. UlConnectionDestroyedWorker(
  139. IN PUL_WORK_ITEM pWorkItem
  140. );
  141. NTSTATUS
  142. UlBindConnectionToProcess(
  143. IN PUL_HTTP_CONNECTION pHttpConnection,
  144. IN PUL_APP_POOL_OBJECT pAppPool,
  145. IN PUL_APP_POOL_PROCESS pProcess
  146. );
  147. PUL_APP_POOL_PROCESS
  148. UlQueryProcessBinding(
  149. IN PUL_HTTP_CONNECTION pHttpConnection,
  150. IN PUL_APP_POOL_OBJECT pAppPool
  151. );
  152. VOID
  153. UlUnlinkHttpRequest(
  154. IN PUL_INTERNAL_REQUEST pRequest
  155. );
  156. VOID
  157. UlCleanupHttpConnection(
  158. IN PUL_HTTP_CONNECTION pHttpConnection
  159. );
  160. VOID
  161. UlDeleteHttpConnection(
  162. IN PUL_WORK_ITEM pWorkItem
  163. );
  164. VOID
  165. UlReferenceHttpConnection(
  166. IN PVOID pObject
  167. REFERENCE_DEBUG_FORMAL_PARAMS
  168. );
  169. VOID
  170. UlDereferenceHttpConnection(
  171. IN PUL_HTTP_CONNECTION pHttpConnection
  172. REFERENCE_DEBUG_FORMAL_PARAMS
  173. );
  174. #if REFERENCE_DEBUG
  175. #define UL_REFERENCE_HTTP_CONNECTION( pconn ) \
  176. UlReferenceHttpConnection( \
  177. (pconn) \
  178. REFERENCE_DEBUG_ACTUAL_PARAMS \
  179. )
  180. #define UL_DEREFERENCE_HTTP_CONNECTION( pconn ) \
  181. UlDereferenceHttpConnection( \
  182. (pconn) \
  183. REFERENCE_DEBUG_ACTUAL_PARAMS \
  184. )
  185. #else
  186. #define UL_REFERENCE_HTTP_CONNECTION( pconn ) \
  187. InterlockedIncrement( &( pconn )->RefCount )
  188. #define UL_DEREFERENCE_HTTP_CONNECTION( pconn ) \
  189. if ( InterlockedDecrement( &( pconn )->RefCount ) == 0 ) \
  190. { \
  191. UL_CALL_PASSIVE( \
  192. &( ( pconn )->WorkItem ), \
  193. &UlDeleteHttpConnection \
  194. ); \
  195. }
  196. #endif
  197. NTSTATUS
  198. UlpCreateHttpRequest(
  199. IN PUL_HTTP_CONNECTION pHttpConnection,
  200. OUT PUL_INTERNAL_REQUEST *ppRequest
  201. );
  202. VOID
  203. UlpFreeHttpRequest(
  204. IN PUL_WORK_ITEM pWorkItem
  205. );
  206. VOID
  207. UlReferenceHttpRequest(
  208. IN PVOID pObject
  209. REFERENCE_DEBUG_FORMAL_PARAMS
  210. );
  211. VOID
  212. UlDereferenceHttpRequest(
  213. IN PUL_INTERNAL_REQUEST pRequest
  214. REFERENCE_DEBUG_FORMAL_PARAMS
  215. );
  216. #if REFERENCE_DEBUG
  217. #define UL_REFERENCE_INTERNAL_REQUEST( preq ) \
  218. UlReferenceHttpRequest( \
  219. (preq) \
  220. REFERENCE_DEBUG_ACTUAL_PARAMS \
  221. )
  222. #define UL_DEREFERENCE_INTERNAL_REQUEST( preq ) \
  223. UlDereferenceHttpRequest( \
  224. (preq) \
  225. REFERENCE_DEBUG_ACTUAL_PARAMS \
  226. )
  227. #else
  228. #define UL_REFERENCE_INTERNAL_REQUEST( preq ) \
  229. InterlockedIncrement( &( preq )->RefCount )
  230. #define UL_DEREFERENCE_INTERNAL_REQUEST( preq ) \
  231. if ( InterlockedDecrement( &( preq )->RefCount ) == 0 ) \
  232. { \
  233. UL_CALL_PASSIVE( \
  234. &( ( preq )->WorkItem ), \
  235. &UlpFreeHttpRequest \
  236. ); \
  237. }
  238. #endif
  239. VOID
  240. UlCancelRequestIo(
  241. IN PUL_INTERNAL_REQUEST pRequest
  242. );
  243. PUL_REQUEST_BUFFER
  244. UlCreateRequestBuffer(
  245. ULONG BufferSize,
  246. ULONG BufferNumber
  247. );
  248. VOID
  249. UlFreeRequestBuffer(
  250. PUL_REQUEST_BUFFER pBuffer
  251. );
  252. #define UL_REFERENCE_REQUEST_BUFFER( pbuf ) \
  253. InterlockedIncrement( &( pbuf )->RefCount )
  254. #define UL_DEREFERENCE_REQUEST_BUFFER( pbuf ) \
  255. if ( InterlockedDecrement( &( pbuf )->RefCount ) == 0 ) \
  256. { \
  257. (pbuf)->Signature = MAKE_FREE_TAG(UL_REQUEST_BUFFER_POOL_TAG); \
  258. \
  259. if ((pbuf)->AllocBytes > DEFAULT_MAX_REQUEST_BUFFER_SIZE) \
  260. { \
  261. UL_FREE_POOL_WITH_SIG((pbuf), UL_REQUEST_BUFFER_POOL_TAG); \
  262. } \
  263. else \
  264. { \
  265. UlPplFreeRequestBuffer((pbuf)); \
  266. } \
  267. }
  268. __inline
  269. PUL_HTTP_CONNECTION
  270. FASTCALL
  271. UlGetConnectionFromId(
  272. IN HTTP_CONNECTION_ID ConnectionId
  273. )
  274. {
  275. return (PUL_HTTP_CONNECTION) UlGetObjectFromOpaqueId(
  276. ConnectionId,
  277. UlOpaqueIdTypeHttpConnection,
  278. UlReferenceHttpConnection
  279. );
  280. }
  281. #define REUSE_CONNECTION_OPAQUE_ID
  282. #ifdef REUSE_CONNECTION_OPAQUE_ID
  283. NTSTATUS
  284. UlAllocateRequestId(
  285. IN PUL_INTERNAL_REQUEST pRequest
  286. );
  287. VOID
  288. UlFreeRequestId(
  289. IN PUL_INTERNAL_REQUEST pRequest
  290. );
  291. PUL_INTERNAL_REQUEST
  292. UlGetRequestFromId(
  293. IN HTTP_REQUEST_ID RequestId
  294. );
  295. #else
  296. __inline
  297. NTSTATUS
  298. UlAllocateRequestId(
  299. IN PUL_INTERNAL_REQUEST pRequest
  300. )
  301. {
  302. return UlAllocateOpaqueId(
  303. &pRequest->RequestId,
  304. UlOpaqueIdTypeHttpRequest,
  305. pRequest
  306. );
  307. }
  308. __inline
  309. NTSTATUS
  310. UlFreeRequestId(
  311. IN PUL_INTERNAL_REQUEST pRequest
  312. )
  313. {
  314. return UlFreeOpaqueId(
  315. &pRequest->RequestId,
  316. UlOpaqueIdTypeHttpRequest
  317. );
  318. }
  319. __inline
  320. PUL_INTERNAL_REQUEST
  321. FASTCALL
  322. UlGetRequestFromId(
  323. IN HTTP_REQUEST_ID RequestId
  324. )
  325. {
  326. return (PUL_INTERNAL_REQUEST) UlGetObjectFromOpaqueId(
  327. RequestId,
  328. UlOpaqueIdTypeHttpRequest,
  329. UlReferenceHttpRequest
  330. );
  331. }
  332. #endif
  333. #ifdef __cplusplus
  334. }; // extern "C"
  335. #endif
  336. #endif // _HTTPCONN_H_