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.

292 lines
8.2 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: op.hpp (operation.hpp)
  14. Author: B.Rajeev
  15. Purpose: Provides declarations for the SnmpOperation base
  16. class and the classes derived from it -
  17. SnmpGetOperation, SnmpGetNextOperation, SnmpSetOperation.
  18. --------------------------------------------------*/
  19. #ifndef __OPERATION__
  20. #define __OPERATION__
  21. #include "forward.h"
  22. #include "error.h"
  23. #include "encdec.h"
  24. #define SEND_ERROR_EVENT (WM_USER+4)
  25. #define OPERATION_COMPLETED_EVENT (WM_USER+5)
  26. /*--------------------------------------------------
  27. Overview: The SnmpOperation class defines protocol operations
  28. within the SNMP class library, the user of the class library is
  29. not expected to interact directly with SNMP frames exposed within
  30. the SnmpSession interface i.e. the user of the class library need
  31. not call into any SnmpSession method or derive from the
  32. SnmpSession class other than to receive flow control information,
  33. unless of course this is a requirement. The SnmpOperation defines
  34. the type of protocol request to send, the variable binding
  35. information requested and the frame encoding operation used to
  36. generate the required SNMP protocol data units.
  37. --------------------------------------------------*/
  38. // This is the base class for the Get, GetNext and Set operations.
  39. // A few notables are -
  40. // 1. It makes the callbacks to an operation user (ReceiveResponse etc.),
  41. // asynchronous with respect to the user's call to SendRequest.
  42. // 2. The base class implementation registers and deregisters itself with
  43. // the session in the constructor and the destructor respectively
  44. // 3. a class deriving from the SnmpOperation method that provides
  45. // alternate definitions for the "non-pure" virtual methods must
  46. // also call the virtual method
  47. class DllImportExport SnmpOperation
  48. {
  49. friend class OperationWindow;
  50. // only purpose of the OperationHelper is to separate certain winsnmp
  51. // typedefs in the parameter list of a few methods from the
  52. // SnmpOperation header file
  53. friend class OperationHelper;
  54. private:
  55. // each public method checks for this flag before exiting. if the
  56. // flag is set, the operation must delete itself. only method that
  57. // sets it on is the protected DestroyOperation
  58. BOOL delete_operation;
  59. // its mandatory for every public method to call this method
  60. // before returning to the caller
  61. // it checks if the call sequence included a call to DestroyOperation
  62. // and if so, deletes "this" before returning
  63. void CheckOperationDeletion();
  64. // "=" operator has been
  65. // made private so that a copy may not be made
  66. SnmpOperation & operator= ( IN const SnmpOperation &snmp_operation )
  67. {
  68. return *this;
  69. }
  70. // sends a Frame with the VBList specifying the list of varbinds
  71. // in winsnmp vbl and SnmpVarBindList
  72. void SendFrame(VBList &list_segment);
  73. // sends the specified var bind list in snmp pdus each carrying
  74. // atmost max_size var binds
  75. void SendVarBindList(
  76. SnmpVarBindList &var_bind_list,
  77. UINT max_size = UINT_MAX,
  78. ULONG var_index = 0
  79. );
  80. // makes the ReceiveErroredResponse callback for each varbind in
  81. // the errored_list
  82. void ReceiveErroredResponse(
  83. ULONG var_index ,
  84. SnmpVarBindList &errored_list,
  85. const SnmpErrorReport &error_report
  86. );
  87. // processes internal events such as error during sending
  88. // a frame or completion of an operation
  89. LONG ProcessInternalEvent(
  90. HWND hWnd,
  91. UINT user_msg_id,
  92. WPARAM wParam,
  93. LPARAM lParam
  94. );
  95. // both the public SendRequest methods call this for sending the varbindlist
  96. void SendRequest(
  97. IN SnmpVarBindList &varBindList,
  98. IN SnmpSecurity *security
  99. );
  100. protected:
  101. SnmpSession &session;
  102. // used for hiding winsnmp manipulations and window messaging
  103. OperationWindow m_OperationWindow;
  104. // References to the following instances are used instead of
  105. // embedded instances themselves. This is done to avoid including
  106. // the header files providing their declaration
  107. // unrecoverable errors during initialization or processing (not yet)
  108. // set this field to FALSE
  109. BOOL is_valid;
  110. // only one operation may be in progress at a time
  111. BOOL in_progress;
  112. // only one thread is permitted to execute SnmpOperation methods
  113. CriticalSection exclusive_CriticalSection;
  114. // keeps all the FrameStates (for all outstanding Frames)
  115. FrameStateRegistry frame_state_registry;
  116. // hides winsnmp typedefs from this file
  117. OperationHelper helper;
  118. // atmost these many varbinds may be transmitted in any snmp pdu
  119. UINT varbinds_per_pdu;
  120. SnmpOperation(SnmpSession &snmp_session);
  121. // each time a pdu is prepared, it obtains the pdu type from the
  122. // derived class
  123. virtual SnmpEncodeDecode :: PduType GetPduType(void) = 0;
  124. virtual void ReceiveResponse();
  125. virtual void ReceiveVarBindResponse(
  126. IN const ULONG &varBindIndex ,
  127. IN const SnmpVarBind &requestVarBind ,
  128. IN const SnmpVarBind &replyVarBind ,
  129. IN const SnmpErrorReport &error
  130. ) {}
  131. virtual void ReceiveErroredVarBindResponse(
  132. IN const ULONG &varBindIndex ,
  133. IN const SnmpVarBind &requestVarBind ,
  134. IN const SnmpErrorReport &error
  135. ) {}
  136. virtual void FrameTooBig() {}
  137. virtual void FrameOverRun() {}
  138. // this method may be called to delete the Operation
  139. // note: the operation is deleted when a public method
  140. // returns. For this reason, if a public method calls another
  141. // public method, it must not access any per-class variables
  142. // after that.
  143. void DestroyOperation();
  144. public:
  145. virtual ~SnmpOperation() ;
  146. // packages the var binds in the var bind list into a series of
  147. // snmp pdus, each with at most varbinds_per_pdu var binds and
  148. // hands them to the session for transmission
  149. virtual void SendRequest(IN SnmpVarBindList &varBindList);
  150. // sends the frames with an additionally specified security context
  151. // (uses the session SendFrame with a security parameter
  152. virtual void SendRequest(
  153. IN SnmpVarBindList &varBindList,
  154. IN SnmpSecurity &security
  155. );
  156. // cancels all the session frames for which frame states exist in the
  157. // frame state registry (all outstanding frames)
  158. void CancelRequest();
  159. // called by the session or the SnmpOperation SendFrame method
  160. // to signal a valid reply, or an errored response (error in sending
  161. // timeout)
  162. void ReceiveFrame(
  163. IN const SessionFrameId session_frame_id,
  164. IN const SnmpPdu &snmpPdu,
  165. IN const SnmpErrorReport &errorReport
  166. );
  167. // called by the session to signal a frame transmission (successful
  168. // or otherwise) or a timeout situation. since a frame may be
  169. // retransmitted, in the absence of a response, more than one
  170. // SendFrame callback may be issued for the same session_frame_id.
  171. // however, atmost one errored SentFrame call may be made for each
  172. // frame/session_frame_id
  173. virtual void SentFrame (
  174. IN const SessionFrameId session_frame_id,
  175. IN const SnmpErrorReport &error_report
  176. );
  177. // used to check if the operation is valid
  178. void *operator()(void) const
  179. {
  180. return ( (is_valid)?(void *)this:NULL );
  181. }
  182. operator void *() const
  183. {
  184. return SnmpOperation::operator()();
  185. }
  186. static UINT g_SendErrorEvent ;
  187. static UINT g_OperationCompleteEvent ;
  188. };
  189. class DllImportExport SnmpGetOperation: public SnmpOperation
  190. {
  191. protected:
  192. SnmpEncodeDecode :: PduType GetPduType(void);
  193. public:
  194. SnmpGetOperation(SnmpSession &snmp_session) : SnmpOperation(snmp_session)
  195. {}
  196. };
  197. class DllImportExport SnmpGetNextOperation: public SnmpOperation
  198. {
  199. protected:
  200. SnmpEncodeDecode :: PduType GetPduType(void);
  201. public:
  202. SnmpGetNextOperation(IN SnmpSession &snmp_session) : SnmpOperation(snmp_session)
  203. {}
  204. };
  205. class DllImportExport SnmpSetOperation: public SnmpOperation
  206. {
  207. protected:
  208. SnmpEncodeDecode :: PduType GetPduType(void);
  209. public:
  210. SnmpSetOperation(SnmpSession &snmp_session) : SnmpOperation(snmp_session)
  211. {}
  212. };
  213. #endif // __OPERATION__