Debian Codegraph @

agent/mibgroup/notification/snmpNotifyFilterProfileTable.c

raw
1 /*
2 * This file was generated by mib2c and is intended for use as
3 * a mib module for the ucd-snmp snmpd agent.
4 *
5 * Portions of this file are copyrighted by:
6 * Copyright (c) 2016 VMware, Inc. All rights reserved.
7 * Use is subject to license terms specified in the COPYING file
8 * distributed with the Net-SNMP package.
9 */
10
11
12 /*
13 * This should always be included first before anything else
14 */
15 #include <net-snmp/net-snmp-config.h>
16
17 #include <sys/types.h>
18 #ifdef HAVE_STDLIB_H
19 #include <stdlib.h>
20 #endif
21 #ifdef HAVE_STRING_H
22 #include <string.h>
23 #else
24 #include <strings.h>
25 #endif
26
27
28 /*
29 * minimal include directives
30 */
31 #include <net-snmp/net-snmp-features.h>
32 #include <net-snmp/net-snmp-includes.h>
33 #include <net-snmp/agent/net-snmp-agent-includes.h>
34
35 #include "header_complex.h"
36 #include "snmpNotifyTable_data.h"
37 #include "snmpNotifyFilterProfileTable.h"
38
39 #ifndef NETSNMP_NO_WRITE_SUPPORT
40 netsnmp_feature_require(header_complex_find_entry);
41 #endif /* NETSNMP_NO_WRITE_SUPPORT */
42
43 /*
44 * snmpNotifyFilterProfileTable_variables_oid:
45 * this is the top level oid that we want to register under. This
46 * is essentially a prefix, with the suffix appearing in the
47 * variable below.
48 */
49
50
51 oid snmpNotifyFilterProfileTable_variables_oid[] =
52 { 1, 3, 6, 1, 6, 3, 13, 1, 2 };
53 #ifndef NETSNMP_NO_WRITE_SUPPORT
54 static const size_t table_offset =
55 sizeof(snmpNotifyFilterProfileTable_variables_oid)/sizeof(oid) + 3 - 1;
56 #endif
57
58 /*
59 * variable2 snmpNotifyFilterProfileTable_variables:
60 * this variable defines function callbacks and type return information
61 * for the snmpNotifyFilterProfileTable mib section
62 */
63
64
65 struct variable2 snmpNotifyFilterProfileTable_variables[] = {
66 /*
67 * magic number , variable type , ro/rw , callback fn , L, oidsuffix
68 */
69 #define SNMPNOTIFYFILTERPROFILENAME 3
70 {SNMPNOTIFYFILTERPROFILENAME, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE,
71 var_snmpNotifyFilterProfileTable, 2, {1, 1}},
72 #define SNMPNOTIFYFILTERPROFILESTORTYPE 4
73 {SNMPNOTIFYFILTERPROFILESTORTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
74 var_snmpNotifyFilterProfileTable, 2, {1, 2}},
75 #define SNMPNOTIFYFILTERPROFILEROWSTATUS 5
76 {SNMPNOTIFYFILTERPROFILEROWSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
77 var_snmpNotifyFilterProfileTable, 2, {1, 3}},
78
79 };
80 /*
81 * (L = length of the oidsuffix)
82 */
83
84
85 /*
86 * global storage of our data, saved in and configured by header_complex()
87 */
88
89
90
91 /*
92 * init_snmpNotifyFilterProfileTable():
93 * Initialization routine. This is called when the agent starts up.
94 * At a minimum, registration of your variables should take place here.
95 */
96 void
97 init_snmpNotifyFilterProfileTable(void)
98 {
99 DEBUGMSGTL(("snmpNotifyFilterProfileTable", "initializing... "));
100
101 init_snmpNotifyFilterProfileTable_data();
102
103 /*
104 * register ourselves with the agent to handle our mib tree
105 */
106 REGISTER_MIB("snmpNotifyFilterProfileTable",
107 snmpNotifyFilterProfileTable_variables, variable2,
108 snmpNotifyFilterProfileTable_variables_oid);
109
110
111 /*
112 * place any other initialization junk you need here
113 */
114
115
116 DEBUGMSGTL(("snmpNotifyFilterProfileTable", "done.\n"));
117 }
118
119 void
120 shutdown_snmpNotifyFilterProfileTable(void)
121 {
122 shutdown_snmpNotifyFilterProfileTable_data();
123 }
124
125
126 /*
127 * var_snmpNotifyFilterProfileTable():
128 * Handle this table separately from the scalar value case.
129 * The workings of this are basically the same as for var_snmpNotifyFilterProfileTable above.
130 */
131 unsigned char *
132 var_snmpNotifyFilterProfileTable(struct variable *vp,
133 oid * name,
134 size_t * length,
135 int exact,
136 size_t * var_len,
137 WriteMethod ** write_method)
138 {
139
140
141 struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
142 int found = 1;
143
144
145 DEBUGMSGTL(("snmpNotifyFilterProfileTable",
146 "var_snmpNotifyFilterProfileTable: Entering... \n"));
147 /*
148 * this assumes you have registered all your data properly
149 */
150 StorageTmp = snmpNotifyFilterProfileTable_oldapi_find(vp, name, length,
151 exact, var_len,
152 write_method);
153 if (StorageTmp == NULL)
154 found = 0;
155
156 switch (vp->magic) {
157 #ifndef NETSNMP_NO_WRITE_SUPPORT
158 case SNMPNOTIFYFILTERPROFILENAME:
159 *write_method = write_snmpNotifyFilterProfileName;
160 break;
161
162 case SNMPNOTIFYFILTERPROFILESTORTYPE:
163 *write_method = write_snmpNotifyFilterProfileStorType;
164 break;
165
166 case SNMPNOTIFYFILTERPROFILEROWSTATUS:
167 *write_method = write_snmpNotifyFilterProfileRowStatus;
168 break;
169 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
170 default:
171 *write_method = NULL;
172 }
173
174 if (!found) {
175 return NULL;
176 }
177
178 /*
179 * this is where we do the value assignments for the mib results.
180 */
181 switch (vp->magic) {
182
183 case SNMPNOTIFYFILTERPROFILENAME:
184 *var_len = StorageTmp->snmpNotifyFilterProfileNameLen;
185 return (u_char *) StorageTmp->snmpNotifyFilterProfileName;
186
187 case SNMPNOTIFYFILTERPROFILESTORTYPE:
188 *var_len = sizeof(StorageTmp->snmpNotifyFilterProfileStorType);
189 return (u_char *) & StorageTmp->snmpNotifyFilterProfileStorType;
190
191 case SNMPNOTIFYFILTERPROFILEROWSTATUS:
192 *var_len = sizeof(StorageTmp->snmpNotifyFilterProfileRowStatus);
193 return (u_char *) & StorageTmp->snmpNotifyFilterProfileRowStatus;
194
195
196 default:
197 ERROR_MSG("");
198 }
199
200 return NULL;
201 }
202
203 #ifndef NETSNMP_NO_WRITE_SUPPORT
204
205 static struct snmpNotifyFilterProfileTable_data *StorageNew;
206
207 int
208 write_snmpNotifyFilterProfileName(int action,
209 u_char * var_val,
210 u_char var_val_type,
211 size_t var_val_len,
212 u_char * statP,
213 oid * name, size_t name_len)
214 {
215 static char *tmpvar;
216 struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
217 static size_t tmplen;
218 size_t newlen = name_len - table_offset;
219
220
221 DEBUGMSGTL(("snmpNotifyFilterProfileTable",
222 "write_snmpNotifyFilterProfileName entering action=%d... \n",
223 action));
224 if (action != RESERVE1 &&
225 (StorageTmp = snmpNotifyFilterProfileTable_oldapi_find(
226 NULL, &name[table_offset], &newlen, 1, NULL, NULL)) == NULL) {
227 if ((StorageTmp = StorageNew) == NULL)
228 return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
229 }
230
231
232 switch (action) {
233 case RESERVE1:
234 if (var_val_type != ASN_OCTET_STR) {
235 return SNMP_ERR_WRONGTYPE;
236 }
237 if (var_val_len < 1 || var_val_len > NOTIFY_NAME_MAX) {
238 return SNMP_ERR_WRONGLENGTH;
239 }
240 break;
241
242
243 case RESERVE2:
244 /*
245 * memory reseveration, final preparation...
246 */
247 tmpvar = StorageTmp->snmpNotifyFilterProfileName;
248 tmplen = StorageTmp->snmpNotifyFilterProfileNameLen;
249 StorageTmp->snmpNotifyFilterProfileName = (char*)calloc(1, var_val_len + 1);
250 if (NULL == StorageTmp->snmpNotifyFilterProfileName)
251 return SNMP_ERR_RESOURCEUNAVAILABLE;
252 break;
253
254
255 case FREE:
256 /*
257 * Release any resources that have been allocated
258 */
259 break;
260
261
262 case ACTION:
263 /*
264 * The variable has been stored in string for
265 * you to use, and you have just been asked to do something with
266 * it. Note that anything done here must be reversable in the UNDO case
267 */
268 memcpy(StorageTmp->snmpNotifyFilterProfileName, var_val, var_val_len);
269 StorageTmp->snmpNotifyFilterProfileNameLen = var_val_len;
270 break;
271
272
273 case UNDO:
274 /*
275 * Back out any changes made in the ACTION case
276 */
277 SNMP_FREE(StorageTmp->snmpNotifyFilterProfileName);
278 StorageTmp->snmpNotifyFilterProfileName = tmpvar;
279 StorageTmp->snmpNotifyFilterProfileNameLen = tmplen;
280 break;
281
282
283 case COMMIT:
284 /*
285 * Things are working well, so it's now safe to make the change
286 * permanently. Make sure that anything done here can't fail!
287 */
288 SNMP_FREE(tmpvar);
289 snmp_store_needed(NULL);
290 break;
291 }
292 return SNMP_ERR_NOERROR;
293 }
294
295
296
297 int
298 write_snmpNotifyFilterProfileStorType(int action,
299 u_char * var_val,
300 u_char var_val_type,
301 size_t var_val_len,
302 u_char * statP,
303 oid * name, size_t name_len)
304 {
305 static int tmpvar;
306 long value = *((long *) var_val);
307 struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
308 size_t newlen = name_len - table_offset;
309
310
311 DEBUGMSGTL(("snmpNotifyFilterProfileTable",
312 "write_snmpNotifyFilterProfileStorType entering action=%d... \n",
313 action));
314 if (action != RESERVE1 &&
315 (StorageTmp = snmpNotifyFilterProfileTable_oldapi_find(
316 NULL, &name[table_offset], &newlen, 1, NULL, NULL)) == NULL) {
317 if ((StorageTmp = StorageNew) == NULL)
318 return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
319 }
320
321 switch (action) {
322 case RESERVE1:
323 if (var_val_type != ASN_INTEGER) {
324 return SNMP_ERR_WRONGTYPE;
325 }
326 if (var_val_len != sizeof(long)) {
327 return SNMP_ERR_WRONGLENGTH;
328 }
329 if (value != SNMP_STORAGE_OTHER && value != SNMP_STORAGE_VOLATILE
330 && value != SNMP_STORAGE_NONVOLATILE) {
331 return SNMP_ERR_WRONGVALUE;
332 }
333 break;
334
335
336 case RESERVE2:
337 /*
338 * memory reseveration, final preparation...
339 */
340 break;
341
342
343 case FREE:
344 /*
345 * Release any resources that have been allocated
346 */
347 break;
348
349
350 case ACTION:
351 /*
352 * The variable has been stored in long_ret for
353 * you to use, and you have just been asked to do something with
354 * it. Note that anything done here must be reversable in the UNDO case
355 */
356 tmpvar = StorageTmp->snmpNotifyFilterProfileStorType;
357 StorageTmp->snmpNotifyFilterProfileStorType = *((long *) var_val);
358 break;
359
360
361 case UNDO:
362 /*
363 * Back out any changes made in the ACTION case
364 */
365 StorageTmp->snmpNotifyFilterProfileStorType = tmpvar;
366 break;
367
368
369 case COMMIT:
370 /*
371 * Things are working well, so it's now safe to make the change
372 * permanently. Make sure that anything done here can't fail!
373 */
374 snmp_store_needed(NULL);
375 break;
376 }
377 return SNMP_ERR_NOERROR;
378 }
379
380
381
382
383
384
385 int
386 write_snmpNotifyFilterProfileRowStatus(int action,
387 u_char * var_val,
388 u_char var_val_type,
389 size_t var_val_len,
390 u_char * statP,
391 oid * name, size_t name_len)
392 {
393 struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
394 static struct snmpNotifyFilterProfileTable_data *StorageDel;
395 size_t newlen = name_len - table_offset;
396 static int old_value;
397 int set_value = *((long *) var_val);
398 netsnmp_variable_list *vars;
399
400
401 DEBUGMSGTL(("snmpNotifyFilterProfileTable",
402 "write_snmpNotifyFilterProfileRowStatus entering action=%d... \n",
403 action));
404 StorageTmp = snmpNotifyFilterProfileTable_oldapi_find(
405 NULL, &name[table_offset], &newlen, 1, NULL, NULL);
406
407 switch (action) {
408 case RESERVE1:
409 if (var_val_type != ASN_INTEGER || var_val == NULL) {
410 return SNMP_ERR_WRONGTYPE;
411 }
412 if (var_val_len != sizeof(long)) {
413 return SNMP_ERR_WRONGLENGTH;
414 }
415 if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) {
416 return SNMP_ERR_WRONGVALUE;
417 }
418 /*
419 * stage one: test validity
420 */
421 if (StorageTmp == NULL) {
422 /*
423 * create the row now?
424 */
425
426
427 /*
428 * ditch illegal values now
429 */
430 if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {
431 return SNMP_ERR_INCONSISTENTVALUE;
432 }
433 } else {
434 /*
435 * row exists. Check for a valid state change
436 */
437 if (set_value == RS_CREATEANDGO
438 || set_value == RS_CREATEANDWAIT) {
439 /*
440 * can't create a row that exists
441 */
442 return SNMP_ERR_INCONSISTENTVALUE;
443 }
444 if ((set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) &&
445 StorageTmp->snmpNotifyFilterProfileNameLen == 0) {
446 /*
447 * can't activate row without a profile name
448 */
449 return SNMP_ERR_INCONSISTENTVALUE;
450 }
451 /*
452 * XXX: interaction with row storage type needed
453 */
454 }
455
456 /*
457 * memory reseveration, final preparation...
458 */
459 if (StorageTmp == NULL &&
460 (set_value == RS_CREATEANDGO
461 || set_value == RS_CREATEANDWAIT)) {
462 /*
463 * creation
464 */
465 vars = NULL;
466
467 snmp_varlist_add_variable(&vars, NULL, 0,
468 ASN_PRIV_IMPLIED_OCTET_STR, NULL, 0);
469
470 if (header_complex_parse_oid
471 (&
472 (name
473 [sizeof(snmpNotifyFilterProfileTable_variables_oid) /
474 sizeof(oid) + 2]), newlen, vars) != SNMPERR_SUCCESS) {
475 snmp_free_var(vars);
476 return SNMP_ERR_INCONSISTENTNAME;
477 }
478
479 StorageNew =
480 SNMP_MALLOC_STRUCT(snmpNotifyFilterProfileTable_data);
481 if (StorageNew == NULL)
482 return SNMP_ERR_GENERR;
483 StorageNew->snmpTargetParamsName =
484 netsnmp_memdup(vars->val.string, vars->val_len);
485 StorageNew->snmpTargetParamsNameLen = vars->val_len;
486 StorageNew->snmpNotifyFilterProfileStorType = ST_NONVOLATILE;
487
488 StorageNew->snmpNotifyFilterProfileRowStatus = RS_NOTREADY;
489 snmp_free_var(vars);
490 }
491
492
493 break;
494
495 case RESERVE2:
496 break;
497
498 case FREE:
499 /*
500 * XXX: free, zero vars
501 */
502 /*
503 * Release any resources that have been allocated
504 */
505 if (StorageNew != NULL) {
506 snmpNotifyFilterProfileTable_free(StorageNew);
507 StorageNew = NULL;
508 }
509 break;
510
511
512
513
514 case ACTION:
515 /*
516 * The variable has been stored in set_value for you to
517 * use, and you have just been asked to do something with
518 * it. Note that anything done here must be reversable in
519 * the UNDO case
520 */
521
522 if (StorageTmp == NULL &&
523 (set_value == RS_CREATEANDGO ||
524 set_value == RS_CREATEANDWAIT)) {
525 /*
526 * row creation, so add it
527 */
528 if (StorageNew != NULL)
529 snmpNotifyFilterProfileTable_add(StorageNew);
530 /*
531 * XXX: ack, and if it is NULL?
532 */
533 } else if (set_value != RS_DESTROY) {
534 /*
535 * set the flag?
536 */
537 if (StorageTmp == NULL)
538 return SNMP_ERR_GENERR; /* should never ever get here */
539
540 old_value = StorageTmp->snmpNotifyFilterProfileRowStatus;
541 StorageTmp->snmpNotifyFilterProfileRowStatus =
542 *((long *) var_val);
543 } else {
544 /*
545 * destroy... extract it for now
546 */
547 if (StorageTmp) {
548 StorageDel =
549 snmpNotifyFilterProfileTable_extract(StorageTmp);
550 }
551
552 }
553 break;
554
555 case UNDO:
556 /*
557 * Back out any changes made in the ACTION case
558 */
559 if (StorageTmp == NULL &&
560 (set_value == RS_CREATEANDGO ||
561 set_value == RS_CREATEANDWAIT)) {
562 /*
563 * row creation, so remove it again
564 */
565 StorageDel =
566 snmpNotifyFilterProfileTable_extract(StorageNew);
567 /*
568 * XXX: free it
569 */
570 } else if (StorageDel != NULL) {
571 /*
572 * row deletion, so add it again
573 */
574 snmpNotifyFilterProfileTable_add(StorageDel);
575 StorageDel = NULL;
576 } else if (set_value != RS_DESTROY) {
577 if (StorageTmp)
578 StorageTmp->snmpNotifyFilterProfileRowStatus = old_value;
579 }
580 break;
581
582
583
584
585 case COMMIT:
586 /*
587 * Things are working well, so it's now safe to make the change
588 * permanently. Make sure that anything done here can't fail!
589 */
590 if (StorageDel != NULL) {
591 snmpNotifyFilterProfileTable_free(StorageDel);
592 StorageDel = NULL;
593 }
594 if (StorageTmp && set_value == RS_CREATEANDGO) {
595 if (StorageTmp->snmpNotifyFilterProfileNameLen)
596 StorageTmp->snmpNotifyFilterProfileRowStatus = RS_ACTIVE;
597 StorageNew = NULL;
598 } else if (StorageTmp && set_value == RS_CREATEANDWAIT) {
599 if (StorageTmp->snmpNotifyFilterProfileNameLen)
600 StorageTmp->snmpNotifyFilterProfileRowStatus = RS_NOTINSERVICE;
601 StorageNew = NULL;
602 }
603 snmp_store_needed(NULL);
604 break;
605 }
606 return SNMP_ERR_NOERROR;
607 }
608
609
610 #endif /* !NETSNMP_NO_WRITE_SUPPORT */