summaryrefslogtreecommitdiff
path: root/cleopatre/application/spidnetsnmp/agent/mibgroup/sarft-eoc-mib/modEoCCNUGroup/modEoCCNUOnline.c
blob: a28ae9920166b2b899f62aa4227242a09569bc8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "modEoCCNUOnline.h"

/** Initializes the modEoCCNUOnline module */
void
init_modEoCCNUOnline(void)
{
    static oid      modEoCCNUOnlineAllReset_oid[] =
        { 1, 3, 6, 1, 4, 1, 22764, 3, 1, 5, 2, 1 };
    static oid      modEoCCNUOnlineCurrentAmount_oid[] =
        { 1, 3, 6, 1, 4, 1, 22764, 3, 1, 5, 2, 2 };
    static oid      modEoCCNUOnlineAmountLimitation_oid[] =
        { 1, 3, 6, 1, 4, 1, 22764, 3, 1, 5, 2, 3 };

    DEBUGMSGTL(("modEoCCNUOnline", "Initializing\n"));

    netsnmp_register_scalar(netsnmp_create_handler_registration
                            ("modEoCCNUOnlineAllReset",
                             handle_modEoCCNUOnlineAllReset,
                             modEoCCNUOnlineAllReset_oid,
                             OID_LENGTH(modEoCCNUOnlineAllReset_oid),
                             HANDLER_CAN_RWRITE));
    netsnmp_register_scalar(netsnmp_create_handler_registration
                            ("modEoCCNUOnlineCurrentAmount",
                             handle_modEoCCNUOnlineCurrentAmount,
                             modEoCCNUOnlineCurrentAmount_oid,
                             OID_LENGTH(modEoCCNUOnlineCurrentAmount_oid),
                             HANDLER_CAN_RONLY));
    netsnmp_register_scalar(netsnmp_create_handler_registration
                            ("modEoCCNUOnlineAmountLimitation",
                             handle_modEoCCNUOnlineAmountLimitation,
                             modEoCCNUOnlineAmountLimitation_oid,
                             OID_LENGTH
                             (modEoCCNUOnlineAmountLimitation_oid),
                             HANDLER_CAN_RWRITE));
}

int
handle_modEoCCNUOnlineAllReset(netsnmp_mib_handler *handler,
                               netsnmp_handler_registration *reginfo,
                               netsnmp_agent_request_info *reqinfo,
                               netsnmp_request_info *requests)
{
    int             ret;	
	/* TEMP: const value for skeleton compilation */
    int             all_reset = 1;
    int             *all_reset_save = NULL;
    u_long          value; 


    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *) &all_reset /* a pointer to the scalar's data */
                                 ,sizeof(all_reset)
                                 /* the length of the data in bytes */ );
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
		/* TODO: some action needed before? */
        /*
         * or you could use netsnmp_check_vb_type_and_size instead 
         */
        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
        if (ret != SNMP_ERR_NOERROR) {
            netsnmp_set_request_error(reqinfo, requests, ret);
        }
        break;

    case MODE_SET_RESERVE2:
		/*
         * malloc "undo" storage buffer 
         */	
        memdup((u_char **) &all_reset_save,
               (u_char *) &all_reset, sizeof(all_reset));

        if ( NULL == all_reset_save /* if malloc, or whatever, failed: */ ) {
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_RESOURCEUNAVAILABLE);
        }  else {
            netsnmp_request_add_list_data(requests,
                                              netsnmp_create_data_list
                                              ("allreset", all_reset_save,
                                               free));
            }
        break;



    case MODE_SET_FREE:
        /*
         * free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
		free(all_reset_save);
        break;

    case MODE_SET_ACTION:
		/* TODO: check if this course of action is appropriate for All Reset value! */
        /*
         * perform the value change here 
         */
		value = *(requests->requestvb->val.integer);
		 /* TODO: should call appropriate function for setting all reset to value 
		  ret should be return value from that function */
		ret = 0;
        if ( 0 != ret /* error? */ ) {
            netsnmp_set_request_error(reqinfo, requests, ret /* some error */);
        }
        break;




    case MODE_SET_COMMIT:
        /*
         * delete temporary storage 
         */
		free(all_reset_save);
        break;

    case MODE_SET_UNDO:
		/* TODO: check if this course of action is appropriate for All Reset value! */
        /*
         * UNDO and return to previous value for the object 
         */
		value =
            *((u_long *) netsnmp_request_get_list_data(requests,
                                                       "allreset"));
        /* TODO: should call appropriate function for setting all reset to
         * value - ret should be return value from that function */
        ret = 0;        
        if ( 0 != ret /* error? */ ) {
            /*
             * try _really_really_ hard to never get to this point 
             */
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_UNDOFAILED);
        }
        break;


    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        snmp_log(LOG_ERR,
                 "unknown mode (%d) in handle_modEoCCNUOnlineAllReset\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}

int
handle_modEoCCNUOnlineCurrentAmount(netsnmp_mib_handler *handler,
                                    netsnmp_handler_registration *reginfo,
                                    netsnmp_agent_request_info *reqinfo,
                                    netsnmp_request_info *requests)
{
	/* TEMP: const value for skeleton compilation */
    int             curr_amount = 20;

	/*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *) &curr_amount /* a pointer to the scalar's data */
                                 ,sizeof(curr_amount) /* the length of the data in bytes */ );
        break;


    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        snmp_log(LOG_ERR,
                 "unknown mode (%d) in handle_modEoCCNUOnlineCurrentAmount\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}

int
handle_modEoCCNUOnlineAmountLimitation(netsnmp_mib_handler *handler,
                                       netsnmp_handler_registration
                                       *reginfo,
                                       netsnmp_agent_request_info *reqinfo,
                                       netsnmp_request_info *requests)
{
    int             ret;
	/* TEMP: const value for skeleton compilation */
    int             amount_limit = 256;
	int             *amount_limit_save = NULL;
    u_long          value; 

    /*
     * We are never called for a GETNEXT if it's registered as a
     * "instance", as it's "magically" handled for us.  
     */

    /*
     * a instance handler also only hands us one request at a time, so
     * we don't need to loop over a list of requests; we'll only get one. 
     */

    switch (reqinfo->mode) {

    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *) &amount_limit /* a pointer to the scalar's data */
                                 ,sizeof(amount_limit) /* the length of the data in bytes */ );
        break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
    case MODE_SET_RESERVE1:
		/* TODO: some action needed before? */
        /*
         * or you could use netsnmp_check_vb_type_and_size instead 
         */
        ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
        if (ret != SNMP_ERR_NOERROR) {
            netsnmp_set_request_error(reqinfo, requests, ret);
        }
        break;

    case MODE_SET_RESERVE2:
        /*
         * malloc "undo" storage buffer 
         */ 
		memdup((u_char **) &amount_limit_save,
               (u_char *) &amount_limit, sizeof(amount_limit));

        if ( NULL == amount_limit_save /* if malloc, or whatever, failed: */ ) {
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_RESOURCEUNAVAILABLE);
        }  else {
            netsnmp_request_add_list_data(requests,
                                              netsnmp_create_data_list
                                              ("onlineamountlimit", amount_limit_save,
                                               free));
            }
        break;



    case MODE_SET_FREE:
        /*
         * free resources allocated in RESERVE1 and/or
         * RESERVE2.  Something failed somewhere, and the states
         * below won't be called. 
         */
		free(amount_limit_save);
        break;

    case MODE_SET_ACTION:
		/*
         * perform the value change here 
         */   

		value = *(requests->requestvb->val.integer);
		/* TODO: should call appropriate function for setting amount limit to value 
		   ret should be return value from that function */
		ret = 0;
        if ( 0 != ret /* error? */ ) {
            netsnmp_set_request_error(reqinfo, requests, ret /* some error */);
        }
        break;



    case MODE_SET_COMMIT:
        /*
         * delete temporary storage 
         */
		free(amount_limit_save);
        break;

    case MODE_SET_UNDO:
		/* UNDO and return to previous value for the object */  
		value =
            *((u_long *) netsnmp_request_get_list_data(requests,
                                                       "onlineamountlimit"));
        /* TODO: should call appropriate function for setting amount limit to
         * value - ret should be return value from that function */
        ret = 0;        
        if ( 0 != ret /* error? */ ) {
            /*
             * try _really_really_ hard to never get to this point 
             */
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_UNDOFAILED);
        }
        break;



    default:
        /*
         * we should never get here, so this is a really bad error 
         */
        snmp_log(LOG_ERR,
                 "unknown mode (%d) in handle_modEoCCNUOnlineAmountLimitation\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}