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.

142 lines
3.5 KiB

  1. //
  2. // DataChannel.cpp : Implementation of CDataChannel
  3. //
  4. #include "PreComp.h"
  5. #include "DataChannel.h"
  6. #include "AlgController.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CDataChannel
  9. STDMETHODIMP CDataChannel::Cancel()
  10. {
  11. MYTRACE_ENTER_NOSHOWEXIT("CDataChannel::Cancel()");
  12. //
  13. // Normal redirect cancel using original argument pass to CreateRedirect
  14. //
  15. HRESULT hr = g_pAlgController->GetNat()->CancelRedirect(
  16. (UCHAR)m_Properties.eProtocol,
  17. m_ulDestinationAddress,
  18. m_usDestinationPort,
  19. m_ulSourceAddress,
  20. m_usSourcePort,
  21. m_ulNewDestinationAddress,
  22. m_usNewDestinationPort,
  23. m_ulNewSourceAddress,
  24. m_usNewSourcePort
  25. );
  26. return hr;
  27. }
  28. STDMETHODIMP CDataChannel::GetChannelProperties(ALG_DATA_CHANNEL_PROPERTIES** ppProperties)
  29. {
  30. HRESULT hr = S_OK;
  31. if (NULL != ppProperties)
  32. {
  33. *ppProperties = reinterpret_cast<ALG_DATA_CHANNEL_PROPERTIES*>(
  34. CoTaskMemAlloc(sizeof(ALG_DATA_CHANNEL_PROPERTIES))
  35. );
  36. if (NULL != *ppProperties)
  37. {
  38. CopyMemory(*ppProperties, &m_Properties, sizeof(ALG_DATA_CHANNEL_PROPERTIES));
  39. }
  40. else
  41. {
  42. hr = E_OUTOFMEMORY;
  43. }
  44. }
  45. else
  46. {
  47. hr = E_POINTER;
  48. }
  49. return hr;
  50. }
  51. //
  52. // Retrieve the requested event handle.
  53. // The caller must call CloseHandle on this handle.
  54. // This routine will fail if session creation notification was not requested.
  55. //
  56. // Notification will be triggered when the Channel is open (TCP)
  57. // or when the first UDP packet are received
  58. //
  59. STDMETHODIMP CDataChannel::GetSessionCreationEventHandle(HANDLE* pHandle)
  60. {
  61. MYTRACE_ENTER("CDataChannel::GetSessionCreationEventHandle");
  62. if ( pHandle == NULL )
  63. return E_INVALIDARG;
  64. if ( !m_hCreateEvent )
  65. return E_FAIL;
  66. if ( DuplicateHandle(
  67. GetCurrentProcess(),
  68. m_hCreateEvent,
  69. GetCurrentProcess(),
  70. pHandle,
  71. 0,
  72. FALSE,
  73. DUPLICATE_SAME_ACCESS
  74. )
  75. )
  76. {
  77. MYTRACE("Duplicated handle from %d to new %d", m_hCreateEvent, *pHandle);
  78. }
  79. else
  80. {
  81. MYTRACE_ERROR("Duplicating handle", 0);
  82. return E_FAIL;
  83. }
  84. return S_OK;
  85. }
  86. //
  87. // Retrieve the requested event handle.
  88. // The caller must call CloseHandle on this handle.
  89. // This routine will fail if session deletion notification was not requested.
  90. //
  91. // Notification will be triggered when the Channel is close
  92. // or when UDP packet are now reveice for a period of time.
  93. //
  94. STDMETHODIMP CDataChannel::GetSessionDeletionEventHandle(HANDLE* pHandle)
  95. {
  96. MYTRACE_ENTER("CDataChannel::GetSessionDeletionEventHandle");
  97. if ( pHandle == NULL )
  98. return E_INVALIDARG;
  99. if ( !m_hDeleteEvent )
  100. return E_FAIL;
  101. if ( DuplicateHandle(
  102. GetCurrentProcess(),
  103. m_hDeleteEvent,
  104. GetCurrentProcess(),
  105. pHandle,
  106. 0,
  107. FALSE,
  108. DUPLICATE_SAME_ACCESS
  109. )
  110. )
  111. {
  112. MYTRACE("Duplicated handle from %d to new %d", m_hDeleteEvent, *pHandle);
  113. }
  114. else
  115. {
  116. MYTRACE_ERROR("Duplicating handle", 0);
  117. return E_FAIL;
  118. }
  119. return S_OK;
  120. }