blob: 5765aea59f55a8128750368ea3e8eeb3ab27527a [file] [log] [blame]
.TH "table_iterator" 3 "24 Jun 2011" "Version 5.4.3.pre1" "net-snmp" \" -*- nroff -*-
.ad l
.nh
.SH NAME
table_iterator \-
.PP
The table iterator helper is designed to simplify the task of writing a table handler for the net-snmp agent when the data being accessed is not in an oid sorted form and must be accessed externally.
.SS "Data Structures"
.in +1c
.ti -1c
.RI "struct \fBti_cache_info_s\fP"
.br
.ti -1c
.RI "struct \fBnetsnmp_iterator_info_s\fP"
.br
.RI "\fIHolds iterator information containing functions which should be called by the iterator_handler to loop over your data set and sort it in a SNMP specific manner. \fP"
.in -1c
.SS "Defines"
.in +1c
.ti -1c
.RI "#define \fBTI_REQUEST_CACHE\fP 'ti_cache'"
.br
.ti -1c
.RI "#define \fBTABLE_ITERATOR_NOTAGAIN\fP 255"
.br
.ti -1c
.RI "#define \fBTABLE_ITERATOR_NAME\fP 'table_iterator'"
.br
.in -1c
.SS "Typedefs"
.in +1c
.ti -1c
.RI "typedef struct \fBti_cache_info_s\fP \fBti_cache_info\fP"
.br
.ti -1c
.RI "typedef \fBnetsnmp_variable_list\fP *( \fBNetsnmp_First_Data_Point\fP )(void **loop_context, void **data_context, \fBnetsnmp_variable_list\fP *, struct \fBnetsnmp_iterator_info_s\fP *)"
.br
.ti -1c
.RI "typedef \fBnetsnmp_variable_list\fP *( \fBNetsnmp_Next_Data_Point\fP )(void **loop_context, void **data_context, \fBnetsnmp_variable_list\fP *, struct \fBnetsnmp_iterator_info_s\fP *)"
.br
.ti -1c
.RI "typedef void *( \fBNetsnmp_Make_Data_Context\fP )(void *loop_context, struct \fBnetsnmp_iterator_info_s\fP *)"
.br
.ti -1c
.RI "typedef void( \fBNetsnmp_Free_Loop_Context\fP )(void *, struct \fBnetsnmp_iterator_info_s\fP *)"
.br
.ti -1c
.RI "typedef void( \fBNetsnmp_Free_Data_Context\fP )(void *, struct \fBnetsnmp_iterator_info_s\fP *)"
.br
.ti -1c
.RI "typedef struct \fBnetsnmp_iterator_info_s\fP \fBnetsnmp_iterator_info\fP"
.br
.RI "\fITypedefs the \fBnetsnmp_iterator_info_s\fP struct into netsnmp_iterator_info. \fP"
.in -1c
.SS "Functions"
.in +1c
.ti -1c
.RI "\fBnetsnmp_iterator_info\fP * \fBnetsnmp_iterator_create_table\fP (Netsnmp_First_Data_Point *firstDP, Netsnmp_Next_Data_Point *nextDP, Netsnmp_First_Data_Point *getidx, \fBnetsnmp_variable_list\fP *indexes)"
.br
.ti -1c
.RI "void \fBnetsnmp_iterator_delete_table\fP (\fBnetsnmp_iterator_info\fP *iinfo)"
.br
.ti -1c
.RI "\fBnetsnmp_mib_handler\fP * \fBnetsnmp_get_table_iterator_handler\fP (\fBnetsnmp_iterator_info\fP *iinfo)"
.br
.RI "\fIreturns a netsnmp_mib_handler object for the table_iterator helper \fP"
.ti -1c
.RI "int \fBnetsnmp_register_table_iterator\fP (\fBnetsnmp_handler_registration\fP *reginfo, \fBnetsnmp_iterator_info\fP *iinfo)"
.br
.RI "\fICreates and registers a table iterator helper handler calling netsnmp_create_handler with a handler name set to TABLE_ITERATOR_NAME and access method, netsnmp_table_iterator_helper_handler. \fP"
.ti -1c
.RI "NETSNMP_INLINE void * \fBnetsnmp_extract_iterator_context\fP (\fBnetsnmp_request_info\fP *request)"
.br
.RI "\fIextracts the table_iterator specific data from a request. \fP"
.ti -1c
.RI "NETSNMP_INLINE void \fBnetsnmp_insert_iterator_context\fP (\fBnetsnmp_request_info\fP *request, void *data)"
.br
.RI "\fIinserts table_iterator specific data for a newly created row into a request \fP"
.ti -1c
.RI "int \fBnetsnmp_table_iterator_helper_handler\fP (\fBnetsnmp_mib_handler\fP *handler, \fBnetsnmp_handler_registration\fP *reginfo, \fBnetsnmp_agent_request_info\fP *reqinfo, \fBnetsnmp_request_info\fP *requests)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_first\fP (\fBnetsnmp_iterator_info\fP *iinfo)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_get\fP (\fBnetsnmp_iterator_info\fP *iinfo, void *row)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_next\fP (\fBnetsnmp_iterator_info\fP *iinfo, void *row)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_get_byidx\fP (\fBnetsnmp_iterator_info\fP *iinfo, \fBnetsnmp_variable_list\fP *indexes)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_next_byidx\fP (\fBnetsnmp_iterator_info\fP *iinfo, \fBnetsnmp_variable_list\fP *indexes)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_get_byoid\fP (\fBnetsnmp_iterator_info\fP *iinfo, oid *instance, size_t len)"
.br
.ti -1c
.RI "void * \fBnetsnmp_iterator_row_next_byoid\fP (\fBnetsnmp_iterator_info\fP *iinfo, oid *instance, size_t len)"
.br
.ti -1c
.RI "int \fBnetsnmp_iterator_row_count\fP (\fBnetsnmp_iterator_info\fP *iinfo)"
.br
.in -1c
.SS "Variables"
.in +1c
.ti -1c
.RI "Netsnmp_Node_Handler \fBnetsnmp_table_iterator_helper_handler\fP"
.br
.in -1c
.SH "Detailed Description"
.PP
The table iterator helper is designed to simplify the task of writing a table handler for the net-snmp agent when the data being accessed is not in an oid sorted form and must be accessed externally.
Functionally, it is a specialized version of the more generic table helper but easies the burden of GETNEXT processing by manually looping through all the data indexes retrieved through function calls which should be supplied by the \fBmodule\fP that wishes help. The \fBmodule\fP the table_iterator helps should, afterwards, never be called for the case of 'MODE_GETNEXT' and only for the GET and SET related modes instead.
.PP
The fundamental notion between the table iterator is that it allows your code to iterate over each 'row' within your data storage mechanism, without requiring that it be sorted in a SNMP-index-compliant manner. Through the get_first_data_point and get_next_data_point hooks, the table_iterator helper will repeatedly call your hooks to find the 'proper' row of data that needs processing. The following concepts are important:
.PP
.IP "\(bu" 2
A loop context is a pointer which indicates where in the current processing of a set of rows you currently are. Allows the get_*_data_point routines to move from one row to the next, once the iterator handler has identified the appropriate row for this request, the job of the loop context is done. The most simple example would be a pointer to an integer which simply counts rows from 1 to X. More commonly, it might be a pointer to a linked list \fBnode\fP, or someother internal or external reference to a data set (file seek value, array pointer, ...). If allocated during iteration, either the free_loop_context_at_end (preferably) or the free_loop_context pointers should be set.
.PP
.PP
.IP "\(bu" 2
A data context is something that your handler code can use in order to retrieve the rest of the data for the needed row. This data can be accessed in your handler via netsnmp_extract_iterator_context api with the netsnmp_request_info structure that's passed in. The important difference between a loop context and a data context is that multiple data contexts can be kept by the table_iterator helper, where as only one loop context will ever be held by the table_iterator helper. If allocated during iteration the free_data_context pointer should be set to an appropriate function.
.PP
.PP
The table iterator operates in a series of steps that call your code hooks from your netsnmp_iterator_info registration pointer.
.PP
.IP "\(bu" 2
the get_first_data_point hook is called at the beginning of processing. It should set the \fBvariable\fP list to a list of indexes for the given table. It should also set the loop_context and maybe a data_context which you will get a pointer back to when it needs to call your code to retrieve actual data later. The list of indexes should be returned after being update.
.PP
.PP
.IP "\(bu" 2
the get_next_data_point hook is then called repeatedly and is passed the loop context and the data context for it to update. The indexes, loop context and data context should all be updated if more data is available, otherwise they should be left alone and a NULL should be returned. Ideally, it should update the loop context without the need to reallocate it. If reallocation is necessary for every iterative step, then the free_loop_context function pointer should be set. If not, then the free_loop_context_at_end pointer should be set, which is more efficient since a malloc/free will only be performed once for every iteration.
.PP
.SH "Typedef Documentation"
.PP
.SS "struct \fBnetsnmp_iterator_info_s\fP \fBnetsnmp_iterator_info\fP"
.PP
Typedefs the \fBnetsnmp_iterator_info_s\fP struct into netsnmp_iterator_info.
.SH "Function Documentation"
.PP
.SS "void * netsnmp_extract_iterator_context (\fBnetsnmp_request_info\fP * request)"
.PP
extracts the table_iterator specific data from a request. This function extracts the table iterator specific data from a netsnmp_request_info object. Calls netsnmp_request_get_list_data with request->parent_data set with data from a request that was added previously by a \fBmodule\fP and TABLE_ITERATOR_NAME handler name.
.PP
\fBParameters:\fP
.RS 4
\fIrequest\fP the netsnmp request info structure
.RE
.PP
\fBReturns:\fP
.RS 4
a void pointer(request->parent_data->data), otherwise NULL is returned if request is NULL or request->parent_data is NULL or request->parent_data object is not found.the net
.RE
.PP
.SS "\fBnetsnmp_mib_handler\fP * netsnmp_get_table_iterator_handler (\fBnetsnmp_iterator_info\fP * iinfo)"
.PP
returns a netsnmp_mib_handler object for the table_iterator helper
.SS "void netsnmp_insert_iterator_context (\fBnetsnmp_request_info\fP * request, void * data)"
.PP
inserts table_iterator specific data for a newly created row into a request
.SS "int netsnmp_register_table_iterator (\fBnetsnmp_handler_registration\fP * reginfo, \fBnetsnmp_iterator_info\fP * iinfo)"
.PP
Creates and registers a table iterator helper handler calling netsnmp_create_handler with a handler name set to TABLE_ITERATOR_NAME and access method, netsnmp_table_iterator_helper_handler. If NOT_SERIALIZED is not defined the function injects the serialize handler into the calling chain prior to calling netsnmp_register_table.
.PP
\fBParameters:\fP
.RS 4
\fIreginfo\fP is a pointer to a netsnmp_handler_registration struct
.br
\fIiinfo\fP is a pointer to a netsnmp_iterator_info struct
.RE
.PP
\fBReturns:\fP
.RS 4
MIB_REGISTERED_OK is returned if the registration was a success. Failures are MIB_REGISTRATION_FAILED, MIB_DUPLICATE_REGISTRATION. If iinfo is NULL, SNMPERR_GENERR is returned.
.RE
.PP
.SH "Author"
.PP
Generated automatically by Doxygen for net-snmp from the source code.