1
/* Portions of this file are subject to the following copyright(s). See
2
* the Net-SNMP's COPYING file for more details and other copyrights
6
* Portions of this file are copyrighted by:
7
* Copyright � 2003 Sun Microsystems, Inc. All rights reserved.
8
* Use is subject to license terms specified in the COPYING file
9
* distributed with the Net-SNMP package.
11
#include <net-snmp/net-snmp-config.h>
13
#include <net-snmp/net-snmp-includes.h>
14
#include <net-snmp/agent/net-snmp-agent-includes.h>
16
#include <net-snmp/agent/mode_end_call.h>
22
/** @defgroup mode_end_call mode_end_call: at the end of a series of requests, call another handler hook.
23
* Handlers that want to loop through a series of requests and then
24
* receive a callback at the end of a particular MODE can use this
25
* helper to make this possible. For most modules, this is not
26
* needed as the handler itself could perform a for() loop around the
27
* request list and then perform its actions afterwards. However, if
28
* something like the serialize helper is in use this isn't possible
29
* because not all the requests for a given handler are being passed
30
* downward in a single group. Thus, this helper *must* be added
31
* above other helpers like the serialize helper to be useful.
33
* Multiple mode specific handlers can be registered and will be
34
* called in the order they were regestered in. Callbacks regesterd
35
* with a mode of NETSNMP_MODE_END_ALL_MODES will be called for all
42
/** returns a mode_end_call handler that can be injected into a given
44
* @param endlist The callback list for the handler to make use of.
45
* @return An injectable Net-SNMP handler.
48
netsnmp_get_mode_end_call_handler(netsnmp_mode_handler_list *endlist)
50
netsnmp_mib_handler *me =
51
netsnmp_create_handler("mode_end_call",
52
netsnmp_mode_end_call_helper);
61
/** adds a mode specific callback to the callback list.
62
* @param endinfo the information structure for the mode_end_call helper. Can be NULL to create a new list.
63
* @param mode the mode to be called upon. A mode of NETSNMP_MODE_END_ALL_MODES = all modes.
64
* @param callbackh the netsnmp_mib_handler callback to call.
65
* @return the new registration information list upon success.
67
netsnmp_mode_handler_list *
68
netsnmp_mode_end_call_add_mode_callback(netsnmp_mode_handler_list *endlist,
70
netsnmp_mib_handler *callbackh) {
71
netsnmp_mode_handler_list *ptr, *ptr2;
72
ptr = SNMP_MALLOC_TYPEDEF(netsnmp_mode_handler_list);
77
ptr->callback_handler = callbackh;
84
for(ptr2 = endlist; ptr2->next != NULL; ptr2 = ptr2->next);
90
/** @internal Implements the mode_end_call handler */
92
netsnmp_mode_end_call_helper(netsnmp_mib_handler *handler,
93
netsnmp_handler_registration *reginfo,
94
netsnmp_agent_request_info *reqinfo,
95
netsnmp_request_info *requests)
99
int ret2 = SNMP_ERR_NOERROR;
100
netsnmp_mode_handler_list *ptr;
102
/* always call the real handlers first */
103
ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
106
/* then call the callback handlers */
107
for(ptr = handler->myvoid; ptr; ptr = ptr->next) {
108
if (ptr->mode == NETSNMP_MODE_END_ALL_MODES ||
109
reqinfo->mode == ptr->mode) {
110
ret2 = netsnmp_call_handler(ptr->callback_handler, reginfo,
112
if (ret != SNMP_ERR_NOERROR)