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.

190 lines
4.4 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  2. /*---------------------------------------------------------
  3. Filename: transp.cpp
  4. Written By: B.Rajeev
  5. ----------------------------------------------------------*/
  6. #include "precomp.h"
  7. #include "common.h"
  8. #include "sync.h"
  9. #include "address.h"
  10. #include "tsess.h"
  11. #include "tsent.h"
  12. #include "idmap.h"
  13. #include "dummy.h"
  14. #include "flow.h"
  15. #include "frame.h"
  16. #include "timer.h"
  17. #include "message.h"
  18. #include "ssent.h"
  19. #include "opreg.h"
  20. #include "session.h"
  21. #include "transp.h"
  22. /*------------------------------------------------------------
  23. Purpose: The SnmpTransport class provides the implementation
  24. of the transport protocol layer for use by the SnmpSession class.
  25. The SnmpImpTransport provides a UDP implementation of the
  26. transport layer.
  27. -------------------------------------------------------------*/
  28. TransportFrameId SnmpImpTransport::next_transport_frame_id = ILLEGAL_TRANSPORT_FRAME_ID ;
  29. SnmpTransport::SnmpTransport (
  30. IN SnmpSession &session,
  31. IN const SnmpTransportAddress &transportAddress
  32. ) :transport_address(transportAddress.Copy())
  33. {
  34. }
  35. SnmpTransportAddress &SnmpTransport::GetTransportAddress()
  36. {
  37. return *transport_address;
  38. }
  39. SnmpTransport::~SnmpTransport()
  40. {
  41. delete transport_address;
  42. }
  43. SnmpImpTransport::SnmpImpTransport (
  44. IN SnmpSession &session,
  45. IN const SnmpTransportAddress &address
  46. ) : SnmpTransport(session, address),
  47. session(session)
  48. {
  49. is_valid = FALSE;
  50. transport_created = FALSE;
  51. if ( !GetTransportAddress()() )
  52. return;
  53. try {
  54. transport = new TransportWindow(*this);
  55. }
  56. catch ( Heap_Exception e_He )
  57. {
  58. return ;
  59. }
  60. catch ( GeneralException exception )
  61. {
  62. return ;
  63. }
  64. transport_created = TRUE;
  65. if ( !(*transport)() )
  66. return;
  67. is_valid = TRUE;
  68. }
  69. SnmpImpTransport::~SnmpImpTransport(void)
  70. {
  71. if ( transport_created )
  72. delete transport;
  73. }
  74. void SnmpImpTransport::TransportSendFrame(
  75. OUT TransportFrameId &transport_frame_id,
  76. IN SnmpPdu &snmpPdu
  77. )
  78. {
  79. if ( next_transport_frame_id == ILLEGAL_TRANSPORT_FRAME_ID )
  80. next_transport_frame_id++;
  81. store.Register(transport_frame_id, SnmpErrorReport(Snmp_Success, Snmp_No_Error) );
  82. transport->PostMessage(Window :: g_SentFrameEvent,
  83. transport_frame_id, 0);
  84. DebugMacro4(
  85. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  86. __FILE__,__LINE__,
  87. L"posted: transport_frame_id = %d\n", transport_frame_id
  88. ) ;
  89. )
  90. try
  91. {
  92. if ( transport->SendPdu(snmpPdu) == FALSE )
  93. store.Modify(transport_frame_id, SnmpErrorReport(Snmp_Error, Snmp_Local_Error));
  94. }
  95. catch ( Heap_Exception e_He )
  96. {
  97. store.Modify(transport_frame_id, SnmpErrorReport(Snmp_Error, Snmp_Local_Error));
  98. }
  99. catch ( GeneralException exception )
  100. {
  101. store.Modify(transport_frame_id, SnmpErrorReport(Snmp_Error, Snmp_Local_Error));
  102. }
  103. }
  104. void SnmpImpTransport::HandleSentFrame(IN TransportFrameId transport_frame_id)
  105. {
  106. TransportSentFrame(transport_frame_id, store.Remove(transport_frame_id));
  107. }
  108. void SnmpImpTransport::TransportSentFrame(IN TransportFrameId transport_frame_id,
  109. IN SnmpErrorReport &errorReport)
  110. {
  111. session.SessionSentFrame(transport_frame_id, errorReport);
  112. }
  113. void SnmpImpTransport::TransportReceiveFrame (
  114. IN SnmpPdu &snmpPdu ,
  115. IN SnmpErrorReport &errorReport
  116. )
  117. {
  118. session.SessionReceiveFrame(snmpPdu, errorReport);
  119. }
  120. SnmpUdpIpTransport :: SnmpUdpIpTransport (
  121. IN SnmpSession &session,
  122. IN const SnmpTransportIpAddress &ipAddress
  123. ) : SnmpImpTransport ( session , ipAddress )
  124. {
  125. }
  126. void * SnmpUdpIpImp::operator()(void) const
  127. {
  128. if ( ( SnmpTransportIpAddress::operator()() == NULL ) ||
  129. ( SnmpImpTransport::operator()() == NULL ) )
  130. return NULL;
  131. else
  132. return (void *)this;
  133. }
  134. SnmpIpxTransport :: SnmpIpxTransport (
  135. IN SnmpSession &session,
  136. IN const SnmpTransportIpxAddress &ipxAddress
  137. ) : SnmpImpTransport ( session , ipxAddress )
  138. {
  139. }
  140. void * SnmpIpxImp::operator()(void) const
  141. {
  142. if ( ( SnmpTransportIpxAddress::operator()() == NULL ) ||
  143. ( SnmpImpTransport::operator()() == NULL ) )
  144. return NULL;
  145. else
  146. return (void *)this;
  147. }