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.

188 lines
7.9 KiB

  1. #pragma once
  2. #include "netconp.h"
  3. #include "dispimpl2.h"
  4. #include "upnphost.h"
  5. #include "InternetGatewayDevice.h"
  6. #include "api.h"
  7. #include "hnetcfg.h"
  8. class CWANConnectionBase :
  9. public CComObjectRootEx<CComMultiThreadModel>,
  10. public IUPnPEventSource,
  11. public INetConnectionNotifySink,
  12. public INATEventsSink,
  13. public IDelegatingDispImpl<IWANIPConnectionService>
  14. {
  15. public:
  16. CWANConnectionBase();
  17. DECLARE_PROTECT_FINAL_CONSTRUCT()
  18. BEGIN_COM_MAP(CWANConnectionBase)
  19. COM_INTERFACE_ENTRY(IWANIPConnectionService)
  20. COM_INTERFACE_ENTRY(IDispatch)
  21. COM_INTERFACE_ENTRY(IUPnPEventSource)
  22. COM_INTERFACE_ENTRY(INetConnectionNotifySink)
  23. END_COM_MAP()
  24. HRESULT StopListening();
  25. HRESULT Initialize(GUID* pGuid, IHNetConnection* pSharedConnection, IStatisticsProvider* pStatisticsProvider);
  26. // IUPnPEventSource methods
  27. STDMETHODIMP Advise(IUPnPEventSink *pesSubscriber);
  28. STDMETHODIMP Unadvise(IUPnPEventSink *pesSubscriber);
  29. // INetConnectionNotifySink
  30. STDMETHODIMP ConnectionAdded(const NETCON_PROPERTIES_EX* pProps);
  31. STDMETHODIMP ConnectionBandWidthChange(const GUID* pguidId);
  32. STDMETHODIMP ConnectionDeleted(const GUID* pguidId);
  33. STDMETHODIMP ConnectionModified(const NETCON_PROPERTIES_EX* pProps);
  34. STDMETHODIMP ConnectionRenamed(const GUID* pguidId, LPCWSTR pszwNewName);
  35. STDMETHODIMP ConnectionStatusChange(const GUID* pguidId, NETCON_STATUS Status);
  36. STDMETHODIMP ConnectionAddressChange(const GUID* pguidId);
  37. STDMETHODIMP ShowBalloon(const GUID* pguidId, const BSTR szCookie, const BSTR szBalloonText);
  38. STDMETHODIMP RefreshAll();
  39. STDMETHODIMP DisableEvents(const BOOL fDisable, const ULONG ulDisableTimeout);
  40. // INATEventsSink
  41. STDMETHODIMP PublicIPAddressChanged(void);
  42. STDMETHODIMP PortMappingsChanged(void);
  43. // IWANPPPConnection and IWANIPConnection
  44. STDMETHODIMP get_ConnectionType(BSTR *pConnectionType);
  45. STDMETHODIMP get_PossibleConnectionTypes(BSTR *pPossibleConnectionTypes);
  46. STDMETHODIMP get_ConnectionStatus(BSTR *pConnectionStatus);
  47. STDMETHODIMP get_Uptime(ULONG *pUptime);
  48. STDMETHODIMP get_UpstreamMaxBitRate(ULONG *pUpstreamMaxBitRate);
  49. STDMETHODIMP get_DownstreamMaxBitRate(ULONG *pDownstreamMaxBitRate);
  50. STDMETHODIMP get_LastConnectionError(BSTR *pLastConnectionError) = 0;
  51. STDMETHODIMP get_RSIPAvailable(VARIANT_BOOL *pRSIPAvailable);
  52. STDMETHODIMP get_NATEnabled(VARIANT_BOOL *pNATEnabled);
  53. STDMETHODIMP get_X_Name(BSTR* pName);
  54. STDMETHODIMP get_ExternalIPAddress(BSTR *pExternalIPAddress);
  55. STDMETHODIMP get_RemoteHost(BSTR *pRemoteHost);
  56. STDMETHODIMP get_ExternalPort(USHORT *pExternalPort);
  57. STDMETHODIMP get_InternalPort(USHORT *pInternalPort);
  58. STDMETHODIMP get_PortMappingProtocol(BSTR *pProtocol);
  59. STDMETHODIMP get_InternalClient(BSTR *pInternalClient);
  60. STDMETHODIMP get_PortMappingDescription(BSTR *pDescription);
  61. STDMETHODIMP get_PortMappingEnabled(VARIANT_BOOL *pEnabled);
  62. STDMETHODIMP get_PortMappingLeaseDuration(ULONG *LeaseDuration);
  63. STDMETHODIMP get_PortMappingNumberOfEntries(USHORT *pNumberOfEntries);
  64. STDMETHODIMP SetConnectionType(BSTR NewConnectionType);
  65. STDMETHODIMP GetConnectionTypeInfo(BSTR* pNewConnectionType, BSTR* pNewPossibleConnectionTypes);
  66. STDMETHODIMP RequestConnection() = 0;
  67. STDMETHODIMP ForceTermination() = 0;
  68. STDMETHODIMP GetStatusInfo(BSTR* pNewConnectionStatus, BSTR* pNewLastConnectionError, ULONG* pNewUptime);
  69. STDMETHODIMP GetNATRSIPStatus(VARIANT_BOOL* pNewRSIPAvailable, VARIANT_BOOL* pNewNATEnabled);
  70. STDMETHODIMP GetLinkLayerMaxBitRates(ULONG* pNewUpstreamMaxBitRate, ULONG* pNewDownstreamMaxBitRate);
  71. STDMETHODIMP GetGenericPortMappingEntry(USHORT uwIndex, BSTR* pRemoteHost, USHORT* puwExternalPort, BSTR* pProtocol, USHORT* puwInternalPort, BSTR* pInternalClient, VARIANT_BOOL* pbEnabled, BSTR* pDescription, ULONG* pulLeaseDuration);
  72. STDMETHODIMP GetSpecificPortMappingEntry(BSTR RemoteHost, USHORT uwExternalPort, BSTR Protocol, USHORT* puwInternalPort, BSTR* pInternalClient, VARIANT_BOOL* pbEnabled, BSTR* pDescription, ULONG* pulLeaseDuration);
  73. STDMETHODIMP AddPortMapping(BSTR RemoteHost, USHORT uwExternalPort, BSTR Protocol, USHORT uwInternalPort, BSTR InternalClient, VARIANT_BOOL bEnabled, BSTR Description, ULONG ulLeaseDuration);
  74. STDMETHODIMP DeletePortMapping(BSTR RemoteHost, USHORT uwExternalPort, BSTR Protocol);
  75. STDMETHODIMP GetExternalIPAddress(BSTR* pExternalIPAddress);
  76. HRESULT FinalConstruct();
  77. HRESULT FinalRelease();
  78. protected:
  79. HRESULT StartNetmanEvents(INetConnectionNotifySink* pSink);
  80. HRESULT ControlEnabled(void);
  81. HRESULT FireEvent(DISPID DispatchId);
  82. HRESULT AddDynamicPortMapping(BSTR RemoteHost, USHORT uwExternalPort, BSTR Protocol, USHORT uwInternalPort, BSTR InternalClient, VARIANT_BOOL bEnabled, BSTR Description, ULONG ulLeaseDuration);
  83. HRESULT AddStaticPortMapping(BSTR RemoteHost, USHORT uwExternalPort, BSTR Protocol, USHORT uwInternalPort, BSTR InternalClient, VARIANT_BOOL bEnabled, BSTR Description, ULONG ulLeaseDuration);
  84. IHNetConnection* m_pHomenetConnection;
  85. GUID m_SharedGuid;
  86. IUPnPEventSink* m_pEventSink;
  87. //
  88. // Needed entries for the PortMappings
  89. //
  90. IHNetIcsSettings* m_IcsSettingsp;
  91. private:
  92. IConnectionPoint* m_pConnectionPoint;
  93. DWORD m_dwConnectionManagerConnectionPointCookie;
  94. IStatisticsProvider* m_pStatisticsProvider;
  95. HRESULT m_hAdviseNATEventsResult;
  96. };
  97. //
  98. // Utility Functions.
  99. //
  100. enum MAPPING_TYPE
  101. {
  102. ePortMappingInvalid = 0,
  103. ePortMappingDynamic,
  104. ePortMappingStatic
  105. };
  106. HRESULT
  107. SearchPortMapping(
  108. IN IHNetIcsSettings* IcsSettingsp,
  109. IN OPTIONAL ULONG searchIndex,
  110. IN OPTIONAL USHORT searchPort,
  111. IN OPTIONAL UCHAR searchProtocol,
  112. OUT IHNetPortMappingProtocol **Protocolpp
  113. );
  114. HRESULT
  115. FillStaticMappingInformation(
  116. IN IHNetPortMappingProtocol* MappingProtocolp,
  117. IN OPTIONAL IHNetPortMappingBinding* Bindingp,
  118. OUT PUSHORT uExternalPortp,
  119. OUT BSTR* Protocolp,
  120. OUT PUSHORT uInternalPortp,
  121. OUT BSTR* InternalClientp,
  122. OUT VARIANT_BOOL* bEnabledp,
  123. OUT BSTR* Descriptionp
  124. );
  125. inline HRESULT
  126. ValidatePortMappingParameters
  127. (
  128. IN BSTR RemoteHost,
  129. IN USHORT uwExternalPort,
  130. IN BSTR Protocol,
  131. IN USHORT uwInternalPort,
  132. IN BSTR InternalClient,
  133. IN VARIANT_BOOL bEnabled,
  134. IN BSTR Description,
  135. IN ULONG ulLeaseDuration,
  136. OUT MAPPING_TYPE* pMappingType
  137. );
  138. #define RESOLVE_PROTOCOL_TYPE( _X_ , _Y_ ) \
  139. if ( !_wcsicmp( (_Y_), L"TCP") ) \
  140. { \
  141. (_X_) = NAT_PROTOCOL_TCP; \
  142. } \
  143. else if ( !_wcsicmp((_Y_), L"UDP") ) \
  144. { \
  145. (_X_) = NAT_PROTOCOL_UDP; \
  146. } \
  147. else \
  148. { \
  149. _ASSERT( FALSE ); \
  150. \
  151. hr = E_INVALIDARG; \
  152. \
  153. break; \
  154. }