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.

440 lines
11 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: session.hpp
  14. Author: B.Rajeev
  15. Purpose: Provides declarations for the SnmpSession class
  16. --------------------------------------------------*/
  17. #ifndef __SESSION__
  18. #define __SESSION__
  19. #include "forward.h"
  20. #include "address.h"
  21. #include "sec.h"
  22. #include "tsent.h"
  23. #include "transp.h"
  24. #include "encdec.h"
  25. typedef UINT_PTR TimerEventId;
  26. #define DEF_RETRY_COUNT 1
  27. #define DEF_RETRY_TIMEOUT 500
  28. #define DEF_VARBINDS_PER_PDU 10
  29. #define DEF_WINDOW_SIZE 4
  30. #pragma warning (disable:4355)
  31. /*------------------------------------------------------------
  32. Overview: The SnmpSession class provides the framework for the
  33. communications session between client and protocol stack. The
  34. SnmpSession exposes SNMP frame ( use the term frame and protocol
  35. data unit interchangeably throughout this document ) transmission
  36. and reception independently of the transport stack implementation.
  37. The SnmpSession provides the interface between communication
  38. subsystem and protocol operation generation.
  39. The SnmpImpSession class provides an implementation of the
  40. SnmpSession abstract class.
  41. ------------------------------------------------------------*/
  42. class DllImportExport SnmpSession
  43. {
  44. private:
  45. // the "=" operator and the copy constructor have been
  46. // made private to prevent any copies from being made
  47. SnmpSession & operator=( const SnmpSession & )
  48. {
  49. return *this;
  50. }
  51. SnmpSession(IN const SnmpSession &snmp_session) {}
  52. protected:
  53. ULONG retry_count;
  54. ULONG retry_timeout;
  55. ULONG varbinds_per_pdu;
  56. ULONG flow_control_window;
  57. /*
  58. * User overridable callback functions
  59. */
  60. virtual void SessionFlowControlOn() {}
  61. virtual void SessionFlowControlOff() {}
  62. /*
  63. * End User overridable callback functions
  64. */
  65. SnmpSession(
  66. IN SnmpTransport &transportProtocol,
  67. IN SnmpSecurity &security,
  68. IN SnmpEncodeDecode &a_SnmpEncodeDecode ,
  69. IN const ULONG retryCount = DEF_RETRY_COUNT,
  70. IN const ULONG retryTimeout = DEF_RETRY_TIMEOUT,
  71. IN const ULONG varbindsPerPdu = DEF_VARBINDS_PER_PDU,
  72. IN const ULONG flowControlWindow = DEF_WINDOW_SIZE
  73. );
  74. public:
  75. virtual ~SnmpSession () {}
  76. /*
  77. * System overridable operation functions
  78. */
  79. virtual SnmpTransport &GetTransportProtocol () const = 0 ;
  80. virtual SnmpSecurity &GetSnmpSecurity () const = 0 ;
  81. virtual SnmpEncodeDecode &GetSnmpEncodeDecode () const = 0 ;
  82. // all operations must register themselves before
  83. // using the Session services and must deregister
  84. // for the session to be destroyed
  85. virtual void RegisterOperation(IN SnmpOperation &operation) = 0;
  86. virtual void DeregisterOperation(IN SnmpOperation &operation) = 0;
  87. // the session is destroyed if the number of registered sessions
  88. // is 0. otherwise the session is flagged to be destroyed when
  89. // the number of registered operations drops to 0.
  90. virtual BOOL DestroySession() = 0;
  91. virtual SnmpErrorReport SessionCancelFrame ( IN const SessionFrameId session_frame_id ) = 0 ;
  92. virtual void SessionSendFrame (
  93. IN SnmpOperation &operation ,
  94. OUT SessionFrameId &session_frame_id ,
  95. IN SnmpPdu &SnmpPdu,
  96. IN SnmpSecurity &security
  97. ) = 0 ;
  98. virtual void SessionSendFrame (
  99. IN SnmpOperation &operation ,
  100. OUT SessionFrameId &session_frame_id ,
  101. IN SnmpPdu &SnmpPdu
  102. ) = 0 ;
  103. virtual void SessionReceiveFrame (
  104. IN SnmpPdu &snmpPdu,
  105. IN SnmpErrorReport &errorReport
  106. ) = 0 ;
  107. virtual void SessionSentFrame (
  108. IN TransportFrameId transport_frame_id,
  109. IN SnmpErrorReport &errorReport
  110. ) = 0;
  111. virtual void * operator()(void) const = 0;
  112. /*
  113. * End system overridable operation functions
  114. */
  115. ULONG GetRetryCount () const
  116. {
  117. return retry_count;
  118. }
  119. ULONG GetRetryTimeout () const
  120. {
  121. return retry_timeout;
  122. }
  123. ULONG GetVarbindsPerPdu () const
  124. {
  125. return varbinds_per_pdu;
  126. }
  127. ULONG GetFlowControlWindow() const
  128. {
  129. return flow_control_window;
  130. }
  131. } ;
  132. class DllImportExport SnmpImpSession : public SnmpSession
  133. {
  134. private:
  135. SessionFrameId received_session_frame_id;
  136. SnmpOperation *operation_to_notify;
  137. friend class WaitingMessage;
  138. friend class FlowControlMechanism;
  139. friend class Timer;
  140. friend class MessageRegistry;
  141. friend class FrameRegistry;
  142. friend class SessionWindow;
  143. BOOL is_valid;
  144. // References to the following instances are used instead of
  145. // embedded instances themselves. This is done to avoid including
  146. // the header files providing their declaration
  147. SessionWindow m_SessionWindow;
  148. CriticalSection session_CriticalSection;
  149. FlowControlMechanism flow_control;
  150. Timer timer;
  151. TimerEventId timer_event_id;
  152. UINT strobe_count ;
  153. MessageRegistry message_registry;
  154. FrameRegistry frame_registry;
  155. SnmpTransport &transport;
  156. SnmpSecurity &security;
  157. SnmpEncodeDecode &m_EncodeDecode ;
  158. SessionSentStateStore store;
  159. IdMapping id_mapping;
  160. // the operation registry keeps track of the registered
  161. // operations
  162. OperationRegistry operation_registry;
  163. // if this flag is TRUE, the session must delete this when
  164. // the number of registered operations falls to 0
  165. BOOL destroy_self;
  166. void PostSentFrameEvent (
  167. SessionFrameId session_frame_id ,
  168. SnmpOperation &operation,
  169. SnmpErrorReport errorReport
  170. ) ;
  171. void NotifyOperation(IN const SessionFrameId session_frame_id,
  172. IN const SnmpPdu &snmp_pdu,
  173. IN const SnmpErrorReport &error_report);
  174. SnmpOperation *GetOperation(IN const SessionFrameId session_frame_id);
  175. // the Handle* methods handle internal windows events
  176. // these are called by the DummySession
  177. void HandleSentFrame (IN SessionFrameId session_frame_id , SnmpOperation *operation);
  178. void HandleDeletionEvent();
  179. protected:
  180. SnmpImpSession (
  181. IN SnmpTransport &transportProtocol ,
  182. IN SnmpSecurity &security ,
  183. IN SnmpEncodeDecode &a_SnmpEncodeDecode ,
  184. IN const ULONG retryCount = DEF_RETRY_COUNT ,
  185. IN const ULONG retryTimeout = DEF_RETRY_TIMEOUT ,
  186. IN const ULONG varbindsPerPdu = DEF_VARBINDS_PER_PDU ,
  187. IN const ULONG flowControlWindow = DEF_WINDOW_SIZE
  188. ) ;
  189. public:
  190. ~SnmpImpSession () ;
  191. SnmpTransport &GetTransportProtocol () const { return transport ; }
  192. SnmpSecurity &GetSnmpSecurity () const { return security ; }
  193. SnmpEncodeDecode &GetSnmpEncodeDecode () const { return m_EncodeDecode ; }
  194. void RegisterOperation(IN SnmpOperation &operation);
  195. void DeregisterOperation(IN SnmpOperation &operation);
  196. // the session is destroyed if the number of registered sessions
  197. // is 0. otherwise the session is flagged to be destroyed when
  198. // the number of registered operations drops to 0.
  199. BOOL DestroySession();
  200. SnmpErrorReport SessionCancelFrame ( IN const SessionFrameId session_frame_id ) ;
  201. void SessionSendFrame ( IN SnmpOperation &operation,
  202. OUT SessionFrameId &session_frame_id ,
  203. IN SnmpPdu &snmpPdu) ;
  204. void SessionSendFrame(IN SnmpOperation &operation,
  205. OUT SessionFrameId &session_frame_id,
  206. IN SnmpPdu &snmpPdu,
  207. IN SnmpSecurity &snmp_security);
  208. void SessionReceiveFrame(IN SnmpPdu &snmpPdu,
  209. IN SnmpErrorReport &errorReport);
  210. void SessionSentFrame(
  211. IN TransportFrameId transport_frame_id,
  212. IN SnmpErrorReport &errorReport);
  213. void * operator()(void) const
  214. {
  215. return (is_valid?(void *)this:NULL);
  216. }
  217. operator void *() const
  218. {
  219. return SnmpImpSession::operator()();
  220. }
  221. static ULONG RetryCount(IN const ULONG retry_count) ;
  222. static ULONG RetryTimeout(IN const ULONG retry_timeout) ;
  223. static ULONG VarbindsPerPdu(IN const ULONG varbinds_per_pdu) ;
  224. static ULONG WindowSize(IN const ULONG window_size) ;
  225. } ;
  226. class DllImportExport SnmpV1OverIp : public SnmpUdpIpImp , public SnmpCommunityBasedSecurity , public SnmpImpSession , public SnmpV1EncodeDecode
  227. {
  228. private:
  229. protected:
  230. public:
  231. SnmpV1OverIp (
  232. IN const char *ipAddress ,
  233. IN const ULONG addressResolution = SNMP_ADDRESS_RESOLVE_VALUE ,
  234. IN const char *communityName = "public" ,
  235. IN const ULONG retryCount = DEF_RETRY_COUNT ,
  236. IN const ULONG retryTimeout = DEF_RETRY_TIMEOUT ,
  237. IN const ULONG varbindsPerPdu = DEF_VARBINDS_PER_PDU ,
  238. IN const ULONG flowControlWindow = DEF_WINDOW_SIZE
  239. )
  240. : SnmpUdpIpImp(*this, ipAddress,addressResolution),
  241. SnmpCommunityBasedSecurity(communityName),
  242. SnmpImpSession(*this, *this,*this, retryCount,
  243. retryTimeout, varbindsPerPdu, flowControlWindow)
  244. {}
  245. void * operator()(void) const;
  246. ~SnmpV1OverIp () {}
  247. } ;
  248. class DllImportExport SnmpV2COverIp : public SnmpUdpIpImp , public SnmpCommunityBasedSecurity , public SnmpImpSession , public SnmpV2CEncodeDecode
  249. {
  250. private:
  251. protected:
  252. public:
  253. SnmpV2COverIp (
  254. IN const char *ipAddress ,
  255. IN const ULONG addressResolution = SNMP_ADDRESS_RESOLVE_VALUE ,
  256. IN const char *communityName = "public" ,
  257. IN const ULONG retryCount = DEF_RETRY_COUNT ,
  258. IN const ULONG retryTimeout = DEF_RETRY_TIMEOUT ,
  259. IN const ULONG varbindsPerPdu = DEF_VARBINDS_PER_PDU ,
  260. IN const ULONG flowControlWindow = DEF_WINDOW_SIZE
  261. )
  262. : SnmpUdpIpImp(*this, ipAddress,addressResolution),
  263. SnmpCommunityBasedSecurity(communityName),
  264. SnmpImpSession(*this, *this,*this, retryCount,
  265. retryTimeout, varbindsPerPdu, flowControlWindow)
  266. {}
  267. void * operator()(void) const;
  268. ~SnmpV2COverIp () {}
  269. } ;
  270. class DllImportExport SnmpV1OverIpx : public SnmpIpxImp , public SnmpCommunityBasedSecurity , public SnmpImpSession , public SnmpV1EncodeDecode
  271. {
  272. private:
  273. protected:
  274. public:
  275. SnmpV1OverIpx (
  276. IN const char *ipxAddress ,
  277. IN const char *communityName = "public" ,
  278. IN const ULONG retryCount = DEF_RETRY_COUNT ,
  279. IN const ULONG retryTimeout = DEF_RETRY_TIMEOUT ,
  280. IN const ULONG varbindsPerPdu = DEF_VARBINDS_PER_PDU ,
  281. IN const ULONG flowControlWindow = DEF_WINDOW_SIZE
  282. )
  283. : SnmpIpxImp(*this, ipxAddress),
  284. SnmpCommunityBasedSecurity(communityName),
  285. SnmpImpSession(*this, *this,*this, retryCount,
  286. retryTimeout, varbindsPerPdu, flowControlWindow)
  287. {}
  288. void * operator()(void) const;
  289. ~SnmpV1OverIpx () {}
  290. } ;
  291. class DllImportExport SnmpV2COverIpx : public SnmpIpxImp , public SnmpCommunityBasedSecurity , public SnmpImpSession , public SnmpV2CEncodeDecode
  292. {
  293. private:
  294. protected:
  295. public:
  296. SnmpV2COverIpx (
  297. IN const char *ipxAddress ,
  298. IN const char *communityName = "public" ,
  299. IN const ULONG retryCount = DEF_RETRY_COUNT ,
  300. IN const ULONG retryTimeout = DEF_RETRY_TIMEOUT ,
  301. IN const ULONG varbindsPerPdu = DEF_VARBINDS_PER_PDU ,
  302. IN const ULONG flowControlWindow = DEF_WINDOW_SIZE
  303. )
  304. : SnmpIpxImp(*this, ipxAddress),
  305. SnmpCommunityBasedSecurity(communityName),
  306. SnmpImpSession(*this, *this,*this, retryCount,
  307. retryTimeout, varbindsPerPdu, flowControlWindow)
  308. {}
  309. void * operator()(void) const;
  310. ~SnmpV2COverIpx () {}
  311. } ;
  312. #pragma warning (default:4355)
  313. #endif // __SESSION__