~ubuntu-branches/ubuntu/gutsy/net-snmp/gutsy-security

« back to all changes in this revision

Viewing changes to local/mib2c.scalar.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.scalar.conf,v 1.7 2003/04/08 14:57:04 dts12 Exp $
 
9
 */
 
10
#ifndef $name.uc_H
 
11
#define $name.uc_H
 
12
 
 
13
/* function declarations */
 
14
void init_$name(void);
 
15
@foreach $i scalar@
 
16
Netsnmp_Node_Handler handle_${i};
 
17
@end@
 
18
 
 
19
#endif /* $name.uc_H */
 
20
######################################################################
 
21
## Do the .c file
 
22
######################################################################
 
23
@open ${name}.c@
 
24
/*
 
25
 * Note: this file originally auto-generated by mib2c using
 
26
 *        $Id: mib2c.scalar.conf,v 1.7 2003/04/08 14:57:04 dts12 Exp $
 
27
 */
 
28
 
 
29
#include <net-snmp/net-snmp-config.h>
 
30
#include <net-snmp/net-snmp-includes.h>
 
31
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
32
#include "${name}.h"
 
33
 
 
34
/** Initializes the $name module */
 
35
void
 
36
init_$name(void)
 
37
{
 
38
  @foreach $i scalar@
 
39
    static oid ${i}_oid[] = { $i.commaoid };
 
40
  @end@
 
41
 
 
42
  DEBUGMSGTL(("$name", "Initializing\n"));
 
43
 
 
44
  @foreach $i scalar@
 
45
    netsnmp_register_scalar(
 
46
        netsnmp_create_handler_registration("$i", handle_$i,
 
47
                               ${i}_oid, OID_LENGTH(${i}_oid),
 
48
    @if !$i.settable@
 
49
                               HANDLER_CAN_RONLY
 
50
    @end@
 
51
    @if $i.settable@
 
52
                               HANDLER_CAN_RWRITE
 
53
    @end@
 
54
        ));
 
55
  @end@
 
56
}
 
57
 
 
58
@foreach $i scalar@
 
59
int
 
60
handle_$i(netsnmp_mib_handler *handler,
 
61
                          netsnmp_handler_registration *reginfo,
 
62
                          netsnmp_agent_request_info   *reqinfo,
 
63
                          netsnmp_request_info         *requests)
 
64
{
 
65
    /* We are never called for a GETNEXT if it's registered as a
 
66
       "instance", as it's "magically" handled for us.  */
 
67
 
 
68
    /* a instance handler also only hands us one request at a time, so
 
69
       we don't need to loop over a list of requests; we'll only get one. */
 
70
    
 
71
    switch(reqinfo->mode) {
 
72
 
 
73
        case MODE_GET:
 
74
            snmp_set_var_typed_value(requests->requestvb, $i.type,
 
75
                                     (u_char *) /* XXX: a pointer to the scalar's data */,
 
76
                                     /* XXX: the length of the data in bytes */);
 
77
            break;
 
78
 
 
79
        @if $i.settable@
 
80
        /*
 
81
         * SET REQUEST
 
82
         *
 
83
         * multiple states in the transaction.  See:
 
84
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
 
85
         */
 
86
        case MODE_SET_RESERVE1:
 
87
            if (/* XXX: check incoming data in requests->requestvb->val.XXX for failures, like an incorrect type or an illegal value or ... */) {
 
88
                netsnmp_set_request_error(reqinfo, requests, /* XXX: set error code depending on problem (like SNMP_ERR_WRONGTYPE or SNMP_ERR_WRONGVALUE or ... */);
 
89
            }
 
90
            break;
 
91
 
 
92
        case MODE_SET_RESERVE2:
 
93
            /* XXX malloc "undo" storage buffer */
 
94
            if (/* XXX if malloc, or whatever, failed: */) {
 
95
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
 
96
            }
 
97
            break;
 
98
 
 
99
        case MODE_SET_FREE:
 
100
            /* XXX: free resources allocated in RESERVE1 and/or
 
101
               RESERVE2.  Something failed somewhere, and the states
 
102
               below won't be called. */
 
103
            break;
 
104
 
 
105
        case MODE_SET_ACTION:
 
106
            /* XXX: perform the value change here */
 
107
            if (/* XXX: error? */) {
 
108
                netsnmp_set_request_error(reqinfo, requests, /* some error */);
 
109
            }
 
110
            break;
 
111
 
 
112
        case MODE_SET_COMMIT:
 
113
            /* XXX: delete temporary storage */
 
114
            if (/* XXX: error? */) {
 
115
                /* try _really_really_ hard to never get to this point */
 
116
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
 
117
            }
 
118
            break;
 
119
 
 
120
        case MODE_SET_UNDO:
 
121
            /* XXX: UNDO and return to previous value for the object */
 
122
            if (/* XXX: error? */) {
 
123
                /* try _really_really_ hard to never get to this point */
 
124
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
 
125
            }
 
126
            break;
 
127
        @end@
 
128
 
 
129
        default:
 
130
            /* we should never get here, so this is a really bad error */
 
131
            return SNMP_ERR_GENERR;
 
132
    }
 
133
 
 
134
    return SNMP_ERR_NOERROR;
 
135
}
 
136
@end@