Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / agent / nsModuleTable.c
1 #ifdef BRCM_SNMP_MIB_SUPPORT
2 /*
3  * Note: this file originally auto-generated by mib2c using
4  *        : mib2c.iterate.conf,v 1.5 2001/12/04 21:36:27 hardaker Exp $
5  */
6
7 #include <net-snmp/net-snmp-config.h>
8 #include <net-snmp/net-snmp-includes.h>
9 #include <net-snmp/agent/net-snmp-agent-includes.h>
10 #include "nsModuleTable.h"
11
12 void
13 nsModuleTable_free(void *context, netsnmp_iterator_info *dont_care)
14 {
15     free(context);
16 }
17     
18 /** Initialize the nsModuleTable table by defining it's contents and how it's structured */
19 void
20 initialize_table_nsModuleTable(void)
21 {
22     static oid      nsModuleTable_oid[] =
23         { 1, 3, 6, 1, 4, 1, 8072, 1, 2, 1 };
24     netsnmp_table_registration_info *table_info;
25     netsnmp_handler_registration *my_handler;
26     netsnmp_iterator_info *iinfo;
27
28     /*
29      * create the table structure itself 
30      */
31     table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
32     iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
33
34     /*
35      * if your table is read only, it's easiest to change the
36      * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY 
37      */
38     my_handler = netsnmp_create_handler_registration("nsModuleTable",
39                                                      nsModuleTable_handler,
40                                                      nsModuleTable_oid,
41                                                      OID_LENGTH
42                                                      (nsModuleTable_oid),
43                                                      HANDLER_CAN_RWRITE);
44
45     if (!my_handler || !table_info || !iinfo)
46         return;                 /* mallocs failed */
47
48     /***************************************************
49      * Setting up the table's definition
50      */
51     netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, /* context name */
52                                      ASN_OBJECT_ID,     /* reg point */
53                                      ASN_INTEGER,       /* priority */
54                                      0);
55
56     table_info->min_column = 4;
57     table_info->max_column = 6;
58
59     /*
60      * iterator access routines 
61      */
62     iinfo->get_first_data_point = nsModuleTable_get_first_data_point;
63     iinfo->get_next_data_point = nsModuleTable_get_next_data_point;
64     iinfo->free_loop_context_at_end = nsModuleTable_free;
65     iinfo->table_reginfo = table_info;
66
67     /***************************************************
68      * registering the table with the master agent
69      */
70     DEBUGMSGTL(("initialize_table_nsModuleTable",
71                 "Registering table nsModuleTable as a table iterator\n"));
72     netsnmp_register_table_iterator(my_handler, iinfo);
73 }
74
75 /** Initialzies the nsModuleTable module */
76 void
77 init_nsModuleTable(void)
78 {
79
80     /*
81      * here we initialize all the tables we're planning on supporting 
82      */
83     initialize_table_nsModuleTable();
84 }
85
86 /** returns the first data point within the nsModuleTable table data.
87
88     Set the my_loop_context variable to the first data point structure
89     of your choice (from which you can find the next one).  This could
90     be anything from the first node in a linked list, to an integer
91     pointer containing the beginning of an array variable.
92
93     Set the my_data_context variable to something to be returned to
94     you later that will provide you with the data to return in a given
95     row.  This could be the same pointer as what my_loop_context is
96     set to, or something different.
97
98     The put_index_data variable contains a list of snmp variable
99     bindings, one for each index in your table.  Set the values of
100     each appropriately according to the data matching the first row
101     and return the put_index_data variable at the end of the function.
102 */
103 typedef struct context_tree_ptr_s {
104     netsnmp_subtree *tree;
105     subtree_context_cache *context_ptr;
106 } context_tree_ptr;
107
108 netsnmp_variable_list *
109 nsModuleTable_get_first_data_point(void **my_loop_context,
110                                    void **my_data_context,
111                                    netsnmp_variable_list * put_index_data,
112                                    netsnmp_iterator_info *otherstuff)
113 {
114
115     struct variable_list *vptr;
116     u_long          ultmp;
117     context_tree_ptr *ctree;
118
119     ctree = SNMP_MALLOC_TYPEDEF(context_tree_ptr);
120
121     ctree->context_ptr = get_top_context_cache();
122     ctree->tree = ctree->context_ptr->first_subtree;
123
124     *my_loop_context = ctree;
125     *my_data_context = ctree->tree;
126
127     vptr = put_index_data;
128     snmp_set_var_value(vptr, (u_char *) ctree->context_ptr->context_name,
129                        strlen(ctree->context_ptr->context_name));
130
131     vptr = vptr->next_variable;
132     snmp_set_var_value(vptr,
133                        (u_char *)ctree->context_ptr->first_subtree->name_a,
134                        ctree->context_ptr->first_subtree->namelen *
135                        sizeof(oid));
136
137     ultmp = ctree->context_ptr->first_subtree->priority;
138     vptr = vptr->next_variable;
139     snmp_set_var_value(vptr, (u_char *) & ultmp, sizeof(ultmp));
140
141     return put_index_data;
142 }
143
144 /** functionally the same as nsModuleTable_get_first_data_point, but
145    my_loop_context has already been set to a previous value and should
146    be updated to the next in the list.  For example, if it was a
147    linked list, you might want to cast it and the return
148    my_loop_context->next.  The my_data_context pointer should be set
149    to something you need later and the indexes in put_index_data
150    updated again. */
151
152 struct variable_list *
153 nsModuleTable_get_next_data_point(void **my_loop_context,
154                                   void **my_data_context,
155                                   struct variable_list *put_index_data,
156                                   netsnmp_iterator_info *otherstuff)
157 {
158
159     struct variable_list *vptr;
160     context_tree_ptr *ctree = (context_tree_ptr *) * my_loop_context;
161     u_long          ultmp;
162
163     if (ctree->tree->next)
164         ctree->tree = ctree->tree->next;
165     else {
166         ctree->context_ptr = ctree->context_ptr->next;
167         if (!ctree->context_ptr) {
168             return NULL;
169         }
170         ctree->tree = ctree->context_ptr->first_subtree;
171     }
172
173     *my_data_context = ctree->tree;
174
175     vptr = put_index_data;
176     snmp_set_var_value(vptr, (u_char *) ctree->context_ptr->context_name,
177                        strlen(ctree->context_ptr->context_name));
178
179     vptr = vptr->next_variable;
180     snmp_set_var_value(vptr, (u_char *) ctree->tree->name_a,
181                        ctree->tree->namelen * sizeof(oid));
182
183     ultmp = ctree->tree->priority;
184     vptr = vptr->next_variable;
185     snmp_set_var_value(vptr, (u_char *) & ultmp, sizeof(ultmp));
186
187     return put_index_data;
188 }
189
190 /** handles requests for the nsModuleTable table, if anything else needs to be done */
191 int
192 nsModuleTable_handler(netsnmp_mib_handler *handler,
193                       netsnmp_handler_registration *reginfo,
194                       netsnmp_agent_request_info *reqinfo,
195                       netsnmp_request_info *requests)
196 {
197
198     netsnmp_table_request_info *table_info;
199     netsnmp_request_info *request;
200     netsnmp_variable_list *var;
201     netsnmp_subtree *tree;
202     u_long          ultmp;
203     u_char          modes[1];
204
205     for (request = requests; request; request = request->next) {
206         var = request->requestvb;
207         if (request->processed != 0)
208             continue;
209
210         /*
211          * perform anything here that you need to do.  The request have
212          * already been processed by the master table_dataset handler, but
213          * this gives you chance to act on the request in some other way if 
214          * need be. 
215          */
216
217         /*
218          * the following extracts the my_data_context pointer set in the
219          * loop functions above.  You can then use the results to help
220          * return data for the columns of the nsModuleTable table in
221          * question 
222          */
223         tree = (netsnmp_subtree *)netsnmp_extract_iterator_context(request);
224         if (tree == NULL) {
225             if (reqinfo->mode == MODE_GET) {
226                 netsnmp_set_request_error(reqinfo, request,
227                                           SNMP_NOSUCHINSTANCE);
228                 continue;
229             }
230             /*
231              * XXX: no row existed, if you support creation and this is a
232              * set, start dealing with it here, else continue 
233              */
234         }
235
236         /*
237          * extracts the information about the table from the request 
238          */
239         table_info = netsnmp_extract_table_info(request);
240
241         /*
242          * table_info->colnum contains the column number requested 
243          */
244         /*
245          * table_info->indexes contains a linked list of snmp variable
246          * bindings for the indexes of the table.  Values in the list have 
247          * been set corresponding to the indexes of the request 
248          */
249         if (table_info == NULL) {
250             continue;
251         }
252
253         switch (reqinfo->mode) {
254             /*
255              * the table_iterator helper should change all GETNEXTs into
256              * GETs for you automatically, so you don't have to worry
257              * about the GETNEXT case.  Only GETs and SETs need to be
258              * dealt with here 
259              */
260         case MODE_GET:
261             switch (table_info->colnum) {
262             case COLUMN_NSMODULENAME:
263                 if (tree->reginfo->handlerName) {
264                     snmp_set_var_typed_value(var, ASN_OCTET_STR,
265                                            tree->reginfo->handlerName,
266                                            strlen(tree->reginfo->handlerName));
267                 } else {
268                     snmp_set_var_typed_value(var, ASN_OCTET_STR, "", 0);
269                 }
270                 break;
271
272             case COLUMN_NSMODULEMODES:
273                 /*
274                  * basically, these BITS needs to be inverted in order 
275                  */
276                 modes[0] =
277                     ((HANDLER_CAN_GETANDGETNEXT & tree->reginfo->
278                       modes) << 7) | ((HANDLER_CAN_SET & tree->reginfo->
279                                        modes) << 5) | ((HANDLER_CAN_GETBULK
280                                                         & tree->reginfo->
281                                                         modes) << 3);
282                 /*  yuck  */
283                 snmp_set_var_typed_value(var, ASN_OCTET_STR, modes, 1);
284                 break;
285
286             case COLUMN_NSMODULETIMEOUT:
287                 ultmp = tree->timeout;
288                 snmp_set_var_typed_value(var, ASN_INTEGER,
289                                          (u_char *) & ultmp,
290                                          sizeof(u_long));
291                 break;
292
293             default:
294                 /*
295                  * We shouldn't get here 
296                  */
297                 snmp_log(LOG_ERR,
298                          "problem encountered in nsModuleTable_handler: unknown column\n");
299             }
300             break;
301
302         default:
303             snmp_log(LOG_ERR,
304                      "problem encountered in nsModuleTable_handler: unsupported mode\n");
305         }
306     }
307     return SNMP_ERR_NOERROR;
308 }
309 #endif /* BRCM_SNMP_MIB_SUPPORT */