152
153
**********************************************************************
153
154
**********************************************************************/
154
/** register specified callbacks for the specified table/oid.
156
/* ==================================
158
* Container Table API: Table maintenance
160
* ================================== */
162
container_table_data *
163
netsnmp_tcontainer_create_table( const char *name,
164
netsnmp_container *container, long flags )
166
container_table_data *table;
168
table = SNMP_MALLOC_TYPEDEF(container_table_data);
172
table->table = container;
174
table->table = netsnmp_container_find("table_container");
182
table->key_type = flags & 0x03; /* Use lowest two bits */
184
table->key_type = TABLE_CONTAINER_KEY_NETSNMP_INDEX;
186
if (!table->table->compare)
187
table->table->compare = netsnmp_compare_netsnmp_index;
188
if (!table->table->ncompare)
189
table->table->ncompare = netsnmp_ncompare_netsnmp_index;
195
netsnmp_tcontainer_delete_table( container_table_data *table )
201
CONTAINER_FREE(table->table);
208
* The various standalone row operation routines
209
* (create/clone/copy/delete)
210
* will be specific to a particular table,
211
* so can't be implemented here.
215
netsnmp_tcontainer_add_row( container_table_data *table, netsnmp_index *row )
217
if (!table || !table->table || !row)
219
CONTAINER_INSERT( table->table, row );
224
netsnmp_tcontainer_remove_row( container_table_data *table, netsnmp_index *row )
226
if (!table || !table->table || !row)
228
CONTAINER_REMOVE( table->table, row );
233
netsnmp_tcontainer_replace_row( container_table_data *table,
234
netsnmp_index *old_row, netsnmp_index *new_row )
236
if (!table || !table->table || !old_row || !new_row)
238
netsnmp_tcontainer_remove_row( table, old_row );
239
netsnmp_tcontainer_add_row( table, new_row );
243
/* netsnmp_tcontainer_remove_delete_row() will be table-specific too */
246
/* ==================================
248
* Container Table API: MIB maintenance
250
* ================================== */
252
/** returns a netsnmp_mib_handler object for the table_container helper */
156
253
netsnmp_mib_handler *
157
254
netsnmp_container_table_handler_get(netsnmp_table_registration_info *tabreg,
158
255
netsnmp_container *container, char key_type)
218
315
return netsnmp_register_table(reginfo, tabreg);
318
/** retrieve the container used by the table_container helper */
320
netsnmp_container_table_container_extract(netsnmp_request_info *request)
322
return (netsnmp_container *)
323
netsnmp_request_get_list_data(request, TABLE_CONTAINER_CONTAINER);
326
#ifndef NETSNMP_USE_INLINE
327
/** find the context data used by the table_container helper */
329
netsnmp_container_table_row_extract(netsnmp_request_info *request)
332
* NOTE: this function must match in table_container.c and table_container.h.
333
* if you change one, change them both!
335
return netsnmp_request_get_list_data(request, TABLE_CONTAINER_ROW);
337
/** find the context data used by the table_container helper */
339
netsnmp_container_table_extract_context(netsnmp_request_info *request)
342
* NOTE: this function must match in table_container.c and table_container.h.
343
* if you change one, change them both!
345
return netsnmp_request_get_list_data(request, TABLE_CONTAINER_ROW);
349
/** inserts a newly created table_container entry into a request list */
351
netsnmp_container_table_row_insert(netsnmp_request_info *request,
354
netsnmp_request_info *req;
355
netsnmp_table_request_info *table_info = NULL;
356
netsnmp_variable_list *this_index = NULL;
357
netsnmp_variable_list *that_index = NULL;
358
oid base_oid[] = {0, 0}; /* Make sure index OIDs are legal! */
359
oid this_oid[MAX_OID_LEN];
360
oid that_oid[MAX_OID_LEN];
361
size_t this_oid_len, that_oid_len;
367
* We'll add the new row information to any request
368
* structure with the same index values as the request
369
* passed in (which includes that one!).
371
* So construct an OID based on these index values.
374
table_info = netsnmp_extract_table_info(request);
375
this_index = table_info->indexes;
376
build_oid_noalloc(this_oid, MAX_OID_LEN, &this_oid_len,
377
base_oid, 2, this_index);
380
* We need to look through the whole of the request list
381
* (as received by the current handler), as there's no
382
* guarantee that this routine will be called by the first
383
* varbind that refers to this row.
384
* In particular, a RowStatus controlled row creation
385
* may easily occur later in the variable list.
387
* So first, we rewind to the head of the list....
389
for (req=request; req->prev; req=req->prev)
393
* ... and then start looking for matching indexes
394
* (by constructing OIDs from these index values)
396
for (; req; req=req->next) {
400
table_info = netsnmp_extract_table_info(req);
401
that_index = table_info->indexes;
402
build_oid_noalloc(that_oid, MAX_OID_LEN, &that_oid_len,
403
base_oid, 2, that_index);
406
* This request has the same index values,
407
* so add the newly-created row information.
409
if (snmp_oid_compare(this_oid, this_oid_len,
410
that_oid, that_oid_len) == 0) {
411
netsnmp_request_add_list_data(req,
412
netsnmp_create_data_list(TABLE_CONTAINER_ROW, row, NULL));
224
418
/**********************************************************************
256
_find_next_row(netsnmp_container *c,
257
netsnmp_table_request_info *tblreq,
262
if (!c || !tblreq || !tblreq->reg_info ) {
263
snmp_log(LOG_ERR,"_find_next_row param error\n");
268
* table helper should have made sure we aren't below our minimum column
270
netsnmp_assert(tblreq->colnum >= tblreq->reg_info->min_column);
273
* if no indexes then use first row.
275
if(tblreq->number_indexes == 0) {
276
row = CONTAINER_FIRST(c);
281
index.oids = tblreq->index_oid;
282
index.len = tblreq->index_oid_len;
283
row = CONTAINER_NEXT(c, &index);
286
row = CONTAINER_NEXT(c, key);
289
* we don't have a row, but we might be at the end of a
290
* column, so try the next column.
294
* don't set tblreq next_col unless we know there is one,
295
* so we don't mess up table handler sparse table processing.
297
oid next_col = netsnmp_table_next_column(tblreq);
299
tblreq->colnum = next_col;
300
row = CONTAINER_FIRST(c);
309
* deprecated, backwards compatability only
311
* expected impact to remove: none
312
* - used between helpers, shouldn't have been used by end users
315
* - never should have been a public method in the first place
318
netsnmp_table_index_find_next_row(netsnmp_container *c,
319
netsnmp_table_request_info *tblreq)
321
return _find_next_row(c, tblreq, NULL );
325
450
NETSNMP_STATIC_INLINE void
326
451
_data_lookup(netsnmp_handler_registration *reginfo,
524
/** retrieve the container used by the table_container helper */
526
netsnmp_container_table_container_extract(netsnmp_request_info *request)
528
return (netsnmp_container *)
529
netsnmp_request_get_list_data(request, TABLE_CONTAINER_CONTAINER);
532
/** inserts a newly created table_container entry into a request list */
534
netsnmp_container_table_row_insert(netsnmp_request_info *request,
537
netsnmp_request_info *req;
538
netsnmp_table_request_info *table_info = NULL;
539
netsnmp_variable_list *this_index = NULL;
540
netsnmp_variable_list *that_index = NULL;
541
oid base_oid[] = {0, 0}; /* Make sure index OIDs are legal! */
542
oid this_oid[MAX_OID_LEN];
543
oid that_oid[MAX_OID_LEN];
544
size_t this_oid_len, that_oid_len;
550
* We'll add the new row information to any request
551
* structure with the same index values as the request
552
* passed in (which includes that one!).
554
* So construct an OID based on these index values.
557
table_info = netsnmp_extract_table_info(request);
558
this_index = table_info->indexes;
559
build_oid_noalloc(this_oid, MAX_OID_LEN, &this_oid_len,
560
base_oid, 2, this_index);
563
* We need to look through the whole of the request list
564
* (as received by the current handler), as there's no
565
* guarantee that this routine will be called by the first
566
* varbind that refers to this row.
567
* In particular, a RowStatus controlled row creation
568
* may easily occur later in the variable list.
570
* So first, we rewind to the head of the list....
572
for (req=request; req->prev; req=req->prev)
576
* ... and then start looking for matching indexes
577
* (by constructing OIDs from these index values)
579
for (; req; req=req->next) {
582
table_info = netsnmp_extract_table_info(req);
583
that_index = table_info->indexes;
584
build_oid_noalloc(that_oid, MAX_OID_LEN, &that_oid_len,
585
base_oid, 2, that_index);
652
/* ==================================
654
* Container Table API: Row operations
656
* ================================== */
659
_find_next_row(netsnmp_container *c,
660
netsnmp_table_request_info *tblreq,
665
if (!c || !tblreq || !tblreq->reg_info ) {
666
snmp_log(LOG_ERR,"_find_next_row param error\n");
671
* table helper should have made sure we aren't below our minimum column
673
netsnmp_assert(tblreq->colnum >= tblreq->reg_info->min_column);
676
* if no indexes then use first row.
678
if(tblreq->number_indexes == 0) {
679
row = CONTAINER_FIRST(c);
684
index.oids = tblreq->index_oid;
685
index.len = tblreq->index_oid_len;
686
row = CONTAINER_NEXT(c, &index);
689
row = CONTAINER_NEXT(c, key);
588
* This request has the same index values,
589
* so add the newly-created row information.
692
* we don't have a row, but we might be at the end of a
693
* column, so try the next column.
591
if (snmp_oid_compare(this_oid, this_oid_len,
592
that_oid, that_oid_len) == 0) {
593
netsnmp_request_add_list_data(req,
594
netsnmp_create_data_list(TABLE_CONTAINER_ROW, row, NULL));
697
* don't set tblreq next_col unless we know there is one,
698
* so we don't mess up table handler sparse table processing.
700
oid next_col = netsnmp_table_next_column(tblreq);
702
tblreq->colnum = next_col;
703
row = CONTAINER_FIRST(c);
599
#ifndef NETSNMP_USE_INLINE
600
/** find the context data used by the table_container helper */
602
netsnmp_container_table_row_extract(netsnmp_request_info *request)
712
* deprecated, backwards compatability only
714
* expected impact to remove: none
715
* - used between helpers, shouldn't have been used by end users
718
* - never should have been a public method in the first place
721
netsnmp_table_index_find_next_row(netsnmp_container *c,
722
netsnmp_table_request_info *tblreq)
605
* NOTE: this function must match in table_container.c and table_container.h.
606
* if you change one, change them both!
608
return netsnmp_request_get_list_data(request, TABLE_CONTAINER_ROW);
724
return _find_next_row(c, tblreq, NULL );
727
/* ==================================
729
* Container Table API: Index operations
731
* ================================== */