and added files
[bcm963xx.git] / userapps / opensource / net-snmp / agent / helpers / serialize.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/serialize.h>
13
14 #if HAVE_DMALLOC_H
15 #include <dmalloc.h>
16 #endif
17
18 /** @defgroup serialize serialize: Calls sub handlers one request at a time.
19  *  @ingroup handler
20  *  This functionally passes in one request at a time
21  *  into lower handlers rather than a whole bunch of requests at once.
22  *  This is useful for handlers that don't want to iterate through the
23  *  request lists themselves.  Generally, this is probably less
24  *  efficient so use with caution.  The serialize handler might be
25  *  useable to dynamically fix handlers with broken looping code,
26  *  however.
27  *  @{
28  */
29
30 /** returns a serialize handler that can be injected into a given
31  *  handler chain.  
32  */
33 netsnmp_mib_handler *
34 netsnmp_get_serialize_handler(void)
35 {
36     return netsnmp_create_handler("serialize",
37                                   netsnmp_serialize_helper_handler);
38 }
39
40 /** functionally the same as calling netsnmp_register_handler() but also
41  * injects a serialize handler at the same time for you. */
42 int
43 netsnmp_register_serialize(netsnmp_handler_registration *reginfo)
44 {
45     netsnmp_inject_handler(reginfo, netsnmp_get_serialize_handler());
46     return netsnmp_register_handler(reginfo);
47 }
48
49 /** Implements the serial handler */
50 int
51 netsnmp_serialize_helper_handler(netsnmp_mib_handler *handler,
52                                  netsnmp_handler_registration *reginfo,
53                                  netsnmp_agent_request_info *reqinfo,
54                                  netsnmp_request_info *requests)
55 {
56
57     netsnmp_request_info *request, *requesttmp;
58
59     DEBUGMSGTL(("helper:serialize", "Got request\n"));
60     /*
61      * loop through requests 
62      */
63     for (request = requests; request; request = request->next) {
64         int             ret;
65
66         /*
67          * store next pointer and delete it 
68          */
69         requesttmp = request->next;
70         request->next = NULL;
71
72         /*
73          * call the next handler 
74          */
75         ret =
76             netsnmp_call_next_handler(handler, reginfo, reqinfo, request);
77
78         /*
79          * restore original next pointer 
80          */
81         request->next = requesttmp;
82
83         if (ret != SNMP_ERR_NOERROR)
84             return ret;
85     }
86
87     return SNMP_ERR_NOERROR;
88 }
89
90 /** 
91  *  initializes the serialize helper which then registers a serialize
92  *  handler as a run-time injectable handler for configuration file
93  *  use.
94  */
95 void
96 netsnmp_init_serialize(void)
97 {
98     netsnmp_register_handler_by_name("serialize",
99                                      netsnmp_get_serialize_handler());
100 }