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.

119 lines
3.3 KiB

  1. // DPrtMapC.cpp : Implementation of CDynamicPortMappingCollection
  2. #include "stdafx.h"
  3. #pragma hdrstop
  4. #include "NATUPnP.h"
  5. #include "DPrtMapC.h"
  6. #include "DPortMap.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CDynamicPortMappingCollection
  9. STDMETHODIMP CDynamicPortMappingCollection::get_Item (BSTR bstrRemoteHost, long lExternalPort, BSTR bstrProtocol, IDynamicPortMapping ** ppDPM)
  10. {
  11. NAT_API_ENTER
  12. if (!ppDPM)
  13. return E_POINTER;
  14. *ppDPM = NULL;
  15. return CDynamicPortMapping::CreateInstance (m_spUPS, bstrRemoteHost, lExternalPort, bstrProtocol, ppDPM);
  16. NAT_API_LEAVE
  17. }
  18. STDMETHODIMP CDynamicPortMappingCollection::get_Count(long *pVal)
  19. {
  20. NAT_API_ENTER
  21. if (!pVal)
  22. return E_POINTER;
  23. *pVal = 0;
  24. ULONG ul = 0;
  25. HRESULT hr = GetNumberOfEntries (m_spUPS, &ul);
  26. if (SUCCEEDED(hr))
  27. *pVal = (long)ul;
  28. return hr;
  29. NAT_API_LEAVE
  30. }
  31. STDMETHODIMP CDynamicPortMappingCollection::Remove(BSTR bstrRemoteHost, long lExternalPort, BSTR bstrProtocol)
  32. {
  33. NAT_API_ENTER
  34. return DeletePortMapping (m_spUPS, bstrRemoteHost, lExternalPort, bstrProtocol);
  35. NAT_API_LEAVE
  36. }
  37. STDMETHODIMP CDynamicPortMappingCollection::Add(BSTR bstrRemoteHost, long lExternalPort, BSTR bstrProtocol, long lInternalPort, BSTR bstrInternalClient, VARIANT_BOOL bEnabled, BSTR bstrDescription, long lLeaseDuration, IDynamicPortMapping ** ppDPM)
  38. {
  39. NAT_API_ENTER
  40. if (!ppDPM)
  41. return E_POINTER;
  42. *ppDPM = NULL;
  43. if (!bstrRemoteHost)
  44. return E_INVALIDARG;
  45. if ((lExternalPort < 0) || (lExternalPort > 65535))
  46. return E_INVALIDARG;
  47. if (!bstrProtocol)
  48. return E_INVALIDARG;
  49. if (wcscmp (bstrProtocol, L"TCP") && wcscmp (bstrProtocol, L"UDP"))
  50. return E_INVALIDARG;
  51. if ((lInternalPort < 0) || (lInternalPort > 65535))
  52. return E_INVALIDARG;
  53. if (!bstrInternalClient)
  54. return E_INVALIDARG;
  55. if (!bstrDescription)
  56. return E_INVALIDARG;
  57. if ((lLeaseDuration < 0) || (lLeaseDuration > 65535))
  58. return E_INVALIDARG;
  59. HRESULT hr = AddPortMapping (m_spUPS,
  60. bstrRemoteHost,
  61. lExternalPort,
  62. bstrProtocol,
  63. lInternalPort,
  64. bstrInternalClient,
  65. bEnabled,
  66. bstrDescription,
  67. lLeaseDuration);
  68. if (SUCCEEDED(hr)) {
  69. hr = CDynamicPortMapping::CreateInstance (
  70. m_spUPS, bstrRemoteHost,lExternalPort,
  71. bstrProtocol, ppDPM);
  72. }
  73. return hr;
  74. NAT_API_LEAVE
  75. }
  76. STDMETHODIMP CDynamicPortMappingCollection::get__NewEnum(IUnknown **ppVal)
  77. {
  78. NAT_API_ENTER
  79. if (!ppVal)
  80. return E_POINTER;
  81. *ppVal = NULL;
  82. CComPtr<IEnumVARIANT> spEV =
  83. CEnumDynamicPortMappingCollection::CreateInstance (m_spUPS);
  84. if (!spEV)
  85. return E_OUTOFMEMORY;
  86. return spEV->QueryInterface (__uuidof(IUnknown), (void**)ppVal);
  87. NAT_API_LEAVE
  88. }
  89. HRESULT CDynamicPortMappingCollection::Initialize (IUPnPService * pUPS)
  90. {
  91. _ASSERT (pUPS);
  92. _ASSERT (m_spUPS == NULL);
  93. m_spUPS = pUPS;
  94. return S_OK;
  95. }