~ubuntu-branches/debian/lenny/net-snmp/lenny

« back to all changes in this revision

Viewing changes to agent/mibgroup/disman/event/mteTriggerDeltaTable.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-10 22:20:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070510222023-3fr07xb9i17xvq32
Tags: upstream-5.3.1
ImportĀ upstreamĀ versionĀ 5.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DisMan Event MIB:
 
3
 *     Implementation of the mteTriggerDeltaTable MIB interface
 
4
 * See 'mteTrigger.c' for active behaviour of this table.
 
5
 *
 
6
 * (based on mib2c.table_data.conf output)
 
7
 */
 
8
 
 
9
#include <net-snmp/net-snmp-config.h>
 
10
#include <net-snmp/net-snmp-includes.h>
 
11
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
12
#include "disman/event/mteTrigger.h"
 
13
#include "disman/event/mteTriggerDeltaTable.h"
 
14
 
 
15
 
 
16
/** Initializes the mteTriggerDeltaTable module */
 
17
void
 
18
init_mteTriggerDeltaTable(void)
 
19
{
 
20
    static oid  mteTDeltaTable_oid[]   = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 3 };
 
21
    size_t      mteTDeltaTable_oid_len = OID_LENGTH(mteTDeltaTable_oid);
 
22
    netsnmp_handler_registration    *reg;
 
23
    netsnmp_table_registration_info *table_info;
 
24
 
 
25
    /*
 
26
     * Ensure the (combined) table container is available...
 
27
     */
 
28
    init_trigger_table_data();
 
29
 
 
30
    /*
 
31
     * ... then set up the MIB interface to the mteTriggerDeltaTable slice
 
32
     */
 
33
    reg = netsnmp_create_handler_registration("mteTriggerDeltaTable",
 
34
                                            mteTriggerDeltaTable_handler,
 
35
                                            mteTDeltaTable_oid,
 
36
                                            mteTDeltaTable_oid_len,
 
37
                                            HANDLER_CAN_RWRITE);
 
38
 
 
39
    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
 
40
    netsnmp_table_helper_add_indexes(table_info,
 
41
                                     ASN_OCTET_STR, /* index: mteOwner       */
 
42
                                                    /* index: mteTriggerName */
 
43
                                     ASN_PRIV_IMPLIED_OCTET_STR,
 
44
                                     0);
 
45
 
 
46
    table_info->min_column = COLUMN_MTETRIGGERDELTADISCONTINUITYID;
 
47
    table_info->max_column = COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE;
 
48
 
 
49
    /* Register this using the (common) trigger_table_data container */
 
50
    netsnmp_tdata_register(reg, trigger_table_data, table_info);
 
51
    DEBUGMSGTL(("disman:event:init", "Trigger Delta Table\n"));
 
52
}
 
53
 
 
54
 
 
55
/** handles requests for the mteTriggerDeltaTable table */
 
56
int
 
57
mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
 
58
                             netsnmp_handler_registration *reginfo,
 
59
                             netsnmp_agent_request_info *reqinfo,
 
60
                             netsnmp_request_info *requests)
 
61
{
 
62
 
 
63
    netsnmp_request_info       *request;
 
64
    netsnmp_table_request_info *tinfo;
 
65
    struct mteTrigger          *entry;
 
66
    int ret;
 
67
 
 
68
    DEBUGMSGTL(("disman:event:mib", "Delta Table handler (%d)\n",
 
69
                                     reqinfo->mode));
 
70
 
 
71
    switch (reqinfo->mode) {
 
72
        /*
 
73
         * Read-support (also covers GetNext requests)
 
74
         */
 
75
    case MODE_GET:
 
76
        for (request = requests; request; request = request->next) {
 
77
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
78
            tinfo = netsnmp_extract_table_info(request);
 
79
 
 
80
            /*
 
81
             * The mteTriggerBooleanTable should only contains entries for
 
82
             *   rows where the mteTriggerSampleType is 'deltaValue(2)'
 
83
             * So skip entries where this isn't the case.
 
84
             */
 
85
            if (!entry || !(entry->flags & MTE_TRIGGER_FLAG_DELTA ))
 
86
                continue;
 
87
 
 
88
            switch (tinfo->colnum) {
 
89
            case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
 
90
                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
 
91
                              (u_char *) entry->mteDeltaDiscontID,
 
92
                                         entry->mteDeltaDiscontID_len*sizeof(oid));
 
93
                break;
 
94
            case COLUMN_MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
 
95
                ret = (entry->flags & MTE_TRIGGER_FLAG_DWILD ) ?
 
96
                           TV_TRUE : TV_FALSE;
 
97
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
 
98
                break;
 
99
            case COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE:
 
100
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
 
101
                                           entry->mteDeltaDiscontIDType);
 
102
                break;
 
103
            }
 
104
        }
 
105
        break;
 
106
 
 
107
        /*
 
108
         * Write-support
 
109
         */
 
110
    case MODE_SET_RESERVE1:
 
111
        for (request = requests; request; request = request->next) {
 
112
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
113
            tinfo = netsnmp_extract_table_info(request);
 
114
 
 
115
            /*
 
116
             * Since the mteTriggerDeltaTable only contains entries for
 
117
             *   rows where mteTriggerSampleType is 'deltaValue(2)',
 
118
             *   strictly speaking we should reject assignments where
 
119
             *   this isn't the case.
 
120
             * But SET requests that include an assignment of
 
121
             *   'deltaValue(2)' at the same time are valid, so would
 
122
             *    need to be accepted. Unfortunately, this assignment
 
123
             *   is only applied in the COMMIT pass, so it's difficult
 
124
             *   to detect whether this holds or not.
 
125
             *
 
126
             * Let's fudge things for now, by processing
 
127
             *   assignments even if this value isn't set.
 
128
             */
 
129
            switch (tinfo->colnum) {
 
130
            case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
 
131
                ret = netsnmp_check_vb_oid(request->requestvb);
 
132
                if (ret != SNMP_ERR_NOERROR) {
 
133
                    netsnmp_set_request_error(reqinfo, request, ret);
 
134
                    return SNMP_ERR_NOERROR;
 
135
                }
 
136
                break;
 
137
            case COLUMN_MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
 
138
                ret = netsnmp_check_vb_truthvalue(request->requestvb);
 
139
                if (ret != SNMP_ERR_NOERROR) {
 
140
                    netsnmp_set_request_error(reqinfo, request, ret);
 
141
                    return SNMP_ERR_NOERROR;
 
142
                }
 
143
                break;
 
144
            case COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE:
 
145
                ret = netsnmp_check_vb_int_range(request->requestvb,
 
146
                                                 MTE_DELTAD_TTICKS,
 
147
                                                 MTE_DELTAD_DATETIME);
 
148
                if (ret != SNMP_ERR_NOERROR) {
 
149
                    netsnmp_set_request_error(reqinfo, request, ret);
 
150
                    return SNMP_ERR_NOERROR;
 
151
                }
 
152
                break;
 
153
            default:
 
154
                netsnmp_set_request_error(reqinfo, request,
 
155
                                          SNMP_ERR_NOTWRITABLE);
 
156
                return SNMP_ERR_NOERROR;
 
157
            }
 
158
 
 
159
            /*
 
160
             * The Event MIB is somewhat ambiguous as to whether the
 
161
             *  various trigger table entries can be modified once the
 
162
             *  main mteTriggerTable entry has been marked 'active'. 
 
163
             * But it's clear from discussion on the DisMan mailing
 
164
             *  list is that the intention is not.
 
165
             *
 
166
             * So check for whether this row is already active,
 
167
             *  and reject *all* SET requests if it is.
 
168
             */
 
169
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
170
            if (entry &&
 
171
                entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) {
 
172
                netsnmp_set_request_error(reqinfo, request,
 
173
                                          SNMP_ERR_INCONSISTENTVALUE);
 
174
                return SNMP_ERR_NOERROR;
 
175
            }
 
176
        }
 
177
        break;
 
178
 
 
179
    case MODE_SET_RESERVE2:
 
180
    case MODE_SET_FREE:
 
181
    case MODE_SET_UNDO:
 
182
        break;
 
183
 
 
184
    case MODE_SET_ACTION:
 
185
        for (request = requests; request; request = request->next) {
 
186
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
187
            if (!entry) {
 
188
                /*
 
189
                 * New rows must be created via the RowStatus column
 
190
                 *   (in the main mteTriggerTable)
 
191
                 */
 
192
                netsnmp_set_request_error(reqinfo, request,
 
193
                                          SNMP_ERR_NOCREATION);
 
194
                                      /* or inconsistentName? */
 
195
                return SNMP_ERR_NOERROR;
 
196
            }
 
197
        }
 
198
        break;
 
199
 
 
200
    case MODE_SET_COMMIT:
 
201
        /*
 
202
         * All these assignments are "unfailable", so it's
 
203
         *  (reasonably) safe to apply them in the Commit phase
 
204
         */
 
205
        for (request = requests; request; request = request->next) {
 
206
            entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
 
207
            tinfo = netsnmp_extract_table_info(request);
 
208
 
 
209
            switch (tinfo->colnum) {
 
210
            case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
 
211
                if ( snmp_oid_compare(
 
212
                       request->requestvb->val.objid,
 
213
                       request->requestvb->val_len/sizeof(oid),
 
214
                       _sysUpTime_instance, _sysUpTime_inst_len) != 0 ) {
 
215
                    memset(entry->mteDeltaDiscontID, 0,
 
216
                           sizeof(entry->mteDeltaDiscontID));
 
217
                    memcpy(entry->mteDeltaDiscontID,
 
218
                           request->requestvb->val.string,
 
219
                           request->requestvb->val_len);
 
220
                    entry->mteDeltaDiscontID_len =
 
221
                        request->requestvb->val_len/sizeof(oid);
 
222
                    entry->flags &= ~MTE_TRIGGER_FLAG_SYSUPT;
 
223
                }
 
224
                break;
 
225
            case COLUMN_MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
 
226
                if (*request->requestvb->val.integer == TV_TRUE)
 
227
                    entry->flags |=  MTE_TRIGGER_FLAG_DWILD;
 
228
                else
 
229
                    entry->flags &= ~MTE_TRIGGER_FLAG_DWILD;
 
230
                break;
 
231
            case COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE:
 
232
                entry->mteDeltaDiscontIDType = *request->requestvb->val.integer;
 
233
                break;
 
234
            }
 
235
        }
 
236
        break;
 
237
    }
 
238
    return SNMP_ERR_NOERROR;
 
239
}