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.

261 lines
4.7 KiB

  1. #ifndef _W3CONN_HXX_
  2. #define _W3CONN_HXX_
  3. //
  4. // W3_CONNECTION - Object representing an HTTP connection. Connection
  5. // associated state (like multi-leg authentication) is stored
  6. // here
  7. //
  8. #define W3_CONNECTION_SIGNATURE ((DWORD) 'NC3W')
  9. #define W3_CONNECTION_SIGNATURE_FREE ((DWORD) 'nc3w')
  10. class W3_CONNECTION_HASH;
  11. class W3_CONNECTION
  12. {
  13. private:
  14. DWORD _dwSignature;
  15. //
  16. // Connection ID for this connection
  17. //
  18. HTTP_CONNECTION_ID _connId;
  19. //
  20. // Reference count for this connection (deleted on 0, duh)
  21. //
  22. LONG _cRefs;
  23. //
  24. // Connection state to cleanup on connection cleanup
  25. //
  26. W3_CONNECTION_STATE * _rgConnectionState[ STATE_COUNT ];
  27. //
  28. // Connection filter state (pool items and private contexts)
  29. //
  30. W3_FILTER_CONNECTION_CONTEXT _FilterConnectionContext;
  31. //
  32. // User context associated with connection
  33. //
  34. W3_USER_CONTEXT * _pUserContext;
  35. //
  36. // set to TRUE unless connection was disconnected
  37. //
  38. BOOL _fConnected;
  39. //
  40. // W3_CONNECTION hash table
  41. //
  42. static W3_CONNECTION_HASH * sm_pConnectionTable;
  43. static ALLOC_CACHE_HANDLER * sm_pachW3Connections;
  44. public:
  45. W3_CONNECTION(
  46. HTTP_CONNECTION_ID connectionId
  47. );
  48. ~W3_CONNECTION();
  49. HTTP_CONNECTION_ID
  50. QueryConnectionId(
  51. VOID
  52. ) const
  53. {
  54. return _connId;
  55. }
  56. BOOL
  57. CheckSignature(
  58. VOID
  59. ) const
  60. {
  61. return _dwSignature == W3_CONNECTION_SIGNATURE;
  62. }
  63. W3_CONNECTION_STATE *
  64. QueryConnectionState(
  65. DWORD stateIndex
  66. )
  67. {
  68. return _rgConnectionState[ stateIndex ];
  69. }
  70. VOID
  71. SetConnectionState(
  72. DWORD stateIndex,
  73. W3_CONNECTION_STATE * pState
  74. )
  75. {
  76. _rgConnectionState[ stateIndex ] = pState;
  77. }
  78. W3_FILTER_CONNECTION_CONTEXT *
  79. QueryFilterConnectionContext(
  80. VOID
  81. )
  82. {
  83. return &_FilterConnectionContext;
  84. }
  85. W3_USER_CONTEXT *
  86. QueryUserContext(
  87. VOID
  88. ) const
  89. {
  90. return _pUserContext;
  91. }
  92. VOID
  93. SetUserContext(
  94. W3_USER_CONTEXT * pUserContext
  95. )
  96. {
  97. _pUserContext = pUserContext;
  98. }
  99. BOOL
  100. QueryConnected(
  101. VOID)
  102. {
  103. return _fConnected;
  104. }
  105. VOID *
  106. operator new(
  107. size_t size
  108. )
  109. {
  110. DBG_ASSERT( size == sizeof( W3_CONNECTION ) );
  111. DBG_ASSERT( sm_pachW3Connections != NULL );
  112. return sm_pachW3Connections->Alloc();
  113. }
  114. VOID
  115. operator delete(
  116. VOID * pW3Connection
  117. )
  118. {
  119. DBG_ASSERT( pW3Connection != NULL );
  120. DBG_ASSERT( sm_pachW3Connections != NULL );
  121. DBG_REQUIRE( sm_pachW3Connections->Free( pW3Connection ) );
  122. }
  123. VOID
  124. ReferenceConnection(
  125. VOID
  126. );
  127. VOID
  128. DereferenceConnection(
  129. VOID
  130. );
  131. VOID
  132. RemoveConnection(
  133. VOID
  134. );
  135. static HRESULT
  136. Initialize(
  137. VOID
  138. );
  139. static VOID
  140. Terminate(
  141. VOID
  142. );
  143. static HRESULT
  144. RetrieveConnection(
  145. HTTP_CONNECTION_ID connectionId,
  146. BOOL fCreateIfNotFound,
  147. W3_CONNECTION ** ppConnection
  148. );
  149. };
  150. //
  151. // W3_CONNECTION_HASH
  152. //
  153. class W3_CONNECTION_HASH
  154. : public CTypedHashTable<
  155. W3_CONNECTION_HASH,
  156. W3_CONNECTION,
  157. ULONGLONG
  158. >
  159. {
  160. public:
  161. W3_CONNECTION_HASH()
  162. : CTypedHashTable< W3_CONNECTION_HASH,
  163. W3_CONNECTION,
  164. ULONGLONG > ( "W3_CONNECTION_HASH" )
  165. {
  166. }
  167. static
  168. ULONGLONG
  169. ExtractKey(
  170. const W3_CONNECTION * pConnection
  171. )
  172. {
  173. return pConnection->QueryConnectionId();
  174. }
  175. static
  176. DWORD
  177. CalcKeyHash(
  178. ULONGLONG ullKey
  179. )
  180. {
  181. return Hash( (DWORD) ullKey );
  182. }
  183. static
  184. bool
  185. EqualKeys(
  186. ULONGLONG ullKey1,
  187. ULONGLONG ullKey2
  188. )
  189. {
  190. return ullKey1 == ullKey2;
  191. }
  192. static
  193. void
  194. AddRefRecord(
  195. W3_CONNECTION * pEntry,
  196. int nIncr
  197. )
  198. {
  199. if ( nIncr == +1 )
  200. {
  201. pEntry->ReferenceConnection();
  202. }
  203. else if ( nIncr == -1 )
  204. {
  205. pEntry->DereferenceConnection();
  206. }
  207. }
  208. };
  209. VOID
  210. OnUlDisconnect(
  211. VOID * pvContext
  212. );
  213. #endif