2
######################################################################
4
######################################################################
7
* Note: this file originally auto-generated by mib2c using
8
* $Id: mib2c.iterate.conf,v 5.9 2003/06/04 00:14:41 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 */
25
#include "${name}_columns.h"
26
@run mib2c.column_defines.conf@
29
#include "${name}_enums.h"
30
@run mib2c.column_enums.conf@
32
#endif /* $name.uc_H */
33
######################################################################
35
######################################################################
38
* Note: this file originally auto-generated by mib2c using
39
* $Id: mib2c.iterate.conf,v 5.9 2003/06/04 00:14:41 hardaker Exp $
42
#include <net-snmp/net-snmp-config.h>
43
#include <net-snmp/net-snmp-includes.h>
44
#include <net-snmp/agent/net-snmp-agent-includes.h>
48
/** Initialize the $i table by defining its contents and how it's structured */
50
initialize_table_$i(void)
52
static oid ${i}_oid[] = {$i.commaoid};
53
netsnmp_table_registration_info *table_info;
54
netsnmp_handler_registration *my_handler;
55
netsnmp_iterator_info *iinfo;
57
/** create the table registration information structures */
58
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
59
iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
61
/** if your table is read only, it's easiest to change the
62
HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */
63
my_handler = netsnmp_create_handler_registration("$i",
69
if (!my_handler || !table_info || !iinfo) {
70
snmp_log(LOG_ERR, "malloc failed in initialize_table_$i");
71
return; /* Serious error. */
74
/***************************************************
75
* Setting up the table's definition
77
netsnmp_table_helper_add_indexes(table_info,
79
$idx.type, /* index: $idx */
83
/** Define the minimum and maximum accessible columns. This
84
optimizes retrival. */
85
@eval $minv = 0xffffffff@
88
@if $c.access =~ /(Read|Create)/@
89
@eval $minv = min($minv, $c.subid)@
90
@eval $maxv = max($maxv, $c.subid)@
93
table_info->min_column = $minv;
94
table_info->max_column = $maxv;
96
/* iterator access routines */
97
iinfo->get_first_data_point = ${i}_get_first_data_point;
98
iinfo->get_next_data_point = ${i}_get_next_data_point;
100
/** you may wish to set these as well */
101
#ifdef MAYBE_USE_THESE
102
iinfo->make_data_context = ${i}_context_convert_function;
103
iinfo->free_data_context = ${i}_data_free;
105
/** pick *only* one of these if you use them */
106
iinfo->free_loop_context = ${i}_loop_free;
107
iinfo->free_loop_context_at_end = ${i}_loop_free;
110
/** tie the two structures together */
111
iinfo->table_reginfo = table_info;
113
/***************************************************
114
* registering the table with the master agent
116
DEBUGMSGTL(("initialize_table_$i",
117
"Registering table $i as a table iterator\n"));
118
netsnmp_register_table_iterator(my_handler, iinfo);
122
/** Initializes the $name module */
127
/** here we initialize all the tables we're planning on supporting */
129
initialize_table_$i();
134
/** returns the first data point within the $i table data.
136
Set the my_loop_context variable to the first data point structure
137
of your choice (from which you can find the next one). This could
138
be anything from the first node in a linked list, to an integer
139
pointer containing the beginning of an array variable.
141
Set the my_data_context variable to something to be returned to
142
you later (in your main ${i}_handler routine) that will provide
143
you with the data to return in a given row. This could be the
144
same pointer as what my_loop_context is set to, or something
147
The put_index_data variable contains a list of snmp variable
148
bindings, one for each index in your table. Set the values of
149
each appropriately according to the data matching the first row
150
and return the put_index_data variable at the end of the function.
152
netsnmp_variable_list *
153
${i}_get_first_data_point(void **my_loop_context, void **my_data_context,
154
netsnmp_variable_list *put_index_data,
155
netsnmp_iterator_info *mydata)
158
netsnmp_variable_list *vptr;
160
*my_loop_context = /** XXX */;
161
*my_data_context = /** XXX */;
163
vptr = put_index_data;
166
snmp_set_var_value(vptr, (u_char *) /** XXX: $idx data */, /** XXX: length of $idx data */);
167
vptr = vptr->next_variable;
170
return put_index_data;
173
/** functionally the same as ${i}_get_first_data_point, but
174
my_loop_context has already been set to a previous value and should
175
be updated to the next in the list. For example, if it was a
176
linked list, you might want to cast it to your local data type and
177
then return my_loop_context->next. The my_data_context pointer
178
should be set to something you need later (in your main
179
${i}_handler routine) and the indexes in put_index_data updated
181
netsnmp_variable_list *
182
${i}_get_next_data_point(void **my_loop_context, void **my_data_context,
183
netsnmp_variable_list *put_index_data,
184
netsnmp_iterator_info *mydata)
187
netsnmp_variable_list *vptr;
189
*my_loop_context = /** XXX */;
190
*my_data_context = /** XXX */;
192
vptr = put_index_data;
195
snmp_set_var_value(vptr, (u_char *) /** XXX: $idx data */, /** XXX: length of $idx data */);
196
vptr = vptr->next_variable;
199
return put_index_data;
202
/** handles requests for the $i table, if anything else needs to be done */
205
netsnmp_mib_handler *handler,
206
netsnmp_handler_registration *reginfo,
207
netsnmp_agent_request_info *reqinfo,
208
netsnmp_request_info *requests) {
210
netsnmp_request_info *request;
211
netsnmp_table_request_info *table_info;
212
netsnmp_variable_list *var;
214
for(request = requests; request; request = request->next) {
215
var = request->requestvb;
216
if (request->processed != 0)
219
/** perform anything here that you need to do before each
220
request is processed. */
222
/** the following extracts the my_data_context pointer set in
223
the loop functions above. You can then use the results to
224
help return data for the columns of the $i table in question */
225
/** XXX */ = (/** XXX */ *) netsnmp_extract_iterator_context(request);
226
if (/** XXX */ == NULL) {
227
if (reqinfo->mode == MODE_GET) {
228
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
231
/** XXX: no row existed, if you support creation and this is a
232
set, start dealing with it here, else continue */
235
/** extracts the information about the table from the request */
236
table_info = netsnmp_extract_table_info(request);
237
/** table_info->colnum contains the column number requested */
238
/** table_info->indexes contains a linked list of snmp variable
239
bindings for the indexes of the table. Values in the list
240
have been set corresponding to the indexes of the
242
if (table_info==NULL) {
246
switch(reqinfo->mode) {
247
/** the table_iterator helper should change all GETNEXTs
248
into GETs for you automatically, so you don't have to
249
worry about the GETNEXT case. Only GETs and SETs need
250
to be dealt with here */
252
switch(table_info->colnum) {
254
@if $c.access =~ /(Read|Create)/@
256
snmp_set_var_typed_value(var, $c.type, (u_char *) /** XXX: column data */, /** XXX: column data length */);
262
/** We shouldn't get here */
263
snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unknown column\n");
267
case MODE_SET_RESERVE1:
268
/** set handling... */
271
snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unsupported mode\n");
274
return SNMP_ERR_NOERROR;