Imported Upstream version 0.4.8
[platform/upstream/libsmi.git] / test / dumps / netsnmp / snmpv2-mib-agt-stub.c
1 /*
2  * This C file has been generated by smidump 0.4.2-pre1.
3  * It is intended to be used with the NET-SNMP agent library.
4  *
5  * This C file is derived from the SNMPv2-MIB module.
6  *
7  * $Id: snmpv2-mib-agt-stub.c 1606 2003-12-01 12:24:15Z strauss $
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <malloc.h>
13
14 #include "snmpv2-mib.h"
15
16 #include <ucd-snmp/asn1.h>
17 #include <ucd-snmp/snmp.h>
18 #include <ucd-snmp/snmp_api.h>
19 #include <ucd-snmp/snmp_impl.h>
20 #include <ucd-snmp/snmp_vars.h>
21
22 /*
23  * Forward declaration of read methods for groups of scalars and tables:
24  */
25
26 static unsigned char *
27 read_system_stub(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);
28 static unsigned char *
29 read_sysOREntry_stub(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);
30 static unsigned char *
31 read_snmp_stub(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);
32 static unsigned char *
33 read_snmpSet_stub(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);
34
35 /*
36  * Forward declaration of write methods for writable objects:
37  */
38
39 static int
40 write_sysContact_stub(int, u_char *, u_char, int, u_char *, oid *, int);
41 static int
42 write_sysName_stub(int, u_char *, u_char, int, u_char *, oid *, int);
43 static int
44 write_sysLocation_stub(int, u_char *, u_char, int, u_char *, oid *, int);
45 static int
46 write_snmpEnableAuthenTraps_stub(int, u_char *, u_char, int, u_char *, oid *, int);
47 static int
48 write_snmpSetSerialNo_stub(int, u_char *, u_char, int, u_char *, oid *, int);
49
50 /*
51  * Definitions of tags that are used internally to read/write
52  * the selected object type. These tags should be unique.
53  */
54
55 #define SYSDESCR                         1
56 #define SYSOBJECTID                      2
57 #define SYSUPTIME                        3
58 #define SYSCONTACT                       4
59 #define SYSNAME                          5
60 #define SYSLOCATION                      6
61 #define SYSSERVICES                      7
62 #define SYSORLASTCHANGE                  8
63
64 static oid system_base[] = {1, 3, 6, 1, 2, 1, 1};
65
66 struct variable system_variables[] = {
67     { SYSDESCR, ASN_OCTET_STR, RONLY, read_system_stub, 1, {1} },
68     { SYSOBJECTID, ASN_OBJECT_ID, RONLY, read_system_stub, 1, {2} },
69     { SYSUPTIME, ASN_INTEGER, RONLY, read_system_stub, 1, {3} },
70     { SYSCONTACT, ASN_OCTET_STR, RWRITE, read_system_stub, 1, {4} },
71     { SYSNAME, ASN_OCTET_STR, RWRITE, read_system_stub, 1, {5} },
72     { SYSLOCATION, ASN_OCTET_STR, RWRITE, read_system_stub, 1, {6} },
73     { SYSSERVICES, ASN_INTEGER, RONLY, read_system_stub, 1, {7} },
74     { SYSORLASTCHANGE, ASN_INTEGER, RONLY, read_system_stub, 1, {8} },
75 };
76
77 #define SYSORID                          2
78 #define SYSORDESCR                       3
79 #define SYSORUPTIME                      4
80
81 static oid sysOREntry_base[] = {1, 3, 6, 1, 2, 1, 1, 9, 1};
82
83 struct variable sysOREntry_variables[] = {
84     { SYSORID, ASN_OBJECT_ID, RONLY, read_sysOREntry_stub, 1, {2} },
85     { SYSORDESCR, ASN_OCTET_STR, RONLY, read_sysOREntry_stub, 1, {3} },
86     { SYSORUPTIME, ASN_INTEGER, RONLY, read_sysOREntry_stub, 1, {4} },
87 };
88
89 #define SNMPINPKTS                       1
90 #define SNMPOUTPKTS                      2
91 #define SNMPINBADVERSIONS                3
92 #define SNMPINBADCOMMUNITYNAMES          4
93 #define SNMPINBADCOMMUNITYUSES           5
94 #define SNMPINASNPARSEERRS               6
95 #define SNMPINTOOBIGS                    8
96 #define SNMPINNOSUCHNAMES                9
97 #define SNMPINBADVALUES                  10
98 #define SNMPINREADONLYS                  11
99 #define SNMPINGENERRS                    12
100 #define SNMPINTOTALREQVARS               13
101 #define SNMPINTOTALSETVARS               14
102 #define SNMPINGETREQUESTS                15
103 #define SNMPINGETNEXTS                   16
104 #define SNMPINSETREQUESTS                17
105 #define SNMPINGETRESPONSES               18
106 #define SNMPINTRAPS                      19
107 #define SNMPOUTTOOBIGS                   20
108 #define SNMPOUTNOSUCHNAMES               21
109 #define SNMPOUTBADVALUES                 22
110 #define SNMPOUTGENERRS                   24
111 #define SNMPOUTGETREQUESTS               25
112 #define SNMPOUTGETNEXTS                  26
113 #define SNMPOUTSETREQUESTS               27
114 #define SNMPOUTGETRESPONSES              28
115 #define SNMPOUTTRAPS                     29
116 #define SNMPENABLEAUTHENTRAPS            30
117 #define SNMPSILENTDROPS                  31
118 #define SNMPPROXYDROPS                   32
119
120 static oid snmp_base[] = {1, 3, 6, 1, 2, 1, 11};
121
122 struct variable snmp_variables[] = {
123     { SNMPINPKTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {1} },
124     { SNMPOUTPKTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {2} },
125     { SNMPINBADVERSIONS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {3} },
126     { SNMPINBADCOMMUNITYNAMES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {4} },
127     { SNMPINBADCOMMUNITYUSES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {5} },
128     { SNMPINASNPARSEERRS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {6} },
129     { SNMPINTOOBIGS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {8} },
130     { SNMPINNOSUCHNAMES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {9} },
131     { SNMPINBADVALUES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {10} },
132     { SNMPINREADONLYS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {11} },
133     { SNMPINGENERRS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {12} },
134     { SNMPINTOTALREQVARS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {13} },
135     { SNMPINTOTALSETVARS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {14} },
136     { SNMPINGETREQUESTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {15} },
137     { SNMPINGETNEXTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {16} },
138     { SNMPINSETREQUESTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {17} },
139     { SNMPINGETRESPONSES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {18} },
140     { SNMPINTRAPS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {19} },
141     { SNMPOUTTOOBIGS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {20} },
142     { SNMPOUTNOSUCHNAMES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {21} },
143     { SNMPOUTBADVALUES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {22} },
144     { SNMPOUTGENERRS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {24} },
145     { SNMPOUTGETREQUESTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {25} },
146     { SNMPOUTGETNEXTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {26} },
147     { SNMPOUTSETREQUESTS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {27} },
148     { SNMPOUTGETRESPONSES, ASN_INTEGER, RONLY, read_snmp_stub, 1, {28} },
149     { SNMPOUTTRAPS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {29} },
150     { SNMPENABLEAUTHENTRAPS, ASN_INTEGER, RWRITE, read_snmp_stub, 1, {30} },
151     { SNMPSILENTDROPS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {31} },
152     { SNMPPROXYDROPS, ASN_INTEGER, RONLY, read_snmp_stub, 1, {32} },
153 };
154
155
156 #define SNMPSETSERIALNO                  1
157
158 static oid snmpSet_base[] = {1, 3, 6, 1, 6, 3, 1, 1, 6};
159
160 struct variable snmpSet_variables[] = {
161     { SNMPSETSERIALNO, ASN_INTEGER, RWRITE, read_snmpSet_stub, 1, {1} },
162 };
163
164
165
166 /*
167  * Registration functions for the various MIB groups.
168  */
169
170 int register_system()
171 {
172     return register_mib("system",
173          system_variables,
174          sizeof(struct variable),
175          sizeof(system_variables)/sizeof(struct variable),
176          system_base,
177          sizeof(system_base)/sizeof(oid));
178 };
179
180
181 int register_sysOREntry()
182 {
183     return register_mib("sysOREntry",
184          sysOREntry_variables,
185          sizeof(struct variable),
186          sizeof(sysOREntry_variables)/sizeof(struct variable),
187          sysOREntry_base,
188          sizeof(sysOREntry_base)/sizeof(oid));
189 };
190
191
192 int register_snmp()
193 {
194     return register_mib("snmp",
195          snmp_variables,
196          sizeof(struct variable),
197          sizeof(snmp_variables)/sizeof(struct variable),
198          snmp_base,
199          sizeof(snmp_base)/sizeof(oid));
200 };
201
202
203 int register_snmpTrap()
204 {
205     return register_mib("snmpTrap",
206          snmpTrap_variables,
207          sizeof(struct variable),
208          sizeof(snmpTrap_variables)/sizeof(struct variable),
209          snmpTrap_base,
210          sizeof(snmpTrap_base)/sizeof(oid));
211 };
212
213
214 int register_snmpSet()
215 {
216     return register_mib("snmpSet",
217          snmpSet_variables,
218          sizeof(struct variable),
219          sizeof(snmpSet_variables)/sizeof(struct variable),
220          snmpSet_base,
221          sizeof(snmpSet_base)/sizeof(oid));
222 };
223
224
225 /*
226  * Read methods for groups of scalars and tables:
227  */
228
229 static unsigned char *
230 read_system_stub(struct variable *vp,
231     oid     *name,
232     size_t  *length,
233     int     exact,
234     size_t  *var_len,
235     WriteMethod **write_method)
236 {
237     static system_t system;
238
239     /* check whether the instance identifier is valid */
240
241     if (header_generic(vp, name, length, exact, var_len,
242                        write_method) == MATCH_FAILED) {
243         return NULL;
244     }
245
246     /* call the user supplied function to retrieve values */
247
248     read_system(&system);
249
250     /* return the current value of the variable */
251
252     switch (vp->magic) {
253
254     case SYSDESCR:
255         *var_len = system._sysDescrLength;
256         return (unsigned char *) system.sysDescr;
257
258     case SYSOBJECTID:
259         *var_len = system._sysObjectIDLength;
260         return (unsigned char *) system.sysObjectID;
261
262     case SYSUPTIME:
263         return (unsigned char *) &system.sysUpTime;
264
265     case SYSCONTACT:
266         *var_len = system._sysContactLength;
267         return (unsigned char *) system.sysContact;
268
269     case SYSNAME:
270         *var_len = system._sysNameLength;
271         return (unsigned char *) system.sysName;
272
273     case SYSLOCATION:
274         *var_len = system._sysLocationLength;
275         return (unsigned char *) system.sysLocation;
276
277     case SYSSERVICES:
278         return (unsigned char *) &system.sysServices;
279
280     case SYSORLASTCHANGE:
281         return (unsigned char *) &system.sysORLastChange;
282
283     default:
284          ERROR_MSG("");
285     }
286
287     return NULL;
288 }
289
290 static unsigned char *
291 read_sysOREntry_stub(struct variable *vp,
292     oid     *name,
293     size_t  *length,
294     int     exact,
295     size_t  *var_len,
296     WriteMethod **write_method)
297 {
298     static sysOREntry_t sysOREntry;
299
300     /* call the user supplied function to retrieve values */
301
302     read_sysOREntry(&sysOREntry);
303
304     /* return the current value of the variable */
305
306     switch (vp->magic) {
307
308     case SYSORID:
309         *var_len = sysOREntry._sysORIDLength;
310         return (unsigned char *) sysOREntry.sysORID;
311
312     case SYSORDESCR:
313         *var_len = sysOREntry._sysORDescrLength;
314         return (unsigned char *) sysOREntry.sysORDescr;
315
316     case SYSORUPTIME:
317         return (unsigned char *) &sysOREntry.sysORUpTime;
318
319     default:
320          ERROR_MSG("");
321     }
322
323     return NULL;
324 }
325
326 static unsigned char *
327 read_snmp_stub(struct variable *vp,
328     oid     *name,
329     size_t  *length,
330     int     exact,
331     size_t  *var_len,
332     WriteMethod **write_method)
333 {
334     static snmp_t snmp;
335
336     /* check whether the instance identifier is valid */
337
338     if (header_generic(vp, name, length, exact, var_len,
339                        write_method) == MATCH_FAILED) {
340         return NULL;
341     }
342
343     /* call the user supplied function to retrieve values */
344
345     read_snmp(&snmp);
346
347     /* return the current value of the variable */
348
349     switch (vp->magic) {
350
351     case SNMPINPKTS:
352         return (unsigned char *) &snmp.snmpInPkts;
353
354     case SNMPOUTPKTS:
355         return (unsigned char *) &snmp.snmpOutPkts;
356
357     case SNMPINBADVERSIONS:
358         return (unsigned char *) &snmp.snmpInBadVersions;
359
360     case SNMPINBADCOMMUNITYNAMES:
361         return (unsigned char *) &snmp.snmpInBadCommunityNames;
362
363     case SNMPINBADCOMMUNITYUSES:
364         return (unsigned char *) &snmp.snmpInBadCommunityUses;
365
366     case SNMPINASNPARSEERRS:
367         return (unsigned char *) &snmp.snmpInASNParseErrs;
368
369     case SNMPINTOOBIGS:
370         return (unsigned char *) &snmp.snmpInTooBigs;
371
372     case SNMPINNOSUCHNAMES:
373         return (unsigned char *) &snmp.snmpInNoSuchNames;
374
375     case SNMPINBADVALUES:
376         return (unsigned char *) &snmp.snmpInBadValues;
377
378     case SNMPINREADONLYS:
379         return (unsigned char *) &snmp.snmpInReadOnlys;
380
381     case SNMPINGENERRS:
382         return (unsigned char *) &snmp.snmpInGenErrs;
383
384     case SNMPINTOTALREQVARS:
385         return (unsigned char *) &snmp.snmpInTotalReqVars;
386
387     case SNMPINTOTALSETVARS:
388         return (unsigned char *) &snmp.snmpInTotalSetVars;
389
390     case SNMPINGETREQUESTS:
391         return (unsigned char *) &snmp.snmpInGetRequests;
392
393     case SNMPINGETNEXTS:
394         return (unsigned char *) &snmp.snmpInGetNexts;
395
396     case SNMPINSETREQUESTS:
397         return (unsigned char *) &snmp.snmpInSetRequests;
398
399     case SNMPINGETRESPONSES:
400         return (unsigned char *) &snmp.snmpInGetResponses;
401
402     case SNMPINTRAPS:
403         return (unsigned char *) &snmp.snmpInTraps;
404
405     case SNMPOUTTOOBIGS:
406         return (unsigned char *) &snmp.snmpOutTooBigs;
407
408     case SNMPOUTNOSUCHNAMES:
409         return (unsigned char *) &snmp.snmpOutNoSuchNames;
410
411     case SNMPOUTBADVALUES:
412         return (unsigned char *) &snmp.snmpOutBadValues;
413
414     case SNMPOUTGENERRS:
415         return (unsigned char *) &snmp.snmpOutGenErrs;
416
417     case SNMPOUTGETREQUESTS:
418         return (unsigned char *) &snmp.snmpOutGetRequests;
419
420     case SNMPOUTGETNEXTS:
421         return (unsigned char *) &snmp.snmpOutGetNexts;
422
423     case SNMPOUTSETREQUESTS:
424         return (unsigned char *) &snmp.snmpOutSetRequests;
425
426     case SNMPOUTGETRESPONSES:
427         return (unsigned char *) &snmp.snmpOutGetResponses;
428
429     case SNMPOUTTRAPS:
430         return (unsigned char *) &snmp.snmpOutTraps;
431
432     case SNMPENABLEAUTHENTRAPS:
433         return (unsigned char *) &snmp.snmpEnableAuthenTraps;
434
435     case SNMPSILENTDROPS:
436         return (unsigned char *) &snmp.snmpSilentDrops;
437
438     case SNMPPROXYDROPS:
439         return (unsigned char *) &snmp.snmpProxyDrops;
440
441     default:
442          ERROR_MSG("");
443     }
444
445     return NULL;
446 }
447
448 static unsigned char *
449 read_snmpSet_stub(struct variable *vp,
450     oid     *name,
451     size_t  *length,
452     int     exact,
453     size_t  *var_len,
454     WriteMethod **write_method)
455 {
456     static snmpSet_t snmpSet;
457
458     /* check whether the instance identifier is valid */
459
460     if (header_generic(vp, name, length, exact, var_len,
461                        write_method) == MATCH_FAILED) {
462         return NULL;
463     }
464
465     /* call the user supplied function to retrieve values */
466
467     read_snmpSet(&snmpSet);
468
469     /* return the current value of the variable */
470
471     switch (vp->magic) {
472
473     case SNMPSETSERIALNO:
474         return (unsigned char *) &snmpSet.snmpSetSerialNo;
475
476     default:
477          ERROR_MSG("");
478     }
479
480     return NULL;
481 }
482
483
484 /*
485  * Forward declaration of write methods for writable objects:
486  */
487
488 static int
489 write_sysContact_stub(int action,
490     u_char   *var_val,
491     u_char   var_val_type,
492     int      var_val_len,
493     u_char   *statP,
494     oid      *name,
495     int      name_len)
496 {
497     return SNMP_ERR_NOERROR;
498 }
499
500 static int
501 write_sysName_stub(int action,
502     u_char   *var_val,
503     u_char   var_val_type,
504     int      var_val_len,
505     u_char   *statP,
506     oid      *name,
507     int      name_len)
508 {
509     return SNMP_ERR_NOERROR;
510 }
511
512 static int
513 write_sysLocation_stub(int action,
514     u_char   *var_val,
515     u_char   var_val_type,
516     int      var_val_len,
517     u_char   *statP,
518     oid      *name,
519     int      name_len)
520 {
521     return SNMP_ERR_NOERROR;
522 }
523
524 static int
525 write_snmpEnableAuthenTraps_stub(int action,
526     u_char   *var_val,
527     u_char   var_val_type,
528     int      var_val_len,
529     u_char   *statP,
530     oid      *name,
531     int      name_len)
532 {
533     return SNMP_ERR_NOERROR;
534 }
535
536 static int
537 write_snmpSetSerialNo_stub(int action,
538     u_char   *var_val,
539     u_char   var_val_type,
540     int      var_val_len,
541     u_char   *statP,
542     oid      *name,
543     int      name_len)
544 {
545     return SNMP_ERR_NOERROR;
546 }
547
548