1 #include <net-snmp/net-snmp-config.h>
3 #include <net-snmp/net-snmp-includes.h>
4 #include <net-snmp/agent/net-snmp-agent-includes.h>
6 #include <net-snmp/agent/mode_end_call.h>
12 /** @defgroup mode_end_call mode_end_call: at the end of a series of requests, call another handler hook.
13 * Handlers that want to loop through a series of requests and then
14 * receive a callback at the end of a particular MODE can use this
15 * helper to make this possible. For most modules, this is not
16 * needed as the handler itself could perform a for() loop around the
17 * request list and then perform its actions afterwards. However, if
18 * something like the serialize helper is in use this isn't possible
19 * because not all the requests for a given handler are being passed
20 * downward in a single group. Thus, this helper *must* be added
21 * above other helpers like the serialize helper to be useful.
23 * Multiple mode specific handlers can be registered and will be
24 * called in the order they were regestered in. Callbacks regesterd
25 * with a mode of NETSNMP_MODE_END_ALL_MODES will be called for all
32 /** returns a mode_end_call handler that can be injected into a given
34 * @param endlist The callback list for the handler to make use of.
35 * @return An injectable Net-SNMP handler.
38 netsnmp_get_mode_end_call_handler(netsnmp_mode_handler_list *endlist)
40 netsnmp_mib_handler *me =
41 netsnmp_create_handler("mode_end_call",
42 netsnmp_mode_end_call_helper);
51 /** adds a mode specific callback to the callback list.
52 * @param endinfo the information structure for the mode_end_call helper. Can be NULL to create a new list.
53 * @param mode the mode to be called upon. A mode of NETSNMP_MODE_END_ALL_MODES = all modes.
54 * @param callbackh the netsnmp_mib_handler callback to call.
55 * @return the new registration information list upon success.
57 netsnmp_mode_handler_list *
58 netsnmp_mode_end_call_add_mode_callback(netsnmp_mode_handler_list *endlist,
60 netsnmp_mib_handler *callbackh) {
61 netsnmp_mode_handler_list *ptr, *ptr2;
62 ptr = SNMP_MALLOC_TYPEDEF(netsnmp_mode_handler_list);
67 ptr->callback_handler = callbackh;
74 for(ptr2 = endlist; ptr2->next != NULL; ptr2 = ptr2->next);
80 /** @internal Implements the mode_end_call handler */
82 netsnmp_mode_end_call_helper(netsnmp_mib_handler *handler,
83 netsnmp_handler_registration *reginfo,
84 netsnmp_agent_request_info *reqinfo,
85 netsnmp_request_info *requests)
89 int ret2 = SNMP_ERR_NOERROR;
90 netsnmp_mode_handler_list *ptr;
92 /* always call the real handlers first */
93 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
96 /* then call the callback handlers */
97 for(ptr = handler->myvoid; ptr; ptr = ptr->next) {
98 if (ptr->mode == NETSNMP_MODE_END_ALL_MODES ||
99 reqinfo->mode == ptr->mode) {
100 ret2 = netsnmp_call_handler(ptr->callback_handler, reginfo,
102 if (ret != SNMP_ERR_NOERROR)