2 ######################################################################
4 ######################################################################
7 * Note: this file originally auto-generated by mib2c using
8 * $Id: mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $
13 /* function declarations */
14 void init_$name(void);
16 void initialize_table_$i(void);
17 Netsnmp_Node_Handler ${i}_handler;
19 Netsnmp_First_Data_Point ${i}_get_first_data_point;
20 Netsnmp_Next_Data_Point ${i}_get_next_data_point;
24 /* column number definitions for table $i */
26 #define COLUMN_$c.uc $c.subid
29 #endif /* $name.uc_H */
30 ######################################################################
32 ######################################################################
35 * Note: this file originally auto-generated by mib2c using
36 * $Id: mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $
39 #include <net-snmp/net-snmp-config.h>
40 #include <net-snmp/net-snmp-includes.h>
41 #include <net-snmp/agent/net-snmp-agent-includes.h>
45 /** Initialize the $i table by defining its contents and how it's structured */
47 initialize_table_$i(void)
49 static oid ${i}_oid[] = {$i.commaoid};
50 netsnmp_table_registration_info *table_info;
51 netsnmp_handler_registration *my_handler;
52 netsnmp_iterator_info *iinfo;
54 /* create the table structure itself */
55 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
56 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
58 /* if your table is read only, it's easiest to change the
59 HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */
60 my_handler = netsnmp_create_handler_registration("$i",
66 if (!my_handler || !table_info || !iinfo)
67 return; /* mallocs failed */
69 /***************************************************
70 * Setting up the table's definition
72 netsnmp_table_helper_add_indexes(table_info,
74 $idx.type, /* index: $idx */
78 @eval $minv = 0xffffffff@
81 @if $c.access =~ /(Read|Create)/@
82 @eval $minv = min($minv, $c.subid)@
83 @eval $maxv = max($maxv, $c.subid)@
86 table_info->min_column = $minv;
87 table_info->max_column = $maxv;
89 /* iterator access routines */
90 iinfo->get_first_data_point = ${i}_get_first_data_point;
91 iinfo->get_next_data_point = ${i}_get_next_data_point;
93 iinfo->table_reginfo = table_info;
95 /***************************************************
96 * registering the table with the master agent
98 DEBUGMSGTL(("initialize_table_$i",
99 "Registering table $i as a table iterator\n"));
100 netsnmp_register_table_iterator(my_handler, iinfo);
104 /** Initializes the $name module */
109 /* here we initialize all the tables we're planning on supporting */
111 initialize_table_$i();
116 /** returns the first data point within the $i table data.
118 Set the my_loop_context variable to the first data point structure
119 of your choice (from which you can find the next one). This could
120 be anything from the first node in a linked list, to an integer
121 pointer containing the beginning of an array variable.
123 Set the my_data_context variable to something to be returned to
124 you later that will provide you with the data to return in a given
125 row. This could be the same pointer as what my_loop_context is
126 set to, or something different.
128 The put_index_data variable contains a list of snmp variable
129 bindings, one for each index in your table. Set the values of
130 each appropriately according to the data matching the first row
131 and return the put_index_data variable at the end of the function.
133 netsnmp_variable_list *
134 ${i}_get_first_data_point(void **my_loop_context, void **my_data_context,
135 netsnmp_variable_list *put_index_data,
136 netsnmp_iterator_info *mydata)
139 netsnmp_variable_list *vptr;
141 *my_loop_context = /* XXX */;
142 *my_data_context = /* XXX */;
144 vptr = put_index_data;
147 snmp_set_var_value(vptr, (u_char *) /* XXX: $idx data */, /* XXX: length of $idx data */);
148 vptr = vptr->next_variable;
151 return put_index_data;
154 /** functionally the same as ${i}_get_first_data_point, but
155 my_loop_context has already been set to a previous value and should
156 be updated to the next in the list. For example, if it was a
157 linked list, you might want to cast it and the return
158 my_loop_context->next. The my_data_context pointer should be set
159 to something you need later and the indexes in put_index_data
162 netsnmp_variable_list *
163 ${i}_get_next_data_point(void **my_loop_context, void **my_data_context,
164 netsnmp_variable_list *put_index_data,
165 netsnmp_iterator_info *mydata)
168 netsnmp_variable_list *vptr;
170 *my_loop_context = /* XXX */;
171 *my_data_context = /* XXX */;
173 vptr = put_index_data;
176 snmp_set_var_value(vptr, (u_char *) /* XXX: $idx data */, /* XXX: length of $idx data */);
177 vptr = vptr->next_variable;
180 return put_index_data;
183 /** handles requests for the $i table, if anything else needs to be done */
186 netsnmp_mib_handler *handler,
187 netsnmp_handler_registration *reginfo,
188 netsnmp_agent_request_info *reqinfo,
189 netsnmp_request_info *requests) {
191 netsnmp_request_info *request;
192 netsnmp_table_request_info *table_info;
193 netsnmp_variable_list *var;
195 for(request = requests; request; request = request->next) {
196 var = request->requestvb;
197 if (request->processed != 0)
200 /* perform anything here that you need to do before each
201 request is processed. */
203 /* the following extracts the my_data_context pointer set in
204 the loop functions above. You can then use the results to
205 help return data for the columns of the $i table in question */
206 /* XXX */ = (/* XXX */ *) netsnmp_extract_iterator_context(request);
207 if (/* XXX */ == NULL) {
208 if (reqinfo->mode == MODE_GET) {
209 netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
212 /* XXX: no row existed, if you support creation and this is a
213 set, start dealing with it here, else continue */
216 /* extracts the information about the table from the request */
217 table_info = netsnmp_extract_table_info(request);
218 /* table_info->colnum contains the column number requested */
219 /* table_info->indexes contains a linked list of snmp variable
220 bindings for the indexes of the table. Values in the list
221 have been set corresponding to the indexes of the
223 if (table_info==NULL) {
227 switch(reqinfo->mode) {
228 /* the table_iterator helper should change all GETNEXTs
229 into GETs for you automatically, so you don't have to
230 worry about the GETNEXT case. Only GETs and SETs need
231 to be dealt with here */
233 switch(table_info->colnum) {
235 @if $c.access =~ /(Read|Create)/@
237 snmp_set_var_typed_value(var, $c.type, (u_char *) /* XXX: column data */, /* XXX: column data length */);
243 /* We shouldn't get here */
244 snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unknown column\n");
248 case MODE_SET_RESERVE1:
249 /* set handling... */
252 snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unsupported mode\n");
255 return SNMP_ERR_NOERROR;