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.

269 lines
7.1 KiB

  1. // ApplicationGatewayServices.h : Declaration of the CApplicationGatewayServices
  2. #pragma once
  3. #include "resource.h" // main symbols
  4. #include "CollectionChannels.h"
  5. #include "CollectionAdapterNotifySinks.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CApplicationGatewayServices
  8. class ATL_NO_VTABLE CApplicationGatewayServices :
  9. public CComObjectRootEx<CComMultiThreadModel>,
  10. public CComCoClass<CApplicationGatewayServices, &CLSID_ApplicationGatewayServices>,
  11. public IApplicationGatewayServices
  12. {
  13. public:
  14. CApplicationGatewayServices()
  15. {
  16. m_hTimerQueue = NULL;
  17. }
  18. ~CApplicationGatewayServices()
  19. {
  20. MYTRACE_ENTER_NOSHOWEXIT("~CApplicationGatewayServices()");
  21. if ( m_hTimerQueue )
  22. {
  23. MYTRACE("Deleting the TimerQueue");
  24. DeleteTimerQueueEx(
  25. m_hTimerQueue, // handle to timer queue
  26. INVALID_HANDLE_VALUE // handle to completion event
  27. );
  28. }
  29. }
  30. HRESULT FinalConstruct()
  31. {
  32. MYTRACE_ENTER_NOSHOWEXIT("CApplicationGatewayServices()::FinalConstruct()");
  33. m_hTimerQueue = CreateTimerQueue();
  34. HRESULT hr = S_OK;
  35. if ( m_hTimerQueue == NULL )
  36. {
  37. hr = HRESULT_FROM_WIN32( GetLastError() );
  38. MYTRACE_ERROR("Could not CreateTimerQueue", hr);
  39. }
  40. return hr;
  41. }
  42. DECLARE_REGISTRY_RESOURCEID(IDR_APPLICATIONGATEWAYSERVICES)
  43. DECLARE_NOT_AGGREGATABLE(CApplicationGatewayServices)
  44. DECLARE_PROTECT_FINAL_CONSTRUCT()
  45. BEGIN_COM_MAP(CApplicationGatewayServices)
  46. COM_INTERFACE_ENTRY(IApplicationGatewayServices)
  47. END_COM_MAP()
  48. // IApplicationGatewayServices
  49. public:
  50. STDMETHODIMP CreatePrimaryControlChannel (
  51. ALG_PROTOCOL eProtocol,
  52. USHORT usPortToCapture,
  53. ALG_CAPTURE eCaptureType,
  54. BOOL fCaptureInbound,
  55. ULONG ulListenAddress,
  56. USHORT usListenPort,
  57. IPrimaryControlChannel** ppIControlChannel
  58. );
  59. STDMETHODIMP CreateSecondaryControlChannel(
  60. ALG_PROTOCOL eProtocol,
  61. ULONG ulPrivateAddress,
  62. USHORT usPrivatePort,
  63. ULONG ulPublicAddress,
  64. USHORT usPublicPort,
  65. ULONG ulRemoteAddress,
  66. USHORT usRemotePort,
  67. ULONG ulListenAddress,
  68. USHORT usListenPort,
  69. ALG_DIRECTION eDirection,
  70. BOOL fPersistent,
  71. ISecondaryControlChannel ** ppControlChannel
  72. );
  73. STDMETHODIMP GetBestSourceAddressForDestinationAddress(
  74. ULONG ulDstAddress,
  75. BOOL fDemandDial,
  76. ULONG * pulBestSrcAddress
  77. );
  78. STDMETHODIMP PrepareProxyConnection(
  79. ALG_PROTOCOL eProtocol,
  80. ULONG ulSrcAddress,
  81. USHORT usSrcPort,
  82. ULONG ulDstAddress,
  83. USHORT usDstPort,
  84. BOOL fNoTimeout,
  85. IPendingProxyConnection ** ppPendingConnection
  86. );
  87. STDMETHODIMP PrepareSourceModifiedProxyConnection(
  88. ALG_PROTOCOL eProtocol,
  89. ULONG ulSrcAddress,
  90. USHORT usSrcPort,
  91. ULONG ulDstAddress,
  92. USHORT usDstPort,
  93. ULONG ulNewSrcAddress,
  94. USHORT usNewSourcePort,
  95. IPendingProxyConnection ** ppPendingConnection
  96. );
  97. STDMETHODIMP CreateDataChannel(
  98. ALG_PROTOCOL eProtocol,
  99. ULONG ulPrivateAddress,
  100. USHORT usPrivatePort,
  101. ULONG ulPublicAddress,
  102. USHORT ulPublicPort,
  103. ULONG ulRemoteAddress,
  104. USHORT ulRemotePort,
  105. ALG_DIRECTION eDirection,
  106. ALG_NOTIFICATION eDesiredNotification,
  107. BOOL fNoTimeout,
  108. IDataChannel** ppDataChannel
  109. );
  110. STDMETHODIMP CreatePersistentDataChannel(
  111. ALG_PROTOCOL eProtocol,
  112. ULONG ulPrivateAddress,
  113. USHORT usPrivatePort,
  114. ULONG ulPublicAddress,
  115. USHORT ulPublicPort,
  116. ULONG ulRemoteAddress,
  117. USHORT ulRemotePort,
  118. ALG_DIRECTION eDirection,
  119. IPersistentDataChannel** ppPersistentDataChannel
  120. );
  121. STDMETHODIMP ReservePort(
  122. USHORT usPortCount,
  123. USHORT* pusReservedPort
  124. );
  125. STDMETHODIMP ReleaseReservedPort(
  126. USHORT usReservedPortBase,
  127. USHORT usPortCount
  128. );
  129. STDMETHODIMP EnumerateAdapters(
  130. IEnumAdapterInfo** ppEnumAdapterInfo
  131. );
  132. STDMETHODIMP StartAdapterNotifications(
  133. IAdapterNotificationSink * pSink,
  134. DWORD* pdwCookie
  135. );
  136. STDMETHODIMP StopAdapterNotifications(
  137. DWORD dwCookieToRemove
  138. );
  139. //
  140. // Properties
  141. //
  142. public:
  143. HANDLE m_hTimerQueue;
  144. //
  145. // Methods
  146. //
  147. public:
  148. static VOID CALLBACK
  149. TimerCallbackReleasePort(
  150. PVOID lpParameter, // thread data
  151. BOOLEAN TimerOrWaitFired // reason
  152. );
  153. };
  154. //
  155. // Reserved port release delay
  156. //
  157. #define ALG_PORT_RELEASE_DELAY 240000
  158. //
  159. //
  160. //
  161. class CTimerQueueReleasePort
  162. {
  163. public:
  164. CTimerQueueReleasePort(
  165. IN HANDLE MainTimerQueue,
  166. IN USHORT usPortBase, // Port to release
  167. IN USHORT usPortCount
  168. ) :
  169. m_hTimerQueue(MainTimerQueue),
  170. m_usPortBase(usPortBase),
  171. m_usPortCount(usPortCount)
  172. {
  173. MYTRACE_ENTER_NOSHOWEXIT("CTimerQueueReleasePort:NEW");
  174. BOOL bRet = CreateTimerQueueTimer(
  175. &m_hTimerThis,
  176. m_hTimerQueue,
  177. CApplicationGatewayServices::TimerCallbackReleasePort,
  178. (PVOID)this,
  179. ALG_PORT_RELEASE_DELAY,
  180. 0,
  181. WT_EXECUTEDEFAULT
  182. );
  183. if ( bRet == FALSE )
  184. {
  185. MYTRACE_ERROR("Could not CreateTimerQueueTimer", GetLastError());
  186. m_hTimerThis = NULL;
  187. }
  188. }
  189. ~CTimerQueueReleasePort()
  190. {
  191. if ( m_hTimerThis )
  192. {
  193. DeleteTimerQueueTimer(
  194. m_hTimerQueue,
  195. m_hTimerThis,
  196. NULL
  197. );
  198. }
  199. }
  200. HANDLE m_hTimerQueue;
  201. HANDLE m_hTimerThis;
  202. USHORT m_usPortBase; // Port to release
  203. USHORT m_usPortCount; // Number of port to release
  204. };