1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 1.17 $ of : mfd-data-access.m2c,v $
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 * standard Net-SNMP includes
12 */
13 #include <net-snmp/net-snmp-config.h>
14 #include <net-snmp/net-snmp-features.h>
15 #include <net-snmp/net-snmp-includes.h>
16 #include <net-snmp/agent/net-snmp-agent-includes.h>
17 #include <net-snmp/library/vacm.h>
18
19 /*
20 * include our parent header
21 */
22 #include "snmpNotifyFilterTable.h"
23
24
25 #include "snmpNotifyFilterTable_data_access.h"
26
27 netsnmp_feature_require(snmpNotifyFilterTable_container_get);
28
29 /** @ingroup interface
30 * @addtogroup data_access data_access: Routines to access data
31 *
32 * These routines are used to locate the data used to satisfy
33 * requests.
34 *
35 * @{
36 */
37 /**********************************************************************
38 **********************************************************************
39 ***
40 *** Table snmpNotifyFilterTable
41 ***
42 **********************************************************************
43 **********************************************************************/
44 /*
45 * SNMP-NOTIFICATION-MIB::snmpNotifyFilterTable is subid 3 of snmpNotifyObjects.
46 * Its status is Current.
47 * OID: .1.3.6.1.6.3.13.1.3, length: 9
48 */
49
50 /**
51 * initialization for snmpNotifyFilterTable data access
52 *
53 * This function is called during startup to allow you to
54 * allocate any resources you need for the data table.
55 *
56 * @param snmpNotifyFilterTable_reg
57 * Pointer to snmpNotifyFilterTable_registration
58 *
59 * @retval MFD_SUCCESS : success.
60 * @retval MFD_ERROR : unrecoverable error.
61 */
62 int
snmpNotifyFilterTable_init_data(snmpNotifyFilterTable_registration * snmpNotifyFilterTable_reg)63 snmpNotifyFilterTable_init_data(snmpNotifyFilterTable_registration *
64 snmpNotifyFilterTable_reg)
65 {
66 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_init_data", "called\n"));
67
68 /*
69 * TODO:303:o: Initialize snmpNotifyFilterTable data.
70 */
71
72 return MFD_SUCCESS;
73 } /* snmpNotifyFilterTable_init_data */
74
75 /**
76 * container overview
77 *
78 */
79
80 /**
81 * container initialization
82 *
83 * @param container_ptr_ptr A pointer to a container pointer. If you
84 * create a custom container, use this parameter to return it
85 * to the MFD helper. If set to NULL, the MFD helper will
86 * allocate a container for you.
87 *
88 * This function is called at startup to allow you to customize certain
89 * aspects of the access method. For the most part, it is for advanced
90 * users. The default code should suffice for most cases. If no custom
91 * container is allocated, the MFD code will create one for your.
92 *
93 * @remark
94 * This would also be a good place to do any initialization needed
95 * for you data source. For example, opening a connection to another
96 * process that will supply the data, opening a database, etc.
97 */
98 void
snmpNotifyFilterTable_container_init(netsnmp_container ** container_ptr_ptr)99 snmpNotifyFilterTable_container_init(netsnmp_container **container_ptr_ptr)
100 {
101 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_init", "called\n"));
102
103 if (NULL == container_ptr_ptr) {
104 snmp_log(LOG_ERR,
105 "bad container param to snmpNotifyFilterTable_container_init\n");
106 return;
107 }
108
109 /*
110 * For advanced users, you can use a custom container. If you
111 * do not create one, one will be created for you.
112 */
113 *container_ptr_ptr = NULL;
114
115 } /* snmpNotifyFilterTable_container_init */
116
117 /**
118 * container shutdown
119 *
120 * @param container_ptr A pointer to the container.
121 *
122 * This function is called at shutdown to allow you to customize certain
123 * aspects of the access method. For the most part, it is for advanced
124 * users. The default code should suffice for most cases.
125 *
126 * This function is called before snmpNotifyFilterTable_container_free().
127 *
128 * @remark
129 * This would also be a good place to do any cleanup needed
130 * for you data source. For example, closing a connection to another
131 * process that supplied the data, closing a database, etc.
132 */
133 void
snmpNotifyFilterTable_container_shutdown(netsnmp_container * container_ptr)134 snmpNotifyFilterTable_container_shutdown(netsnmp_container *container_ptr)
135 {
136 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_shutdown", "called\n"));
137
138 if (NULL == container_ptr) {
139 snmp_log(LOG_ERR,
140 "bad params to snmpNotifyFilterTable_container_shutdown\n");
141 return;
142 }
143
144 } /* snmpNotifyFilterTable_container_shutdown */
145
146 /**
147 * load initial data
148 *
149 * TODO:350:M: Implement snmpNotifyFilterTable data load
150 *
151 * @param container container to which items should be inserted
152 *
153 * @retval MFD_SUCCESS : success.
154 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
155 * @retval MFD_ERROR : other error.
156 *
157 * This function is called to load the index(es) (and data, optionally)
158 * for the every row in the data set.
159 *
160 * @remark
161 * While loading the data, the only important thing is the indexes.
162 * If access to your data is cheap/fast (e.g. you have a pointer to a
163 * structure in memory), it would make sense to update the data here.
164 * If, however, the accessing the data invovles more work (e.g. parsing
165 * some other existing data, or peforming calculations to derive the data),
166 * then you can limit yourself to setting the indexes and saving any
167 * information you will need later. Then use the saved information in
168 * snmpNotifyFilterTable_row_prep() for populating data.
169 *
170 * @note
171 * If you need consistency between rows (like you want statistics
172 * for each row to be from the same time frame), you should set all
173 * data here.
174 *
175 */
176 int
snmpNotifyFilterTable_container_load(netsnmp_container * container)177 snmpNotifyFilterTable_container_load(netsnmp_container *container)
178 {
179 snmpNotifyFilterTable_rowreq_ctx *rowreq_ctx;
180 size_t count = 0;
181
182 /*
183 * temporary storage for index values
184 */
185 /*
186 * snmpNotifyFilterProfileName(1)/SnmpAdminString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H
187 */
188 char snmpNotifyFilterProfileName[32];
189 size_t snmpNotifyFilterProfileName_len;
190 /*
191 * snmpNotifyFilterSubtree(1)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/a/w/e/r/d/h
192 */
193 /** 128 - 1(entry) - 1(col) - 1(other indexes) = 114 */
194 oid snmpNotifyFilterSubtree[114];
195 size_t snmpNotifyFilterSubtree_len;
196
197
198 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_load", "called\n"));
199
200 /*
201 * TODO:351:M: |-> Load/update data in the snmpNotifyFilterTable container.
202 * loop over your snmpNotifyFilterTable data, allocate a rowreq context,
203 * set the index(es) [and data, optionally] and insert into
204 * the container.
205 */
206 while (1) {
207 /*
208 * check for end of data; bail out if there is no more data
209 */
210 if (1)
211 break;
212
213 /*
214 * TODO:352:M: | |-> set indexes in new snmpNotifyFilterTable rowreq context.
215 * data context will be set from the param (unless NULL,
216 * in which case a new data context will be allocated)
217 */
218 rowreq_ctx = snmpNotifyFilterTable_allocate_rowreq_ctx(NULL);
219 if (NULL == rowreq_ctx) {
220 snmp_log(LOG_ERR, "memory allocation failed\n");
221 return MFD_RESOURCE_UNAVAILABLE;
222 }
223 if (MFD_SUCCESS !=
224 snmpNotifyFilterTable_indexes_set(rowreq_ctx,
225 snmpNotifyFilterProfileName,
226 snmpNotifyFilterProfileName_len,
227 snmpNotifyFilterSubtree,
228 snmpNotifyFilterSubtree_len))
229 {
230 snmp_log(LOG_ERR,
231 "error setting index while loading "
232 "snmpNotifyFilterTable data.\n");
233 snmpNotifyFilterTable_release_rowreq_ctx(rowreq_ctx);
234 continue;
235 }
236
237 /*
238 * TODO:352:r: | |-> populate snmpNotifyFilterTable data context.
239 * Populate data context here. (optionally, delay until row prep)
240 */
241 /*
242 * non-TRANSIENT data: no need to copy. set pointer to data
243 */
244
245 /*
246 * insert into table container
247 */
248 CONTAINER_INSERT(container, rowreq_ctx);
249 ++count;
250 }
251
252 DEBUGMSGT(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_load",
253 "inserted %" NETSNMP_PRIz "u records\n", count));
254
255 return MFD_SUCCESS;
256 } /* snmpNotifyFilterTable_container_load */
257
258 /**
259 * container clean up
260 *
261 * @param container container with all current items
262 *
263 * This optional callback is called prior to all
264 * item's being removed from the container. If you
265 * need to do any processing before that, do it here.
266 *
267 * @note
268 * The MFD helper will take care of releasing all the row contexts.
269 *
270 */
271 void
snmpNotifyFilterTable_container_free(netsnmp_container * container)272 snmpNotifyFilterTable_container_free(netsnmp_container *container)
273 {
274 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_free", "called\n"));
275
276 /*
277 * TODO:380:M: Free snmpNotifyFilterTable container data.
278 */
279 } /* snmpNotifyFilterTable_container_free */
280
281 /**
282 * prepare row for processing.
283 *
284 * When the agent has located the row for a request, this function is
285 * called to prepare the row for processing. If you fully populated
286 * the data context during the index setup phase, you may not need to
287 * do anything.
288 *
289 * @param rowreq_ctx pointer to a context.
290 *
291 * @retval MFD_SUCCESS : success.
292 * @retval MFD_ERROR : other error.
293 */
294 int
snmpNotifyFilterTable_row_prep(snmpNotifyFilterTable_rowreq_ctx * rowreq_ctx)295 snmpNotifyFilterTable_row_prep(snmpNotifyFilterTable_rowreq_ctx *
296 rowreq_ctx)
297 {
298 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_row_prep", "called\n"));
299
300 netsnmp_assert(NULL != rowreq_ctx);
301
302 /*
303 * TODO:390:o: Prepare row for request.
304 * If populating row data was delayed, this is the place to
305 * fill in the row for this request.
306 */
307
308 return MFD_SUCCESS;
309 } /* snmpNotifyFilterTable_row_prep */
310
311 /*
312 * TODO:420:r: Implement snmpNotifyFilterTable index validation.
313 */
314 /*---------------------------------------------------------------------
315 * SNMP-NOTIFICATION-MIB::snmpNotifyFilterProfileEntry.snmpNotifyFilterProfileName
316 * snmpNotifyFilterProfileName is subid 1 of snmpNotifyFilterProfileEntry.
317 * Its status is Current, and its access level is Create.
318 * OID: .1.3.6.1.6.3.13.1.2.1.1
319 * Description:
320 The name of the filter profile to be used when generating
321 notifications using the corresponding entry in the
322 snmpTargetAddrTable.
323 *
324 * Attributes:
325 * accessible 1 isscalar 0 enums 0 hasdefval 0
326 * readable 1 iscolumn 1 ranges 1 hashint 1
327 * settable 1
328 * hint: 255t
329 *
330 * Ranges: 1 - 32;
331 *
332 * Its syntax is SnmpAdminString (based on perltype OCTETSTR)
333 * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char)
334 * This data type requires a length. (Max 32)
335 */
336 /**
337 * check validity of snmpNotifyFilterProfileName external index portion
338 *
339 * NOTE: this is not the place to do any checks for the sanity
340 * of multiple indexes. Those types of checks should be done in the
341 * snmpNotifyFilterTable_validate_index() function.
342 *
343 * @retval MFD_SUCCESS : the incoming value is legal
344 * @retval MFD_ERROR : the incoming value is NOT legal
345 */
346 int
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index(snmpNotifyFilterTable_rowreq_ctx * rowreq_ctx)362 snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index
363 (snmpNotifyFilterTable_rowreq_ctx * rowreq_ctx) {
364 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index", "called\n"));
365
366 netsnmp_assert(NULL != rowreq_ctx);
367
368 /*
369 * TODO:424:M: |-> Check snmpNotifyFilterTable external index snmpNotifyFilterProfileName.
370 * check that index value in the table context (rowreq_ctx)
371 * for the external index snmpNotifyFilterProfileName is legal.
372 */
373
374 return MFD_SUCCESS; /* external index snmpNotifyFilterProfileName ok */
375 } /* snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index */
376
377 /*---------------------------------------------------------------------
378 * SNMP-NOTIFICATION-MIB::snmpNotifyFilterEntry.snmpNotifyFilterSubtree
379 * snmpNotifyFilterSubtree is subid 1 of snmpNotifyFilterEntry.
380 * Its status is Current, and its access level is NoAccess.
381 * OID: .1.3.6.1.6.3.13.1.3.1.1
382 * Description:
383 The MIB subtree which, when combined with the corresponding
384 instance of snmpNotifyFilterMask, defines a family of
385 subtrees which are included in or excluded from the
386 filter profile.
387 *
388 * Attributes:
389 * accessible 0 isscalar 0 enums 0 hasdefval 0
390 * readable 0 iscolumn 1 ranges 0 hashint 0
391 * settable 0
392 *
393 *
394 * Its syntax is OBJECTID (based on perltype OBJECTID)
395 * The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid)
396 * This data type requires a length.
397 *
398 *
399 *
400 * NOTE: NODE snmpNotifyFilterSubtree IS NOT ACCESSIBLE
401 *
402 *
403 */
404 /**
405 * check validity of snmpNotifyFilterSubtree index portion
406 *
407 * @retval MFD_SUCCESS : the incoming value is legal
408 * @retval MFD_ERROR : the incoming value is NOT legal
409 *
410 * @note this is not the place to do any checks for the sanity
411 * of multiple indexes. Those types of checks should be done in the
412 * snmpNotifyFilterTable_validate_index() function.
413 *
414 * @note Also keep in mind that if the index refers to a row in this or
415 * some other table, you can't check for that row here to make
416 * decisions, since that row might not be created yet, but may
417 * be created during the processing this request. If you have
418 * such checks, they should be done in the check_dependencies
419 * function, because any new/deleted/changed rows should be
420 * available then.
421 *
422 * The following checks have already been done for you:
423 *
424 * If there a no other checks you need to do, simply return MFD_SUCCESS.
425 */
426 int
snmpNotifyFilterSubtree_check_index(snmpNotifyFilterTable_rowreq_ctx * rowreq_ctx)427 snmpNotifyFilterSubtree_check_index(snmpNotifyFilterTable_rowreq_ctx *
428 rowreq_ctx)
429 {
430 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterSubtree_check_index", "called\n"));
431
432 netsnmp_assert(NULL != rowreq_ctx);
433
434 /*
435 * TODO:426:M: |-> Check snmpNotifyFilterTable index snmpNotifyFilterSubtree.
436 * check that index value in the table context is legal.
437 * (rowreq_ctx->tbl_index.snmpNotifyFilterSubtree)
438 */
439
440 return MFD_SUCCESS; /* snmpNotifyFilterSubtree index ok */
441 } /* snmpNotifyFilterSubtree_check_index */
442
443 /**
444 * verify specified index is valid.
445 *
446 * This check is independent of whether or not the values specified for
447 * the columns of the new row are valid. Column values and row consistency
448 * will be checked later. At this point, only the index values should be
449 * checked.
450 *
451 * All of the individual index validation functions have been called, so this
452 * is the place to make sure they are valid as a whole when combined. If
453 * you only have one index, then you probably don't need to do anything else
454 * here.
455 *
456 * @note Keep in mind that if the indexes refer to a row in this or
457 * some other table, you can't check for that row here to make
458 * decisions, since that row might not be created yet, but may
459 * be created during the processing this request. If you have
460 * such checks, they should be done in the check_dependencies
461 * function, because any new/deleted/changed rows should be
462 * available then.
463 *
464 *
465 * @param snmpNotifyFilterTable_reg
466 * Pointer to the user registration data
467 * @param rowreq_ctx
468 * Pointer to the users context.
469 * @retval MFD_SUCCESS : success
470 * @retval MFD_CANNOT_CREATE_NOW : index not valid right now
471 * @retval MFD_CANNOT_CREATE_EVER : index never valid
472 */
473 int
snmpNotifyFilterTable_validate_index(snmpNotifyFilterTable_registration * snmpNotifyFilterTable_reg,snmpNotifyFilterTable_rowreq_ctx * rowreq_ctx)474 snmpNotifyFilterTable_validate_index(snmpNotifyFilterTable_registration *
475 snmpNotifyFilterTable_reg,
476 snmpNotifyFilterTable_rowreq_ctx *
477 rowreq_ctx)
478 {
479 int rc = MFD_SUCCESS;
480
481 DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_validate_index", "called\n"));
482
483 /** we should have a non-NULL pointer */
484 netsnmp_assert(NULL != rowreq_ctx);
485
486 /*
487 * TODO:430:M: |-> Validate potential snmpNotifyFilterTable index.
488 */
489
490 return rc;
491 } /* snmpNotifyFilterTable_validate_index */
492
493 /** @} */
494