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

« back to all changes in this revision

Viewing changes to agent/mibgroup/disman/event/mteObjectsTable.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 mteObjectsTable MIB interface
 
4
 * See 'mteObjects.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/mteObjects.h"
 
13
#include "disman/event/mteObjectsTable.h"
 
14
 
 
15
/** Initializes the mteObjectsTable module */
 
16
void
 
17
init_mteObjectsTable(void)
 
18
 
 
19
{
 
20
    static oid mteObjectsTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 3, 1 };
 
21
    size_t     mteObjectsTable_oid_len = OID_LENGTH(mteObjectsTable_oid);
 
22
    netsnmp_handler_registration    *reg;
 
23
    netsnmp_table_registration_info *table_info;
 
24
 
 
25
    /*
 
26
     * Ensure the object table container is available...
 
27
     */
 
28
    init_objects_table_data();
 
29
 
 
30
    /*
 
31
     * ... then set up the MIB interface to this table
 
32
     */
 
33
    reg = netsnmp_create_handler_registration("mteObjectsTable",
 
34
                                            mteObjectsTable_handler,
 
35
                                            mteObjectsTable_oid,
 
36
                                            mteObjectsTable_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
                                     ASN_OCTET_STR, /* index: mteObjectsName */
 
43
                                     ASN_UNSIGNED,  /* index: mteObjectsIndex */
 
44
                                     0);
 
45
 
 
46
    table_info->min_column = COLUMN_MTEOBJECTSID;
 
47
    table_info->max_column = COLUMN_MTEOBJECTSENTRYSTATUS;
 
48
 
 
49
 
 
50
    netsnmp_tdata_register(reg, objects_table_data, table_info);
 
51
}
 
52
 
 
53
 
 
54
/** handles requests for the mteObjectsTable table */
 
55
int
 
56
mteObjectsTable_handler(netsnmp_mib_handler *handler,
 
57
                        netsnmp_handler_registration *reginfo,
 
58
                        netsnmp_agent_request_info *reqinfo,
 
59
                        netsnmp_request_info *requests)
 
60
{
 
61
 
 
62
    netsnmp_request_info       *request;
 
63
    netsnmp_table_request_info *tinfo;
 
64
    netsnmp_tdata_row          *row;
 
65
    struct mteObject           *entry;
 
66
    char mteOwner[MTE_STR1_LEN+1];
 
67
    char mteOName[MTE_STR1_LEN+1];
 
68
    long ret;
 
69
 
 
70
    DEBUGMSGTL(("disman:event:mib", "ObjTable handler (%d)\n", reqinfo->mode));
 
71
 
 
72
    switch (reqinfo->mode) {
 
73
        /*
 
74
         * Read-support (also covers GetNext requests)
 
75
         */
 
76
    case MODE_GET:
 
77
        for (request = requests; request; request = request->next) {
 
78
            entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
 
79
            tinfo = netsnmp_extract_table_info(request);
 
80
 
 
81
            switch (tinfo->colnum) {
 
82
            case COLUMN_MTEOBJECTSID:
 
83
                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
 
84
                              (u_char *) entry->mteObjectID,
 
85
                                         entry->mteObjectID_len*sizeof(oid));
 
86
                break;
 
87
            case COLUMN_MTEOBJECTSIDWILDCARD:
 
88
                ret = (entry->flags & MTE_OBJECT_FLAG_WILD ) ?
 
89
                           TV_TRUE : TV_FALSE;
 
90
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
 
91
                break;
 
92
            case COLUMN_MTEOBJECTSENTRYSTATUS:
 
93
                ret = (entry->flags & MTE_OBJECT_FLAG_ACTIVE ) ?
 
94
                           RS_ACTIVE : RS_NOTINSERVICE;
 
95
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
 
96
                break;
 
97
            }
 
98
        }
 
99
        break;
 
100
 
 
101
        /*
 
102
         * Write-support
 
103
         */
 
104
    case MODE_SET_RESERVE1:
 
105
 
 
106
        for (request = requests; request; request = request->next) {
 
107
            entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
 
108
            tinfo = netsnmp_extract_table_info(request);
 
109
 
 
110
            switch (tinfo->colnum) {
 
111
            case COLUMN_MTEOBJECTSID:
 
112
                ret = netsnmp_check_vb_oid( request->requestvb );
 
113
                if (ret != SNMP_ERR_NOERROR) {
 
114
                    netsnmp_set_request_error(reqinfo, request, ret);
 
115
                    return SNMP_ERR_NOERROR;
 
116
                }
 
117
                /*
 
118
                 * Can't modify the OID of an active row
 
119
                 *  (an unnecessary restriction, IMO)
 
120
                 */
 
121
                if (entry &&
 
122
                    entry->flags & MTE_OBJECT_FLAG_ACTIVE ) {
 
123
                    netsnmp_set_request_error(reqinfo, request,
 
124
                                              SNMP_ERR_INCONSISTENTVALUE);
 
125
                    return SNMP_ERR_NOERROR;
 
126
                }
 
127
                break;
 
128
            case COLUMN_MTEOBJECTSIDWILDCARD:
 
129
                ret = netsnmp_check_vb_truthvalue( request->requestvb );
 
130
                if (ret != SNMP_ERR_NOERROR) {
 
131
                    netsnmp_set_request_error(reqinfo, request, ret);
 
132
                    return SNMP_ERR_NOERROR;
 
133
                }
 
134
                /*
 
135
                 * Can't modify the wildcarding of an active row
 
136
                 *  (an unnecessary restriction, IMO)
 
137
                 */
 
138
                if (entry &&
 
139
                    entry->flags & MTE_OBJECT_FLAG_ACTIVE ) {
 
140
                    netsnmp_set_request_error(reqinfo, request,
 
141
                                              SNMP_ERR_INCONSISTENTVALUE);
 
142
                    return SNMP_ERR_NOERROR;
 
143
                }
 
144
                break;
 
145
            case COLUMN_MTEOBJECTSENTRYSTATUS:
 
146
                ret = netsnmp_check_vb_rowstatus(request->requestvb,
 
147
                          (entry ? RS_ACTIVE : RS_NONEXISTENT));
 
148
                if (ret != SNMP_ERR_NOERROR) {
 
149
                    netsnmp_set_request_error(reqinfo, request, ret);
 
150
                    return SNMP_ERR_NOERROR;
 
151
                }
 
152
                /* An active row can only be deleted */
 
153
                if (entry &&
 
154
                    entry->flags & MTE_OBJECT_FLAG_ACTIVE &&
 
155
                    *request->requestvb->val.integer == RS_NOTINSERVICE ) {
 
156
                    netsnmp_set_request_error(reqinfo, request,
 
157
                                              SNMP_ERR_INCONSISTENTVALUE);
 
158
                    return SNMP_ERR_NOERROR;
 
159
                }
 
160
                break;
 
161
            default:
 
162
                netsnmp_set_request_error(reqinfo, request,
 
163
                                          SNMP_ERR_NOTWRITABLE);
 
164
                return SNMP_ERR_NOERROR;
 
165
            }
 
166
        }
 
167
        break;
 
168
 
 
169
    case MODE_SET_RESERVE2:
 
170
 
 
171
        for (request = requests; request; request = request->next) {
 
172
            tinfo = netsnmp_extract_table_info(request);
 
173
 
 
174
            switch (tinfo->colnum) {
 
175
            case COLUMN_MTEOBJECTSENTRYSTATUS:
 
176
                switch (*request->requestvb->val.integer) {
 
177
                case RS_CREATEANDGO:
 
178
                case RS_CREATEANDWAIT:
 
179
                    /*
 
180
                     * Create an (empty) new row structure
 
181
                     */
 
182
                    memset(mteOwner, 0, sizeof(mteOwner));
 
183
                    memcpy(mteOwner, tinfo->indexes->val.string,
 
184
                                     tinfo->indexes->val_len);
 
185
                    memset(mteOName, 0, sizeof(mteOName));
 
186
                    memcpy(mteOName,
 
187
                           tinfo->indexes->next_variable->val.string,
 
188
                           tinfo->indexes->next_variable->val_len);
 
189
                    ret = *tinfo->indexes->next_variable->next_variable->val.integer;
 
190
 
 
191
                    row = mteObjects_createEntry(mteOwner, mteOName, ret, 0);
 
192
                    if (!row) {
 
193
                        netsnmp_set_request_error(reqinfo, request,
 
194
                                                  SNMP_ERR_RESOURCEUNAVAILABLE);
 
195
                        return SNMP_ERR_NOERROR;
 
196
                    }
 
197
                    netsnmp_insert_tdata_row( request, row );
 
198
                }
 
199
            }
 
200
        }
 
201
        break;
 
202
 
 
203
    case MODE_SET_FREE:
 
204
 
 
205
        for (request = requests; request; request = request->next) {
 
206
            tinfo = netsnmp_extract_table_info(request);
 
207
 
 
208
            switch (tinfo->colnum) {
 
209
            case COLUMN_MTEOBJECTSENTRYSTATUS:
 
210
                switch (*request->requestvb->val.integer) {
 
211
                case RS_CREATEANDGO:
 
212
                case RS_CREATEANDWAIT:
 
213
                    /*
 
214
                     * Tidy up after a failed row creation request
 
215
                     */ 
 
216
                    entry = (struct mteObject *)
 
217
                                netsnmp_tdata_extract_entry(request);
 
218
                    if (entry &&
 
219
                      !(entry->flags & MTE_OBJECT_FLAG_VALID)) {
 
220
                        row = (netsnmp_tdata_row *)
 
221
                                netsnmp_tdata_extract_row(request);
 
222
                        mteObjects_removeEntry( row );
 
223
                    }
 
224
                }
 
225
            }
 
226
        }
 
227
        break;
 
228
 
 
229
    case MODE_SET_ACTION:
 
230
        for (request = requests; request; request = request->next) {
 
231
            entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
 
232
            if (!entry) {
 
233
                /*
 
234
                 * New rows must be created via the RowStatus column
 
235
                 */
 
236
                netsnmp_set_request_error(reqinfo, request,
 
237
                                          SNMP_ERR_NOCREATION);
 
238
                                      /* or inconsistentName? */
 
239
                return SNMP_ERR_NOERROR;
 
240
 
 
241
            }
 
242
        }
 
243
        break;
 
244
 
 
245
    case MODE_SET_UNDO:
 
246
        break;
 
247
 
 
248
    case MODE_SET_COMMIT:
 
249
        /*
 
250
         * All these assignments are "unfailable", so it's
 
251
         *  (reasonably) safe to apply them in the Commit phase
 
252
         */
 
253
        for (request = requests; request; request = request->next) {
 
254
            entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
 
255
            tinfo = netsnmp_extract_table_info(request);
 
256
 
 
257
            switch (tinfo->colnum) {
 
258
            case COLUMN_MTEOBJECTSID:
 
259
                memset(entry->mteObjectID, 0, sizeof(entry->mteObjectID));
 
260
                memcpy(entry->mteObjectID, request->requestvb->val.objid,
 
261
                                           request->requestvb->val_len);
 
262
                entry->mteObjectID_len = request->requestvb->val_len/sizeof(oid);
 
263
                break;
 
264
 
 
265
            case COLUMN_MTEOBJECTSIDWILDCARD:
 
266
                if (*request->requestvb->val.integer == TV_TRUE)
 
267
                    entry->flags |=  MTE_OBJECT_FLAG_WILD;
 
268
                else
 
269
                    entry->flags &= ~MTE_OBJECT_FLAG_WILD;
 
270
                break;
 
271
 
 
272
            case COLUMN_MTEOBJECTSENTRYSTATUS:
 
273
                switch (*request->requestvb->val.integer) {
 
274
                case RS_ACTIVE:
 
275
                    entry->flags |= MTE_OBJECT_FLAG_ACTIVE;
 
276
                    break;
 
277
                case RS_CREATEANDGO:
 
278
                    entry->flags |= MTE_OBJECT_FLAG_VALID;
 
279
                    entry->flags |= MTE_OBJECT_FLAG_ACTIVE;
 
280
                    break;
 
281
                case RS_CREATEANDWAIT:
 
282
                    entry->flags |= MTE_OBJECT_FLAG_VALID;
 
283
                    break;
 
284
 
 
285
                case RS_DESTROY:
 
286
                    row = (netsnmp_tdata_row *)
 
287
                               netsnmp_tdata_extract_row(request);
 
288
                    mteObjects_removeEntry(row);
 
289
                }
 
290
            }
 
291
        }
 
292
        break;
 
293
    }
 
294
    return SNMP_ERR_NOERROR;
 
295
}