and added files
[bcm963xx.git] / userapps / opensource / net-snmp / agent / helpers / bulk_to_next.c
1 #include <net-snmp/net-snmp-config.h>
2
3 #if HAVE_STRING_H
4 #include <string.h>
5 #else
6 #include <strings.h>
7 #endif
8
9 #include <net-snmp/net-snmp-includes.h>
10 #include <net-snmp/agent/net-snmp-agent-includes.h>
11
12 #include <net-snmp/agent/bulk_to_next.h>
13
14 #if HAVE_DMALLOC_H
15 #include <dmalloc.h>
16 #endif
17
18 /** @defgroup bulk_to_next bulk_to_next: convert GETBULK requests into GETNEXT requests for the handler.
19  *  The only purpose of this handler is to convert a GETBULK request
20  *  to a GETNEXT request.  It is inserted into handler chains where
21  *  the handler has not set the HANDLER_CAN_GETBULK flag.
22  *  @ingroup handler
23  *  @{
24  */
25
26 /** returns a bulk_to_next handler that can be injected into a given
27  *  handler chain.
28  */
29 netsnmp_mib_handler *
30 netsnmp_get_bulk_to_next_handler(void)
31 {
32     return netsnmp_create_handler("bulk_to_next",
33                                   netsnmp_bulk_to_next_helper);
34 }
35
36 /** takes answered requests and decrements the repeat count and
37  *  updates the requests to the next to-do varbind in the list */
38 void
39 netsnmp_bulk_to_next_fix_requests(netsnmp_request_info *requests)
40 {
41     netsnmp_request_info *request;
42     /*
43      * update the varbinds for the next request series 
44      */
45     for (request = requests; request; request = request->next) {
46         if (request->repeat > 0 &&
47             request->requestvb->type != ASN_NULL &&
48             request->requestvb->type != ASN_PRIV_RETRY) {
49             request->repeat--;
50             snmp_set_var_objid(request->requestvb->next_variable,
51                                request->requestvb->name,
52                                request->requestvb->name_length);
53             request->requestvb = request->requestvb->next_variable;
54             request->requestvb->type = ASN_PRIV_RETRY;
55         }
56     }
57 }
58
59 /** @internal Implements the bulk_to_next handler */
60 int
61 netsnmp_bulk_to_next_helper(netsnmp_mib_handler *handler,
62                             netsnmp_handler_registration *reginfo,
63                             netsnmp_agent_request_info *reqinfo,
64                             netsnmp_request_info *requests)
65 {
66
67     int             ret;
68
69     switch (reqinfo->mode) {
70
71     case MODE_GETBULK:
72         reqinfo->mode = MODE_GETNEXT;
73         ret =
74             netsnmp_call_next_handler(handler, reginfo, reqinfo, requests);
75         reqinfo->mode = MODE_GETBULK;
76
77         /*
78          * update the varbinds for the next request series 
79          */
80         netsnmp_bulk_to_next_fix_requests(requests);
81         return ret;
82
83     default:
84         return netsnmp_call_next_handler(handler, reginfo, reqinfo,
85                                          requests);
86     }
87     return SNMP_ERR_GENERR;     /* should never get here */
88 }
89
90 /** initializes the bulk_to_next helper which then registers a bulk_to_next
91  *  handler as a run-time injectable handler for configuration file
92  *  use.
93  */
94 void
95 netsnmp_init_bulk_to_next_helper(void)
96 {
97     netsnmp_register_handler_by_name("bulk_to_next",
98                                      netsnmp_get_bulk_to_next_handler());
99 }