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.

151 lines
3.9 KiB

  1. //***************************************************************************
  2. //
  3. // File:
  4. //
  5. // Module: MS SNMP Provider
  6. //
  7. // Purpose:
  8. //
  9. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. /*---------------------------------------------------------
  13. Filename: frame.cpp
  14. Written By: B.Rajeev
  15. ----------------------------------------------------------*/
  16. #include "precomp.h"
  17. #include "common.h"
  18. #include "sync.h"
  19. #include "flow.h"
  20. #include "frame.h"
  21. #include "idmap.h"
  22. #include "vblist.h"
  23. #include "sec.h"
  24. #include "pdu.h"
  25. #include "ssent.h"
  26. #include "dummy.h"
  27. #include "opreg.h"
  28. #include "session.h"
  29. SessionFrameId FrameRegistry::GenerateSessionFrameId(void)
  30. {
  31. SessionFrameId session_frame_id = next_session_frame_id++;
  32. if ( next_session_frame_id == ILLEGAL_SESSION_FRAME_ID )
  33. next_session_frame_id++;
  34. return session_frame_id;
  35. }
  36. void FrameRegistry::RegisterFrame(IN const SessionFrameId session_frame_id,
  37. IN WaitingMessage &waiting_message)
  38. {
  39. mapping[session_frame_id] = &waiting_message;
  40. DebugMacro4(
  41. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  42. __FILE__,__LINE__,
  43. L"frame %d registered\n" ,session_frame_id
  44. ) ;
  45. )
  46. }
  47. // returns NULL if no such waiting message
  48. WaitingMessage *FrameRegistry::GetWaitingMessage(IN const SessionFrameId session_frame_id)
  49. {
  50. WaitingMessage *waiting_message;
  51. BOOL found = mapping.Lookup(session_frame_id, waiting_message);
  52. if ( found )
  53. return waiting_message;
  54. else
  55. return NULL;
  56. }
  57. void FrameRegistry::DeregisterFrame(IN const SessionFrameId session_frame_id)
  58. {
  59. if ( !mapping.RemoveKey(session_frame_id) )
  60. throw GeneralException(Snmp_Error, Snmp_Local_Error,__FILE__,__LINE__);
  61. DebugMacro4(
  62. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  63. __FILE__,__LINE__,
  64. L"frame %d removed\n" ,session_frame_id
  65. ) ;
  66. )
  67. }
  68. // if the specified waiting message is found,
  69. // cancel the <TransportFrameId, SessionFrameId> association,
  70. // ensure that no sent message notifications shall be passed to the operation
  71. // remove any buffered responses for the waiting message
  72. // inform the flow control mechanism
  73. // otherwise, the message is still in the flow control queue
  74. // inform the flow control mechanism
  75. void FrameRegistry::CancelFrameNotification(IN const SessionFrameId session_frame_id)
  76. {
  77. WaitingMessage *waiting_message;
  78. BOOL found = mapping.Lookup(session_frame_id, waiting_message);
  79. // obtain corresponding waiting_message
  80. if ( found )
  81. {
  82. // ensure that sent message notifications shall not
  83. // be passed on to the operation
  84. session->id_mapping.DisassociateSessionFrameId(session_frame_id);
  85. // remove any SnmpErrorReport for an attempt to send the message
  86. session->store.Remove(session_frame_id);
  87. // inform flow control mechanism
  88. // it advances window and destroys the waiting_message
  89. session->flow_control.AdvanceWindow(*waiting_message);
  90. }
  91. else // the frame must still be in the flow control message queue
  92. session->flow_control.DeleteMessage(session_frame_id);
  93. }
  94. // destroy each stored waiting message in the local store and
  95. // remove all associations
  96. FrameRegistry::~FrameRegistry(void)
  97. {
  98. // get the first position
  99. POSITION current = mapping.GetStartPosition();
  100. // while the position isn't null
  101. while ( current != NULL )
  102. {
  103. SessionFrameId id;
  104. WaitingMessage *waiting_message;
  105. // get the next pair
  106. mapping.GetNextAssoc(current, id, waiting_message);
  107. // delete the ptr
  108. delete waiting_message;
  109. }
  110. // remove all the keys
  111. mapping.RemoveAll();
  112. }