~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to local/mib2c.iterate.conf

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## -*- c -*-
 
2
######################################################################
 
3
## Do the .h file
 
4
######################################################################
 
5
@open ${name}.h@
 
6
/*
 
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 $
 
9
 */
 
10
#ifndef $name.uc_H
 
11
#define $name.uc_H
 
12
 
 
13
/* function declarations */
 
14
void init_$name(void);
 
15
@foreach $i table@
 
16
void initialize_table_$i(void);
 
17
Netsnmp_Node_Handler ${i}_handler;
 
18
 
 
19
Netsnmp_First_Data_Point  ${i}_get_first_data_point;
 
20
Netsnmp_Next_Data_Point   ${i}_get_next_data_point;
 
21
@end@
 
22
@foreach $i table@
 
23
 
 
24
/* column number definitions for table $i */
 
25
#include "${name}_columns.h"
 
26
@run mib2c.column_defines.conf@
 
27
 
 
28
/* enum definions */
 
29
#include "${name}_enums.h"
 
30
@run mib2c.column_enums.conf@
 
31
 
 
32
#endif /* $name.uc_H */
 
33
######################################################################
 
34
## Do the .c file
 
35
######################################################################
 
36
@open ${name}.c@
 
37
/*
 
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 $
 
40
 */
 
41
 
 
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>
 
45
#include "${name}.h"
 
46
 
 
47
@foreach $i table@
 
48
/** Initialize the $i table by defining its contents and how it's structured */
 
49
void
 
50
initialize_table_$i(void)
 
51
{
 
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;
 
56
 
 
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);
 
60
 
 
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",
 
64
                                             ${i}_handler,
 
65
                                             ${i}_oid,
 
66
                                             OID_LENGTH(${i}_oid),
 
67
                                             HANDLER_CAN_RWRITE);
 
68
            
 
69
    if (!my_handler || !table_info || !iinfo) {
 
70
        snmp_log(LOG_ERR, "malloc failed in initialize_table_$i");
 
71
        return; /* Serious error. */
 
72
    }
 
73
 
 
74
    /***************************************************
 
75
     * Setting up the table's definition
 
76
     */
 
77
    netsnmp_table_helper_add_indexes(table_info,
 
78
    @foreach $idx index@
 
79
                                  $idx.type, /* index: $idx */
 
80
    @end@
 
81
                             0);
 
82
 
 
83
    /** Define the minimum and maximum accessible columns.  This
 
84
        optimizes retrival. */
 
85
    @eval $minv = 0xffffffff@
 
86
    @eval $maxv = 0@
 
87
    @foreach $c column@
 
88
        @if $c.access =~ /(Read|Create)/@
 
89
          @eval $minv = min($minv, $c.subid)@
 
90
          @eval $maxv = max($maxv, $c.subid)@
 
91
        @end@
 
92
    @end@
 
93
    table_info->min_column = $minv;
 
94
    table_info->max_column = $maxv;
 
95
 
 
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;
 
99
 
 
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;
 
104
 
 
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;
 
108
#endif
 
109
 
 
110
    /** tie the two structures together */
 
111
    iinfo->table_reginfo = table_info;
 
112
 
 
113
    /***************************************************
 
114
     * registering the table with the master agent
 
115
     */
 
116
    DEBUGMSGTL(("initialize_table_$i",
 
117
                "Registering table $i as a table iterator\n"));          
 
118
    netsnmp_register_table_iterator(my_handler, iinfo);
 
119
}
 
120
@end@
 
121
 
 
122
/** Initializes the $name module */
 
123
void
 
124
init_$name(void)
 
125
{
 
126
 
 
127
  /** here we initialize all the tables we're planning on supporting */
 
128
  @foreach $i table@
 
129
    initialize_table_$i();
 
130
  @end@
 
131
}
 
132
@foreach $i table@
 
133
 
 
134
/** returns the first data point within the $i table data.
 
135
 
 
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.
 
140
 
 
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
 
145
    different.
 
146
 
 
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.
 
151
*/
 
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)
 
156
{
 
157
 
 
158
    netsnmp_variable_list *vptr;
 
159
 
 
160
    *my_loop_context = /** XXX */;
 
161
    *my_data_context = /** XXX */;
 
162
 
 
163
    vptr = put_index_data;
 
164
    
 
165
    @foreach $idx index@
 
166
    snmp_set_var_value(vptr, (u_char *) /** XXX: $idx data */, /** XXX: length of $idx data */);
 
167
    vptr = vptr->next_variable;
 
168
    @end@
 
169
 
 
170
    return put_index_data;
 
171
}
 
172
 
 
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
 
180
   again. */
 
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)
 
185
{
 
186
 
 
187
    netsnmp_variable_list *vptr;
 
188
 
 
189
    *my_loop_context = /** XXX */;
 
190
    *my_data_context = /** XXX */;
 
191
 
 
192
    vptr = put_index_data;
 
193
    
 
194
    @foreach $idx index@
 
195
    snmp_set_var_value(vptr, (u_char *) /** XXX: $idx data */, /** XXX: length of $idx data */);
 
196
    vptr = vptr->next_variable;
 
197
    @end@
 
198
 
 
199
    return put_index_data;
 
200
}
 
201
 
 
202
/** handles requests for the $i table, if anything else needs to be done */
 
203
int
 
204
${i}_handler(
 
205
    netsnmp_mib_handler               *handler,
 
206
    netsnmp_handler_registration      *reginfo,
 
207
    netsnmp_agent_request_info        *reqinfo,
 
208
    netsnmp_request_info              *requests) {
 
209
 
 
210
    netsnmp_request_info *request;
 
211
    netsnmp_table_request_info *table_info;
 
212
    netsnmp_variable_list *var;
 
213
    
 
214
    for(request = requests; request; request = request->next) {
 
215
        var = request->requestvb;
 
216
        if (request->processed != 0)
 
217
            continue;
 
218
 
 
219
        /** perform anything here that you need to do before each
 
220
           request is processed. */
 
221
 
 
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);
 
229
                continue;
 
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
        /** 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
 
241
           request */
 
242
        if (table_info==NULL) {
 
243
            continue;
 
244
        }
 
245
 
 
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 */
 
251
            case MODE_GET:
 
252
                switch(table_info->colnum) {
 
253
                    @foreach $c column@
 
254
                        @if $c.access =~ /(Read|Create)/@
 
255
                    case COLUMN_$c.uc:
 
256
                        snmp_set_var_typed_value(var, $c.type, (u_char *) /** XXX: column data */, /** XXX: column data length */);
 
257
                        break;
 
258
 
 
259
                        @end@
 
260
                    @end@
 
261
                    default:
 
262
                        /** We shouldn't get here */
 
263
                        snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unknown column\n");
 
264
                }
 
265
                break;
 
266
 
 
267
            case MODE_SET_RESERVE1:
 
268
                /** set handling... */
 
269
 
 
270
            default:
 
271
                snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unsupported mode\n");
 
272
        }
 
273
    }
 
274
    return SNMP_ERR_NOERROR;
 
275
}