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.

278 lines
5.3 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. HTTP_CONNECTION_ID *
  57. QueryConnectionIdKey(
  58. VOID
  59. ) const
  60. {
  61. return (HTTP_CONNECTION_ID*) &_connId;
  62. }
  63. BOOL
  64. CheckSignature(
  65. VOID
  66. ) const
  67. {
  68. return _dwSignature == W3_CONNECTION_SIGNATURE;
  69. }
  70. W3_CONNECTION_STATE *
  71. QueryConnectionState(
  72. DWORD stateIndex
  73. )
  74. {
  75. return _rgConnectionState[ stateIndex ];
  76. }
  77. VOID
  78. SetConnectionState(
  79. DWORD stateIndex,
  80. W3_CONNECTION_STATE * pState
  81. )
  82. {
  83. _rgConnectionState[ stateIndex ] = pState;
  84. }
  85. W3_FILTER_CONNECTION_CONTEXT *
  86. QueryFilterConnectionContext(
  87. VOID
  88. )
  89. {
  90. return &_FilterConnectionContext;
  91. }
  92. W3_USER_CONTEXT *
  93. QueryUserContext(
  94. VOID
  95. ) const
  96. {
  97. return _pUserContext;
  98. }
  99. VOID
  100. SetUserContext(
  101. W3_USER_CONTEXT * pUserContext
  102. )
  103. {
  104. _pUserContext = pUserContext;
  105. }
  106. BOOL
  107. QueryConnected(
  108. VOID)
  109. {
  110. return _fConnected;
  111. }
  112. VOID *
  113. operator new(
  114. #if DBG
  115. size_t size
  116. #else
  117. size_t
  118. #endif
  119. )
  120. {
  121. DBG_ASSERT( size == sizeof( W3_CONNECTION ) );
  122. DBG_ASSERT( sm_pachW3Connections != NULL );
  123. return sm_pachW3Connections->Alloc();
  124. }
  125. VOID
  126. operator delete(
  127. VOID * pW3Connection
  128. )
  129. {
  130. DBG_ASSERT( pW3Connection != NULL );
  131. DBG_ASSERT( sm_pachW3Connections != NULL );
  132. DBG_REQUIRE( sm_pachW3Connections->Free( pW3Connection ) );
  133. }
  134. VOID
  135. ReferenceConnection(
  136. VOID
  137. );
  138. VOID
  139. DereferenceConnection(
  140. VOID
  141. );
  142. VOID
  143. RemoveConnection(
  144. VOID
  145. );
  146. static HRESULT
  147. Initialize(
  148. VOID
  149. );
  150. static VOID
  151. Terminate(
  152. VOID
  153. );
  154. static HRESULT
  155. RetrieveConnection(
  156. HTTP_CONNECTION_ID connectionId,
  157. BOOL fCreateIfNotFound,
  158. W3_CONNECTION ** ppConnection
  159. );
  160. };
  161. //
  162. // W3_CONNECTION_HASH
  163. //
  164. class W3_CONNECTION_HASH
  165. : public CTypedHashTable<
  166. W3_CONNECTION_HASH,
  167. W3_CONNECTION,
  168. ULONGLONG *
  169. >
  170. {
  171. public:
  172. W3_CONNECTION_HASH()
  173. : CTypedHashTable< W3_CONNECTION_HASH,
  174. W3_CONNECTION,
  175. ULONGLONG * > ( "W3_CONNECTION_HASH" )
  176. {
  177. }
  178. static
  179. ULONGLONG *
  180. ExtractKey(
  181. const W3_CONNECTION * pConnection
  182. )
  183. {
  184. return pConnection->QueryConnectionIdKey();
  185. }
  186. static
  187. DWORD
  188. CalcKeyHash(
  189. ULONGLONG * ullKey
  190. )
  191. {
  192. return HashBlob( ullKey, sizeof( ULONGLONG ) );
  193. }
  194. static
  195. bool
  196. EqualKeys(
  197. ULONGLONG * ullKey1,
  198. ULONGLONG * ullKey2
  199. )
  200. {
  201. return *ullKey1 == *ullKey2;
  202. }
  203. static
  204. void
  205. AddRefRecord(
  206. W3_CONNECTION * pEntry,
  207. int nIncr
  208. )
  209. {
  210. if ( nIncr == +1 )
  211. {
  212. pEntry->ReferenceConnection();
  213. }
  214. else if ( nIncr == -1 )
  215. {
  216. pEntry->DereferenceConnection();
  217. }
  218. }
  219. private:
  220. W3_CONNECTION_HASH(const W3_CONNECTION_HASH &);
  221. void operator=(const W3_CONNECTION_HASH &);
  222. };
  223. VOID
  224. OnUlDisconnect(
  225. VOID * pvContext
  226. );
  227. #endif