2
* Note: this file originally auto-generated by mib2c using
3
* version : 1.17 $ of : mfd-data-access.m2c,v $
5
* $Id: snmpNotifyFilterTable_data_access.c,v 1.2.2.3 2006/01/25 16:26:39 dts12 Exp $
8
* standard Net-SNMP includes
10
#include <net-snmp/net-snmp-config.h>
11
#include <net-snmp/net-snmp-includes.h>
12
#include <net-snmp/agent/net-snmp-agent-includes.h>
13
#include <net-snmp/library/vacm.h>
16
* include our parent header
18
#include "snmpNotifyFilterTable.h"
21
#include "snmpNotifyFilterTable_data_access.h"
23
/** @ingroup interface
24
* @addtogroup data_access data_access: Routines to access data
26
* These routines are used to locate the data used to satisfy
31
/**********************************************************************
32
**********************************************************************
34
*** Table snmpNotifyFilterTable
36
**********************************************************************
37
**********************************************************************/
39
* SNMP-NOTIFICATION-MIB::snmpNotifyFilterTable is subid 3 of snmpNotifyObjects.
40
* Its status is Current.
41
* OID: .1.3.6.1.6.3.13.1.3, length: 9
45
* initialization for snmpNotifyFilterTable data access
47
* This function is called during startup to allow you to
48
* allocate any resources you need for the data table.
50
* @param snmpNotifyFilterTable_reg
51
* Pointer to snmpNotifyFilterTable_registration
53
* @retval MFD_SUCCESS : success.
54
* @retval MFD_ERROR : unrecoverable error.
57
snmpNotifyFilterTable_init_data(snmpNotifyFilterTable_registration *
58
snmpNotifyFilterTable_reg)
60
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_init_data", "called\n"));
63
* TODO:303:o: Initialize snmpNotifyFilterTable data.
67
} /* snmpNotifyFilterTable_init_data */
75
* container initialization
77
* @param container_ptr_ptr A pointer to a container pointer. If you
78
* create a custom container, use this parameter to return it
79
* to the MFD helper. If set to NULL, the MFD helper will
80
* allocate a container for you.
82
* This function is called at startup to allow you to customize certain
83
* aspects of the access method. For the most part, it is for advanced
84
* users. The default code should suffice for most cases. If no custom
85
* container is allocated, the MFD code will create one for your.
88
* This would also be a good place to do any initialization needed
89
* for you data source. For example, opening a connection to another
90
* process that will supply the data, opening a database, etc.
93
snmpNotifyFilterTable_container_init(netsnmp_container **container_ptr_ptr)
95
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_init", "called\n"));
97
if (NULL == container_ptr_ptr) {
99
"bad container param to snmpNotifyFilterTable_container_init\n");
104
* For advanced users, you can use a custom container. If you
105
* do not create one, one will be created for you.
107
*container_ptr_ptr = NULL;
109
} /* snmpNotifyFilterTable_container_init */
114
* @param container_ptr A pointer to the container.
116
* This function is called at shutdown to allow you to customize certain
117
* aspects of the access method. For the most part, it is for advanced
118
* users. The default code should suffice for most cases.
120
* This function is called before snmpNotifyFilterTable_container_free().
123
* This would also be a good place to do any cleanup needed
124
* for you data source. For example, closing a connection to another
125
* process that supplied the data, closing a database, etc.
128
snmpNotifyFilterTable_container_shutdown(netsnmp_container *container_ptr)
130
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_shutdown", "called\n"));
132
if (NULL == container_ptr) {
134
"bad params to snmpNotifyFilterTable_container_shutdown\n");
138
} /* snmpNotifyFilterTable_container_shutdown */
143
* TODO:350:M: Implement snmpNotifyFilterTable data load
145
* @param container container to which items should be inserted
147
* @retval MFD_SUCCESS : success.
148
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
149
* @retval MFD_ERROR : other error.
151
* This function is called to load the index(es) (and data, optionally)
152
* for the every row in the data set.
155
* While loading the data, the only important thing is the indexes.
156
* If access to your data is cheap/fast (e.g. you have a pointer to a
157
* structure in memory), it would make sense to update the data here.
158
* If, however, the accessing the data invovles more work (e.g. parsing
159
* some other existing data, or peforming calculations to derive the data),
160
* then you can limit yourself to setting the indexes and saving any
161
* information you will need later. Then use the saved information in
162
* snmpNotifyFilterTable_row_prep() for populating data.
165
* If you need consistency between rows (like you want statistics
166
* for each row to be from the same time frame), you should set all
171
snmpNotifyFilterTable_container_load(netsnmp_container *container)
173
snmpNotifyFilterTable_rowreq_ctx *rowreq_ctx;
177
* temporary storage for index values
180
* snmpNotifyFilterProfileName(1)/SnmpAdminString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H
182
char snmpNotifyFilterProfileName[32];
183
size_t snmpNotifyFilterProfileName_len;
185
* snmpNotifyFilterSubtree(1)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/a/w/e/r/d/h
187
/** 128 - 1(entry) - 1(col) - 1(other indexes) = 114 */
188
oid snmpNotifyFilterSubtree[114];
189
size_t snmpNotifyFilterSubtree_len;
192
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_load", "called\n"));
195
* TODO:351:M: |-> Load/update data in the snmpNotifyFilterTable container.
196
* loop over your snmpNotifyFilterTable data, allocate a rowreq context,
197
* set the index(es) [and data, optionally] and insert into
202
* check for end of data; bail out if there is no more data
208
* TODO:352:M: | |-> set indexes in new snmpNotifyFilterTable rowreq context.
209
* data context will be set from the param (unless NULL,
210
* in which case a new data context will be allocated)
212
rowreq_ctx = snmpNotifyFilterTable_allocate_rowreq_ctx(NULL);
213
if (NULL == rowreq_ctx) {
214
snmp_log(LOG_ERR, "memory allocation failed\n");
215
return MFD_RESOURCE_UNAVAILABLE;
218
snmpNotifyFilterTable_indexes_set(rowreq_ctx,
219
snmpNotifyFilterProfileName,
220
snmpNotifyFilterProfileName_len,
221
snmpNotifyFilterSubtree,
222
snmpNotifyFilterSubtree_len))
225
"error setting index while loading "
226
"snmpNotifyFilterTable data.\n");
227
snmpNotifyFilterTable_release_rowreq_ctx(rowreq_ctx);
232
* TODO:352:r: | |-> populate snmpNotifyFilterTable data context.
233
* Populate data context here. (optionally, delay until row prep)
236
* non-TRANSIENT data: no need to copy. set pointer to data
240
* insert into table container
242
CONTAINER_INSERT(container, rowreq_ctx);
246
DEBUGMSGT(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_load", "inserted %d records\n", count));
249
} /* snmpNotifyFilterTable_container_load */
254
* @param container container with all current items
256
* This optional callback is called prior to all
257
* item's being removed from the container. If you
258
* need to do any processing before that, do it here.
261
* The MFD helper will take care of releasing all the row contexts.
265
snmpNotifyFilterTable_container_free(netsnmp_container *container)
267
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_container_free", "called\n"));
270
* TODO:380:M: Free snmpNotifyFilterTable container data.
272
} /* snmpNotifyFilterTable_container_free */
275
* prepare row for processing.
277
* When the agent has located the row for a request, this function is
278
* called to prepare the row for processing. If you fully populated
279
* the data context during the index setup phase, you may not need to
282
* @param rowreq_ctx pointer to a context.
284
* @retval MFD_SUCCESS : success.
285
* @retval MFD_ERROR : other error.
288
snmpNotifyFilterTable_row_prep(snmpNotifyFilterTable_rowreq_ctx *
291
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_row_prep", "called\n"));
293
netsnmp_assert(NULL != rowreq_ctx);
296
* TODO:390:o: Prepare row for request.
297
* If populating row data was delayed, this is the place to
298
* fill in the row for this request.
302
} /* snmpNotifyFilterTable_row_prep */
305
* TODO:420:r: Implement snmpNotifyFilterTable index validation.
307
/*---------------------------------------------------------------------
308
* SNMP-NOTIFICATION-MIB::snmpNotifyFilterProfileEntry.snmpNotifyFilterProfileName
309
* snmpNotifyFilterProfileName is subid 1 of snmpNotifyFilterProfileEntry.
310
* Its status is Current, and its access level is Create.
311
* OID: .1.3.6.1.6.3.13.1.2.1.1
313
The name of the filter profile to be used when generating
314
notifications using the corresponding entry in the
318
* accessible 1 isscalar 0 enums 0 hasdefval 0
319
* readable 1 iscolumn 1 ranges 1 hashint 1
325
* Its syntax is SnmpAdminString (based on perltype OCTETSTR)
326
* The net-snmp type is ASN_OCTET_STR. The C type decl is char (char)
327
* This data type requires a length. (Max 32)
330
* check validity of snmpNotifyFilterProfileName external index portion
332
* NOTE: this is not the place to do any checks for the sanity
333
* of multiple indexes. Those types of checks should be done in the
334
* snmpNotifyFilterTable_validate_index() function.
336
* @retval MFD_SUCCESS : the incoming value is legal
337
* @retval MFD_ERROR : the incoming value is NOT legal
355
snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index
356
(snmpNotifyFilterTable_rowreq_ctx * rowreq_ctx) {
357
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index", "called\n"));
359
netsnmp_assert(NULL != rowreq_ctx);
362
* TODO:424:M: |-> Check snmpNotifyFilterTable external index snmpNotifyFilterProfileName.
363
* check that index value in the table context (rowreq_ctx)
364
* for the external index snmpNotifyFilterProfileName is legal.
367
return MFD_SUCCESS; /* external index snmpNotifyFilterProfileName ok */
368
} /* snmpNotifyFilterTable_snmpNotifyFilterProfileName_check_index */
370
/*---------------------------------------------------------------------
371
* SNMP-NOTIFICATION-MIB::snmpNotifyFilterEntry.snmpNotifyFilterSubtree
372
* snmpNotifyFilterSubtree is subid 1 of snmpNotifyFilterEntry.
373
* Its status is Current, and its access level is NoAccess.
374
* OID: .1.3.6.1.6.3.13.1.3.1.1
376
The MIB subtree which, when combined with the corresponding
377
instance of snmpNotifyFilterMask, defines a family of
378
subtrees which are included in or excluded from the
382
* accessible 0 isscalar 0 enums 0 hasdefval 0
383
* readable 0 iscolumn 1 ranges 0 hashint 0
387
* Its syntax is OBJECTID (based on perltype OBJECTID)
388
* The net-snmp type is ASN_OBJECT_ID. The C type decl is oid (oid)
389
* This data type requires a length.
393
* NOTE: NODE snmpNotifyFilterSubtree IS NOT ACCESSIBLE
398
* check validity of snmpNotifyFilterSubtree index portion
400
* @retval MFD_SUCCESS : the incoming value is legal
401
* @retval MFD_ERROR : the incoming value is NOT legal
403
* @note this is not the place to do any checks for the sanity
404
* of multiple indexes. Those types of checks should be done in the
405
* snmpNotifyFilterTable_validate_index() function.
407
* @note Also keep in mind that if the index refers to a row in this or
408
* some other table, you can't check for that row here to make
409
* decisions, since that row might not be created yet, but may
410
* be created during the processing this request. If you have
411
* such checks, they should be done in the check_dependencies
412
* function, because any new/deleted/changed rows should be
415
* The following checks have already been done for you:
417
* If there a no other checks you need to do, simply return MFD_SUCCESS.
420
snmpNotifyFilterSubtree_check_index(snmpNotifyFilterTable_rowreq_ctx *
423
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterSubtree_check_index", "called\n"));
425
netsnmp_assert(NULL != rowreq_ctx);
428
* TODO:426:M: |-> Check snmpNotifyFilterTable index snmpNotifyFilterSubtree.
429
* check that index value in the table context is legal.
430
* (rowreq_ctx->tbl_index.snmpNotifyFilterSubtree)
433
return MFD_SUCCESS; /* snmpNotifyFilterSubtree index ok */
434
} /* snmpNotifyFilterSubtree_check_index */
437
* verify specified index is valid.
439
* This check is independent of whether or not the values specified for
440
* the columns of the new row are valid. Column values and row consistency
441
* will be checked later. At this point, only the index values should be
444
* All of the individual index validation functions have been called, so this
445
* is the place to make sure they are valid as a whole when combined. If
446
* you only have one index, then you probably don't need to do anything else
449
* @note Keep in mind that if the indexes refer to a row in this or
450
* some other table, you can't check for that row here to make
451
* decisions, since that row might not be created yet, but may
452
* be created during the processing this request. If you have
453
* such checks, they should be done in the check_dependencies
454
* function, because any new/deleted/changed rows should be
458
* @param snmpNotifyFilterTable_reg
459
* Pointer to the user registration data
461
* Pointer to the users context.
462
* @retval MFD_SUCCESS : success
463
* @retval MFD_CANNOT_CREATE_NOW : index not valid right now
464
* @retval MFD_CANNOT_CREATE_EVER : index never valid
467
snmpNotifyFilterTable_validate_index(snmpNotifyFilterTable_registration *
468
snmpNotifyFilterTable_reg,
469
snmpNotifyFilterTable_rowreq_ctx *
472
int rc = MFD_SUCCESS;
474
DEBUGMSGTL(("verbose:snmpNotifyFilterTable:snmpNotifyFilterTable_validate_index", "called\n"));
476
/** we should have a non-NULL pointer */
477
netsnmp_assert(NULL != rowreq_ctx);
480
* TODO:430:M: |-> Validate potential snmpNotifyFilterTable index.
484
} /* snmpNotifyFilterTable_validate_index */
489
* ugly, inefficient hack: create a dummy viewEntry list from the filter table
490
* entries matching a profile name. This lets us use the existing vacm
491
* routines for matching oids to views.
493
struct vacm_viewEntry *
494
snmpNotifyFilterTable_vacm_view_subtree(const char *profile)
496
oid tmp_oid[MAX_OID_LEN];
497
netsnmp_index tmp_idx;
499
netsnmp_void_array *s;
500
struct vacm_viewEntry *tmp;
501
snmpNotifyFilterTable_rowreq_ctx *rowreq;
502
netsnmp_container *c;
505
tmp_idx.oids = tmp_oid;
510
c = snmpNotifyFilterTable_container_get();
511
if ((NULL == profile) || (NULL == c))
515
* get the profile subset
517
tmp_idx.oids[0] = strlen(profile);
518
tmp_idx.len = tmp_idx.oids[0] + 1;
519
for (i = 0; i < tmp_idx.len; ++i)
520
tmp_idx.oids[i + 1] = profile[i];
521
s = c->get_subset(c, &tmp_idx);
526
* allocate temporary storage
528
tmp = calloc(sizeof(struct vacm_viewEntry), s->size + 1);
538
for (i = 0, j = 0; i < s->size; ++i) {
539
rowreq = (snmpNotifyFilterTable_rowreq_ctx *) s->array[i];
542
* must match profile name exactly, and subset will return
543
* longer matches, if they exist.
545
if (tmp_idx.oids[0] !=
546
rowreq->tbl_idx.snmpNotifyFilterProfileName_len)
550
* exact match, copy data
551
* vacm_viewEntry viewName and viewSubtree are prefixed with length
555
rowreq->tbl_idx.snmpNotifyFilterProfileName_len;
556
memcpy(&tmp[j].viewName[1],
557
rowreq->tbl_idx.snmpNotifyFilterProfileName,
560
tmp[j].viewSubtree[0] =
561
rowreq->tbl_idx.snmpNotifyFilterSubtree_len;
562
memcpy(&tmp[j].viewSubtree[1],
563
rowreq->tbl_idx.snmpNotifyFilterSubtree,
564
tmp[j].viewSubtree[0] * sizeof(oid));
565
tmp[j].viewSubtreeLen = tmp[j].viewSubtree[0] + 1;
567
tmp[j].viewMaskLen = rowreq->data.snmpNotifyFilterMask_len;
568
memcpy(tmp[j].viewMask, rowreq->data.snmpNotifyFilterMask,
569
tmp[j].viewMaskLen * sizeof(oid));
572
tmp[j].viewType = rowreq->data.snmpNotifyFilterType;
574
tmp[j].next = &tmp[j + 1];
578
tmp[j - 1].next = NULL;