summaryrefslogtreecommitdiff
path: root/local/mib2c.old-api.conf
blob: 8fa270b45fa82a2dbffcef80f892834431e7897b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
## -*- c -*-
######################################################################
## Do the .h file
######################################################################
@open ${name}.h@
/*
 * Note: this file originally auto-generated by mib2c using
 *        $Id$
 */
#ifndef $name.uc_H
#define $name.uc_H

/* function declarations */
void init_$name(void);
FindVarMethod var_$name;
@foreach $i table@
FindVarMethod var_${i};
@end@
@foreach $i scalar@
    @if $i.settable@
    WriteMethod write_${i};
    @end@
@end@
@foreach $i table@
 @foreach $c column@
    @if $c.settable@
    WriteMethod write_${c};
    @end@
 @end@
@end@

#endif /* $name.uc_H */
######################################################################
## Do the .c file
######################################################################
@open ${name}.c@
/*
 * Note: this file originally auto-generated by mib2c using
 *        $Id$
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "${name}.h"

/* 
 * ${name}_variables_oid:
 *   this is the top level oid that we want to register under.  This
 *   is essentially a prefix, with the suffix appearing in the
 *   variable below.
 */

oid ${name}_variables_oid[] = { $name.commaoid };

/* 
 * variable4 ${name}_variables:
 *   this variable defines function callbacks and type return information 
 *   for the $name mib section 
 */

struct variable4 ${name}_variables[] = {
/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
@eval $magic = 0@
@eval $namelen = length("$name.commaoid")@
@foreach $i scalar@
    @eval $magic = $magic + 1@
    @eval $suffix = substr("$i.commaoid", $namelen + 1)@
    @eval $suffixlen = $i.oidlength - $name.oidlength@
#define $i.uc		$magic
    @if $i.settable@
{$i.uc,  $i.type,  NETSNMP_OLDAPI_RWRITE,
 var_${name}, $suffixlen,  { $suffix }},
    @end@
    @if !$i.settable@
{$i.uc,  $i.type,  NETSNMP_OLDAPI_RONLY,
 var_${name}, $suffixlen,  { $suffix }},
    @end@
@end@

@foreach $i table@
 @eval $magic = 0@
 @eval $nlen2 = length("$i.commaoid")@
 @if $nlen2 > $namelen@
  @eval $suffix = substr("$i.commaoid", $namelen + 1)@
  @eval $ctmp = ","@
 @else@
  @eval $suffix = ""@
  @eval $ctmp = ""@
 @end@
 @eval $suffixlen = $i.oidlength - $name.oidlength + 2@
 @foreach $c column@
    @eval $magic = $magic + 1@
#define $c.uc		$magic
    @if $c.settable@
{$c.uc,  $c.type,  NETSNMP_OLDAPI_RWRITE,
 var_${i}, $suffixlen,  { $suffix $ctmp 1, $c.subid }},
    @end@
    @if !$c.settable@
{$c.uc,  $c.type,  NETSNMP_OLDAPI_RONLY,
 var_${i}, $suffixlen,  { $suffix $ctmp 1, $c.subid }},
    @end@
 @end@
@end@
};
/*    (L = length of the oidsuffix) */


/** Initializes the $name module */
void
init_$name(void)
{

    DEBUGMSGTL(("$name", "Initializing\n"));

    /* register ourselves with the agent to handle our mib tree */
    REGISTER_MIB("$name", ${name}_variables, variable4,
               ${name}_variables_oid);

    /* place any other initialization junk you need here */
}

/*
 * var_$name():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char *
var_$name(struct variable *vp, 
                oid     *name, 
                size_t  *length, 
                int     exact, 
                size_t  *var_len, 
                WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static u_long ulong_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;

    if (header_generic(vp,name,length,exact,var_len,write_method)
                                  == MATCH_FAILED )
    return NULL;

    /* 
   * this is where we do the value assignments for the mib results.
   */
    switch(vp->magic) {
@foreach $i scalar@
    case $i.uc:
    @if $i.settable@
        *write_method = write_${i};
    @end@
        VAR = VALUE;	/* XXX */
        return (u_char*) &VAR;
@end@
    default:
      ERROR_MSG("");
    }
    return NULL;
}


@foreach $i table@
/*
 * var_$i():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_$name above.
 */
unsigned char *
var_$i(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static u_long ulong_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;

    /* 
   * This assumes that the table is a 'simple' table.
   *	See the implementation documentation for the meaning of this.
   *	You will need to provide the correct value for the TABLE_SIZE parameter
   *
   * If this table does not meet the requirements for a simple table,
   *	you will need to provide the replacement code yourself.
   *	Mib2c is not smart enough to write this for you.
   *    Again, see the implementation documentation for what is required.
   */
    if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
                                                == MATCH_FAILED )
    return NULL;

    /* 
   * this is where we do the value assignments for the mib results.
   */
    switch(vp->magic) {
@foreach $c column@
    case $c.uc:
    @if $c.settable@
        *write_method = write_${c};
    @end@
        VAR = VALUE;	/* XXX */
        return (u_char*) &VAR;
@end@
    default:
      ERROR_MSG("");
    }
    return NULL;
}
@end@

@foreach $i scalar@
@if $i.settable@


int
write_$i(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,
            oid      *name,
            size_t   name_len)
{
    $i.decl value;
    int size;

    switch ( action ) {
        case RESERVE1:
          if (var_val_type != $i.type) {
              fprintf(stderr, "write to $name not $i.type\n");
              return SNMP_ERR_WRONGTYPE;
          }
          if (var_val_len > sizeof($i.decl)) {
              fprintf(stderr,"write to $name: bad length\n");
              return SNMP_ERR_WRONGLENGTH;
          }
          break;

        case RESERVE2:
          size  = var_val_len;
          value = * ($i.decl *) var_val;

          break;

        case FREE:
             /* Release any resources that have been allocated */
          break;

        case ACTION:
             /*
              * The variable has been stored in 'value' for you to use,
              * and you have just been asked to do something with it.
              * Note that anything done here must be reversable in the UNDO case
              */
          break;

        case UNDO:
             /* Back out any changes made in the ACTION case */
          break;

        case COMMIT:
             /*
              * Things are working well, so it's now safe to make the change
              * permanently.  Make sure that anything done here can't fail!
              */
          break;
    }
    return SNMP_ERR_NOERROR;
}
@end@
@end@

@foreach $i table@
@foreach $c column@
@if $c.settable@
int
write_$c(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,
            oid      *name,
            size_t   name_len)
{
    $c.decl value;
    int size;

    switch ( action ) {
        case RESERVE1:
          if (var_val_type != $c.type) {
              fprintf(stderr, "write to $name not $c.type\n");
              return SNMP_ERR_WRONGTYPE;
          }
          if (var_val_len > sizeof($c.decl)) {
              fprintf(stderr,"write to $name: bad length\n");
              return SNMP_ERR_WRONGLENGTH;
          }
          break;

        case RESERVE2:
          size  = var_val_len;
          value = * ($c.decl *) var_val;

          break;

        case FREE:
             /* Release any resources that have been allocated */
          break;

        case ACTION:
             /*
              * The variable has been stored in 'value' for you to use,
              * and you have just been asked to do something with it.
              * Note that anything done here must be reversable in the UNDO case
              */
          break;

        case UNDO:
             /* Back out any changes made in the ACTION case */
          break;

        case COMMIT:
             /*
              * Things are working well, so it's now safe to make the change
              * permanently.  Make sure that anything done here can't fail!
              */
          break;
    }
    return SNMP_ERR_NOERROR;
}
@end@
@end@
@end@