1 #ifdef BRCM_SNMP_MIB_SUPPORT
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 $
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"
13 nsModuleTable_free(void *context, netsnmp_iterator_info *dont_care)
18 /** Initialize the nsModuleTable table by defining it's contents and how it's structured */
20 initialize_table_nsModuleTable(void)
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;
29 * create the table structure itself
31 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
32 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
35 * if your table is read only, it's easiest to change the
36 * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY
38 my_handler = netsnmp_create_handler_registration("nsModuleTable",
39 nsModuleTable_handler,
45 if (!my_handler || !table_info || !iinfo)
46 return; /* mallocs failed */
48 /***************************************************
49 * Setting up the table's definition
51 netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, /* context name */
52 ASN_OBJECT_ID, /* reg point */
53 ASN_INTEGER, /* priority */
56 table_info->min_column = 4;
57 table_info->max_column = 6;
60 * iterator access routines
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;
67 /***************************************************
68 * registering the table with the master agent
70 DEBUGMSGTL(("initialize_table_nsModuleTable",
71 "Registering table nsModuleTable as a table iterator\n"));
72 netsnmp_register_table_iterator(my_handler, iinfo);
75 /** Initialzies the nsModuleTable module */
77 init_nsModuleTable(void)
81 * here we initialize all the tables we're planning on supporting
83 initialize_table_nsModuleTable();
86 /** returns the first data point within the nsModuleTable table data.
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.
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.
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.
103 typedef struct context_tree_ptr_s {
104 netsnmp_subtree *tree;
105 subtree_context_cache *context_ptr;
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)
115 struct variable_list *vptr;
117 context_tree_ptr *ctree;
119 ctree = SNMP_MALLOC_TYPEDEF(context_tree_ptr);
121 ctree->context_ptr = get_top_context_cache();
122 ctree->tree = ctree->context_ptr->first_subtree;
124 *my_loop_context = ctree;
125 *my_data_context = ctree->tree;
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));
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 *
137 ultmp = ctree->context_ptr->first_subtree->priority;
138 vptr = vptr->next_variable;
139 snmp_set_var_value(vptr, (u_char *) & ultmp, sizeof(ultmp));
141 return put_index_data;
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
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)
159 struct variable_list *vptr;
160 context_tree_ptr *ctree = (context_tree_ptr *) * my_loop_context;
163 if (ctree->tree->next)
164 ctree->tree = ctree->tree->next;
166 ctree->context_ptr = ctree->context_ptr->next;
167 if (!ctree->context_ptr) {
170 ctree->tree = ctree->context_ptr->first_subtree;
173 *my_data_context = ctree->tree;
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));
179 vptr = vptr->next_variable;
180 snmp_set_var_value(vptr, (u_char *) ctree->tree->name_a,
181 ctree->tree->namelen * sizeof(oid));
183 ultmp = ctree->tree->priority;
184 vptr = vptr->next_variable;
185 snmp_set_var_value(vptr, (u_char *) & ultmp, sizeof(ultmp));
187 return put_index_data;
190 /** handles requests for the nsModuleTable table, if anything else needs to be done */
192 nsModuleTable_handler(netsnmp_mib_handler *handler,
193 netsnmp_handler_registration *reginfo,
194 netsnmp_agent_request_info *reqinfo,
195 netsnmp_request_info *requests)
198 netsnmp_table_request_info *table_info;
199 netsnmp_request_info *request;
200 netsnmp_variable_list *var;
201 netsnmp_subtree *tree;
205 for (request = requests; request; request = request->next) {
206 var = request->requestvb;
207 if (request->processed != 0)
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
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
223 tree = (netsnmp_subtree *)netsnmp_extract_iterator_context(request);
225 if (reqinfo->mode == MODE_GET) {
226 netsnmp_set_request_error(reqinfo, request,
227 SNMP_NOSUCHINSTANCE);
231 * XXX: no row existed, if you support creation and this is a
232 * set, start dealing with it here, else continue
237 * extracts the information about the table from the request
239 table_info = netsnmp_extract_table_info(request);
242 * table_info->colnum contains the column number requested
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
249 if (table_info == NULL) {
253 switch (reqinfo->mode) {
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
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));
268 snmp_set_var_typed_value(var, ASN_OCTET_STR, "", 0);
272 case COLUMN_NSMODULEMODES:
274 * basically, these BITS needs to be inverted in order
277 ((HANDLER_CAN_GETANDGETNEXT & tree->reginfo->
278 modes) << 7) | ((HANDLER_CAN_SET & tree->reginfo->
279 modes) << 5) | ((HANDLER_CAN_GETBULK
283 snmp_set_var_typed_value(var, ASN_OCTET_STR, modes, 1);
286 case COLUMN_NSMODULETIMEOUT:
287 ultmp = tree->timeout;
288 snmp_set_var_typed_value(var, ASN_INTEGER,
295 * We shouldn't get here
298 "problem encountered in nsModuleTable_handler: unknown column\n");
304 "problem encountered in nsModuleTable_handler: unsupported mode\n");
307 return SNMP_ERR_NOERROR;
309 #endif /* BRCM_SNMP_MIB_SUPPORT */