and added files
[bcm963xx.git] / userapps / opensource / net-snmp / local / mib2c.old-api.conf
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.old-api.conf,v 1.3 2002/10/17 09:40:46 dts12 Exp $
9  */
10 #ifndef $name.uc_H
11 #define $name.uc_H
12
13 /* function declarations */
14 void init_$name(void);
15 FindVarMethod var_$name;
16 @foreach $i table@
17 FindVarMethod var_${i};
18 @end@
19 @foreach $i scalar@
20     @if $i.settable@
21     WriteMethod write_${i};
22     @end@
23 @end@
24 @foreach $i table@
25  @foreach $c column@
26     @if $c.settable@
27     WriteMethod write_${c};
28     @end@
29  @end@
30 @end@
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.old-api.conf,v 1.3 2002/10/17 09:40:46 dts12 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 /* 
48  * ${name}_variables_oid:
49  *   this is the top level oid that we want to register under.  This
50  *   is essentially a prefix, with the suffix appearing in the
51  *   variable below.
52  */
53
54 oid ${name}_variables_oid[] = { $name.commaoid };
55
56 /* 
57  * variable4 ${name}_variables:
58  *   this variable defines function callbacks and type return information 
59  *   for the $outputName mib section 
60  */
61
62 struct variable4 ${name}_variables[] = {
63 /*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
64 @eval $magic = 0@
65 @foreach $i scalar@
66     @eval $magic = $magic + 1@
67 #define $i.uc           $magic
68     @if $i.settable@
69 {$i.uc,  $i.type,  RWRITE,  var_${name}, 1,  { $i.subid }},
70     @end@
71     @if !$i.settable@
72 {$i.uc,  $i.type,  RONLY ,  var_${name}, 1,  { $i.subid }},
73     @end@
74 @end@
75
76 @foreach $i table@
77  @foreach $c column@
78     @eval $magic = $magic + 1@
79 #define $c.uc           $magic
80     @if $c.settable@
81 {$c.uc,  $c.type,  RWRITE,  var_${i}, 3,  { $i.subid, 1, $c.subid }},
82     @end@
83     @if !$c.settable@
84 {$c.uc,  $c.type,  RONLY,   var_${i}, 3,  { $i.subid, 1, $c.subid }},
85     @end@
86  @end@
87 @end@
88 };
89 /*    (L = length of the oidsuffix) */
90
91
92 /** Initializes the $name module */
93 void
94 init_$name(void)
95 {
96
97     DEBUGMSGTL(("$name", "Initializing\n"));
98
99     /* register ourselves with the agent to handle our mib tree */
100     REGISTER_MIB("$name", ${name}_variables, variable4,
101                ${name}_variables_oid);
102
103     /* place any other initialization junk you need here */
104 }
105
106 /*
107  * var_$name():
108  *   This function is called every time the agent gets a request for
109  *   a scalar variable that might be found within your mib section
110  *   registered above.  It is up to you to do the right thing and
111  *   return the correct value.
112  *     You should also correct the value of "var_len" if necessary.
113  *
114  *   Please see the documentation for more information about writing
115  *   module extensions, and check out the examples in the examples
116  *   and mibII directories.
117  */
118 unsigned char *
119 var_$name(struct variable *vp, 
120                 oid     *name, 
121                 size_t  *length, 
122                 int     exact, 
123                 size_t  *var_len, 
124                 WriteMethod **write_method)
125 {
126     /* variables we may use later */
127     static long long_ret;
128     static u_long ulong_ret;
129     static unsigned char string[SPRINT_MAX_LEN];
130     static oid objid[MAX_OID_LEN];
131     static struct counter64 c64;
132
133     if (header_generic(vp,name,length,exact,var_len,write_method)
134                                   == MATCH_FAILED )
135     return NULL;
136
137     /* 
138    * this is where we do the value assignments for the mib results.
139    */
140     switch(vp->magic) {
141 @foreach $i scalar@
142     $i.uc:
143     @if $i.settable@
144         *write_method = write_${i};
145     @end@
146         VAR = VALUE;    /* XXX */
147         return (u_char*) &VAR;
148 @end@
149     default:
150       ERROR_MSG("");
151     }
152     return NULL;
153 }
154
155
156 @foreach $i table@
157 /*
158  * var_$i():
159  *   Handle this table separately from the scalar value case.
160  *   The workings of this are basically the same as for var_$outputName above.
161  */
162 unsigned char *
163 var_$i(struct variable *vp,
164             oid     *name,
165             size_t  *length,
166             int     exact,
167             size_t  *var_len,
168             WriteMethod **write_method)
169 {
170     /* variables we may use later */
171     static long long_ret;
172     static u_long ulong_ret;
173     static unsigned char string[SPRINT_MAX_LEN];
174     static oid objid[MAX_OID_LEN];
175     static struct counter64 c64;
176
177     /* 
178    * This assumes that the table is a 'simple' table.
179    *    See the implementation documentation for the meaning of this.
180    *    You will need to provide the correct value for the TABLE_SIZE parameter
181    *
182    * If this table does not meet the requirements for a simple table,
183    *    you will need to provide the replacement code yourself.
184    *    Mib2c is not smart enough to write this for you.
185    *    Again, see the implementation documentation for what is required.
186    */
187     if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
188                                                 == MATCH_FAILED )
189     return NULL;
190
191     /* 
192    * this is where we do the value assignments for the mib results.
193    */
194     switch(vp->magic) {
195 @foreach $c column@
196     $c.uc:
197     @if $c.settable@
198         *write_method = write_${c};
199     @end@
200         VAR = VALUE;    /* XXX */
201         return (u_char*) &VAR;
202 @end@
203     default:
204       ERROR_MSG("");
205     }
206     return NULL;
207 }
208 @end@
209
210 @foreach $i scalar@
211 @if $i.settable@
212
213
214 int
215 write_$i(int      action,
216             u_char   *var_val,
217             u_char   var_val_type,
218             size_t   var_val_len,
219             u_char   *statP,
220             oid      *name,
221             size_t   name_len)
222 {
223     $i.decl value;
224     int size;
225
226     switch ( action ) {
227         case RESERVE1:
228           if (var_val_type != $i.type) {
229               fprintf(stderr, "write to $name not $i.type\n");
230               return SNMP_ERR_WRONGTYPE;
231           }
232           if (var_val_len > sizeof($i.decl)) {
233               fprintf(stderr,"write to $name: bad length\n");
234               return SNMP_ERR_WRONGLENGTH;
235           }
236           break;
237
238         case RESERVE2:
239           size  = var_val_len;
240           value = * ($i.decl *) var_val;
241
242           break;
243
244         case FREE:
245              /* Release any resources that have been allocated */
246           break;
247
248         case ACTION:
249              /*
250               * The variable has been stored in 'value' for you to use,
251               * and you have just been asked to do something with it.
252               * Note that anything done here must be reversable in the UNDO case
253               */
254           break;
255
256         case UNDO:
257              /* Back out any changes made in the ACTION case */
258           break;
259
260         case COMMIT:
261              /*
262               * Things are working well, so it's now safe to make the change
263               * permanently.  Make sure that anything done here can't fail!
264               */
265           break;
266     }
267     return SNMP_ERR_NOERROR;
268 }
269 @end@
270 @end@
271
272 @foreach $i table@
273 @foreach $c column@
274 @if $c.settable@
275 int
276 write_$c(int      action,
277             u_char   *var_val,
278             u_char   var_val_type,
279             size_t   var_val_len,
280             u_char   *statP,
281             oid      *name,
282             size_t   name_len)
283 {
284     $c.decl value;
285     int size;
286
287     switch ( action ) {
288         case RESERVE1:
289           if (var_val_type != $c.type) {
290               fprintf(stderr, "write to $name not $c.type\n");
291               return SNMP_ERR_WRONGTYPE;
292           }
293           if (var_val_len > sizeof($c.decl)) {
294               fprintf(stderr,"write to $name: bad length\n");
295               return SNMP_ERR_WRONGLENGTH;
296           }
297           break;
298
299         case RESERVE2:
300           size  = var_val_len;
301           value = * ($c.decl *) var_val;
302
303           break;
304
305         case FREE:
306              /* Release any resources that have been allocated */
307           break;
308
309         case ACTION:
310              /*
311               * The variable has been stored in 'value' for you to use,
312               * and you have just been asked to do something with it.
313               * Note that anything done here must be reversable in the UNDO case
314               */
315           break;
316
317         case UNDO:
318              /* Back out any changes made in the ACTION case */
319           break;
320
321         case COMMIT:
322              /*
323               * Things are working well, so it's now safe to make the change
324               * permanently.  Make sure that anything done here can't fail!
325               */
326           break;
327     }
328     return SNMP_ERR_NOERROR;
329 }
330 @end@
331 @end@
332 @end@