added files
[bcm963xx.git] / userapps / opensource / net-snmp / agent / helpers / read_only.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/read_only.h>
13
14 #if HAVE_DMALLOC_H
15 #include <dmalloc.h>
16 #endif
17
18 /** @defgroup read_only read_only: make your handler read_only automatically 
19  *  The only purpose of this handler is to return an
20  *  appropriate error for any requests passed to it in a SET mode.
21  *  Inserting it into your handler chain will ensure you're never
22  *  asked to perform a SET request so you can ignore those error
23  *  conditions.
24  *  @ingroup handler
25  *  @{
26  */
27
28 /** returns a read_only handler that can be injected into a given
29  *  handler chain.
30  */
31 netsnmp_mib_handler *
32 netsnmp_get_read_only_handler(void)
33 {
34     return netsnmp_create_handler("read_only", netsnmp_read_only_helper);
35 }
36
37 /** @internal Implements the read_only handler */
38 int
39 netsnmp_read_only_helper(netsnmp_mib_handler *handler,
40                          netsnmp_handler_registration *reginfo,
41                          netsnmp_agent_request_info *reqinfo,
42                          netsnmp_request_info *requests)
43 {
44
45     DEBUGMSGTL(("helper:read_only", "Got request\n"));
46
47     switch (reqinfo->mode) {
48
49     case MODE_SET_RESERVE1:
50     case MODE_SET_RESERVE2:
51     case MODE_SET_ACTION:
52     case MODE_SET_COMMIT:
53     case MODE_SET_FREE:
54     case MODE_SET_UNDO:
55         netsnmp_set_all_requests_error(reqinfo, requests,
56                                        SNMP_ERR_NOTWRITABLE);
57         return SNMP_ERR_NOERROR;
58
59     default:
60         return netsnmp_call_next_handler(handler, reginfo, reqinfo,
61                                          requests);
62     }
63     return SNMP_ERR_GENERR;     /* should never get here */
64 }
65
66 /** initializes the read_only helper which then registers a read_only
67  *  handler as a run-time injectable handler for configuration file
68  *  use.
69  */
70 void
71 netsnmp_init_read_only_helper(void)
72 {
73     netsnmp_register_handler_by_name("read_only",
74                                      netsnmp_get_read_only_handler());
75 }